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

Also account for the filters when counting the subgraphs. #1705

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 22 additions & 2 deletions src/engine/QueryPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,13 +1338,33 @@ QueryPlanner::runDynamicProgrammingOnConnectedComponent(

// _____________________________________________________________________________
size_t QueryPlanner::countSubgraphs(
std::vector<const QueryPlanner::SubtreePlan*> graph, size_t budget) {
std::vector<const QueryPlanner::SubtreePlan*> graph,
const std::vector<SparqlFilter>& filters, size_t budget) {
// Remove duplicate plans from `graph`.
auto getId = [](const SubtreePlan* v) { return v->_idsOfIncludedNodes; };
ql::ranges::sort(graph, ql::ranges::less{}, getId);
graph.erase(std::ranges::unique(graph, ql::ranges::equal_to{}, getId).begin(),
graph.end());

// We also have to consider the `filters`. To make life easy, we temporarily
// create simple `SubtreePlans` for them which just have the correct
// variables.
std::vector<QueryPlanner::SubtreePlan> dummyPlansForFilter;
for (const auto& filter : filters) {
const auto& vars = filter.expression_.containedVariables();
// We use a `VALUES` clause as the dummy because this operation is the
// easiest to setup for a number of given variables.
parsedQuery::SparqlValues values;
for (auto* var : vars) {
values._variables.push_back(*var);
}
dummyPlansForFilter.push_back(
makeSubtreePlan<Values>(_qec, std::move(values)));
}
for (const auto& filterPlan : dummyPlansForFilter) {
graph.push_back(&filterPlan);
}

// Qlever currently limits the number of triples etc. per group to be <= 64
// anyway, so we can simply assert here.
AD_CORRECTNESS_CHECK(graph.size() <= 64,
Expand Down Expand Up @@ -1424,7 +1444,7 @@ vector<vector<QueryPlanner::SubtreePlan>> QueryPlanner::fillDpTab(
g.push_back(&plan);
}
const size_t budget = RuntimeParameters().get<"query-planning-budget">();
bool useGreedyPlanning = countSubgraphs(g, budget) > budget;
bool useGreedyPlanning = countSubgraphs(g, filters, budget) > budget;
if (useGreedyPlanning) {
LOG(INFO)
<< "Using the greedy query planner for a large connected component"
Expand Down
7 changes: 5 additions & 2 deletions src/engine/QueryPlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,11 @@ class QueryPlanner {
// if the number of subgraphs is `> budget`. This is used to analyze the
// complexity of the query graph and to choose between the DP and the greedy
// query planner see above.
static size_t countSubgraphs(std::vector<const SubtreePlan*> graph,
size_t budget);
// Note: We also need the added filters, because they behave like additional
// graph nodes wrt the performance of the DP based query planner.
size_t countSubgraphs(std::vector<const SubtreePlan*> graph,
const std::vector<SparqlFilter>& filters,
size_t budget);

// Creates a SubtreePlan for the given text leaf node in the triple graph.
// While doing this the TextLimitMetaObjects are created and updated according
Expand Down
Loading