Skip to content

Commit 2e0b2f6

Browse files
craig[bot]mgartner
andcommitted
Merge #120079
120079: opt: fix row count estimates for inverted filters r=mgartner a=mgartner #### opt: assign table ID to hypothetical inverted index columns This commit fixes a minor bug in index recommendations where hypothetical inverted index columns were not assigned table IDs in the hypothetical table's metadata. In theory this could cause internal errors, however, there are no known reproductions of errors. Release note: None #### opt: decrease row count rounding precision Row counts are now rounded with less precision so that optimizer test outputs are the same across different CPU architectures. Follow-up of #75723. Release note: None #### opt: fix row count estimates for inverted filters Previously, inverted filter row counts were set to their input's row count. This was often an over-estimation because inverted filters de-duplicate inverted index tuples from their input by primary key, and inverted indexes can contain multiple tuples for each logical row. This commit fixes this over-estimation by setting the row count of inverted filters to the distinct count of the primary key columns from the input. Fixes #120055 Release note (performance improvement): A bug has been fixed that caused the optimizer to over-estimate the cost of inverted index scans in some cases. Now, plans with inverted index scans should be selected in more cases where they are optimal. Co-authored-by: Marcus Gartner <[email protected]>
2 parents 3516ea0 + 45607bc commit 2e0b2f6

Some content is hidden

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

75 files changed

+789
-782
lines changed

pkg/ccl/logictestccl/testdata/logic_test/explain_redact

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ EXPLAIN (OPT, VERBOSE, REDACT) SELECT * FROM q WHERE q > 2
294294
scan q
295295
├── columns: q:1 r:2
296296
├── constraint: /1: ‹×›
297-
├── stats: [rows=333.3333, distinct(1)=333.333, null(1)=0]
297+
├── stats: [rows=333.333, distinct(1)=333.333, null(1)=0]
298298
├── cost: 378.02
299299
├── key: (1)
300300
├── fd: (1)-->(2)
@@ -307,7 +307,7 @@ EXPLAIN (OPT, TYPES, REDACT) SELECT * FROM q WHERE q > 2
307307
scan q
308308
├── columns: q:1(int!null) r:2(int)
309309
├── constraint: /1: ‹×›
310-
├── stats: [rows=333.3333, distinct(1)=333.333, null(1)=0]
310+
├── stats: [rows=333.333, distinct(1)=333.333, null(1)=0]
311311
├── cost: 378.02
312312
├── key: (1)
313313
├── fd: (1)-->(2)

pkg/ccl/logictestccl/testdata/logic_test/multi_region_remote_access_error

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ project
10791079
│ ├── key columns: [26 22] = [13 9]
10801080
│ ├── lookup columns are key
10811081
│ ├── immutable
1082-
│ ├── stats: [rows=3333.333]
1082+
│ ├── stats: [rows=3333.33]
10831083
│ ├── cost: 4309.11778
10841084
│ ├── fd: ()-->(13), (9)-->(11)
10851085
│ ├── limit hint: 1.00
@@ -1092,7 +1092,7 @@ project
10921092
│ │ ├── prefix key columns: [21] = [26]
10931093
│ │ ├── inverted-expr
10941094
│ │ │ └── t1.j:24 @> t2.j:3
1095-
│ │ ├── stats: [rows=3333.333, distinct(21)=1, null(21)=0, distinct(22)=964.524, null(22)=0, distinct(26)=1, null(26)=0]
1095+
│ │ ├── stats: [rows=3333.33, distinct(21)=1, null(21)=0, distinct(22)=964.524, null(22)=0, distinct(26)=1, null(26)=0]
10961096
│ │ ├── cost: 3837.19889
10971097
│ │ ├── fd: ()-->(26)
10981098
│ │ ├── limit hint: 100.00

pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_query_behavior

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3646,7 +3646,7 @@ WHERE
36463646
project
36473647
├── columns: str:12 id1:2 id2:5 created_at:3 updated_at:4 id1:21 id2:24 created_at:22 updated_at:23
36483648
├── immutable
3649-
├── stats: [rows=0.3666667]
3649+
├── stats: [rows=0.366667]
36503650
├── cost: 45.3262257
36513651
├── fd: ()-->(2,5,21,24), (3)==(22), (22)==(3), (5)==(24), (24)==(5), (4)==(23), (23)==(4), (2)==(21), (21)==(2)
36523652
├── distribution: ap-southeast-2
@@ -3655,7 +3655,7 @@ project
36553655
├── columns: a.id:1 a.id1:2 a.created_at:3 a.updated_at:4 a.id2:5 a.crdb_region:6 str:12 abc_id:13 x.id2:14 x.crdb_region:15 b.id:20 b.id1:21 b.created_at:22 b.updated_at:23 b.id2:24 b.crdb_region:25
36563656
├── key columns: [6 5] = [15 14]
36573657
├── immutable
3658-
├── stats: [rows=0.3666667, 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]
3658+
├── 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]
36593659
├── cost: 45.302559
36603660
├── 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)
36613661
├── distribution: ap-southeast-2
@@ -3665,7 +3665,7 @@ project
36653665
│ ├── key columns: [25 20] = [25 20]
36663666
│ ├── lookup columns are key
36673667
│ ├── immutable
3668-
│ ├── stats: [rows=0.1344445, 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]
3668+
│ ├── 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]
36693669
│ ├── cost: 34.9459129
36703670
│ ├── key: (20)
36713671
│ ├── 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)
@@ -3677,7 +3677,7 @@ project
36773677
│ │ ├── key columns: [6 2 5 1] = [25 21 24 20]
36783678
│ │ ├── lookup columns are key
36793679
│ │ ├── immutable
3680-
│ │ ├── stats: [rows=0.003666667, 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]
3680+
│ │ ├── 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]
36813681
│ │ ├── cost: 34.8283629
36823682
│ │ ├── key: (20)
36833683
│ │ ├── 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)
@@ -3687,7 +3687,7 @@ project
36873687
│ │ ├── index-join abc
36883688
│ │ │ ├── columns: a.id:1 a.id1:2 a.created_at:3 a.updated_at:4 a.id2:5 a.crdb_region:6
36893689
│ │ │ ├── immutable
3690-
│ │ │ ├── stats: [rows=0.3666667, distinct(1)=0.366667, null(1)=0, distinct(2)=0.366667, null(2)=0, distinct(3)=0.360675, null(3)=0, distinct(4)=0.360675, null(4)=0, distinct(5)=0.366667, null(5)=0, distinct(6)=0.366667, null(6)=0, distinct(2,5,6)=0.366667, null(2,5,6)=0]
3690+
│ │ │ ├── stats: [rows=0.366667, distinct(1)=0.366667, null(1)=0, distinct(2)=0.366667, null(2)=0, distinct(3)=0.360675, null(3)=0, distinct(4)=0.360675, null(4)=0, distinct(5)=0.366667, null(5)=0, distinct(6)=0.366667, null(6)=0, distinct(2,5,6)=0.366667, null(2,5,6)=0]
36913691
│ │ │ │ histogram(6)= 0 0.36667
36923692
│ │ │ │ <--- 'ap-southeast-2'
36933693
│ │ │ ├── cost: 33.2056672
@@ -3699,7 +3699,7 @@ project
36993699
│ │ │ └── scan abc@abc_id1_id2_idx [as=a]
37003700
│ │ │ ├── columns: a.id:1 a.id1:2 a.id2:5 a.crdb_region:6
37013701
│ │ │ ├── constraint: /6/2/5/1: [/'ap-southeast-2'/'6da4f356-e526-4b78-b9f9-bbb1a7fc12d6'/'68088706-02c6-47d1-b993-a421cd761f2b' - /'ap-southeast-2'/'6da4f356-e526-4b78-b9f9-bbb1a7fc12d6'/'68088706-02c6-47d1-b993-a421cd761f2b']
3702-
│ │ │ ├── stats: [rows=0.3666667, distinct(1)=0.366667, null(1)=0, distinct(2)=0.366667, null(2)=0, distinct(5)=0.366667, null(5)=0, distinct(6)=0.366667, null(6)=0, distinct(2,5,6)=0.366667, null(2,5,6)=0]
3702+
│ │ │ ├── stats: [rows=0.366667, distinct(1)=0.366667, null(1)=0, distinct(2)=0.366667, null(2)=0, distinct(5)=0.366667, null(5)=0, distinct(6)=0.366667, null(6)=0, distinct(2,5,6)=0.366667, null(2,5,6)=0]
37033703
│ │ │ │ histogram(6)= 0 0.36667
37043704
│ │ │ │ <--- 'ap-southeast-2'
37053705
│ │ │ ├── cost: 25.430667

pkg/sql/logictest/testdata/logic_test/prepare

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ EXECUTE e
11821182
select
11831183
├── columns: k:1 str:2
11841184
├── immutable
1185-
├── stats: [rows=333.3333]
1185+
├── stats: [rows=333.333]
11861186
├── cost: 1118.85
11871187
├── key: (1)
11881188
├── fd: (1)-->(2)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ group-by (streaming)
10261026
├── columns: b:2 count:7
10271027
├── grouping columns: b:2
10281028
├── internal-ordering: +2 opt(1)
1029-
├── stats: [rows=9.561793, distinct(2)=9.56179, null(2)=0]
1029+
├── stats: [rows=9.56179, distinct(2)=9.56179, null(2)=0]
10301030
├── cost: 29.145618
10311031
├── key: (2)
10321032
├── fd: (2)-->(7)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,14 @@ union
180180
├── interesting orderings: (+15)
181181
├── project
182182
│ ├── columns: nulls.x:1
183-
│ ├── stats: [rows=333.3333, distinct(1)=5, null(1)=3.33333]
183+
│ ├── stats: [rows=333.333, distinct(1)=5, null(1)=3.33333]
184184
│ ├── cost: 1142.40333
185185
│ ├── ordering: +1
186186
│ ├── distribution: test
187187
│ ├── interesting orderings: (+1)
188188
│ └── select
189189
│ ├── columns: nulls.x:1 y:2
190-
│ ├── stats: [rows=333.3333, distinct(1)=5, null(1)=3.33333, distinct(2)=33.3333, null(2)=0]
190+
│ ├── stats: [rows=333.333, distinct(1)=5, null(1)=3.33333, distinct(2)=33.3333, null(2)=0]
191191
│ ├── cost: 1139.05
192192
│ ├── ordering: +1
193193
│ ├── distribution: test
@@ -204,14 +204,14 @@ union
204204
│ └── y:2 < 0 [outer=(2), constraints=(/2: (/NULL - /-1]; tight)]
205205
└── project
206206
├── columns: nulls.x:8
207-
├── stats: [rows=333.3333, distinct(8)=5, null(8)=3.33333]
207+
├── stats: [rows=333.333, distinct(8)=5, null(8)=3.33333]
208208
├── cost: 1142.40333
209209
├── ordering: +8
210210
├── distribution: test
211211
├── interesting orderings: (+8)
212212
└── select
213213
├── columns: nulls.x:8 y:9
214-
├── stats: [rows=333.3333, distinct(8)=5, null(8)=3.33333, distinct(9)=33.3333, null(9)=0]
214+
├── stats: [rows=333.333, distinct(8)=5, null(8)=3.33333, distinct(9)=33.3333, null(9)=0]
215215
├── cost: 1139.05
216216
├── ordering: +8
217217
├── distribution: test

pkg/sql/opt/exec/execbuilder/testdata/explain

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,7 @@ EXPLAIN (OPT, VERBOSE) SELECT * FROM tc WHERE a + 2 * b > 1 ORDER BY a*b
17691769
distribute
17701770
├── columns: a:1 b:2 [hidden: column8:8]
17711771
├── immutable
1772-
├── stats: [rows=333.3333]
1772+
├── stats: [rows=333.333]
17731773
├── cost: 1418.32951
17741774
├── fd: (1,2)-->(8)
17751775
├── ordering: +8
@@ -1780,7 +1780,7 @@ distribute
17801780
└── sort
17811781
├── columns: a:1 b:2 column8:8
17821782
├── immutable
1783-
├── stats: [rows=333.3333]
1783+
├── stats: [rows=333.333]
17841784
├── cost: 1218.30951
17851785
├── fd: (1,2)-->(8)
17861786
├── ordering: +8
@@ -1789,15 +1789,15 @@ distribute
17891789
└── project
17901790
├── columns: column8:8 a:1 b:2
17911791
├── immutable
1792-
├── stats: [rows=333.3333]
1792+
├── stats: [rows=333.333]
17931793
├── cost: 1145.73667
17941794
├── fd: (1,2)-->(8)
17951795
├── prune: (1,2,8)
17961796
├── interesting orderings: (+1)
17971797
├── select
17981798
│ ├── columns: a:1 b:2
17991799
│ ├── immutable
1800-
│ ├── stats: [rows=333.3333]
1800+
│ ├── stats: [rows=333.333]
18011801
│ ├── cost: 1139.05
18021802
│ ├── interesting orderings: (+1)
18031803
│ ├── scan tc
@@ -1817,7 +1817,7 @@ EXPLAIN (OPT, VERBOSE, REDACT) SELECT * FROM tc WHERE a + 2 * b > 1 ORDER BY a*b
18171817
distribute
18181818
├── columns: a:1 b:2 [hidden: column8:8]
18191819
├── immutable
1820-
├── stats: [rows=333.3333]
1820+
├── stats: [rows=333.333]
18211821
├── cost: 1418.32951
18221822
├── fd: (1,2)-->(8)
18231823
├── ordering: +8
@@ -1828,7 +1828,7 @@ distribute
18281828
└── sort
18291829
├── columns: a:1 b:2 column8:8
18301830
├── immutable
1831-
├── stats: [rows=333.3333]
1831+
├── stats: [rows=333.333]
18321832
├── cost: 1218.30951
18331833
├── fd: (1,2)-->(8)
18341834
├── ordering: +8
@@ -1837,15 +1837,15 @@ distribute
18371837
└── project
18381838
├── columns: column8:8 a:1 b:2
18391839
├── immutable
1840-
├── stats: [rows=333.3333]
1840+
├── stats: [rows=333.333]
18411841
├── cost: 1145.73667
18421842
├── fd: (1,2)-->(8)
18431843
├── prune: (1,2,8)
18441844
├── interesting orderings: (+1)
18451845
├── select
18461846
│ ├── columns: a:1 b:2
18471847
│ ├── immutable
1848-
│ ├── stats: [rows=333.3333]
1848+
│ ├── stats: [rows=333.333]
18491849
│ ├── cost: 1139.05
18501850
│ ├── interesting orderings: (+1)
18511851
│ ├── scan tc
@@ -1865,7 +1865,7 @@ EXPLAIN (OPT, TYPES) SELECT * FROM tc WHERE a + 2 * b > 1 ORDER BY a*b
18651865
distribute
18661866
├── columns: a:1(int) b:2(int) [hidden: column8:8(int)]
18671867
├── immutable
1868-
├── stats: [rows=333.3333]
1868+
├── stats: [rows=333.333]
18691869
├── cost: 1418.32951
18701870
├── fd: (1,2)-->(8)
18711871
├── ordering: +8
@@ -1876,7 +1876,7 @@ distribute
18761876
└── sort
18771877
├── columns: a:1(int) b:2(int) column8:8(int)
18781878
├── immutable
1879-
├── stats: [rows=333.3333]
1879+
├── stats: [rows=333.333]
18801880
├── cost: 1218.30951
18811881
├── fd: (1,2)-->(8)
18821882
├── ordering: +8
@@ -1885,15 +1885,15 @@ distribute
18851885
└── project
18861886
├── columns: column8:8(int) a:1(int) b:2(int)
18871887
├── immutable
1888-
├── stats: [rows=333.3333]
1888+
├── stats: [rows=333.333]
18891889
├── cost: 1145.73667
18901890
├── fd: (1,2)-->(8)
18911891
├── prune: (1,2,8)
18921892
├── interesting orderings: (+1)
18931893
├── select
18941894
│ ├── columns: a:1(int) b:2(int)
18951895
│ ├── immutable
1896-
│ ├── stats: [rows=333.3333]
1896+
│ ├── stats: [rows=333.333]
18971897
│ ├── cost: 1139.05
18981898
│ ├── interesting orderings: (+1)
18991899
│ ├── scan tc
@@ -1921,7 +1921,7 @@ EXPLAIN (OPT, TYPES, REDACT) SELECT * FROM tc WHERE a + 2 * b > 1 ORDER BY a*b
19211921
distribute
19221922
├── columns: a:1(int) b:2(int) [hidden: column8:8(int)]
19231923
├── immutable
1924-
├── stats: [rows=333.3333]
1924+
├── stats: [rows=333.333]
19251925
├── cost: 1418.32951
19261926
├── fd: (1,2)-->(8)
19271927
├── ordering: +8
@@ -1932,7 +1932,7 @@ distribute
19321932
└── sort
19331933
├── columns: a:1(int) b:2(int) column8:8(int)
19341934
├── immutable
1935-
├── stats: [rows=333.3333]
1935+
├── stats: [rows=333.333]
19361936
├── cost: 1218.30951
19371937
├── fd: (1,2)-->(8)
19381938
├── ordering: +8
@@ -1941,15 +1941,15 @@ distribute
19411941
└── project
19421942
├── columns: column8:8(int) a:1(int) b:2(int)
19431943
├── immutable
1944-
├── stats: [rows=333.3333]
1944+
├── stats: [rows=333.333]
19451945
├── cost: 1145.73667
19461946
├── fd: (1,2)-->(8)
19471947
├── prune: (1,2,8)
19481948
├── interesting orderings: (+1)
19491949
├── select
19501950
│ ├── columns: a:1(int) b:2(int)
19511951
│ ├── immutable
1952-
│ ├── stats: [rows=333.3333]
1952+
│ ├── stats: [rows=333.333]
19531953
│ ├── cost: 1139.05
19541954
│ ├── interesting orderings: (+1)
19551955
│ ├── scan tc

0 commit comments

Comments
 (0)