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

Don't use the exact size from the cache for query planning #1736

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
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: 5 additions & 9 deletions src/engine/QueryExecutionTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,11 @@ size_t QueryExecutionTree::getCostEstimate() {
// _____________________________________________________________________________
size_t QueryExecutionTree::getSizeEstimate() {
if (!sizeEstimate_.has_value()) {
if (cachedResult_) {
AD_CORRECTNESS_CHECK(cachedResult_->isFullyMaterialized());
sizeEstimate_ = cachedResult_->idTable().size();
} else {
// if we are in a unit test setting and there is no QueryExecutionContest
// specified it is the rootOperation_'s obligation to handle this case
// correctly
sizeEstimate_ = rootOperation_->getSizeEstimate();
}
// Note: Previously we used the exact size instead of the estimate for
// results that were already in the cache. This however often lead to poor
// planning, because the query planner compared exact sizes with estimates,
// which lead to worse plans than just conistently choosing the estimate.
sizeEstimate_ = rootOperation_->getSizeEstimate();
}
return sizeEstimate_.value();
}
Expand Down
6 changes: 3 additions & 3 deletions test/OperationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,12 @@ TEST(OperationTest, estimatesForCachedResults) {
[[maybe_unused]] auto res = qet->getResult();
}
// The result is now cached inside the static execution context, if we create
// the same operation again, the cost estimate is 0 and the size estimate is
// exact (3 rows).
// the same operation again, the cost estimate is 0. The size estimate doesn't
// change (see the `getCostEstimate` function for details on why).
{
auto qet = makeQet();
EXPECT_EQ(qet->getCacheKey(), qet->getRootOperation()->getCacheKey());
EXPECT_EQ(qet->getSizeEstimate(), 3u);
EXPECT_EQ(qet->getSizeEstimate(), 24u);
EXPECT_EQ(qet->getCostEstimate(), 0u);
}
}
Expand Down
Loading