Support of IN operator in the planner (#3640)

This commit is contained in:
Emmanuel Keller 2024-03-06 23:41:48 +00:00 committed by GitHub
parent e637a538d2
commit 686a140d80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 60 additions and 6 deletions

View file

@ -316,12 +316,11 @@ impl<'a> TreeBuilder<'a> {
(Operator::Contain, v, IdiomPosition::Left) => {
Some(IndexOperator::Equality(v.clone()))
}
(Operator::ContainAny, Value::Array(a), IdiomPosition::Left) => {
Some(IndexOperator::Union(a.clone()))
}
(Operator::ContainAll, Value::Array(a), IdiomPosition::Left) => {
Some(IndexOperator::Union(a.clone()))
}
(
Operator::ContainAny | Operator::ContainAll | Operator::Inside,
Value::Array(a),
IdiomPosition::Left,
) => Some(IndexOperator::Union(a.clone())),
(
Operator::LessThan
| Operator::LessThanOrEqual

View file

@ -1246,3 +1246,58 @@ async fn select_with_uuid_value() -> Result<(), Error> {
Ok(())
}
#[tokio::test]
async fn select_with_in_operator() -> Result<(), Error> {
let dbs = new_ds().await?;
let ses = Session::owner().with_ns("test").with_db("test");
let sql = "
DEFINE INDEX user_email_idx ON user FIELDS email;
CREATE user:1 CONTENT { email: 'a@b' };
CREATE user:2 CONTENT { email: 'c@d' };
SELECT * FROM user WHERE email IN ['a@b', 'e@f'] EXPLAIN;
SELECT * FROM user WHERE email INSIDE ['a@b', 'e@f'] EXPLAIN;
SELECT * FROM user WHERE email IN ['a@b', 'e@f'];
SELECT * FROM user WHERE email INSIDE ['a@b', 'e@f'];
";
let mut res = dbs.execute(&sql, &ses, None).await?;
assert_eq!(res.len(), 7);
skip_ok(&mut res, 3)?;
for _ in 0..2 {
let tmp = res.remove(0).result?;
let val = Value::parse(
r#"[
{
detail: {
plan: {
index: 'user_email_idx',
operator: 'union',
value: ['a@b', 'e@f']
},
table: 'user'
},
operation: 'Iterate Index'
}
]"#,
);
assert_eq!(format!("{:#}", tmp), format!("{:#}", val));
}
for _ in 0..2 {
let tmp = res.remove(0).result?;
let val = Value::parse(
r#"[
{
'id': user:1,
'email': 'a@b'
}
]"#,
);
assert_eq!(format!("{:#}", tmp), format!("{:#}", val));
}
Ok(())
}