release-26.2: opt: add optimizer_span_limit and use in GenerateConstrainedScans#168617
Merged
trunk-io[bot] merged 1 commit intocockroachdb:release-26.2from Apr 22, 2026
Merged
Conversation
|
Thanks for opening a backport. Before merging, please confirm that the change does not break backwards compatibility and otherwise complies with the backport policy. Include a brief release justification in the PR description explaining why the backport is appropriate. All backports must be reviewed by the TL for the owning area. While the stricter LTS policy does not yet apply, please exercise judgment and consider gating non-critical changes behind a disabled-by-default feature flag when appropriate. |
Contributor
|
😎 Merged successfully - details. |
Member
This commit creates a new session variable `optimizer_span_limit`, and uses it to bound the number of spans in constrained scans produced by `GenerateConstrainedScans`. Fixes: cockroachdb#167620 Release note (sql change): Add a new session variable `optimizer_span_limit` which bounds the number of spans the optimizer will allow in a single constrained index scan. If a single IN set has more items than this limit, that IN set will not be used to build a constrained index scan. If the cross product of two or more IN sets would produce more spans than this limit for a composite index, then only a prefix of the IN sets will be used to produce spans. For example, for the following table and query, only the predicates on columns `a` and `b` will be used to construct the constrained scan of `abc_idx`, because including the predicate on column `c` would produce more spans than `optimizer_span_limit`: ```sql CREATE TABLE abc (a INT, b INT, c INT, INDEX abc_idx (a, b, c)); SET optimizer_span_limit = 10; SELECT * FROM abc WHERE a IN (1, 3, 5) AND b IN (2, 4, 6) AND c IN (7, 9, 11); ``` Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
9ded621 to
d4b920d
Compare
|
Detected infrastructure failure (matched: self-hosted runner lost communication with the server). Automatically rerunning failed jobs. (run link) |
mw5h
approved these changes
Apr 21, 2026
Collaborator
Author
|
Thanks! /trunk merge |
a3c4314
into
cockroachdb:release-26.2
31 of 32 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport 1/2 commits from #167180.
/cc @cockroachdb/release
opt: add optimizer_span_limit and use in GenerateConstrainedScans
This commit creates a new session variable
optimizer_span_limit, anduses it to bound the number of spans in constrained scans produced by
GenerateConstrainedScans.Fixes: #167620
Release note (sql change): Add a new session variable
optimizer_span_limitwhich bounds the number of spans the optimizerwill allow in a single constrained index scan. If a single IN set has
more items than this limit, that IN set will not be used to build a
constrained index scan. If the cross product of two or more IN sets
would produce more spans than this limit for a composite index, then
only a prefix of the IN sets will be used to produce spans.
For example, for the following table and query, only the predicates on
columns
aandbwill be used to construct the constrained scan ofabc_idx, because including the predicate on columncwould producemore spans than
optimizer_span_limit:Co-Authored-By: roachdev-claude roachdev-claude-bot@cockroachlabs.com
Release justification: disabled-by-default fix for customer workload.