521 lines
33 KiB
Plaintext
521 lines
33 KiB
Plaintext
set tidb_cost_model_version=1;
|
|
drop table if exists t1, t2;
|
|
create table t1 (c1 int primary key, c2 int, index c2 (c2));
|
|
create table t2 (c1 int unique, c2 int);
|
|
insert into t1 values(1, 0), (2, 1);
|
|
insert into t2 values(1, 0), (2, 1);
|
|
explain with cte(a) as (select 1) select * from cte;
|
|
id estRows task access object operator info
|
|
Projection_7 1.00 root 1->Column#3
|
|
└─TableDual_8 1.00 root rows:1
|
|
explain with cte(a) as (select c1 from t1) select * from cte;
|
|
id estRows task access object operator info
|
|
TableReader_9 10000.00 root data:TableFullScan_8
|
|
└─TableFullScan_8 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
explain with cte(a,b,c,d) as (select * from t1, t2) select * from cte;
|
|
id estRows task access object operator info
|
|
HashJoin_13 100000000.00 root CARTESIAN inner join
|
|
├─TableReader_20(Build) 10000.00 root data:TableFullScan_19
|
|
│ └─TableFullScan_19 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
|
|
└─TableReader_16(Probe) 10000.00 root data:TableFullScan_15
|
|
└─TableFullScan_15 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
explain with recursive cte(a) as (select 1 union select a+1 from cte where a < 10) select * from cte;
|
|
id estRows task access object operator info
|
|
CTEFullScan_17 2.00 root CTE:cte data:CTE_0
|
|
CTE_0 2.00 root Recursive CTE
|
|
├─Projection_11(Seed Part) 1.00 root 1->Column#2
|
|
│ └─TableDual_12 1.00 root rows:1
|
|
└─Projection_13(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5
|
|
└─Selection_14 0.80 root lt(Column#3, 10)
|
|
└─CTETable_15 1.00 root Scan on CTE_0
|
|
explain with recursive cte(a) as (select c2 from t1 union select a+1 from cte where a < 10) select * from cte;
|
|
id estRows task access object operator info
|
|
CTEFullScan_20 8001.00 root CTE:cte data:CTE_0
|
|
CTE_0 8001.00 root Recursive CTE
|
|
├─TableReader_13(Seed Part) 10000.00 root data:TableFullScan_12
|
|
│ └─TableFullScan_12 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
└─Projection_16(Recursive Part) 8000.00 root cast(plus(explain_cte.t1.c2, 1), int(11))->explain_cte.t1.c2
|
|
└─Selection_17 8000.00 root lt(explain_cte.t1.c2, 10)
|
|
└─CTETable_18 10000.00 root Scan on CTE_0
|
|
explain with cte(a) as (with recursive cte1(a) as (select 1 union select a + 1 from cte1 where a < 10) select * from cte1) select * from cte;
|
|
id estRows task access object operator info
|
|
CTEFullScan_29 2.00 root CTE:cte1 data:CTE_2
|
|
CTE_2 2.00 root Recursive CTE
|
|
├─Projection_23(Seed Part) 1.00 root 1->Column#9
|
|
│ └─TableDual_24 1.00 root rows:1
|
|
└─Projection_25(Recursive Part) 0.80 root cast(plus(Column#10, 1), bigint(1) BINARY)->Column#12
|
|
└─Selection_26 0.80 root lt(Column#10, 10)
|
|
└─CTETable_27 1.00 root Scan on CTE_2
|
|
explain with recursive cte(a) as (select 1 union select a+1 from cte where a < 10) select * from cte t1, cte t2;
|
|
id estRows task access object operator info
|
|
HashJoin_20 4.00 root CARTESIAN inner join
|
|
├─CTEFullScan_23(Build) 2.00 root CTE:cte AS t2 data:CTE_0
|
|
└─CTEFullScan_22(Probe) 2.00 root CTE:cte AS t1 data:CTE_0
|
|
CTE_0 2.00 root Recursive CTE
|
|
├─Projection_13(Seed Part) 1.00 root 1->Column#2
|
|
│ └─TableDual_14 1.00 root rows:1
|
|
└─Projection_15(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5
|
|
└─Selection_16 0.80 root lt(Column#3, 10)
|
|
└─CTETable_17 1.00 root Scan on CTE_0
|
|
explain with cte(a) as (with recursive cte1(a) as (select 1 union select a + 1 from cte1 where a < 10) select * from cte1) select * from cte t1, cte t2;
|
|
id estRows task access object operator info
|
|
HashJoin_25 4.00 root CARTESIAN inner join
|
|
├─CTEFullScan_28(Build) 2.00 root CTE:cte AS t2 data:CTE_0
|
|
└─CTEFullScan_27(Probe) 2.00 root CTE:cte AS t1 data:CTE_0
|
|
CTE_0 2.00 root Non-Recursive CTE
|
|
└─CTEFullScan_22(Seed Part) 2.00 root CTE:cte1 data:CTE_1
|
|
CTE_1 2.00 root Recursive CTE
|
|
├─Projection_16(Seed Part) 1.00 root 1->Column#2
|
|
│ └─TableDual_17 1.00 root rows:1
|
|
└─Projection_18(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5
|
|
└─Selection_19 0.80 root lt(Column#3, 10)
|
|
└─CTETable_20 1.00 root Scan on CTE_1
|
|
explain with recursive cte1(a) as (select 1 union select a+1 from cte1 where a < 10), cte2(a) as (select c2 from t1 union select a+1 from cte2 where a < 10) select * from cte1, cte2;
|
|
id estRows task access object operator info
|
|
HashJoin_37 16002.00 root CARTESIAN inner join
|
|
├─CTEFullScan_40(Build) 2.00 root CTE:cte1 data:CTE_0
|
|
└─CTEFullScan_41(Probe) 8001.00 root CTE:cte2 data:CTE_1
|
|
CTE_0 2.00 root Recursive CTE
|
|
├─Projection_21(Seed Part) 1.00 root 1->Column#2
|
|
│ └─TableDual_22 1.00 root rows:1
|
|
└─Projection_23(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5
|
|
└─Selection_24 0.80 root lt(Column#3, 10)
|
|
└─CTETable_25 1.00 root Scan on CTE_0
|
|
CTE_1 8001.00 root Recursive CTE
|
|
├─TableReader_28(Seed Part) 10000.00 root data:TableFullScan_27
|
|
│ └─TableFullScan_27 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
└─Projection_31(Recursive Part) 8000.00 root cast(plus(explain_cte.t1.c2, 1), int(11))->explain_cte.t1.c2
|
|
└─Selection_32 8000.00 root lt(explain_cte.t1.c2, 10)
|
|
└─CTETable_33 10000.00 root Scan on CTE_1
|
|
explain with q(a,b) as (select * from t1) select /*+ merge(q) no_merge(q1) */ * from q, q q1 where q.a=1 and q1.a=2;
|
|
id estRows task access object operator info
|
|
HashJoin_15 2.56 root CARTESIAN inner join
|
|
├─Selection_19(Build) 1.60 root eq(explain_cte.t1.c1, 2)
|
|
│ └─CTEFullScan_20 2.00 root CTE:q AS q1 data:CTE_0
|
|
└─Selection_17(Probe) 1.60 root eq(explain_cte.t1.c1, 1)
|
|
└─CTEFullScan_18 2.00 root CTE:q data:CTE_0
|
|
CTE_0 2.00 root Non-Recursive CTE
|
|
└─Batch_Point_Get_12(Seed Part) 2.00 root table:t1 handle:[1 2], keep order:false, desc:false
|
|
explain with recursive cte(a,b) as (select 1, concat('a', 1) union select a+1, concat(b, 1) from cte where a < 5) select * from cte;
|
|
id estRows task access object operator info
|
|
CTEFullScan_17 2.00 root CTE:cte data:CTE_0
|
|
CTE_0 2.00 root Recursive CTE
|
|
├─Projection_11(Seed Part) 1.00 root 1->Column#3, a1->Column#4
|
|
│ └─TableDual_12 1.00 root rows:1
|
|
└─Projection_13(Recursive Part) 0.80 root cast(plus(Column#5, 1), bigint(1) BINARY)->Column#9, cast(concat(Column#6, 1), var_string(21))->Column#10
|
|
└─Selection_14 0.80 root lt(Column#5, 5)
|
|
└─CTETable_15 1.00 root Scan on CTE_0
|
|
explain select * from t1 dt where exists(with recursive qn as (select c1*0+1 as b union all select b+1 from qn where b=0) select * from qn where b=1);
|
|
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) 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(explain_cte.t1.c1, 0), 1)->Column#4
|
|
│ └─TableDual_18 1.00 root rows:1
|
|
└─Projection_19(Recursive Part) 0.80 root plus(Column#5, 1)->Column#7
|
|
└─Selection_20 0.80 root eq(Column#5, 0)
|
|
└─CTETable_21 1.00 root Scan on CTE_0
|
|
explain with recursive cte1(c1) as (select c1 from t1 union select c1 + 1 c1 from cte1 limit 1) select * from cte1;
|
|
id estRows task access object operator info
|
|
CTEFullScan_19 8001.00 root CTE:cte1 data:CTE_0
|
|
CTE_0 8001.00 root Recursive CTE, limit(offset:0, count:1)
|
|
├─TableReader_13(Seed Part) 10000.00 root data:TableFullScan_12
|
|
│ └─TableFullScan_12 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
└─Projection_16(Recursive Part) 10000.00 root cast(plus(explain_cte.t1.c1, 1), int(11))->explain_cte.t1.c1
|
|
└─CTETable_17 10000.00 root Scan on CTE_0
|
|
explain with recursive cte1(c1) as (select c1 from t1 union select c1 + 1 c1 from cte1 limit 100 offset 100) select * from cte1;
|
|
id estRows task access object operator info
|
|
CTEFullScan_19 8001.00 root CTE:cte1 data:CTE_0
|
|
CTE_0 8001.00 root Recursive CTE, limit(offset:100, count:100)
|
|
├─TableReader_13(Seed Part) 10000.00 root data:TableFullScan_12
|
|
│ └─TableFullScan_12 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
└─Projection_16(Recursive Part) 10000.00 root cast(plus(explain_cte.t1.c1, 1), int(11))->explain_cte.t1.c1
|
|
└─CTETable_17 10000.00 root Scan on CTE_0
|
|
explain with recursive cte1(c1) as (select c1 from t1 union select c1 + 1 c1 from cte1 limit 0 offset 0) select * from cte1;
|
|
id estRows task access object operator info
|
|
CTEFullScan_19 8001.00 root CTE:cte1 data:CTE_0
|
|
CTE_0 8001.00 root Recursive CTE, limit(offset:0, count:0)
|
|
├─TableReader_13(Seed Part) 10000.00 root data:TableFullScan_12
|
|
│ └─TableFullScan_12 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
└─Projection_16(Recursive Part) 10000.00 root cast(plus(explain_cte.t1.c1, 1), int(11))->explain_cte.t1.c1
|
|
└─CTETable_17 10000.00 root Scan on CTE_0
|
|
explain with recursive cte1(c1) as (select c1 from t1 union select c1 + 1 c1 from cte1 limit 1) select * from cte1 dt1 join cte1 dt2 on dt1.c1 = dt2.c1;
|
|
id estRows task access object operator info
|
|
HashJoin_25 6400.80 root inner join, equal:[eq(explain_cte.t1.c1, explain_cte.t1.c1)]
|
|
├─Selection_29(Build) 6400.80 root not(isnull(explain_cte.t1.c1))
|
|
│ └─CTEFullScan_30 8001.00 root CTE:cte1 AS dt2 data:CTE_0
|
|
└─Selection_27(Probe) 6400.80 root not(isnull(explain_cte.t1.c1))
|
|
└─CTEFullScan_28 8001.00 root CTE:cte1 AS dt1 data:CTE_0
|
|
CTE_0 8001.00 root Recursive CTE, limit(offset:0, count:1)
|
|
├─TableReader_18(Seed Part) 10000.00 root data:TableFullScan_17
|
|
│ └─TableFullScan_17 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
└─Projection_21(Recursive Part) 10000.00 root cast(plus(explain_cte.t1.c1, 1), int(11))->explain_cte.t1.c1
|
|
└─CTETable_22 10000.00 root Scan on CTE_0
|
|
explain with recursive cte1(c1) as (select c1 from t1 union select c1 + 1 c1 from cte1 limit 0 offset 0) select * from cte1 dt1 join cte1 dt2 on dt1.c1 = dt2.c1;
|
|
id estRows task access object operator info
|
|
HashJoin_25 6400.80 root inner join, equal:[eq(explain_cte.t1.c1, explain_cte.t1.c1)]
|
|
├─Selection_29(Build) 6400.80 root not(isnull(explain_cte.t1.c1))
|
|
│ └─CTEFullScan_30 8001.00 root CTE:cte1 AS dt2 data:CTE_0
|
|
└─Selection_27(Probe) 6400.80 root not(isnull(explain_cte.t1.c1))
|
|
└─CTEFullScan_28 8001.00 root CTE:cte1 AS dt1 data:CTE_0
|
|
CTE_0 8001.00 root Recursive CTE, limit(offset:0, count:0)
|
|
├─TableReader_18(Seed Part) 10000.00 root data:TableFullScan_17
|
|
│ └─TableFullScan_17 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
└─Projection_21(Recursive Part) 10000.00 root cast(plus(explain_cte.t1.c1, 1), int(11))->explain_cte.t1.c1
|
|
└─CTETable_22 10000.00 root Scan on CTE_0
|
|
CREATE TABLE `customer` (
|
|
`c_customer_sk` int(11) NOT NULL,
|
|
`c_customer_id` char(16) NOT NULL,
|
|
`c_current_cdemo_sk` int(11) DEFAULT NULL,
|
|
`c_current_hdemo_sk` int(11) DEFAULT NULL,
|
|
`c_current_addr_sk` int(11) DEFAULT NULL,
|
|
`c_first_shipto_date_sk` int(11) DEFAULT NULL,
|
|
`c_first_sales_date_sk` int(11) DEFAULT NULL,
|
|
`c_salutation` char(10) DEFAULT NULL,
|
|
`c_first_name` char(20) DEFAULT NULL,
|
|
`c_last_name` char(30) DEFAULT NULL,
|
|
`c_preferred_cust_flag` char(1) DEFAULT NULL,
|
|
`c_birth_day` int(11) DEFAULT NULL,
|
|
`c_birth_month` int(11) DEFAULT NULL,
|
|
`c_birth_year` int(11) DEFAULT NULL,
|
|
`c_birth_country` varchar(20) DEFAULT NULL,
|
|
`c_login` char(13) DEFAULT NULL,
|
|
`c_email_address` char(50) DEFAULT NULL,
|
|
`c_last_review_date_sk` int(11) DEFAULT NULL,
|
|
PRIMARY KEY (`c_customer_sk`) /*T![clustered_index] NONCLUSTERED */
|
|
);
|
|
CREATE TABLE `store_sales` (
|
|
`ss_sold_date_sk` int(11) DEFAULT NULL,
|
|
`ss_sold_time_sk` int(11) DEFAULT NULL,
|
|
`ss_item_sk` int(11) NOT NULL,
|
|
`ss_customer_sk` int(11) DEFAULT NULL,
|
|
`ss_cdemo_sk` int(11) DEFAULT NULL,
|
|
`ss_hdemo_sk` int(11) DEFAULT NULL,
|
|
`ss_addr_sk` int(11) DEFAULT NULL,
|
|
`ss_store_sk` int(11) DEFAULT NULL,
|
|
`ss_promo_sk` int(11) DEFAULT NULL,
|
|
`ss_ticket_number` int(11) NOT NULL,
|
|
`ss_quantity` int(11) DEFAULT NULL,
|
|
`ss_wholesale_cost` decimal(7,2) DEFAULT NULL,
|
|
`ss_list_price` decimal(7,2) DEFAULT NULL,
|
|
`ss_sales_price` decimal(7,2) DEFAULT NULL,
|
|
`ss_ext_discount_amt` decimal(7,2) DEFAULT NULL,
|
|
`ss_ext_sales_price` decimal(7,2) DEFAULT NULL,
|
|
`ss_ext_wholesale_cost` decimal(7,2) DEFAULT NULL,
|
|
`ss_ext_list_price` decimal(7,2) DEFAULT NULL,
|
|
`ss_ext_tax` decimal(7,2) DEFAULT NULL,
|
|
`ss_coupon_amt` decimal(7,2) DEFAULT NULL,
|
|
`ss_net_paid` decimal(7,2) DEFAULT NULL,
|
|
`ss_net_paid_inc_tax` decimal(7,2) DEFAULT NULL,
|
|
`ss_net_profit` decimal(7,2) DEFAULT NULL,
|
|
PRIMARY KEY (`ss_item_sk`,`ss_ticket_number`) /*T![clustered_index] NONCLUSTERED */
|
|
);
|
|
CREATE TABLE `date_dim` (
|
|
`d_date_sk` int(11) NOT NULL,
|
|
`d_date_id` char(16) NOT NULL,
|
|
`d_date` date DEFAULT NULL,
|
|
`d_month_seq` int(11) DEFAULT NULL,
|
|
`d_week_seq` int(11) DEFAULT NULL,
|
|
`d_quarter_seq` int(11) DEFAULT NULL,
|
|
`d_year` int(11) DEFAULT NULL,
|
|
`d_dow` int(11) DEFAULT NULL,
|
|
`d_moy` int(11) DEFAULT NULL,
|
|
`d_dom` int(11) DEFAULT NULL,
|
|
`d_qoy` int(11) DEFAULT NULL,
|
|
`d_fy_year` int(11) DEFAULT NULL,
|
|
`d_fy_quarter_seq` int(11) DEFAULT NULL,
|
|
`d_fy_week_seq` int(11) DEFAULT NULL,
|
|
`d_day_name` char(9) DEFAULT NULL,
|
|
`d_quarter_name` char(6) DEFAULT NULL,
|
|
`d_holiday` char(1) DEFAULT NULL,
|
|
`d_weekend` char(1) DEFAULT NULL,
|
|
`d_following_holiday` char(1) DEFAULT NULL,
|
|
`d_first_dom` int(11) DEFAULT NULL,
|
|
`d_last_dom` int(11) DEFAULT NULL,
|
|
`d_same_day_ly` int(11) DEFAULT NULL,
|
|
`d_same_day_lq` int(11) DEFAULT NULL,
|
|
`d_current_day` char(1) DEFAULT NULL,
|
|
`d_current_week` char(1) DEFAULT NULL,
|
|
`d_current_month` char(1) DEFAULT NULL,
|
|
`d_current_quarter` char(1) DEFAULT NULL,
|
|
`d_current_year` char(1) DEFAULT NULL,
|
|
PRIMARY KEY (`d_date_sk`) /*T![clustered_index] NONCLUSTERED */
|
|
);
|
|
CREATE TABLE `web_sales` (
|
|
`ws_sold_date_sk` int(11) DEFAULT NULL,
|
|
`ws_sold_time_sk` int(11) DEFAULT NULL,
|
|
`ws_ship_date_sk` int(11) DEFAULT NULL,
|
|
`ws_item_sk` int(11) NOT NULL,
|
|
`ws_bill_customer_sk` int(11) DEFAULT NULL,
|
|
`ws_bill_cdemo_sk` int(11) DEFAULT NULL,
|
|
`ws_bill_hdemo_sk` int(11) DEFAULT NULL,
|
|
`ws_bill_addr_sk` int(11) DEFAULT NULL,
|
|
`ws_ship_customer_sk` int(11) DEFAULT NULL,
|
|
`ws_ship_cdemo_sk` int(11) DEFAULT NULL,
|
|
`ws_ship_hdemo_sk` int(11) DEFAULT NULL,
|
|
`ws_ship_addr_sk` int(11) DEFAULT NULL,
|
|
`ws_web_page_sk` int(11) DEFAULT NULL,
|
|
`ws_web_site_sk` int(11) DEFAULT NULL,
|
|
`ws_ship_mode_sk` int(11) DEFAULT NULL,
|
|
`ws_warehouse_sk` int(11) DEFAULT NULL,
|
|
`ws_promo_sk` int(11) DEFAULT NULL,
|
|
`ws_order_number` int(11) NOT NULL,
|
|
`ws_quantity` int(11) DEFAULT NULL,
|
|
`ws_wholesale_cost` decimal(7,2) DEFAULT NULL,
|
|
`ws_list_price` decimal(7,2) DEFAULT NULL,
|
|
`ws_sales_price` decimal(7,2) DEFAULT NULL,
|
|
`ws_ext_discount_amt` decimal(7,2) DEFAULT NULL,
|
|
`ws_ext_sales_price` decimal(7,2) DEFAULT NULL,
|
|
`ws_ext_wholesale_cost` decimal(7,2) DEFAULT NULL,
|
|
`ws_ext_list_price` decimal(7,2) DEFAULT NULL,
|
|
`ws_ext_tax` decimal(7,2) DEFAULT NULL,
|
|
`ws_coupon_amt` decimal(7,2) DEFAULT NULL,
|
|
`ws_ext_ship_cost` decimal(7,2) DEFAULT NULL,
|
|
`ws_net_paid` decimal(7,2) DEFAULT NULL,
|
|
`ws_net_paid_inc_tax` decimal(7,2) DEFAULT NULL,
|
|
`ws_net_paid_inc_ship` decimal(7,2) DEFAULT NULL,
|
|
`ws_net_paid_inc_ship_tax` decimal(7,2) DEFAULT NULL,
|
|
`ws_net_profit` decimal(7,2) DEFAULT NULL,
|
|
PRIMARY KEY (`ws_item_sk`,`ws_order_number`) /*T![clustered_index] NONCLUSTERED */
|
|
);
|
|
desc format='brief' with year_total as (
|
|
select c_customer_id customer_id
|
|
,c_first_name customer_first_name
|
|
,c_last_name customer_last_name
|
|
,c_preferred_cust_flag customer_preferred_cust_flag
|
|
,c_birth_country customer_birth_country
|
|
,c_login customer_login
|
|
,c_email_address customer_email_address
|
|
,d_year dyear
|
|
,sum(ss_ext_list_price-ss_ext_discount_amt) year_total
|
|
,'s' sale_type
|
|
from customer
|
|
,store_sales
|
|
,date_dim
|
|
where c_customer_sk = ss_customer_sk
|
|
and ss_sold_date_sk = d_date_sk
|
|
group by c_customer_id
|
|
,c_first_name
|
|
,c_last_name
|
|
,c_preferred_cust_flag
|
|
,c_birth_country
|
|
,c_login
|
|
,c_email_address
|
|
,d_year
|
|
union all
|
|
select c_customer_id customer_id
|
|
,c_first_name customer_first_name
|
|
,c_last_name customer_last_name
|
|
,c_preferred_cust_flag customer_preferred_cust_flag
|
|
,c_birth_country customer_birth_country
|
|
,c_login customer_login
|
|
,c_email_address customer_email_address
|
|
,d_year dyear
|
|
,sum(ws_ext_list_price-ws_ext_discount_amt) year_total
|
|
,'w' sale_type
|
|
from customer
|
|
,web_sales
|
|
,date_dim
|
|
where c_customer_sk = ws_bill_customer_sk
|
|
and ws_sold_date_sk = d_date_sk
|
|
group by c_customer_id
|
|
,c_first_name
|
|
,c_last_name
|
|
,c_preferred_cust_flag
|
|
,c_birth_country
|
|
,c_login
|
|
,c_email_address
|
|
,d_year
|
|
)
|
|
select
|
|
t_s_secyear.customer_id
|
|
,t_s_secyear.customer_first_name
|
|
,t_s_secyear.customer_last_name
|
|
,t_s_secyear.customer_email_address
|
|
from year_total t_s_firstyear
|
|
,year_total t_s_secyear
|
|
,year_total t_w_firstyear
|
|
,year_total t_w_secyear
|
|
where t_s_secyear.customer_id = t_s_firstyear.customer_id
|
|
and t_s_firstyear.customer_id = t_w_secyear.customer_id
|
|
and t_s_firstyear.customer_id = t_w_firstyear.customer_id
|
|
and t_s_firstyear.sale_type = 's'
|
|
and t_w_firstyear.sale_type = 'w'
|
|
and t_s_secyear.sale_type = 's'
|
|
and t_w_secyear.sale_type = 'w'
|
|
and t_s_firstyear.dyear = 2001
|
|
and t_s_secyear.dyear = 2001+1
|
|
and t_w_firstyear.dyear = 2001
|
|
and t_w_secyear.dyear = 2001+1
|
|
and t_s_firstyear.year_total > 0
|
|
and t_w_firstyear.year_total > 0
|
|
and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end
|
|
> case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end
|
|
order by t_s_secyear.customer_id
|
|
,t_s_secyear.customer_first_name
|
|
,t_s_secyear.customer_last_name
|
|
,t_s_secyear.customer_email_address
|
|
limit 100;
|
|
id estRows task access object operator info
|
|
TopN 40.00 root Column#180, Column#181, Column#182, Column#186, offset:0, count:100
|
|
└─HashJoin 40.00 root inner join, equal:[eq(Column#170, Column#200)], other cond:gt(case(gt(Column#198, 0), div(Column#208, Column#198), 0.000000), case(gt(Column#178, 0), div(Column#188, Column#178), 0.000000))
|
|
├─Selection(Build) 40.00 root eq(Column#207, 2002), eq(Column#209, "w"), not(isnull(Column#200))
|
|
│ └─CTEFullScan 50.00 root CTE:year_total AS t_w_secyear data:CTE_0
|
|
└─HashJoin(Probe) 40.00 root inner join, equal:[eq(Column#170, Column#190)]
|
|
├─Selection(Build) 40.00 root eq(Column#197, 2001), eq(Column#199, "w"), gt(Column#198, 0), not(isnull(Column#190))
|
|
│ └─CTEFullScan 50.00 root CTE:year_total AS t_w_firstyear data:CTE_0
|
|
└─HashJoin(Probe) 40.00 root inner join, equal:[eq(Column#170, Column#180)]
|
|
├─Selection(Build) 40.00 root eq(Column#187, 2002), eq(Column#189, "s"), not(isnull(Column#180))
|
|
│ └─CTEFullScan 50.00 root CTE:year_total AS t_s_secyear data:CTE_0
|
|
└─Selection(Probe) 40.00 root eq(Column#177, 2001), eq(Column#179, "s"), gt(Column#178, 0), not(isnull(Column#170))
|
|
└─CTEFullScan 50.00 root CTE:year_total AS t_s_firstyear data:CTE_0
|
|
CTE_0 50.00 root Non-Recursive CTE
|
|
└─Union(Seed Part) 50.00 root
|
|
├─Projection 25.00 root explain_cte.customer.c_customer_id->Column#160, explain_cte.customer.c_first_name->Column#161, explain_cte.customer.c_last_name->Column#162, explain_cte.customer.c_preferred_cust_flag->Column#163, explain_cte.customer.c_birth_country->Column#164, explain_cte.customer.c_login->Column#165, explain_cte.customer.c_email_address->Column#166, explain_cte.date_dim.d_year->Column#167, Column#73->Column#168, s->Column#169
|
|
│ └─Selection 25.00 root or(or(and(1, and(eq(explain_cte.date_dim.d_year, 2001), gt(Column#73, 0))), and(1, eq(explain_cte.date_dim.d_year, 2002))), 0)
|
|
│ └─HashAgg 31.25 root group by:Column#225, Column#226, Column#227, Column#228, Column#229, Column#230, Column#231, Column#232, funcs:sum(Column#224)->Column#73, funcs:firstrow(Column#225)->explain_cte.customer.c_customer_id, funcs:firstrow(Column#226)->explain_cte.customer.c_first_name, funcs:firstrow(Column#227)->explain_cte.customer.c_last_name, funcs:firstrow(Column#228)->explain_cte.customer.c_preferred_cust_flag, funcs:firstrow(Column#229)->explain_cte.customer.c_birth_country, funcs:firstrow(Column#230)->explain_cte.customer.c_login, funcs:firstrow(Column#231)->explain_cte.customer.c_email_address, funcs:firstrow(Column#232)->explain_cte.date_dim.d_year
|
|
│ └─Projection 31.25 root minus(explain_cte.store_sales.ss_ext_list_price, explain_cte.store_sales.ss_ext_discount_amt)->Column#224, explain_cte.customer.c_customer_id->Column#225, explain_cte.customer.c_first_name->Column#226, explain_cte.customer.c_last_name->Column#227, explain_cte.customer.c_preferred_cust_flag->Column#228, explain_cte.customer.c_birth_country->Column#229, explain_cte.customer.c_login->Column#230, explain_cte.customer.c_email_address->Column#231, explain_cte.date_dim.d_year->Column#232
|
|
│ └─Projection 31.25 root explain_cte.customer.c_customer_id, explain_cte.customer.c_first_name, explain_cte.customer.c_last_name, explain_cte.customer.c_preferred_cust_flag, explain_cte.customer.c_birth_country, explain_cte.customer.c_login, explain_cte.customer.c_email_address, explain_cte.store_sales.ss_ext_discount_amt, explain_cte.store_sales.ss_ext_list_price, explain_cte.date_dim.d_year
|
|
│ └─IndexJoin 31.25 root inner join, inner:IndexLookUp, outer key:explain_cte.store_sales.ss_customer_sk, inner key:explain_cte.customer.c_customer_sk, equal cond:eq(explain_cte.store_sales.ss_customer_sk, explain_cte.customer.c_customer_sk)
|
|
│ ├─HashJoin(Build) 25.00 root inner join, equal:[eq(explain_cte.date_dim.d_date_sk, explain_cte.store_sales.ss_sold_date_sk)]
|
|
│ │ ├─TableReader(Build) 20.00 root data:Selection
|
|
│ │ │ └─Selection 20.00 cop[tikv] or(and(1, eq(explain_cte.date_dim.d_year, 2001)), or(and(1, eq(explain_cte.date_dim.d_year, 2002)), 0))
|
|
│ │ │ └─TableFullScan 10000.00 cop[tikv] table:date_dim keep order:false, stats:pseudo
|
|
│ │ └─TableReader(Probe) 9980.01 root data:Selection
|
|
│ │ └─Selection 9980.01 cop[tikv] not(isnull(explain_cte.store_sales.ss_customer_sk)), not(isnull(explain_cte.store_sales.ss_sold_date_sk))
|
|
│ │ └─TableFullScan 10000.00 cop[tikv] table:store_sales 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(explain_cte.customer.c_customer_sk, explain_cte.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 explain_cte.customer.c_customer_id->Column#160, explain_cte.customer.c_first_name->Column#161, explain_cte.customer.c_last_name->Column#162, explain_cte.customer.c_preferred_cust_flag->Column#163, explain_cte.customer.c_birth_country->Column#164, explain_cte.customer.c_login->Column#165, explain_cte.customer.c_email_address->Column#166, explain_cte.date_dim.d_year->Column#167, Column#158->Column#168, w->Column#169
|
|
└─Selection 25.00 root or(0, or(and(1, and(eq(explain_cte.date_dim.d_year, 2001), gt(Column#158, 0))), and(1, eq(explain_cte.date_dim.d_year, 2002))))
|
|
└─HashAgg 31.25 root group by:Column#234, Column#235, Column#236, Column#237, Column#238, Column#239, Column#240, Column#241, funcs:sum(Column#233)->Column#158, funcs:firstrow(Column#234)->explain_cte.customer.c_customer_id, funcs:firstrow(Column#235)->explain_cte.customer.c_first_name, funcs:firstrow(Column#236)->explain_cte.customer.c_last_name, funcs:firstrow(Column#237)->explain_cte.customer.c_preferred_cust_flag, funcs:firstrow(Column#238)->explain_cte.customer.c_birth_country, funcs:firstrow(Column#239)->explain_cte.customer.c_login, funcs:firstrow(Column#240)->explain_cte.customer.c_email_address, funcs:firstrow(Column#241)->explain_cte.date_dim.d_year
|
|
└─Projection 31.25 root minus(explain_cte.web_sales.ws_ext_list_price, explain_cte.web_sales.ws_ext_discount_amt)->Column#233, explain_cte.customer.c_customer_id->Column#234, explain_cte.customer.c_first_name->Column#235, explain_cte.customer.c_last_name->Column#236, explain_cte.customer.c_preferred_cust_flag->Column#237, explain_cte.customer.c_birth_country->Column#238, explain_cte.customer.c_login->Column#239, explain_cte.customer.c_email_address->Column#240, explain_cte.date_dim.d_year->Column#241
|
|
└─Projection 31.25 root explain_cte.customer.c_customer_id, explain_cte.customer.c_first_name, explain_cte.customer.c_last_name, explain_cte.customer.c_preferred_cust_flag, explain_cte.customer.c_birth_country, explain_cte.customer.c_login, explain_cte.customer.c_email_address, explain_cte.web_sales.ws_ext_discount_amt, explain_cte.web_sales.ws_ext_list_price, explain_cte.date_dim.d_year
|
|
└─IndexJoin 31.25 root inner join, inner:IndexLookUp, outer key:explain_cte.web_sales.ws_bill_customer_sk, inner key:explain_cte.customer.c_customer_sk, equal cond:eq(explain_cte.web_sales.ws_bill_customer_sk, explain_cte.customer.c_customer_sk)
|
|
├─HashJoin(Build) 25.00 root inner join, equal:[eq(explain_cte.date_dim.d_date_sk, explain_cte.web_sales.ws_sold_date_sk)]
|
|
│ ├─TableReader(Build) 20.00 root data:Selection
|
|
│ │ └─Selection 20.00 cop[tikv] or(0, or(and(1, eq(explain_cte.date_dim.d_year, 2001)), and(1, eq(explain_cte.date_dim.d_year, 2002))))
|
|
│ │ └─TableFullScan 10000.00 cop[tikv] table:date_dim keep order:false, stats:pseudo
|
|
│ └─TableReader(Probe) 9980.01 root data:Selection
|
|
│ └─Selection 9980.01 cop[tikv] not(isnull(explain_cte.web_sales.ws_bill_customer_sk)), not(isnull(explain_cte.web_sales.ws_sold_date_sk))
|
|
│ └─TableFullScan 10000.00 cop[tikv] table:web_sales 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(explain_cte.customer.c_customer_sk, explain_cte.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);
|
|
insert into t1 (id,bench_type,version,tps) values (2,'sysbench','6.0.0',222222);
|
|
with all_data as
|
|
(select * from t1
|
|
),version1 as (select * from all_data where version ='5.4.0'
|
|
),version2 as(select * from all_data where version ='6.0.0')
|
|
select v1.tps v1_tps,v2.tps v2_tps
|
|
from version1 v1, version2 v2
|
|
where v1.bench_type =v2.bench_type;
|
|
v1_tps v2_tps
|
|
1111111 222222
|
|
desc format='brief' with all_data as
|
|
(select * from t1
|
|
),version1 as (select * from all_data where version ='5.4.0'
|
|
),version2 as(select * from all_data where version ='6.0.0')
|
|
select v1.tps v1_tps,v2.tps v2_tps
|
|
from version1 v1, version2 v2
|
|
where v1.bench_type =v2.bench_type;
|
|
id estRows task access object operator info
|
|
HashJoin 19.97 root inner join, equal:[eq(explain_cte.t1.bench_type, explain_cte.t1.bench_type)]
|
|
├─Selection(Build) 15.98 root eq(explain_cte.t1.version, "6.0.0"), not(isnull(explain_cte.t1.bench_type))
|
|
│ └─CTEFullScan 19.97 root CTE:all_data data:CTE_0
|
|
└─Selection(Probe) 15.98 root eq(explain_cte.t1.version, "5.4.0"), not(isnull(explain_cte.t1.bench_type))
|
|
└─CTEFullScan 19.97 root CTE:all_data data:CTE_0
|
|
CTE_0 19.97 root Non-Recursive CTE
|
|
└─TableReader(Seed Part) 19.97 root data:Selection
|
|
└─Selection 19.97 cop[tikv] or(and(eq(explain_cte.t1.version, "5.4.0"), not(isnull(explain_cte.t1.bench_type))), and(eq(explain_cte.t1.version, "6.0.0"), not(isnull(explain_cte.t1.bench_type))))
|
|
└─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
drop table if exists tbl;
|
|
create table tbl (id int);
|
|
explain with t1 as (select id from tbl), t2 as (select a.id from t1 a join t1 b on a.id = b.id) select * from t2 where id in (select id from t2);
|
|
id estRows task access object operator info
|
|
HashJoin_33 8000.00 root inner join, equal:[eq(explain_cte.tbl.id, explain_cte.tbl.id)]
|
|
├─HashAgg_37(Build) 5120.00 root group by:explain_cte.tbl.id, funcs:firstrow(explain_cte.tbl.id)->explain_cte.tbl.id
|
|
│ └─Selection_38 8000.00 root not(isnull(explain_cte.tbl.id))
|
|
│ └─CTEFullScan_39 10000.00 root CTE:t2 data:CTE_1
|
|
└─Selection_35(Probe) 8000.00 root not(isnull(explain_cte.tbl.id))
|
|
└─CTEFullScan_36 10000.00 root CTE:t2 data:CTE_1
|
|
CTE_1 10000.00 root Non-Recursive CTE
|
|
└─HashJoin_25(Seed Part) 10000.00 root inner join, equal:[eq(explain_cte.tbl.id, explain_cte.tbl.id)]
|
|
├─Selection_29(Build) 8000.00 root not(isnull(explain_cte.tbl.id))
|
|
│ └─CTEFullScan_30 10000.00 root CTE:t1 AS b data:CTE_0
|
|
└─Selection_27(Probe) 8000.00 root not(isnull(explain_cte.tbl.id))
|
|
└─CTEFullScan_28 10000.00 root CTE:t1 AS a data:CTE_0
|
|
CTE_0 10000.00 root Non-Recursive CTE
|
|
└─TableReader_22(Seed Part) 10000.00 root data:TableFullScan_21
|
|
└─TableFullScan_21 10000.00 cop[tikv] table:tbl keep order:false, stats:pseudo
|
|
drop table if exists t1, t2, t3;
|
|
create table t1 (a int, b int);
|
|
create table t2 (c int, d int);
|
|
create table t3 (e int, f int);
|
|
insert into t1 values(1,1);
|
|
insert into t2 values(1,1);
|
|
insert into t3 values(1,1234);
|
|
explain update t1 inner join (select t2.c from t2 inner join (with temp as (select e from t3 where t3.f = 1234) select e from temp) tt on t2.d = tt.e) t on t1.a = t.c set t1.b = 4321;
|
|
id estRows task access object operator info
|
|
Update_17 N/A root N/A
|
|
└─HashJoin_22 15.61 root inner join, equal:[eq(explain_cte.t1.a, explain_cte.t2.c)]
|
|
├─HashJoin_30(Build) 12.49 root inner join, equal:[eq(explain_cte.t3.e, explain_cte.t2.d)]
|
|
│ ├─TableReader_39(Build) 9.99 root data:Projection_33
|
|
│ │ └─Projection_33 9.99 cop[tikv] explain_cte.t3.e
|
|
│ │ └─Selection_38 9.99 cop[tikv] eq(explain_cte.t3.f, 1234), not(isnull(explain_cte.t3.e))
|
|
│ │ └─TableFullScan_37 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo
|
|
│ └─TableReader_42(Probe) 9980.01 root data:Selection_41
|
|
│ └─Selection_41 9980.01 cop[tikv] not(isnull(explain_cte.t2.c)), not(isnull(explain_cte.t2.d))
|
|
│ └─TableFullScan_40 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
|
|
└─TableReader_26(Probe) 9990.00 root data:Selection_25
|
|
└─Selection_25 9990.00 cop[tikv] not(isnull(explain_cte.t1.a))
|
|
└─TableFullScan_24 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
update t1 inner join (select t2.c from t2 inner join (with temp as (select e from t3 where t3.f = 1234) select e from temp) tt on t2.d = tt.e) t on t1.a = t.c set t1.b = 4321;
|
|
select * from t1;
|
|
a b
|
|
1 4321
|
|
explain insert into t1 select t1.a, t1.b from t1 inner join (select t2.c from t2 inner join (with temp as (select e from t3 where t3.f = 1234) select e from temp) tt on t2.d = tt.e) t on t1.a = t.c;
|
|
id estRows task access object operator info
|
|
Insert_1 N/A root N/A
|
|
└─HashJoin_26 15.61 root inner join, equal:[eq(explain_cte.t2.c, explain_cte.t1.a)]
|
|
├─HashJoin_28(Build) 12.49 root inner join, equal:[eq(explain_cte.t3.e, explain_cte.t2.d)]
|
|
│ ├─TableReader_31(Build) 9.99 root data:Selection_30
|
|
│ │ └─Selection_30 9.99 cop[tikv] eq(explain_cte.t3.f, 1234), not(isnull(explain_cte.t3.e))
|
|
│ │ └─TableFullScan_29 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo
|
|
│ └─TableReader_34(Probe) 9980.01 root data:Selection_33
|
|
│ └─Selection_33 9980.01 cop[tikv] not(isnull(explain_cte.t2.c)), not(isnull(explain_cte.t2.d))
|
|
│ └─TableFullScan_32 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
|
|
└─TableReader_37(Probe) 9990.00 root data:Selection_36
|
|
└─Selection_36 9990.00 cop[tikv] not(isnull(explain_cte.t1.a))
|
|
└─TableFullScan_35 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
insert into t1 select t1.a, t1.b from t1 inner join (select t2.c from t2 inner join (with temp as (select e from t3 where t3.f = 1234) select e from temp) tt on t2.d = tt.e) t on t1.a = t.c;
|
|
select * from t1;
|
|
a b
|
|
1 4321
|
|
1 4321
|
|
explain delete from t1 using t1 inner join (select t2.c from t2 inner join (with temp as (select e from t3 where t3.f = 1234) select e from temp) tt on t2.d = tt.e) t on t1.a = t.c;
|
|
id estRows task access object operator info
|
|
Delete_17 N/A root N/A
|
|
└─Projection_23 15.61 root explain_cte.t1.a, explain_cte.t1.b, explain_cte.t1._tidb_rowid, explain_cte.t2.c
|
|
└─HashJoin_25 15.61 root inner join, equal:[eq(explain_cte.t2.c, explain_cte.t1.a)]
|
|
├─HashJoin_27(Build) 12.49 root inner join, equal:[eq(explain_cte.t3.e, explain_cte.t2.d)]
|
|
│ ├─TableReader_30(Build) 9.99 root data:Selection_29
|
|
│ │ └─Selection_29 9.99 cop[tikv] eq(explain_cte.t3.f, 1234), not(isnull(explain_cte.t3.e))
|
|
│ │ └─TableFullScan_28 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo
|
|
│ └─TableReader_33(Probe) 9980.01 root data:Selection_32
|
|
│ └─Selection_32 9980.01 cop[tikv] not(isnull(explain_cte.t2.c)), not(isnull(explain_cte.t2.d))
|
|
│ └─TableFullScan_31 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
|
|
└─TableReader_36(Probe) 9990.00 root data:Selection_35
|
|
└─Selection_35 9990.00 cop[tikv] not(isnull(explain_cte.t1.a))
|
|
└─TableFullScan_34 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
|
|
delete from t1 using t1 inner join (select t2.c from t2 inner join (with temp as (select e from t3 where t3.f = 1234) select e from temp) tt on t2.d = tt.e) t on t1.a = t.c;
|
|
select * from t1;
|
|
a b
|