Skip to content

Add utilities in preparation for materialized view query rewriting#2692

Open
ullingerc wants to merge 18 commits intoad-freiburg:masterfrom
ullingerc:matview-rewrite-prep
Open

Add utilities in preparation for materialized view query rewriting#2692
ullingerc wants to merge 18 commits intoad-freiburg:masterfrom
ullingerc:matview-rewrite-prep

Conversation

@ullingerc
Copy link
Member

@ullingerc ullingerc commented Feb 2, 2026

This change adds various utilities for the query rewriting infrastructure that will allow implicit use of materialized views.

Preparation for #2649

@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 98.27586% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.61%. Comparing base (f35a290) to head (78d40c3).

Files with missing lines Patch % Lines
src/parser/GraphPatternOperation.cpp 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2692   +/-   ##
=======================================
  Coverage   91.60%   91.61%           
=======================================
  Files         483      487    +4     
  Lines       41386    41448   +62     
  Branches     5496     5505    +9     
=======================================
+ Hits        37912    37971   +59     
+ Misses       1897     1895    -2     
- Partials     1577     1582    +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ullingerc ullingerc requested a review from joka921 February 3, 2026 13:34
Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much and sorry for the long wait.
Please ping me for the next round, it should be faster then.

Comment on lines 89 to 92
// Extract all variables present in a the first `BasicGraphPattern` contained in
// a vector of `GraphPatternOperation`s. It is used for skipping some graph
// patterns in `MaterializedViewQueryAnalysis.cpp`.
//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is a little ambigious:

  1. does this use the first basic pattern in the query, even if the pattern is not at the beginnning of the query (so first subquery, then BGP), or only "the first element if it is a parsed graph pattern". The comment says more the first, but as this is a function with strange uninituitive behavior, better be precise and verbose.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the first BGP (which can be the first but also a later pattern). I could have

BIND(42 AS ?x)
?a geo:hasGeometry ?b .
?b geo:asWKT ?c

then I would still get the geo:hasGeometry ... as a BGP here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change the comment, but maybe this function is so specific that it should be hidden in the place where we use it. Do you agree?

ad_utility::filterRangeOfVariantsByType<parsedQuery::BasicGraphPattern>(
graphPatterns);
if (!ql::ranges::empty(basicGraphPatterns)) {
(*basicGraphPatterns.begin()).collectAllContainedVariables(vars);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not bgp.begin()-> (the start is confusing to read )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clang complains that it can't find the method if i use -> here. That's the reason for (*).

Comment on lines +18 to +25
// interested in the bindings for variables from `variables_` as they do not
// affect the result for these `variables_`.
//
// For example: A basic graph pattern (a list of triples) is invariant to a
// `BIND` statement whose target variable is not contained in the basic graph
// pattern, because the `BIND` only adds its own column, but neither adds nor
// deletes result rows.
//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this statement actually true:

 ?x <is-a> ?y .
 BIND (somethingCompletelyElse as ?z) # seems invariant.
 FILTER (?x > ?y)  upps...

Or will you in this case consider filter the whole thing out, because you see the filter and EVERYTHING has to be invariant? in that case please comment this, that this is only true for one step.

But otherwise: The comment is now great to understand

Copy link
Member Author

@ullingerc ullingerc Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filter will be considered. So everything after the graph pattern in the beginning must be invariant. We use this visitor for filtering the graph patterns and if anything except for the original basic graph pattern is left after filtering, no optimization is detected anymore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But for this struct all of this doesn't matter. It handles one graph pattern at a time. So it will get the Bind and say I don't care about this, but then see the Filter and say 'oh we have a filter - I always care about filters'

ASSERT_EQ(map.size(), 2u);

// Lookup using `std::string_view` pairs.
auto it = map.find(StringViewPair{"hello", "world"});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I seeing correctly as this could never allocate, as StringViewPair is not convertible to StringPair? If yes, then this could be a static assertion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • something i forgot in the implementation:

For the same reason (if I am right), we cannot insert via the string_view_pair (because not even explicitly they are convertible, then this should be commented as part of the interface there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added asserts. Are those the ones you mean here - or could you elaborate otherwise?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The header is now very clear. With the static assert there is no need for runtime testing here that no allocations happened.

@ullingerc ullingerc requested a review from joka921 February 10, 2026 10:44
@sparql-conformance
Copy link

Overview

Number of Tests Passed ✅ Intended ✅ Failed ❌ Not tested
548 449 73 26 0

Conformance check passed ✅

Test Status Changes 📊

Number of Tests Previous Status Current Status
1 - Failed

Details: https://qlever.dev/sparql-conformance-ui?cur=78d40c32d8e09689ef8abb86bcc7d997d7720f67&prev=f35a290fc35e28fefdc9ac56139660fad14ab860

@sonarqubecloud
Copy link

Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much, the improvements now look clean. Write a good message, and forward this to @hannahbast

ASSERT_EQ(map.size(), 2u);

// Lookup using `std::string_view` pairs.
auto it = map.find(StringViewPair{"hello", "world"});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The header is now very clear. With the static assert there is no need for runtime testing here that no allocations happened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants