Skip to content

Commit

Permalink
Check whether index is valid at runtime (vesoft-inc#1291)
Browse files Browse the repository at this point in the history
* Check whether index is valid at runtime

* Fix failed ut

* Fix steps

* drop the used space

* Format
  • Loading branch information
yixinglu authored and CPWstatic committed Aug 2, 2021
1 parent e0b6d6c commit 8feea4b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 70 deletions.
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()) {
return Status::Error("There is no index to use 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

0 comments on commit 8feea4b

Please sign in to comment.