Skip to content

Find the rows of a correlated subquery through an index for an expression of the outer columns - #445

Merged
tamnd merged 1 commit into
mainfrom
outer-lookups
Oct 20, 2026
Merged

tamnd merged 1 commit into
mainfrom
outer-lookups

Conversation

@tamnd

@tamnd tamnd commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Summary

A correlated subquery finds its rows through an index of a column when its condition is an = of the column and a value of the outer query. Before, the value had to be a column of the outer query. Now it can be an expression of the columns of the outer query, as t2.thousand = t1.tenthous + 1. In the regression test create_index, one such query read 100 million rows and took 281 seconds.

Changes

  • outer_expr replaces outer_var in rupg-exec. It accepts a column of an outer query, a constant, a parameter, a cast, and a function that is not volatile and does not return a set, of such expressions. The expression must read at least one column of an outer query, so a plain query still scans its rows once.
  • volatile in rupg-exec is now pub(crate).

Known differences

None. The result of each query is the same, and the scan only reads fewer rows.

Tests

connection/outer_lookups.test is the output of PostgreSQL 19 for the same script in a new database. fmt, clippy, the workspace tests and the checks of xtask pass on server1.

@tamnd tamnd added kind/perf It is slower or larger than the budget. area/execution Operators, vectors, morsels, joins, aggregation and spill. labels Oct 20, 2026
@tamnd
tamnd merged commit 2f5f671 into main Oct 20, 2026
5 checks passed
@tamnd
tamnd deleted the outer-lookups branch October 20, 2026 07:22
@tamnd tamnd mentioned this pull request Oct 20, 2026
1 of 17 tasks
tamnd added a commit that referenced this pull request Oct 20, 2026
… its join (#446)

* Add the changelog entry for #445

* Run a LATERAL part once when it reads no relation of the left side of its join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/execution Operators, vectors, morsels, joins, aggregation and spill. kind/perf It is slower or larger than the budget.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant