group_min_max.test

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· TEST 代码 · 共 895 行 · 第 1/4 页

TEST
895
字号
select a1,a2,b,min(c),max(c) from t2 where (a2 >= 'b') and (b = 'a') and (c > 'b111') group by a1,a2,b;select a1,a2,b,min(c) from t2 where ((a1 > 'a') or (a1 < '9'))  and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c < 'h112') or (c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122')) group by a1,a2,b;select a1,a2,b,min(c) from t2 where ((a1 > 'a') or (a1 < '9'))  and ((a2 >= 'b') and (a2 < 'z')) and (b = 'a') and ((c = 'j121') or (c > 'k121' and c < 'm122') or (c > 'o122') or (c < 'h112') or (c = 'c111')) group by a1,a2,b;select a1,a2,b,min(c) from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;## GROUP BY queries without MIN/MAX## plansexplain select a1,a2,b from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b;explain select a1,a2,b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;explain select a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b;explain select a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;--replace_column 9 #explain select a1,a2,b from t2 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b;--replace_column 9 #explain select a1,a2,b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;--replace_column 9 #explain select a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b;--replace_column 9 #explain select a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;# queriesselect a1,a2,b from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b;select a1,a2,b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;select a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b;select a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;select a1,a2,b from t2 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b;select a1,a2,b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;select a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b;select a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;## DISTINCT queries## plansexplain select distinct a1,a2,b from t1;explain select distinct a1,a2,b from t1 where (a2 >= 'b') and (b = 'a');explain select distinct a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121');explain select distinct a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c');explain select distinct b from t1 where (a2 >= 'b') and (b = 'a');--replace_column 9 #explain select distinct a1,a2,b from t2;--replace_column 9 #explain select distinct a1,a2,b from t2 where (a2 >= 'b') and (b = 'a');explain select distinct a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121');--replace_column 9 #explain select distinct a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c');explain select distinct b from t2 where (a2 >= 'b') and (b = 'a');# queriesselect distinct a1,a2,b from t1;select distinct a1,a2,b from t1 where (a2 >= 'b') and (b = 'a');select distinct a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121');select distinct a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c');select distinct b from t1 where (a2 >= 'b') and (b = 'a');select distinct a1,a2,b from t2;select distinct a1,a2,b from t2 where (a2 >= 'b') and (b = 'a');select distinct a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121');select distinct a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c');select distinct b from t2 where (a2 >= 'b') and (b = 'a');# BUG #6303select distinct t_00.a1from t1 t_00where exists ( select * from t2 where a1 = t_00.a1 );# BUG #8532 - SELECT DISTINCT a, a causes server to crashselect distinct a1,a1 from t1;select distinct a2,a1,a2,a1 from t1;select distinct t1.a1,t2.a1 from t1,t2;## DISTINCT queries with GROUP-BY## plansexplain select distinct a1,a2,b from t1;explain select distinct a1,a2,b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;explain select distinct a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b;explain select distinct a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;explain select distinct b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;--replace_column 9 #explain select distinct a1,a2,b from t2;--replace_column 9 #explain select distinct a1,a2,b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;--replace_column 9 #explain select distinct a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b;--replace_column 9 #explain select distinct a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;--replace_column 9 #explain select distinct b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;# queriesselect distinct a1,a2,b from t1;select distinct a1,a2,b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;select distinct a1,a2,b,c from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b;select distinct a1,a2,b from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;select distinct b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;select distinct a1,a2,b from t2;select distinct a1,a2,b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;select distinct a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121') group by a1,a2,b;select distinct a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b;select distinct b from t2 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;## COUNT (DISTINCT cols) queries#explain select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a');explain select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121');explain select count(distinct a1,a2,b) from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c');explain select count(distinct b) from t1 where (a2 >= 'b') and (b = 'a');explain select ord(a1) + count(distinct a1,a2,b) from t1 where (a1 > 'a') and (a2 > 'a');select count(distinct a1,a2,b) from t1 where (a2 >= 'b') and (b = 'a');select count(distinct a1,a2,b,c) from t1 where (a2 >= 'b') and (b = 'a') and (c = 'i121');select count(distinct a1,a2,b) from t1 where (a1 > 'a') and (a2 > 'a') and (b = 'c');select count(distinct b) from t1 where (a2 >= 'b') and (b = 'a');select ord(a1) + count(distinct a1,a2,b) from t1 where (a1 > 'a') and (a2 > 'a');## Queries with expressions in the select clause#explain select a1,a2,b, concat(min(c), max(c)) from t1 where a1 < 'd' group by a1,a2,b;explain select concat(a1,min(c)),b from t1 where a1 < 'd' group by a1,a2,b;explain select concat(a1,min(c)),b,max(c) from t1 where a1 < 'd' group by a1,a2,b;explain select concat(a1,a2),b,min(c),max(c) from t1 where a1 < 'd' group by a1,a2,b;explain select concat(ord(min(b)),ord(max(b))),min(b),max(b) from t1 group by a1,a2;select a1,a2,b, concat(min(c), max(c)) from t1 where a1 < 'd' group by a1,a2,b;select concat(a1,min(c)),b from t1 where a1 < 'd' group by a1,a2,b;select concat(a1,min(c)),b,max(c) from t1 where a1 < 'd' group by a1,a2,b;select concat(a1,a2),b,min(c),max(c) from t1 where a1 < 'd' group by a1,a2,b;select concat(ord(min(b)),ord(max(b))),min(b),max(b) from t1 group by a1,a2;## Negative examples: queries that should NOT be treated as optimizable by# QUICK_GROUP_MIN_MAX_SELECT## select a non-indexed attributeexplain select a1,a2,b,d,min(c),max(c) from t1 group by a1,a2,b;explain select a1,a2,b,d from t1 group by a1,a2,b;# predicate that references an attribute that is after the MIN/MAX argument# in the indexexplain select a1,a2,min(b),max(b) from t1where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2;# predicate that references a non-indexed attributeexplain select a1,a2,b,min(c),max(c) from t1where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (d > 'xy2') group by a1,a2,b;explain select a1,a2,b,c from t1where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (d > 'xy2') group by a1,a2,b,c;# non-equality predicate for a non-group select attributeexplain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') or (b < 'b') group by a1;explain select a1,a2,b from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2,b;# non-group field with an equality predicate that references a keypart after the# MIN/MAX argumentexplain select a1,a2,min(b),c from t2 where (a2 = 'a') and (c = 'a111') group by a1;select a1,a2,min(b),c from t2 where (a2 = 'a') and (c = 'a111') group by a1;# disjunction for a non-group select attributeexplain select a1,a2,b,max(c),min(c) from t2 where (a2 = 'a') and (b = 'b') or (b = 'a') group by a1;# non-range predicate for the MIN/MAX attributeexplain select a1,a2,b,min(c),max(c) from t2where (c > 'a000') and (c <= 'd999') and (c like '_8__') group by a1,a2,b;# not all attributes are indexed by one indexexplain select a1, a2, b, c, min(d), max(d) from t1 group by a1,a2,b,c;# other aggregate functions than MIN/MAXexplain select a1,a2,count(a2) from t1 group by a1,a2,b;explain select a1,a2,count(a2) from t1 where (a1 > 'a') group by a1,a2,b;explain select sum(ord(a1)) from t1 where (a1 > 'a') group by a1,a2,b;## Bug #16710: select distinct doesn't return all it should#explain select distinct(a1) from t1 where ord(a2) = 98;select distinct(a1) from t1 where ord(a2) = 98;## BUG#11044: DISTINCT or GROUP BY queries with equality predicates instead of MIN/MAX.#explain select a1 from t1 where a2 = 'b' group by a1;select a1 from t1 where a2 = 'b' group by a1;explain select distinct a1 from t1 where a2 = 'b';select distinct a1 from t1 where a2 = 'b';drop table t1,t2,t3;## Bug #14920 Ordering aggregated result sets with composite primary keys# corrupts resultset#create table t1 (c1 int not null,c2 int not null, primary key(c1,c2));insert into t1 (c1,c2) values(10,1),(10,2),(10,3),(20,4),(20,5),(20,6),(30,7),(30,8),(30,9);select distinct c1, c2 from t1 order by c2;select c1,min(c2) as c2 from t1 group by c1 order by c2;select c1,c2 from t1 group by c1,c2 order by c2;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?