-
Notifications
You must be signed in to change notification settings - Fork 202
Allow reordering of joins in Planner::planRegularMatch
#4625
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
Draft
royi-luo
wants to merge
2
commits into
master
Choose a base branch
from
royi/more-plan-improvements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
add_kuzu_test(planner_tests cardinality_test.cpp) | ||
add_kuzu_test(planner_tests | ||
cardinality_test.cpp | ||
planner_test.cpp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "graph_test/graph_test.h" | ||
#include "planner/operator/logical_plan_util.h" | ||
#include "test_runner/test_runner.h" | ||
|
||
namespace kuzu { | ||
namespace testing { | ||
|
||
class PlannerTest : public DBTest { | ||
public: | ||
std::string getInputDir() override { | ||
return TestHelper::appendKuzuRootPath("dataset/tinysnb/"); | ||
} | ||
|
||
std::string getEncodedPlan(const std::string& query) { | ||
return planner::LogicalPlanUtil::encodeJoin(*getRoot(query)); | ||
} | ||
std::unique_ptr<planner::LogicalPlan> getRoot(const std::string& query) { | ||
return TestRunner::getLogicalPlan(query, *conn); | ||
} | ||
std::pair<planner::LogicalOperator*, planner::LogicalOperator*> getSource( | ||
planner::LogicalOperator* op, planner::LogicalOperator* parent = nullptr) { | ||
if (op->getNumChildren() == 0) { | ||
return {parent, op}; | ||
} | ||
return getSource(op->getChild(0).get(), op); | ||
} | ||
planner::LogicalOperator* getOpWithType(planner::LogicalOperator* op, | ||
planner::LogicalOperatorType type) { | ||
if (op->getOperatorType() == type) { | ||
return op; | ||
} | ||
if (op->getNumChildren() == 0) { | ||
return nullptr; | ||
} | ||
return getOpWithType(op->getChild(0).get(), type); | ||
} | ||
}; | ||
|
||
TEST_F(PlannerTest, TestSubqueryJoinOrder) { | ||
// Cross Product | ||
{ | ||
// We should pick the smaller table to be on the build side | ||
auto query = "MATCH (a:person) WITH a MATCH (b:organisation) RETURN *"; | ||
EXPECT_STREQ("CP(){S(a)}{S(b)}", getEncodedPlan(query).c_str()); | ||
auto queryFlipped = "MATCH (b:organisation) WITH b MATCH (a:person) RETURN *"; | ||
EXPECT_STREQ("CP(){S(a)}{S(b)}", getEncodedPlan(queryFlipped).c_str()); | ||
} | ||
|
||
// Hash Join | ||
{ | ||
// cardinality(person) > cardinality(studyAt) | ||
// scan(person) should go on probe side | ||
auto query = "MATCH (a:person) WITH a MATCH (a)-[s:studyAt]->(b:organisation) RETURN *"; | ||
EXPECT_STREQ("HJ(a._ID){S(a)}{HJ(b._ID){S(b)}{E(b)S(a)}}", getEncodedPlan(query).c_str()); | ||
|
||
// cardinality(organisation) < cardinality(studyAt) + cardinality(workAt) | ||
// scan(organisation) should go on build side | ||
auto queryFlipped = | ||
"MATCH (b:organisation) WITH b MATCH (a:person)-[s:studyAt|:workAt]->(b) RETURN *"; | ||
EXPECT_STREQ("HJ(b._ID){E(b)S(a)}{S(b)}", getEncodedPlan(queryFlipped).c_str()); | ||
} | ||
} | ||
|
||
} // namespace testing | ||
} // namespace kuzu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
-DATASET CSV lsqb-sf01 | ||
-BUFFER_POOL_SIZE 1073741824 | ||
-BUFFER_POOL_SIZE 4294967296 | ||
|
||
-- | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For q3 we overestimate the cardinality of the cycle query
MATCH (person1)-[:Person_knows_Person]-(person2)-[:Person_knows_Person]-(person3)-[:Person_knows_Person]-(person1)
so when we join it with the remaining part of the query we reorder the cycle query to be on the probe side. So q3 runs quite a bit slower and goes over the old buffer pool limit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plan (the problematic join is the outer/leftmost one):