Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
a52ef9c
some experiments
ullingerc Jan 12, 2026
ad50dbc
Allow writing materialized views from queries with less than four col…
ullingerc Jan 12, 2026
63973a9
logging
ullingerc Jan 12, 2026
fdcf7b3
docs
ullingerc Jan 12, 2026
8032b7f
test logging
ullingerc Jan 12, 2026
9435955
stuff
ullingerc Jan 12, 2026
a29a3a1
apply Johannes' feedback
ullingerc Jan 13, 2026
726a957
Merge https://github.com/ad-freiburg/qlever into matview-fewer-cols
ullingerc Jan 13, 2026
addf9c6
remove obsolete comment
ullingerc Jan 13, 2026
8e035f9
Merge https://github.com/ad-freiburg/qlever into matview-detect-join
ullingerc Jan 13, 2026
11ed04f
Merge branch 'matview-fewer-cols' into matview-detect-join
ullingerc Jan 13, 2026
1a75011
write join pattern
ullingerc Jan 13, 2026
adbb5db
more experiments
ullingerc Jan 14, 2026
d5c6b7e
Merge https://github.com/ad-freiburg/qlever into matview-detect-join
ullingerc Jan 19, 2026
b3ee508
first working draft
ullingerc Jan 19, 2026
7071e40
Fix build failure
RobinTF Jan 19, 2026
d0b40be
Merge remote-tracking branch 'RobinTF/fix-build-failure' into matview…
ullingerc Jan 19, 2026
e8956f3
comment
ullingerc Jan 19, 2026
e92b283
Merge https://github.com/ad-freiburg/qlever into matview-detect-join
ullingerc Jan 20, 2026
38d2aaf
add tests
ullingerc Jan 20, 2026
a73a174
make stuff more nice
ullingerc Jan 20, 2026
062e408
further clean up
ullingerc Jan 20, 2026
e71b605
fix spelling
ullingerc Jan 20, 2026
d4c2190
initialize to zero
ullingerc Jan 21, 2026
395630f
Merge https://github.com/ad-freiburg/qlever into matview-fewer-cols
ullingerc Jan 21, 2026
3dd5f87
Save original query string when writing a materialized view
ullingerc Jan 21, 2026
e2483b3
Merge branch 'matview-fewer-cols' into matview-detect-join
ullingerc Jan 21, 2026
8af75f3
Merge branch 'matview-save-query' into matview-detect-join
ullingerc Jan 21, 2026
e4c1bde
apply Johannes' feedback
ullingerc Jan 21, 2026
d02157e
Merge branch 'matview-save-query' into matview-detect-join
ullingerc Jan 21, 2026
7db97a5
optional query string
ullingerc Jan 21, 2026
76392f2
Merge https://github.com/ad-freiburg/qlever into matview-detect-join
ullingerc Jan 22, 2026
f48eb71
small improvements
ullingerc Jan 22, 2026
712e808
remove old
ullingerc Jan 22, 2026
d143325
warn unbound vars
ullingerc Jan 22, 2026
9795dea
Merge https://github.com/ad-freiburg/qlever into matview-detect-join
ullingerc Jan 26, 2026
48110cd
lots of work for refactoring the query planning part
ullingerc Jan 27, 2026
7798db8
bug fix
ullingerc Jan 27, 2026
a2f9c3f
improvements + clean up
ullingerc Jan 27, 2026
babaa7b
more work
ullingerc Jan 27, 2026
3ee6103
lots of stuff
ullingerc Jan 27, 2026
1e3271f
fix some comments
ullingerc Jan 27, 2026
f05db5b
apply some feedback
ullingerc Jan 28, 2026
ffb7e11
clean up
ullingerc Jan 28, 2026
b2242db
Merge https://github.com/ad-freiburg/qlever into matview-detect-join
ullingerc Jan 29, 2026
7a23840
notes and improvements
ullingerc Jan 29, 2026
ddfce01
Modularize and fix greedy planning
ullingerc Jan 29, 2026
94b6c73
remove redundant
ullingerc Jan 29, 2026
cc39f61
use erase_if backport
ullingerc Jan 29, 2026
37e6012
comment
ullingerc Jan 29, 2026
59d6ce9
Test property path getters
ullingerc Jan 29, 2026
a2a7fe9
runtime toggle for query rewriting
ullingerc Jan 30, 2026
e9e21e8
Merge https://github.com/ad-freiburg/qlever into matview-detect-join
ullingerc Jan 30, 2026
37cb1a9
apply Johannes' feedback for BasicGraphPatternsInvariantTo
ullingerc Jan 30, 2026
c208ff2
some clean up
ullingerc Jan 30, 2026
3419447
explain ignore
ullingerc Jan 30, 2026
c914c1c
fix ambigious symbol
ullingerc Jan 30, 2026
454a379
fix
ullingerc Jan 30, 2026
f9eeeaa
merge fix test
ullingerc Jan 30, 2026
ea3b1b0
next try
ullingerc Jan 30, 2026
6319d50
extend tests to greedy
ullingerc Jan 30, 2026
fae24b5
todo
ullingerc Jan 30, 2026
4a74165
improve test
ullingerc Jan 30, 2026
98eab72
checkout util changes from other branch
ullingerc Feb 2, 2026
a48823e
Merge https://github.com/ad-freiburg/qlever into matview-detect-join
ullingerc Feb 2, 2026
6933abc
Merge branch 'matview-rewrite-prep' into matview-detect-join
ullingerc Feb 2, 2026
04d0143
apply Johannes' feedback
ullingerc Feb 2, 2026
5907cbe
Merge branch 'matview-rewrite-prep' into matview-detect-join
ullingerc Feb 2, 2026
5b2593d
merge after care
ullingerc Feb 2, 2026
85eb90a
add todo
ullingerc Feb 2, 2026
76509c7
add todo
ullingerc Feb 2, 2026
e8ff99e
try to fix compiler error
ullingerc Feb 2, 2026
818b411
Merge branch 'matview-rewrite-prep' into matview-detect-join
ullingerc Feb 2, 2026
7774adf
move code to cpp
ullingerc Feb 2, 2026
44e4f89
move code to cpp
ullingerc Feb 2, 2026
7d0fc41
add a test for string pair hash map
ullingerc Feb 2, 2026
2d34cfc
make codespell happy
ullingerc Feb 2, 2026
a2ea70b
Improve test coverage
ullingerc Feb 3, 2026
cd263f4
fix includes
ullingerc Feb 3, 2026
41b733c
another test
ullingerc Feb 3, 2026
af74163
part of comment got lost
ullingerc Feb 3, 2026
37ab08d
Merge branch 'matview-rewrite-prep' into matview-detect-join
ullingerc Feb 3, 2026
95d0256
fix linker
ullingerc Feb 3, 2026
6a8f219
Merge branch 'matview-rewrite-prep' into matview-detect-join
ullingerc Feb 3, 2026
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
5 changes: 5 additions & 0 deletions src/ServerMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ int main(int argc, char** argv) {
->multitoken(),
"The names of materialized views to be loaded automatically on server "
"start (this option takes an arbitrary number of arguments).");
add("enable-materialized-view-query-rewrite",
optionFactory.getProgramOption<
&RuntimeParameters::enableMaterializedViewQueryRewrite_>(),
"If set to true, loaded materialized views will be considered as "
"alternative query plans for certain supported query patterns.");
po::variables_map optionsMap;

try {
Expand Down
3 changes: 2 additions & 1 deletion src/engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ add_library(engine
QueryExecutionContext.cpp ExistsJoin.cpp SparqlProtocol.cpp ParsedRequestBuilder.cpp
NeutralOptional.cpp Load.cpp StripColumns.cpp NamedResultCache.cpp
ExplicitIdTableOperation.cpp StringMapping.cpp MaterializedViews.cpp
PermutationSelector.cpp ConstructQueryEvaluator.cpp ConstructTripleGenerator.cpp)
PermutationSelector.cpp ConstructQueryEvaluator.cpp ConstructTripleGenerator.cpp
MaterializedViewsQueryAnalysis.cpp)

qlever_target_link_libraries(engine util index parser global sparqlExpressions SortPerformanceEstimator Boost::iostreams s2 spatialjoin-dev pb_util pb_util_geo)

Expand Down
29 changes: 26 additions & 3 deletions src/engine/MaterializedViews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <stdexcept>

#include "engine/IndexScan.h"
#include "engine/Join.h"
#include "engine/MaterializedViewsQueryAnalysis.h"
#include "engine/QueryExecutionContext.h"
#include "engine/QueryExecutionTree.h"
#include "engine/VariableToColumnMap.h"
Expand Down Expand Up @@ -92,7 +94,9 @@ MaterializedViewWriter::getIdTableColumnNamesAndPermutation() const {
// Column information for the columns selected by the user's query.
auto existingCols = ::ranges::to<std::vector<ColumnNameAndIndex>>(
targetVarsAndCols | ql::views::transform([](const auto& opt) {
AD_CONTRACT_CHECK(opt.has_value());
AD_CONTRACT_CHECK(
opt.has_value(),
"Please ensure that all variables in your SELECT are bound.");
return ColumnNameAndIndex{opt.value().variable_,
opt.value().columnIndex_};
}));
Expand Down Expand Up @@ -375,17 +379,27 @@ std::shared_ptr<const Permutation> MaterializedView::permutation() const {
// _____________________________________________________________________________
void MaterializedViewsManager::loadView(const std::string& name) const {
auto lock = loadedViews_.wlock();
auto patternLock = queryPatternCache_.wlock();
if (lock->contains(name)) {
return;
}
lock->insert({name, std::make_shared<MaterializedView>(onDiskBase_, name)});
};
auto view = std::make_shared<MaterializedView>(onDiskBase_, name);
lock->insert({name, view});
// Analyzing the view when loading instead of (de)serializing an analysis
// result has the benefit that query analysis can be extended without needing
// to rewrite views.
if (patternLock->analyzeView(view)) {
AD_LOG_INFO << "The materialized view '" << name
<< "' was added to the query pattern cache." << std::endl;
}
}

// _____________________________________________________________________________
void MaterializedViewsManager::unloadViewIfLoaded(
const std::string& name) const {
// `HashMap::erase` is a no-op for nonexisting keys.
loadedViews_.wlock()->erase(name);
// TODO<ullingerc> Query pattern cache unload.
}

// _____________________________________________________________________________
Expand Down Expand Up @@ -597,6 +611,15 @@ std::shared_ptr<IndexScan> MaterializedView::makeIndexScan(
viewQuery.getVarsToKeep());
}

// _____________________________________________________________________________
std::vector<MaterializedViewJoinReplacement>
MaterializedViewsManager::makeJoinReplacementIndexScans(
QueryExecutionContext* qec,
const parsedQuery::BasicGraphPattern& triples) const {
return queryPatternCache_.rlock()->makeJoinReplacementIndexScans(qec,
triples);
}

// _____________________________________________________________________________
std::shared_ptr<IndexScan> MaterializedViewsManager::makeIndexScan(
QueryExecutionContext* qec,
Expand Down
17 changes: 17 additions & 0 deletions src/engine/MaterializedViews.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
#ifndef QLEVER_SRC_ENGINE_MATERIALIZEDVIEWS_H_
#define QLEVER_SRC_ENGINE_MATERIALIZEDVIEWS_H_

#include "engine/MaterializedViewsQueryAnalysis.h"
#include "engine/VariableToColumnMap.h"
#include "engine/idTable/CompressedExternalIdTable.h"
#include "index/DeltaTriples.h"
#include "index/ExternalSortFunctors.h"
#include "index/Permutation.h"
#include "libqlever/QleverTypes.h"
#include "parser/GraphPatternOperation.h"
#include "parser/MaterializedViewQuery.h"
#include "parser/ParsedQuery.h"
#include "parser/SparqlTriple.h"
#include "util/HashMap.h"
#include "util/Synchronized.h"

// Forward declarations
class QueryExecutionContext;
Expand Down Expand Up @@ -223,6 +226,9 @@ class MaterializedView {
const parsedQuery::MaterializedViewQuery& viewQuery) const;
};

// Shorthand for query rewriting helper class.
using materializedViewsQueryAnalysis::MaterializedViewJoinReplacement;

// The `MaterializedViewsManager` is part of the `QueryExecutionContext` and is
// used to manage the currently loaded `MaterializedViews` in a `Server` or
// `Qlever` instance.
Expand All @@ -232,6 +238,9 @@ class MaterializedViewsManager {
mutable ad_utility::Synchronized<
ad_utility::HashMap<std::string, std::shared_ptr<MaterializedView>>>
loadedViews_;
mutable ad_utility::Synchronized<
materializedViewsQueryAnalysis::QueryPatternCache>
queryPatternCache_;

public:
MaterializedViewsManager() = default;
Expand Down Expand Up @@ -266,6 +275,14 @@ class MaterializedViewsManager {
QueryExecutionContext* qec,
const parsedQuery::MaterializedViewQuery& viewQuery) const;

// Given a set of triples, check if some join operations that would be
// required when evaluating them can be replaced by scans on materialized
// views that are currently loaded. This is implemented using the
// `queryPatternCache_`.
std::vector<MaterializedViewJoinReplacement> makeJoinReplacementIndexScans(
QueryExecutionContext* qec,
const parsedQuery::BasicGraphPattern& triples) const;

// Write a `MaterializedView` given a valid `name` (consisting only of
// alphanumerics and hyphens) and a `queryPlan` to be executed. The query's
// result is written to the view.
Expand Down
Loading
Loading