Add thing as scalar node for indexing (#2239)

Co-authored-by: Emmanuel Keller <emmanuel.keller@surrealdb.com>
This commit is contained in:
hchockarprasad 2023-07-10 13:49:37 +05:30 committed by GitHub
parent a10b9cbb75
commit bb61ee7ff9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 0 deletions

View file

@ -77,6 +77,7 @@ impl<'a> TreeBuilder<'a> {
Value::Strand(_) => Node::Scalar(v.to_owned()),
Value::Number(_) => Node::Scalar(v.to_owned()),
Value::Bool(_) => Node::Scalar(v.to_owned()),
Value::Thing(_) => Node::Scalar(v.to_owned()),
Value::Subquery(s) => self.eval_subquery(s).await?,
Value::Param(p) => {
let v = p.compute(self.ctx, self.opt, self.txn, None).await?;

View file

@ -258,6 +258,58 @@ async fn select_where_field_is_bool() -> Result<(), Error> {
Ok(())
}
#[tokio::test]
async fn select_where_field_is_thing_and_with_index() -> Result<(), Error> {
let sql = "
CREATE person:tobie SET name = 'Tobie';
DEFINE INDEX author ON TABLE post COLUMNS author;
CREATE post:1 SET author = person:tobie;
CREATE post:2 SET author = person:tobie;
SELECT * FROM post WHERE author = person:tobie EXPLAIN;";
let dbs = Datastore::new("memory").await?;
let ses = Session::for_kv().with_ns("test").with_db("test");
let res = &mut dbs.execute(sql, &ses, None).await?;
assert_eq!(res.len(), 5);
//
let _ = res.remove(0).result?;
let _ = res.remove(0).result?;
let _ = res.remove(0).result?;
let _ = res.remove(0).result?;
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"[
{
author: person:tobie,
id: post:1
},
{
author: person:tobie,
id: post:2
},
{
explain:
[
{
detail: {
plan: {
index: 'author',
operator: '=',
value: person:tobie
},
table: 'post',
},
operation: 'Iterate Index'
}
]
}
]",
);
assert_eq!(tmp, val);
Ok(())
}
#[tokio::test]
async fn select_where_and_with_index() -> Result<(), Error> {
let sql = "