diff --git a/pkg/sql/logictest/testdata/logic_test/prepare b/pkg/sql/logictest/testdata/logic_test/prepare index 1eef588e572a..d84870242195 100644 --- a/pkg/sql/logictest/testdata/logic_test/prepare +++ b/pkg/sql/logictest/testdata/logic_test/prepare @@ -1141,7 +1141,7 @@ EXECUTE e select ├── columns: k:1 str:2 ├── stats: [rows=333.333333] - ├── cost: 1050.03 + ├── cost: 1050.04 ├── key: (1) ├── fd: (1)-->(2) ├── prune: (2) diff --git a/pkg/sql/opt/exec/execbuilder/testdata/explain b/pkg/sql/opt/exec/execbuilder/testdata/explain index fee73c0136ec..a56857f5875d 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/explain +++ b/pkg/sql/opt/exec/execbuilder/testdata/explain @@ -987,7 +987,7 @@ EXPLAIN (OPT, VERBOSE) SELECT * FROM tc WHERE a + 2 * b > 1 ORDER BY a*b sort ├── columns: a:1 b:2 [hidden: column4:4] ├── stats: [rows=333.333333] - ├── cost: 1179.25548 + ├── cost: 1179.26548 ├── fd: (1,2)-->(4) ├── ordering: +4 ├── prune: (1,2,4) @@ -995,14 +995,14 @@ sort └── project ├── columns: column4:4 a:1 b:2 ├── stats: [rows=333.333333] - ├── cost: 1116.70667 + ├── cost: 1116.71667 ├── fd: (1,2)-->(4) ├── prune: (1,2,4) ├── interesting orderings: (+1) ├── select │ ├── columns: a:1 b:2 │ ├── stats: [rows=333.333333] - │ ├── cost: 1110.03 + │ ├── cost: 1110.04 │ ├── interesting orderings: (+1) │ ├── scan tc │ │ ├── columns: a:1 b:2 @@ -1021,7 +1021,7 @@ EXPLAIN (OPT, TYPES) SELECT * FROM tc WHERE a + 2 * b > 1 ORDER BY a*b sort ├── columns: a:1(int) b:2(int) [hidden: column4:4(int)] ├── stats: [rows=333.333333] - ├── cost: 1179.25548 + ├── cost: 1179.26548 ├── fd: (1,2)-->(4) ├── ordering: +4 ├── prune: (1,2,4) @@ -1029,14 +1029,14 @@ sort └── project ├── columns: column4:4(int) a:1(int) b:2(int) ├── stats: [rows=333.333333] - ├── cost: 1116.70667 + ├── cost: 1116.71667 ├── fd: (1,2)-->(4) ├── prune: (1,2,4) ├── interesting orderings: (+1) ├── select │ ├── columns: a:1(int) b:2(int) │ ├── stats: [rows=333.333333] - │ ├── cost: 1110.03 + │ ├── cost: 1110.04 │ ├── interesting orderings: (+1) │ ├── scan tc │ │ ├── columns: a:1(int) b:2(int) diff --git a/pkg/sql/opt/memo/statistics_builder.go b/pkg/sql/opt/memo/statistics_builder.go index 83668d8e93fc..b7827462923e 100644 --- a/pkg/sql/opt/memo/statistics_builder.go +++ b/pkg/sql/opt/memo/statistics_builder.go @@ -2358,6 +2358,30 @@ func (sb *statisticsBuilder) rowsProcessed(e RelExpr) float64 { withoutOn := e.Memo().MemoizeLookupJoin(t.Input, nil /* on */, lookupJoinPrivate) return withoutOn.Relational().Stats.RowCount + case *GeoLookupJoinExpr: + var lookupJoinPrivate *GeoLookupJoinPrivate + switch t.JoinType { + case opt.SemiJoinOp, opt.SemiJoinApplyOp, opt.AntiJoinOp, opt.AntiJoinApplyOp: + // The number of rows processed for semi and anti joins is closer to the + // number of output rows for an equivalent inner join. + copy := t.GeoLookupJoinPrivate + copy.JoinType = semiAntiJoinToInnerJoin(t.JoinType) + lookupJoinPrivate = © + + default: + if t.On.IsTrue() { + // If there are no additional ON filters, the number of rows processed + // equals the number of output rows. + return e.Relational().Stats.RowCount + } + lookupJoinPrivate = &t.GeoLookupJoinPrivate + } + + // We need to determine the row count of the join before the + // ON conditions are applied. + withoutOn := e.Memo().MemoizeGeoLookupJoin(t.Input, nil /* on */, lookupJoinPrivate) + return withoutOn.Relational().Stats.RowCount + case *MergeJoinExpr: var mergeJoinPrivate *MergeJoinPrivate switch t.JoinType { diff --git a/pkg/sql/opt/memo/testdata/format b/pkg/sql/opt/memo/testdata/format index db05c0fc99dc..d6c89c5510aa 100644 --- a/pkg/sql/opt/memo/testdata/format +++ b/pkg/sql/opt/memo/testdata/format @@ -8,7 +8,7 @@ SELECT a + 1, min(b) FROM t WHERE k + a > b GROUP BY a ORDER BY a sort ├── columns: "?column?":5(int) min:4(int!null) [hidden: t.public.t.a:1(int)] ├── stats: [rows=98.1771622] - ├── cost: 1097.87224 + ├── cost: 1097.88224 ├── key: (1) ├── fd: (1)-->(4,5) ├── ordering: +1 @@ -16,7 +16,7 @@ sort └── project ├── columns: "?column?":5(int) t.public.t.a:1(int) min:4(int!null) ├── stats: [rows=98.1771622] - ├── cost: 1082.90531 + ├── cost: 1082.91531 ├── key: (1) ├── fd: (1)-->(4,5) ├── prune: (1,4,5) @@ -24,14 +24,14 @@ sort │ ├── columns: t.public.t.a:1(int) min:4(int!null) │ ├── grouping columns: t.public.t.a:1(int) │ ├── stats: [rows=98.1771622, distinct(1)=98.1771622, null(1)=1] - │ ├── cost: 1080.93177 + │ ├── cost: 1080.94177 │ ├── key: (1) │ ├── fd: (1)-->(4) │ ├── prune: (4) │ ├── select │ │ ├── columns: t.public.t.a:1(int) t.public.t.b:2(int!null) t.public.t.k:3(int!null) │ │ ├── stats: [rows=330, distinct(1)=98.1771622, null(1)=3.3, distinct(2)=100, null(2)=0] - │ │ ├── cost: 1070.03 + │ │ ├── cost: 1070.04 │ │ ├── key: (3) │ │ ├── fd: (3)-->(1,2) │ │ ├── interesting orderings: (+3) @@ -63,21 +63,21 @@ SELECT a + 1, min(b) FROM t WHERE k + a > b GROUP BY a ORDER BY a sort ├── columns: "?column?":5(int) min:4(int!null) [hidden: t.public.t.a:1(int)] ├── stats: [rows=98.1771622] - ├── cost: 1097.87224 + ├── cost: 1097.88224 ├── ordering: +1 └── project ├── columns: "?column?":5(int) t.public.t.a:1(int) min:4(int!null) ├── stats: [rows=98.1771622] - ├── cost: 1082.90531 + ├── cost: 1082.91531 ├── group-by │ ├── columns: t.public.t.a:1(int) min:4(int!null) │ ├── grouping columns: t.public.t.a:1(int) │ ├── stats: [rows=98.1771622, distinct(1)=98.1771622, null(1)=1] - │ ├── cost: 1080.93177 + │ ├── cost: 1080.94177 │ ├── select │ │ ├── columns: t.public.t.a:1(int) t.public.t.b:2(int!null) t.public.t.k:3(int!null) │ │ ├── stats: [rows=330, distinct(1)=98.1771622, null(1)=3.3, distinct(2)=100, null(2)=0] - │ │ ├── cost: 1070.03 + │ │ ├── cost: 1070.04 │ │ ├── scan t.public.t │ │ │ ├── columns: t.public.t.a:1(int) t.public.t.b:2(int) t.public.t.k:3(int!null) │ │ │ ├── stats: [rows=1000, distinct(1)=100, null(1)=10, distinct(2)=100, null(2)=10] @@ -257,25 +257,25 @@ SELECT a + 1, min(b) FROM t WHERE k + a > b GROUP BY a ORDER BY a ---- sort ├── stats: [rows=98.1771622] - ├── cost: 1097.87224 + ├── cost: 1097.88224 ├── key: (1) ├── fd: (1)-->(4,5) ├── prune: (1,4,5) └── project ├── stats: [rows=98.1771622] - ├── cost: 1082.90531 + ├── cost: 1082.91531 ├── key: (1) ├── fd: (1)-->(4,5) ├── prune: (1,4,5) ├── group-by │ ├── stats: [rows=98.1771622, distinct(1)=98.1771622, null(1)=1] - │ ├── cost: 1080.93177 + │ ├── cost: 1080.94177 │ ├── key: (1) │ ├── fd: (1)-->(4) │ ├── prune: (4) │ ├── select │ │ ├── stats: [rows=330, distinct(1)=98.1771622, null(1)=3.3, distinct(2)=100, null(2)=0] - │ │ ├── cost: 1070.03 + │ │ ├── cost: 1070.04 │ │ ├── key: (3) │ │ ├── fd: (3)-->(1,2) │ │ ├── interesting orderings: (+3) diff --git a/pkg/sql/opt/memo/testdata/memo b/pkg/sql/opt/memo/testdata/memo index b4be9f94dbbe..fb35405a1def 100644 --- a/pkg/sql/opt/memo/testdata/memo +++ b/pkg/sql/opt/memo/testdata/memo @@ -123,37 +123,37 @@ memo (optimized, ~18KB, required=[presentation: y:2,x:3,c:6] [ordering: +2]) ├── G1: (project G2 G3 y x) │ ├── [presentation: y:2,x:3,c:6] [ordering: +2] │ │ ├── best: (project G2="[ordering: +2]" G3 y x) - │ │ └── cost: 1722.59 + │ │ └── cost: 1722.60 │ └── [] │ ├── best: (project G2 G3 y x) - │ └── cost: 1722.59 + │ └── cost: 1722.60 ├── G2: (limit G4 G5 ordering=+2) │ ├── [ordering: +2] │ │ ├── best: (limit G4="[ordering: +2] [limit hint: 10.00]" G5 ordering=+2) - │ │ └── cost: 1722.38 + │ │ └── cost: 1722.39 │ └── [] │ ├── best: (limit G4="[ordering: +2] [limit hint: 10.00]" G5 ordering=+2) - │ └── cost: 1722.38 + │ └── cost: 1722.39 ├── G3: (projections G6) ├── G4: (inner-join G7 G8 G9) (inner-join G8 G7 G9) (lookup-join G7 G10 b,keyCols=[5],outCols=(2,3,5)) (merge-join G8 G7 G10 inner-join,+3,+5) │ ├── [ordering: +2] [limit hint: 10.00] │ │ ├── best: (lookup-join G7="[ordering: +2] [limit hint: 100.00]" G10 b,keyCols=[5],outCols=(2,3,5)) - │ │ └── cost: 1722.27 + │ │ └── cost: 1722.28 │ └── [] │ ├── best: (inner-join G8 G7 G9) - │ └── cost: 2108.40 + │ └── cost: 2108.41 ├── G5: (const 10) ├── G6: (plus G11 G12) ├── G7: (project G13 G14 y) │ ├── [ordering: +2] [limit hint: 100.00] │ │ ├── best: (sort G7) - │ │ └── cost: 1119.26 + │ │ └── cost: 1119.27 │ ├── [ordering: +5] │ │ ├── best: (sort G7) - │ │ └── cost: 1119.26 + │ │ └── cost: 1119.27 │ └── [] │ ├── best: (project G13 G14 y) - │ └── cost: 1056.71 + │ └── cost: 1056.72 ├── G8: (scan b,cols=(3)) │ ├── [ordering: +3] │ │ ├── best: (scan b,cols=(3)) @@ -168,10 +168,10 @@ memo (optimized, ~18KB, required=[presentation: y:2,x:3,c:6] [ordering: +2]) ├── G13: (select G16 G17) │ ├── [ordering: +2] [limit hint: 100.00] │ │ ├── best: (sort G13) - │ │ └── cost: 1112.58 + │ │ └── cost: 1112.59 │ └── [] │ ├── best: (select G16 G17) - │ └── cost: 1050.03 + │ └── cost: 1050.04 ├── G14: (projections G18) ├── G15: (eq G19 G20) ├── G16: (scan a) @@ -198,11 +198,11 @@ memo (optimized, ~4KB, required=[presentation: a:3,b:4,c:5,d:6]) ├── G1: (project G2 G3) │ └── [presentation: a:3,b:4,c:5,d:6] │ ├── best: (project G2 G3) - │ └── cost: 1050.21 + │ └── cost: 1050.23 ├── G2: (select G4 G5) │ └── [] │ ├── best: (select G4 G5) - │ └── cost: 1050.03 + │ └── cost: 1050.05 ├── G3: (projections G6 G7 G8 G9) ├── G4: (scan b) │ └── [] @@ -233,11 +233,11 @@ memo (optimized, ~5KB, required=[presentation: x:1]) ├── G1: (project G2 G3 x) │ └── [presentation: x:1] │ ├── best: (project G2 G3 x) - │ └── cost: 1.09 + │ └── cost: 1.10 ├── G2: (select G4 G5) (select G6 G7) │ └── [] │ ├── best: (select G6 G7) - │ └── cost: 1.07 + │ └── cost: 1.08 ├── G3: (projections) ├── G4: (scan a) │ └── [] diff --git a/pkg/sql/opt/norm/testdata/rules/combo b/pkg/sql/opt/norm/testdata/rules/combo index d70f4166a15d..261a7804acec 100644 --- a/pkg/sql/opt/norm/testdata/rules/combo +++ b/pkg/sql/opt/norm/testdata/rules/combo @@ -110,7 +110,7 @@ SimplifyJoinFilters + └── i:2 = 9 [outer=(2), constraints=(/2: [/9 - /9]; tight), fd=()-->(2)] ================================================================================ PushFilterIntoJoinLeft - Cost: 2167.90 + Cost: 2167.91 ================================================================================ project ├── columns: s:4 @@ -141,7 +141,7 @@ PushFilterIntoJoinLeft + └── k:1 = x:6 [outer=(1,6), constraints=(/1: (/NULL - ]; /6: (/NULL - ]), fd=(1)==(6), (6)==(1)] ================================================================================ PruneJoinLeftCols - Cost: 2168.01 + Cost: 2168.02 ================================================================================ project ├── columns: s:4 @@ -182,7 +182,7 @@ PruneJoinLeftCols └── k:1 = x:6 [outer=(1,6), constraints=(/1: (/NULL - ]; /6: (/NULL - ]), fd=(1)==(6), (6)==(1)] ================================================================================ PruneSelectCols - Cost: 2148.01 + Cost: 2148.02 ================================================================================ project ├── columns: s:4 @@ -216,7 +216,7 @@ PruneSelectCols └── k:1 = x:6 [outer=(1,6), constraints=(/1: (/NULL - ]; /6: (/NULL - ]), fd=(1)==(6), (6)==(1)] ================================================================================ EliminateProject - Cost: 2147.90 + Cost: 2147.91 ================================================================================ project ├── columns: s:4 @@ -253,7 +253,7 @@ EliminateProject └── k:1 = x:6 [outer=(1,6), constraints=(/1: (/NULL - ]; /6: (/NULL - ]), fd=(1)==(6), (6)==(1)] ================================================================================ PruneJoinRightCols - Cost: 2137.90 + Cost: 2137.91 ================================================================================ project ├── columns: s:4 @@ -323,7 +323,7 @@ CommuteJoin └── k:1 = x:6 [outer=(1,6), constraints=(/1: (/NULL - ]; /6: (/NULL - ]), fd=(1)==(6), (6)==(1)] ================================================================================ GenerateMergeJoins - Cost: 2130.37 + Cost: 2130.38 ================================================================================ project ├── columns: s:4 @@ -359,7 +359,7 @@ GenerateMergeJoins + └── filters (true) ================================================================================ GenerateLookupJoins - Cost: 1150.45 + Cost: 1150.46 ================================================================================ project ├── columns: s:4 @@ -461,7 +461,7 @@ GenerateLookupJoinsWithFilter (higher cost) + └── i:2 = 9 [outer=(2), constraints=(/2: [/9 - /9]; tight), fd=()-->(2)] ================================================================================ Final best expression - Cost: 1150.45 + Cost: 1150.46 ================================================================================ project ├── columns: s:4 @@ -489,7 +489,7 @@ SELECT s, k FROM a WHERE s='foo' AND f>100 ---- ================================================================================ Initial expression - Cost: 1110.07 + Cost: 1110.08 ================================================================================ project ├── columns: s:4!null k:1!null @@ -507,7 +507,7 @@ Initial expression └── (s:4 = 'foo') AND (f:3 > 100.0) [outer=(3,4), constraints=(/3: [/100.00000000000001 - ]; /4: [/'foo' - /'foo']; tight), fd=()-->(4)] ================================================================================ SimplifySelectFilters - Cost: 1110.07 + Cost: 1110.09 ================================================================================ project ├── columns: s:4!null k:1!null @@ -527,7 +527,7 @@ SimplifySelectFilters + └── f:3 > 100.0 [outer=(3), constraints=(/3: [/100.00000000000001 - ]; tight)] ================================================================================ PruneSelectCols - Cost: 1090.07 + Cost: 1090.09 ================================================================================ project ├── columns: s:4!null k:1!null @@ -550,7 +550,7 @@ PruneSelectCols └── f:3 > 100.0 [outer=(3), constraints=(/3: [/100.00000000000001 - ]; tight)] ================================================================================ GenerateIndexScans - Cost: 1080.07 + Cost: 1080.09 ================================================================================ project ├── columns: s:4!null k:1!null @@ -613,7 +613,7 @@ SELECT * FROM a WHERE EXISTS(SELECT * FROM xy WHERE y=i) ---- ================================================================================ Initial expression - Cost: 2160.06 + Cost: 2160.08 ================================================================================ select ├── columns: k:1!null i:2 f:3 s:4 j:5 @@ -638,7 +638,7 @@ Initial expression └── y:7 = i:2 [outer=(2,7), constraints=(/2: (/NULL - ]; /7: (/NULL - ]), fd=(2)==(7), (7)==(2)] ================================================================================ HoistSelectExists - Cost: 12089.90 + Cost: 12089.91 ================================================================================ select ├── columns: k:1!null i:2 f:3 s:4 j:5 @@ -888,7 +888,7 @@ SELECT 5=ANY(SELECT i FROM a WHERE k=x) AS r FROM xy ---- ================================================================================ Initial expression - Cost: 2170.08 + Cost: 2170.09 ================================================================================ project ├── columns: r:8 @@ -919,7 +919,7 @@ Initial expression └── 5 ================================================================================ PruneSelectCols - Cost: 2140.08 + Cost: 2140.09 ================================================================================ project ├── columns: r:8 @@ -954,7 +954,7 @@ PruneSelectCols └── 5 ================================================================================ PruneScanCols - Cost: 2130.08 + Cost: 2130.09 ================================================================================ project ├── columns: r:8 @@ -987,7 +987,7 @@ PruneScanCols └── 5 ================================================================================ HoistProjectSubquery - Cost: 2152.71 + Cost: 2152.73 ================================================================================ project ├── columns: r:8 @@ -1077,7 +1077,7 @@ HoistProjectSubquery + └── case:11 [as=r:8, outer=(11)] ================================================================================ CommuteVar - Cost: 2152.71 + Cost: 2152.73 ================================================================================ project ├── columns: r:8 @@ -1145,7 +1145,7 @@ CommuteVar └── case:11 [as=r:8, outer=(11)] ================================================================================ PushSelectIntoProject - Cost: 2152.71 + Cost: 2152.73 ================================================================================ project ├── columns: r:8 @@ -1225,7 +1225,7 @@ PushSelectIntoProject └── case:11 [as=r:8, outer=(11)] ================================================================================ MergeSelects - Cost: 2152.73 + Cost: 2152.75 ================================================================================ project ├── columns: r:8 @@ -1303,7 +1303,7 @@ MergeSelects └── case:11 [as=r:8, outer=(11)] ================================================================================ EliminateSelect - Cost: 2152.71 + Cost: 2152.73 ================================================================================ project ├── columns: r:8 @@ -1384,7 +1384,7 @@ EliminateSelect └── case:11 [as=r:8, outer=(11)] ================================================================================ MergeProjects - Cost: 2152.69 + Cost: 2152.71 ================================================================================ project ├── columns: r:8 @@ -1454,7 +1454,7 @@ MergeProjects └── case:11 [as=r:8, outer=(11)] ================================================================================ FoldNonNullIsNotNull - Cost: 2152.69 + Cost: 2152.71 ================================================================================ project ├── columns: r:8 @@ -1509,7 +1509,7 @@ FoldNonNullIsNotNull └── case:11 [as=r:8, outer=(11)] ================================================================================ SimplifyAndTrue - Cost: 2152.69 + Cost: 2152.71 ================================================================================ project ├── columns: r:8 @@ -1564,7 +1564,7 @@ SimplifyAndTrue └── case:11 [as=r:8, outer=(11)] ================================================================================ TryDecorrelateProject - Cost: 2182.68 + Cost: 2182.70 ================================================================================ project ├── columns: r:8 @@ -1654,7 +1654,7 @@ TryDecorrelateProject └── case:11 [as=r:8, outer=(11)] ================================================================================ TryDecorrelateScalarGroupBy - Cost: 2242.68 + Cost: 2242.70 ================================================================================ project ├── columns: r:8 @@ -1899,7 +1899,7 @@ DecorrelateJoin └── case:11 [as=r:8, outer=(11)] ================================================================================ PushFilterIntoJoinRight - Cost: 2278.48 + Cost: 2278.49 ================================================================================ project ├── columns: r:8 @@ -1971,7 +1971,7 @@ PushFilterIntoJoinRight └── case:11 [as=r:8, outer=(11)] ================================================================================ PushSelectIntoProject - Cost: 2268.49 + Cost: 2268.50 ================================================================================ project ├── columns: r:8 @@ -2043,7 +2043,7 @@ PushSelectIntoProject └── case:11 [as=r:8, outer=(11)] ================================================================================ EliminateSelect - Cost: 2265.15 + Cost: 2265.16 ================================================================================ project ├── columns: r:8 @@ -2122,7 +2122,7 @@ EliminateSelect └── case:11 [as=r:8, outer=(11)] ================================================================================ PruneJoinRightCols - Cost: 2265.15 + Cost: 2265.16 ================================================================================ project ├── columns: r:8 @@ -2189,7 +2189,7 @@ PruneJoinRightCols └── case:11 [as=r:8, outer=(11)] ================================================================================ EliminateGroupByProject - Cost: 2255.14 + Cost: 2255.15 ================================================================================ project ├── columns: r:8 @@ -2277,7 +2277,7 @@ EliminateGroupByProject └── case:11 [as=r:8, outer=(11)] ================================================================================ EliminateProject - Cost: 2245.13 + Cost: 2245.14 ================================================================================ project ├── columns: r:8 @@ -2368,7 +2368,7 @@ EliminateProject └── case:11 [as=r:8, outer=(11)] ================================================================================ EliminateSelect - Cost: 2235.12 + Cost: 2235.13 ================================================================================ project ├── columns: r:8 @@ -2451,7 +2451,7 @@ EliminateSelect └── case:11 [as=r:8, outer=(11)] ================================================================================ EliminateSelect - Cost: 2225.11 + Cost: 2225.12 ================================================================================ project ├── columns: r:8 @@ -2535,7 +2535,7 @@ EliminateSelect └── case:11 [as=r:8, outer=(11)] ================================================================================ PruneProjectCols - Cost: 2225.11 + Cost: 2225.12 ================================================================================ project ├── columns: r:8 @@ -2583,7 +2583,7 @@ PruneProjectCols └── case:11 [as=r:8, outer=(11)] ================================================================================ InlineProjectInProject - Cost: 2205.10 + Cost: 2205.11 ================================================================================ project ├── columns: r:8 @@ -2714,7 +2714,7 @@ CommuteLeftJoin (higher cost) └── CASE WHEN bool_or:10 THEN true WHEN bool_or:10 IS NULL THEN false END [as=r:8, outer=(10)] ================================================================================ GenerateMergeJoins - Cost: 2200.10 + Cost: 2200.11 ================================================================================ project ├── columns: r:8 @@ -2817,7 +2817,7 @@ GenerateMergeJoins (higher cost) └── CASE WHEN bool_or:10 THEN true WHEN bool_or:10 IS NULL THEN false END [as=r:8, outer=(10)] ================================================================================ GenerateStreamingGroupBy - Cost: 2190.10 + Cost: 2190.11 ================================================================================ project ├── columns: r:8 @@ -2865,7 +2865,7 @@ GenerateStreamingGroupBy └── CASE WHEN bool_or:10 THEN true WHEN bool_or:10 IS NULL THEN false END [as=r:8, outer=(10)] ================================================================================ Final best expression - Cost: 2190.10 + Cost: 2190.11 ================================================================================ project ├── columns: r:8 diff --git a/pkg/sql/opt/norm/testdata/rules/scalar b/pkg/sql/opt/norm/testdata/rules/scalar index e55534a81b8e..1704aa2170ae 100644 --- a/pkg/sql/opt/norm/testdata/rules/scalar +++ b/pkg/sql/opt/norm/testdata/rules/scalar @@ -989,14 +989,14 @@ SELECT k FROM e WHERE i IS NOT DISTINCT FROM NULL::FLOAT project ├── columns: k:1(int!null) ├── stats: [rows=10] - ├── cost: 1080.14 + ├── cost: 1080.15 ├── key: (1) ├── prune: (1) ├── interesting orderings: (+1) └── select ├── columns: t.public.e.k:1(int!null) t.public.e.i:2(int) ├── stats: [rows=10, distinct(2)=1, null(2)=10] - ├── cost: 1080.03 + ├── cost: 1080.04 ├── key: (1) ├── fd: ()-->(2) ├── prune: (1) @@ -1020,14 +1020,14 @@ SELECT k FROM e WHERE i IS DISTINCT FROM NULL::FLOAT project ├── columns: k:1(int!null) ├── stats: [rows=990] - ├── cost: 1089.94 + ├── cost: 1089.95 ├── key: (1) ├── prune: (1) ├── interesting orderings: (+1) └── select ├── columns: t.public.e.k:1(int!null) t.public.e.i:2(int!null) ├── stats: [rows=990, distinct(2)=100, null(2)=0] - ├── cost: 1080.03 + ├── cost: 1080.04 ├── key: (1) ├── fd: (1)-->(2) ├── prune: (1) diff --git a/pkg/sql/opt/optgen/exprgen/testdata/join b/pkg/sql/opt/optgen/exprgen/testdata/join index 0fafc5cca75f..c9eee3bb9029 100644 --- a/pkg/sql/opt/optgen/exprgen/testdata/join +++ b/pkg/sql/opt/optgen/exprgen/testdata/join @@ -114,7 +114,7 @@ expr inner-join-apply ├── columns: t.public.abc.a:1(int) t.public.abc.b:2(int) t.public.abc.c:3(int) t.public.def.d:5(int) t.public.def.e:6(int) t.public.def.f:7(int) ├── stats: [rows=333333.333] - ├── cost: 5611.39451 + ├── cost: 5611.40451 ├── prune: (7) ├── sort │ ├── columns: t.public.abc.a:1(int) t.public.abc.b:2(int) t.public.abc.c:3(int) @@ -128,7 +128,7 @@ inner-join-apply │ ├── columns: t.public.def.d:5(int) t.public.def.e:6(int) t.public.def.f:7(int) │ ├── outer: (1) │ ├── stats: [rows=333.333333, distinct(1)=1, null(1)=0] - │ ├── cost: 1080.03 + │ ├── cost: 1080.04 │ ├── prune: (7) │ ├── scan t.public.def │ │ ├── columns: t.public.def.d:5(int) t.public.def.e:6(int) t.public.def.f:7(int) diff --git a/pkg/sql/opt/optgen/exprgen/testdata/scan b/pkg/sql/opt/optgen/exprgen/testdata/scan index d42b6e7b324a..699ee000f859 100644 --- a/pkg/sql/opt/optgen/exprgen/testdata/scan +++ b/pkg/sql/opt/optgen/exprgen/testdata/scan @@ -46,7 +46,7 @@ expr select ├── columns: t.public.abc.a:1(int!null) t.public.abc.b:2(int) t.public.abc.c:3(int) ├── stats: [rows=10, distinct(1)=1, null(1)=0] - ├── cost: 1080.03 + ├── cost: 1080.04 ├── fd: ()-->(1) ├── prune: (2,3) ├── interesting orderings: (+1,+2) diff --git a/pkg/sql/opt/testutils/opttester/testdata/opt-steps b/pkg/sql/opt/testutils/opttester/testdata/opt-steps index 7776909e57c5..64ceb61cf71d 100644 --- a/pkg/sql/opt/testutils/opttester/testdata/opt-steps +++ b/pkg/sql/opt/testutils/opttester/testdata/opt-steps @@ -55,7 +55,7 @@ SELECT * FROM ab WHERE b=1 ---- ================================================================================ Initial expression - Cost: 1050.03 + Cost: 1050.04 ================================================================================ select ├── columns: a:1(int!null) b:2(int!null) @@ -359,7 +359,7 @@ SELECT * FROM comp WHERE k=1 ---- ================================================================================ Initial expression - Cost: 1070.14 + Cost: 1070.15 ================================================================================ project ├── columns: k:1(int!null) c:2(bool) @@ -386,7 +386,7 @@ Initial expression └── const: 1 [type=int] ================================================================================ NormalizeInConst - Cost: 1070.14 + Cost: 1070.15 ================================================================================ project ├── columns: k:1(int!null) c:2(bool) @@ -415,7 +415,7 @@ NormalizeInConst └── const: 1 [type=int] ================================================================================ PruneSelectCols - Cost: 1060.14 + Cost: 1060.15 ================================================================================ project ├── columns: k:1(int!null) c:2(bool) @@ -453,7 +453,7 @@ PruneSelectCols └── const: 1 [type=int] ================================================================================ EliminateProject - Cost: 1060.03 + Cost: 1060.04 ================================================================================ -project +select diff --git a/pkg/sql/opt/xform/coster.go b/pkg/sql/opt/xform/coster.go index 0687a954b46b..b38048f7bb50 100644 --- a/pkg/sql/opt/xform/coster.go +++ b/pkg/sql/opt/xform/coster.go @@ -133,6 +133,11 @@ const ( // If the final expression has this cost or larger, it means that there was no // plan that could satisfy the hints. hugeCost memo.Cost = 1e100 + + // Some benchmarks showed that some geo functions were atleast 10 times + // slower than some float functions, so this is a somewhat data-backed + // guess. + geoFnCost = cpuCostFactor * 10 ) // Init initializes a new coster structure with the given memo. @@ -183,7 +188,7 @@ func (c *coster) ComputeCost(candidate memo.RelExpr, required *physical.Required cost = c.computeLookupJoinCost(candidate.(*memo.LookupJoinExpr), required) case opt.GeoLookupJoinOp: - cost = c.computeGeoLookupJoinCost(candidate.(*memo.GeoLookupJoinExpr)) + cost = c.computeGeoLookupJoinCost(candidate.(*memo.GeoLookupJoinExpr), required) case opt.ZigzagJoinOp: cost = c.computeZigzagJoinCost(candidate.(*memo.ZigzagJoinExpr)) @@ -316,6 +321,7 @@ func (c *coster) computeSelectCost(sel *memo.SelectExpr) memo.Cost { // The filter has to be evaluated on each input row. inputRowCount := sel.Input.Relational().Stats.RowCount cost := memo.Cost(inputRowCount) * cpuCostFactor + cost += c.computeFiltersCost(sel.Filters, util.FastIntMap{}) * memo.Cost(inputRowCount) return cost } @@ -380,7 +386,7 @@ func (c *coster) computeHashJoinCost(join memo.RelExpr) memo.Cost { eqMap.Set(left, right) eqMap.Set(right, left) } - cost += c.computeFiltersCost(*on, eqMap) + cost += c.computeFiltersCost(*on, eqMap) * memo.Cost(rowsProcessed) return cost } @@ -401,7 +407,7 @@ func (c *coster) computeMergeJoinCost(join *memo.MergeJoinExpr) memo.Cost { } cost += memo.Cost(rowsProcessed) * cpuCostFactor - cost += c.computeFiltersCost(join.On, util.FastIntMap{}) + cost += c.computeFiltersCost(join.On, util.FastIntMap{}) * memo.Cost(rowsProcessed) return cost } @@ -474,26 +480,68 @@ func (c *coster) computeLookupJoinCost( cost += memo.Cost(rowsProcessed) * perRowCost - cost += c.computeFiltersCost(join.On, util.FastIntMap{}) + cost += c.computeFiltersCost(join.On, util.FastIntMap{}) * memo.Cost(rowsProcessed) return cost } -func (c *coster) computeGeoLookupJoinCost(join *memo.GeoLookupJoinExpr) memo.Cost { +func (c *coster) computeGeoLookupJoinCost( + join *memo.GeoLookupJoinExpr, required *physical.Required, +) memo.Cost { lookupCount := join.Input.Relational().Stats.RowCount + // Take into account that the "internal" row count is higher, according to + // the selectivities of the conditions. In particular, we need to ignore + // left-over conditions that are not selective. + // A contrived example, where gid is a SERIAL PK: + // nyc_census_blocks c JOIN nyc_neighborhoods n ON ST_Intersects(c.geom, n.geom) AND c.gid = 10 + // which can become a lookup join with left-over condition c.gid = 10 which doesn't + // actually filter anything. + rowsProcessed, ok := c.mem.RowsProcessed(join) + if !ok { + // We shouldn't ever get here. Since we don't allow the memo + // to be optimized twice, the coster should never be used after + // logPropsBuilder.clear() is called. + panic(errors.AssertionFailedf("could not get rows processed for geolookup join")) + } + + // Lookup joins can return early if enough rows have been found. An otherwise + // expensive lookup join might have a lower cost if its limit hint estimates + // that most rows will not be needed. + if required.LimitHint != 0 && lookupCount > 0 { + outputRows := join.Relational().Stats.RowCount + unlimitedLookupCount := lookupCount + lookupCount = lookupJoinInputLimitHint(unlimitedLookupCount, outputRows, required.LimitHint) + // We scale the number of rows processed by the same factor (we are + // calculating the average number of rows processed per lookup and + // multiplying by the new lookup count). + rowsProcessed = (rowsProcessed / unlimitedLookupCount) * lookupCount + } + // The rows in the (left) input are used to probe into the (right) table. // Since the matching rows in the table may not all be in the same range, this // counts as random I/O. perLookupCost := memo.Cost(randIOCostFactor) + // Since inverted indexes can't form a key, execution will have to + // limit KV batches which prevents running requests to multiple nodes + // in parallel. An experiment on a 4 node cluster with a table with + // 100k rows split into 100 ranges showed that a "non-parallel" lookup + // join is about 5 times slower. + perLookupCost *= 5 cost := memo.Cost(lookupCount) * perLookupCost - // TODO: support GeoLookupJoinExpr in c.mem.RowsProcessed. See - // computeLookupJoinCost. + // Each lookup might retrieve many rows; add the IO cost of retrieving the + // rows (relevant when we expect many resulting rows per lookup) and the CPU + // cost of emitting the rows. + numLookupCols := join.Cols.Difference(join.Input.Relational().OutputCols).Len() + perRowCost := lookupJoinRetrieveRowCost + + c.rowScanCost(join.Table, join.Index, numLookupCols) + cost += memo.Cost(rowsProcessed) * perRowCost - cost += c.computeFiltersCost(join.On, util.FastIntMap{}) + cost += c.computeFiltersCost(join.On, util.FastIntMap{}) * memo.Cost(rowsProcessed) return cost } +// computeFiltersCost returns the per-row cost of executing a filter. func (c *coster) computeFiltersCost(filters memo.FiltersExpr, eqMap util.FastIntMap) memo.Cost { var cost memo.Cost for i := range filters { @@ -515,6 +563,11 @@ func (c *coster) computeFiltersCost(filters memo.FiltersExpr, eqMap util.FastInt // them. They do not cost anything. continue } + case opt.FunctionOp: + if IsGeoIndexFunction(f.Condition) { + cost += geoFnCost + } + // TODO(mjibson): do we need to cost other functions? } // Add a constant "setup" cost per ON condition to account for the fact that @@ -546,7 +599,7 @@ func (c *coster) computeZigzagJoinCost(join *memo.ZigzagJoinExpr) memo.Cost { // given two indexes will be accessed. cost := memo.Cost(rowCount) * (2*(cpuCostFactor+seqIOCostFactor) + scanCost) - cost += c.computeFiltersCost(join.On, util.FastIntMap{}) + cost += c.computeFiltersCost(join.On, util.FastIntMap{}) * memo.Cost(rowCount) return cost } diff --git a/pkg/sql/opt/xform/custom_funcs.go b/pkg/sql/opt/xform/custom_funcs.go index 9e0c9d4f5b1c..2ebd25850079 100644 --- a/pkg/sql/opt/xform/custom_funcs.go +++ b/pkg/sql/opt/xform/custom_funcs.go @@ -1651,6 +1651,12 @@ var geoRelationshipMap = map[string]geoindex.RelationshipType{ // IsGeoIndexFunction returns true if the given function is a geospatial // function that can be index-accelerated. func (c *CustomFuncs) IsGeoIndexFunction(fn opt.ScalarExpr) bool { + return IsGeoIndexFunction(fn) +} + +// IsGeoIndexFunction returns true if the given function is a geospatial +// function that can be index-accelerated. +func IsGeoIndexFunction(fn opt.ScalarExpr) bool { function := fn.(*memo.FunctionExpr) _, ok := geoRelationshipMap[function.Name] return ok diff --git a/pkg/sql/opt/xform/testdata/coster/join b/pkg/sql/opt/xform/testdata/coster/join index 69b90a6e8fa1..55c6c8134078 100644 --- a/pkg/sql/opt/xform/testdata/coster/join +++ b/pkg/sql/opt/xform/testdata/coster/join @@ -12,12 +12,12 @@ SELECT k, x FROM a INNER JOIN b ON k=x WHERE d=1.0 project ├── columns: k:1!null x:5!null ├── stats: [rows=99] - ├── cost: 2124.725 + ├── cost: 2134.725 ├── fd: (1)==(5), (5)==(1) └── inner-join (hash) ├── columns: k:1!null d:4!null x:5!null ├── stats: [rows=99, distinct(1)=10, null(1)=0, distinct(5)=10, null(5)=0] - ├── cost: 2123.725 + ├── cost: 2133.725 ├── fd: ()-->(4), (1)==(5), (5)==(1) ├── scan b │ ├── columns: x:5 @@ -26,7 +26,7 @@ project ├── select │ ├── columns: k:1!null d:4!null │ ├── stats: [rows=10, distinct(1)=10, null(1)=0, distinct(4)=1, null(4)=0] - │ ├── cost: 1070.03 + │ ├── cost: 1080.03 │ ├── key: (1) │ ├── fd: ()-->(4) │ ├── scan a @@ -143,12 +143,12 @@ inner-join (lookup a) ├── key columns: [6] = [1] ├── lookup columns are key ├── stats: [rows=10000, distinct(1)=1000, null(1)=0, distinct(6)=1000, null(6)=0] - ├── cost: 71400.04 + ├── cost: 71500.04 ├── fd: (1)-->(2-4), (1)==(6), (6)==(1) ├── select │ ├── columns: x:5!null z:6!null │ ├── stats: [rows=10000, distinct(5)=1000, null(5)=0, distinct(6)=1000, null(6)=0] - │ ├── cost: 10600.03 + │ ├── cost: 10700.03 │ ├── scan b │ │ ├── columns: x:5 z:6!null │ │ ├── stats: [rows=10000, distinct(5)=1000, null(5)=0, distinct(6)=1000, null(6)=0] @@ -165,20 +165,20 @@ limit ├── columns: k:1!null i:2 s:3 d:4!null x:5!null z:6!null ├── cardinality: [0 - 6000] ├── stats: [rows=6000] - ├── cost: 47140.05 + ├── cost: 47240.05 ├── fd: (1)-->(2-4), (1)==(6), (6)==(1) ├── inner-join (lookup a) │ ├── columns: k:1!null i:2 s:3 d:4!null x:5!null z:6!null │ ├── key columns: [6] = [1] │ ├── lookup columns are key │ ├── stats: [rows=10000, distinct(1)=1000, null(1)=0, distinct(6)=1000, null(6)=0] - │ ├── cost: 47080.04 + │ ├── cost: 47180.04 │ ├── fd: (1)-->(2-4), (1)==(6), (6)==(1) │ ├── limit hint: 6000.00 │ ├── select │ │ ├── columns: x:5!null z:6!null │ │ ├── stats: [rows=10000, distinct(5)=1000, null(5)=0, distinct(6)=1000, null(6)=0] - │ │ ├── cost: 10600.03 + │ │ ├── cost: 10700.03 │ │ ├── limit hint: 6000.00 │ │ ├── scan b │ │ │ ├── columns: x:5 z:6!null @@ -200,20 +200,20 @@ limit ├── columns: k:1!null i:2 s:3 d:4!null x:5!null z:6!null ├── cardinality: [0 - 5950] ├── stats: [rows=5950] - ├── cost: 47139.55 + ├── cost: 47239.55 ├── fd: (1)-->(2-4), (1)==(6), (6)==(1) ├── inner-join (lookup a) │ ├── columns: k:1!null i:2 s:3 d:4!null x:5!null z:6!null │ ├── key columns: [6] = [1] │ ├── lookup columns are key │ ├── stats: [rows=10000, distinct(1)=1000, null(1)=0, distinct(6)=1000, null(6)=0] - │ ├── cost: 47080.04 + │ ├── cost: 47180.04 │ ├── fd: (1)-->(2-4), (1)==(6), (6)==(1) │ ├── limit hint: 5950.00 │ ├── select │ │ ├── columns: x:5!null z:6!null │ │ ├── stats: [rows=10000, distinct(5)=1000, null(5)=0, distinct(6)=1000, null(6)=0] - │ │ ├── cost: 10600.03 + │ │ ├── cost: 10700.03 │ │ ├── limit hint: 6000.00 │ │ ├── scan b │ │ │ ├── columns: x:5 z:6!null @@ -422,18 +422,18 @@ WHERE w = 'foo' AND x = '2AB23800-06B1-4E19-A3BB-DF3768B808D2' project ├── columns: w:1!null x:2!null y:3!null z:4!null ├── stats: [rows=500.488759] - ├── cost: 3155.07489 + ├── cost: 3167.05489 ├── fd: ()-->(1,2) └── inner-join (lookup abcde@idx_abcd) ├── columns: w:1!null x:2!null y:3!null z:4!null a:6!null b:7!null c:8!null ├── key columns: [1 2 3] = [6 7 8] ├── stats: [rows=500.488759, distinct(1)=1, null(1)=0, distinct(2)=1, null(2)=0, distinct(3)=25, null(3)=0, distinct(6)=1, null(6)=0, distinct(7)=1, null(7)=0, distinct(8)=25, null(8)=0] - ├── cost: 3150.06 + ├── cost: 3162.04 ├── fd: ()-->(1,2,6,7), (1)==(6), (6)==(1), (2)==(7), (7)==(2), (3)==(8), (8)==(3) ├── select │ ├── columns: w:1!null x:2!null y:3!null z:4!null │ ├── stats: [rows=100, distinct(1)=1, null(1)=0, distinct(2)=1, null(2)=0, distinct(3)=25, null(3)=0, distinct(4)=10, null(4)=0] - │ ├── cost: 110.03 + │ ├── cost: 112.03 │ ├── fd: ()-->(1,2) │ ├── scan wxyz │ │ ├── columns: w:1!null x:2!null y:3!null z:4!null @@ -532,18 +532,18 @@ WHERE w = 'foo' AND x = '2AB23800-06B1-4E19-A3BB-DF3768B808D2' AND (i,j,k,l,m,n) project ├── columns: w:1!null x:2!null y:3!null z:4!null ├── stats: [rows=1.25e-15] - ├── cost: 12200.07 + ├── cost: 13000.05 ├── fd: ()-->(1,2) - └── inner-join (lookup abcde@idx_abcd) + └── inner-join (lookup abcde@idx_abd) ├── columns: w:1!null x:2!null y:3!null z:4!null i:5!null j:6!null k:7!null l:8!null m:9!null n:10!null a:12!null b:13!null c:14!null - ├── key columns: [1 2 3] = [12 13 14] + ├── key columns: [1 2] = [12 13] ├── stats: [rows=1.25e-15, distinct(1)=1e-20, null(1)=0, distinct(2)=1e-20, null(2)=0, distinct(3)=1e-20, null(3)=0, distinct(12)=1e-20, null(12)=0, distinct(13)=1e-20, null(13)=0, distinct(14)=1e-20, null(14)=0] - ├── cost: 12200.06 + ├── cost: 13000.04 ├── fd: ()-->(1,2,5-10,12,13), (1)==(12), (12)==(1), (2)==(13), (13)==(2), (3)==(14), (14)==(3) ├── select │ ├── columns: w:1!null x:2!null y:3!null z:4!null i:5!null j:6!null k:7!null l:8!null m:9!null n:10!null │ ├── stats: [rows=1e-20, distinct(1)=1e-20, null(1)=0, distinct(2)=1e-20, null(2)=0, distinct(3)=1e-20, null(3)=0, distinct(4)=1e-20, null(4)=0, distinct(5)=1e-20, null(5)=0, distinct(6)=1e-20, null(6)=0, distinct(7)=1e-20, null(7)=0, distinct(8)=1e-20, null(8)=0, distinct(9)=1e-20, null(9)=0, distinct(10)=1e-20, null(10)=0] - │ ├── cost: 12200.03 + │ ├── cost: 13000.03 │ ├── fd: ()-->(1,2,5-10) │ ├── scan wxyzijklmn │ │ ├── columns: w:1!null x:2!null y:3!null z:4!null i:5 j:6 k:7 l:8 m:9 n:10 @@ -559,6 +559,7 @@ project │ ├── m:9 = 5 [outer=(9), constraints=(/9: [/5 - /5]; tight), fd=()-->(9)] │ └── n:10 = 6 [outer=(10), constraints=(/10: [/6 - /6]; tight), fd=()-->(10)] └── filters + ├── y:3 = c:14 [outer=(3,14), constraints=(/3: (/NULL - ]; /14: (/NULL - ]), fd=(3)==(14), (14)==(3)] ├── a:12 = 'foo' [outer=(12), constraints=(/12: [/'foo' - /'foo']; tight), fd=()-->(12)] └── b:13 = '2ab23800-06b1-4e19-a3bb-df3768b808d2' [outer=(13), constraints=(/13: [/'2ab23800-06b1-4e19-a3bb-df3768b808d2' - /'2ab23800-06b1-4e19-a3bb-df3768b808d2']; tight), fd=()-->(13)] @@ -655,7 +656,7 @@ project ├── columns: w:1!null x:2!null y:3!null z:4!null [hidden: d:8!null] ├── cardinality: [0 - 10] ├── stats: [rows=10] - ├── cost: 699.541329 + ├── cost: 700.322111 ├── key: (8) ├── fd: ()-->(1,2), (3)-->(4,8), (8)-->(3,4) ├── ordering: +8 opt(1,2) [actual: +8] @@ -664,7 +665,7 @@ project ├── internal-ordering: +8 opt(1,2,5,6) ├── cardinality: [0 - 10] ├── stats: [rows=10] - ├── cost: 699.431329 + ├── cost: 700.212111 ├── key: (7) ├── fd: ()-->(1,2,5,6), (3)-->(4), (7)-->(8), (8)-->(7), (1)==(5), (5)==(1), (2)==(6), (6)==(2), (3)==(7), (7)==(3) ├── ordering: +8 opt(1,2,5,6) [actual: +8] @@ -673,7 +674,7 @@ project │ ├── key columns: [5 6 7] = [1 2 3] │ ├── lookup columns are key │ ├── stats: [rows=50048.8759, distinct(1)=1, null(1)=0, distinct(2)=1, null(2)=0, distinct(3)=2500, null(3)=0, distinct(5)=1, null(5)=0, distinct(6)=1, null(6)=0, distinct(7)=2500, null(7)=0] - │ ├── cost: 699.321329 + │ ├── cost: 700.102111 │ ├── key: (7) │ ├── fd: ()-->(1,2,5,6), (3)-->(4), (7)-->(8), (8)-->(7), (1)==(5), (5)==(1), (2)==(6), (6)==(2), (3)==(7), (7)==(3) │ ├── ordering: +8 opt(1,2,5,6) [actual: +8] diff --git a/pkg/sql/opt/xform/testdata/coster/scan b/pkg/sql/opt/xform/testdata/coster/scan index 7a82ac57da68..220bbf74ec96 100644 --- a/pkg/sql/opt/xform/testdata/coster/scan +++ b/pkg/sql/opt/xform/testdata/coster/scan @@ -38,13 +38,13 @@ limit ├── columns: k:1!null i:2!null s:3 d:4!null ├── cardinality: [0 - 20] ├── stats: [rows=20] - ├── cost: 1197.56333 + ├── cost: 1530.89667 ├── key: (1) ├── fd: (1)-->(2-4) ├── select │ ├── columns: k:1!null i:2!null s:3 d:4!null │ ├── stats: [rows=1666.66667, distinct(1)=1666.66667, null(1)=0, distinct(2)=5, null(2)=0] - │ ├── cost: 1197.35333 + │ ├── cost: 1530.68667 │ ├── key: (1) │ ├── fd: (1)-->(2-4) │ ├── limit hint: 20.00 @@ -69,14 +69,14 @@ limit ├── columns: k:1!null i:2!null s:3 d:4!null ├── cardinality: [0 - 20] ├── stats: [rows=20] - ├── cost: 490.73 + ├── cost: 495.23 ├── key: (1) ├── fd: (1)-->(2-4) ├── select │ ├── columns: k:1!null i:2!null s:3 d:4!null │ ├── cardinality: [0 - 450] │ ├── stats: [rows=22.5, distinct(1)=22.5, null(1)=0, distinct(2)=5, null(2)=0] - │ ├── cost: 490.52 + │ ├── cost: 495.02 │ ├── key: (1) │ ├── fd: (1)-->(2-4) │ ├── limit hint: 20.00 @@ -105,7 +105,7 @@ select ├── columns: id:1!null ├── cardinality: [0 - 1000] ├── stats: [rows=333.333333, distinct(1)=333.333333, null(1)=0] - ├── cost: 1030.02 + ├── cost: 1040.02 ├── key: (1) ├── scan speed_test │ ├── columns: id:1!null @@ -125,7 +125,7 @@ select ├── columns: id:1!null ├── cardinality: [0 - 2000] ├── stats: [rows=333.333333, distinct(1)=333.333333, null(1)=0] - ├── cost: 1030.02 + ├── cost: 1040.02 ├── key: (1) ├── scan speed_test │ ├── columns: id:1!null diff --git a/pkg/sql/opt/xform/testdata/coster/select b/pkg/sql/opt/xform/testdata/coster/select index 8e5dcbab2e93..4f1e76b39f73 100644 --- a/pkg/sql/opt/xform/testdata/coster/select +++ b/pkg/sql/opt/xform/testdata/coster/select @@ -8,7 +8,7 @@ SELECT k, s FROM a WHERE s >= 'foo' select ├── columns: k:1!null s:3!null ├── stats: [rows=333.333333, distinct(3)=33.3333333, null(3)=0] - ├── cost: 1070.03 + ├── cost: 1080.03 ├── key: (1) ├── fd: (1)-->(3) ├── scan a diff --git a/pkg/sql/opt/xform/testdata/coster/sort b/pkg/sql/opt/xform/testdata/coster/sort index 3d7ea2b24860..641976192d93 100644 --- a/pkg/sql/opt/xform/testdata/coster/sort +++ b/pkg/sql/opt/xform/testdata/coster/sort @@ -145,13 +145,13 @@ SELECT * FROM abc WHERE a = b ORDER BY b, a, c sort (segmented) ├── columns: a:1!null b:2!null c:3 ├── stats: [rows=2000, distinct(1)=2, null(1)=0, distinct(2)=2, null(2)=0] - ├── cost: 11239.0614 + ├── cost: 11339.0614 ├── fd: (1)==(2), (2)==(1) ├── ordering: +(1|2),+3 [actual: +1,+3] └── select ├── columns: a:1!null b:2!null c:3 ├── stats: [rows=2000, distinct(1)=2, null(1)=0, distinct(2)=2, null(2)=0] - ├── cost: 10800.02 + ├── cost: 10900.02 ├── fd: (1)==(2), (2)==(1) ├── ordering: +1 ├── scan abc@ab diff --git a/pkg/sql/opt/xform/testdata/coster/virtual-scan b/pkg/sql/opt/xform/testdata/coster/virtual-scan index b6b137a2e8dc..a740e84f20ff 100644 --- a/pkg/sql/opt/xform/testdata/coster/virtual-scan +++ b/pkg/sql/opt/xform/testdata/coster/virtual-scan @@ -4,7 +4,7 @@ SELECT * FROM information_schema.schemata WHERE SCHEMA_NAME='public' select ├── columns: catalog_name:2!null schema_name:3!null default_character_set_name:4 sql_path:5 ├── stats: [rows=10, distinct(3)=1, null(3)=0] - ├── cost: 1100.03 + ├── cost: 1110.03 ├── fd: ()-->(3) ├── scan information_schema.schemata │ ├── columns: catalog_name:2!null schema_name:3!null default_character_set_name:4 sql_path:5 diff --git a/pkg/sql/opt/xform/testdata/coster/zone b/pkg/sql/opt/xform/testdata/coster/zone index b62ca4cbc95d..02eb1ce9ce68 100644 --- a/pkg/sql/opt/xform/testdata/coster/zone +++ b/pkg/sql/opt/xform/testdata/coster/zone @@ -367,7 +367,7 @@ inner-join (lookup xy@y2) ├── flags: force lookup join (into right side) ├── key columns: [2] = [5] ├── stats: [rows=100, distinct(2)=1, null(2)=0, distinct(5)=1, null(5)=0] - ├── cost: 412.59 + ├── cost: 413.57 ├── key: (1,4) ├── fd: ()-->(2,5), (1)-->(3), (2,3)~~>(1), (2)==(5), (5)==(2) ├── prune: (1,3,4) @@ -405,7 +405,7 @@ inner-join (lookup xy@y1) ├── flags: force lookup join (into right side) ├── key columns: [2] = [5] ├── stats: [rows=100, distinct(2)=1, null(2)=0, distinct(5)=1, null(5)=0] - ├── cost: 412.59 + ├── cost: 413.57 ├── key: (1,4) ├── fd: ()-->(2,5), (1)-->(3), (2,3)~~>(1), (2)==(5), (5)==(2) ├── prune: (1,3,4) diff --git a/pkg/sql/opt/xform/testdata/physprops/ordering b/pkg/sql/opt/xform/testdata/physprops/ordering index 6b42e834fa16..86ee9fc32beb 100644 --- a/pkg/sql/opt/xform/testdata/physprops/ordering +++ b/pkg/sql/opt/xform/testdata/physprops/ordering @@ -266,17 +266,17 @@ memo (optimized, ~5KB, required=[presentation: y:2,z:5] [ordering: +1,-2]) ├── G1: (project G2 G3 x y) │ ├── [presentation: y:2,z:5] [ordering: +1,-2] │ │ ├── best: (project G2="[ordering: +1,-2]" G3 x y) - │ │ └── cost: 1076.71 + │ │ └── cost: 1086.71 │ └── [] │ ├── best: (project G2 G3 x y) - │ └── cost: 1076.71 + │ └── cost: 1086.71 ├── G2: (select G4 G5) │ ├── [ordering: +1,-2] │ │ ├── best: (select G4="[ordering: +1,-2]" G5) - │ │ └── cost: 1070.03 + │ │ └── cost: 1080.03 │ └── [] │ ├── best: (select G4 G5) - │ └── cost: 1070.03 + │ └── cost: 1080.03 ├── G3: (projections G6) ├── G4: (scan a,cols=(1,2)) │ ├── [ordering: +1,-2] @@ -319,17 +319,17 @@ memo (optimized, ~5KB, required=[presentation: y:2,z:3] [ordering: +2]) ├── G1: (project G2 G3 y z) │ ├── [presentation: y:2,z:3] [ordering: +2] │ │ ├── best: (sort G1) - │ │ └── cost: 1145.92 + │ │ └── cost: 1155.92 │ └── [] │ ├── best: (project G2 G3 y z) - │ └── cost: 1083.37 + │ └── cost: 1093.37 ├── G2: (select G4 G5) │ ├── [ordering: +2] │ │ ├── best: (sort G2) - │ │ └── cost: 1142.58 + │ │ └── cost: 1152.58 │ └── [] │ ├── best: (select G4 G5) - │ └── cost: 1080.03 + │ └── cost: 1090.03 ├── G3: (projections) ├── G4: (scan a,cols=(1-3)) │ ├── [ordering: +2] diff --git a/pkg/sql/opt/xform/testdata/rules/groupby b/pkg/sql/opt/xform/testdata/rules/groupby index bb686abee482..707a657b0201 100644 --- a/pkg/sql/opt/xform/testdata/rules/groupby +++ b/pkg/sql/opt/xform/testdata/rules/groupby @@ -532,16 +532,16 @@ memo (optimized, ~6KB, required=[presentation: min:5]) ├── G4: (limit G7 G8 ordering=+2) │ └── [] │ ├── best: (limit G7="[ordering: +2] [limit hint: 1.00]" G8 ordering=+2) - │ └── cost: 1276.90 + │ └── cost: 1286.90 ├── G5: (aggregations G9) ├── G6: (min G10) ├── G7: (select G2 G11) │ ├── [ordering: +2] [limit hint: 1.00] │ │ ├── best: (sort G7) - │ │ └── cost: 1276.88 + │ │ └── cost: 1286.88 │ └── [] │ ├── best: (select G2 G11) - │ └── cost: 1060.03 + │ └── cost: 1070.03 ├── G8: (const 1) ├── G9: (const-agg G10) ├── G10: (variable b) @@ -594,16 +594,16 @@ memo (optimized, ~6KB, required=[presentation: max:5]) ├── G4: (limit G7 G8 ordering=-2) │ └── [] │ ├── best: (limit G7="[ordering: -2] [limit hint: 1.00]" G8 ordering=-2) - │ └── cost: 1276.90 + │ └── cost: 1286.90 ├── G5: (aggregations G9) ├── G6: (max G10) ├── G7: (select G2 G11) │ ├── [ordering: -2] [limit hint: 1.00] │ │ ├── best: (sort G7) - │ │ └── cost: 1276.88 + │ │ └── cost: 1286.88 │ └── [] │ ├── best: (select G2 G11) - │ └── cost: 1060.03 + │ └── cost: 1070.03 ├── G8: (const 1) ├── G9: (const-agg G10) ├── G10: (variable b) @@ -702,16 +702,16 @@ memo (optimized, ~6KB, required=[presentation: max:5]) ├── G4: (limit G7 G8 ordering=-2) │ └── [] │ ├── best: (limit G7="[ordering: -2] [limit hint: 1.00]" G8 ordering=-2) - │ └── cost: 1276.90 + │ └── cost: 1286.90 ├── G5: (aggregations G9) ├── G6: (max G10) ├── G7: (select G2 G11) │ ├── [ordering: -2] [limit hint: 1.00] │ │ ├── best: (sort G7) - │ │ └── cost: 1276.88 + │ │ └── cost: 1286.88 │ └── [] │ ├── best: (select G2 G11) - │ └── cost: 1060.03 + │ └── cost: 1070.03 ├── G8: (const 1) ├── G9: (const-agg G10) ├── G10: (variable b) @@ -1243,28 +1243,28 @@ memo (optimized, ~10KB, required=[presentation: array_agg:5]) ├── G1: (project G2 G3 array_agg) │ └── [presentation: array_agg:5] │ ├── best: (project G2 G3 array_agg) - │ └── cost: 1079.63 + │ └── cost: 1089.53 ├── G2: (group-by G4 G5 cols=(4),ordering=+(2|3) opt(4)) (group-by G4 G5 cols=(4),ordering=+(2|3)) (group-by G4 G5 cols=(4),ordering=+4,+(2|3)) (group-by G4 G5 cols=(4),ordering=+(2|3),+4) │ └── [] │ ├── best: (group-by G4="[ordering: +(2|3) opt(4)]" G5 cols=(4),ordering=+(2|3) opt(4)) - │ └── cost: 1079.53 + │ └── cost: 1089.43 ├── G3: (projections) ├── G4: (select G6 G7) (select G8 G7) (select G9 G7) │ ├── [ordering: +(2|3) opt(4)] │ │ ├── best: (select G8="[ordering: +2 opt(4)]" G7) - │ │ └── cost: 1079.12 + │ │ └── cost: 1089.02 │ ├── [ordering: +(2|3),+4] │ │ ├── best: (sort G4) - │ │ └── cost: 1080.01 + │ │ └── cost: 1089.91 │ ├── [ordering: +(2|3)] │ │ ├── best: (select G8="[ordering: +2]" G7) - │ │ └── cost: 1079.12 + │ │ └── cost: 1089.02 │ ├── [ordering: +4,+(2|3)] │ │ ├── best: (sort G4) - │ │ └── cost: 1080.01 + │ │ └── cost: 1089.91 │ └── [] │ ├── best: (select G8 G7) - │ └── cost: 1079.12 + │ └── cost: 1089.02 ├── G5: (aggregations G10) ├── G6: (scan kuvw) (scan kuvw@uvw) (scan kuvw@wvu) (scan kuvw@vw) (scan kuvw@w) │ ├── [ordering: +2 opt(4)] @@ -1337,22 +1337,22 @@ memo (optimized, ~9KB, required=[presentation: sum:5]) ├── G1: (project G2 G3 sum) │ └── [presentation: sum:5] │ ├── best: (project G2 G3 sum) - │ └── cost: 1079.69 + │ └── cost: 1089.59 ├── G2: (group-by G4 G5 cols=(2,4)) (group-by G4 G5 cols=(2,4),ordering=+(2|3)) (group-by G4 G5 cols=(2,4),ordering=+4) │ └── [] │ ├── best: (group-by G4="[ordering: +(2|3)]" G5 cols=(2,4),ordering=+(2|3)) - │ └── cost: 1079.58 + │ └── cost: 1089.48 ├── G3: (projections) ├── G4: (select G6 G7) (select G8 G7) (select G9 G7) │ ├── [ordering: +(2|3)] │ │ ├── best: (select G8="[ordering: +2]" G7) - │ │ └── cost: 1079.12 + │ │ └── cost: 1089.02 │ ├── [ordering: +4] │ │ ├── best: (sort G4) - │ │ └── cost: 1079.97 + │ │ └── cost: 1089.87 │ └── [] │ ├── best: (select G8 G7) - │ └── cost: 1079.12 + │ └── cost: 1089.02 ├── G5: (aggregations G10) ├── G6: (scan kuvw) (scan kuvw@uvw) (scan kuvw@wvu) (scan kuvw@vw) (scan kuvw@w) │ ├── [ordering: +2] @@ -1796,19 +1796,19 @@ memo (optimized, ~19KB, required=[]) ├── G1: (insert G2 G3 xyz) │ └── [] │ ├── best: (insert G2 G3 xyz) - │ └── cost: 2150.50 + │ └── cost: 2160.50 ├── G2: (upsert-distinct-on G4 G5 cols=(6)) (upsert-distinct-on G4 G5 cols=(6),ordering=+6 opt(8,9)) │ └── [] │ ├── best: (upsert-distinct-on G4="[ordering: +6 opt(8,9)]" G5 cols=(6),ordering=+6 opt(8,9)) - │ └── cost: 2150.49 + │ └── cost: 2160.49 ├── G3: (f-k-checks) ├── G4: (select G6 G7) │ ├── [ordering: +6 opt(8,9)] │ │ ├── best: (select G6="[ordering: +6 opt(8,9)]" G7) - │ │ └── cost: 2150.07 + │ │ └── cost: 2160.07 │ └── [] │ ├── best: (select G6 G7) - │ └── cost: 2150.07 + │ └── cost: 2160.07 ├── G5: (aggregations G8 G9) ├── G6: (left-join G10 G11 G12) (right-join G11 G10 G12) (merge-join G10 G11 G13 left-join,+6,+9) (lookup-join G10 G13 xyz,keyCols=[6],outCols=(6-9)) (lookup-join G10 G13 xyz@xy,keyCols=[6],outCols=(6-9)) (merge-join G11 G10 G13 right-join,+9,+6) │ ├── [ordering: +6 opt(8,9)] diff --git a/pkg/sql/opt/xform/testdata/rules/join b/pkg/sql/opt/xform/testdata/rules/join index cb6f1d6ad983..2b0612756c4f 100644 --- a/pkg/sql/opt/xform/testdata/rules/join +++ b/pkg/sql/opt/xform/testdata/rules/join @@ -637,11 +637,11 @@ memo (optimized, ~13KB, required=[presentation: a:1,b:2,c:3,x:5,y:6,z:7]) ├── G1: (inner-join G2 G3 G4) (inner-join G3 G2 G4) │ └── [presentation: a:1,b:2,c:3,x:5,y:6,z:7] │ ├── best: (inner-join G3 G2 G4) - │ └── cost: 2249.93 + │ └── cost: 2259.83 ├── G2: (select G5 G6) (select G7 G6) (select G8 G6) │ └── [] │ ├── best: (select G7 G6) - │ └── cost: 1069.22 + │ └── cost: 1079.12 ├── G3: (scan xyz,cols=(5-7)) (scan xyz@xy,cols=(5-7)) (scan xyz@yz,cols=(5-7)) │ └── [] │ ├── best: (scan xyz,cols=(5-7)) @@ -675,7 +675,7 @@ memo (optimized, ~8KB, required=[presentation: a:1,b:2,c:3,k:5]) ├── G1: (inner-join G2 G3 G4) (inner-join G3 G2 G4) │ └── [presentation: a:1,b:2,c:3,k:5] │ ├── best: (inner-join G2 G3 G4) - │ └── cost: 12120.06 + │ └── cost: 22120.05 ├── G2: (scan abc,cols=(1-3)) (scan abc@ab,cols=(1-3)) (scan abc@bc,cols=(1-3)) │ └── [] │ ├── best: (scan abc,cols=(1-3)) @@ -1693,16 +1693,16 @@ memo (optimized, ~23KB, required=[presentation: name:13,popn_per_sqkm:16]) ├── G1: (project G2 G3 name) │ └── [presentation: name:13,popn_per_sqkm:16] │ ├── best: (project G2 G3 name) - │ └── cost: 5110.53 + │ └── cost: 6811.94 ├── G2: (group-by G4 G5 cols=(13,14)) │ └── [] │ ├── best: (group-by G4 G5 cols=(13,14)) - │ └── cost: 5110.48 + │ └── cost: 6811.89 ├── G3: (projections G6) ├── G4: (inner-join G7 G8 G9) (inner-join G8 G7 G9) (lookup-join G10 G9 nyc_census_blocks,keyCols=[1],outCols=(3,9,10,12-14)) │ └── [] │ ├── best: (lookup-join G10 G9 nyc_census_blocks,keyCols=[1],outCols=(3,9,10,12-14)) - │ └── cost: 4903.53 + │ └── cost: 6604.95 ├── G5: (aggregations G11) ├── G6: (div G12 G13) ├── G7: (scan c,cols=(3,9,10)) @@ -1712,12 +1712,12 @@ memo (optimized, ~23KB, required=[presentation: name:13,popn_per_sqkm:16]) ├── G8: (select G14 G15) │ └── [] │ ├── best: (select G14 G15) - │ └── cost: 139.35 + │ └── cost: 140.64 ├── G9: (filters G16 G17) ├── G10: (geo-lookup-join G8 G18 nyc_census_blocks@nyc_census_blocks_geo_idx) │ └── [] │ ├── best: (geo-lookup-join G8 G18 nyc_census_blocks@nyc_census_blocks_geo_idx) - │ └── cost: 147.36 + │ └── cost: 1755.69 ├── G11: (sum G19) ├── G12: (variable sum) ├── G13: (div G20 G21) @@ -1784,7 +1784,7 @@ memo (optimized, ~13KB, required=[presentation: q:2,r:3]) ├── G1: (select G2 G3) (zigzag-join G3 pqr@q pqr@r) (select G4 G5) (select G6 G7) (select G8 G7) │ └── [presentation: q:2,r:3] │ ├── best: (zigzag-join G3 pqr@q pqr@r) - │ └── cost: 0.24 + │ └── cost: 0.22 ├── G2: (scan pqr,cols=(2,3)) │ └── [] │ ├── best: (scan pqr,cols=(2,3)) @@ -1865,7 +1865,7 @@ memo (optimized, ~15KB, required=[presentation: q:2,r:3,s:4]) ├── G1: (select G2 G3) (lookup-join G4 G5 pqr,keyCols=[1],outCols=(2-4)) (select G6 G7) (select G8 G9) (select G10 G9) │ └── [presentation: q:2,r:3,s:4] │ ├── best: (lookup-join G4 G5 pqr,keyCols=[1],outCols=(2-4)) - │ └── cost: 0.86 + │ └── cost: 0.84 ├── G2: (scan pqr,cols=(2-4)) │ └── [] │ ├── best: (scan pqr,cols=(2-4)) @@ -1874,7 +1874,7 @@ memo (optimized, ~15KB, required=[presentation: q:2,r:3,s:4]) ├── G4: (zigzag-join G3 pqr@q pqr@r) │ └── [] │ ├── best: (zigzag-join G3 pqr@q pqr@r) - │ └── cost: 0.24 + │ └── cost: 0.22 ├── G5: (filters) ├── G6: (index-join G13 pqr,cols=(2-4)) │ └── [] @@ -1930,7 +1930,7 @@ memo (optimized, ~11KB, required=[presentation: q:2,s:4]) ├── G1: (select G2 G3) (zigzag-join G3 pqr@q pqr@s) (select G4 G5) (select G6 G7) │ └── [presentation: q:2,s:4] │ ├── best: (zigzag-join G3 pqr@q pqr@s) - │ └── cost: 0.24 + │ └── cost: 0.22 ├── G2: (scan pqr,cols=(2,4)) │ └── [] │ ├── best: (scan pqr,cols=(2,4)) @@ -1984,7 +1984,7 @@ memo (optimized, ~13KB, required=[presentation: r:3,t:5]) ├── G1: (select G2 G3) (zigzag-join G3 pqr@rs pqr@ts) (select G4 G5) (select G6 G5) (select G7 G8) │ └── [presentation: r:3,t:5] │ ├── best: (zigzag-join G3 pqr@rs pqr@ts) - │ └── cost: 0.24 + │ └── cost: 0.22 ├── G2: (scan pqr,cols=(3,5)) │ └── [] │ ├── best: (scan pqr,cols=(3,5)) @@ -2075,7 +2075,7 @@ memo (optimized, ~31KB, required=[presentation: p:1,q:2,r:3,s:4]) ├── G1: (select G2 G3) (lookup-join G4 G5 pqr,keyCols=[1],outCols=(1-4)) (zigzag-join G3 pqr@q pqr@s) (zigzag-join G3 pqr@q pqr@rs) (lookup-join G6 G7 pqr,keyCols=[1],outCols=(1-4)) (select G8 G9) (select G10 G11) (select G12 G7) (select G13 G7) │ └── [presentation: p:1,q:2,r:3,s:4] │ ├── best: (zigzag-join G3 pqr@q pqr@s) - │ └── cost: 0.04 + │ └── cost: 0.01 ├── G2: (scan pqr,cols=(1-4)) │ └── [] │ ├── best: (scan pqr,cols=(1-4)) @@ -2084,12 +2084,12 @@ memo (optimized, ~31KB, required=[presentation: p:1,q:2,r:3,s:4]) ├── G4: (zigzag-join G17 pqr@q pqr@r) │ └── [] │ ├── best: (zigzag-join G17 pqr@q pqr@r) - │ └── cost: 0.24 + │ └── cost: 0.22 ├── G5: (filters G16) ├── G6: (zigzag-join G9 pqr@r pqr@s) │ └── [] │ ├── best: (zigzag-join G9 pqr@r pqr@s) - │ └── cost: 0.24 + │ └── cost: 0.22 ├── G7: (filters G14) ├── G8: (index-join G18 pqr,cols=(1-4)) │ └── [] @@ -2104,7 +2104,7 @@ memo (optimized, ~31KB, required=[presentation: p:1,q:2,r:3,s:4]) ├── G12: (index-join G20 pqr,cols=(1-4)) │ └── [] │ ├── best: (index-join G20 pqr,cols=(1-4)) - │ └── cost: 15.47 + │ └── cost: 15.57 ├── G13: (index-join G21 pqr,cols=(1-4)) │ └── [] │ ├── best: (index-join G21 pqr,cols=(1-4)) @@ -2124,7 +2124,7 @@ memo (optimized, ~31KB, required=[presentation: p:1,q:2,r:3,s:4]) ├── G20: (select G27 G28) │ └── [] │ ├── best: (select G27 G28) - │ └── cost: 10.72 + │ └── cost: 10.82 ├── G21: (scan pqr@rs,cols=(1,3,4),constrained) │ └── [] │ ├── best: (scan pqr@rs,cols=(1,3,4),constrained) @@ -2167,7 +2167,7 @@ memo (optimized, ~9KB, required=[presentation: q:2,t:5]) ├── G1: (select G2 G3) (select G4 G5) (select G6 G7) │ └── [presentation: q:2,t:5] │ ├── best: (select G4 G5) - │ └── cost: 51.33 + │ └── cost: 51.43 ├── G2: (scan pqr,cols=(2,5)) │ └── [] │ ├── best: (scan pqr,cols=(2,5)) @@ -2307,11 +2307,11 @@ memo (optimized, ~14KB, required=[presentation: a:1]) ├── G1: (project G2 G3 a) │ └── [presentation: a:1] │ ├── best: (project G2 G3 a) - │ └── cost: 100.29 + │ └── cost: 100.40 ├── G2: (select G4 G5) (lookup-join G6 G5 t5,keyCols=[1],outCols=(1,2)) (select G7 G5) │ └── [] │ ├── best: (lookup-join G6 G5 t5,keyCols=[1],outCols=(1,2)) - │ └── cost: 100.15 + │ └── cost: 100.27 ├── G3: (projections) ├── G4: (scan t5,cols=(1,2)) │ └── [] diff --git a/pkg/sql/opt/xform/testdata/rules/limit b/pkg/sql/opt/xform/testdata/rules/limit index c932c224f03f..1761a1491538 100644 --- a/pkg/sql/opt/xform/testdata/rules/limit +++ b/pkg/sql/opt/xform/testdata/rules/limit @@ -373,7 +373,7 @@ ConsolidateSelectFilters └── 5 ================================================================================ GenerateIndexScans - Cost: 5134.91 + Cost: 5144.91 ================================================================================ explain ├── columns: tree:5 field:6 description:7 @@ -442,7 +442,7 @@ GenerateConstrainedScans (no changes) -------------------------------------------------------------------------------- ================================================================================ Final best expression - Cost: 5134.91 + Cost: 5144.91 ================================================================================ explain ├── columns: tree:5 field:6 description:7 diff --git a/pkg/sql/opt/xform/testdata/rules/select b/pkg/sql/opt/xform/testdata/rules/select index aaf92aa3c638..b9e2c0388c58 100644 --- a/pkg/sql/opt/xform/testdata/rules/select +++ b/pkg/sql/opt/xform/testdata/rules/select @@ -266,11 +266,11 @@ memo (optimized, ~6KB, required=[presentation: k:1]) ├── G1: (project G2 G3 k) │ └── [presentation: k:1] │ ├── best: (project G2 G3 k) - │ └── cost: 1.10 + │ └── cost: 1.11 ├── G2: (select G4 G5) (select G6 G7) (select G8 G9) │ └── [] │ ├── best: (select G8 G9) - │ └── cost: 1.09 + │ └── cost: 1.10 ├── G3: (projections) ├── G4: (scan a) (scan a@u) (scan a@v) │ └── [] @@ -420,7 +420,7 @@ memo (optimized, ~6KB, required=[presentation: k:1,u:2,v:3,j:4]) ├── G1: (select G2 G3) (select G4 G5) (index-join G6 b,cols=(1-4)) │ └── [presentation: k:1,u:2,v:3,j:4] │ ├── best: (index-join G6 b,cols=(1-4)) - │ └── cost: 24.16 + │ └── cost: 24.26 ├── G2: (scan b) │ └── [] │ ├── best: (scan b) @@ -434,7 +434,7 @@ memo (optimized, ~6KB, required=[presentation: k:1,u:2,v:3,j:4]) ├── G6: (select G9 G10) │ └── [] │ ├── best: (select G9 G10) - │ └── cost: 10.52 + │ └── cost: 10.62 ├── G7: (range G11) ├── G8: (gt G12 G13) ├── G9: (scan b@v,cols=(1,3),constrained) @@ -517,7 +517,7 @@ memo (optimized, ~5KB, required=[presentation: k:1,u:2,v:3,j:4]) ├── G1: (select G2 G3) (select G4 G5) │ └── [presentation: k:1,u:2,v:3,j:4] │ ├── best: (select G4 G5) - │ └── cost: 51.43 + │ └── cost: 51.53 ├── G2: (scan b) │ └── [] │ ├── best: (scan b) @@ -580,7 +580,7 @@ memo (optimized, ~7KB, required=[presentation: k:1,u:2,v:3,j:4]) ├── G1: (select G2 G3) (select G4 G5) (select G6 G7) │ └── [presentation: k:1,u:2,v:3,j:4] │ ├── best: (select G6 G7) - │ └── cost: 24.21 + │ └── cost: 24.34 ├── G2: (scan b) │ └── [] │ ├── best: (scan b) @@ -594,7 +594,7 @@ memo (optimized, ~7KB, required=[presentation: k:1,u:2,v:3,j:4]) ├── G6: (index-join G11 b,cols=(1-4)) │ └── [] │ ├── best: (index-join G11 b,cols=(1-4)) - │ └── cost: 24.16 + │ └── cost: 24.26 ├── G7: (filters G9) ├── G8: (range G12) ├── G9: (eq G13 G14) @@ -602,7 +602,7 @@ memo (optimized, ~7KB, required=[presentation: k:1,u:2,v:3,j:4]) ├── G11: (select G17 G18) │ └── [] │ ├── best: (select G17 G18) - │ └── cost: 10.52 + │ └── cost: 10.62 ├── G12: (and G19 G20) ├── G13: (plus G15 G21) ├── G14: (const 1) @@ -647,7 +647,7 @@ memo (optimized, ~5KB, required=[presentation: k:1,u:2,v:3,j:4]) ├── G1: (select G2 G3) (select G4 G3) │ └── [presentation: k:1,u:2,v:3,j:4] │ ├── best: (select G4 G3) - │ └── cost: 45.72 + │ └── cost: 45.90 ├── G2: (scan b) │ └── [] │ ├── best: (scan b)