Skip to content

Optimize binding of multiple columns in transitive paths#2844

Draft
schaetzr wants to merge 2 commits intoad-freiburg:masterfrom
schaetzr:bind_multicolumn
Draft

Optimize binding of multiple columns in transitive paths#2844
schaetzr wants to merge 2 commits intoad-freiburg:masterfrom
schaetzr:bind_multicolumn

Conversation

@schaetzr
Copy link
Copy Markdown
Contributor

@schaetzr schaetzr commented Apr 27, 2026

This PR aims to improve query planning for special queries where both sides of a triple are already bound (= are variables that have values already assigned to them). Currently, this would invoke a scan over the whole dataset and then execute a multi-column join instead of picking one column as start node and thereby vastly improving query runtime.

Example:

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT * WHERE {
  VALUES (?s ?o) {(wd:Q2 wd:Q1)} .
  ?s wdt:P361* ?o
}

... creates a multicolumn join, but it'd be better if it ran like:

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT * WHERE {
  VALUES (?s) {(wd:Q2)} .
  ?s wdt:P361* wd:Q1
}

which instead calls a transitive path operation in the query planer.

This PR is WIP and currently, nothing regarding this optimization is working as expected. Tests should also fail.

@schaetzr
Copy link
Copy Markdown
Contributor Author

In the first attempt, I tried to make the bindLeftOrRightSide function inside the TransitivePathBase accept a second column, however, I am currently running into the following error:

Assertion `!plan->variableColumns_.contains(variable)` failed. Please report this to the developers. In file "/bproj/qlever/src/engine/TransitivePathBase.cpp " at line 640

This happens on my toy example dataset:

<Q1> <P1> <Q2> .
<Q2> <P1> <Q3> .
<Q1> <P1> <Q1> .

with the query

SELECT * WHERE {
  VALUES (?s ?o) {(<Q1> <Q2>)} .
  ?s <P1>* ?o 
}

i am working on finding out what mistake I made and how to fix the error

@sparql-conformance
Copy link
Copy Markdown

Overview

Number of Tests Passed ✅ Intended ✅ Failed ❌ Not tested
548 445 73 30 0

Conformance check failed ❌

Test Status Changes 📊

Number of Tests Previous Status Current Status
2 Passed Failed

Details: https://qlever.dev/sparql-conformance-ui?cur=9f8f19f123717da6e7f5cc6e03a29a017318235d&prev=b2f2e101de954c81794a5c4167f9f404da689ff0

@sonarqubecloud
Copy link
Copy Markdown

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.

1 participant