Skip to content

Commit

Permalink
Sort order of cartesian product join children
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTF committed Feb 26, 2025
1 parent 8fe0642 commit 7f8f88c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/engine/QueryPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,9 @@ vector<vector<QueryPlanner::SubtreePlan>> QueryPlanner::fillDpTab(
textLimitIds |= plan.idsOfIncludedTextLimits_;
subtrees.push_back(std::move(plan._qet));
});
// Ensure estimated largest tree is on the right side.
ql::ranges::sort(subtrees, {},
[](const auto& tree) { return tree->getSizeEstimate(); });
result.at(0).push_back(
makeSubtreePlan<CartesianProductJoin>(_qec, std::move(subtrees)));
auto& plan = result.at(0).back();
Expand Down
29 changes: 29 additions & 0 deletions test/QueryPlannerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2981,3 +2981,32 @@ TEST(QueryPlanner, Exists) {
"GRAPH ?g { ?u ?v ?c}}}",
filter);
}

// _____________________________________________________________________________
TEST(QueryPlanner, CartesianProductJoinChildrenAreOrdered) {
auto qp = makeQueryPlanner();
{
auto query =
SparqlParser::parseQuery("SELECT * { VALUES ?x {1} VALUES ?y {2 3} }");
auto qet = qp.createExecutionTree(query);
EXPECT_TRUE(std::dynamic_pointer_cast<CartesianProductJoin>(
qet.getRootOperation()));
ASSERT_EQ(qet.getRootOperation()->getChildren().size(), 2);
EXPECT_EQ(qet.getRootOperation()->getChildren().at(0)->getCacheKey(),
"VALUES (?x) { (1) }");
EXPECT_EQ(qet.getRootOperation()->getChildren().at(1)->getCacheKey(),
"VALUES (?y) { (2) (3) }");
}
{
auto query =
SparqlParser::parseQuery("SELECT * { VALUES ?y {2 3} VALUES ?x {1} }");
auto qet = qp.createExecutionTree(query);
EXPECT_TRUE(std::dynamic_pointer_cast<CartesianProductJoin>(
qet.getRootOperation()));
ASSERT_EQ(qet.getRootOperation()->getChildren().size(), 2);
EXPECT_EQ(qet.getRootOperation()->getChildren().at(0)->getCacheKey(),
"VALUES (?x) { (1) }");
EXPECT_EQ(qet.getRootOperation()->getChildren().at(1)->getCacheKey(),
"VALUES (?y) { (2) (3) }");
}
}

0 comments on commit 7f8f88c

Please sign in to comment.