You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

126 lines
8.9 KiB

use test;
drop table if exists t;
create table t (a int, b int, c timestamp, index idx(a));
set @@tidb_enable_window_function = 1;
set @@session.tidb_window_concurrency = 1;
explain select sum(a) over() from t;
id estRows task access object operator info
Projection_7 10000.00 root Column#6
└─Window_8 10000.00 root sum(cast(test.t.a, decimal(65,0) BINARY))->Column#6 over()
└─IndexReader_12 10000.00 root index:IndexFullScan_11
└─IndexFullScan_11 10000.00 cop[tikv] table:t, index:idx(a) keep order:false, stats:pseudo
explain select sum(a) over(partition by a) from t;
id estRows task access object operator info
Projection_7 10000.00 root Column#6
└─Window_8 10000.00 root sum(cast(test.t.a, decimal(65,0) BINARY))->Column#6 over(partition by test.t.a)
└─IndexReader_10 10000.00 root index:IndexFullScan_9
└─IndexFullScan_9 10000.00 cop[tikv] table:t, index:idx(a) keep order:true, stats:pseudo
explain select sum(a) over(partition by a order by b) from t;
id estRows task access object operator info
Projection_7 10000.00 root Column#6
└─Window_8 10000.00 root sum(cast(test.t.a, decimal(65,0) BINARY))->Column#6 over(partition by test.t.a order by test.t.b asc range between unbounded preceding and current row)
└─Sort_11 10000.00 root test.t.a:asc, test.t.b:asc
└─TableReader_10 10000.00 root data:TableFullScan_9
└─TableFullScan_9 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
explain select sum(a) over(partition by a order by b rows unbounded preceding) from t;
id estRows task access object operator info
Projection_7 10000.00 root Column#6
└─Window_8 10000.00 root sum(cast(test.t.a, decimal(65,0) BINARY))->Column#6 over(partition by test.t.a order by test.t.b asc rows between unbounded preceding and current row)
└─Sort_11 10000.00 root test.t.a:asc, test.t.b:asc
└─TableReader_10 10000.00 root data:TableFullScan_9
└─TableFullScan_9 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
explain select sum(a) over(partition by a order by b rows between 1 preceding and 1 following) from t;
id estRows task access object operator info
Projection_7 10000.00 root Column#6
└─Window_8 10000.00 root sum(cast(test.t.a, decimal(65,0) BINARY))->Column#6 over(partition by test.t.a order by test.t.b asc rows between 1 preceding and 1 following)
└─Sort_11 10000.00 root test.t.a:asc, test.t.b:asc
└─TableReader_10 10000.00 root data:TableFullScan_9
└─TableFullScan_9 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
explain select sum(a) over(partition by a order by b range between 1 preceding and 1 following) from t;
id estRows task access object operator info
Projection_7 10000.00 root Column#6
└─Window_8 10000.00 root sum(cast(test.t.a, decimal(65,0) BINARY))->Column#6 over(partition by test.t.a order by test.t.b asc range between 1 preceding and 1 following)
└─Sort_11 10000.00 root test.t.a:asc, test.t.b:asc
└─TableReader_10 10000.00 root data:TableFullScan_9
└─TableFullScan_9 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
explain select sum(a) over(partition by a order by c range between interval '2:30' minute_second preceding and interval '2:30' minute_second following) from t;
id estRows task access object operator info
Projection_7 10000.00 root Column#6
└─Window_8 10000.00 root sum(cast(test.t.a, decimal(65,0) BINARY))->Column#6 over(partition by test.t.a order by test.t.c asc range between interval "2:30" "MINUTE_SECOND" preceding and interval "2:30" "MINUTE_SECOND" following)
└─Sort_11 10000.00 root test.t.a:asc, test.t.c:asc
└─TableReader_10 10000.00 root data:TableFullScan_9
└─TableFullScan_9 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
set @@session.tidb_window_concurrency = 4;
explain select sum(a) over() from t;
id estRows task access object operator info
Projection_7 10000.00 root Column#6
└─Window_8 10000.00 root sum(cast(test.t.a, decimal(65,0) BINARY))->Column#6 over()
└─IndexReader_12 10000.00 root index:IndexFullScan_11
└─IndexFullScan_11 10000.00 cop[tikv] table:t, index:idx(a) keep order:false, stats:pseudo
explain select sum(a) over(partition by a) from t;
id estRows task access object operator info
Projection_7 10000.00 root Column#6
└─Window_8 10000.00 root sum(cast(test.t.a, decimal(65,0) BINARY))->Column#6 over(partition by test.t.a)
└─IndexReader_10 10000.00 root index:IndexFullScan_9
└─IndexFullScan_9 10000.00 cop[tikv] table:t, index:idx(a) keep order:true, stats:pseudo
explain select sum(a) over(partition by a order by b) from t;
id estRows task access object operator info
Projection_7 10000.00 root Column#6
└─Shuffle_12 10000.00 root execution info: concurrency:4, data source:TableReader_10
└─Window_8 10000.00 root sum(cast(test.t.a, decimal(65,0) BINARY))->Column#6 over(partition by test.t.a order by test.t.b asc range between unbounded preceding and current row)
└─Sort_11 10000.00 root test.t.a:asc, test.t.b:asc
└─TableReader_10 10000.00 root data:TableFullScan_9
└─TableFullScan_9 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
explain select sum(a) over(partition by a order by b rows unbounded preceding) from t;
id estRows task access object operator info
Projection_7 10000.00 root Column#6
└─Shuffle_12 10000.00 root execution info: concurrency:4, data source:TableReader_10
└─Window_8 10000.00 root sum(cast(test.t.a, decimal(65,0) BINARY))->Column#6 over(partition by test.t.a order by test.t.b asc rows between unbounded preceding and current row)
└─Sort_11 10000.00 root test.t.a:asc, test.t.b:asc
└─TableReader_10 10000.00 root data:TableFullScan_9
└─TableFullScan_9 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
explain select sum(a) over(partition by a order by b rows between 1 preceding and 1 following) from t;
id estRows task access object operator info
Projection_7 10000.00 root Column#6
└─Shuffle_12 10000.00 root execution info: concurrency:4, data source:TableReader_10
└─Window_8 10000.00 root sum(cast(test.t.a, decimal(65,0) BINARY))->Column#6 over(partition by test.t.a order by test.t.b asc rows between 1 preceding and 1 following)
└─Sort_11 10000.00 root test.t.a:asc, test.t.b:asc
└─TableReader_10 10000.00 root data:TableFullScan_9
└─TableFullScan_9 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
explain select sum(a) over(partition by a order by b range between 1 preceding and 1 following) from t;
id estRows task access object operator info
Projection_7 10000.00 root Column#6
└─Shuffle_12 10000.00 root execution info: concurrency:4, data source:TableReader_10
└─Window_8 10000.00 root sum(cast(test.t.a, decimal(65,0) BINARY))->Column#6 over(partition by test.t.a order by test.t.b asc range between 1 preceding and 1 following)
└─Sort_11 10000.00 root test.t.a:asc, test.t.b:asc
└─TableReader_10 10000.00 root data:TableFullScan_9
└─TableFullScan_9 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
explain select sum(a) over(partition by a order by c range between interval '2:30' minute_second preceding and interval '2:30' minute_second following) from t;
id estRows task access object operator info
Projection_7 10000.00 root Column#6
└─Shuffle_12 10000.00 root execution info: concurrency:4, data source:TableReader_10
└─Window_8 10000.00 root sum(cast(test.t.a, decimal(65,0) BINARY))->Column#6 over(partition by test.t.a order by test.t.c asc range between interval "2:30" "MINUTE_SECOND" preceding and interval "2:30" "MINUTE_SECOND" following)
└─Sort_11 10000.00 root test.t.a:asc, test.t.c:asc
└─TableReader_10 10000.00 root data:TableFullScan_9
└─TableFullScan_9 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
drop table if exists t1;
create table t1(a int primary key, b int);
insert into t1 values(1, 1), (2, 1);
analyze table t1;
explain select sum(a) over(partition by b) from t1;
id estRows task access object operator info
Projection_7 2.00 root Column#4
└─Window_8 2.00 root sum(cast(test.t1.a, decimal(65,0) BINARY))->Column#4 over(partition by test.t1.b)
└─Sort_11 2.00 root test.t1.b:asc
└─TableReader_10 2.00 root data:TableFullScan_9
└─TableFullScan_9 2.00 cop[tikv] table:t1 keep order:false
insert into t1 values(3, 3);
analyze table t1;
explain select sum(a) over(partition by b) from t1;
id estRows task access object operator info
Projection_7 3.00 root Column#4
└─Shuffle_12 3.00 root execution info: concurrency:2, data source:TableReader_10
└─Window_8 3.00 root sum(cast(test.t1.a, decimal(65,0) BINARY))->Column#4 over(partition by test.t1.b)
└─Sort_11 3.00 root test.t1.b:asc
└─TableReader_10 3.00 root data:TableFullScan_9
└─TableFullScan_9 3.00 cop[tikv] table:t1 keep order:false