Skip to content

Commit f678273

Browse files
committed
opt: fix incorrect column indexing in index recommendations
Fixes #83965 Release note (bug fix): A minor bug has been fixed that caused internal errors and poor index recommendations when running `EXPLAIN` statements.
1 parent 86e007d commit f678273

3 files changed

Lines changed: 136 additions & 57 deletions

File tree

pkg/sql/opt/indexrec/testdata/geospatial-index-candidates-recommendations

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ select
3434
├── immutable
3535
├── cost: 1054.09
3636
├── index-join t2
37-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
37+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
3838
│ ├── cost: 941.837778
3939
│ └── inverted-filter
4040
│ ├── columns: rowid:11!null
@@ -77,7 +77,7 @@ select
7777
│ ├── cost: 250.706667
7878
│ ├── key: (11)
7979
│ └── scan t2@_hyp_1
80-
│ ├── columns: rowid:11!null k:14!null
80+
│ ├── columns: rowid:11!null geom1_inverted_key:14!null
8181
│ ├── inverted constraint: /14/11
8282
│ │ └── spans
8383
│ │ ├── ["B\xfd\x10\x00\x00\x00\x00\x00\x00\x00", "B\xfd\x10\x00\x00\x00\x00\x00\x00\x00"]
@@ -136,7 +136,7 @@ select
136136
├── immutable
137137
├── cost: 1054.09
138138
├── index-join t2
139-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
139+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
140140
│ ├── cost: 941.837778
141141
│ └── inverted-filter
142142
│ ├── columns: rowid:11!null
@@ -179,7 +179,7 @@ select
179179
│ ├── cost: 250.706667
180180
│ ├── key: (11)
181181
│ └── scan t2@_hyp_1
182-
│ ├── columns: rowid:11!null k:14!null
182+
│ ├── columns: rowid:11!null geom2_inverted_key:14!null
183183
│ ├── inverted constraint: /14/11
184184
│ │ └── spans
185185
│ │ ├── ["B\xfd\x10\x00\x00\x00\x00\x00\x00\x00", "B\xfd\x10\x00\x00\x00\x00\x00\x00\x00"]
@@ -251,7 +251,7 @@ select
251251
├── immutable
252252
├── cost: 2246.15
253253
├── scan t2
254-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
254+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
255255
│ └── cost: 1236.12
256256
└── filters
257257
└── st_coveredby(geom1:4, geom2:8) [outer=(4,8), immutable, constraints=(/4: (/NULL - ]; /8: (/NULL - ])]
@@ -282,7 +282,7 @@ select
282282
├── immutable
283283
├── cost: 12054.09
284284
├── index-join t2
285-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
285+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
286286
│ ├── cost: 941.837778
287287
│ └── inverted-filter
288288
│ ├── columns: rowid:11!null
@@ -325,7 +325,7 @@ select
325325
│ ├── cost: 250.706667
326326
│ ├── key: (11)
327327
│ └── scan t2@_hyp_1
328-
│ ├── columns: rowid:11!null k:14!null
328+
│ ├── columns: rowid:11!null geom2_inverted_key:14!null
329329
│ ├── inverted constraint: /14/11
330330
│ │ └── spans
331331
│ │ ├── ["B\xfd\x10\x00\x00\x00\x00\x00\x00\x00", "B\xfd\x10\x00\x00\x00\x00\x00\x00\x00"]
@@ -383,7 +383,7 @@ select
383383
├── immutable
384384
├── cost: 101246.15
385385
├── scan t2
386-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
386+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
387387
│ └── cost: 1236.12
388388
└── filters
389389
└── st_containsproperly(geom1:4, geom2:8) [outer=(4,8), immutable, constraints=(/4: (/NULL - ]; /8: (/NULL - ])]
@@ -406,7 +406,7 @@ select
406406
├── immutable
407407
├── cost: 101246.15
408408
├── scan t2
409-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
409+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
410410
│ └── cost: 1236.12
411411
└── filters
412412
└── st_crosses(geom1:4, geom2:8) [outer=(4,8), immutable, constraints=(/4: (/NULL - ]; /8: (/NULL - ])]
@@ -444,7 +444,7 @@ select
444444
├── immutable
445445
├── cost: 12054.09
446446
├── index-join t2
447-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
447+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
448448
│ ├── cost: 941.837778
449449
│ └── inverted-filter
450450
│ ├── columns: rowid:11!null
@@ -487,7 +487,7 @@ select
487487
│ ├── cost: 250.706667
488488
│ ├── key: (11)
489489
│ └── scan t2@_hyp_1
490-
│ ├── columns: rowid:11!null k:14!null
490+
│ ├── columns: rowid:11!null geom1_inverted_key:14!null
491491
│ ├── inverted constraint: /14/11
492492
│ │ └── spans
493493
│ │ ├── ["B\xfd\x10\x00\x00\x00\x00\x00\x00\x00", "B\xfd\x10\x00\x00\x00\x00\x00\x00\x00"]
@@ -546,7 +546,7 @@ select
546546
├── immutable
547547
├── cost: 1058.09
548548
├── index-join t2
549-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
549+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
550550
│ ├── cost: 945.837778
551551
│ └── inverted-filter
552552
│ ├── columns: rowid:11!null
@@ -590,7 +590,7 @@ select
590590
│ ├── cost: 254.706667
591591
│ ├── key: (11)
592592
│ └── scan t2@_hyp_1
593-
│ ├── columns: rowid:11!null k:14!null
593+
│ ├── columns: rowid:11!null geom1_inverted_key:14!null
594594
│ ├── inverted constraint: /14/11
595595
│ │ └── spans
596596
│ │ ├── ["B\xfd\x10\x00\x00\x00\x00\x00\x00\x00", "B\xfd\x10\x00\x00\x00\x00\x00\x00\x00"]
@@ -649,7 +649,7 @@ select
649649
├── immutable
650650
├── cost: 101246.15
651651
├── scan t2
652-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
652+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
653653
│ └── cost: 1236.12
654654
└── filters
655655
└── st_overlaps(geom1:4, geom2:8) [outer=(4,8), immutable, constraints=(/4: (/NULL - ]; /8: (/NULL - ])]
@@ -693,7 +693,7 @@ select
693693
├── immutable
694694
├── cost: 926.978889
695695
├── index-join t2
696-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
696+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
697697
│ ├── cost: 925.837778
698698
│ └── inverted-filter
699699
│ ├── columns: rowid:11!null
@@ -732,7 +732,7 @@ select
732732
│ ├── cost: 234.706667
733733
│ ├── key: (11)
734734
│ └── scan t2@_hyp_1
735-
│ ├── columns: rowid:11!null k:14!null
735+
│ ├── columns: rowid:11!null geog2_inverted_key:14!null
736736
│ ├── inverted constraint: /14/11
737737
│ │ └── spans
738738
│ │ ├── ["B\xfdL\x00\x00\x00\x00\x00\x00\x00", "B\xfdL\x00\x00\x00\x00\x00\x00\x00"]
@@ -786,7 +786,7 @@ select
786786
├── immutable
787787
├── cost: 1246.15
788788
├── scan t2
789-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
789+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
790790
│ └── cost: 1236.12
791791
└── filters
792792
└── st_dwithinexclusive(geog1:5, geog2:9, 10.0) [outer=(5,9), immutable, constraints=(/5: (/NULL - ]; /9: (/NULL - ])]
@@ -824,7 +824,7 @@ select
824824
├── immutable
825825
├── cost: 1221.85
826826
├── scan t2@_hyp_1
827-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6!null bbox2:7 geom2:8 geog2:9 inet1:10
827+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6!null bbox2:7 geom2:8 geog2:9 inet1:10
828828
│ ├── constraint: /6/11: (/NULL - ]
829829
│ └── cost: 1211.92
830830
└── filters
@@ -855,7 +855,7 @@ select
855855
├── immutable
856856
├── cost: 946.988889
857857
├── index-join t2
858-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
858+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
859859
│ ├── cost: 945.837778
860860
│ └── inverted-filter
861861
│ ├── columns: rowid:11!null
@@ -899,7 +899,7 @@ select
899899
│ ├── cost: 254.706667
900900
│ ├── key: (11)
901901
│ └── scan t2@_hyp_3
902-
│ ├── columns: rowid:11!null k:14!null
902+
│ ├── columns: rowid:11!null geom1_inverted_key:14!null
903903
│ ├── inverted constraint: /14/11
904904
│ │ └── spans
905905
│ │ ├── ["B\xfd\x10\x00\x00\x00\x00\x00\x00\x00", "B\xfd\x10\x00\x00\x00\x00\x00\x00\x00"]
@@ -1055,7 +1055,7 @@ select
10551055
├── immutable
10561056
├── cost: 23165.2111
10571057
├── index-join t2
1058-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
1058+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
10591059
│ ├── cost: 941.837778
10601060
│ └── inverted-filter
10611061
│ ├── columns: rowid:11!null
@@ -1098,7 +1098,7 @@ select
10981098
│ ├── cost: 250.706667
10991099
│ ├── key: (11)
11001100
│ └── scan t2@_hyp_1
1101-
│ ├── columns: rowid:11!null k:14!null
1101+
│ ├── columns: rowid:11!null geom1_inverted_key:14!null
11021102
│ ├── inverted constraint: /14/11
11031103
│ │ └── spans
11041104
│ │ ├── ["B\xfd\x10\x00\x00\x00\x00\x00\x00\x00", "B\xfd\x10\x00\x00\x00\x00\x00\x00\x00"]
@@ -1162,7 +1162,7 @@ select
11621162
├── cost: 133.301112
11631163
├── fd: ()-->(1)
11641164
├── index-join t2
1165-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
1165+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
11661166
│ ├── cost: 22.148889
11671167
│ └── inverted-filter
11681168
│ ├── columns: rowid:11!null
@@ -1205,7 +1205,7 @@ select
12051205
│ ├── cost: 15.2177778
12061206
│ ├── key: (11)
12071207
│ └── scan t2@_hyp_3
1208-
│ ├── columns: rowid:11!null k:15!null
1208+
│ ├── columns: rowid:11!null geom1_inverted_key:15!null
12091209
│ ├── constraint: /1: [/2 - /2]
12101210
│ ├── inverted constraint: /15/11
12111211
│ │ └── spans
@@ -1267,7 +1267,7 @@ select
12671267
├── immutable
12681268
├── cost: 12054.1
12691269
├── index-join t2
1270-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
1270+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
12711271
│ ├── cost: 941.837778
12721272
│ └── inverted-filter
12731273
│ ├── columns: rowid:11!null
@@ -1310,7 +1310,7 @@ select
13101310
│ ├── cost: 250.706667
13111311
│ ├── key: (11)
13121312
│ └── scan t2@_hyp_2
1313-
│ ├── columns: rowid:11!null k:14!null
1313+
│ ├── columns: rowid:11!null geom1_inverted_key:14!null
13141314
│ ├── inverted constraint: /14/11
13151315
│ │ └── spans
13161316
│ │ ├── ["B\xfd\x10\x00\x00\x00\x00\x00\x00\x00", "B\xfd\x10\x00\x00\x00\x00\x00\x00\x00"]
@@ -1349,7 +1349,7 @@ select
13491349
│ └── fd: (11)-->(14)
13501350
└── filters
13511351
├── st_overlaps(geom1:4, '01010000C00000000000000000000000000000000000000000000000000000000000000000') [outer=(4), immutable, constraints=(/4: (/NULL - ])]
1352-
└── t2.k:1 > 2 [outer=(1), constraints=(/1: [/3 - ]; tight)]
1352+
└── k:1 > 2 [outer=(1), constraints=(/1: [/3 - ]; tight)]
13531353

13541354
# 4.Geospatial inverted + EQ + EQ: combined index (inverted + equal, inverted +
13551355
# equal group, equal group candidates)
@@ -1385,7 +1385,7 @@ inner-join (zigzag t2@_hyp_1 t2@_hyp_2)
13851385
├── fd: ()-->(1,2)
13861386
└── filters
13871387
├── st_overlaps(geom1:4, '01010000C00000000000000000000000000000000000000000000000000000000000000000') [outer=(4), immutable, constraints=(/4: (/NULL - ])]
1388-
├── t2.k:1 = 2 [outer=(1), constraints=(/1: [/2 - /2]; tight), fd=()-->(1)]
1388+
├── k:1 = 2 [outer=(1), constraints=(/1: [/2 - /2]; tight), fd=()-->(1)]
13891389
└── i:2 = 3 [outer=(2), constraints=(/2: [/3 - /3]; tight), fd=()-->(2)]
13901390

13911391
# 5. Geospatial inverted + R + R: combined index (inverted + equal, inverted +
@@ -1411,7 +1411,7 @@ select
14111411
├── immutable
14121412
├── cost: 12054.11
14131413
├── index-join t2
1414-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
1414+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
14151415
│ ├── cost: 941.837778
14161416
│ └── inverted-filter
14171417
│ ├── columns: rowid:11!null
@@ -1454,7 +1454,7 @@ select
14541454
│ ├── cost: 250.706667
14551455
│ ├── key: (11)
14561456
│ └── scan t2@_hyp_3
1457-
│ ├── columns: rowid:11!null k:14!null
1457+
│ ├── columns: rowid:11!null geom1_inverted_key:14!null
14581458
│ ├── inverted constraint: /14/11
14591459
│ │ └── spans
14601460
│ │ ├── ["B\xfd\x10\x00\x00\x00\x00\x00\x00\x00", "B\xfd\x10\x00\x00\x00\x00\x00\x00\x00"]
@@ -1493,7 +1493,7 @@ select
14931493
│ └── fd: (11)-->(14)
14941494
└── filters
14951495
├── st_overlaps(geom1:4, '01010000C00000000000000000000000000000000000000000000000000000000000000000') [outer=(4), immutable, constraints=(/4: (/NULL - ])]
1496-
├── t2.k:1 > 2 [outer=(1), constraints=(/1: [/3 - ]; tight)]
1496+
├── k:1 > 2 [outer=(1), constraints=(/1: [/3 - ]; tight)]
14971497
└── i:2 > 3 [outer=(2), constraints=(/2: [/4 - ]; tight)]
14981498

14991499
# 6. Geospatial inverted + EQ + R: combined index (inverted + equal, equal +
@@ -1607,7 +1607,7 @@ select
16071607
├── cost: 22.1900001
16081608
├── fd: ()-->(1)
16091609
├── index-join t2
1610-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
1610+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
16111611
│ ├── cost: 22.148889
16121612
│ └── inverted-filter
16131613
│ ├── columns: rowid:11!null
@@ -1651,7 +1651,7 @@ select
16511651
│ ├── cost: 15.2177778
16521652
│ ├── key: (11)
16531653
│ └── scan t2@_hyp_3
1654-
│ ├── columns: rowid:11!null k:15!null
1654+
│ ├── columns: rowid:11!null geom1_inverted_key:15!null
16551655
│ ├── constraint: /1: [/2 - /2]
16561656
│ ├── inverted constraint: /15/11
16571657
│ │ └── spans
@@ -1716,7 +1716,7 @@ select
17161716
├── immutable
17171717
├── cost: 420.726667
17181718
├── scan t2@_hyp_3
1719-
│ ├── columns: t2.k:1!null i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
1719+
│ ├── columns: k:1!null i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
17201720
│ ├── constraint: /1/11: [/3 - ]
17211721
│ └── cost: 417.353333
17221722
└── filters
@@ -1743,11 +1743,11 @@ select
17431743
├── immutable
17441744
├── cost: 2246.16
17451745
├── scan t2
1746-
│ ├── columns: t2.k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
1746+
│ ├── columns: k:1 i:2 s:3 geom1:4 geog1:5 bbox1:6 bbox2:7 geom2:8 geog2:9 inet1:10
17471747
│ └── cost: 1236.12
17481748
└── filters
17491749
├── st_covers(geom1:4, geom2:8) [outer=(4,8), immutable, constraints=(/4: (/NULL - ]; /8: (/NULL - ])]
1750-
└── (~t2.k:1) = 1 [outer=(1), immutable]
1750+
└── (~k:1) = 1 [outer=(1), immutable]
17511751

17521752
# 16. Geospatial Inverted + J + EQ: combined index between join + equal,
17531753
# inverted + equal

0 commit comments

Comments
 (0)