Skip to content

Commit

Permalink
Also account for the filters when counting the subgraphs.
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Kalmbach <johannes.kalmbach@gmail.com>
  • Loading branch information
joka921 committed Jan 9, 2025
1 parent acb6633 commit f29efc6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
23 changes: 20 additions & 3 deletions src/engine/QueryPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,13 +1338,28 @@ 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());

std::vector<QueryPlanner::SubtreePlan> dummyPlansForFilter;
for (const auto& filter : filters) {
const auto& vars = filter.expression_.containedVariables();
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 All @@ -1366,7 +1381,9 @@ size_t QueryPlanner::countSubgraphs(
g.push_back(v);
}

return countConnectedSubgraphs::countSubgraphs(g, budget);
auto result = countConnectedSubgraphs::countSubgraphs(g, budget);
LOG(INFO) << "number of subgraphs inside a component " << result << std::endl;
return result;
}

// _____________________________________________________________________________
Expand Down Expand Up @@ -1424,7 +1441,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
5 changes: 3 additions & 2 deletions src/engine/QueryPlanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,9 @@ 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);
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

0 comments on commit f29efc6

Please sign in to comment.