Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the lookup limit result. #3171

Merged
merged 4 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 6 additions & 8 deletions src/graph/planner/ngql/LookupPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ StatusOr<SubPlan> LookupPlanner::transform(AstContext* astCtx) {
lookupCtx->idxReturnCols,
lookupCtx->schemaId,
lookupCtx->isEmptyResultSet);
if (lookupCtx->limit >= 0) {
edgeIndexFullScan->setLimit(lookupCtx->limit);
}
plan.tail = edgeIndexFullScan;
plan.root = edgeIndexFullScan;
} else {
auto* tagIndexFullScan = TagIndexFullScan::make(qctx,
nullptr,
Expand All @@ -51,19 +49,19 @@ StatusOr<SubPlan> LookupPlanner::transform(AstContext* astCtx) {
lookupCtx->idxReturnCols,
lookupCtx->schemaId,
lookupCtx->isEmptyResultSet);
if (lookupCtx->limit >= 0) {
tagIndexFullScan->setLimit(lookupCtx->limit);
}
plan.tail = tagIndexFullScan;
plan.root = tagIndexFullScan;
}
plan.tail->setColNames(lookupCtx->idxColNames);

plan.root = plan.tail;

if (lookupCtx->filter) {
plan.root = Filter::make(qctx, plan.root, lookupCtx->filter);
}

if (lookupCtx->limit >= 0) {
plan.root = Limit::make(qctx, plan.root, 0, lookupCtx->limit);
}

plan.root = Project::make(qctx, plan.root, lookupCtx->yieldExpr);
return plan;
}
Expand Down
1 change: 1 addition & 0 deletions src/graph/validator/BalanceValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include "graph/validator/BalanceValidator.h"

#include "graph/planner/plan/Admin.h"

namespace nebula {
Expand Down
1 change: 1 addition & 0 deletions src/graph/validator/IngestValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include "graph/validator/IngestValidator.h"

#include "graph/planner/plan/Admin.h"

namespace nebula {
Expand Down
85 changes: 29 additions & 56 deletions tests/tck/features/lookup/LookUpLimit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,92 +16,61 @@ Feature: Push Limit down IndexScan Rule
| VertexID |
| "Amar'e Stoudemire" |
| "Aron Baynes" |
| "Ben Simmons" |
| "Blake Griffin" |
| "Boris Diaw" |
| "Carmelo Anthony" |
| "Chris Paul" |
| "Cory Joseph" |
| "Damian Lillard" |
| "DeAndre Jordan" |
| "Dwyane Wade" |
| "JaVale McGee" |
| "Klay Thompson" |
| "Luka Doncic" |
And the execution plan should be:
| id | name | dependencies | operator info |
| 4 | DataCollect | 5 | |
| 5 | Sort | 6 | |
| 6 | Project | 7 | |
| 7 | TagIndexFullScan | 0 | {"limit": "2"} |
| 7 | Limit | 8 | {"count": "2"} |
| 8 | TagIndexFullScan | 0 | {"limit": "2"} |
| 0 | Start | | |
When profiling query:
"""
LOOKUP ON like Limit 2 | ORDER BY $-.SrcVID
"""
Then the result should be, in any order:
| SrcVID | DstVID | Ranking |
| "Ben Simmons" | "Joel Embiid" | 0 |
| "Blake Griffin" | "Chris Paul" | 0 |
| "Damian Lillard" | "LaMarcus Aldridge" | 0 |
| "Dirk Nowitzki" | "Dwyane Wade" | 0 |
| "Jason Kidd" | "Vince Carter" | 0 |
| "Klay Thompson" | "Stephen Curry" | 0 |
| "Kyrie Irving" | "LeBron James" | 0 |
| "LaMarcus Aldridge" | "Tim Duncan" | 0 |
| "LaMarcus Aldridge" | "Tony Parker" | 0 |
| "Marco Belinelli" | "Tim Duncan" | 0 |
| "Marco Belinelli" | "Tony Parker" | 0 |
| "Rajon Rondo" | "Ray Allen" | 0 |
| "Ray Allen" | "Rajon Rondo" | 0 |
| "Rudy Gay" | "LaMarcus Aldridge" | 0 |
| SrcVID | DstVID | Ranking |
| "Ben Simmons" | "Joel Embiid" | 0 |
| "Blake Griffin" | "Chris Paul" | 0 |
Shylock-Hg marked this conversation as resolved.
Show resolved Hide resolved
And the execution plan should be:
| id | name | dependencies | operator info |
| 4 | DataCollect | 5 | |
| 5 | Sort | 6 | |
| 6 | Project | 7 | |
| 7 | EdgeIndexFullScan | 0 | {"limit": "2"} |
| 7 | Limit | 8 | {"count": "2"} |
| 8 | EdgeIndexFullScan | 0 | {"limit": "2"} |
| 0 | Start | | |
When profiling query:
"""
LOOKUP ON player WHERE player.age == 33 Limit 2 | ORDER BY $-.VertexID
"""
Then the result should be, in any order:
| VertexID |
| "Chris Paul" |
| "Dwight Howard" |
| "LaMarcus Aldridge" |
| "Rajon Rondo" |
| VertexID |
| "Chris Paul" |
| "Dwight Howard" |
And the execution plan should be:
| id | name | dependencies | operator info |
| 4 | DataCollect | 5 | |
| 5 | Sort | 6 | |
| 6 | Project | 7 | |
| 7 | TagIndexPrefixScan | 0 | {"limit": "2"} |
| 7 | Limit | 8 | {"count": "2"} |
| 8 | TagIndexPrefixScan | 0 | {"limit": "2"} |
| 0 | Start | | |
When profiling query:
"""
LOOKUP ON like WHERE like.likeness == 90 Limit 2 | ORDER BY $-.SrcVID
"""
Then the result should be, in any order:
| SrcVID | DstVID | Ranking |
| "Amar'e Stoudemire" | "Steve Nash" | 0 |
| "Carmelo Anthony" | "Chris Paul" | 0 |
| "Chris Paul" | "Carmelo Anthony" | 0 |
| "Chris Paul" | "Dwyane Wade" | 0 |
| "Dwyane Wade" | "Carmelo Anthony" | 0 |
| "Dwyane Wade" | "Chris Paul" | 0 |
| "Jason Kidd" | "Steve Nash" | 0 |
| "Klay Thompson" | "Stephen Curry" | 0 |
| "Luka Doncic" | "Dirk Nowitzki" | 0 |
| "Luka Doncic" | "Kristaps Porzingis" | 0 |
| "Paul Gasol" | "Kobe Bryant" | 0 |
| SrcVID | DstVID | Ranking |
| "Amar'e Stoudemire" | "Steve Nash" | 0 |
| "Carmelo Anthony" | "Chris Paul" | 0 |
And the execution plan should be:
| id | name | dependencies | operator info |
| 4 | DataCollect | 5 | |
| 5 | Sort | 6 | |
| 6 | Project | 7 | |
| 7 | EdgeIndexPrefixScan | 0 | {"limit": "2"} |
| 7 | Limit | 8 | {"count": "2"} |
| 8 | EdgeIndexPrefixScan | 0 | {"limit": "2"} |
| 0 | Start | | |

Scenario: push limit down to IndexScan with limit
Expand All @@ -120,8 +89,9 @@ Feature: Push Limit down IndexScan Rule
| 4 | Sort | 5 | |
| 5 | Project | 6 | |
| 6 | Limit | 7 | |
| 7 | TagIndexFullScan | 8 | {"limit": "3"} |
| 8 | Start | | |
| 7 | Limit | 8 | |
| 8 | TagIndexFullScan | 9 | {"limit": "3"} |
| 9 | Start | | |
When profiling query:
"""
LOOKUP ON like Limit 3 | LIMIT 3 | ORDER BY $-.SrcVID
Expand All @@ -137,8 +107,9 @@ Feature: Push Limit down IndexScan Rule
| 4 | Sort | 5 | |
| 5 | Project | 6 | |
| 6 | Limit | 7 | |
| 7 | EdgeIndexFullScan | 8 | {"limit": "3"} |
| 8 | Start | | |
| 7 | Limit | 8 | |
| 8 | EdgeIndexFullScan | 9 | {"limit": "3"} |
| 9 | Start | | |
When profiling query:
"""
LOOKUP ON player WHERE player.age == 33 Limit 3 | LIMIT 3 | ORDER BY $-.VertexID
Shylock-Hg marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -154,8 +125,9 @@ Feature: Push Limit down IndexScan Rule
| 4 | Sort | 5 | |
| 5 | Project | 6 | |
| 6 | Limit | 7 | |
| 7 | TagIndexPrefixScan | 8 | {"limit": "3"} |
| 8 | Start | | |
| 7 | Limit | 8 | |
| 8 | TagIndexPrefixScan | 9 | {"limit": "3"} |
| 9 | Start | | |
When profiling query:
"""
LOOKUP ON like WHERE like.likeness == 90 Limit 3 | LIMIT 3 | ORDER BY $-.SrcVID
Expand All @@ -171,5 +143,6 @@ Feature: Push Limit down IndexScan Rule
| 4 | Sort | 5 | |
| 5 | Project | 6 | |
| 6 | Limit | 7 | |
| 7 | EdgeIndexPrefixScan | 8 | {"limit": "3"} |
| 8 | Start | | |
| 7 | Limit | 8 | |
| 8 | EdgeIndexPrefixScan | 9 | {"limit": "3"} |
| 9 | Start | | |