1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
################################################################################
# inc/vcol_select.inc #
# #
# Purpose: #
# Testing different SELECTs. #
# #
# #
#------------------------------------------------------------------------------#
# Original Author: Andrey Zhakov #
# Original Date: 2008-09-18 #
# Change Author: Oleksandr Byelkin (Monty program Ab)
# Date: 2009-03-24
# Change: Syntax changed
################################################################################
# Table t1 is used below to test:
# - Join type of ALL (sequential scan of the entire table)
# - Join type of Index
# - Join type of Range
# - Join type of Ref_or_null
create table t1 (a int,
b int as (-a),
c int as (-a) persistent,
index (c));
insert into t1 (a) values (2), (1), (1), (3), (NULL);
# Table t2 is used below to test:
# - Join type of system and const
create table t2 like t1;
insert into t2 (a) values (1);
# Table t3 is used below to test
# - Join type of Eq_ref with a unique virtual column
# - Join type of Const
create table t3 (a int primary key,
b int as (-a),
c int as (-a) persistent unique);
insert into t3 (a) values (2),(1),(3),(5),(4),(7);
--echo # select_type=SIMPLE, type=system
let $s = select * from t2;
eval $s;
eval explain $s;
let $s = select * from t2 where c=-1;
eval $s;
eval explain $s;
--echo # select_type=SIMPLE, type=ALL
let $s = select * from t1 where b=-1;
eval $s;
eval explain $s;
--echo # select_type=SIMPLE, type=const
let $s = select * from t3 where a=1;
eval $s;
eval explain $s;
--echo # select_type=SIMPLE, type=range
let $s = select * from t3 where c>=-1;
eval $s;
eval explain $s;
--echo # select_type=SIMPLE, type=ref
let $s = select * from t1,t3 where t1.c=t3.c and t3.c=-1;
eval $s;
eval explain $s;
--echo # select_type=PRIMARY, type=index,ALL
let $s = select * from t1 where b in (select c from t3);
eval $s;
eval explain $s;
--echo # select_type=PRIMARY, type=range,ref
let $s = select * from t1 where c in (select c from t3 where c between -2 and -1);
eval $s;
eval explain $s;
--echo # select_type=UNION, type=system
--echo # select_type=UNION RESULT, type=<union1,2>
let $s = select * from t1 union select * from t2;
eval $s;
eval explain $s;
--echo # select_type=DERIVED, type=system
set @tmp_optimizer_switch=@@optimizer_switch;
set optimizer_switch='derived_merge=off,derived_with_keys=off';
let $s = select * from (select a,b,c from t1) as t11;
eval $s;
eval explain $s;
set optimizer_switch=@tmp_optimizer_switch;
--echo ###
--echo ### Using aggregate functions with/without DISTINCT
--echo ###
--echo # SELECT COUNT(*) FROM tbl_name
let $s = select count(*) from t1;
eval $s;
eval explain $s;
--echo # SELECT COUNT(DISTINCT <non-vcol>) FROM tbl_name
let $s = select count(distinct a) from t1;
eval $s;
eval explain $s;
--echo # SELECT COUNT(DISTINCT <non-stored vcol>) FROM tbl_name
let $s = select count(distinct b) from t1;
eval $s;
eval explain $s;
--echo # SELECT COUNT(DISTINCT <stored vcol>) FROM tbl_name
let $s = select count(distinct c) from t1;
eval $s;
eval explain $s;
--echo ###
--echo ### filesort & range-based utils
--echo ###
--echo # SELECT * FROM tbl_name WHERE <vcol expr>
let $s = select * from t3 where c >= -2;
eval $s;
eval explain $s;
--echo # SELECT * FROM tbl_name WHERE <non-vcol expr>
let $s = select * from t3 where a between 1 and 2;
eval $s;
eval explain $s;
--echo # SELECT * FROM tbl_name WHERE <non-indexed vcol expr>
let $s = select * from t3 where b between -2 and -1;
eval $s;
eval explain $s;
--echo # SELECT * FROM tbl_name WHERE <indexed vcol expr>
let $s = select * from t3 where c between -2 and -1;
eval $s;
eval explain $s;
#### Remove for MyISAM due to a bug
#### when all the three records are returned (a=1,2,3)
#### instead of just two (a=1,2).
#### This bug is presumably in base SQL routines as the same happens
#### with this table:
#### create table t4 (a int primary key, b int, c int unique);
let $myisam_engine = `SELECT @@session.default_storage_engine='myisam'`;
if (!$myisam_engine)
{
--echo # SELECT * FROM tbl_name WHERE <non-vcol expr> ORDER BY <non-indexed vcol>
let $s = select * from t3 where a between 1 and 2 order by b;
eval $s;
eval explain $s;
}
--echo # SELECT * FROM tbl_name WHERE <non-vcol expr> ORDER BY <indexed vcol>
let $s = select * from t3 where a between 1 and 2 order by c;
eval $s;
eval explain $s;
--echo # SELECT * FROM tbl_name WHERE <non-indexed vcol expr> ORDER BY <non-vcol>
let $s = select * from t3 where b between -2 and -1 order by a;
eval $s;
eval explain $s;
#### Remove for MyISAM due to a bug
#### when all the three records are returned (a=1,2,3)
#### instead of just two (a=1,2).
#### This bug is presumably in base SQL routines as the same happens
#### with this table:
#### create table t4 (a int primary key, b int, c int unique);
let $innodb_engine = `SELECT @@session.default_storage_engine='innodb'`;
if (!$innodb_engine)
{
--echo # SELECT * FROM tbl_name WHERE <indexed vcol expr> ORDER BY <non-vcol>
let $s = select * from t3 where c between -2 and -1 order by a;
eval $s;
eval explain $s;
}
--echo # SELECT * FROM tbl_name WHERE <non-indexed vcol expr> ORDER BY <non-indexed vcol>
let $s = select * from t3 where b between -2 and -1 order by b;
eval $s;
eval explain $s;
--echo # SELECT * FROM tbl_name WHERE <indexed vcol expr> ORDER BY <non-indexed vcol>
let $s = select * from t3 where c between -2 and -1 order by b;
eval $s;
eval explain $s;
--echo # SELECT * FROM tbl_name WHERE <non-indexed vcol expr> ORDER BY <indexed vcol>
let $s = select * from t3 where b between -2 and -1 order by c;
eval $s;
eval explain $s;
--echo # SELECT * FROM tbl_name WHERE <indexed vcol expr> ORDER BY <indexed vcol>
let $s = select * from t3 where c between -2 and -1 order by c;
eval $s;
eval explain $s;
--echo # SELECT sum(<non-indexed vcol>) FROM tbl_name GROUP BY <non-indexed vcol>
let $s = select sum(b) from t1 group by b;
eval $s;
eval explain $s;
--echo # SELECT sum(<indexed vcol>) FROM tbl_name GROUP BY <indexed vcol>
let $s = select sum(c) from t1 group by c;
eval $s;
eval explain $s;
--echo # SELECT sum(<non-indexed vcol>) FROM tbl_name GROUP BY <indexed vcol>
let $s = select sum(b) from t1 group by c;
eval $s;
eval explain $s;
--echo # SELECT sum(<indexed vcol>) FROM tbl_name GROUP BY <non-indexed vcol>
let $s = select sum(c) from t1 group by b;
eval $s;
eval explain $s;
|