Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Check whether index is valid at runtime #1291

Merged
merged 5 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/executor/query/IndexScanExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "executor/query/IndexScanExecutor.h"

#include <algorithm>

#include "planner/plan/PlanNode.h"
#include "context/QueryContext.h"
#include "service/GraphFlags.h"
Expand All @@ -28,8 +30,16 @@ folly::Future<Status> IndexScanExecutor::indexScan() {
DataSet dataSet({"dummy"});
return finish(ResultBuilder().value(Value(std::move(dataSet))).finish());
}

const auto &ictxs = lookup->queryContext();
auto iter = std::find_if(
ictxs.begin(), ictxs.end(), [](auto &ictx) { return !ictx.index_id_ref().is_set(); });
if (ictxs.empty() || iter != ictxs.end()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the checking logic in the if statement ictxs.empty() necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My test cases is for this scenario.

return Status::Error("There is no index to use at runtime");
}

Comment on lines +33 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the index ID not set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now index is selected in multiple opt rules. when all rules could not select the index, IndexFullScanNode without index is still in the execution plan. so here needs to check the real index at runtime.

return storageClient->lookupIndex(lookup->space(),
lookup->queryContext(),
ictxs,
lookup->isEdge(),
lookup->schemaId(),
lookup->returnColumns())
Expand Down
95 changes: 26 additions & 69 deletions tests/tck/features/lookup/LookUp.IntVid.feature
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
Feature: LookUpTest_Vid_Int

Scenario: LookupTest IntVid VertexIndexHint
Background:
Given an empty graph
And create a space with following options:
| partition_num | 9 |
| replica_factor | 1 |
| vid_type | int64 |
| charset | utf8 |
| collate | utf8_bin |
And having executed:

Scenario: LookupTest IntVid VertexIndexHint
Given having executed:
"""
CREATE TAG lookup_tag_1(col1 int, col2 int, col3 int);
CREATE TAG lookup_tag_2(col1 bool, col2 int, col3 double, col4 bool);
Expand Down Expand Up @@ -45,14 +47,7 @@ Feature: LookUpTest_Vid_Int
Then drop the used space

Scenario: LookupTest IntVid EdgeIndexHint
Given an empty graph
And create a space with following options:
| partition_num | 9 |
| replica_factor | 1 |
| vid_type | int64 |
| charset | utf8 |
| collate | utf8_bin |
And having executed:
Given having executed:
"""
CREATE EDGE lookup_edge_1(col1 int, col2 int, col3 int);
CREATE EDGE lookup_edge_2(col1 bool,col2 int, col3 double, col4 bool);
Expand Down Expand Up @@ -86,14 +81,7 @@ Feature: LookUpTest_Vid_Int
Then drop the used space

Scenario: LookupTest IntVid VertexConditionScan
Given an empty graph
And create a space with following options:
| partition_num | 9 |
| replica_factor | 1 |
| vid_type | int64 |
| charset | utf8 |
| collate | utf8_bin |
And having executed:
Given having executed:
"""
CREATE TAG lookup_tag_2(col1 bool, col2 int, col3 double, col4 bool);
CREATE TAG INDEX t_index_2 ON lookup_tag_2(col2, col3, col4);
Expand Down Expand Up @@ -244,14 +232,7 @@ Feature: LookUpTest_Vid_Int
Then drop the used space

Scenario: LookupTest IntVid EdgeConditionScan
Given an empty graph
And create a space with following options:
| partition_num | 9 |
| replica_factor | 1 |
| vid_type | int64 |
| charset | utf8 |
| collate | utf8_bin |
And having executed:
Given having executed:
"""
CREATE EDGE lookup_edge_2(col1 bool,col2 int, col3 double, col4 bool);
CREATE EDGE INDEX e_index_2 ON lookup_edge_2(col2, col3, col4);
Expand Down Expand Up @@ -395,14 +376,7 @@ Feature: LookUpTest_Vid_Int
Then drop the used space

Scenario: LookupTest IntVid FunctionExprTest
Given an empty graph
And create a space with following options:
| partition_num | 9 |
| replica_factor | 1 |
| vid_type | int64 |
| charset | utf8 |
| collate | utf8_bin |
And having executed:
Given having executed:
"""
CREATE TAG lookup_tag_2(col1 bool, col2 int, col3 double, col4 bool);
CREATE TAG INDEX t_index_2 ON lookup_tag_2(col2, col3, col4);
Expand Down Expand Up @@ -532,13 +506,6 @@ Feature: LookUpTest_Vid_Int
Then drop the used space

Scenario: LookupTest IntVid YieldClauseTest
Given an empty graph
And create a space with following options:
| partition_num | 9 |
| replica_factor | 1 |
| vid_type | int64 |
| charset | utf8 |
| collate | utf8_bin |
When executing query:
"""
CREATE TAG student(number int, age int)
Expand Down Expand Up @@ -590,13 +557,6 @@ Feature: LookUpTest_Vid_Int
Then drop the used space

Scenario: LookupTest IntVid OptimizerTest
Given an empty graph
And create a space with following options:
| partition_num | 9 |
| replica_factor | 1 |
| vid_type | int64 |
| charset | utf8 |
| collate | utf8_bin |
When executing query:
"""
CREATE TAG t1(c1 int, c2 int, c3 int, c4 int, c5 int)
Expand Down Expand Up @@ -681,13 +641,6 @@ Feature: LookUpTest_Vid_Int
Then drop the used space

Scenario: LookupTest IntVid OptimizerWithStringFieldTest
Given an empty graph
And create a space with following options:
| partition_num | 9 |
| replica_factor | 1 |
| vid_type | int64 |
| charset | utf8 |
| collate | utf8_bin |
When executing query:
"""
CREATE TAG t1_str(c1 int, c2 int, c3 string, c4 string)
Expand Down Expand Up @@ -762,13 +715,6 @@ Feature: LookUpTest_Vid_Int
Then drop the used space

Scenario: LookupTest IntVid StringFieldTest
Given an empty graph
And create a space with following options:
| partition_num | 9 |
| replica_factor | 1 |
| vid_type | int64 |
| charset | utf8 |
| collate | utf8_bin |
When executing query:
"""
CREATE TAG tag_with_str(c1 int, c2 string, c3 string)
Expand Down Expand Up @@ -848,13 +794,6 @@ Feature: LookUpTest_Vid_Int
Then drop the used space

Scenario: LookupTest IntVid ConditionTest
Given an empty graph
And create a space with following options:
| partition_num | 9 |
| replica_factor | 1 |
| vid_type | int64 |
| charset | utf8 |
| collate | utf8_bin |
When executing query:
"""
create tag identity (BIRTHDAY int, NATION string, BIRTHPLACE_CITY string)
Expand Down Expand Up @@ -887,3 +826,21 @@ Feature: LookUpTest_Vid_Int
Then the result should be, in any order:
| VertexID |
Then drop the used space

Scenario: LookupTest no index to use at runtime
Given having executed:
"""
CREATE TAG player(name string, age int);
"""
And wait 6 seconds
When executing query:
"""
INSERT VERTEX player(name, age) VALUES hash('Tim'):('Tim', 20);
"""
Then the execution should be successful
When executing query:
"""
LOOKUP ON player WHERE player.name == 'Tim'
"""
Then an ExecutionError should be raised at runtime: There is no index to use at runtime
Then drop the used space
18 changes: 18 additions & 0 deletions tests/tck/features/lookup/LookUp.feature
Original file line number Diff line number Diff line change
Expand Up @@ -957,3 +957,21 @@ Feature: LookUpTest_Vid_String
| VertexID |
| '202' |
Then drop the used space

Scenario: LookupTest no index to use at runtime
Given having executed:
"""
CREATE TAG player(name string, age int);
"""
And wait 6 seconds
When executing query:
"""
INSERT VERTEX player(name, age) VALUES 'Tim':('Tim', 20);
"""
Then the execution should be successful
When executing query:
"""
LOOKUP ON player WHERE player.name == 'Tim'
"""
Then an ExecutionError should be raised at runtime: There is no index to use at runtime
Then drop the used space