Skip to content

Commit

Permalink
planner: make the meaning of displayed estimated row count consistent…
Browse files Browse the repository at this point in the history
… with actual row count (#38188)

close #38187
  • Loading branch information
time-and-fate authored Oct 17, 2022
1 parent aa49a4c commit 5fa9da1
Show file tree
Hide file tree
Showing 36 changed files with 1,104 additions and 924 deletions.
26 changes: 13 additions & 13 deletions cmd/explaintest/r/cte.result
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,11 @@ Projection_16 10000.00 root test.t1.c1, test.t1.c2
└─Apply_18 10000.00 root CARTESIAN inner join, other cond:or(and(gt(test.t1.c1, Column#11), if(ne(Column#12, 0), NULL, 1)), or(eq(Column#13, 0), if(isnull(test.t1.c1), NULL, 0)))
├─TableReader_20(Build) 10000.00 root data:TableFullScan_19
│ └─TableFullScan_19 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
└─StreamAgg_35(Probe) 1.00 root funcs:max(Column#19)->Column#11, funcs:sum(Column#20)->Column#12, funcs:count(Column#21)->Column#13
└─TableReader_36 1.00 root data:StreamAgg_24
└─StreamAgg_24 1.00 cop[tikv] funcs:max(test.t2.c1)->Column#19, funcs:sum(isnull(test.t2.c1))->Column#20, funcs:count(1)->Column#21
└─Selection_34 10.00 cop[tikv] eq(test.t2.c2, test.t1.c2)
└─TableFullScan_33 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
└─StreamAgg_35(Probe) 10000.00 root funcs:max(Column#19)->Column#11, funcs:sum(Column#20)->Column#12, funcs:count(Column#21)->Column#13
└─TableReader_36 10000.00 root data:StreamAgg_24
└─StreamAgg_24 10000.00 cop[tikv] funcs:max(test.t2.c1)->Column#19, funcs:sum(isnull(test.t2.c1))->Column#20, funcs:count(1)->Column#21
└─Selection_34 100000.00 cop[tikv] eq(test.t2.c2, test.t1.c2)
└─TableFullScan_33 100000000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
select * from t1 where c1 > all(with cte1 as (select c1 from t2 where t2.c2 = t1.c2) select c1 from cte1);
c1 c2
2 1
Expand All @@ -624,9 +624,9 @@ Projection_26 10000.00 root test.t1.c1, test.t1.c2
└─Apply_28 10000.00 root CARTESIAN inner join, other cond:or(and(gt(test.t1.c1, Column#14), if(ne(Column#15, 0), NULL, 1)), or(eq(Column#16, 0), if(isnull(test.t1.c1), NULL, 0)))
├─TableReader_30(Build) 10000.00 root data:TableFullScan_29
│ └─TableFullScan_29 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
└─HashAgg_31(Probe) 1.00 root funcs:max(Column#19)->Column#14, funcs:sum(Column#20)->Column#15, funcs:count(1)->Column#16
└─Projection_35 20.00 root test.t2.c1, cast(isnull(test.t2.c1), decimal(20,0) BINARY)->Column#20
└─CTEFullScan_33 20.00 root CTE:cte1 data:CTE_0
└─HashAgg_31(Probe) 10000.00 root funcs:max(Column#19)->Column#14, funcs:sum(Column#20)->Column#15, funcs:count(1)->Column#16
└─Projection_35 200000.00 root test.t2.c1, cast(isnull(test.t2.c1), decimal(20,0) BINARY)->Column#20
└─CTEFullScan_33 200000.00 root CTE:cte1 data:CTE_0
CTE_0 20.00 root Recursive CTE, limit(offset:0, count:1)
├─Projection_19(Seed Part) 10.00 root test.t2.c1
│ └─TableReader_22 10.00 root data:Selection_21
Expand All @@ -643,7 +643,7 @@ id estRows task access object operator info
Apply_25 10000.00 root CARTESIAN semi join
├─TableReader_27(Build) 10000.00 root data:TableFullScan_26
│ └─TableFullScan_26 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
└─CTEFullScan_28(Probe) 20.00 root CTE:cte1 data:CTE_0
└─CTEFullScan_28(Probe) 200000.00 root CTE:cte1 data:CTE_0
CTE_0 20.00 root Recursive CTE, limit(offset:0, count:10)
├─Projection_17(Seed Part) 10.00 root test.t2.c1
│ └─TableReader_20 10.00 root data:Selection_19
Expand All @@ -662,9 +662,9 @@ Projection_24 10000.00 root test.t1.c1, test.t1.c2
└─Apply_26 10000.00 root CARTESIAN inner join, other cond:or(and(gt(test.t1.c1, Column#18), if(ne(Column#19, 0), NULL, 1)), or(eq(Column#20, 0), if(isnull(test.t1.c1), NULL, 0)))
├─TableReader_28(Build) 10000.00 root data:TableFullScan_27
│ └─TableFullScan_27 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
└─HashAgg_29(Probe) 1.00 root funcs:max(Column#23)->Column#18, funcs:sum(Column#24)->Column#19, funcs:count(1)->Column#20
└─Projection_33 18000.00 root test.t2.c1, cast(isnull(test.t2.c1), decimal(20,0) BINARY)->Column#24
└─CTEFullScan_31 18000.00 root CTE:cte1 data:CTE_0
└─HashAgg_29(Probe) 10000.00 root funcs:max(Column#23)->Column#18, funcs:sum(Column#24)->Column#19, funcs:count(1)->Column#20
└─Projection_33 180000000.00 root test.t2.c1, cast(isnull(test.t2.c1), decimal(20,0) BINARY)->Column#24
└─CTEFullScan_31 180000000.00 root CTE:cte1 data:CTE_0
CTE_0 18000.00 root Recursive CTE
├─TableReader_19(Seed Part) 10000.00 root data:TableFullScan_18
│ └─TableFullScan_18 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
Expand All @@ -678,7 +678,7 @@ id estRows task access object operator info
Apply_23 10000.00 root CARTESIAN semi join
├─TableReader_25(Build) 10000.00 root data:TableFullScan_24
│ └─TableFullScan_24 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
└─CTEFullScan_26(Probe) 18000.00 root CTE:cte1 data:CTE_0
└─CTEFullScan_26(Probe) 180000000.00 root CTE:cte1 data:CTE_0
CTE_0 18000.00 root Recursive CTE
├─TableReader_17(Seed Part) 10000.00 root data:TableFullScan_16
│ └─TableFullScan_16 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
Expand Down
32 changes: 16 additions & 16 deletions cmd/explaintest/r/explain_complex.result
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ Projection 0.00 root test.st.id, test.dd.id, test.st.aid, test.st.cm, test.dd.d
│ └─Selection(Probe) 0.00 cop[tikv] eq(test.st.bm, 0), eq(test.st.dit, "mac"), eq(test.st.pt, "ios"), not(isnull(test.st.dic))
│ └─TableRowIDScan 3333.33 cop[tikv] table:gad keep order:false, stats:pseudo
└─IndexLookUp(Probe) 0.00 root
├─IndexRangeScan(Build) 10000.00 cop[tikv] table:sdk, index:aid(aid, dic) range: decided by [eq(test.dd.aid, test.st.aid)], keep order:false, stats:pseudo
├─IndexRangeScan(Build) 0.03 cop[tikv] table:sdk, index:aid(aid, dic) range: decided by [eq(test.dd.aid, test.st.aid)], keep order:false, stats:pseudo
└─Selection(Probe) 0.00 cop[tikv] eq(test.dd.bm, 0), eq(test.dd.pt, "ios"), gt(test.dd.t, 1477971479), not(isnull(test.dd.mac)), not(isnull(test.dd.t))
└─TableRowIDScan 10000.00 cop[tikv] table:sdk keep order:false, stats:pseudo
└─TableRowIDScan 0.03 cop[tikv] table:sdk keep order:false, stats:pseudo
explain format = 'brief' 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 estRows task access object operator info
Projection 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, Column#20, Column#21
Expand All @@ -157,11 +157,11 @@ Projection 0.01 root test.dt.id, test.dt.aid, test.dt.pt, test.dt.dic, test.dt.
├─TableReader(Build) 3.33 root data:Selection
│ └─Selection 3.33 cop[tikv] eq(test.rr.pt, "ios"), gt(test.rr.t, 1478185592)
│ └─TableFullScan 10000.00 cop[tikv] table:rr keep order:false, stats:pseudo
└─IndexLookUp(Probe) 0.00 root
├─Selection(Build) 1.00 cop[tikv] not(isnull(test.dt.dic))
│ └─IndexRangeScan 1.00 cop[tikv] table:dt, index:aid(aid, dic) range: decided by [eq(test.dt.aid, test.rr.aid) eq(test.dt.dic, test.rr.dic)], keep order:false, stats:pseudo
└─Selection(Probe) 0.00 cop[tikv] eq(test.dt.bm, 0), eq(test.dt.pt, "ios"), gt(test.dt.t, 1478185592)
└─TableRowIDScan 1.00 cop[tikv] table:dt keep order:false, stats:pseudo
└─IndexLookUp(Probe) 0.01 root
├─Selection(Build) 3.33 cop[tikv] not(isnull(test.dt.dic))
│ └─IndexRangeScan 3.33 cop[tikv] table:dt, index:aid(aid, dic) range: decided by [eq(test.dt.aid, test.rr.aid) eq(test.dt.dic, test.rr.dic)], keep order:false, stats:pseudo
└─Selection(Probe) 0.01 cop[tikv] eq(test.dt.bm, 0), eq(test.dt.pt, "ios"), gt(test.dt.t, 1478185592)
└─TableRowIDScan 3.33 cop[tikv] table:dt keep order:false, stats:pseudo
explain format = 'brief' 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 estRows task access object operator info
Projection 1.00 root test.pp.pc, test.pp.cr, Column#22, Column#23, Column#24
Expand Down Expand Up @@ -253,11 +253,11 @@ Sort 1.00 root test.org_department.left_value
│ │ ├─IndexRangeScan(Build) 10.00 cop[tikv] table:d, index:org_department_ctx_index(ctx) range:[1,1], keep order:false, stats:pseudo
│ │ └─Selection(Probe) 0.01 cop[tikv] eq(test.org_department.status, 1000)
│ │ └─TableRowIDScan 10.00 cop[tikv] table:d keep order:false, stats:pseudo
│ └─IndexLookUp(Probe) 1.25 root
│ ├─Selection(Build) 1250.00 cop[tikv] not(isnull(test.org_position.department_id))
│ │ └─IndexRangeScan 1251.25 cop[tikv] table:p, index:org_position_department_id_index(department_id) range: decided by [eq(test.org_position.department_id, test.org_department.id)], keep order:false, stats:pseudo
│ └─Selection(Probe) 1.25 cop[tikv] eq(test.org_position.status, 1000)
│ └─TableRowIDScan 1250.00 cop[tikv] table:p keep order:false, stats:pseudo
│ └─IndexLookUp(Probe) 0.01 root
│ ├─Selection(Build) 12.50 cop[tikv] not(isnull(test.org_position.department_id))
│ │ └─IndexRangeScan 12.51 cop[tikv] table:p, index:org_position_department_id_index(department_id) range: decided by [eq(test.org_position.department_id, test.org_department.id)], keep order:false, stats:pseudo
│ └─Selection(Probe) 0.01 cop[tikv] eq(test.org_position.status, 1000)
│ └─TableRowIDScan 12.50 cop[tikv] table:p keep order:false, stats:pseudo
└─TableReader(Probe) 9.99 root data:Selection
└─Selection 9.99 cop[tikv] eq(test.org_employee_position.status, 1000), not(isnull(test.org_employee_position.position_id))
└─TableFullScan 10000.00 cop[tikv] table:ep keep order:false, stats:pseudo
Expand All @@ -278,10 +278,10 @@ Projection_8 15.62 root test.tab_a.name, test.tab_b.name, test.tab_a.amt, test.
│ ├─TableReader_33(Build) 10.00 root data:Selection_32
│ │ └─Selection_32 10.00 cop[tikv] eq(test.tab_a.num, 112)
│ │ └─TableFullScan_31 10000.00 cop[tikv] table:Tab_A keep order:false, stats:pseudo
│ └─TableReader_21(Probe) 1.00 root data:TableRangeScan_20
│ └─TableRangeScan_20 1.00 cop[tikv] table:Tab_B range: decided by [test.tab_a.bid], keep order:false, stats:pseudo
└─TableReader_10(Probe) 1.00 root data:TableRangeScan_9
└─TableRangeScan_9 1.00 cop[tikv] table:Tab_C range: decided by [test.tab_a.cid], keep order:false, stats:pseudo
│ └─TableReader_21(Probe) 10.00 root data:TableRangeScan_20
│ └─TableRangeScan_20 10.00 cop[tikv] table:Tab_B range: decided by [test.tab_a.bid], keep order:false, stats:pseudo
└─TableReader_10(Probe) 12.50 root data:TableRangeScan_9
└─TableRangeScan_9 12.50 cop[tikv] table:Tab_C range: decided by [test.tab_a.cid], keep order:false, stats:pseudo
select Tab_A.name AAA,Tab_B.name BBB,Tab_A.amt Aamt, Tab_C.amt Bamt,IFNULL(Tab_C.amt, 0) FROM Tab_A left join Tab_B on Tab_A.bid=Tab_B.id left join Tab_C on Tab_A.cid=Tab_C.id and Tab_A.type='01' where Tab_A.num=112;
AAA BBB Aamt Bamt IFNULL(Tab_C.amt, 0)
A01 B01 111.00 22.00 22.00
Expand Down
16 changes: 8 additions & 8 deletions cmd/explaintest/r/explain_complex_stats.result
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ Projection 170.34 root test.st.id, test.dd.id, test.st.aid, test.st.cm, test.dd
├─TableReader(Build) 170.34 root data:Selection
│ └─Selection 170.34 cop[tikv] eq(test.st.bm, 0), eq(test.st.dit, "mac"), eq(test.st.pt, "ios"), gt(test.st.t, 1477971479), not(isnull(test.st.dic))
│ └─TableFullScan 1999.00 cop[tikv] table:gad keep order:false
└─IndexLookUp(Probe) 1.00 root
├─IndexRangeScan(Build) 3.93 cop[tikv] table:sdk, index:aid(aid, dic) range: decided by [eq(test.dd.aid, test.st.aid)], keep order:false
└─Selection(Probe) 1.00 cop[tikv] eq(test.dd.bm, 0), eq(test.dd.pt, "ios"), gt(test.dd.t, 1477971479), not(isnull(test.dd.mac)), not(isnull(test.dd.t))
└─TableRowIDScan 3.93 cop[tikv] table:sdk keep order:false
└─IndexLookUp(Probe) 170.34 root
├─IndexRangeScan(Build) 669.25 cop[tikv] table:sdk, index:aid(aid, dic) range: decided by [eq(test.dd.aid, test.st.aid)], keep order:false
└─Selection(Probe) 170.34 cop[tikv] eq(test.dd.bm, 0), eq(test.dd.pt, "ios"), gt(test.dd.t, 1477971479), not(isnull(test.dd.mac)), not(isnull(test.dd.t))
└─TableRowIDScan 669.25 cop[tikv] table:sdk keep order:false
explain format = 'brief' 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 estRows task access object operator info
Projection 39.28 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, Column#20, Column#21
Expand All @@ -163,10 +163,10 @@ Projection 428.32 root test.dt.id, test.dt.aid, test.dt.pt, test.dt.dic, test.d
├─TableReader(Build) 428.32 root data:Selection
│ └─Selection 428.32 cop[tikv] eq(test.dt.bm, 0), eq(test.dt.pt, "ios"), gt(test.dt.t, 1478185592), not(isnull(test.dt.dic))
│ └─TableFullScan 2000.00 cop[tikv] table:dt keep order:false
└─IndexLookUp(Probe) 1.00 root
├─IndexRangeScan(Build) 1.00 cop[tikv] table:rr, index:PRIMARY(aid, dic) range: decided by [eq(test.rr.aid, test.dt.aid) eq(test.rr.dic, test.dt.dic)], keep order:false
└─Selection(Probe) 1.00 cop[tikv] eq(test.rr.pt, "ios"), gt(test.rr.t, 1478185592)
└─TableRowIDScan 1.00 cop[tikv] table:rr keep order:false
└─IndexLookUp(Probe) 428.32 root
├─IndexRangeScan(Build) 428.32 cop[tikv] table:rr, index:PRIMARY(aid, dic) range: decided by [eq(test.rr.aid, test.dt.aid) eq(test.rr.dic, test.dt.dic)], keep order:false
└─Selection(Probe) 428.32 cop[tikv] eq(test.rr.pt, "ios"), gt(test.rr.t, 1478185592)
└─TableRowIDScan 428.32 cop[tikv] table:rr keep order:false
explain format = 'brief' 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 estRows task access object operator info
Projection 207.02 root test.pp.pc, test.pp.cr, Column#22, Column#23, Column#24
Expand Down
16 changes: 8 additions & 8 deletions cmd/explaintest/r/explain_cte.result
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ id estRows task access object operator info
Apply_24 10000.00 root CARTESIAN semi join
├─TableReader_26(Build) 10000.00 root data:TableFullScan_25
│ └─TableFullScan_25 10000.00 cop[tikv] table:dt keep order:false, stats:pseudo
└─Selection_29(Probe) 1.44 root eq(Column#8, 1)
└─CTEFullScan_30 1.80 root CTE:qn data:CTE_0
└─Selection_29(Probe) 14400.00 root eq(Column#8, 1)
└─CTEFullScan_30 18000.00 root CTE:qn data:CTE_0
CTE_0 1.80 root Recursive CTE
├─Projection_17(Seed Part) 1.00 root plus(mul(test.t1.c1, 0), 1)->Column#4
│ └─TableDual_18 1.00 root rows:1
Expand Down Expand Up @@ -417,9 +417,9 @@ CTE_0 50.00 root Non-Recursive CTE
│ │ └─TableReader(Probe) 9980.01 root data:Selection
│ │ └─Selection 9980.01 cop[tikv] not(isnull(test.store_sales.ss_customer_sk)), not(isnull(test.store_sales.ss_sold_date_sk))
│ │ └─TableFullScan 10000.00 cop[tikv] table:store_sales keep order:false, stats:pseudo
│ └─IndexLookUp(Probe) 1.00 root
│ ├─IndexRangeScan(Build) 1.00 cop[tikv] table:customer, index:PRIMARY(c_customer_sk) range: decided by [eq(test.customer.c_customer_sk, test.store_sales.ss_customer_sk)], keep order:false, stats:pseudo
│ └─TableRowIDScan(Probe) 1.00 cop[tikv] table:customer keep order:false, stats:pseudo
│ └─IndexLookUp(Probe) 25.00 root
│ ├─IndexRangeScan(Build) 25.00 cop[tikv] table:customer, index:PRIMARY(c_customer_sk) range: decided by [eq(test.customer.c_customer_sk, test.store_sales.ss_customer_sk)], keep order:false, stats:pseudo
│ └─TableRowIDScan(Probe) 25.00 cop[tikv] table:customer keep order:false, stats:pseudo
└─Projection 25.00 root test.customer.c_customer_id, test.customer.c_first_name, test.customer.c_last_name, test.customer.c_preferred_cust_flag, test.customer.c_birth_country, test.customer.c_login, test.customer.c_email_address, test.date_dim.d_year, Column#158, w->Column#169
└─Selection 25.00 root or(0, or(and(1, and(eq(test.date_dim.d_year, 2001), gt(Column#158, 0))), and(1, eq(test.date_dim.d_year, 2002))))
└─HashAgg 31.25 root group by:Column#250, Column#251, Column#252, Column#253, Column#254, Column#255, Column#256, Column#257, funcs:sum(Column#241)->Column#158, funcs:firstrow(Column#242)->test.customer.c_customer_id, funcs:firstrow(Column#243)->test.customer.c_first_name, funcs:firstrow(Column#244)->test.customer.c_last_name, funcs:firstrow(Column#245)->test.customer.c_preferred_cust_flag, funcs:firstrow(Column#246)->test.customer.c_birth_country, funcs:firstrow(Column#247)->test.customer.c_login, funcs:firstrow(Column#248)->test.customer.c_email_address, funcs:firstrow(Column#249)->test.date_dim.d_year
Expand All @@ -433,9 +433,9 @@ CTE_0 50.00 root Non-Recursive CTE
│ └─TableReader(Probe) 9980.01 root data:Selection
│ └─Selection 9980.01 cop[tikv] not(isnull(test.web_sales.ws_bill_customer_sk)), not(isnull(test.web_sales.ws_sold_date_sk))
│ └─TableFullScan 10000.00 cop[tikv] table:web_sales keep order:false, stats:pseudo
└─IndexLookUp(Probe) 1.00 root
├─IndexRangeScan(Build) 1.00 cop[tikv] table:customer, index:PRIMARY(c_customer_sk) range: decided by [eq(test.customer.c_customer_sk, test.web_sales.ws_bill_customer_sk)], keep order:false, stats:pseudo
└─TableRowIDScan(Probe) 1.00 cop[tikv] table:customer keep order:false, stats:pseudo
└─IndexLookUp(Probe) 25.00 root
├─IndexRangeScan(Build) 25.00 cop[tikv] table:customer, index:PRIMARY(c_customer_sk) range: decided by [eq(test.customer.c_customer_sk, test.web_sales.ws_bill_customer_sk)], keep order:false, stats:pseudo
└─TableRowIDScan(Probe) 25.00 cop[tikv] table:customer keep order:false, stats:pseudo
drop table if exists t1;
create table t1 (id int, bench_type varchar(10),version varchar(10),tps int(20));
insert into t1 (id,bench_type,version,tps) values (1,'sysbench','5.4.0',1111111);
Expand Down
Loading

0 comments on commit 5fa9da1

Please sign in to comment.