Skip to content

release-25.4.10-rc: opt: add optimizer_span_limit and use in GenerateConstrainedScans#168892

Merged
michae2 merged 1 commit intocockroachdb:release-25.4.10-rcfrom
michae2:backport25.4.10-167180
Apr 28, 2026
Merged

release-25.4.10-rc: opt: add optimizer_span_limit and use in GenerateConstrainedScans#168892
michae2 merged 1 commit intocockroachdb:release-25.4.10-rcfrom
michae2:backport25.4.10-167180

Conversation

@michae2
Copy link
Copy Markdown
Collaborator

@michae2 michae2 commented Apr 22, 2026

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, and
uses 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_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:

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


Release justification: disabled-by-default fix for customer workload. Fixes ENGREQ-424.

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>
@michae2 michae2 requested review from a team and mw5h April 22, 2026 15:44
@michae2 michae2 added T-sql-queries SQL Queries Team backport Label PR's that are backports to older release branches labels Apr 22, 2026
@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented Apr 22, 2026

Thanks for opening a backport.

Before merging, please confirm that it falls into one of the following categories (select one):

  • Non-production code changes OR fixes for serious issues. Non-production includes test-only changes, build system changes, etc. Serious issues are defined in the policy as correctness, stability, or security issues, data corruption/loss, significant performance regressions, breaking working and widely used functionality, or an inability to detect and debug production issues.
  • Other approved changes. These changes must be gated behind a disabled-by-default feature flag unless there is a strong justification not to. Reference the approved ENGREQ ticket in the PR body (e.g., "Fixes ENGREQ-123").

Add a brief release justification to the PR description explaining your selection.

Also, confirm that the change does not break backward compatibility and complies with all aspects of the backport policy.

All backports must be reviewed by the TL and EM for the owning area.

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented Apr 22, 2026

✅ PR #168892 is compliant with backport policy

Confidence: high
Feature flag detected: Yes
Backward compatible: true
Explanation: The pull request introduces a new session variable optimizer_span_limit that is disabled by default. This session variable limits the number of spans the optimizer will allow in a single constrained index scan, effectively acting as a feature flag for the new behavior introduced. Since it is disabled by default, it complies with the backport policy for feature flags. Additionally, the PR includes a 'Release justification: disabled-by-default fix for customer workload. Fixes ENGREQ-424.' which explicitly states the change is gated by a feature that is disabled by default and is intended to address a specific customer request (ENGREQ-424), further supporting the exemption from typical backport requirements.

ENGREQ Check Passed: ENGREQ ticket referenced in PR body.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Copy link
Copy Markdown
Collaborator

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@DrewKimball reviewed 20 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on mw5h).

Copy link
Copy Markdown
Contributor

@mw5h mw5h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@mw5h made 1 comment.
Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on michae2).

@michae2
Copy link
Copy Markdown
Collaborator Author

michae2 commented Apr 28, 2026

Thanks!

@michae2 michae2 merged commit a198902 into cockroachdb:release-25.4.10-rc Apr 28, 2026
19 checks passed
@michae2 michae2 deleted the backport25.4.10-167180 branch April 28, 2026 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Label PR's that are backports to older release branches T-sql-queries SQL Queries Team v25.4.10

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants