Skip to content

Query: Always use INNER join to establish the outer query link - #173

Draft
nilmerg wants to merge 1 commit into
fix/proper-reversal-of-relations-in-sub-queries-170from
always-use-inner-joins-for-sub-queries
Draft

Query: Always use INNER join to establish the outer query link#173
nilmerg wants to merge 1 commit into
fix/proper-reversal-of-relations-in-sub-queries-170from
always-use-inner-joins-for-sub-queries

Conversation

@nilmerg

@nilmerg nilmerg commented Aug 26, 2026

Copy link
Copy Markdown
Member

A subquery always needs to establish a link, be it part of a WHERE or solely used to eager load (using Query::derive) a relation. Using an INNER join allows the database to apply optimizations it wouldn't be able to otherwise.

Since this affects Query::derive(), any eager loaded relation will now return no result. But this should be usually not a problem, as a caller that iterates or calls first() without handling the never entered loop or null-return is already bugged, IMHO. I've checked this with Icinga DB Web and found exactly two cases: Icinga/icingadb-web#1408

Still attempting to prove this is actually of advantage, though…

A subquery always needs to establish a link, be it part of a
WHERE or solely used to eager load (using `Query::derive`)
a relation. Using an INNER join allows the database to apply
optimizations it wouldn't be able to otherwise.
@nilmerg nilmerg added this to the v1.0.0 milestone Aug 26, 2026
@nilmerg nilmerg self-assigned this Aug 26, 2026
@cla-bot cla-bot Bot added the cla/signed label Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant