Skip to content

release-26.2: opt: add optimizer_span_limit and use in GenerateConstrainedScans#168617

Merged
trunk-io[bot] merged 1 commit intocockroachdb:release-26.2from
michae2:backport26.2-167180
Apr 22, 2026
Merged

release-26.2: opt: add optimizer_span_limit and use in GenerateConstrainedScans#168617
trunk-io[bot] merged 1 commit intocockroachdb:release-26.2from
michae2:backport26.2-167180

Conversation

@michae2
Copy link
Copy Markdown
Collaborator

@michae2 michae2 commented Apr 17, 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.

@michae2 michae2 requested review from a team, DrewKimball and mw5h April 17, 2026 21:36
@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented Apr 17, 2026

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.

@trunk-io
Copy link
Copy Markdown
Contributor

trunk-io Bot commented Apr 17, 2026

😎 Merged successfully - details.

@blathers-crl blathers-crl Bot added backport Label PR's that are backports to older release branches T-sql-queries SQL Queries Team labels Apr 17, 2026
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

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 force-pushed the backport26.2-167180 branch from 9ded621 to d4b920d Compare April 17, 2026 22:34
@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented Apr 17, 2026

Detected infrastructure failure (matched: self-hosted runner lost communication with the server). Automatically rerunning failed jobs. (run link)

@michae2
Copy link
Copy Markdown
Collaborator Author

michae2 commented Apr 21, 2026

Thanks!

/trunk merge

@trunk-io trunk-io Bot merged commit a3c4314 into cockroachdb:release-26.2 Apr 22, 2026
31 of 32 checks passed
@michae2 michae2 deleted the backport26.2-167180 branch April 22, 2026 00:46
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 target-release-26.2.1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants