Skip to content

Commit d8f04bd

Browse files
eurekakazz-jason
authored andcommitted
planner: correct estimated row count for inner plan of index join (#10015) (#10044)
1 parent e87c6f1 commit d8f04bd

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

cmd/explaintest/r/explain_easy.result

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ explain select count(b.c2) from t1 a, t2 b where a.c1 = b.c2 group by a.c1;
6060
id count task operator info
6161
Projection_11 10000.00 root cast(join_agg_0)
6262
└─IndexJoin_14 10000.00 root inner join, inner:TableReader_13, outer key:b.c2, inner key:a.c1
63-
├─TableReader_13 10.00 root data:TableScan_12
64-
│ └─TableScan_12 10.00 cop table:a, range: decided by [b.c2], keep order:false, stats:pseudo
63+
├─TableReader_13 1.00 root data:TableScan_12
64+
│ └─TableScan_12 1.00 cop table:a, range: decided by [b.c2], keep order:false, stats:pseudo
6565
└─HashAgg_21 8000.00 root group by:col_2, funcs:count(col_0), firstrow(col_1)
6666
└─TableReader_22 8000.00 root data:HashAgg_17
6767
└─HashAgg_17 8000.00 cop group by:b.c2, funcs:count(b.c2), firstrow(b.c2)
@@ -279,9 +279,9 @@ Projection_11 10000.00 root 9_aux_0
279279
└─IndexJoin_44 10000.00 root inner join, inner:TableReader_43, outer key:s.a, inner key:t1.a
280280
├─TableReader_37 1.00 root data:TableScan_36
281281
│ └─TableScan_36 1.00 cop table:s, range: decided by [eq(s.a, test.t.a)], keep order:false, stats:pseudo
282-
└─TableReader_43 8000.00 root data:Selection_42
283-
└─Selection_42 8000.00 cop eq(t1.a, test.t.a)
284-
└─TableScan_41 10.00 cop table:t1, range: decided by [s.a], keep order:false, stats:pseudo
282+
└─TableReader_43 0.80 root data:Selection_42
283+
└─Selection_42 0.80 cop eq(t1.a, test.t.a)
284+
└─TableScan_41 1.00 cop table:t1, range: decided by [s.a], keep order:false, stats:pseudo
285285
explain select t.c in (select count(*) from t s use index(idx), t t1 where s.b = t.a and s.a = t1.a) from t;
286286
id count task operator info
287287
Projection_11 10000.00 root 9_aux_0
@@ -292,8 +292,8 @@ Projection_11 10000.00 root 9_aux_0
292292
└─IndexJoin_32 10000.00 root inner join, inner:TableReader_31, outer key:s.a, inner key:t1.a
293293
├─IndexReader_27 10000.00 root index:IndexScan_26
294294
│ └─IndexScan_26 10000.00 cop table:s, index:b, range: decided by [eq(s.b, test.t.a)], keep order:false, stats:pseudo
295-
└─TableReader_31 10.00 root data:TableScan_30
296-
└─TableScan_30 10.00 cop table:t1, range: decided by [s.a], keep order:false, stats:pseudo
295+
└─TableReader_31 1.00 root data:TableScan_30
296+
└─TableScan_30 1.00 cop table:t1, range: decided by [s.a], keep order:false, stats:pseudo
297297
explain select t.c in (select count(*) from t s use index(idx), t t1 where s.b = t.a and s.c = t1.a) from t;
298298
id count task operator info
299299
Projection_11 10000.00 root 9_aux_0
@@ -305,8 +305,8 @@ Projection_11 10000.00 root 9_aux_0
305305
├─IndexLookUp_28 10000.00 root
306306
│ ├─IndexScan_26 10000.00 cop table:s, index:b, range: decided by [eq(s.b, test.t.a)], keep order:false, stats:pseudo
307307
│ └─TableScan_27 10000.00 cop table:t, keep order:false, stats:pseudo
308-
└─TableReader_32 10.00 root data:TableScan_31
309-
└─TableScan_31 10.00 cop table:t1, range: decided by [s.c], keep order:false, stats:pseudo
308+
└─TableReader_32 1.00 root data:TableScan_31
309+
└─TableScan_31 1.00 cop table:t1, range: decided by [s.c], keep order:false, stats:pseudo
310310
drop table if exists t;
311311
create table t(a int unsigned);
312312
explain select t.a = '123455' from t;

cmd/explaintest/r/tpch.result

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,8 @@ Sort_22 2406.00 root profit.nation:asc, profit.o_year:desc
601601
│ ├─IndexJoin_40 241379546.70 root inner join, inner:TableReader_39, outer key:tpch.supplier.s_nationkey, inner key:tpch.nation.n_nationkey
602602
│ │ ├─IndexJoin_43 241379546.70 root inner join, inner:TableReader_42, outer key:tpch.lineitem.l_suppkey, inner key:tpch.supplier.s_suppkey
603603
│ │ │ ├─IndexJoin_47 241379546.70 root inner join, inner:TableReader_46, outer key:tpch.lineitem.l_partkey, inner key:tpch.part.p_partkey
604-
│ │ │ │ ├─TableReader_46 8000000.00 root data:Selection_45
605-
│ │ │ │ │ └─Selection_45 8000000.00 cop like(tpch.part.p_name, "%dim%", 92)
604+
│ │ │ │ ├─TableReader_46 0.80 root data:Selection_45
605+
│ │ │ │ │ └─Selection_45 0.80 cop like(tpch.part.p_name, "%dim%", 92)
606606
│ │ │ │ │ └─TableScan_44 1.00 cop table:part, range: decided by [tpch.lineitem.l_partkey], keep order:false
607607
│ │ │ │ └─IndexLookUp_51 300005811.00 root
608608
│ │ │ │ ├─IndexScan_49 300005811.00 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range:[NULL,+inf], keep order:true
@@ -1098,8 +1098,8 @@ StreamAgg_13 1.00 root funcs:sum(col_0)
10981098
├─TableReader_22 6286493.79 root data:Selection_21
10991099
│ └─Selection_21 6286493.79 cop eq(tpch.lineitem.l_shipinstruct, "DELIVER IN PERSON"), in(tpch.lineitem.l_shipmode, "AIR", "AIR REG"), or(and(ge(tpch.lineitem.l_quantity, 4), le(tpch.lineitem.l_quantity, 14)), or(and(ge(tpch.lineitem.l_quantity, 18), le(tpch.lineitem.l_quantity, 28)), and(ge(tpch.lineitem.l_quantity, 29), le(tpch.lineitem.l_quantity, 39))))
11001100
│ └─TableScan_20 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false
1101-
└─TableReader_28 8000000.00 root data:Selection_27
1102-
└─Selection_27 8000000.00 cop ge(tpch.part.p_size, 1), or(and(eq(tpch.part.p_brand, "Brand#52"), and(in(tpch.part.p_container, "SM CASE", "SM BOX", "SM PACK", "SM PKG"), le(tpch.part.p_size, 5))), or(and(eq(tpch.part.p_brand, "Brand#11"), and(in(tpch.part.p_container, "MED BAG", "MED BOX", "MED PKG", "MED PACK"), le(tpch.part.p_size, 10))), and(eq(tpch.part.p_brand, "Brand#51"), and(in(tpch.part.p_container, "LG CASE", "LG BOX", "LG PACK", "LG PKG"), le(tpch.part.p_size, 15)))))
1101+
└─TableReader_28 0.80 root data:Selection_27
1102+
└─Selection_27 0.80 cop ge(tpch.part.p_size, 1), or(and(eq(tpch.part.p_brand, "Brand#52"), and(in(tpch.part.p_container, "SM CASE", "SM BOX", "SM PACK", "SM PKG"), le(tpch.part.p_size, 5))), or(and(eq(tpch.part.p_brand, "Brand#11"), and(in(tpch.part.p_container, "MED BAG", "MED BOX", "MED PKG", "MED PACK"), le(tpch.part.p_size, 10))), and(eq(tpch.part.p_brand, "Brand#51"), and(in(tpch.part.p_container, "LG CASE", "LG BOX", "LG PACK", "LG PKG"), le(tpch.part.p_size, 15)))))
11031103
└─TableScan_26 1.00 cop table:part, range: decided by [tpch.lineitem.l_partkey], keep order:false
11041104
/*
11051105
Q20 Potential Part Promotion Query

planner/core/exhaust_physical_plans.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -490,22 +490,15 @@ func (p *LogicalJoin) constructInnerTableScan(ds *DataSource, pk *expression.Col
490490
}.init(ds.ctx)
491491
ts.SetSchema(ds.schema)
492492

493-
var rowCount float64
494-
pkHist, ok := ds.statisticTable.Columns[pk.ID]
495-
if ok && !ds.statisticTable.Pseudo {
496-
rowCount = pkHist.AvgCountPerValue(ds.statisticTable.Count)
497-
} else {
498-
rowCount = ds.statisticTable.PseudoAvgCountPerValue()
499-
}
500-
501-
ts.stats = property.NewSimpleStats(rowCount)
493+
ts.stats = property.NewSimpleStats(1)
502494
ts.stats.UsePseudoStats = ds.statisticTable.Pseudo
503495

504496
copTask := &copTask{
505497
tablePlan: ts,
506498
indexPlanFinished: true,
507499
}
508-
ts.addPushedDownSelection(copTask, ds.stats)
500+
selStats := ts.stats.Scale(selectionFactor)
501+
ts.addPushedDownSelection(copTask, selStats)
509502
t := finishCopTask(ds.ctx, copTask)
510503
return t.plan()
511504
}

0 commit comments

Comments
 (0)