Skip to content

Commit 2019a42

Browse files
committed
opt: enable optimizer_prefer_bounded_cardinality by default
Release note (sql change): The session setting `optimizer_prefer_bounded_cardinality` is now enabled by default.
1 parent 55d7fbb commit 2019a42

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2554
-287
lines changed

pkg/ccl/logictestccl/testdata/logic_test/explain_redact

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ scan q
296296
├── constraint: /1: ‹×›
297297
├── stats: [rows=333.333, distinct(1)=333.333, null(1)=0]
298298
├── cost: 378.02
299+
├── cost-flags: unbounded-cardinality
299300
├── key: (1)
300301
├── fd: (1)-->(2)
301302
├── distribution: test
@@ -309,6 +310,7 @@ scan q
309310
├── constraint: /1: ‹×›
310311
├── stats: [rows=333.333, distinct(1)=333.333, null(1)=0]
311312
├── cost: 378.02
313+
├── cost-flags: unbounded-cardinality
312314
├── key: (1)
313315
├── fd: (1)-->(2)
314316
├── distribution: test

pkg/ccl/logictestccl/testdata/logic_test/multi_region_remote_access_error

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ SELECT * FROM (SELECT 1, 'Hello, Dude!') vtab(account_id, message)
395395

396396
# A scalar subquery with no home region should fail.
397397
retry
398-
statement error pq: Query has no home region\. Try adding a filter on rbr\.crdb_region and/or on key column \(rbr\.account_id\)\. For more information, see https://www.cockroachlabs.com/docs/stable/cost-based-optimizer.html#control-whether-queries-are-limited-to-a-single-region
398+
statement error pq: Query has no home region. Try adding a LIMIT clause. For more information, see https://www.cockroachlabs.com/docs/stable/cost-based-optimizer.html#control-whether-queries-are-limited-to-a-single-region
399399
SELECT * FROM (SELECT (SELECT max(account_id) FROM messages_rbr rbr), 'Hello, Dude!') vtab(account_id, message)
400400
INNER LOOKUP JOIN messages_rbt rbt on vtab.account_id = rbt.account_id
401401

@@ -416,7 +416,7 @@ CREATE OR REPLACE FUNCTION rbr() RETURNS INT AS 'SELECT max(account_id) FROM mes
416416

417417
# A UDF with no home region should fail.
418418
retry
419-
statement error pq: Query has no home region\. Try adding a filter on messages_rbr\.crdb_region and/or on key column \(multi_region_test_db\.public\.messages_rbr\.account_id\)\. For more information, see https://www.cockroachlabs.com/docs/stable/cost-based-optimizer.html#control-whether-queries-are-limited-to-a-single-region
419+
statement error pq: Query has no home region. Try adding a LIMIT clause. For more information, see https://www.cockroachlabs.com/docs/stable/cost-based-optimizer.html#control-whether-queries-are-limited-to-a-single-region
420420
SELECT rbr()
421421

422422
# An EXISTS subquery with no home region should fail.
@@ -440,22 +440,22 @@ SELECT * FROM messages_rbr rbr, LATERAL
440440

441441
# An array scalar expression with no home region should fail.
442442
retry
443-
statement error pq: Query has no home region\. Try adding a filter on messages_rbr\.crdb_region and/or on key column \(multi_region_test_db\.public\.messages_rbr\.account_id\)\. For more information, see https://www.cockroachlabs.com/docs/stable/cost-based-optimizer.html#control-whether-queries-are-limited-to-a-single-region
443+
statement error pq: Query has no home region. Try adding a LIMIT clause. For more information, see https://www.cockroachlabs.com/docs/stable/cost-based-optimizer.html#control-whether-queries-are-limited-to-a-single-region
444444
SELECT ARRAY[rbr(),rbr()]
445445

446446
# An ALL subquery with no home region should fail.
447447
retry
448-
statement error pq: Query has no home region\. Try adding a filter on messages_rbr\.crdb_region and/or on key column \(messages_rbr\.account_id\)\. For more information, see https://www.cockroachlabs.com/docs/stable/cost-based-optimizer.html#control-whether-queries-are-limited-to-a-single-region
448+
statement error pq: Query has no home region. Try adding a LIMIT clause. For more information, see https://www.cockroachlabs.com/docs/stable/cost-based-optimizer.html#control-whether-queries-are-limited-to-a-single-region
449449
SELECT 1 WHERE 1 > ALL (SELECT max(account_id) FROM messages_rbr)
450450

451451
# An ANY subquery with no home region should fail.
452452
retry
453-
statement error pq: Query has no home region\. Try adding a filter on messages_rbr\.crdb_region and/or on key column \(messages_rbr\.account_id\)\. For more information, see https://www.cockroachlabs.com/docs/stable/cost-based-optimizer.html#control-whether-queries-are-limited-to-a-single-region
453+
statement error pq: Query has no home region. Try adding a LIMIT clause. For more information, see https://www.cockroachlabs.com/docs/stable/cost-based-optimizer.html#control-whether-queries-are-limited-to-a-single-region
454454
SELECT 1 WHERE 1 > ANY (SELECT max(account_id) FROM messages_rbr)
455455

456456
# A SOME subquery with no home region should fail.
457457
retry
458-
statement error pq: Query has no home region\. Try adding a filter on messages_rbr\.crdb_region and/or on key column \(messages_rbr\.account_id\)\. For more information, see https://www.cockroachlabs.com/docs/stable/cost-based-optimizer.html#control-whether-queries-are-limited-to-a-single-region
458+
statement error pq: Query has no home region. Try adding a LIMIT clause. For more information, see https://www.cockroachlabs.com/docs/stable/cost-based-optimizer.html#control-whether-queries-are-limited-to-a-single-region
459459
SELECT 1 WHERE 1 > ANY (SELECT max(account_id) FROM messages_rbr)
460460

461461
### Regression tests for issue #89875
@@ -1073,6 +1073,7 @@ project
10731073
├── immutable
10741074
├── stats: [rows=1]
10751075
├── cost: 4309.15778
1076+
├── cost-flags: unbounded-cardinality
10761077
├── key: ()
10771078
├── fd: ()-->(9)
10781079
├── distribution: ap-southeast-2
@@ -1083,6 +1084,7 @@ project
10831084
├── immutable
10841085
├── stats: [rows=1]
10851086
├── cost: 4309.13778
1087+
├── cost-flags: unbounded-cardinality
10861088
├── key: ()
10871089
├── fd: ()-->(3,9,11,13)
10881090
├── distribution: ap-southeast-2
@@ -1093,6 +1095,7 @@ project
10931095
│ ├── immutable
10941096
│ ├── stats: [rows=3333.33]
10951097
│ ├── cost: 4309.11778
1098+
│ ├── cost-flags: unbounded-cardinality
10961099
│ ├── fd: ()-->(13), (9)-->(11)
10971100
│ ├── limit hint: 1.00
10981101
│ ├── distribution: ap-southeast-2
@@ -1106,19 +1109,22 @@ project
11061109
│ │ │ └── t1.j:24 @> t2.j:3
11071110
│ │ ├── stats: [rows=3333.33, distinct(21)=1, null(21)=0, distinct(22)=964.524, null(22)=0, distinct(26)=1, null(26)=0]
11081111
│ │ ├── cost: 3837.19889
1112+
│ │ ├── cost-flags: unbounded-cardinality
11091113
│ │ ├── fd: ()-->(26)
11101114
│ │ ├── limit hint: 100.00
11111115
│ │ ├── distribution: ap-southeast-2
11121116
│ │ ├── project
11131117
│ │ │ ├── columns: "inverted_join_const_col_@13":21 t2.j:3
11141118
│ │ │ ├── stats: [rows=1000, distinct(21)=1, null(21)=0]
11151119
│ │ │ ├── cost: 1136.62333
1120+
│ │ │ ├── cost-flags: unbounded-cardinality
11161121
│ │ │ ├── fd: ()-->(21)
11171122
│ │ │ ├── distribution: ap-southeast-2
11181123
│ │ │ ├── scan json_arr2_rbt [as=t2]
11191124
│ │ │ │ ├── columns: t2.j:3
11201125
│ │ │ │ ├── stats: [rows=1000]
11211126
│ │ │ │ ├── cost: 1116.60333
1127+
│ │ │ │ ├── cost-flags: unbounded-cardinality
11221128
│ │ │ │ ├── distribution: ap-southeast-2
11231129
│ │ │ │ ├── prune: (3)
11241130
│ │ │ │ └── unfiltered-cols: (1-8)

pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_query_behavior

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3654,6 +3654,7 @@ project
36543654
├── immutable
36553655
├── stats: [rows=0.366667]
36563656
├── cost: 45.3262257
3657+
├── cost-flags: unbounded-cardinality
36573658
├── fd: ()-->(2,5,21,24), (3)==(22), (22)==(3), (5)==(24), (24)==(5), (4)==(23), (23)==(4), (2)==(21), (21)==(2)
36583659
├── distribution: ap-southeast-2
36593660
├── prune: (2-5,12,21-24)
@@ -3663,6 +3664,7 @@ project
36633664
├── immutable
36643665
├── stats: [rows=0.366667, distinct(13)=0.366667, null(13)=0, distinct(14)=0.366667, null(14)=0, distinct(15)=0.366667, null(15)=0, distinct(20)=0.366667, null(20)=0, distinct(24)=0.366667, null(24)=0, distinct(25)=0.366667, null(25)=0]
36653666
├── cost: 45.302559
3667+
├── cost-flags: unbounded-cardinality
36663668
├── fd: ()-->(2,5,6,14,15,21,24,25), (1)-->(3,4), (20)-->(22,23), (1)==(13,20), (13)==(1,20), (20)==(1,13), (5)==(14,24), (14)==(5,24), (24)==(5,14), (6)==(15,25), (15)==(6,25), (25)==(6,15), (2)==(21), (21)==(2), (3)==(22), (22)==(3), (4)==(23), (23)==(4)
36673669
├── distribution: ap-southeast-2
36683670
├── lookup table distribution: ap-southeast-2,ca-central-1,us-east-1
@@ -3673,6 +3675,7 @@ project
36733675
│ ├── immutable
36743676
│ ├── stats: [rows=0.134444, distinct(1)=0.134444, null(1)=0, distinct(2)=0.134444, null(2)=0, distinct(3)=0.134444, null(3)=0, distinct(4)=0.134444, null(4)=0, distinct(5)=0.134444, null(5)=0, distinct(6)=0.134444, null(6)=0, distinct(20)=0.134444, null(20)=0, distinct(21)=0.134444, null(21)=0, distinct(22)=0.134444, null(22)=0, distinct(23)=0.134444, null(23)=0, distinct(24)=0.134444, null(24)=0, distinct(25)=0.134444, null(25)=0]
36753677
│ ├── cost: 34.9459129
3678+
│ ├── cost-flags: unbounded-cardinality
36763679
│ ├── key: (20)
36773680
│ ├── fd: ()-->(2,5,6,21,24,25), (1)-->(3,4), (20)-->(22,23), (1)==(20), (20)==(1), (2)==(21), (21)==(2), (3)==(22), (22)==(3), (4)==(23), (23)==(4), (5)==(24), (24)==(5), (6)==(25), (25)==(6)
36783681
│ ├── distribution: ap-southeast-2
@@ -3685,6 +3688,7 @@ project
36853688
│ │ ├── immutable
36863689
│ │ ├── stats: [rows=0.00366667, distinct(1)=0.00366667, null(1)=0, distinct(2)=0.00366667, null(2)=0, distinct(5)=0.00366667, null(5)=0, distinct(6)=0.00366667, null(6)=0, distinct(20)=0.00366667, null(20)=0, distinct(21)=0.00366667, null(21)=0, distinct(24)=0.00366667, null(24)=0, distinct(25)=0.00366667, null(25)=0, distinct(21,24,25)=0.00366667, null(21,24,25)=0]
36873690
│ │ ├── cost: 34.8283629
3691+
│ │ ├── cost-flags: unbounded-cardinality
36883692
│ │ ├── key: (20)
36893693
│ │ ├── fd: ()-->(2,5,6,21,24,25), (1)-->(3,4), (6)==(25), (25)==(6), (2)==(21), (21)==(2), (5)==(24), (24)==(5), (1)==(20), (20)==(1)
36903694
│ │ ├── distribution: ap-southeast-2
@@ -3697,6 +3701,7 @@ project
36973701
│ │ │ │ histogram(6)= 0 0.36667
36983702
│ │ │ │ <--- 'ap-southeast-2'
36993703
│ │ │ ├── cost: 33.2056672
3704+
│ │ │ ├── cost-flags: unbounded-cardinality
37003705
│ │ │ ├── key: (1)
37013706
│ │ │ ├── fd: ()-->(2,5,6), (1)-->(3,4)
37023707
│ │ │ ├── distribution: ap-southeast-2
@@ -3709,6 +3714,7 @@ project
37093714
│ │ │ │ histogram(6)= 0 0.36667
37103715
│ │ │ │ <--- 'ap-southeast-2'
37113716
│ │ │ ├── cost: 25.430667
3717+
│ │ │ ├── cost-flags: unbounded-cardinality
37123718
│ │ │ ├── key: (1)
37133719
│ │ │ ├── fd: ()-->(2,5,6)
37143720
│ │ │ ├── distribution: ap-southeast-2

pkg/sql/logictest/testdata/logic_test/information_schema

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4052,7 +4052,7 @@ optimizer_hoist_uncorrelated_equality_subqueries on
40524052
optimizer_merge_joins_enabled on
40534053
optimizer_min_row_count 0
40544054
optimizer_plan_lookup_joins_with_reverse_scans on
4055-
optimizer_prefer_bounded_cardinality off
4055+
optimizer_prefer_bounded_cardinality on
40564056
optimizer_prove_implication_with_virtual_computed_columns on
40574057
optimizer_push_limit_into_project_filtered_scan on
40584058
optimizer_push_offset_into_index_join on

pkg/sql/logictest/testdata/logic_test/pg_catalog

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,7 +3045,7 @@ optimizer_hoist_uncorrelated_equality_subqueries on
30453045
optimizer_merge_joins_enabled on NULL NULL NULL string
30463046
optimizer_min_row_count 0 NULL NULL NULL string
30473047
optimizer_plan_lookup_joins_with_reverse_scans on NULL NULL NULL string
3048-
optimizer_prefer_bounded_cardinality off NULL NULL NULL string
3048+
optimizer_prefer_bounded_cardinality on NULL NULL NULL string
30493049
optimizer_prove_implication_with_virtual_computed_columns on NULL NULL NULL string
30503050
optimizer_push_limit_into_project_filtered_scan on NULL NULL NULL string
30513051
optimizer_push_offset_into_index_join on NULL NULL NULL string
@@ -3281,7 +3281,7 @@ optimizer_hoist_uncorrelated_equality_subqueries on
32813281
optimizer_merge_joins_enabled on NULL user NULL on on
32823282
optimizer_min_row_count 0 NULL user NULL 0 0
32833283
optimizer_plan_lookup_joins_with_reverse_scans on NULL user NULL on on
3284-
optimizer_prefer_bounded_cardinality off NULL user NULL off off
3284+
optimizer_prefer_bounded_cardinality on NULL user NULL on on
32853285
optimizer_prove_implication_with_virtual_computed_columns on NULL user NULL on on
32863286
optimizer_push_limit_into_project_filtered_scan on NULL user NULL on on
32873287
optimizer_push_offset_into_index_join on NULL user NULL on on

pkg/sql/logictest/testdata/logic_test/prepare

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,13 +1184,15 @@ select
11841184
├── immutable
11851185
├── stats: [rows=333.333]
11861186
├── cost: 1118.85
1187+
├── cost-flags: unbounded-cardinality
11871188
├── key: (1)
11881189
├── fd: (1)-->(2)
11891190
├── prune: (2)
11901191
├── scan t2
11911192
│ ├── columns: k:1 str:2
11921193
│ ├── stats: [rows=1000]
11931194
│ ├── cost: 1108.82
1195+
│ ├── cost-flags: unbounded-cardinality
11941196
│ ├── key: (1)
11951197
│ ├── fd: (1)-->(2)
11961198
│ └── prune: (1,2)

pkg/sql/logictest/testdata/logic_test/show_source

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ optimizer_hoist_uncorrelated_equality_subqueries on
159159
optimizer_merge_joins_enabled on
160160
optimizer_min_row_count 0
161161
optimizer_plan_lookup_joins_with_reverse_scans on
162-
optimizer_prefer_bounded_cardinality off
162+
optimizer_prefer_bounded_cardinality on
163163
optimizer_prove_implication_with_virtual_computed_columns on
164164
optimizer_push_limit_into_project_filtered_scan on
165165
optimizer_push_offset_into_index_join on

pkg/sql/opt/exec/execbuilder/testdata/collated_strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ select
137137
│ histogram(2)= 0 10
138138
│ <--- 'hello' COLLATE en_US_u_ks_level2
139139
├── cost: 43.02
140+
├── cost-flags: unbounded-cardinality
140141
├── key: (1)
141142
├── fd: ()-->(2)
142143
├── distribution: test
@@ -149,6 +150,7 @@ select
149150
│ │ histogram(2)= 0 1 10 2
150151
│ │ <--- 'foo' COLLATE en_US_u_ks_level2 ---- 'world' COLLATE en_US_u_ks_level2
151152
│ ├── cost: 42.86
153+
│ ├── cost-flags: unbounded-cardinality
152154
│ ├── key: (1)
153155
│ ├── fd: (1)-->(2)
154156
│ ├── distribution: test

pkg/sql/opt/exec/execbuilder/testdata/distsql_agg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,7 @@ group-by (streaming)
10341034
├── internal-ordering: +2 opt(1)
10351035
├── stats: [rows=9.56179, distinct(2)=9.56179, null(2)=0]
10361036
├── cost: 29.145618
1037+
├── cost-flags: unbounded-cardinality
10371038
├── key: (2)
10381039
├── fd: (2)-->(7)
10391040
├── distribution: test
@@ -1043,6 +1044,7 @@ group-by (streaming)
10431044
│ ├── constraint: /1/2: [/1 - /1]
10441045
│ ├── stats: [rows=10, distinct(1)=1, null(1)=0, distinct(2)=9.56179, null(2)=0]
10451046
│ ├── cost: 28.8200001
1047+
│ ├── cost-flags: unbounded-cardinality
10461048
│ ├── key: (2)
10471049
│ ├── fd: ()-->(1)
10481050
│ ├── ordering: +2 opt(1) [actual: +2]

pkg/sql/opt/exec/execbuilder/testdata/enums

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,14 @@ distinct-on
124124
├── cardinality: [0 - 4]
125125
├── stats: [rows=4, distinct(1)=4, null(1)=0]
126126
├── cost: 1118.88
127+
├── cost-flags: unbounded-cardinality
127128
├── key: (1)
128129
├── distribution: test
129130
└── scan checks@checks_x_y_idx
130131
├── columns: x:1
131132
├── stats: [rows=1000, distinct(1)=4, null(1)=0]
132133
├── cost: 1108.82
134+
├── cost-flags: unbounded-cardinality
133135
├── ordering: +1
134136
├── distribution: test
135137
├── prune: (1)
@@ -175,27 +177,31 @@ union
175177
├── cardinality: [0 - 5]
176178
├── stats: [rows=5, distinct(15)=5, null(15)=1]
177179
├── cost: 2284.86667
180+
├── cost-flags: unbounded-cardinality
178181
├── key: (15)
179182
├── distribution: test
180183
├── interesting orderings: (+15)
181184
├── project
182185
│ ├── columns: nulls.x:1
183186
│ ├── stats: [rows=333.333, distinct(1)=5, null(1)=3.33333]
184187
│ ├── cost: 1142.40333
188+
│ ├── cost-flags: unbounded-cardinality
185189
│ ├── ordering: +1
186190
│ ├── distribution: test
187191
│ ├── interesting orderings: (+1)
188192
│ └── select
189193
│ ├── columns: nulls.x:1 y:2
190194
│ ├── stats: [rows=333.333, distinct(1)=5, null(1)=3.33333, distinct(2)=33.3333, null(2)=0]
191195
│ ├── cost: 1139.05
196+
│ ├── cost-flags: unbounded-cardinality
192197
│ ├── ordering: +1
193198
│ ├── distribution: test
194199
│ ├── interesting orderings: (+1,+2)
195200
│ ├── scan nulls@nulls_x_y_idx
196201
│ │ ├── columns: nulls.x:1 y:2
197202
│ │ ├── stats: [rows=1000, distinct(1)=5, null(1)=10, distinct(2)=100, null(2)=10]
198203
│ │ ├── cost: 1129.02
204+
│ │ ├── cost-flags: unbounded-cardinality
199205
│ │ ├── ordering: +1
200206
│ │ ├── distribution: test
201207
│ │ ├── prune: (1,2)
@@ -206,20 +212,23 @@ union
206212
├── columns: nulls.x:8
207213
├── stats: [rows=333.333, distinct(8)=5, null(8)=3.33333]
208214
├── cost: 1142.40333
215+
├── cost-flags: unbounded-cardinality
209216
├── ordering: +8
210217
├── distribution: test
211218
├── interesting orderings: (+8)
212219
└── select
213220
├── columns: nulls.x:8 y:9
214221
├── stats: [rows=333.333, distinct(8)=5, null(8)=3.33333, distinct(9)=33.3333, null(9)=0]
215222
├── cost: 1139.05
223+
├── cost-flags: unbounded-cardinality
216224
├── ordering: +8
217225
├── distribution: test
218226
├── interesting orderings: (+8,+9)
219227
├── scan nulls@nulls_x_y_idx
220228
│ ├── columns: nulls.x:8 y:9
221229
│ ├── stats: [rows=1000, distinct(8)=5, null(8)=10, distinct(9)=100, null(9)=10]
222230
│ ├── cost: 1129.02
231+
│ ├── cost-flags: unbounded-cardinality
223232
│ ├── ordering: +8
224233
│ ├── distribution: test
225234
│ ├── prune: (8,9)

0 commit comments

Comments
 (0)