Skip to content

Commit ea695fb

Browse files
opt: set default optimizer_span_limit to 131072
Set the default value of the `optimizer_span_limit` session variable to 2^17 (131072) instead of 0 (no limit). This provides a reasonable upper bound on the number of spans the optimizer will produce, preventing pathological cases where large cross-products of IN sets produce excessive spans. Informs: #167620 Release note (sql change): The session variable `optimizer_span_limit` now defaults to 131072. This bounds the number of spans the optimizer will allow in constrained index scans generated during query optimization. Queries that would exceed this limit will use fewer looser spans with remaining filters instead. Set to 0 to disable the limit. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
1 parent 5b2bfa5 commit ea695fb

5 files changed

Lines changed: 6 additions & 6 deletions

File tree

pkg/sql/logictest/testdata/logic_test/information_schema

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3919,7 +3919,7 @@ optimizer_prefer_bounded_cardinality on
39193919
optimizer_prove_implication_with_virtual_computed_columns on
39203920
optimizer_push_limit_into_project_filtered_scan on
39213921
optimizer_push_offset_into_index_join on
3922-
optimizer_span_limit 0
3922+
optimizer_span_limit 131072
39233923
optimizer_use_conditional_hoist_fix on
39243924
optimizer_use_delete_range_fast_path on
39253925
optimizer_use_exists_filter_hoist_rule on

pkg/sql/logictest/testdata/logic_test/pg_catalog

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,7 +3320,7 @@ optimizer_prefer_bounded_cardinality on
33203320
optimizer_prove_implication_with_virtual_computed_columns on NULL NULL NULL string
33213321
optimizer_push_limit_into_project_filtered_scan on NULL NULL NULL string
33223322
optimizer_push_offset_into_index_join on NULL NULL NULL string
3323-
optimizer_span_limit 0 NULL NULL NULL string
3323+
optimizer_span_limit 131072 NULL NULL NULL string
33243324
optimizer_use_conditional_hoist_fix on NULL NULL NULL string
33253325
optimizer_use_delete_range_fast_path on NULL NULL NULL string
33263326
optimizer_use_exists_filter_hoist_rule on NULL NULL NULL string
@@ -3580,7 +3580,7 @@ optimizer_prefer_bounded_cardinality on
35803580
optimizer_prove_implication_with_virtual_computed_columns on NULL user NULL on on
35813581
optimizer_push_limit_into_project_filtered_scan on NULL user NULL on on
35823582
optimizer_push_offset_into_index_join on NULL user NULL on on
3583-
optimizer_span_limit 0 NULL user NULL 0 0
3583+
optimizer_span_limit 131072 NULL user NULL 131072 131072
35843584
optimizer_use_conditional_hoist_fix on NULL user NULL on on
35853585
optimizer_use_delete_range_fast_path on NULL user NULL on on
35863586
optimizer_use_exists_filter_hoist_rule on NULL user NULL on on

pkg/sql/logictest/testdata/logic_test/show_source

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ optimizer_prefer_bounded_cardinality on
168168
optimizer_prove_implication_with_virtual_computed_columns on Controls whether the optimizer should use virtual computed columns to prove partial index implication.
169169
optimizer_push_limit_into_project_filtered_scan on Controls whether the optimizer should push limit expressions into projects of filtered scans.
170170
optimizer_push_offset_into_index_join on Controls whether the optimizer should push offset expressions into index joins.
171-
optimizer_span_limit 0 Sets the maximum number of constraint spans allowed in a scan during query optimization. 0 means no limit.
171+
optimizer_span_limit 131072 Sets the maximum number of constraint spans allowed in a scan during query optimization. 0 means no limit.
172172
optimizer_use_conditional_hoist_fix on Prevents the optimizer from hoisting volatile expressions that are conditionally executed by CASE, COALESCE, or IFERR expressions.
173173
optimizer_use_delete_range_fast_path on Controls whether the optimizer uses the fast path for DELETE operations using range deletions.
174174
optimizer_use_exists_filter_hoist_rule on Controls whether the optimizer hoists filters out of EXISTS subqueries.

pkg/sql/sessiondatapb/local_only_session_data.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ message LocalOnlySessionData {
814814
// (show CRDB syntax explicitly).
815815
string pg_dump_compatibility = 206;
816816
// OptimizerSpanLimit sets the maximum number of constraint spans allowed in
817-
// a scan during query optimization. 0 means no limit.
817+
// a scan during query optimization. 0 means no limit. Default: 131072.
818818
int32 optimizer_span_limit = 207;
819819

820820
///////////////////////////////////////////////////////////////////////////

pkg/sql/vars.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3016,7 +3016,7 @@ var varGen = map[string]sessionVar{
30163016
return strconv.FormatInt(int64(evalCtx.SessionData().OptimizerSpanLimit), 10), nil
30173017
},
30183018
GlobalDefault: func(_ *settings.Values) string {
3019-
return "0"
3019+
return "131072"
30203020
},
30213021
},
30223022

0 commit comments

Comments
 (0)