Skip to content

features-sql: avoid redundant meta queries for large result limits#530

Merged
cportele merged 2 commits into
masterfrom
optimize-metaqueries
Jun 13, 2026
Merged

features-sql: avoid redundant meta queries for large result limits#530
cportele merged 2 commits into
masterfrom
optimize-metaqueries

Conversation

@cportele

@cportele cportele commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

A query with a large limit is split into limit/chunkSize query sets, each carrying its own meta query. Previously every chunk re-ran the full numberMatched count and, with computeNumberMatched enabled, meta queries kept being issued even after the result was exhausted - producing hundreds of identical counts for a single page.

numberMatched is now computed only on the first chunk of each collection (it is invariant across chunks); later chunks reuse that value. Meta queries also stop once the limit is reached or a collection is exhausted, independent of computeNumberMatched.

MetaQueryTemplate gains a withNumberMatched flag; the now-obsolete allowSkipMetaQueries flag is removed.

Closes ldproxy/ldproxy#1643

A query with a large limit is split into limit/chunkSize query sets, each carrying its
own meta query. Previously every chunk re-ran the full numberMatched count and, with
computeNumberMatched enabled, meta queries kept being issued even after the result was
exhausted - producing hundreds of identical counts for a single page.

numberMatched is now computed only on the first chunk of each collection (it is
invariant across chunks); later chunks reuse that value. Meta queries also stop once
the limit is reached or a collection is exhausted, independent of computeNumberMatched.

MetaQueryTemplate gains a withNumberMatched flag; the now-obsolete allowSkipMetaQueries
flag is removed.
@cportele cportele requested a review from azahnen as a code owner June 12, 2026 11:24
@cportele cportele enabled auto-merge (squash) June 13, 2026 06:36
@cportele cportele merged commit 5d81a35 into master Jun 13, 2026
3 checks passed
@cportele cportele deleted the optimize-metaqueries branch June 13, 2026 06:39
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.

SQL: avoid redundant meta queries for large result limits

2 participants