Select/Explain should only return the explanation (#2256)
This commit is contained in:
parent
ce9430d1ac
commit
ee3a1c211f
3 changed files with 197 additions and 201 deletions
|
@ -89,7 +89,7 @@ impl Iterator {
|
|||
// Process the query START clause
|
||||
self.setup_start(&cancel_ctx, opt, txn, stm).await?;
|
||||
// Process any EXPLAIN clause
|
||||
let explanation = self.output_explain(&cancel_ctx, opt, txn, stm)?;
|
||||
if !self.output_explain(&cancel_ctx, opt, txn, stm)? {
|
||||
// Process prepared values
|
||||
self.iterate(&cancel_ctx, opt, txn, stm).await?;
|
||||
// Return any document errors
|
||||
|
@ -108,9 +108,6 @@ impl Iterator {
|
|||
self.output_limit(ctx, opt, txn, stm).await?;
|
||||
// Process any FETCH clause
|
||||
self.output_fetch(ctx, opt, txn, stm).await?;
|
||||
// Add the EXPLAIN clause to the result
|
||||
if let Some(e) = explanation {
|
||||
self.results.push(e);
|
||||
}
|
||||
// Output the results
|
||||
Ok(mem::take(&mut self.results).into())
|
||||
|
@ -362,9 +359,10 @@ impl Iterator {
|
|||
_opt: &Options,
|
||||
_txn: &Transaction,
|
||||
stm: &Statement<'_>,
|
||||
) -> Result<Option<Value>, Error> {
|
||||
Ok(if stm.explain() {
|
||||
let mut explains = Vec::with_capacity(self.entries.len());
|
||||
) -> Result<bool, Error> {
|
||||
if !stm.explain() {
|
||||
return Ok(false);
|
||||
}
|
||||
for iter in &self.entries {
|
||||
let (operation, detail) = match iter {
|
||||
Iterable::Value(v) => ("Iterate Value", vec![("value", v.to_owned())]),
|
||||
|
@ -401,15 +399,9 @@ impl Iterator {
|
|||
("operation", Value::from(operation)),
|
||||
("detail", Value::Object(Object::from(HashMap::from_iter(detail)))),
|
||||
]));
|
||||
explains.push(Value::Object(explain));
|
||||
self.results.push(Value::Object(explain));
|
||||
}
|
||||
Some(Value::Object(Object::from(HashMap::from([(
|
||||
"explain",
|
||||
Value::Array(Array::from(explains)),
|
||||
)]))))
|
||||
} else {
|
||||
None
|
||||
})
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
|
|
|
@ -11,12 +11,13 @@ async fn select_where_matches_using_index() -> Result<(), Error> {
|
|||
CREATE blog:1 SET title = 'Hello World!';
|
||||
DEFINE ANALYZER simple TOKENIZERS blank,class;
|
||||
DEFINE INDEX blog_title ON blog FIELDS title SEARCH ANALYZER simple BM25 HIGHLIGHTS;
|
||||
SELECT id, search::highlight('<em>', '</em>', 1) AS title FROM blog WHERE title @1@ 'Hello' EXPLAIN;
|
||||
SELECT id FROM blog WHERE title @1@ 'Hello' EXPLAIN;
|
||||
SELECT id, search::highlight('<em>', '</em>', 1) AS title FROM blog WHERE title @1@ 'Hello';
|
||||
";
|
||||
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(), 4);
|
||||
assert_eq!(res.len(), 5);
|
||||
//
|
||||
let _ = res.remove(0).result?;
|
||||
let _ = res.remove(0).result?;
|
||||
|
@ -24,13 +25,6 @@ async fn select_where_matches_using_index() -> Result<(), Error> {
|
|||
let tmp = res.remove(0).result?;
|
||||
let val = Value::parse(
|
||||
"[
|
||||
{
|
||||
id: blog:1,
|
||||
title: '<em>Hello</em> World!'
|
||||
},
|
||||
{
|
||||
explain:
|
||||
[
|
||||
{
|
||||
detail: {
|
||||
plan: {
|
||||
|
@ -42,7 +36,15 @@ async fn select_where_matches_using_index() -> Result<(), Error> {
|
|||
},
|
||||
operation: 'Iterate Index'
|
||||
}
|
||||
]
|
||||
]",
|
||||
);
|
||||
assert_eq!(tmp, val);
|
||||
let tmp = res.remove(0).result?;
|
||||
let val = Value::parse(
|
||||
"[
|
||||
{
|
||||
id: blog:1,
|
||||
title: '<em>Hello</em> World!'
|
||||
}
|
||||
]",
|
||||
);
|
||||
|
@ -57,12 +59,13 @@ async fn select_where_matches_without_using_index_iterator() -> Result<(), Error
|
|||
CREATE blog:2 SET title = 'Foo Bar!';
|
||||
DEFINE ANALYZER simple TOKENIZERS blank,class FILTERS lowercase;
|
||||
DEFINE INDEX blog_title ON blog FIELDS title SEARCH ANALYZER simple BM25(1.2,0.75) HIGHLIGHTS;
|
||||
SELECT id,search::highlight('<em>', '</em>', 1) AS title FROM blog WHERE (title @0@ 'hello' AND identifier > 0) OR (title @1@ 'world' AND identifier < 99) EXPLAIN;
|
||||
SELECT id FROM blog WHERE (title @0@ 'hello' AND identifier > 0) OR (title @1@ 'world' AND identifier < 99) EXPLAIN;
|
||||
SELECT id,search::highlight('<em>', '</em>', 1) AS title FROM blog WHERE (title @0@ 'hello' AND identifier > 0) OR (title @1@ 'world' AND identifier < 99);
|
||||
";
|
||||
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);
|
||||
assert_eq!(res.len(), 6);
|
||||
//
|
||||
let _ = res.remove(0).result?;
|
||||
let _ = res.remove(0).result?;
|
||||
|
@ -71,20 +74,21 @@ async fn select_where_matches_without_using_index_iterator() -> Result<(), Error
|
|||
let tmp = res.remove(0).result?;
|
||||
let val = Value::parse(
|
||||
"[
|
||||
{
|
||||
id: blog:1,
|
||||
title: 'Hello <em>World</em>!'
|
||||
},
|
||||
{
|
||||
explain:
|
||||
[
|
||||
{
|
||||
detail: {
|
||||
table: 'blog',
|
||||
},
|
||||
operation: 'Iterate Table'
|
||||
}
|
||||
]
|
||||
]",
|
||||
);
|
||||
assert_eq!(tmp, val);
|
||||
let tmp = res.remove(0).result?;
|
||||
let val = Value::parse(
|
||||
"[
|
||||
{
|
||||
id: blog:1,
|
||||
title: 'Hello <em>World</em>!'
|
||||
}
|
||||
]",
|
||||
);
|
||||
|
@ -93,41 +97,32 @@ async fn select_where_matches_without_using_index_iterator() -> Result<(), Error
|
|||
}
|
||||
|
||||
async fn select_where_matches_using_index_and_arrays(parallel: bool) -> Result<(), Error> {
|
||||
let p = if parallel {
|
||||
"PARALLEL"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let sql = format!(
|
||||
r"
|
||||
CREATE blog:1 SET content = ['Hello World!', 'Be Bop', 'Foo Bãr'];
|
||||
DEFINE ANALYZER simple TOKENIZERS blank,class;
|
||||
DEFINE INDEX blog_content ON blog FIELDS content SEARCH ANALYZER simple BM25 HIGHLIGHTS;
|
||||
SELECT id, search::highlight('<em>', '</em>', 1) AS content FROM blog WHERE content @1@ 'Hello Bãr' {} EXPLAIN;
|
||||
",
|
||||
if parallel {
|
||||
"PARALLEL"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
SELECT id FROM blog WHERE content @1@ 'Hello Bãr' {p} EXPLAIN;
|
||||
SELECT id, search::highlight('<em>', '</em>', 1) AS content FROM blog WHERE content @1@ 'Hello Bãr' {p};
|
||||
"
|
||||
);
|
||||
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(), 4);
|
||||
assert_eq!(res.len(), 5);
|
||||
//
|
||||
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(
|
||||
"[
|
||||
{
|
||||
id: blog:1,
|
||||
content: [
|
||||
'<em>Hello</em> World!',
|
||||
'Be Bop',
|
||||
'Foo <em>Bãr</em>'
|
||||
]
|
||||
},
|
||||
{
|
||||
explain:
|
||||
[
|
||||
{
|
||||
detail: {
|
||||
plan: {
|
||||
|
@ -139,6 +134,19 @@ async fn select_where_matches_using_index_and_arrays(parallel: bool) -> Result<(
|
|||
},
|
||||
operation: 'Iterate Index'
|
||||
}
|
||||
]",
|
||||
);
|
||||
assert_eq!(tmp, val);
|
||||
//
|
||||
let tmp = res.remove(0).result?;
|
||||
let val = Value::parse(
|
||||
"[
|
||||
{
|
||||
id: blog:1,
|
||||
content: [
|
||||
'<em>Hello</em> World!',
|
||||
'Be Bop',
|
||||
'Foo <em>Bãr</em>'
|
||||
]
|
||||
}
|
||||
]",
|
||||
|
@ -164,7 +172,7 @@ async fn select_where_matches_using_index_offsets() -> Result<(), Error> {
|
|||
DEFINE ANALYZER simple TOKENIZERS blank,class;
|
||||
DEFINE INDEX blog_title ON blog FIELDS title SEARCH ANALYZER simple BM25(1.2,0.75) HIGHLIGHTS;
|
||||
DEFINE INDEX blog_content ON blog FIELDS content SEARCH ANALYZER simple BM25 HIGHLIGHTS;
|
||||
SELECT id, search::offsets(0) AS title, search::offsets(1) AS content FROM blog WHERE title @0@ 'title' AND content @1@ 'Hello Bãr' EXPLAIN;
|
||||
SELECT id, search::offsets(0) AS title, search::offsets(1) AS content FROM blog WHERE title @0@ 'title' AND content @1@ 'Hello Bãr';
|
||||
";
|
||||
let dbs = Datastore::new("memory").await?;
|
||||
let ses = Session::for_kv().with_ns("test").with_db("test");
|
||||
|
@ -186,22 +194,6 @@ async fn select_where_matches_using_index_offsets() -> Result<(), Error> {
|
|||
0: [{s:0, e:5}],
|
||||
2: [{s:4, e:7}]
|
||||
}
|
||||
},
|
||||
{
|
||||
explain:
|
||||
[
|
||||
{
|
||||
detail: {
|
||||
plan: {
|
||||
index: 'blog_content',
|
||||
operator: '@1@',
|
||||
value: 'Hello Bãr'
|
||||
},
|
||||
table: 'blog',
|
||||
},
|
||||
operation: 'Iterate Index'
|
||||
}
|
||||
]
|
||||
}
|
||||
]",
|
||||
);
|
||||
|
|
|
@ -266,11 +266,12 @@ async fn select_where_field_is_thing_and_with_index() -> Result<(), Error> {
|
|||
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;";
|
||||
SELECT * FROM post WHERE author = person:tobie EXPLAIN;
|
||||
SELECT * FROM post WHERE author = person:tobie;";
|
||||
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);
|
||||
assert_eq!(res.len(), 6);
|
||||
//
|
||||
let _ = res.remove(0).result?;
|
||||
let _ = res.remove(0).result?;
|
||||
|
@ -280,17 +281,6 @@ async fn select_where_field_is_thing_and_with_index() -> Result<(), Error> {
|
|||
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: {
|
||||
|
@ -302,7 +292,20 @@ async fn select_where_field_is_thing_and_with_index() -> Result<(), Error> {
|
|||
},
|
||||
operation: 'Iterate Index'
|
||||
}
|
||||
]
|
||||
]",
|
||||
);
|
||||
assert_eq!(tmp, val);
|
||||
//
|
||||
let tmp = res.remove(0).result?;
|
||||
let val = Value::parse(
|
||||
"[
|
||||
{
|
||||
author: person:tobie,
|
||||
id: post:1
|
||||
},
|
||||
{
|
||||
author: person:tobie,
|
||||
id: post:2
|
||||
}
|
||||
]",
|
||||
);
|
||||
|
@ -316,11 +319,12 @@ async fn select_where_and_with_index() -> Result<(), Error> {
|
|||
CREATE person:tobie SET name = 'Tobie', genre='m';
|
||||
CREATE person:jaime SET name = 'Jaime', genre='m';
|
||||
DEFINE INDEX person_name ON TABLE person COLUMNS name;
|
||||
SELECT name FROM person WHERE name = 'Tobie' AND genre = 'm' EXPLAIN;";
|
||||
SELECT name FROM person WHERE name = 'Tobie' AND genre = 'm' EXPLAIN;
|
||||
SELECT name FROM person WHERE name = 'Tobie' AND genre = 'm';";
|
||||
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(), 4);
|
||||
assert_eq!(res.len(), 5);
|
||||
//
|
||||
let _ = res.remove(0).result?;
|
||||
let _ = res.remove(0).result?;
|
||||
|
@ -329,12 +333,6 @@ async fn select_where_and_with_index() -> Result<(), Error> {
|
|||
let tmp = res.remove(0).result?;
|
||||
let val = Value::parse(
|
||||
"[
|
||||
{
|
||||
name: 'Tobie'
|
||||
},
|
||||
{
|
||||
explain:
|
||||
[
|
||||
{
|
||||
detail: {
|
||||
plan: {
|
||||
|
@ -346,7 +344,15 @@ async fn select_where_and_with_index() -> Result<(), Error> {
|
|||
},
|
||||
operation: 'Iterate Index'
|
||||
}
|
||||
]
|
||||
]",
|
||||
);
|
||||
assert_eq!(tmp, val);
|
||||
//
|
||||
let tmp = res.remove(0).result?;
|
||||
let val = Value::parse(
|
||||
"[
|
||||
{
|
||||
name: 'Tobie'
|
||||
}
|
||||
]",
|
||||
);
|
||||
|
@ -360,11 +366,12 @@ async fn select_where_and_with_unique_index() -> Result<(), Error> {
|
|||
CREATE person:tobie SET name = 'Tobie', genre='m';
|
||||
CREATE person:jaime SET name = 'Jaime', genre='m';
|
||||
DEFINE INDEX person_name ON TABLE person COLUMNS name UNIQUE;
|
||||
SELECT name FROM person WHERE name = 'Jaime' AND genre = 'm' EXPLAIN;";
|
||||
SELECT name FROM person WHERE name = 'Jaime' AND genre = 'm' EXPLAIN;
|
||||
SELECT name FROM person WHERE name = 'Jaime' AND genre = 'm';";
|
||||
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(), 4);
|
||||
assert_eq!(res.len(), 5);
|
||||
//
|
||||
let _ = res.remove(0).result?;
|
||||
let _ = res.remove(0).result?;
|
||||
|
@ -373,12 +380,6 @@ async fn select_where_and_with_unique_index() -> Result<(), Error> {
|
|||
let tmp = res.remove(0).result?;
|
||||
let val = Value::parse(
|
||||
"[
|
||||
{
|
||||
name: 'Jaime'
|
||||
},
|
||||
{
|
||||
explain:
|
||||
[
|
||||
{
|
||||
detail: {
|
||||
plan: {
|
||||
|
@ -390,7 +391,15 @@ async fn select_where_and_with_unique_index() -> Result<(), Error> {
|
|||
},
|
||||
operation: 'Iterate Index'
|
||||
}
|
||||
]
|
||||
]",
|
||||
);
|
||||
assert_eq!(tmp, val);
|
||||
//
|
||||
let tmp = res.remove(0).result?;
|
||||
let val = Value::parse(
|
||||
"[
|
||||
{
|
||||
name: 'Jaime'
|
||||
}
|
||||
]",
|
||||
);
|
||||
|
@ -405,11 +414,12 @@ async fn select_where_and_with_fulltext_index() -> Result<(), Error> {
|
|||
CREATE person:jaime SET name = 'Jaime', genre='m';
|
||||
DEFINE ANALYZER simple TOKENIZERS blank,class FILTERS lowercase;
|
||||
DEFINE INDEX ft_name ON TABLE person COLUMNS name SEARCH ANALYZER simple BM25(1.2,0.75);
|
||||
SELECT name FROM person WHERE name @@ 'Jaime' AND genre = 'm' EXPLAIN;";
|
||||
SELECT name FROM person WHERE name @@ 'Jaime' AND genre = 'm' EXPLAIN;
|
||||
SELECT name FROM person WHERE name @@ 'Jaime' AND genre = 'm';";
|
||||
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);
|
||||
assert_eq!(res.len(), 6);
|
||||
//
|
||||
let _ = res.remove(0).result?;
|
||||
let _ = res.remove(0).result?;
|
||||
|
@ -419,12 +429,6 @@ async fn select_where_and_with_fulltext_index() -> Result<(), Error> {
|
|||
let tmp = res.remove(0).result?;
|
||||
let val = Value::parse(
|
||||
"[
|
||||
{
|
||||
name: 'Jaime'
|
||||
},
|
||||
{
|
||||
explain:
|
||||
[
|
||||
{
|
||||
detail: {
|
||||
plan: {
|
||||
|
@ -436,7 +440,15 @@ async fn select_where_and_with_fulltext_index() -> Result<(), Error> {
|
|||
},
|
||||
operation: 'Iterate Index'
|
||||
}
|
||||
]
|
||||
]",
|
||||
);
|
||||
assert_eq!(tmp, val);
|
||||
//
|
||||
let tmp = res.remove(0).result?;
|
||||
let val = Value::parse(
|
||||
"[
|
||||
{
|
||||
name: 'Jaime'
|
||||
}
|
||||
]",
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue