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

Conversation

yixinglu
Copy link
Contributor

as title.

Comment on lines +33 to +40

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");
}

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.

@bright-starry-sky
Copy link
Contributor

In addition, maybe need to check the validity of the index. for example :
tag t1 (c1)
index i1 ()
this index is only used for count(*)

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.

@yixinglu
Copy link
Contributor Author

In addition, maybe need to check the validity of the index. for example :
tag t1 (c1)
index i1 ()
this index is only used for count(*)

Now if you use t1.c1 to lookup, the execution plan can use the index i1 to full scan the whole tag. such as

(root@nebula) [test_index]> explain lookup on player where player.name == 'tim'
Execution succeeded (time spent 1403/1847 us)

Execution Plan (optimize time 813 us)

-----+------------------+--------------+----------------+--------------------------------------
| id | name             | dependencies | profiling data | operator info                       |
-----+------------------+--------------+----------------+--------------------------------------
|  3 | Project          | 2            |                | outputVar: [                        |
|    |                  |              |                |   {                                 |
|    |                  |              |                |     "colNames": [                   |
|    |                  |              |                |       "VertexID"                    |
|    |                  |              |                |     ],                              |
|    |                  |              |                |     "name": "__Project_3",          |
|    |                  |              |                |     "type": "DATASET"               |
|    |                  |              |                |   }                                 |
|    |                  |              |                | ]                                   |
|    |                  |              |                | inputVar: __Filter_2                |
|    |                  |              |                | columns: [                          |
|    |                  |              |                |   "$-.VertexID AS VertexID"         |
|    |                  |              |                | ]                                   |
-----+------------------+--------------+----------------+--------------------------------------
|  2 | Filter           | 4            |                | outputVar: [                        |
|    |                  |              |                |   {                                 |
|    |                  |              |                |     "colNames": [                   |
|    |                  |              |                |       "VertexID",                   |
|    |                  |              |                |       "player.name"                 |
|    |                  |              |                |     ],                              |
|    |                  |              |                |     "type": "DATASET",              |
|    |                  |              |                |     "name": "__Filter_2"            |
|    |                  |              |                |   }                                 |
|    |                  |              |                | ]                                   |
|    |                  |              |                | inputVar: __TagIndexFullScan_1      |
|    |                  |              |                | condition: (player.name=="tim")     |
|    |                  |              |                | isStable: false                     |
-----+------------------+--------------+----------------+--------------------------------------
|  4 | TagIndexFullScan | 0            |                | outputVar: [                        |
|    |                  |              |                |   {                                 |
|    |                  |              |                |     "colNames": [                   |
|    |                  |              |                |       "VertexID",                   |
|    |                  |              |                |       "player.name"                 |
|    |                  |              |                |     ],                              |
|    |                  |              |                |     "name": "__TagIndexFullScan_1", |
|    |                  |              |                |     "type": "DATASET"               |
|    |                  |              |                |   }                                 |
|    |                  |              |                | ]                                   |
|    |                  |              |                | inputVar:                           |
|    |                  |              |                | space: 5600                         |
|    |                  |              |                | dedup: false                        |
|    |                  |              |                | limit: 9223372036854775807          |
|    |                  |              |                | filter:                             |
|    |                  |              |                | orderBy: []                         |
|    |                  |              |                | schemaId: 5601                      |
|    |                  |              |                | isEdge: false                       |
|    |                  |              |                | returnCols: [                       |
|    |                  |              |                |   "_vid",                           |
|    |                  |              |                |   "name"                            |
|    |                  |              |                | ]                                   |
|    |                  |              |                | indexCtx: [                         |
|    |                  |              |                |   {                                 |
|    |                  |              |                |     "columnHints": [],              |
|    |                  |              |                |     "index_id": 5602,               |
|    |                  |              |                |     "filter": ""                    |
|    |                  |              |                |   }                                 |
|    |                  |              |                | ]                                   |
-----+------------------+--------------+----------------+--------------------------------------
|  0 | Start            |              |                | outputVar: [                        |
|    |                  |              |                |   {                                 |
|    |                  |              |                |     "colNames": [],                 |
|    |                  |              |                |     "type": "DATASET",              |
|    |                  |              |                |     "name": "__Start_0"             |
|    |                  |              |                |   }                                 |
|    |                  |              |                | ]                                   |
-----+------------------+--------------+----------------+--------------------------------------

@yixinglu yixinglu merged commit 1dc1749 into vesoft-inc:master Jul 28, 2021
@yixinglu yixinglu deleted the fix-no-index branch July 28, 2021 05:30
CPWstatic pushed a commit to CPWstatic/nebula-graph that referenced this pull request Aug 2, 2021
* Check whether index is valid at runtime

* Fix failed ut

* Fix steps

* drop the used space

* Format
CPWstatic added a commit that referenced this pull request Aug 3, 2021
* Fix the go return bad_type when the vertex without the tag (#1273)

Co-authored-by: Yee <2520865+yixinglu@users.noreply.github.com>

* fix util functions (#1277)

small delete

* Check whether index is valid at runtime (#1291)

* Check whether index is valid at runtime

* Fix failed ut

* Fix steps

* drop the used space

* Format

* Replace the lastUser by user count.… (#1243)

* Replace the lastUser by user count.The last user maybe could run simultaneously, so can't determine which is real last user in timeline.

* Fix the typo.

Co-authored-by: Yee <2520865+yixinglu@users.noreply.github.com>

* fix first plan node input var (#1298)

Co-authored-by: laura-ding <48548375+laura-ding@users.noreply.github.com>
Co-authored-by: Yee <2520865+yixinglu@users.noreply.github.com>
Co-authored-by: kyle.cao <kyle.cao@vesoft.com>
Co-authored-by: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
ready-for-testing PR: ready for the CI test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants