Skip to content

Commit

Permalink
planner: improve row count estimation of IndexJoin's inner scan (#12085)
Browse files Browse the repository at this point in the history
  • Loading branch information
eurekaka authored and sre-bot committed Sep 11, 2019
1 parent 440bb74 commit f2adf1d
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 133 deletions.
22 changes: 11 additions & 11 deletions cmd/explaintest/r/explain_complex.result
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ Projection_13 1.00 root test.gad.id, test.dd.id, test.gad.aid, test.gad.cm, test
└─HashAgg_19 1.00 root group by:test.dd.dic, test.gad.aid, funcs:firstrow(test.gad.id), firstrow(test.gad.aid), firstrow(test.gad.cm), firstrow(test.gad.p1), firstrow(test.gad.p2), firstrow(test.gad.p3), firstrow(test.gad.p4), firstrow(test.gad.p5), firstrow(test.gad.p6_md5), firstrow(test.gad.p7_md5), firstrow(test.gad.ext), firstrow(test.gad.t), firstrow(test.dd.id), firstrow(test.dd.dic), firstrow(test.dd.ip), firstrow(test.dd.t)
└─IndexMergeJoin_30 0.00 root inner join, inner:IndexLookUp_28, outer key:test.gad.aid, inner key:test.dd.aid, other cond:eq(test.dd.ip, test.gad.ip), gt(test.dd.t, test.gad.t)
├─IndexLookUp_28 0.00 root
│ ├─IndexScan_25 10.00 cop table:dd, index:aid, dic, range: decided by [eq(test.dd.aid, test.gad.aid)], keep order:true, stats:pseudo
│ ├─IndexScan_25 0.00 cop table:dd, index:aid, dic, range: decided by [eq(test.dd.aid, test.gad.aid)], keep order:true, stats:pseudo
│ └─Selection_27 0.00 cop eq(test.dd.bm, 0), eq(test.dd.pt, "android"), gt(test.dd.t, 1478143908), not(isnull(test.dd.ip)), not(isnull(test.dd.t))
│ └─TableScan_26 10.00 cop table:dd, keep order:false, stats:pseudo
│ └─TableScan_26 0.00 cop table:dd, keep order:false, stats:pseudo
└─IndexLookUp_39 3.33 root
├─IndexScan_36 3333.33 cop table:gad, index:t, range:(1478143908,+inf], keep order:false, stats:pseudo
└─Selection_38 3.33 cop eq(test.gad.pt, "android"), not(isnull(test.gad.ip))
Expand All @@ -137,9 +137,9 @@ Projection_10 0.00 root test.gad.id, test.sdk.id, test.gad.aid, test.gad.cm, tes
│ └─Selection_32 0.00 cop eq(test.gad.bm, 0), eq(test.gad.dit, "mac"), eq(test.gad.pt, "ios"), not(isnull(test.gad.dic))
│ └─TableScan_31 3333.33 cop table:gad, keep order:false, stats:pseudo
└─IndexLookUp_22 0.00 root
├─IndexScan_19 10.00 cop table:sdk, index:aid, dic, range: decided by [eq(test.sdk.aid, test.gad.aid)], keep order:true, stats:pseudo
├─IndexScan_19 0.00 cop table:sdk, index:aid, dic, range: decided by [eq(test.sdk.aid, test.gad.aid)], keep order:true, stats:pseudo
└─Selection_21 0.00 cop eq(test.sdk.bm, 0), eq(test.sdk.pt, "ios"), gt(test.sdk.t, 1477971479), not(isnull(test.sdk.mac)), not(isnull(test.sdk.t))
└─TableScan_20 10.00 cop table:sdk, keep order:false, stats:pseudo
└─TableScan_20 0.00 cop table:sdk, keep order:false, stats:pseudo
explain SELECT cm, p1, p2, p3, p4, p5, p6_md5, p7_md5, count(1) as click_pv, count(DISTINCT ip) as click_ip FROM st WHERE (t between 1478188800 and 1478275200) and aid='cn.sbkcq' and pt='android' GROUP BY cm, p1, p2, p3, p4, p5, p6_md5, p7_md5;
id count task operator info
Projection_5 1.00 root test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p4, test.st.p5, test.st.p6_md5, test.st.p7_md5, 3_col_0, 3_col_1
Expand All @@ -157,9 +157,9 @@ Projection_10 0.00 root test.dt.id, test.dt.aid, test.dt.pt, test.dt.dic, test.d
│ └─Selection_52 0.00 cop eq(test.dt.bm, 0), eq(test.dt.pt, "ios"), gt(test.dt.t, 1478185592), not(isnull(test.dt.dic))
│ └─TableScan_51 10000.00 cop table:dt, range:[0,+inf], keep order:false, stats:pseudo
└─IndexLookUp_23 0.00 root
├─IndexScan_20 10.00 cop table:rr, index:aid, dic, range: decided by [eq(test.rr.aid, test.dt.aid) eq(test.rr.dic, test.dt.dic)], keep order:true, stats:pseudo
├─IndexScan_20 1.25 cop table:rr, index:aid, dic, range: decided by [eq(test.rr.aid, test.dt.aid) eq(test.rr.dic, test.dt.dic)], keep order:true, stats:pseudo
└─Selection_22 0.00 cop eq(test.rr.pt, "ios"), gt(test.rr.t, 1478185592)
└─TableScan_21 10.00 cop table:rr, keep order:false, stats:pseudo
└─TableScan_21 1.25 cop table:rr, keep order:false, stats:pseudo
explain select pc,cr,count(DISTINCT uid) as pay_users,count(oid) as pay_times,sum(am) as am from pp where ps=2 and ppt>=1478188800 and ppt<1478275200 and pi in ('510017','520017') and uid in ('18089709','18090780') group by pc,cr;
id count task operator info
Projection_5 1.00 root test.pp.pc, test.pp.cr, 3_col_0, 3_col_1, 3_col_2
Expand Down Expand Up @@ -251,11 +251,11 @@ Sort_10 1.00 root test.d.left_value:asc
│ │ ├─IndexScan_55 10.00 cop table:d, index:ctx, range:[1,1], keep order:false, stats:pseudo
│ │ └─Selection_57 0.01 cop eq(test.d.status, 1000)
│ │ └─TableScan_56 10.00 cop table:d, keep order:false, stats:pseudo
│ └─IndexLookUp_37 0.01 root
│ ├─Selection_35 9.99 cop not(isnull(test.p.department_id))
│ │ └─IndexScan_33 10.00 cop table:p, index:department_id, range: decided by [eq(test.p.department_id, test.d.id)], keep order:true, stats:pseudo
│ └─Selection_36 0.01 cop eq(test.p.status, 1000)
│ └─TableScan_34 9.99 cop table:p, keep order:false, stats:pseudo
│ └─IndexLookUp_37 0.00 root
│ ├─Selection_35 1.25 cop not(isnull(test.p.department_id))
│ │ └─IndexScan_33 1.25 cop table:p, index:department_id, range: decided by [eq(test.p.department_id, test.d.id)], keep order:true, stats:pseudo
│ └─Selection_36 0.00 cop eq(test.p.status, 1000)
│ └─TableScan_34 1.25 cop table:p, keep order:false, stats:pseudo
└─TableReader_68 9.99 root data:Selection_67
└─Selection_67 9.99 cop eq(test.ep.status, 1000), not(isnull(test.ep.position_id))
└─TableScan_66 10000.00 cop table:ep, range:[-inf,+inf], keep order:false, stats:pseudo
12 changes: 6 additions & 6 deletions cmd/explaintest/r/index_join.result
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ id count task operator info
IndexMergeJoin_14 8000.00 root semi join, inner:IndexReader_12, outer key:test.t1.a, inner key:test.t2.a
├─TableReader_16 10000.00 root data:TableScan_15
│ └─TableScan_15 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
└─IndexReader_12 10.00 root index:IndexScan_11
└─IndexScan_11 10.00 cop table:t2, index:a, range: decided by [eq(test.t2.a, test.t1.a)], keep order:true, stats:pseudo
└─IndexReader_12 1.25 root index:IndexScan_11
└─IndexScan_11 1.25 cop table:t2, index:a, range: decided by [eq(test.t2.a, test.t1.a)], keep order:true, stats:pseudo
show warnings;
Level Code Message
set @@tidb_opt_insubq_to_join_and_agg=1;
Expand All @@ -46,10 +46,10 @@ create table t2(a int not null, b int not null, key a(a));
explain select /*+ TIDB_INLJ(t1) */ * from t1 where t1.a in (select t2.a from t2);
id count task operator info
Projection_8 10000.00 root test.t1.a, test.t1.b
└─IndexJoin_12 10000.00 root inner join, inner:IndexLookUp_11, outer key:test.t2.a, inner key:test.t1.a
├─IndexLookUp_11 10.00 root
│ ├─IndexScan_9 10.00 cop table:t1, index:a, range: decided by [eq(test.t1.a, test.t2.a)], keep order:false, stats:pseudo
│ └─TableScan_10 10.00 cop table:t1, keep order:false, stats:pseudo
└─IndexMergeJoin_17 10000.00 root inner join, inner:IndexLookUp_15, outer key:test.t2.a, inner key:test.t1.a
├─IndexLookUp_15 1.25 root
│ ├─IndexScan_13 1.25 cop table:t1, index:a, range: decided by [eq(test.t1.a, test.t2.a)], keep order:true, stats:pseudo
│ └─TableScan_14 1.25 cop table:t1, keep order:false, stats:pseudo
└─StreamAgg_22 8000.00 root group by:test.t2.a, funcs:firstrow(test.t2.a)
└─IndexReader_35 10000.00 root index:IndexScan_34
└─IndexScan_34 10000.00 cop table:t2, index:a, range:[NULL,+inf], keep order:true, stats:pseudo
22 changes: 11 additions & 11 deletions cmd/explaintest/r/topn_push_down.result
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ Projection_13 0.00 root test.te.expect_time
│ │ │ └─IndexScan_86 10.00 cop table:tr, index:shop_identy, trade_status, business_type, trade_pay_status, trade_type, delivery_type, source, biz_date, range:[810094178,810094178], keep order:false, stats:pseudo
│ │ └─Selection_89 0.00 cop eq(test.tr.brand_identy, 32314), eq(test.tr.domain_type, 2)
│ │ └─TableScan_87 0.00 cop table:tr, keep order:false, stats:pseudo
│ └─IndexLookUp_45 0.25 root
│ ├─IndexScan_42 10.00 cop table:te, index:trade_id, range: decided by [eq(test.te.trade_id, test.tr.id)], keep order:true, stats:pseudo
│ └─Selection_44 0.25 cop ge(test.te.expect_time, 2018-04-23 00:00:00.000000), le(test.te.expect_time, 2018-04-23 23:59:59.000000)
│ └─TableScan_43 10.00 cop table:te, keep order:false, stats:pseudo
└─IndexReader_115 9.99 root index:Selection_114
└─Selection_114 9.99 cop not(isnull(test.p.relate_id))
└─IndexScan_113 10.00 cop table:p, index:relate_id, range: decided by [eq(test.p.relate_id, test.tr.id)], keep order:false, stats:pseudo
│ └─IndexLookUp_45 0.03 root
│ ├─IndexScan_42 1.25 cop table:te, index:trade_id, range: decided by [eq(test.te.trade_id, test.tr.id)], keep order:true, stats:pseudo
│ └─Selection_44 0.03 cop ge(test.te.expect_time, 2018-04-23 00:00:00.000000), le(test.te.expect_time, 2018-04-23 23:59:59.000000)
│ └─TableScan_43 1.25 cop table:te, keep order:false, stats:pseudo
└─IndexReader_115 1.25 root index:Selection_114
└─Selection_114 1.25 cop not(isnull(test.p.relate_id))
└─IndexScan_113 1.25 cop table:p, index:relate_id, range: decided by [eq(test.p.relate_id, test.tr.id)], keep order:false, stats:pseudo
desc select 1 as a from dual order by a limit 1;
id count task operator info
Projection_6 1.00 root 1
Expand Down Expand Up @@ -225,17 +225,17 @@ Limit_11 5.00 root offset:0, count:5
└─IndexMergeJoin_19 5.00 root inner join, inner:IndexReader_17, outer key:test.t1.a, inner key:test.t2.a
├─IndexReader_23 4.00 root index:IndexScan_22
│ └─IndexScan_22 4.00 cop table:t1, index:a, range:[NULL,+inf], keep order:false, stats:pseudo
└─IndexReader_17 10.00 root index:IndexScan_16
└─IndexScan_16 10.00 cop table:t2, index:a, range: decided by [eq(test.t2.a, test.t1.a)], keep order:true, stats:pseudo
└─IndexReader_17 1.25 root index:IndexScan_16
└─IndexScan_16 1.25 cop table:t2, index:a, range: decided by [eq(test.t2.a, test.t1.a)], keep order:true, stats:pseudo
explain select /*+ TIDB_INLJ(t2) */ * from t t1 left join t t2 on t1.a = t2.a where t2.a is null limit 5;
id count task operator info
Limit_12 5.00 root offset:0, count:5
└─Selection_13 5.00 root isnull(test.t2.a)
└─IndexMergeJoin_21 5.00 root left outer join, inner:IndexReader_19, outer key:test.t1.a, inner key:test.t2.a
├─IndexReader_25 4.00 root index:IndexScan_24
│ └─IndexScan_24 4.00 cop table:t1, index:a, range:[NULL,+inf], keep order:false, stats:pseudo
└─IndexReader_19 10.00 root index:IndexScan_18
└─IndexScan_18 10.00 cop table:t2, index:a, range: decided by [eq(test.t2.a, test.t1.a)], keep order:true, stats:pseudo
└─IndexReader_19 1.25 root index:IndexScan_18
└─IndexScan_18 1.25 cop table:t2, index:a, range: decided by [eq(test.t2.a, test.t1.a)], keep order:true, stats:pseudo
explain select /*+ TIDB_SMJ(t1, t2) */ * from t t1 join t t2 on t1.a = t2.a limit 5;
id count task operator info
Limit_11 5.00 root offset:0, count:5
Expand Down
Loading

0 comments on commit f2adf1d

Please sign in to comment.