Indexes should be populated on import ()

This commit is contained in:
Micha de Vries 2024-05-15 15:29:40 +02:00 committed by GitHub
parent 8dfdf3dd88
commit 47054b2891
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 73 additions and 4 deletions
core/src/doc
lib/tests

View file

@ -23,10 +23,6 @@ impl<'a> Document<'a> {
txn: &Transaction,
_stm: &Statement<'_>,
) -> Result<(), Error> {
// Check import
if opt.import {
return Ok(());
}
// Was this force targeted at a specific index?
let targeted_force = matches!(opt.force, Force::Index(_));
// Collect indexes or skip

73
lib/tests/option.rs Normal file
View file

@ -0,0 +1,73 @@
mod parse;
use parse::Parse;
mod helpers;
use helpers::new_ds;
use surrealdb::dbs::Session;
use surrealdb::err::Error;
use surrealdb::sql::Value;
#[tokio::test]
async fn option_import_indexes_should_be_populated() -> Result<(), Error> {
let sql = "
OPTION IMPORT;
DEFINE INDEX field_num ON test FIELDS num;
CREATE ONLY test:1 SET num = 123;
SELECT * FROM test WHERE num = 123;
SELECT * FROM test WHERE num = 123 EXPLAIN;
";
let dbs = new_ds().await?;
let ses = Session::owner().with_ns("test").with_db("test");
let res = &mut dbs.execute(sql, &ses, None).await?;
//
// OPTION IMPORT does not count as a result
assert_eq!(res.len(), 4);
//
let tmp = res.remove(0).result;
assert!(tmp.is_ok(), "{:?}", tmp.err());
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"{
id: test:1,
num: 123
}",
);
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"[
{
id: test:1,
num: 123
}
]",
);
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"[
{
detail: {
plan: {
index: 'field_num',
operator: '=',
value: 123
},
table: 'test'
},
operation: 'Iterate Index'
},
{
detail: {
type: 'Memory'
},
operation: 'Collector'
}
]",
);
assert_eq!(tmp, val);
//
Ok(())
}