1
by brian
clean slate |
1 |
#
|
2 |
# Testing of found_rows() |
|
3 |
#
|
|
4 |
--disable_warnings
|
|
5 |
drop table if exists t1,t2; |
|
6 |
--enable_warnings
|
|
7 |
||
8 |
create table t1 (a int not null auto_increment, b int not null, primary key(a)); |
|
9 |
insert into t1 (b) values (2),(3),(5),(5),(5),(6),(7),(9); |
|
10 |
select SQL_CALC_FOUND_ROWS * from t1; |
|
11 |
select found_rows(); |
|
12 |
select SQL_CALC_FOUND_ROWS * from t1 limit 1; |
|
13 |
select found_rows(); |
|
14 |
select SQL_BUFFER_RESULT SQL_CALC_FOUND_ROWS * from t1 limit 1; |
|
15 |
select found_rows(); |
|
16 |
select SQL_CALC_FOUND_ROWS * from t1 order by b desc limit 1; |
|
17 |
select found_rows(); |
|
18 |
select SQL_CALC_FOUND_ROWS distinct b from t1 limit 1; |
|
19 |
select found_rows(); |
|
20 |
select SQL_CALC_FOUND_ROWS b,count(*) as c from t1 group by b order by c desc limit 1; |
|
21 |
select found_rows(); |
|
22 |
select SQL_CALC_FOUND_ROWS * from t1 left join t1 as t2 on (t1.b=t2.a) limit 2,1; |
|
23 |
select found_rows(); |
|
24 |
drop table t1; |
|
25 |
||
26 |
#
|
|
27 |
# Test SQL_CALC_FOUND_ROWS optimization when used with one table and filesort |
|
28 |
#
|
|
29 |
||
30 |
create table t1 (a int not null primary key); |
|
31 |
insert into t1 values (1),(2),(3),(4),(5); |
|
32 |
select sql_calc_found_rows a from t1 where a in (1,2,3) order by a desc limit 0,2; |
|
33 |
select FOUND_ROWS(); |
|
34 |
select sql_calc_found_rows a from t1 where a in (1,2,3) order by a+2 desc limit 0,2; |
|
35 |
select FOUND_ROWS(); |
|
36 |
drop table t1; |
|
37 |
||
38 |
#
|
|
39 |
# Test of SQL_CALC_FOUND_ROWS with DISTINCT |
|
40 |
#
|
|
41 |
||
42 |
CREATE TABLE t1 ( |
|
43 |
`id` smallint(5) unsigned NOT NULL auto_increment, |
|
44 |
`kid` smallint(5) unsigned NOT NULL default '0', |
|
45 |
PRIMARY KEY (`id`), |
|
46 |
KEY `kid` (`kid`) |
|
47 |
);
|
|
48 |
||
49 |
CREATE TABLE t2 ( |
|
50 |
id smallint(5) unsigned NOT NULL auto_increment, |
|
51 |
name varchar(50) NOT NULL default '', |
|
52 |
email varchar(50) NOT NULL default '', |
|
53 |
PRIMARY KEY (id), |
|
54 |
UNIQUE KEY e_n (email,name) |
|
55 |
);
|
|
56 |
||
57 |
disable_query_log; |
|
58 |
let $1=200; |
|
59 |
let $2=0; |
|
60 |
while ($1) |
|
61 |
{
|
|
62 |
inc $2; |
|
63 |
eval INSERT INTO t2 VALUES ($2,'name$2','email$2'); |
|
64 |
dec $1; |
|
65 |
}
|
|
66 |
enable_query_log; |
|
67 |
||
68 |
EXPLAIN SELECT SQL_CALC_FOUND_ROWS DISTINCT email FROM t2 LEFT JOIN t1 ON kid = t2.id WHERE t1.id IS NULL LIMIT 10; |
|
69 |
SELECT SQL_CALC_FOUND_ROWS DISTINCT email FROM t2 LEFT JOIN t1 ON kid = t2.id WHERE t1.id IS NULL LIMIT 10; |
|
70 |
SELECT FOUND_ROWS(); |
|
71 |
||
72 |
SELECT SQL_CALC_FOUND_ROWS DISTINCT email FROM t2 LEFT JOIN t1 ON kid = t2.id WHERE t1.id IS NULL order by email LIMIT 10; |
|
73 |
SELECT FOUND_ROWS(); |
|
74 |
||
75 |
SELECT DISTINCT email FROM t2 LEFT JOIN t1 ON kid = t2.id WHERE t1.id IS NULL LIMIT 10; |
|
76 |
SELECT DISTINCT email FROM t2 LEFT JOIN t1 ON kid = t2.id WHERE t1.id IS NULL ORDER BY email LIMIT 10; |
|
77 |
INSERT INTO `t1` (`id`, `kid`) VALUES ('0', '150'); |
|
78 |
||
79 |
SELECT SQL_CALC_FOUND_ROWS DISTINCT email FROM t2 LEFT JOIN t1 ON kid = t2.id WHERE t1.id IS NULL LIMIT 10; |
|
80 |
SELECT FOUND_ROWS(); |
|
81 |
||
82 |
drop table t1,t2; |
|
83 |
||
84 |
#
|
|
85 |
# Test bug when using range optimization |
|
86 |
#
|
|
87 |
||
88 |
CREATE TABLE `t1` ( |
|
89 |
`titre` char(80) NOT NULL default '', |
|
90 |
`numeropost` mediumint(8) unsigned NOT NULL auto_increment, |
|
91 |
`maxnumrep` int(10) unsigned NOT NULL default '0', |
|
92 |
PRIMARY KEY (`numeropost`), |
|
93 |
KEY `maxnumrep` (`maxnumrep`) |
|
94 |
) ENGINE=MyISAM ROW_FORMAT=FIXED; |
|
95 |
INSERT INTO t1 (titre,maxnumrep) VALUES |
|
96 |
('test1','1'),('test2','2'),('test3','3'); |
|
97 |
SELECT SQL_CALC_FOUND_ROWS titre,numeropost,maxnumrep FROM t1 WHERE numeropost IN (1,2) ORDER BY maxnumrep DESC LIMIT 0, 1; |
|
98 |
SELECT FOUND_ROWS(); |
|
99 |
SELECT SQL_CALC_FOUND_ROWS 1 FROM (SELECT 1) as a LIMIT 0; |
|
100 |
SELECT FOUND_ROWS(); |
|
101 |
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE numeropost > 1 LIMIT 0; |
|
102 |
SELECT FOUND_ROWS(); |
|
103 |
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 0; |
|
104 |
SELECT FOUND_ROWS(); |
|
105 |
SELECT SQL_CALC_FOUND_ROWS * FROM t1 ORDER BY numeropost LIMIT 0; |
|
106 |
SELECT FOUND_ROWS(); |
|
107 |
drop table t1; |
|
108 |
||
109 |
#
|
|
110 |
# Test problem with impossible WHERE (Bug #1468) |
|
111 |
#
|
|
112 |
||
113 |
create table t1 (id int, primary key (id)); |
|
114 |
insert into t1 values (1), (2), (3), (4), (5); |
|
115 |
select SQL_CALC_FOUND_ROWS * from t1 where id > 3 limit 0, 1; |
|
116 |
select FOUND_ROWS(); |
|
117 |
select SQL_CALC_FOUND_ROWS * from t1 where id > 3 AND 1=2 limit 0, 1; |
|
118 |
select FOUND_ROWS(); |
|
119 |
select SQL_CALC_FOUND_ROWS * from t1 where id > 6 limit 0, 1; |
|
120 |
select FOUND_ROWS(); |
|
121 |
drop table t1; |
|
122 |
||
123 |
#
|
|
124 |
# Other bugs with range optimization |
|
125 |
#
|
|
126 |
||
127 |
# bug #2448 |
|
128 |
||
129 |
CREATE TABLE t1 ( a int not null, b int not null, KEY ab(a,b) ); |
|
130 |
INSERT INTO t1 VALUES ( 47, 1 ); |
|
131 |
INSERT INTO t1 VALUES ( 70, 1 ); |
|
132 |
SELECT * FROM t1 |
|
133 |
WHERE
|
|
134 |
(
|
|
135 |
( b =1 AND a BETWEEN 14 AND 21 ) OR |
|
136 |
( b =2 AND a BETWEEN 16 AND 18 ) OR |
|
137 |
( b =3 AND a BETWEEN 15 AND 19 ) |
|
138 |
);
|
|
139 |
DROP TABLE t1; |
|
140 |
||
141 |
# bug #2698 |
|
142 |
||
143 |
CREATE TABLE t1 ( a integer, u varchar(15), r integer, key uao_idx( r, a, u)); |
|
144 |
DELETE FROM t1 |
|
145 |
WHERE ( r = 1 AND a IN ( 1, 2 ) AND ( u = 'w' OR u LIKE 'w/%' ) ) |
|
146 |
OR ( r = 1 AND a IN ( 3 ) AND ( u = 'w/U' OR u LIKE 'w/U/%' ) ) |
|
147 |
OR ( r = 1 AND a IN ( 1, 2, 3 ) AND ( u = 'w' ) ); |
|
148 |
drop table t1; |
|
149 |
||
150 |
#
|
|
151 |
# Bug #3738: we have a ref key |
|
152 |
#
|
|
153 |
||
154 |
CREATE TABLE t1 (a VARCHAR(16), UNIQUE(a)); |
|
155 |
INSERT INTO t1 VALUES ('1'), ('2'), ('3'); |
|
156 |
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a = '2' LIMIT 0, 1; |
|
157 |
SELECT FOUND_ROWS(); |
|
158 |
DROP TABLE t1; |
|
159 |
||
160 |
#
|
|
161 |
# Bug #3845: group by, having and empty result |
|
162 |
#
|
|
163 |
||
164 |
CREATE TABLE t1 (a INT); |
|
165 |
INSERT INTO t1 VALUES (0), (0), (1), (2); |
|
166 |
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a = 0 GROUP BY a HAVING a > 10; |
|
167 |
SELECT FOUND_ROWS(); |
|
168 |
DROP TABLE t1; |
|
169 |
||
170 |
#
|
|
171 |
# Bug #6089: queries which don't use any tables |
|
172 |
#
|
|
173 |
||
174 |
SELECT 'foo'; |
|
175 |
SELECT FOUND_ROWS();
|
|
176 |
SELECT SQL_CALC_FOUND_ROWS 'foo'; |
|
177 |
SELECT FOUND_ROWS();
|
|
178 |
SELECT SQL_CALC_FOUND_ROWS 'foo' limit 0; |
|
179 |
SELECT FOUND_ROWS();
|
|
180 |
SELECT FOUND_ROWS();
|
|
181 |
||
182 |
SELECT SQL_CALC_FOUND_ROWS 'foo' UNION SELECT 'bar' LIMIT 0; |
|
183 |
SELECT FOUND_ROWS();
|
|
184 |
||
185 |
#
|
|
186 |
# Bug #7945: group by + distinct with constant expression + limit
|
|
187 |
#
|
|
188 |
||
189 |
CREATE TABLE t1 (a int, b int);
|
|
190 |
INSERT INTO t1 VALUES (1,2), (1,3), (1,4), (1,5);
|
|
191 |
SELECT SQL_CALC_FOUND_ROWS DISTINCT 'a' FROM t1 GROUP BY b LIMIT 2; |
|
192 |
SELECT FOUND_ROWS(); |
|
193 |
DROP TABLE t1; |
|
194 |
||
195 |
# End of 4.1 tests |