Commit 892495ac authored by gkodinov@dl145s.mysql.com's avatar gkodinov@dl145s.mysql.com

Merge dl145s.mysql.com:/data/bk/team_tree_merge/mysql-5.0

into  dl145s.mysql.com:/data/bk/team_tree_merge/MERGE/mysql-5.0-opt
parents 9c0b8726 3a4a9521
...@@ -224,12 +224,17 @@ enum ha_base_keytype { ...@@ -224,12 +224,17 @@ enum ha_base_keytype {
/* poor old NISAM has 8-bit flags :-( */ /* poor old NISAM has 8-bit flags :-( */
#define HA_SORT_ALLOWS_SAME 128 /* Intern bit when sorting records */ #define HA_SORT_ALLOWS_SAME 128 /* Intern bit when sorting records */
#endif #endif
#if MYSQL_VERSION_ID < 0x50200
/* /*
Key has a part that can have end space. If this is an unique key Key has a part that can have end space. If this is an unique key
we have to handle it differently from other unique keys as we can find we have to handle it differently from other unique keys as we can find
many matching rows for one key (because end space are not compared) many matching rows for one key (because end space are not compared)
*/ */
#define HA_END_SPACE_KEY 4096 #define HA_END_SPACE_KEY 0 /* was: 4096 */
#else
#error HA_END_SPACE_KEY is obsolete, please remove it
#endif
/* These flags can be added to key-seg-flag */ /* These flags can be added to key-seg-flag */
......
...@@ -71,6 +71,21 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx, key_range *min_key, ...@@ -71,6 +71,21 @@ ha_rows mi_records_in_range(MI_INFO *info, int inx, key_range *min_key,
uchar * key_buff; uchar * key_buff;
uint start_key_len; uint start_key_len;
/*
The problem is that the optimizer doesn't support
RTree keys properly at the moment.
Hope this will be fixed some day.
But now NULL in the min_key means that we
didn't make the task for the RTree key
and expect BTree functionality from it.
As it's not able to handle such request
we return the error.
*/
if (!min_key)
{
res= HA_POS_ERROR;
break;
}
key_buff= info->lastkey+info->s->base.max_key_length; key_buff= info->lastkey+info->s->base.max_key_length;
start_key_len= _mi_pack_key(info,inx, key_buff, start_key_len= _mi_pack_key(info,inx, key_buff,
(uchar*) min_key->key, min_key->length, (uchar*) min_key->key, min_key->length,
......
...@@ -1509,27 +1509,27 @@ i 10 ...@@ -1509,27 +1509,27 @@ i 10
select sql_big_result v,count(t) from t1 group by v limit 10; select sql_big_result v,count(t) from t1 group by v limit 10;
v count(t) v count(t)
a 1 a 1
a 10 a 10
b 10 b 10
c 10 c 10
d 10 d 10
e 10 e 10
f 10 f 10
g 10 g 10
h 10 h 10
i 10 i 10
select sql_big_result v,count(c) from t1 group by v limit 10; select sql_big_result v,count(c) from t1 group by v limit 10;
v count(c) v count(c)
a 1 a 1
a 10 a 10
b 10 b 10
c 10 c 10
d 10 d 10
e 10 e 10
f 10 f 10
g 10 g 10
h 10 h 10
i 10 i 10
select c,count(*) from t1 group by c limit 10; select c,count(*) from t1 group by c limit 10;
c count(*) c count(*)
a 1 a 1
...@@ -1673,15 +1673,15 @@ i 10 ...@@ -1673,15 +1673,15 @@ i 10
select sql_big_result v,count(t) from t1 group by v limit 10; select sql_big_result v,count(t) from t1 group by v limit 10;
v count(t) v count(t)
a 1 a 1
a 10 a 10
b 10 b 10
c 10 c 10
d 10 d 10
e 10 e 10
f 10 f 10
g 10 g 10
h 10 h 10
i 10 i 10
alter table t1 drop key v, add key v (v(30)); alter table t1 drop key v, add key v (v(30));
show create table t1; show create table t1;
Table Create Table Table Create Table
...@@ -1800,15 +1800,15 @@ i 10 ...@@ -1800,15 +1800,15 @@ i 10
select sql_big_result v,count(t) from t1 group by v limit 10; select sql_big_result v,count(t) from t1 group by v limit 10;
v count(t) v count(t)
a 1 a 1
a 10 a 10
b 10 b 10
c 10 c 10
d 10 d 10
e 10 e 10
f 10 f 10
g 10 g 10
h 10 h 10
i 10 i 10
drop table t1; drop table t1;
create table t1 (a char(10), unique (a)); create table t1 (a char(10), unique (a));
insert into t1 values ('a '); insert into t1 values ('a ');
......
...@@ -74,11 +74,6 @@ grp group_concat(c order by 1) ...@@ -74,11 +74,6 @@ grp group_concat(c order by 1)
1 a 1 a
2 b,c 2 b,c
3 C,D,d,d,D,E 3 C,D,d,d,D,E
select grp,group_concat(c order by "c") from t1 group by grp;
grp group_concat(c order by "c")
1 a
2 b,c
3 C,D,d,d,D,E
select grp,group_concat(distinct c order by c) from t1 group by grp; select grp,group_concat(distinct c order by c) from t1 group by grp;
grp group_concat(distinct c order by c) grp group_concat(distinct c order by c)
1 a 1 a
......
...@@ -1143,9 +1143,9 @@ EXPLAIN EXTENDED ...@@ -1143,9 +1143,9 @@ EXPLAIN EXTENDED
SELECT * FROM t1 INNER JOIN t2 ON code=id SELECT * FROM t1 INNER JOIN t2 ON code=id
WHERE id='a12' AND (LENGTH(code)=5 OR code < 'a00'); WHERE id='a12' AND (LENGTH(code)=5 OR code < 'a00');
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 const PRIMARY PRIMARY 12 const 1 Using index
1 SIMPLE t1 ref code code 13 const 3 Using where; Using index 1 SIMPLE t1 ref code code 13 const 3 Using where; Using index
1 SIMPLE t2 ref PRIMARY PRIMARY 12 const 1 Using where; Using index
Warnings: Warnings:
Note 1003 select `test`.`t1`.`code` AS `code`,`test`.`t2`.`id` AS `id` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`code` = _latin1'a12') and (`test`.`t2`.`id` = _latin1'a12') and (length(`test`.`t1`.`code`) = 5)) Note 1003 select `test`.`t1`.`code` AS `code`,`test`.`t2`.`id` AS `id` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`code` = _latin1'a12') and (length(`test`.`t1`.`code`) = 5))
DROP TABLE t1,t2; DROP TABLE t1,t2;
End of 5.0 tests End of 5.0 tests
...@@ -862,3 +862,14 @@ CHECK TABLE t1 EXTENDED; ...@@ -862,3 +862,14 @@ CHECK TABLE t1 EXTENDED;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 check status OK test.t1 check status OK
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (foo GEOMETRY NOT NULL, SPATIAL INDEX(foo) );
INSERT INTO t1 (foo) VALUES (PointFromWKB(POINT(1,1)));
INSERT INTO t1 (foo) VALUES (PointFromWKB(POINT(1,0)));
INSERT INTO t1 (foo) VALUES (PointFromWKB(POINT(0,1)));
INSERT INTO t1 (foo) VALUES (PointFromWKB(POINT(0,0)));
SELECT 1 FROM t1 WHERE foo != PointFromWKB(POINT(0,0));
1
1
1
1
DROP TABLE t1;
...@@ -303,10 +303,10 @@ spid sum(userid) ...@@ -303,10 +303,10 @@ spid sum(userid)
1 1 1 1
explain select sql_big_result score,count(*) from t1 group by score desc; explain select sql_big_result score,count(*) from t1 group by score desc;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL score 3 NULL 8 Using index 1 SIMPLE t1 index NULL score 3 NULL 8 Using index; Using filesort
explain select sql_big_result score,count(*) from t1 group by score desc order by null; explain select sql_big_result score,count(*) from t1 group by score desc order by null;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL score 3 NULL 8 Using index 1 SIMPLE t1 index NULL score 3 NULL 8 Using index; Using filesort
select sql_big_result score,count(*) from t1 group by score desc; select sql_big_result score,count(*) from t1 group by score desc;
score count(*) score count(*)
3 5 3 5
...@@ -775,6 +775,55 @@ select sql_buffer_result max(f1)+1 from t1; ...@@ -775,6 +775,55 @@ select sql_buffer_result max(f1)+1 from t1;
max(f1)+1 max(f1)+1
3 3
drop table t1; drop table t1;
CREATE TABLE t1(a INT);
INSERT INTO t1 VALUES (1),(2);
SELECT a FROM t1 GROUP BY 'a';
a
1
SELECT a FROM t1 GROUP BY "a";
a
1
SELECT a FROM t1 GROUP BY `a`;
a
1
2
set sql_mode=ANSI_QUOTES;
SELECT a FROM t1 GROUP BY "a";
a
1
2
SELECT a FROM t1 GROUP BY 'a';
a
1
SELECT a FROM t1 GROUP BY `a`;
a
1
2
set sql_mode='';
SELECT a FROM t1 HAVING 'a' > 1;
a
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'a'
SELECT a FROM t1 HAVING "a" > 1;
a
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'a'
SELECT a FROM t1 HAVING `a` > 1;
a
2
SELECT a FROM t1 ORDER BY 'a' DESC;
a
1
2
SELECT a FROM t1 ORDER BY "a" DESC;
a
1
2
SELECT a FROM t1 ORDER BY `a` DESC;
a
2
1
DROP TABLE t1;
create table t1 (c1 char(3), c2 char(3)); create table t1 (c1 char(3), c2 char(3));
create table t2 (c3 char(3), c4 char(3)); create table t2 (c3 char(3), c4 char(3));
insert into t1 values ('aaa', 'bb1'), ('aaa', 'bb2'); insert into t1 values ('aaa', 'bb1'), ('aaa', 'bb2');
...@@ -821,3 +870,66 @@ a b real_b ...@@ -821,3 +870,66 @@ a b real_b
68 France France 68 France France
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1,t2; DROP TABLE t1,t2;
CREATE TABLE t1 (a INT PRIMARY KEY, b INT, key (b));
INSERT INTO t1 VALUES (1, 1);
INSERT INTO t1 SELECT a + 1 , MOD(a + 1 , 20) FROM t1;
INSERT INTO t1 SELECT a + 2 , MOD(a + 2 , 20) FROM t1;
INSERT INTO t1 SELECT a + 4 , MOD(a + 4 , 20) FROM t1;
INSERT INTO t1 SELECT a + 8 , MOD(a + 8 , 20) FROM t1;
INSERT INTO t1 SELECT a + 16, MOD(a + 16, 20) FROM t1;
INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20) FROM t1;
INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20) FROM t1;
SELECT MIN(b), MAX(b) from t1;
MIN(b) MAX(b)
0 19
EXPLAIN SELECT b, sum(1) FROM t1 GROUP BY b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL b 5 NULL 128 Using index
EXPLAIN SELECT SQL_BIG_RESULT b, sum(1) FROM t1 GROUP BY b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL b 5 NULL 128 Using index; Using filesort
SELECT b, sum(1) FROM t1 GROUP BY b;
b sum(1)
0 6
1 7
2 7
3 7
4 7
5 7
6 7
7 7
8 7
9 6
10 6
11 6
12 6
13 6
14 6
15 6
16 6
17 6
18 6
19 6
SELECT SQL_BIG_RESULT b, sum(1) FROM t1 GROUP BY b;
b sum(1)
0 6
1 7
2 7
3 7
4 7
5 7
6 7
7 7
8 7
9 6
10 6
11 6
12 6
13 6
14 6
15 6
16 6
17 6
18 6
19 6
DROP TABLE t1;
...@@ -2142,3 +2142,23 @@ t1; ...@@ -2142,3 +2142,23 @@ t1;
id2 id3 id5 id4 id3 id6 id5 id1 id2 id3 id5 id4 id3 id6 id5 id1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
DROP TABLE t1,t2,t3,t4,t5,t6; DROP TABLE t1,t2,t3,t4,t5,t6;
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a,b), KEY b (b));
INSERT INTO t1 VALUES (1,1),(1,2),(1,0),(1,3);
explain SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY,b PRIMARY 8 NULL 1 Using where; Using index for group-by
SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a;
MAX(b) a
1 1
SELECT MIN(b), a FROM t1 WHERE b > 1 AND a = 1 GROUP BY a;
MIN(b) a
2 1
CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a,b,c));
INSERT INTO t2 SELECT a,b,b FROM t1;
explain SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range PRIMARY PRIMARY 12 NULL 1 Using where; Using index for group-by
SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a;
MIN(c)
2
DROP TABLE t1,t2;
...@@ -2070,15 +2070,15 @@ i 10 ...@@ -2070,15 +2070,15 @@ i 10
select sql_big_result v,count(c) from t1 group by v limit 10; select sql_big_result v,count(c) from t1 group by v limit 10;
v count(c) v count(c)
a 1 a 1
a 10 a 10
b 10 b 10
c 10 c 10
d 10 d 10
e 10 e 10
f 10 f 10
g 10 g 10
h 10 h 10
i 10 i 10
select c,count(*) from t1 group by c limit 10; select c,count(*) from t1 group by c limit 10;
c count(*) c count(*)
a 1 a 1
......
...@@ -337,3 +337,19 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -337,3 +337,19 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 index NULL fkey 5 NULL 5 Using index 1 SIMPLE t2 index NULL fkey 5 NULL 5 Using index
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.fkey 1 Using where 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.fkey 1 Using where
DROP TABLE t1,t2; DROP TABLE t1,t2;
CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB;
INSERT INTO t1 VALUES ( 1 , 1 , 1);
INSERT INTO t1 SELECT a + 1 , MOD(a + 1 , 20), 1 FROM t1;
INSERT INTO t1 SELECT a + 2 , MOD(a + 2 , 20), 1 FROM t1;
INSERT INTO t1 SELECT a + 4 , MOD(a + 4 , 20), 1 FROM t1;
INSERT INTO t1 SELECT a + 8 , MOD(a + 8 , 20), 1 FROM t1;
INSERT INTO t1 SELECT a + 16, MOD(a + 16, 20), 1 FROM t1;
INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20), 1 FROM t1;
INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20), 1 FROM t1;
EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL b 5 NULL 128
EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 128 Using filesort
DROP TABLE t1;
...@@ -626,7 +626,7 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -626,7 +626,7 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT * FROM t2 WHERE fileset_id = 2 EXPLAIN SELECT * FROM t2 WHERE fileset_id = 2
AND file_code = '0000000115' LIMIT 1; AND file_code = '0000000115' LIMIT 1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ref PRIMARY,files PRIMARY 35 const,const 1 Using where 1 SIMPLE t2 const PRIMARY,files PRIMARY 35 const,const 1
DROP TABLE t2, t1; DROP TABLE t2, t1;
create table t1 (x int, y int, index xy(x, y)); create table t1 (x int, y int, index xy(x, y));
create table t2 (x int, y int, index xy(x, y)); create table t2 (x int, y int, index xy(x, y));
......
...@@ -1002,15 +1002,15 @@ i 10 ...@@ -1002,15 +1002,15 @@ i 10
select sql_big_result v,count(c) from t1 group by v limit 10; select sql_big_result v,count(c) from t1 group by v limit 10;
v count(c) v count(c)
a 1 a 1
a 10 a 10
b 10 b 10
c 10 c 10
d 10 d 10
e 10 e 10
f 10 f 10
g 10 g 10
h 10 h 10
i 10 i 10
select c,count(*) from t1 group by c limit 10; select c,count(*) from t1 group by c limit 10;
c count(*) c count(*)
a 1 a 1
......
...@@ -54,3 +54,13 @@ Tables_in_test ...@@ -54,3 +54,13 @@ Tables_in_test
t2 t2
t4 t4
drop table t2, t4; drop table t2, t4;
create table t1(f1 int);
create view v1 as select * from t1;
alter table v1 rename to v2;
alter table v1 rename to v2;
ERROR 42S02: Table 'test.v1' doesn't exist
rename table v2 to v1;
rename table v2 to v1;
ERROR 42S01: Table 'v1' already exists
drop view v1;
drop table t1;
...@@ -3517,3 +3517,97 @@ id a b c d e ...@@ -3517,3 +3517,97 @@ id a b c d e
2 NULL NULL NULL 2 40 2 NULL NULL NULL 2 40
2 NULL NULL NULL 2 50 2 NULL NULL NULL 2 50
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
create table t1 (c1 varchar(1), c2 int, c3 int, c4 int, c5 int, c6 int,
c7 int, c8 int, c9 int, fulltext key (`c1`));
select distinct match (`c1`) against ('z') , c2, c3, c4,c5, c6,c7, c8
from t1 where c9=1 order by c2, c2;
match (`c1`) against ('z') c2 c3 c4 c5 c6 c7 c8
drop table t1;
CREATE TABLE t1 (pk varchar(10) PRIMARY KEY, fk varchar(16));
CREATE TABLE t2 (pk varchar(16) PRIMARY KEY, fk varchar(10));
INSERT INTO t1 VALUES
('d','dddd'), ('i','iii'), ('a','aa'), ('b','bb'), ('g','gg'),
('e','eee'), ('c','cccc'), ('h','hhh'), ('j','jjj'), ('f','fff');
INSERT INTO t2 VALUES
('jjj', 'j'), ('cc','c'), ('ccc','c'), ('aaa', 'a'), ('jjjj','j'),
('hhh','h'), ('gg','g'), ('fff','f'), ('ee','e'), ('ffff','f'),
('bbb','b'), ('ff','f'), ('cccc','c'), ('dddd','d'), ('jj','j'),
('aaaa','a'), ('bb','b'), ('eeee','e'), ('aa','a'), ('hh','h');
EXPLAIN SELECT t2.*
FROM t1 JOIN t2 ON t2.fk=t1.pk
WHERE t2.fk < 'c' AND t2.pk=t1.fk;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 12 NULL 3 Using where
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 18 test.t1.fk 1 Using where
EXPLAIN SELECT t2.*
FROM t1 JOIN t2 ON t2.fk=t1.pk
WHERE t2.fk BETWEEN 'a' AND 'b' AND t2.pk=t1.fk;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 12 NULL 2 Using where
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 18 test.t1.fk 1 Using where
EXPLAIN SELECT t2.*
FROM t1 JOIN t2 ON t2.fk=t1.pk
WHERE t2.fk IN ('a','b') AND t2.pk=t1.fk;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 12 NULL 2 Using where
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 18 test.t1.fk 1 Using where
DROP TABLE t1,t2;
CREATE TABLE t1 (a int, b varchar(20) NOT NULL, PRIMARY KEY(a));
CREATE TABLE t2 (a int, b varchar(20) NOT NULL,
PRIMARY KEY (a), UNIQUE KEY (b));
INSERT INTO t1 VALUES (1,'a'),(2,'b'),(3,'c');
INSERT INTO t2 VALUES (1,'a'),(2,'b'),(3,'c');
EXPLAIN SELECT t1.a FROM t1 LEFT JOIN t2 ON t2.b=t1.b WHERE t1.a=3;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 const b b 22 const 1 Using index
DROP TABLE t1,t2;
CREATE TABLE t1(id int PRIMARY KEY, b int, e int);
CREATE TABLE t2(i int, a int, INDEX si(i), INDEX ai(a));
CREATE TABLE t3(a int PRIMARY KEY, c char(4), INDEX ci(c));
INSERT INTO t1 VALUES
(1,10,19), (2,20,22), (4,41,42), (9,93,95), (7, 77,79),
(6,63,67), (5,55,58), (3,38,39), (8,81,89);
INSERT INTO t2 VALUES
(21,210), (41,410), (82,820), (83,830), (84,840),
(65,650), (51,510), (37,370), (94,940), (76,760),
(22,220), (33,330), (40,400), (95,950), (38,380),
(67,670), (88,880), (57,570), (96,960), (97,970);
INSERT INTO t3 VALUES
(210,'bb'), (950,'ii'), (400,'ab'), (500,'ee'), (220,'gg'),
(440,'gg'), (310,'eg'), (380,'ee'), (840,'bb'), (830,'ff'),
(230,'aa'), (960,'ii'), (410,'aa'), (510,'ee'), (290,'bb'),
(450,'gg'), (320,'dd'), (390,'hh'), (850,'jj'), (860,'ff');
EXPLAIN
SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
WHERE t1.id = 8 AND t2.i BETWEEN t1.b AND t1.e AND
t3.a=t2.a AND t3.c IN ('bb','ee');
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range si si 5 NULL 4 Using where
1 SIMPLE t3 eq_ref PRIMARY,ci PRIMARY 4 test.t2.a 1 Using where
EXPLAIN
SELECT t3.a FROM t1,t2,t3
WHERE t1.id = 8 AND t2.i BETWEEN t1.b AND t1.e AND
t3.a=t2.a AND t3.c IN ('bb','ee') ;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range si,ai si 5 NULL 4 Using where
1 SIMPLE t3 eq_ref PRIMARY,ci PRIMARY 4 test.t2.a 1 Using where
EXPLAIN
SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
t3.c IN ('bb','ee');
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range si si 5 NULL 2 Using where
1 SIMPLE t3 eq_ref PRIMARY,ci PRIMARY 4 test.t2.a 1 Using where
EXPLAIN
SELECT t3.a FROM t1,t2,t3
WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
t3.c IN ('bb','ee');
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t2 range si,ai si 5 NULL 2 Using where
1 SIMPLE t3 eq_ref PRIMARY,ci PRIMARY 4 test.t2.a 1 Using where
DROP TABLE t1,t2,t3;
...@@ -363,12 +363,12 @@ INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1'); ...@@ -363,12 +363,12 @@ INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1'); INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t8 ref PRIMARY PRIMARY 37 const 1 Using where; Using index 1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 Using index
4 SUBQUERY t8 ref PRIMARY PRIMARY 37 1 Using where; Using index 4 SUBQUERY t8 const PRIMARY PRIMARY 37 1 Using index
2 SUBQUERY t8 ref PRIMARY PRIMARY 37 const 1 Using where 2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1
3 SUBQUERY t8 ref PRIMARY PRIMARY 37 1 Using where; Using index 3 SUBQUERY t8 const PRIMARY PRIMARY 37 1 Using index
Warnings: Warnings:
Note 1003 select `test`.`t8`.`pseudo` AS `pseudo`,(select `test`.`t8`.`email` AS `email` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select `test`.`t8`.`pseudo` AS `pseudo` from `test`.`t8` where (`test`.`t8`.`pseudo` = _latin1'joce')))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where (`test`.`t8`.`pseudo` = (select `test`.`t8`.`pseudo` AS `pseudo` from `test`.`t8` where (`test`.`t8`.`pseudo` = _latin1'joce'))) Note 1003 select `test`.`t8`.`pseudo` AS `pseudo`,(select `test`.`t8`.`email` AS `email` from `test`.`t8` where 1) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where 1
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
t8 WHERE pseudo='joce'); t8 WHERE pseudo='joce');
ERROR 21000: Operand should contain 1 column(s) ERROR 21000: Operand should contain 1 column(s)
...@@ -3458,6 +3458,32 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -3458,6 +3458,32 @@ id select_type table type possible_keys key key_len ref rows Extra
4 UNION t12 system NULL NULL NULL NULL 0 const row not found 4 UNION t12 system NULL NULL NULL NULL 0 const row not found
NULL UNION RESULT <union2,4> ALL NULL NULL NULL NULL NULL NULL UNION RESULT <union2,4> ALL NULL NULL NULL NULL NULL
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
insert into t1 (a) values (FLOOR(rand() * 100));
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
SELECT a,
(SELECT REPEAT(' ',250) FROM t1 i1
WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a
FROM t1 ORDER BY a LIMIT 5;
a a
0 NULL
0 NULL
0 NULL
0 NULL
0 NULL
DROP TABLE t1;
CREATE TABLE t1 (a INT, b INT); CREATE TABLE t1 (a INT, b INT);
CREATE TABLE t2 (a INT); CREATE TABLE t2 (a INT);
INSERT INTO t2 values (1); INSERT INTO t2 values (1);
......
...@@ -779,3 +779,14 @@ select f1 from t1 where f1 in (select f1 from t1); ...@@ -779,3 +779,14 @@ select f1 from t1 where f1 in (select f1 from t1);
f1 f1
40 40
drop table t1; drop table t1;
create table t1 as
select from_days(s) as date,t
from (select 1 as s,'t' as t union select null, null ) as sub1;
select group_concat(t) from t1 group by week(date)/10;
group_concat(t)
t
Warnings:
Warning 1292 Truncated incorrect datetime value: '0000-00-00'
Warning 1292 Truncated incorrect datetime value: '0000-00-00'
Warning 1292 Truncated incorrect datetime value: '0000-00-00'
drop table t1;
...@@ -2956,4 +2956,14 @@ View Create View ...@@ -2956,4 +2956,14 @@ View Create View
v1 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`pk` AS `pk` from (`t1` join `t2` on(((`t2`.`fk` = `t1`.`pk`) and (`t2`.`ver` = (select max(`t`.`ver`) AS `MAX(t.ver)` from `t2` `t` where (`t`.`org` = `t2`.`org`)))))) v1 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`pk` AS `pk` from (`t1` join `t2` on(((`t2`.`fk` = `t1`.`pk`) and (`t2`.`ver` = (select max(`t`.`ver`) AS `MAX(t.ver)` from `t2` `t` where (`t`.`org` = `t2`.`org`))))))
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1, t2; DROP TABLE t1, t2;
CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, val INT UNSIGNED NOT NULL);
CREATE VIEW v1 AS SELECT id, val FROM t1 WHERE val >= 1 AND val <= 5 WITH CHECK OPTION;
INSERT INTO v1 (val) VALUES (2);
INSERT INTO v1 (val) VALUES (4);
INSERT INTO v1 (val) VALUES (6);
ERROR HY000: CHECK OPTION failed 'test.v1'
UPDATE v1 SET val=6 WHERE id=2;
ERROR HY000: CHECK OPTION failed 'test.v1'
DROP VIEW v1;
DROP TABLE t1;
End of 5.0 tests. End of 5.0 tests.
...@@ -32,7 +32,6 @@ select grp,group_concat(d order by a desc) from t1 group by grp; ...@@ -32,7 +32,6 @@ select grp,group_concat(d order by a desc) from t1 group by grp;
select grp,group_concat(a order by a,d+c-ascii(c)-a) from t1 group by grp; select grp,group_concat(a order by a,d+c-ascii(c)-a) from t1 group by grp;
select grp,group_concat(a order by d+c-ascii(c),a) from t1 group by grp; select grp,group_concat(a order by d+c-ascii(c),a) from t1 group by grp;
select grp,group_concat(c order by 1) from t1 group by grp; select grp,group_concat(c order by 1) from t1 group by grp;
select grp,group_concat(c order by "c") from t1 group by grp;
select grp,group_concat(distinct c order by c) from t1 group by grp; select grp,group_concat(distinct c order by c) from t1 group by grp;
select grp,group_concat(distinct c order by c desc) from t1 group by grp; select grp,group_concat(distinct c order by c desc) from t1 group by grp;
explain extended select grp,group_concat(distinct c order by c desc) from t1 group by grp; explain extended select grp,group_concat(distinct c order by c desc) from t1 group by grp;
......
...@@ -231,4 +231,14 @@ INSERT INTO t1 (c1) VALUES ( ...@@ -231,4 +231,14 @@ INSERT INTO t1 (c1) VALUES (
CHECK TABLE t1 EXTENDED; CHECK TABLE t1 EXTENDED;
DROP TABLE t1; DROP TABLE t1;
#
# Bug #21888: Query on GEOMETRY field using PointFromWKB() results in lost connection
#
CREATE TABLE t1 (foo GEOMETRY NOT NULL, SPATIAL INDEX(foo) );
INSERT INTO t1 (foo) VALUES (PointFromWKB(POINT(1,1)));
INSERT INTO t1 (foo) VALUES (PointFromWKB(POINT(1,0)));
INSERT INTO t1 (foo) VALUES (PointFromWKB(POINT(0,1)));
INSERT INTO t1 (foo) VALUES (PointFromWKB(POINT(0,0)));
SELECT 1 FROM t1 WHERE foo != PointFromWKB(POINT(0,0));
DROP TABLE t1;
# End of 4.1 tests # End of 4.1 tests
...@@ -609,6 +609,30 @@ select sql_buffer_result max(f1) is null from t1; ...@@ -609,6 +609,30 @@ select sql_buffer_result max(f1) is null from t1;
select sql_buffer_result max(f1)+1 from t1; select sql_buffer_result max(f1)+1 from t1;
drop table t1; drop table t1;
#
# BUG#14019-4.1-opt
#
CREATE TABLE t1(a INT); INSERT INTO t1 VALUES (1),(2);
SELECT a FROM t1 GROUP BY 'a';
SELECT a FROM t1 GROUP BY "a";
SELECT a FROM t1 GROUP BY `a`;
set sql_mode=ANSI_QUOTES;
SELECT a FROM t1 GROUP BY "a";
SELECT a FROM t1 GROUP BY 'a';
SELECT a FROM t1 GROUP BY `a`;
set sql_mode='';
SELECT a FROM t1 HAVING 'a' > 1;
SELECT a FROM t1 HAVING "a" > 1;
SELECT a FROM t1 HAVING `a` > 1;
SELECT a FROM t1 ORDER BY 'a' DESC;
SELECT a FROM t1 ORDER BY "a" DESC;
SELECT a FROM t1 ORDER BY `a` DESC;
DROP TABLE t1;
# End of 4.1 tests # End of 4.1 tests
# #
...@@ -655,3 +679,25 @@ where t2.b=v1.a GROUP BY t2.b; ...@@ -655,3 +679,25 @@ where t2.b=v1.a GROUP BY t2.b;
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1,t2; DROP TABLE t1,t2;
#
# Bug#22781: SQL_BIG_RESULT fails to influence sort plan
#
CREATE TABLE t1 (a INT PRIMARY KEY, b INT, key (b));
INSERT INTO t1 VALUES (1, 1);
INSERT INTO t1 SELECT a + 1 , MOD(a + 1 , 20) FROM t1;
INSERT INTO t1 SELECT a + 2 , MOD(a + 2 , 20) FROM t1;
INSERT INTO t1 SELECT a + 4 , MOD(a + 4 , 20) FROM t1;
INSERT INTO t1 SELECT a + 8 , MOD(a + 8 , 20) FROM t1;
INSERT INTO t1 SELECT a + 16, MOD(a + 16, 20) FROM t1;
INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20) FROM t1;
INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20) FROM t1;
SELECT MIN(b), MAX(b) from t1;
EXPLAIN SELECT b, sum(1) FROM t1 GROUP BY b;
EXPLAIN SELECT SQL_BIG_RESULT b, sum(1) FROM t1 GROUP BY b;
SELECT b, sum(1) FROM t1 GROUP BY b;
SELECT SQL_BIG_RESULT b, sum(1) FROM t1 GROUP BY b;
DROP TABLE t1;
...@@ -794,3 +794,19 @@ SELECT * FROM ...@@ -794,3 +794,19 @@ SELECT * FROM
t1; t1;
DROP TABLE t1,t2,t3,t4,t5,t6; DROP TABLE t1,t2,t3,t4,t5,t6;
#
# Bug#22342: No results returned for query using max and group by
#
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a,b), KEY b (b));
INSERT INTO t1 VALUES (1,1),(1,2),(1,0),(1,3);
explain SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a;
SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a;
SELECT MIN(b), a FROM t1 WHERE b > 1 AND a = 1 GROUP BY a;
CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a,b,c));
INSERT INTO t2 SELECT a,b,b FROM t1;
explain SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a;
SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a;
DROP TABLE t1,t2;
...@@ -302,3 +302,21 @@ SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id ...@@ -302,3 +302,21 @@ SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id
WHERE t1.name LIKE 'A%' OR FALSE; WHERE t1.name LIKE 'A%' OR FALSE;
DROP TABLE t1,t2; DROP TABLE t1,t2;
#
# Bug#22781: SQL_BIG_RESULT fails to influence sort plan
#
CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB;
INSERT INTO t1 VALUES ( 1 , 1 , 1);
INSERT INTO t1 SELECT a + 1 , MOD(a + 1 , 20), 1 FROM t1;
INSERT INTO t1 SELECT a + 2 , MOD(a + 2 , 20), 1 FROM t1;
INSERT INTO t1 SELECT a + 4 , MOD(a + 4 , 20), 1 FROM t1;
INSERT INTO t1 SELECT a + 8 , MOD(a + 8 , 20), 1 FROM t1;
INSERT INTO t1 SELECT a + 16, MOD(a + 16, 20), 1 FROM t1;
INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20), 1 FROM t1;
INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20), 1 FROM t1;
EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b;
EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b;
DROP TABLE t1;
...@@ -72,4 +72,17 @@ disconnect con2; ...@@ -72,4 +72,17 @@ disconnect con2;
disconnect con1; disconnect con1;
connection default; connection default;
#
# Bug#14959: ALTER TABLE isn't able to rename a view
#
create table t1(f1 int);
create view v1 as select * from t1;
alter table v1 rename to v2;
--error 1146
alter table v1 rename to v2;
rename table v2 to v1;
--error 1050
rename table v2 to v1;
drop view v1;
drop table t1;
# End of 4.1 tests # End of 4.1 tests
...@@ -2996,5 +2996,99 @@ SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id ...@@ -2996,5 +2996,99 @@ SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id
SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id
WHERE t1.id=2; WHERE t1.id=2;
DROP TABLE t1,t2,t3;
#
# Bug#20503: Server crash due to the ORDER clause isn't taken into account
# while space allocation
#
create table t1 (c1 varchar(1), c2 int, c3 int, c4 int, c5 int, c6 int,
c7 int, c8 int, c9 int, fulltext key (`c1`));
select distinct match (`c1`) against ('z') , c2, c3, c4,c5, c6,c7, c8
from t1 where c9=1 order by c2, c2;
drop table t1;
#
# Bug #22735: no equality propagation for BETWEEN and IN with STRING arguments
#
CREATE TABLE t1 (pk varchar(10) PRIMARY KEY, fk varchar(16));
CREATE TABLE t2 (pk varchar(16) PRIMARY KEY, fk varchar(10));
INSERT INTO t1 VALUES
('d','dddd'), ('i','iii'), ('a','aa'), ('b','bb'), ('g','gg'),
('e','eee'), ('c','cccc'), ('h','hhh'), ('j','jjj'), ('f','fff');
INSERT INTO t2 VALUES
('jjj', 'j'), ('cc','c'), ('ccc','c'), ('aaa', 'a'), ('jjjj','j'),
('hhh','h'), ('gg','g'), ('fff','f'), ('ee','e'), ('ffff','f'),
('bbb','b'), ('ff','f'), ('cccc','c'), ('dddd','d'), ('jj','j'),
('aaaa','a'), ('bb','b'), ('eeee','e'), ('aa','a'), ('hh','h');
EXPLAIN SELECT t2.*
FROM t1 JOIN t2 ON t2.fk=t1.pk
WHERE t2.fk < 'c' AND t2.pk=t1.fk;
EXPLAIN SELECT t2.*
FROM t1 JOIN t2 ON t2.fk=t1.pk
WHERE t2.fk BETWEEN 'a' AND 'b' AND t2.pk=t1.fk;
EXPLAIN SELECT t2.*
FROM t1 JOIN t2 ON t2.fk=t1.pk
WHERE t2.fk IN ('a','b') AND t2.pk=t1.fk;
DROP TABLE t1,t2;
#
# Bug #22367: Optimizer uses ref join type instead of eq_ref for simple
# join on strings
#
CREATE TABLE t1 (a int, b varchar(20) NOT NULL, PRIMARY KEY(a));
CREATE TABLE t2 (a int, b varchar(20) NOT NULL,
PRIMARY KEY (a), UNIQUE KEY (b));
INSERT INTO t1 VALUES (1,'a'),(2,'b'),(3,'c');
INSERT INTO t2 VALUES (1,'a'),(2,'b'),(3,'c');
EXPLAIN SELECT t1.a FROM t1 LEFT JOIN t2 ON t2.b=t1.b WHERE t1.a=3;
DROP TABLE t1,t2;
#
# Bug #19579: predicates that become sargable after reading const tables
# are not taken into account by optimizer
#
CREATE TABLE t1(id int PRIMARY KEY, b int, e int);
CREATE TABLE t2(i int, a int, INDEX si(i), INDEX ai(a));
CREATE TABLE t3(a int PRIMARY KEY, c char(4), INDEX ci(c));
INSERT INTO t1 VALUES
(1,10,19), (2,20,22), (4,41,42), (9,93,95), (7, 77,79),
(6,63,67), (5,55,58), (3,38,39), (8,81,89);
INSERT INTO t2 VALUES
(21,210), (41,410), (82,820), (83,830), (84,840),
(65,650), (51,510), (37,370), (94,940), (76,760),
(22,220), (33,330), (40,400), (95,950), (38,380),
(67,670), (88,880), (57,570), (96,960), (97,970);
INSERT INTO t3 VALUES
(210,'bb'), (950,'ii'), (400,'ab'), (500,'ee'), (220,'gg'),
(440,'gg'), (310,'eg'), (380,'ee'), (840,'bb'), (830,'ff'),
(230,'aa'), (960,'ii'), (410,'aa'), (510,'ee'), (290,'bb'),
(450,'gg'), (320,'dd'), (390,'hh'), (850,'jj'), (860,'ff');
EXPLAIN
SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
WHERE t1.id = 8 AND t2.i BETWEEN t1.b AND t1.e AND
t3.a=t2.a AND t3.c IN ('bb','ee');
EXPLAIN
SELECT t3.a FROM t1,t2,t3
WHERE t1.id = 8 AND t2.i BETWEEN t1.b AND t1.e AND
t3.a=t2.a AND t3.c IN ('bb','ee') ;
EXPLAIN
SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
t3.c IN ('bb','ee');
EXPLAIN
SELECT t3.a FROM t1,t2,t3
WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
t3.c IN ('bb','ee');
DROP TABLE t1,t2,t3; DROP TABLE t1,t2,t3;
...@@ -2370,6 +2370,32 @@ explain select * from t1 where not exists ...@@ -2370,6 +2370,32 @@ explain select * from t1 where not exists
DROP TABLE t1; DROP TABLE t1;
#
# Bug#21798: memory leak during query execution with subquery in column
# list using a function
#
CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
insert into t1 (a) values (FLOOR(rand() * 100));
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
insert into t1 (a) select FLOOR(rand() * 100) from t1;
SELECT a,
(SELECT REPEAT(' ',250) FROM t1 i1
WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a
FROM t1 ORDER BY a LIMIT 5;
DROP TABLE t1;
# #
# Bug #21540: Subqueries with no from and aggregate functions return # Bug #21540: Subqueries with no from and aggregate functions return
# wrong results # wrong results
......
...@@ -385,3 +385,12 @@ insert into t1 values (40); ...@@ -385,3 +385,12 @@ insert into t1 values (40);
flush tables; flush tables;
select f1 from t1 where f1 in (select f1 from t1); select f1 from t1 where f1 in (select f1 from t1);
drop table t1; drop table t1;
#
# Bug#22183: Unhandled NULL caused server crash
#
create table t1 as
select from_days(s) as date,t
from (select 1 as s,'t' as t union select null, null ) as sub1;
select group_concat(t) from t1 group by week(date)/10;
drop table t1;
...@@ -2879,4 +2879,19 @@ SHOW CREATE VIEW v1; ...@@ -2879,4 +2879,19 @@ SHOW CREATE VIEW v1;
DROP VIEW v1; DROP VIEW v1;
DROP TABLE t1, t2; DROP TABLE t1, t2;
#
# Bug #16813 (WITH CHECK OPTION doesn't work with UPDATE)
#
CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, val INT UNSIGNED NOT NULL);
CREATE VIEW v1 AS SELECT id, val FROM t1 WHERE val >= 1 AND val <= 5 WITH CHECK OPTION;
INSERT INTO v1 (val) VALUES (2);
INSERT INTO v1 (val) VALUES (4);
-- error 1369
INSERT INTO v1 (val) VALUES (6);
-- error 1369
UPDATE v1 SET val=6 WHERE id=2;
DROP VIEW v1;
DROP TABLE t1;
--echo End of 5.0 tests. --echo End of 5.0 tests.
...@@ -132,11 +132,17 @@ bool Cached_item_decimal::cmp() ...@@ -132,11 +132,17 @@ bool Cached_item_decimal::cmp()
{ {
my_decimal tmp; my_decimal tmp;
my_decimal *ptmp= item->val_decimal(&tmp); my_decimal *ptmp= item->val_decimal(&tmp);
if (null_value != item->null_value || my_decimal_cmp(&value, ptmp)) if (null_value != item->null_value ||
(!item->null_value && my_decimal_cmp(&value, ptmp)))
{ {
null_value= item->null_value; null_value= item->null_value;
my_decimal2decimal(ptmp, &value); /* Save only not null values */
return TRUE; if (!null_value)
{
my_decimal2decimal(ptmp, &value);
return TRUE;
}
return FALSE;
} }
return FALSE; return FALSE;
} }
......
...@@ -1078,6 +1078,8 @@ bool Item_func_between::fix_fields(THD *thd, Item **ref) ...@@ -1078,6 +1078,8 @@ bool Item_func_between::fix_fields(THD *thd, Item **ref)
if (Item_func_opt_neg::fix_fields(thd, ref)) if (Item_func_opt_neg::fix_fields(thd, ref))
return 1; return 1;
thd->lex->current_select->between_count++;
/* not_null_tables_cache == union(T1(e),T1(e1),T1(e2)) */ /* not_null_tables_cache == union(T1(e),T1(e1),T1(e2)) */
if (pred_level && !negated) if (pred_level && !negated)
return 0; return 0;
......
...@@ -446,6 +446,7 @@ public: ...@@ -446,6 +446,7 @@ public:
negated= !negated; negated= !negated;
return this; return this;
} }
bool subst_argument_checker(byte **arg) { return TRUE; }
}; };
......
...@@ -659,6 +659,9 @@ int quick_rm_table(enum db_type base,const char *db, ...@@ -659,6 +659,9 @@ int quick_rm_table(enum db_type base,const char *db,
const char *table_name); const char *table_name);
void close_cached_table(THD *thd, TABLE *table); void close_cached_table(THD *thd, TABLE *table);
bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list); bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list);
bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db,
char *new_table_name, char *new_table_alias,
bool skip_error);
bool mysql_change_db(THD *thd,const char *name,bool no_access_check); bool mysql_change_db(THD *thd,const char *name,bool no_access_check);
void mysql_parse(THD *thd,char *inBuf,uint length); void mysql_parse(THD *thd,char *inBuf,uint length);
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length); bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
...@@ -722,7 +725,8 @@ bool mysql_xa_recover(THD *thd); ...@@ -722,7 +725,8 @@ bool mysql_xa_recover(THD *thd);
bool check_simple_select(); bool check_simple_select();
SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length); SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length,
SORT_FIELD *sortorder);
int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
List<Item> &fields, List <Item> &all_fields, ORDER *order); List<Item> &fields, List <Item> &all_fields, ORDER *order);
int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
......
...@@ -8372,6 +8372,7 @@ TRP_GROUP_MIN_MAX::make_quick(PARAM *param, bool retrieve_full_rows, ...@@ -8372,6 +8372,7 @@ TRP_GROUP_MIN_MAX::make_quick(PARAM *param, bool retrieve_full_rows,
quick->quick_prefix_select= NULL; quick->quick_prefix_select= NULL;
quick->update_key_stat(); quick->update_key_stat();
quick->adjust_prefix_ranges();
DBUG_RETURN(quick); DBUG_RETURN(quick);
} }
...@@ -8601,6 +8602,42 @@ bool QUICK_GROUP_MIN_MAX_SELECT::add_range(SEL_ARG *sel_range) ...@@ -8601,6 +8602,42 @@ bool QUICK_GROUP_MIN_MAX_SELECT::add_range(SEL_ARG *sel_range)
} }
/*
Opens the ranges if there are more conditions in quick_prefix_select than
the ones used for jumping through the prefixes.
SYNOPSIS
QUICK_GROUP_MIN_MAX_SELECT::adjust_prefix_ranges()
NOTES
quick_prefix_select is made over the conditions on the whole key.
It defines a number of ranges of length x.
However when jumping through the prefixes we use only the the first
few most significant keyparts in the range key. However if there
are more keyparts to follow the ones we are using we must make the
condition on the key inclusive (because x < "ab" means
x[0] < 'a' OR (x[0] == 'a' AND x[1] < 'b').
To achive the above we must turn off the NEAR_MIN/NEAR_MAX
*/
void QUICK_GROUP_MIN_MAX_SELECT::adjust_prefix_ranges ()
{
if (quick_prefix_select &&
group_prefix_len < quick_prefix_select->max_used_key_length)
{
DYNAMIC_ARRAY *arr;
uint inx;
for (inx= 0, arr= &quick_prefix_select->ranges; inx < arr->elements; inx++)
{
QUICK_RANGE *range;
get_dynamic(arr, (gptr)&range, inx);
range->flag &= ~(NEAR_MIN | NEAR_MAX);
}
}
}
/* /*
Determine the total number and length of the keys that will be used for Determine the total number and length of the keys that will be used for
index lookup. index lookup.
......
...@@ -295,6 +295,7 @@ protected: ...@@ -295,6 +295,7 @@ protected:
friend class QUICK_SELECT_DESC; friend class QUICK_SELECT_DESC;
friend class QUICK_INDEX_MERGE_SELECT; friend class QUICK_INDEX_MERGE_SELECT;
friend class QUICK_ROR_INTERSECT_SELECT; friend class QUICK_ROR_INTERSECT_SELECT;
friend class QUICK_GROUP_MIN_MAX_SELECT;
DYNAMIC_ARRAY ranges; /* ordered array of range ptrs */ DYNAMIC_ARRAY ranges; /* ordered array of range ptrs */
QUICK_RANGE **cur_range; /* current element in ranges */ QUICK_RANGE **cur_range; /* current element in ranges */
...@@ -643,6 +644,7 @@ public: ...@@ -643,6 +644,7 @@ public:
~QUICK_GROUP_MIN_MAX_SELECT(); ~QUICK_GROUP_MIN_MAX_SELECT();
bool add_range(SEL_ARG *sel_range); bool add_range(SEL_ARG *sel_range);
void update_key_stat(); void update_key_stat();
void adjust_prefix_ranges();
bool alloc_buffers(); bool alloc_buffers();
int init(); int init();
int reset(); int reset();
......
...@@ -3450,13 +3450,20 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter, ...@@ -3450,13 +3450,20 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
const char *field_name=0; const char *field_name=0;
const char *table_name=0; const char *table_name=0;
bool found_unaliased_non_uniq= 0; bool found_unaliased_non_uniq= 0;
/*
true if the item that we search for is a valid name reference
(and not an item that happens to have a name).
*/
bool is_ref_by_name= 0;
uint unaliased_counter; uint unaliased_counter;
LINT_INIT(unaliased_counter); // Dependent on found_unaliased LINT_INIT(unaliased_counter); // Dependent on found_unaliased
*unaliased= FALSE; *unaliased= FALSE;
if (find->type() == Item::FIELD_ITEM || find->type() == Item::REF_ITEM) is_ref_by_name= (find->type() == Item::FIELD_ITEM ||
find->type() == Item::REF_ITEM);
if (is_ref_by_name)
{ {
field_name= ((Item_ident*) find)->field_name; field_name= ((Item_ident*) find)->field_name;
table_name= ((Item_ident*) find)->table_name; table_name= ((Item_ident*) find)->table_name;
...@@ -3568,7 +3575,7 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter, ...@@ -3568,7 +3575,7 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
} }
} }
else if (!table_name && (find->eq(item,0) || else if (!table_name && (find->eq(item,0) ||
find->name && item->name && is_ref_by_name && find->name && item->name &&
!my_strcasecmp(system_charset_info, !my_strcasecmp(system_charset_info,
item->name,find->name))) item->name,find->name)))
{ {
...@@ -4899,6 +4906,7 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves, ...@@ -4899,6 +4906,7 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
thd->set_query_id=1; thd->set_query_id=1;
select_lex->cond_count= 0; select_lex->cond_count= 0;
select_lex->between_count= 0;
for (table= tables; table; table= table->next_local) for (table= tables; table; table= table->next_local)
{ {
......
...@@ -167,7 +167,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ...@@ -167,7 +167,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
MYF(MY_FAE | MY_ZEROFILL)); MYF(MY_FAE | MY_ZEROFILL));
if (!(sortorder= make_unireg_sortorder((ORDER*) order->first, if (!(sortorder= make_unireg_sortorder((ORDER*) order->first,
&length)) || &length, NULL)) ||
(table->sort.found_records = filesort(thd, table, sortorder, length, (table->sort.found_records = filesort(thd, table, sortorder, length,
select, HA_POS_ERROR, select, HA_POS_ERROR,
&examined_rows)) &examined_rows))
......
...@@ -1138,7 +1138,7 @@ void st_select_lex::init_query() ...@@ -1138,7 +1138,7 @@ void st_select_lex::init_query()
initialization is checked for failure. initialization is checked for failure.
*/ */
parent_lex->push_context(&context); parent_lex->push_context(&context);
cond_count= with_wild= 0; cond_count= between_count= with_wild= 0;
conds_processed_with_permanent_arena= 0; conds_processed_with_permanent_arena= 0;
ref_pointer_array= 0; ref_pointer_array= 0;
select_n_having_items= 0; select_n_having_items= 0;
......
...@@ -530,7 +530,8 @@ public: ...@@ -530,7 +530,8 @@ public:
list during split_sum_func list during split_sum_func
*/ */
uint select_n_having_items; uint select_n_having_items;
uint cond_count; /* number of arguments of and/or/xor in where/having */ uint cond_count; /* number of arguments of and/or/xor in where/having/on */
uint between_count; /* number of between predicates in where/having/on */
enum_parsing_place parsing_place; /* where we are parsing expression */ enum_parsing_place parsing_place; /* where we are parsing expression */
bool with_sum_func; /* sum function indicator */ bool with_sum_func; /* sum function indicator */
/* /*
......
...@@ -126,94 +126,146 @@ static TABLE_LIST *reverse_table_list(TABLE_LIST *table_list) ...@@ -126,94 +126,146 @@ static TABLE_LIST *reverse_table_list(TABLE_LIST *table_list)
/* /*
Rename all tables in list; Return pointer to wrong entry if something goes Rename a single table or a view
wrong. Note that the table_list may be empty!
SYNPOSIS
do_rename()
thd Thread handle
ren_table A table/view to be renamed
new_db The database to which the table to be moved to
new_table_name The new table/view name
new_table_alias The new table/view alias
skip_error Whether to skip error
DESCRIPTION
Rename a single table or a view.
RETURN
false Ok
true rename failed
*/ */
static TABLE_LIST * bool
rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error) do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
char *new_table_alias, bool skip_error)
{ {
TABLE_LIST *ren_table,*new_table; int rc= 1;
char name[FN_REFLEN];
const char *new_alias, *old_alias;
frm_type_enum frm_type; frm_type_enum frm_type;
db_type table_type; db_type table_type;
DBUG_ENTER("rename_tables"); DBUG_ENTER("do_rename");
for (ren_table= table_list; ren_table; ren_table= new_table->next_local) if (lower_case_table_names == 2)
{ {
int rc= 1; old_alias= ren_table->alias;
char name[FN_REFLEN]; new_alias= new_table_alias;
const char *new_alias, *old_alias; }
else
new_table= ren_table->next_local; {
if (lower_case_table_names == 2) old_alias= ren_table->table_name;
{ new_alias= new_table_name;
old_alias= ren_table->alias; }
new_alias= new_table->alias; sprintf(name,"%s/%s/%s%s",mysql_data_home,
} new_db, new_alias, reg_ext);
else unpack_filename(name, name);
{ if (!access(name,F_OK))
old_alias= ren_table->table_name; {
new_alias= new_table->table_name; my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
} DBUG_RETURN(1); // This can't be skipped
sprintf(name,"%s/%s/%s%s",mysql_data_home, }
new_table->db, new_alias, reg_ext); sprintf(name,"%s/%s/%s%s",mysql_data_home,
unpack_filename(name, name); ren_table->db, old_alias,
if (!access(name,F_OK)) reg_ext);
{ unpack_filename(name, name);
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
DBUG_RETURN(ren_table); // This can't be skipped
}
sprintf(name,"%s/%s/%s%s",mysql_data_home,
ren_table->db, old_alias,
reg_ext);
unpack_filename(name, name);
frm_type= mysql_frm_type(thd, name, &table_type); frm_type= mysql_frm_type(thd, name, &table_type);
switch (frm_type) switch (frm_type)
{
case FRMTYPE_TABLE:
{ {
case FRMTYPE_TABLE: if (table_type == DB_TYPE_UNKNOWN)
my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
else
{ {
if (table_type == DB_TYPE_UNKNOWN) if (!(rc= mysql_rename_table(table_type, ren_table->db, old_alias,
my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno); new_db, new_alias)))
else
{ {
if (!(rc= mysql_rename_table(table_type, ren_table->db, old_alias, if ((rc= Table_triggers_list::change_table_name(thd, ren_table->db,
new_table->db, new_alias))) old_alias,
new_db,
new_alias)))
{ {
if ((rc= Table_triggers_list::change_table_name(thd, ren_table->db, /*
old_alias, We've succeeded in renaming table's .frm and in updating
new_table->db, corresponding handler data, but have failed to update table's
new_alias))) triggers appropriately. So let us revert operations on .frm
{ and handler's data and report about failure to rename table.
/* */
We've succeeded in renaming table's .frm and in updating (void) mysql_rename_table(table_type, new_db, new_alias,
corresponding handler data, but have failed to update table's ren_table->db, old_alias);
triggers appropriately. So let us revert operations on .frm
and handler's data and report about failure to rename table.
*/
(void) mysql_rename_table(table_type, new_table->db, new_alias,
ren_table->db, old_alias);
}
} }
} }
break;
} }
case FRMTYPE_VIEW: break;
/* change of schema is not allowed */
if (strcmp(ren_table->db, new_table->db))
my_error(ER_FORBID_SCHEMA_CHANGE, MYF(0), ren_table->db,
new_table->db);
else
rc= mysql_rename_view(thd, new_alias, ren_table);
break;
default:
DBUG_ASSERT(0); // should never happen
case FRMTYPE_ERROR:
my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
break;
} }
if (rc && !skip_error) case FRMTYPE_VIEW:
/* change of schema is not allowed */
if (strcmp(ren_table->db, new_db))
my_error(ER_FORBID_SCHEMA_CHANGE, MYF(0), ren_table->db,
new_db);
else
rc= mysql_rename_view(thd, new_alias, ren_table);
break;
default:
DBUG_ASSERT(0); // should never happen
case FRMTYPE_ERROR:
my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
break;
}
if (rc && !skip_error)
DBUG_RETURN(1);
DBUG_RETURN(0);
}
/*
Rename all tables in list; Return pointer to wrong entry if something goes
wrong. Note that the table_list may be empty!
*/
/*
Rename tables/views in the list
SYNPOSIS
rename_tables()
thd Thread handle
table_list List of tables to rename
skip_error Whether to skip errors
DESCRIPTION
Take a table/view name from and odd list element and rename it to a
the name taken from list element+1. Note that the table_list may be
empty.
RETURN
false Ok
true rename failed
*/
static TABLE_LIST *
rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error)
{
TABLE_LIST *ren_table,*new_table, *tmp_table;
DBUG_ENTER("rename_tables");
for (ren_table= table_list; ren_table; ren_table= new_table->next_local)
{
new_table= ren_table->next_local;
if (do_rename(thd, ren_table, new_table->db, new_table->table_name,
new_table->alias, skip_error))
DBUG_RETURN(ren_table); DBUG_RETURN(ren_table);
} }
DBUG_RETURN(0); DBUG_RETURN(0);
......
This diff is collapsed.
...@@ -282,6 +282,18 @@ public: ...@@ -282,6 +282,18 @@ public:
bool union_part; // this subselect is part of union bool union_part; // this subselect is part of union
bool optimized; // flag to avoid double optimization in EXPLAIN bool optimized; // flag to avoid double optimization in EXPLAIN
/*
storage for caching buffers allocated during query execution.
These buffers allocations need to be cached as the thread memory pool is
cleared only at the end of the execution of the whole query and not caching
allocations that occur in repetition at execution time will result in
excessive memory usage.
*/
SORT_FIELD *sortorder; // make_unireg_sortorder()
TABLE **table_reexec; // make_simple_join()
JOIN_TAB *join_tab_reexec; // make_simple_join()
/* end of allocation caching storage */
JOIN(THD *thd_arg, List<Item> &fields_arg, ulonglong select_options_arg, JOIN(THD *thd_arg, List<Item> &fields_arg, ulonglong select_options_arg,
select_result *result_arg) select_result *result_arg)
:fields_list(fields_arg) :fields_list(fields_arg)
...@@ -307,6 +319,9 @@ public: ...@@ -307,6 +319,9 @@ public:
examined_rows= 0; examined_rows= 0;
exec_tmp_table1= 0; exec_tmp_table1= 0;
exec_tmp_table2= 0; exec_tmp_table2= 0;
sortorder= 0;
table_reexec= 0;
join_tab_reexec= 0;
thd= thd_arg; thd= thd_arg;
sum_funcs= sum_funcs2= 0; sum_funcs= sum_funcs2= 0;
procedure= 0; procedure= 0;
......
...@@ -3155,9 +3155,10 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -3155,9 +3155,10 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
ha_rows copied,deleted; ha_rows copied,deleted;
ulonglong next_insert_id; ulonglong next_insert_id;
uint db_create_options, used_fields; uint db_create_options, used_fields;
enum db_type old_db_type,new_db_type; enum db_type old_db_type, new_db_type, table_type;
bool need_copy_table; bool need_copy_table;
bool no_table_reopen= FALSE, varchar= FALSE; bool no_table_reopen= FALSE, varchar= FALSE;
frm_type_enum frm_type;
DBUG_ENTER("mysql_alter_table"); DBUG_ENTER("mysql_alter_table");
thd->proc_info="init"; thd->proc_info="init";
...@@ -3175,6 +3176,51 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -3175,6 +3176,51 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
if (alter_info->tablespace_op != NO_TABLESPACE_OP) if (alter_info->tablespace_op != NO_TABLESPACE_OP)
DBUG_RETURN(mysql_discard_or_import_tablespace(thd,table_list, DBUG_RETURN(mysql_discard_or_import_tablespace(thd,table_list,
alter_info->tablespace_op)); alter_info->tablespace_op));
sprintf(new_name_buff,"%s/%s/%s%s",mysql_data_home, db, table_name, reg_ext);
unpack_filename(new_name_buff, new_name_buff);
if (lower_case_table_names != 2)
my_casedn_str(files_charset_info, new_name_buff);
frm_type= mysql_frm_type(thd, new_name_buff, &table_type);
/* Rename a view */
if (frm_type == FRMTYPE_VIEW && !(alter_info->flags & ~ALTER_RENAME))
{
/*
Avoid problems with a rename on a table that we have locked or
if the user is trying to to do this in a transcation context
*/
if (thd->locked_tables || thd->active_transaction())
{
my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
DBUG_RETURN(1);
}
if (wait_if_global_read_lock(thd,0,1))
DBUG_RETURN(1);
VOID(pthread_mutex_lock(&LOCK_open));
if (lock_table_names(thd, table_list))
goto view_err;
error=0;
if (!do_rename(thd, table_list, new_db, new_name, new_name, 1))
{
if (mysql_bin_log.is_open())
{
thd->clear_error();
Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo);
}
send_ok(thd);
}
unlock_table_names(thd, table_list, (TABLE_LIST*) 0);
view_err:
pthread_mutex_unlock(&LOCK_open);
start_waiting_global_read_lock(thd);
DBUG_RETURN(error);
}
if (!(table=open_ltable(thd,table_list,TL_WRITE_ALLOW_READ))) if (!(table=open_ltable(thd,table_list,TL_WRITE_ALLOW_READ)))
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
...@@ -4050,7 +4096,7 @@ copy_data_between_tables(TABLE *from,TABLE *to, ...@@ -4050,7 +4096,7 @@ copy_data_between_tables(TABLE *from,TABLE *to,
if (thd->lex->select_lex.setup_ref_array(thd, order_num) || if (thd->lex->select_lex.setup_ref_array(thd, order_num) ||
setup_order(thd, thd->lex->select_lex.ref_pointer_array, setup_order(thd, thd->lex->select_lex.ref_pointer_array,
&tables, fields, all_fields, order) || &tables, fields, all_fields, order) ||
!(sortorder=make_unireg_sortorder(order, &length)) || !(sortorder=make_unireg_sortorder(order, &length, NULL)) ||
(from->sort.found_records = filesort(thd, from, sortorder, length, (from->sort.found_records = filesort(thd, from, sortorder, length,
(SQL_SELECT *) 0, HA_POS_ERROR, (SQL_SELECT *) 0, HA_POS_ERROR,
&examined_rows)) == &examined_rows)) ==
......
...@@ -311,7 +311,7 @@ int mysql_update(THD *thd, ...@@ -311,7 +311,7 @@ int mysql_update(THD *thd,
table->sort.io_cache = (IO_CACHE *) my_malloc(sizeof(IO_CACHE), table->sort.io_cache = (IO_CACHE *) my_malloc(sizeof(IO_CACHE),
MYF(MY_FAE | MY_ZEROFILL)); MYF(MY_FAE | MY_ZEROFILL));
if (!(sortorder=make_unireg_sortorder(order, &length)) || if (!(sortorder=make_unireg_sortorder(order, &length, NULL)) ||
(table->sort.found_records = filesort(thd, table, sortorder, length, (table->sort.found_records = filesort(thd, table, sortorder, length,
select, limit, select, limit,
&examined_rows)) &examined_rows))
......
...@@ -1977,12 +1977,13 @@ bool st_table_list::prep_where(THD *thd, Item **conds, ...@@ -1977,12 +1977,13 @@ bool st_table_list::prep_where(THD *thd, Item **conds,
this expression will not be moved to WHERE condition (i.e. will this expression will not be moved to WHERE condition (i.e. will
be clean correctly for PS/SP) be clean correctly for PS/SP)
*/ */
tbl->on_expr= and_conds(tbl->on_expr, where); tbl->on_expr= and_conds(tbl->on_expr,
where->copy_andor_structure(thd));
break; break;
} }
} }
if (tbl == 0) if (tbl == 0)
*conds= and_conds(*conds, where); *conds= and_conds(*conds, where->copy_andor_structure(thd));
if (arena) if (arena)
thd->restore_active_arena(arena, &backup); thd->restore_active_arena(arena, &backup);
where_processed= TRUE; where_processed= TRUE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment