Commit b471565e authored by unknown's avatar unknown

Merge trift2.:/MySQL/M51/mysql-5.1

into  trift2.:/MySQL/M51/push-5.1

parents 80cb3cf4 7c472868
......@@ -742,4 +742,24 @@ select * from t2;
drop table t2;
#
# Tests for bug #28415 "Some ALTER TABLE statements no longer work
# under LOCK TABLES" and some aspects of fast ALTER TABLE behaviour
# for transactional tables.
#
--disable_warnings
drop table if exists t1, t2;
--enable_warnings
create table t1 (i int);
alter table t1 modify i int default 1;
alter table t1 modify i int default 2, rename t2;
lock table t2 write;
alter table t2 modify i int default 3;
unlock tables;
lock table t2 write;
alter table t2 modify i int default 4, rename t1;
unlock tables;
drop table t1;
--echo End of 5.1 tests
......@@ -782,6 +782,100 @@ t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 MAX_ROWS=4294967295
drop table t1;
create table t1 select * from t2;
ERROR 42S02: Table 'test.t2' doesn't exist
create table t1 select * from t1;
ERROR HY000: You can't specify target table 't1' for update in FROM clause
create table t1 select coalesce('a' collate latin1_swedish_ci,'b' collate latin1_bin);
ERROR HY000: Illegal mix of collations (latin1_swedish_ci,EXPLICIT) and (latin1_bin,EXPLICIT) for operation 'coalesce'
create table t1 (primary key(a)) select "b" as b;
ERROR 42000: Key column 'a' doesn't exist in table
create table t1 (a int);
create table if not exists t1 select 1 as a, 2 as b;
ERROR 21S01: Column count doesn't match value count at row 1
drop table t1;
create table t1 (primary key (a)) (select 1 as a) union all (select 1 as a);
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
create table t1 (i int);
create table t1 select 1 as i;
ERROR 42S01: Table 't1' already exists
create table if not exists t1 select 1 as i;
Warnings:
Note 1050 Table 't1' already exists
select * from t1;
i
1
create table t1 select coalesce('a' collate latin1_swedish_ci,'b' collate latin1_bin);
ERROR HY000: Illegal mix of collations (latin1_swedish_ci,EXPLICIT) and (latin1_bin,EXPLICIT) for operation 'coalesce'
select * from t1;
i
1
alter table t1 add primary key (i);
create table if not exists t1 (select 2 as i) union all (select 2 as i);
ERROR 23000: Duplicate entry '2' for key 'PRIMARY'
select * from t1;
i
1
2
drop table t1;
create temporary table t1 (j int);
create table if not exists t1 select 1;
Warnings:
Note 1050 Table 't1' already exists
select * from t1;
j
1
drop temporary table t1;
select * from t1;
ERROR 42S02: Table 'test.t1' doesn't exist
drop table t1;
ERROR 42S02: Unknown table 't1'
create table t1 (i int);
insert into t1 values (1), (2);
lock tables t1 read;
create table t2 select * from t1;
ERROR HY000: Table 't2' was not locked with LOCK TABLES
create table if not exists t2 select * from t1;
ERROR HY000: Table 't2' was not locked with LOCK TABLES
unlock tables;
create table t2 (j int);
lock tables t1 read;
create table t2 select * from t1;
ERROR HY000: Table 't2' was not locked with LOCK TABLES
create table if not exists t2 select * from t1;
ERROR HY000: Table 't2' was not locked with LOCK TABLES
unlock tables;
lock table t1 read, t2 read;
create table t2 select * from t1;
ERROR HY000: Table 't2' was locked with a READ lock and can't be updated
create table if not exists t2 select * from t1;
ERROR HY000: Table 't2' was locked with a READ lock and can't be updated
unlock tables;
lock table t1 read, t2 write;
create table t2 select * from t1;
ERROR 42S01: Table 't2' already exists
create table if not exists t2 select * from t1;
Warnings:
Note 1050 Table 't2' already exists
select * from t1;
i
1
2
unlock tables;
drop table t2;
lock tables t1 read;
create temporary table t2 select * from t1;
create temporary table if not exists t2 select * from t1;
Warnings:
Note 1050 Table 't2' already exists
select * from t2;
i
1
2
1
2
unlock tables;
drop table t1, t2;
create table t1 (upgrade int);
drop table t1;
End of 5.0 tests
......
drop table if exists t1,t2,t3,t4,t5;
set session debug="+d,sleep_create_select_before_create";
create table t1 select 1 as i;;
create table t1 (j char(5));
ERROR 42S01: Table 't1' already exists
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(1) NOT NULL DEFAULT '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 select 1 as i;;
create table t1 select "Test" as j;
ERROR 42S01: Table 't1' already exists
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(1) NOT NULL DEFAULT '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t3 (j char(5));
create table t1 select 1 as i;;
create table t1 like t3;
ERROR 42S01: Table 't1' already exists
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(1) NOT NULL DEFAULT '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 select 1 as i;;
rename table t3 to t1;
ERROR 42S01: Table 't1' already exists
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(1) NOT NULL DEFAULT '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 select 1 as i;;
alter table t3 rename to t1;
ERROR 42S01: Table 't1' already exists
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(1) NOT NULL DEFAULT '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
create table t1 select 1 as i;;
alter table t3 rename to t1, add k int;
ERROR 42S01: Table 't1' already exists
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(1) NOT NULL DEFAULT '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1, t3;
set session debug="-d,sleep_create_select_before_create:+d,sleep_create_select_before_open";
create table t1 select 1 as i;;
drop table t1;
create table t1 select 1 as i;;
rename table t1 to t2;
drop table t2;
create table t1 select 1 as i;;
select * from t1;
i
1
drop table t1;
create table t1 select 1 as i;;
insert into t1 values (2);
select * from t1;
i
1
2
drop table t1;
set @a:=0;
create table t1 select 1 as i;;
create trigger t1_bi before insert on t1 for each row set @a:=1;
select @a;
@a
0
drop table t1;
set session debug="-d,sleep_create_select_before_open:+d,sleep_create_select_before_lock";
create table t1 select 1 as i;;
drop table t1;
create table t1 select 1 as i;;
rename table t1 to t2;
drop table t2;
create table t1 select 1 as i;;
select * from t1;
i
1
drop table t1;
create table t1 select 1 as i;;
insert into t1 values (2);
select * from t1;
i
1
2
drop table t1;
set @a:=0;
create table t1 select 1 as i;;
create trigger t1_bi before insert on t1 for each row set @a:=1;
select @a;
@a
0
drop table t1;
set session debug="-d,sleep_create_select_before_lock:+d,sleep_create_select_before_check_if_exists";
create table t1 (i int);
create table if not exists t1 select 1 as i;;
drop table t1;
Warnings:
Note 1050 Table 't1' already exists
create table t1 (i int);
set @a:=0;
create table if not exists t1 select 1 as i;;
create trigger t1_bi before insert on t1 for each row set @a:=1;
Warnings:
Note 1050 Table 't1' already exists
select @a;
@a
0
select * from t1;
i
1
drop table t1;
set session debug="-d,sleep_create_select_before_check_if_exists";
create table t2 (a int);
create table t4 (b int);
lock table t4 write;
select 1;
1
1
create table t3 as select * from t4;;
create table t1 select * from t2, t3;;
unlock tables;
select * from t1;
a b
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1, t3;
lock table t4 read;
select 1;
1
1
rename table t4 to t3;;
create table if not exists t1 select 1 as i from t2, t3;;
create table t5 (j int);
rename table t5 to t1;
unlock tables;
Warnings:
Note 1050 Table 't1' already exists
select * from t1;
j
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`j` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1, t2, t3;
......@@ -785,4 +785,15 @@ k a c
11 15 1
12 20 1
drop table t2;
drop table if exists t1, t2;
create table t1 (i int);
alter table t1 modify i int default 1;
alter table t1 modify i int default 2, rename t2;
lock table t2 write;
alter table t2 modify i int default 3;
unlock tables;
lock table t2 write;
alter table t2 modify i int default 4, rename t1;
unlock tables;
drop table t1;
End of 5.1 tests
......@@ -384,3 +384,119 @@ id data
8 140
9 150
drop table t1;
DROP TABLE IF EXISTS t1;
DROP FUNCTION IF EXISTS f1;
DROP FUNCTION IF EXISTS f2;
CREATE TABLE t1 (i INT);
CREATE FUNCTION f1() RETURNS INT
BEGIN
INSERT INTO t1 VALUES (1);
RETURN 1;
END |
CREATE FUNCTION f2() RETURNS INT
BEGIN
INSERT DELAYED INTO t1 VALUES (2);
RETURN 1;
END |
SELECT f1();
f1()
1
SELECT f2();
f2()
1
INSERT INTO t1 VALUES (3);
INSERT DELAYED INTO t1 VALUES (4);
INSERT INTO t1 VALUES (f1());
ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
INSERT DELAYED INTO t1 VALUES (f1());
ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
INSERT INTO t1 VALUES (f2());
ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
INSERT DELAYED INTO t1 VALUES (f2());
ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
INSERT INTO t1 VALUES (NEW.i);
INSERT INTO t1 VALUES (1);
ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
INSERT DELAYED INTO t1 VALUES (1);
ERROR HY000: Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
SELECT * FROM t1;
i
1
2
3
4
DROP FUNCTION f2;
DROP FUNCTION f1;
DROP TABLE t1;
DROP TABLE IF EXISTS t1, t2;
CREATE TABLE t1 (i INT);
CREATE TABLE t2 (i INT);
CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
INSERT DELAYED INTO t2 VALUES (NEW.i);
CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW
INSERT DELAYED INTO t2 VALUES (NEW.i);
CREATE TRIGGER t1_bd BEFORE DELETE ON t1 FOR EACH ROW
INSERT DELAYED INTO t2 VALUES (OLD.i);
INSERT INTO t1 VALUES (1);
INSERT DELAYED INTO t1 VALUES (2);
SELECT * FROM t1;
i
1
2
UPDATE t1 SET i = 3 WHERE i = 1;
SELECT * FROM t1;
i
3
2
DELETE FROM t1 WHERE i = 3;
SELECT * FROM t1;
i
2
SELECT * FROM t2;
i
1
2
3
3
DROP TABLE t1, t2;
DROP TABLE IF EXISTS t1, t2;
CREATE TABLE t1 (i INT);
CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
SET @a= NEW.i;
SET @a= 0;
INSERT DELAYED INTO t1 VALUES (1);
SELECT @a;
@a
1
INSERT DELAYED INTO t1 VALUES (2);
SELECT @a;
@a
2
DROP TABLE t1;
CREATE TABLE t1 (i INT);
CREATE TABLE t2 (i INT);
CREATE TRIGGER t1_ai AFTER INSERT ON t1 FOR EACH ROW
INSERT INTO t2 VALUES (NEW.i);
CREATE TRIGGER t1_au AFTER UPDATE ON t1 FOR EACH ROW
INSERT DELAYED INTO t2 VALUES (NEW.i);
CREATE TRIGGER t1_ad AFTER DELETE ON t1 FOR EACH ROW
INSERT DELAYED INTO t2 VALUES (OLD.i);
INSERT DELAYED INTO t1 VALUES (1);
SELECT * FROM t1;
i
1
UPDATE t1 SET i = 2 WHERE i = 1;
SELECT * FROM t1;
i
2
DELETE FROM t1 WHERE i = 2;
SELECT * FROM t1;
i
SELECT * FROM t2;
i
1
2
2
DROP TABLE t1, t2;
End of 5.0 tests.
......@@ -26,11 +26,11 @@ ERROR HY000: Unknown prepared statement handler (no_such_statement) given to DEA
execute stmt1;
ERROR HY000: Incorrect arguments to EXECUTE
prepare stmt2 from 'prepare nested_stmt from "select 1"';
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"select 1"' at line 1
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt2 from 'execute stmt1';
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'stmt1' at line 1
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt2 from 'deallocate prepare z';
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'z' at line 1
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt3 from 'insert into t1 values (?,?)';
set @arg1=5, @arg2='five';
execute stmt3 using @arg1, @arg2;
......
......@@ -373,11 +373,11 @@ drop table t5 ;
deallocate prepare stmt_do ;
deallocate prepare stmt_set ;
prepare stmt1 from ' prepare stmt2 from '' select 1 '' ' ;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' select 1 '' at line 1
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt1 from ' execute stmt2 ' ;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'stmt2' at line 1
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt1 from ' deallocate prepare never_prepared ' ;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'never_prepared' at line 1
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt4 from ' use test ' ;
ERROR HY000: This command is not supported in the prepared statement protocol yet
prepare stmt3 from ' create database mysqltest ';
......
......@@ -1343,3 +1343,97 @@ c1
100
drop table t1;
set global query_cache_size=0;
create table t1 (a int);
insert into t1 values (1),(2),(3);
set GLOBAL query_cache_type=1;
set GLOBAL query_cache_limit=10000;
set GLOBAL query_cache_min_res_unit=0;
set GLOBAL query_cache_size= 100000;
reset query cache;
set LOCAL default_week_format = 0;
select week('2007-01-04');
week('2007-01-04')
0
select week('2007-01-04') from t1;
week('2007-01-04')
0
0
0
select extract(WEEK FROM '2007-01-04') from t1;
extract(WEEK FROM '2007-01-04')
0
0
0
set LOCAL default_week_format = 2;
select week('2007-01-04');
week('2007-01-04')
53
select week('2007-01-04') from t1;
week('2007-01-04')
53
53
53
select extract(WEEK FROM '2007-01-04') from t1;
extract(WEEK FROM '2007-01-04')
53
53
53
reset query cache;
set LOCAL div_precision_increment=2;
select 1/7;
1/7
0.14
select 1/7 from t1;
1/7
0.14
0.14
0.14
set LOCAL div_precision_increment=4;
select 1/7;
1/7
0.1429
select 1/7 from t1;
1/7
0.1429
0.1429
0.1429
drop table t1;
CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b));
INSERT INTO t1 VALUES('MySQL has now support', 'for full-text search'),
('Full-text indexes', 'are called collections'),
('Only MyISAM tables','support collections'),
('Function MATCH ... AGAINST()','is used to do a search'),
('Full-text search in MySQL', 'implements vector space model');
set GLOBAL ft_boolean_syntax='+ -><()~*:""&|';
select *, MATCH(a,b) AGAINST("+called +collections" IN BOOLEAN MODE) as x from t1;
a b x
MySQL has now support for full-text search 0
Full-text indexes are called collections 1
Only MyISAM tables support collections 0
Function MATCH ... AGAINST() is used to do a search 0
Full-text search in MySQL implements vector space model 0
set GLOBAL ft_boolean_syntax='- +><()~*:""&|';
select *, MATCH(a,b) AGAINST("+called +collections" IN BOOLEAN MODE) as x from t1;
a b x
MySQL has now support for full-text search 0
Full-text indexes are called collections 0
Only MyISAM tables support collections 0
Function MATCH ... AGAINST() is used to do a search 0
Full-text search in MySQL implements vector space model 0
create function change_global() returns integer deterministic
begin
set global ft_boolean_syntax='+ -><()~*:""&|';
return 1;
end|
select *, change_global() from t1;
a b change_global()
MySQL has now support for full-text search 1
Full-text indexes are called collections 1
Only MyISAM tables support collections 1
Function MATCH ... AGAINST() is used to do a search 1
Full-text search in MySQL implements vector space model 1
drop function change_global;
set GLOBAL query_cache_type=default;
set GLOBAL query_cache_limit=default;
set GLOBAL query_cache_min_res_unit=default;
set GLOBAL query_cache_size= default;
......@@ -620,6 +620,119 @@ SHOW PROCEDURE CODE p1;
Pos Instruction
0 stmt 2 "CREATE INDEX idx ON t1 (c1)"
DROP PROCEDURE p1;
drop table if exists t1;
drop procedure if exists proc_26977_broken;
drop procedure if exists proc_26977_works;
create table t1(a int unique);
create procedure proc_26977_broken(v int)
begin
declare i int default 5;
declare continue handler for sqlexception
begin
select 'caught something';
retry:
while i > 0 do
begin
set i = i - 1;
select 'looping', i;
end;
end while retry;
end;
select 'do something';
insert into t1 values (v);
select 'do something again';
insert into t1 values (v);
end//
create procedure proc_26977_works(v int)
begin
declare i int default 5;
declare continue handler for sqlexception
begin
select 'caught something';
retry:
while i > 0 do
begin
set i = i - 1;
select 'looping', i;
end;
end while retry;
select 'optimizer: keep hreturn';
end;
select 'do something';
insert into t1 values (v);
select 'do something again';
insert into t1 values (v);
end//
show procedure code proc_26977_broken;
Pos Instruction
0 set i@1 5
1 hpush_jump 8 2 CONTINUE
2 stmt 0 "select 'caught something'"
3 jump_if_not 7(7) (i@1 > 0)
4 set i@1 (i@1 - 1)
5 stmt 0 "select 'looping', i"
6 jump 3
7 hreturn 2
8 stmt 0 "select 'do something'"
9 stmt 5 "insert into t1 values (v)"
10 stmt 0 "select 'do something again'"
11 stmt 5 "insert into t1 values (v)"
12 hpop 1
show procedure code proc_26977_works;
Pos Instruction
0 set i@1 5
1 hpush_jump 9 2 CONTINUE
2 stmt 0 "select 'caught something'"
3 jump_if_not 7(7) (i@1 > 0)
4 set i@1 (i@1 - 1)
5 stmt 0 "select 'looping', i"
6 jump 3
7 stmt 0 "select 'optimizer: keep hreturn'"
8 hreturn 2
9 stmt 0 "select 'do something'"
10 stmt 5 "insert into t1 values (v)"
11 stmt 0 "select 'do something again'"
12 stmt 5 "insert into t1 values (v)"
13 hpop 1
call proc_26977_broken(1);
do something
do something
do something again
do something again
caught something
caught something
looping i
looping 4
looping i
looping 3
looping i
looping 2
looping i
looping 1
looping i
looping 0
call proc_26977_works(2);
do something
do something
do something again
do something again
caught something
caught something
looping i
looping 4
looping i
looping 3
looping i
looping 2
looping i
looping 1
looping i
looping 0
optimizer: keep hreturn
optimizer: keep hreturn
drop table t1;
drop procedure proc_26977_broken;
drop procedure proc_26977_works;
End of 5.0 tests.
CREATE PROCEDURE p1()
BEGIN
......
......@@ -6210,6 +6210,13 @@ Warning 1265 Data truncated for column 'bug5274_f1' at row 1
Warning 1265 Data truncated for column 'bug5274_f1' at row 1
DROP FUNCTION bug5274_f1|
DROP FUNCTION bug5274_f2|
drop procedure if exists proc_21513|
create procedure proc_21513()`my_label`:BEGIN END|
show create procedure proc_21513|
Procedure sql_mode Create Procedure
proc_21513 CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_21513`()
`my_label`:BEGIN END
drop procedure proc_21513|
End of 5.0 tests.
drop table t1,t2;
CREATE TABLE t1 (a int auto_increment primary key) engine=MyISAM;
......
......@@ -1414,4 +1414,39 @@ id val
DROP TRIGGER trg27006_a_insert;
DROP TRIGGER trg27006_a_update;
drop table t1,t2;
drop table if exists t1, t2, t3;
create table t1 (i int);
create trigger t1_bi before insert on t1 for each row set new.i = 7;
create trigger t1_ai after insert on t1 for each row set @a := 7;
create table t2 (j int);
insert into t2 values (1), (2);
set @a:="";
create table if not exists t1 select * from t2;
Warnings:
Note 1050 Table 't1' already exists
select * from t1;
i
7
7
select @a;
@a
7
drop trigger t1_bi;
drop trigger t1_ai;
create table t3 (isave int);
create trigger t1_bi before insert on t1 for each row insert into t3 values (new.i);
create table if not exists t1 select * from t2;
Warnings:
Note 1050 Table 't1' already exists
select * from t1;
i
7
7
1
2
select * from t3;
isave
1
2
drop table t1, t2, t3;
End of 5.0 tests
......@@ -673,6 +673,117 @@ alter table t1 max_rows=100000000000;
show create table t1;
drop table t1;
#
# Tests for errors happening at various stages of CREATE TABLES ... SELECT
#
# (Also checks that it behaves atomically in the sense that in case
# of error it is automatically dropped if it has not existed before.)
#
# Error during open_and_lock_tables() of tables
--error ER_NO_SUCH_TABLE
create table t1 select * from t2;
# Rather special error which also caught during open tables pahse
--error ER_UPDATE_TABLE_USED
create table t1 select * from t1;
# Error which happens before select_create::prepare()
--error ER_CANT_AGGREGATE_2COLLATIONS
create table t1 select coalesce('a' collate latin1_swedish_ci,'b' collate latin1_bin);
# Error during table creation
--error ER_KEY_COLUMN_DOES_NOT_EXITS
create table t1 (primary key(a)) select "b" as b;
# Error in select_create::prepare() which is not related to table creation
create table t1 (a int);
--error ER_WRONG_VALUE_COUNT_ON_ROW
create table if not exists t1 select 1 as a, 2 as b;
drop table t1;
# Finally error which happens during insert
--error ER_DUP_ENTRY_WITH_KEY_NAME
create table t1 (primary key (a)) (select 1 as a) union all (select 1 as a);
# What happens if table already exists ?
create table t1 (i int);
--error ER_TABLE_EXISTS_ERROR
create table t1 select 1 as i;
create table if not exists t1 select 1 as i;
select * from t1;
# Error before select_create::prepare()
--error ER_CANT_AGGREGATE_2COLLATIONS
create table t1 select coalesce('a' collate latin1_swedish_ci,'b' collate latin1_bin);
select * from t1;
# Error which happens during insertion of rows
alter table t1 add primary key (i);
--error ER_DUP_ENTRY_WITH_KEY_NAME
create table if not exists t1 (select 2 as i) union all (select 2 as i);
select * from t1;
drop table t1;
# Base vs temporary tables dillema (a.k.a. bug#24508 "Inconsistent
# results of CREATE TABLE ... SELECT when temporary table exists").
# In this situation we either have to create non-temporary table and
# insert data in it or insert data in temporary table without creation
# of permanent table. Since currently temporary tables always shadow
# permanent tables we adopt second approach.
create temporary table t1 (j int);
create table if not exists t1 select 1;
select * from t1;
drop temporary table t1;
--error ER_NO_SUCH_TABLE
select * from t1;
--error ER_BAD_TABLE_ERROR
drop table t1;
#
# CREATE TABLE ... SELECT and LOCK TABLES
#
# There is little sense in using CREATE TABLE ... SELECT under
# LOCK TABLES as it mostly does not work. At least we check that
# the server doesn't crash, hang and produces sensible errors.
# Includes test for bug #20662 "Infinite loop in CREATE TABLE
# IF NOT EXISTS ... SELECT with locked tables".
create table t1 (i int);
insert into t1 values (1), (2);
lock tables t1 read;
--error ER_TABLE_NOT_LOCKED
create table t2 select * from t1;
--error ER_TABLE_NOT_LOCKED
create table if not exists t2 select * from t1;
unlock tables;
create table t2 (j int);
lock tables t1 read;
--error ER_TABLE_NOT_LOCKED
create table t2 select * from t1;
# This should not be ever allowed as it will undermine
# lock-all-at-once approach
--error ER_TABLE_NOT_LOCKED
create table if not exists t2 select * from t1;
unlock tables;
lock table t1 read, t2 read;
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
create table t2 select * from t1;
--error ER_TABLE_NOT_LOCKED_FOR_WRITE
create table if not exists t2 select * from t1;
unlock tables;
lock table t1 read, t2 write;
--error ER_TABLE_EXISTS_ERROR
create table t2 select * from t1;
# This is the only case which really works.
create table if not exists t2 select * from t1;
select * from t1;
unlock tables;
drop table t2;
# OTOH CREATE TEMPORARY TABLE ... SELECT should work
# well under LOCK TABLES.
lock tables t1 read;
create temporary table t2 select * from t1;
create temporary table if not exists t2 select * from t1;
select * from t2;
unlock tables;
drop table t1, t2;
#
# Bug#21772: can not name a column 'upgrade' when create a table
#
......@@ -715,6 +826,7 @@ INSERT INTO t2 select * from t1;
SELECT * from t2;
drop table t1,t2;
#
# Test incorrect database names
#
......
# Tests for various aspects of CREATE TABLE ... SELECT implementation
#
# Note that we don't test general CREATE TABLE ... SELECT functionality here as
# it is already covered by create.test. We are more interested in extreme cases.
#
# This test takes rather long time so let us run it only in --big-test mode
--source include/big_test.inc
# We are using some debug-only features in this test
--source include/have_debug.inc
# Create auxilliary connections
connect (addconroot1, localhost, root,,);
connect (addconroot2, localhost, root,,);
connect (addconroot3, localhost, root,,);
connection default;
--disable_warnings
drop table if exists t1,t2,t3,t4,t5;
--enable_warnings
#
# Tests for concurrency problems.
#
# We introduce delays between various stages of table creation
# and check that other statements dealing with this table cannot
# interfere during those delays.
#
# What happens in situation when other statement messes with
# table to be created before it is created ?
# Concurrent CREATE TABLE
set session debug="+d,sleep_create_select_before_create";
--send create table t1 select 1 as i;
connection addconroot1;
--sleep 2
--error ER_TABLE_EXISTS_ERROR
create table t1 (j char(5));
connection default;
--reap
show create table t1;
drop table t1;
# Concurrent CREATE TABLE ... SELECT
--send create table t1 select 1 as i;
connection addconroot1;
--sleep 2
--error ER_TABLE_EXISTS_ERROR
create table t1 select "Test" as j;
connection default;
--reap
show create table t1;
drop table t1;
# Concurrent CREATE TABLE LIKE
create table t3 (j char(5));
--send create table t1 select 1 as i;
connection addconroot1;
--sleep 2
--error ER_TABLE_EXISTS_ERROR
create table t1 like t3;
connection default;
--reap
show create table t1;
drop table t1;
# Concurrent RENAME TABLE
--send create table t1 select 1 as i;
connection addconroot1;
--sleep 2
--error ER_TABLE_EXISTS_ERROR
rename table t3 to t1;
connection default;
--reap
show create table t1;
drop table t1;
# Concurrent ALTER TABLE RENAME
--send create table t1 select 1 as i;
connection addconroot1;
--sleep 2
--error ER_TABLE_EXISTS_ERROR
alter table t3 rename to t1;
connection default;
--reap
show create table t1;
drop table t1;
# Concurrent ALTER TABLE RENAME which also adds column
--send create table t1 select 1 as i;
connection addconroot1;
--sleep 2
--error ER_TABLE_EXISTS_ERROR
alter table t3 rename to t1, add k int;
connection default;
--reap
show create table t1;
drop table t1, t3;
# What happens if other statement sneaks in after the table
# creation but before its opening ?
set session debug="-d,sleep_create_select_before_create:+d,sleep_create_select_before_open";
# Concurrent DROP TABLE
--send create table t1 select 1 as i;
connection addconroot1;
--sleep 2
drop table t1;
connection default;
--reap
# Concurrent RENAME TABLE
--send create table t1 select 1 as i;
connection addconroot1;
--sleep 2
rename table t1 to t2;
connection default;
--reap
drop table t2;
# Concurrent SELECT
--send create table t1 select 1 as i;
connection addconroot1;
--sleep 2
select * from t1;
connection default;
--reap
drop table t1;
# Concurrent INSERT
--send create table t1 select 1 as i;
connection addconroot1;
--sleep 2
insert into t1 values (2);
connection default;
--reap
select * from t1;
drop table t1;
# Concurrent CREATE TRIGGER
set @a:=0;
--send create table t1 select 1 as i;
connection addconroot1;
--sleep 2
create trigger t1_bi before insert on t1 for each row set @a:=1;
connection default;
--reap
select @a;
drop table t1;
# Okay, now the same tests for the potential gap between open and lock
set session debug="-d,sleep_create_select_before_open:+d,sleep_create_select_before_lock";
# Concurrent DROP TABLE
--send create table t1 select 1 as i;
connection addconroot1;
--sleep 2
drop table t1;
connection default;
--reap
# Concurrent RENAME TABLE
--send create table t1 select 1 as i;
connection addconroot1;
--sleep 2
rename table t1 to t2;
connection default;
--reap
drop table t2;
# Concurrent SELECT
--send create table t1 select 1 as i;
connection addconroot1;
--sleep 2
select * from t1;
connection default;
--reap
drop table t1;
# Concurrent INSERT
--send create table t1 select 1 as i;
connection addconroot1;
--sleep 2
insert into t1 values (2);
connection default;
--reap
select * from t1;
drop table t1;
# Concurrent CREATE TRIGGER
set @a:=0;
--send create table t1 select 1 as i;
connection addconroot1;
--sleep 2
create trigger t1_bi before insert on t1 for each row set @a:=1;
connection default;
--reap
select @a;
drop table t1;
# Some tests for case with existing table
set session debug="-d,sleep_create_select_before_lock:+d,sleep_create_select_before_check_if_exists";
create table t1 (i int);
# Concurrent DROP TABLE
--send create table if not exists t1 select 1 as i;
connection addconroot1;
--sleep 2
drop table t1;
connection default;
--reap
# Concurrent CREATE TRIGGER
create table t1 (i int);
set @a:=0;
--send create table if not exists t1 select 1 as i;
connection addconroot1;
--sleep 2
create trigger t1_bi before insert on t1 for each row set @a:=1;
connection default;
--reap
select @a;
select * from t1;
drop table t1;
set session debug="-d,sleep_create_select_before_check_if_exists";
# Test for some details of CREATE TABLE ... SELECT implementation.
#
# We check that create placeholder is handled properly if we have
# to reopen tables in open_tables().
# This test heavily relies on current implementation of name-locking/
# table cache so it may stop working if it changes. OTOH it such problem
# will serve as warning that such changes should not be done lightly.
create table t2 (a int);
create table t4 (b int);
connection addconroot2;
lock table t4 write;
select 1;
connection addconroot1;
# Create placeholder/name-lock for t3
--send create table t3 as select * from t4;
--sleep 2
connection default;
# This statement creates placeholder for t1, then opens t2,
# then meets name-lock for t3 and then reopens all tables
--send create table t1 select * from t2, t3;
--sleep 2
connection addconroot2;
unlock tables;
connection addconroot1;
--reap
connection default;
--reap
select * from t1;
show create table t1;
drop table t1, t3;
# Now similar test which proves that we really temporarily
# remove placeholder when we reopen tables.
connection addconroot2;
lock table t4 read;
select 1;
connection addconroot1;
# Create name-lock for t3
--send rename table t4 to t3;
--sleep 2
connection default;
# This statement creates placeholder for t1, then opens t2,
# then meets name-lock for t3 and then reopens all tables
--send create table if not exists t1 select 1 as i from t2, t3;
--sleep 2
connection addconroot3;
# We should be able to take name-lock on table t1 as we should not have
# open placeholder for it at this point (otherwise it is possible to
# come-up with situation which will lead to deadlock, e.g. think of
# concurrent CREATE TABLE t1 SELECT * FROM t2 and RENAME TABLE t2 TO t1)
create table t5 (j int);
# This statement takes name-lock on t1 and therefore proves
# that there is no active open placeholder for it.
rename table t5 to t1;
connection addconroot2;
unlock tables;
connection addconroot1;
--reap
connection default;
--reap
select * from t1;
show create table t1;
drop table t1, t2, t3;
......@@ -11,7 +11,9 @@
##############################################################################
user_limits : Bug#23921 random failure of user_limits.test
im_options : Bug#20294 2006-07-24 stewart Instance manager test im_options fails randomly
im_options : Bug#20294 2006-07-24 stewart Instance manager test im_options fails randomly
im_daemon_life_cycle : Bug#20294 2007-05-14 alik Instance manager tests fail randomly
im_cmd_line : Bug#20294 2007-05-14 alik Instance manager tests fail randomly
im_life_cycle : BUG#27851 Instance manager dies on ASSERT in ~Thread_registry() or from not being able to close a mysqld instance.
concurrent_innodb : BUG#21579 2006-08-11 mleich innodb_concurrent random failures with varying differences
ndb_autodiscover : BUG#18952 2006-02-16 jmiller Needs to be fixed w.r.t binlog
......
......@@ -250,3 +250,142 @@ insert ignore into t1 values(NULL,130),(NULL,140),(500,110),(550,120),(450,100),
select * from t1 order by id;
drop table t1;
#
# BUG#21483: Server abort or deadlock on INSERT DELAYED with another
# implicit insert
#
# The solution is to downgrade INSERT DELAYED to normal INSERT if the
# statement uses functions and access tables or triggers, or is called
# from a function or a trigger.
#
--disable_warnings
DROP TABLE IF EXISTS t1;
DROP FUNCTION IF EXISTS f1;
DROP FUNCTION IF EXISTS f2;
--enable_warnings
CREATE TABLE t1 (i INT);
delimiter |;
CREATE FUNCTION f1() RETURNS INT
BEGIN
INSERT INTO t1 VALUES (1);
RETURN 1;
END |
CREATE FUNCTION f2() RETURNS INT
BEGIN
INSERT DELAYED INTO t1 VALUES (2);
RETURN 1;
END |
delimiter ;|
SELECT f1();
SELECT f2();
INSERT INTO t1 VALUES (3);
INSERT DELAYED INTO t1 VALUES (4);
--error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG
INSERT INTO t1 VALUES (f1());
--error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG
INSERT DELAYED INTO t1 VALUES (f1());
--error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG
INSERT INTO t1 VALUES (f2());
--error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG
INSERT DELAYED INTO t1 VALUES (f2());
CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
INSERT INTO t1 VALUES (NEW.i);
--error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG
INSERT INTO t1 VALUES (1);
--error ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG
INSERT DELAYED INTO t1 VALUES (1);
SELECT * FROM t1;
DROP FUNCTION f2;
DROP FUNCTION f1;
DROP TABLE t1;
#
# BUG#20497: Trigger with INSERT DELAYED causes Error 1165
#
# Fixed by the patch for Bug#21483
#
--disable_warnings
DROP TABLE IF EXISTS t1, t2;
--enable_warnings
CREATE TABLE t1 (i INT);
CREATE TABLE t2 (i INT);
CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
INSERT DELAYED INTO t2 VALUES (NEW.i);
CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 FOR EACH ROW
INSERT DELAYED INTO t2 VALUES (NEW.i);
CREATE TRIGGER t1_bd BEFORE DELETE ON t1 FOR EACH ROW
INSERT DELAYED INTO t2 VALUES (OLD.i);
INSERT INTO t1 VALUES (1);
INSERT DELAYED INTO t1 VALUES (2);
SELECT * FROM t1;
UPDATE t1 SET i = 3 WHERE i = 1;
SELECT * FROM t1;
DELETE FROM t1 WHERE i = 3;
SELECT * FROM t1;
SELECT * FROM t2;
DROP TABLE t1, t2;
#
# BUG#21714: Wrong NEW.value and server abort on INSERT DELAYED to a
# table with a trigger
#
# Fixed by the patch for Bug#21483
#
--disable_warnings
DROP TABLE IF EXISTS t1, t2;
--enable_warnings
CREATE TABLE t1 (i INT);
CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
SET @a= NEW.i;
SET @a= 0;
INSERT DELAYED INTO t1 VALUES (1);
SELECT @a;
INSERT DELAYED INTO t1 VALUES (2);
SELECT @a;
DROP TABLE t1;
CREATE TABLE t1 (i INT);
CREATE TABLE t2 (i INT);
CREATE TRIGGER t1_ai AFTER INSERT ON t1 FOR EACH ROW
INSERT INTO t2 VALUES (NEW.i);
CREATE TRIGGER t1_au AFTER UPDATE ON t1 FOR EACH ROW
INSERT DELAYED INTO t2 VALUES (NEW.i);
CREATE TRIGGER t1_ad AFTER DELETE ON t1 FOR EACH ROW
INSERT DELAYED INTO t2 VALUES (OLD.i);
INSERT DELAYED INTO t1 VALUES (1);
SELECT * FROM t1;
UPDATE t1 SET i = 2 WHERE i = 1;
SELECT * FROM t1;
DELETE FROM t1 WHERE i = 2;
SELECT * FROM t1;
SELECT * FROM t2;
DROP TABLE t1, t2;
--echo End of 5.0 tests.
......@@ -34,13 +34,13 @@ deallocate prepare no_such_statement;
execute stmt1;
# Nesting ps commands is not allowed:
--error 1064
--error ER_UNSUPPORTED_PS
prepare stmt2 from 'prepare nested_stmt from "select 1"';
--error 1064
--error ER_UNSUPPORTED_PS
prepare stmt2 from 'execute stmt1';
--error 1064
--error ER_UNSUPPORTED_PS
prepare stmt2 from 'deallocate prepare z';
# PS insert
......
......@@ -407,11 +407,11 @@ deallocate prepare stmt_do ;
deallocate prepare stmt_set ;
## nonsense like prepare of prepare,execute or deallocate
--error 1064
--error ER_UNSUPPORTED_PS
prepare stmt1 from ' prepare stmt2 from '' select 1 '' ' ;
--error 1064
--error ER_UNSUPPORTED_PS
prepare stmt1 from ' execute stmt2 ' ;
--error 1064
--error ER_UNSUPPORTED_PS
prepare stmt1 from ' deallocate prepare never_prepared ' ;
## switch the database connection
......
......@@ -928,3 +928,75 @@ select * from t1;
drop table t1;
set global query_cache_size=0;
#
# Query cache and changes to system variables
#
create table t1 (a int);
insert into t1 values (1),(2),(3);
set GLOBAL query_cache_type=1;
set GLOBAL query_cache_limit=10000;
set GLOBAL query_cache_min_res_unit=0;
set GLOBAL query_cache_size= 100000;
# default_week_format
reset query cache;
set LOCAL default_week_format = 0;
select week('2007-01-04');
select week('2007-01-04') from t1;
select extract(WEEK FROM '2007-01-04') from t1;
set LOCAL default_week_format = 2;
select week('2007-01-04');
select week('2007-01-04') from t1;
select extract(WEEK FROM '2007-01-04') from t1;
# div_precision_increment
reset query cache;
set LOCAL div_precision_increment=2;
select 1/7;
select 1/7 from t1;
set LOCAL div_precision_increment=4;
select 1/7;
select 1/7 from t1;
drop table t1;
CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b));
INSERT INTO t1 VALUES('MySQL has now support', 'for full-text search'),
('Full-text indexes', 'are called collections'),
('Only MyISAM tables','support collections'),
('Function MATCH ... AGAINST()','is used to do a search'),
('Full-text search in MySQL', 'implements vector space model');
set GLOBAL ft_boolean_syntax='+ -><()~*:""&|';
select *, MATCH(a,b) AGAINST("+called +collections" IN BOOLEAN MODE) as x from t1;
# swap +/-
set GLOBAL ft_boolean_syntax='- +><()~*:""&|';
select *, MATCH(a,b) AGAINST("+called +collections" IN BOOLEAN MODE) as x from t1;
# If in the future we need to cache queries with functions
# be sure not to cause dead lock if the query cache is flushed
# while inserting a query in the query cache.
delimiter |;
create function change_global() returns integer deterministic
begin
set global ft_boolean_syntax='+ -><()~*:""&|';
return 1;
end|
delimiter ;|
select *, change_global() from t1;
drop function change_global;
set GLOBAL query_cache_type=default;
set GLOBAL query_cache_limit=default;
set GLOBAL query_cache_min_res_unit=default;
set GLOBAL query_cache_size= default;
# End of 5.0 tests
......@@ -446,6 +446,81 @@ SHOW PROCEDURE CODE p1;
DROP PROCEDURE p1;
#
# Bug#26977 exception handlers never hreturn
#
--disable_warnings
drop table if exists t1;
drop procedure if exists proc_26977_broken;
drop procedure if exists proc_26977_works;
--enable_warnings
create table t1(a int unique);
delimiter //;
create procedure proc_26977_broken(v int)
begin
declare i int default 5;
declare continue handler for sqlexception
begin
select 'caught something';
retry:
while i > 0 do
begin
set i = i - 1;
select 'looping', i;
end;
end while retry;
end;
select 'do something';
insert into t1 values (v);
select 'do something again';
insert into t1 values (v);
end//
create procedure proc_26977_works(v int)
begin
declare i int default 5;
declare continue handler for sqlexception
begin
select 'caught something';
retry:
while i > 0 do
begin
set i = i - 1;
select 'looping', i;
end;
end while retry;
select 'optimizer: keep hreturn';
end;
select 'do something';
insert into t1 values (v);
select 'do something again';
insert into t1 values (v);
end//
delimiter ;//
show procedure code proc_26977_broken;
show procedure code proc_26977_works;
## This caust an error because of jump short cut
## optimization.
call proc_26977_broken(1);
## This works
call proc_26977_works(2);
drop table t1;
drop procedure proc_26977_broken;
drop procedure proc_26977_works;
--echo End of 5.0 tests.
#
......
......@@ -7146,6 +7146,17 @@ SELECT bug5274_f2()|
DROP FUNCTION bug5274_f1|
DROP FUNCTION bug5274_f2|
#
# Bug#21513 (SP having body starting with quoted label rendered unusable)
#
--disable_warnings
drop procedure if exists proc_21513|
--enable_warnings
create procedure proc_21513()`my_label`:BEGIN END|
show create procedure proc_21513|
drop procedure proc_21513|
###
--echo End of 5.0 tests.
......
......@@ -1737,4 +1737,30 @@ DROP TRIGGER trg27006_a_insert;
DROP TRIGGER trg27006_a_update;
drop table t1,t2;
#
# Bug #20903 "Crash when using CREATE TABLE .. SELECT and triggers"
#
--disable_warnings
drop table if exists t1, t2, t3;
--enable_warnings
create table t1 (i int);
create trigger t1_bi before insert on t1 for each row set new.i = 7;
create trigger t1_ai after insert on t1 for each row set @a := 7;
create table t2 (j int);
insert into t2 values (1), (2);
set @a:="";
create table if not exists t1 select * from t2;
select * from t1;
select @a;
# Let us check that trigger that involves table also works ok.
drop trigger t1_bi;
drop trigger t1_ai;
create table t3 (isave int);
create trigger t1_bi before insert on t1 for each row insert into t3 values (new.i);
create table if not exists t1 select * from t2;
select * from t1;
select * from t3;
drop table t1, t2, t3;
--echo End of 5.0 tests
......@@ -156,10 +156,14 @@ void
Event_parse_data::init_body(THD *thd)
{
DBUG_ENTER("Event_parse_data::init_body");
/* This method is called from within the parser, from sql_yacc.yy */
DBUG_ASSERT(thd->m_lip != NULL);
DBUG_PRINT("info", ("body: '%s' body_begin: 0x%lx end: 0x%lx", body_begin,
(long) body_begin, (long) thd->lex->ptr));
(long) body_begin, (long) thd->m_lip->ptr));
body.length= thd->lex->ptr - body_begin;
body.length= thd->m_lip->ptr - body_begin;
const char *body_end= body_begin + body.length - 1;
/* Trim nuls or close-comments ('*'+'/') or spaces at the end */
......@@ -1909,18 +1913,28 @@ Event_job_data::execute(THD *thd, bool drop)
thd->variables.sql_mode= sql_mode;
thd->variables.time_zone= time_zone;
/*
Peculiar initialization order is a clutch to avoid races in SHOW
PROCESSLIST which reads thd->{query/query_length} without a mutex.
*/
thd->query_length= 0;
thd->query= sp_sql.c_ptr_safe();
thd->query_length= sp_sql.length();
lex_start(thd, thd->query, thd->query_length);
if (MYSQLparse(thd) || thd->is_fatal_error)
{
sql_print_error("Event Scheduler: "
"%serror during compilation of %s.%s",
thd->is_fatal_error ? "fatal " : "",
(const char *) dbname.str, (const char *) name.str);
goto end;
Lex_input_stream lip(thd, thd->query, thd->query_length);
thd->m_lip= &lip;
lex_start(thd);
int err= MYSQLparse(thd);
if (err || thd->is_fatal_error)
{
sql_print_error("Event Scheduler: "
"%serror during compilation of %s.%s",
thd->is_fatal_error ? "fatal " : "",
(const char *) dbname.str, (const char *) name.str);
goto end;
}
}
{
......@@ -1959,6 +1973,11 @@ Event_job_data::execute(THD *thd, bool drop)
ret= 1;
else
{
/*
Peculiar initialization order is a clutch to avoid races in SHOW
PROCESSLIST which reads thd->{query/query_length} without a mutex.
*/
thd->query_length= 0;
thd->query= sp_sql.c_ptr_safe();
thd->query_length= sp_sql.length();
if (Events::drop_event(thd, dbname, name, FALSE))
......
......@@ -6674,7 +6674,7 @@ int ndb_create_table_from_engine(THD *thd, const char *db,
LEX *old_lex= thd->lex, newlex;
thd->lex= &newlex;
newlex.current_select= NULL;
lex_start(thd, "", 0);
lex_start(thd);
int res= ha_create_table_from_engine(thd, db, table_name);
thd->lex= old_lex;
return res;
......
......@@ -230,6 +230,7 @@ static void run_query(THD *thd, char *buf, char *end,
ulonglong save_thd_options= thd->options;
DBUG_ASSERT(sizeof(save_thd_options) == sizeof(thd->options));
NET save_net= thd->net;
const char* found_semicolon= NULL;
bzero((char*) &thd->net, sizeof(NET));
thd->query_length= end - buf;
......@@ -239,7 +240,7 @@ static void run_query(THD *thd, char *buf, char *end,
thd->options&= ~OPTION_BIN_LOG;
DBUG_PRINT("query", ("%s", thd->query));
mysql_parse(thd, thd->query, thd->query_length);
mysql_parse(thd, thd->query, thd->query_length, &found_semicolon);
if (print_error && thd->query_error)
{
......
......@@ -4731,7 +4731,6 @@ inline uint char_val(char X)
Item_hex_string::Item_hex_string(const char *str, uint str_length)
{
name=(char*) str-2; // Lex makes this start with 0x
max_length=(str_length+1)/2;
char *ptr=(char*) sql_alloc(max_length+1);
if (!ptr)
......@@ -4842,7 +4841,6 @@ Item_bin_string::Item_bin_string(const char *str, uint str_length)
uchar bits= 0;
uint power= 1;
name= (char*) str - 2;
max_length= (str_length + 7) >> 3;
char *ptr= (char*) sql_alloc(max_length + 1);
if (!ptr)
......
......@@ -4419,7 +4419,7 @@ int get_var_with_binlog(THD *thd, enum_sql_command sql_command,
List<set_var_base> tmp_var_list;
LEX *sav_lex= thd->lex, lex_tmp;
thd->lex= &lex_tmp;
lex_start(thd, NULL, 0);
lex_start(thd);
tmp_var_list.push_back(new set_var_user(new Item_func_set_user_var(name,
new Item_null())));
/* Create the variable */
......
......@@ -892,8 +892,6 @@ int lock_and_wait_for_table_name(THD *thd, TABLE_LIST *table_list)
int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use)
{
TABLE *table;
TABLE_SHARE *share;
char *key_buff;
char key[MAX_DBKEY_LENGTH];
char *db= table_list->db;
uint key_length;
......@@ -921,29 +919,11 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use)
}
}
}
/*
Create a table entry with the right key and with an old refresh version
Note that we must use my_multi_malloc() here as this is freed by the
table cache
*/
if (!my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
&table, sizeof(*table),
&share, sizeof(*share),
&key_buff, key_length,
NULL))
DBUG_RETURN(-1);
table->s= share;
share->set_table_cache_key(key_buff, key, key_length);
share->tmp_table= INTERNAL_TMP_TABLE; // for intern_close_table
table->in_use= thd;
table->locked_by_name=1;
table_list->table=table;
if (my_hash_insert(&open_cache, (byte*) table))
{
my_free((gptr) table,MYF(0));
if (!(table= table_cache_insert_placeholder(thd, key, key_length)))
DBUG_RETURN(-1);
}
table_list->table=table;
/* Return 1 if table is in use */
DBUG_RETURN(test(remove_table_from_cache(thd, db, table_list->table_name,
......
......@@ -2053,7 +2053,8 @@ int Query_log_event::do_apply_event(RELAY_LOG_INFO const *rli,
thd->variables.collation_database= thd->db_charset;
/* Execute the query (note that we bypass dispatch_command()) */
mysql_parse(thd, thd->query, thd->query_length);
const char* found_semicolon= NULL;
mysql_parse(thd, thd->query, thd->query_length, &found_semicolon);
}
else
......@@ -3224,10 +3225,12 @@ int Load_log_event::do_apply_event(NET* net, RELAY_LOG_INFO const *rli,
/* see Query_log_event::do_apply_event() and BUG#13360 */
DBUG_ASSERT(!rli->m_table_map.count());
/*
Usually mysql_init_query() is called by mysql_parse(), but we need it here
Usually lex_start() is called by mysql_parse(), but we need it here
as the present method does not call mysql_parse().
*/
mysql_init_query(thd, 0, 0);
lex_start(thd);
mysql_reset_thd_for_next_command(thd);
if (!use_rli_only_for_errors)
{
/*
......@@ -5860,7 +5863,7 @@ int Rows_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
Table_map_log_event::do_apply_event() we don't call
mysql_init_query() as that may reset the binlog format.
*/
lex_start(thd, NULL, 0);
lex_start(thd);
while ((error= lock_tables(thd, rli->tables_to_lock,
rli->tables_to_lock_count, &need_reopen)))
......@@ -6510,7 +6513,8 @@ int Table_map_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
initialized, so we should call lex_start(); to be even safer, we
call mysql_init_query() which does a more complete set of inits.
*/
mysql_init_query(thd, NULL, 0);
lex_start(thd);
mysql_reset_thd_for_next_command(thd);
/*
Check if the slave is set to use SBR. If so, it should switch
to using RBR until the end of the "statement", i.e., next
......
......@@ -652,6 +652,8 @@ struct Query_cache_query_flags
ulong sql_mode;
ulong max_sort_length;
ulong group_concat_max_len;
ulong default_week_format;
ulong div_precision_increment;
MY_LOCALE *lc_time_names;
};
#define QUERY_CACHE_FLAGS_SIZE sizeof(Query_cache_query_flags)
......@@ -787,8 +789,6 @@ check_and_unset_inject_value(int value)
#endif
uint build_table_path(char *buff, size_t bufflen, const char *db,
const char *table, const char *ext);
void write_bin_log(THD *thd, bool clear_error,
char const *query, ulong query_length);
......@@ -831,13 +831,15 @@ bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db,
bool skip_error);
bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name,
bool force_switch);
void mysql_parse(THD *thd,char *inBuf,uint length);
void mysql_parse(THD *thd, const char *inBuf, uint length,
const char ** semicolon);
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
bool is_update_query(enum enum_sql_command command);
bool alloc_query(THD *thd, const char *packet, uint packet_length);
void mysql_init_select(LEX *lex);
void mysql_reset_thd_for_next_command(THD *thd);
void mysql_init_query(THD *thd, const char *buf, uint length);
bool mysql_new_select(LEX *lex, bool move_down);
void create_select_for_variable(const char *var_name);
void mysql_init_multi_delete(LEX *lex);
......@@ -961,6 +963,12 @@ bool mysql_create_table(THD *thd,const char *db, const char *table_name,
List<create_field> &fields, List<Key> &keys,
bool tmp_table, uint select_field_count,
bool use_copy_create_info);
bool mysql_create_table_no_lock(THD *thd, const char *db,
const char *table_name,
HA_CREATE_INFO *create_info,
List<create_field> &fields, List<Key> &keys,
bool tmp_table, uint select_field_count,
bool use_copy_create_info);
bool mysql_alter_table(THD *thd, char *new_db, char *new_name,
HA_CREATE_INFO *create_info,
......@@ -1018,7 +1026,11 @@ TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update);
TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem,
bool *refresh, uint flags);
bool reopen_name_locked_table(THD* thd, TABLE_LIST* table);
bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in);
TABLE *table_cache_insert_placeholder(THD *thd, const char *key,
uint key_length);
bool lock_table_name_if_not_cached(THD *thd, const char *db,
const char *table_name, TABLE **table);
TABLE *find_locked_table(THD *thd, const char *db,const char *table_name);
bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
bool close_data_tables(THD *thd,const char *db, const char *table_name);
......@@ -1187,7 +1199,9 @@ void add_join_on(TABLE_LIST *b,Item *expr);
void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields,
SELECT_LEX *lex);
bool add_proc_to_list(THD *thd, Item *item);
TABLE *unlink_open_table(THD *thd,TABLE *list,TABLE *find);
void unlink_open_table(THD *thd, TABLE *find, bool unlock);
void drop_open_table(THD *thd, TABLE *table, const char *db_name,
const char *table_name);
void update_non_unique_table_error(TABLE_LIST *update,
const char *operation,
TABLE_LIST *duplicate);
......@@ -1622,7 +1636,7 @@ extern double log_01[32];
extern ulonglong log_10_int[20];
extern ulonglong keybuff_size;
extern ulonglong thd_startup_options;
extern ulong refresh_version, thread_id;
extern ulong thread_id;
extern ulong binlog_cache_use, binlog_cache_disk_use;
extern ulong aborted_threads,aborted_connects;
extern ulong delayed_insert_timeout;
......@@ -1761,7 +1775,7 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count,
#define MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK 0x0001
#define MYSQL_LOCK_IGNORE_FLUSH 0x0002
#define MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN 0x0004
#define MYSQL_OPEN_IGNORE_LOCKED_TABLES 0x0008
#define MYSQL_OPEN_TEMPORARY_ONLY 0x0008
void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock);
void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock);
......
......@@ -802,6 +802,11 @@ static bool sys_update_ftb_syntax(THD *thd, set_var * var)
{
strmake(ft_boolean_syntax, var->value->str_value.c_ptr(),
sizeof(ft_boolean_syntax)-1);
#ifdef HAVE_QUERY_CACHE
query_cache.flush();
#endif /* HAVE_QUERY_CACHE */
return 0;
}
......
......@@ -923,6 +923,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
handler *file;
ulonglong save_options;
NET *net= &mysql->net;
const char *found_semicolon= NULL;
DBUG_ENTER("create_table_from_dump");
packet_len= my_net_read(net); // read create table statement
......@@ -974,7 +975,7 @@ static int create_table_from_dump(THD* thd, MYSQL *mysql, const char* db,
thd->db = (char*)db;
DBUG_ASSERT(thd->db != 0);
thd->db_length= strlen(thd->db);
mysql_parse(thd, thd->query, packet_len); // run create table
mysql_parse(thd, thd->query, packet_len, &found_semicolon); // run create table
thd->db = save_db; // leave things the way the were before
thd->db_length= save_db_length;
thd->options = save_options;
......
......@@ -384,10 +384,15 @@ db_load_routine(THD *thd, int type, sp_name *name, sp_head **sphp,
if ((ret= sp_use_new_db(thd, name->m_db, &old_db, 1, &dbchanged)))
goto end;
lex_start(thd, defstr.c_ptr(), defstr.length());
{
Lex_input_stream lip(thd, defstr.c_ptr(), defstr.length());
thd->m_lip= &lip;
lex_start(thd);
ret= MYSQLparse(thd);
}
thd->spcont= 0;
if (MYSQLparse(thd) || thd->is_fatal_error || newlex.sphead == NULL)
if (ret || thd->is_fatal_error || newlex.sphead == NULL)
{
sp_head *sp= newlex.sphead;
......
......@@ -557,6 +557,7 @@ sp_head::init_strings(THD *thd, LEX *lex)
const char *endp; /* Used to trim the end */
/* During parsing, we must use thd->mem_root */
MEM_ROOT *root= thd->mem_root;
Lex_input_stream *lip=thd->m_lip;
if (m_param_begin && m_param_end)
{
......@@ -565,7 +566,7 @@ sp_head::init_strings(THD *thd, LEX *lex)
}
/* If ptr has overrun end_of_query then end_of_query is the end */
endp= (lex->ptr > lex->end_of_query ? lex->end_of_query : lex->ptr);
endp= (lip->ptr > lip->end_of_query ? lip->end_of_query : lip->ptr);
/*
Trim "garbage" at the end. This is sometimes needed with the
"/ * ! VERSION... * /" wrapper in dump files.
......@@ -574,8 +575,8 @@ sp_head::init_strings(THD *thd, LEX *lex)
m_body.length= endp - m_body_begin;
m_body.str= strmake_root(root, m_body_begin, m_body.length);
m_defstr.length= endp - lex->buf;
m_defstr.str= strmake_root(root, lex->buf, m_defstr.length);
m_defstr.length= endp - lip->buf;
m_defstr.str= strmake_root(root, lip->buf, m_defstr.length);
DBUG_VOID_RETURN;
}
......@@ -1815,25 +1816,13 @@ sp_head::reset_lex(THD *thd)
DBUG_ENTER("sp_head::reset_lex");
LEX *sublex;
LEX *oldlex= thd->lex;
my_lex_states org_next_state= oldlex->next_state;
(void)m_lex.push_front(oldlex);
thd->lex= sublex= new st_lex;
/* Reset most stuff. The length arguments doesn't matter here. */
lex_start(thd, oldlex->buf, (ulong) (oldlex->end_of_query - oldlex->ptr));
/* Reset most stuff. */
lex_start(thd);
/*
next_state is normally the same (0), but it happens that we swap lex in
"mid-sentence", so we must restore it.
*/
sublex->next_state= org_next_state;
/* We must reset ptr and end_of_query again */
sublex->ptr= oldlex->ptr;
sublex->end_of_query= oldlex->end_of_query;
sublex->tok_start= oldlex->tok_start;
sublex->tok_end= oldlex->tok_end;
sublex->yylineno= oldlex->yylineno;
/* And keep the SP stuff too */
sublex->sphead= oldlex->sphead;
sublex->spcont= oldlex->spcont;
......@@ -1866,10 +1855,6 @@ sp_head::restore_lex(THD *thd)
if (! oldlex)
return; // Nothing to restore
// Update some state in the old one first
oldlex->ptr= sublex->ptr;
oldlex->tok_end= sublex->tok_end;
oldlex->next_state= sublex->next_state;
oldlex->trg_table_fields.push_back(&sublex->trg_table_fields);
/*
......@@ -3062,10 +3047,20 @@ sp_instr_hreturn::print(String *str)
uint
sp_instr_hreturn::opt_mark(sp_head *sp, List<sp_instr> *leads)
{
if (m_dest)
return sp_instr_jump::opt_mark(sp, leads);
marked= 1;
if (m_dest)
{
/*
This is an EXIT handler; next instruction step is in m_dest.
*/
return m_dest;
}
/*
This is a CONTINUE handler; next instruction step will come from
the handler stack and not from opt_mark.
*/
return UINT_MAX;
}
......@@ -3519,6 +3514,14 @@ sp_head::merge_table_list(THD *thd, TABLE_LIST *table, LEX *lex_for_tmp_check)
tlen+= alen;
tname[tlen]= '\0';
/*
Upgrade the lock type because this table list will be used
only in pre-locked mode, in which DELAYED inserts are always
converted to normal inserts.
*/
if (table->lock_type == TL_WRITE_DELAYED)
table->lock_type= TL_WRITE;
/*
We ignore alias when we check if table was already marked as temporary
(and therefore should not be prelocked). Otherwise we will erroneously
......
......@@ -176,7 +176,9 @@ class sp_head :private Query_arena
*/
HASH m_sroutines;
// Pointers set during parsing
const char *m_param_begin, *m_param_end, *m_body_begin;
const char *m_param_begin;
const char *m_param_end;
const char *m_body_begin;
/*
Security context for stored routine which should be run under
......@@ -990,6 +992,12 @@ class sp_instr_hreturn : public sp_instr_jump
virtual void print(String *str);
/* This instruction will not be short cut optimized. */
virtual uint opt_shortcut_jump(sp_head *sp, sp_instr *start)
{
return m_ip;
}
virtual uint opt_mark(sp_head *sp, List<sp_instr> *leads);
private:
......
This diff is collapsed.
......@@ -867,10 +867,13 @@ void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
flags.max_sort_length= thd->variables.max_sort_length;
flags.lc_time_names= thd->variables.lc_time_names;
flags.group_concat_max_len= thd->variables.group_concat_max_len;
flags.div_precision_increment= thd->variables.div_precincrement;
flags.default_week_format= thd->variables.default_week_format;
DBUG_PRINT("qcache", ("\
long %d, 4.1: %d, bin_proto: %d, more results %d, pkt_nr: %d, \
CS client: %u, CS result: %u, CS conn: %u, limit: %lu, TZ: 0x%lx, \
sql mode: 0x%lx, sort len: %lu, conncat len: %lu",
sql mode: 0x%lx, sort len: %lu, conncat len: %lu, div_precision: %lu, \
def_week_frmt: %lu",
(int)flags.client_long_flag,
(int)flags.client_protocol_41,
(int)flags.result_in_binary_protocol,
......@@ -883,7 +886,9 @@ sql mode: 0x%lx, sort len: %lu, conncat len: %lu",
(ulong) flags.time_zone,
flags.sql_mode,
flags.max_sort_length,
flags.group_concat_max_len));
flags.group_concat_max_len,
flags.div_precision_increment,
flags.default_week_format));
/*
Make InnoDB to release the adaptive hash index latch before
acquiring the query cache mutex.
......@@ -1112,11 +1117,14 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
flags.sql_mode= thd->variables.sql_mode;
flags.max_sort_length= thd->variables.max_sort_length;
flags.group_concat_max_len= thd->variables.group_concat_max_len;
flags.div_precision_increment= thd->variables.div_precincrement;
flags.default_week_format= thd->variables.default_week_format;
flags.lc_time_names= thd->variables.lc_time_names;
DBUG_PRINT("qcache", ("\
long %d, 4.1: %d, bin_proto: %d, more results %d, pkt_nr: %d, \
CS client: %u, CS result: %u, CS conn: %u, limit: %lu, TZ: 0x%lx, \
sql mode: 0x%lx, sort len: %lu, conncat len: %lu",
sql mode: 0x%lx, sort len: %lu, conncat len: %lu, div_precision: %lu, \
def_week_frmt: %lu",
(int)flags.client_long_flag,
(int)flags.client_protocol_41,
(int)flags.result_in_binary_protocol,
......@@ -1129,7 +1137,9 @@ sql mode: 0x%lx, sort len: %lu, conncat len: %lu",
(ulong) flags.time_zone,
flags.sql_mode,
flags.max_sort_length,
flags.group_concat_max_len));
flags.group_concat_max_len,
flags.div_precision_increment,
flags.default_week_format));
memcpy((void *)(sql + (tot_length - QUERY_CACHE_FLAGS_SIZE)),
&flags, QUERY_CACHE_FLAGS_SIZE);
query_block = (Query_cache_block *) hash_search(&queries, (byte*) sql,
......
......@@ -31,6 +31,7 @@ class Load_log_event;
class Slave_log_event;
class sp_rcontext;
class sp_cache;
class Lex_input_stream;
class Rows_log_event;
enum enum_enable_or_disable { LEAVE_AS_IS, ENABLE, DISABLE };
......@@ -171,7 +172,7 @@ class LEX_COLUMN : public Sql_alloc
#include "sql_lex.h" /* Must be here */
class delayed_insert;
class Delayed_insert;
class select_result;
class Time_zone;
......@@ -1013,7 +1014,7 @@ class THD :public Statement,
time_t start_time,time_after_lock,user_time;
time_t connect_time,thr_create_time; // track down slow pthread_create
thr_lock_type update_lock_default;
delayed_insert *di;
Delayed_insert *di;
/* <> 0 if we are inside of trigger or stored function. */
uint in_sub_stmt;
......@@ -1435,6 +1436,16 @@ class THD :public Statement,
*/
query_id_t first_query_id;
} binlog_evt_union;
/**
Character input stream consumed by the lexical analyser,
used during parsing.
Note that since the parser is not re-entrant, we keep only one input
stream here. This member is valid only when executing code during parsing,
and may point to invalid memory after that.
*/
Lex_input_stream *m_lip;
#ifdef WITH_PARTITION_STORAGE_ENGINE
partition_info *work_part_info;
#endif
......
......@@ -682,7 +682,7 @@ int mysql_ha_flush(THD *thd, TABLE_LIST *tables, uint mode_flags,
while (*table_ptr)
{
if ((mode_flags & MYSQL_HA_FLUSH_ALL) ||
((*table_ptr)->s->version != refresh_version))
(*table_ptr)->needs_reopen_or_name_lock())
{
/* The first time it is required, lock for close_thread_table(). */
if (! did_lock && ! is_locked)
......@@ -783,15 +783,22 @@ void mysql_ha_mark_tables_for_reopen(THD *thd, TABLE *table)
safe_mutex_assert_owner(&LOCK_open);
for (; table; table= table->next)
{
TABLE_LIST *hash_tables;
if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash,
(byte*) table->alias,
strlen(table->alias) + 1)))
/*
Some elements in open table list, for example placeholders used for
name-locking, can have alias set to 0.
*/
if (table->alias)
{
/* Mark table as ready for reopen. */
hash_tables->table= NULL;
/* End open index/table scans. */
table->file->ha_index_or_rnd_end();
TABLE_LIST *hash_tables;
if ((hash_tables= (TABLE_LIST*) hash_search(&thd->handler_tables_hash,
(byte*) table->alias,
strlen(table->alias) + 1)))
{
/* Mark table as ready for reopen. */
hash_tables->table= NULL;
/* End open index/table scans. */
table->file->ha_index_or_rnd_end();
}
}
}
DBUG_VOID_RETURN;
......
This diff is collapsed.
This diff is collapsed.
......@@ -543,7 +543,7 @@ class st_select_lex_unit: public st_select_lex_node {
void set_thd(THD *thd_arg) { thd= thd_arg; }
inline bool is_union ();
friend void lex_start(THD *thd, const char *buf, uint length);
friend void lex_start(THD *thd);
friend int subselect_union_engine::exec();
List<Item> *get_unit_column_types();
......@@ -744,7 +744,7 @@ class st_select_lex: public st_select_lex_node
void cut_subtree() { slave= 0; }
bool test_limit();
friend void lex_start(THD *thd, const char *buf, uint length);
friend void lex_start(THD *thd);
st_select_lex() : n_sum_items(0), n_child_sum_items(0) {}
void make_empty_select()
{
......@@ -971,6 +971,12 @@ class Query_tables_list
query_tables_own_last= 0;
}
}
/**
true if the parsed tree contains references to stored procedures
or functions, false otherwise
*/
bool uses_stored_routines() const
{ return sroutines_list.elements != 0; }
};
......@@ -991,23 +997,72 @@ struct st_parsing_options
};
/**
This class represents the character input stream consumed during
lexical analysis.
*/
class Lex_input_stream
{
public:
Lex_input_stream(THD *thd, const char* buff, unsigned int length);
~Lex_input_stream();
/** Current thread. */
THD *m_thd;
/** Current line number. */
uint yylineno;
/** Length of the last token parsed. */
uint yytoklen;
/** Interface with bison, value of the last token parsed. */
LEX_YYSTYPE yylval;
/** Pointer to the current position in the input stream. */
const char* ptr;
/** Starting position of the last token parsed. */
const char* tok_start;
/** Ending position of the last token parsed. */
const char* tok_end;
/** End of the query text in the input stream. */
const char* end_of_query;
/** Starting position of the previous token parsed. */
const char* tok_start_prev;
/** Begining of the query text in the input stream. */
const char* buf;
/** Current state of the lexical analyser. */
enum my_lex_states next_state;
/** Position of ';' in the stream, to delimit multiple queries. */
const char* found_semicolon;
/** SQL_MODE = IGNORE_SPACE. */
bool ignore_space;
/*
TRUE if we're parsing a prepared statement: in this mode
we should allow placeholders and disallow multi-statements.
*/
bool stmt_prepare_mode;
};
/* The state of the lex parsing. This is saved in the THD struct */
typedef struct st_lex : public Query_tables_list
{
uint yylineno,yytoklen; /* Simulate lex */
LEX_YYSTYPE yylval;
SELECT_LEX_UNIT unit; /* most upper unit */
SELECT_LEX select_lex; /* first SELECT_LEX */
/* current SELECT_LEX in parsing */
SELECT_LEX *current_select;
/* list of all SELECT_LEX */
SELECT_LEX *all_selects_list;
const char *buf; /* The beginning of string, used by SPs */
const char *ptr,*tok_start,*tok_end,*end_of_query;
/* The value of tok_start as they were one call of MYSQLlex before */
const char *tok_start_prev;
char *length,*dec,*change;
LEX_STRING name;
......@@ -1016,7 +1071,6 @@ typedef struct st_lex : public Query_tables_list
char *backup_dir; /* For RESTORE/BACKUP */
char* to_log; /* For PURGE MASTER LOGS TO */
char* x509_subject,*x509_issuer,*ssl_cipher;
char* found_semicolon; /* For multi queries - next query */
String *wild;
sql_exchange *exchange;
select_result *result;
......@@ -1105,7 +1159,6 @@ typedef struct st_lex : public Query_tables_list
thr_lock_type lock_option;
enum SSL_type ssl_type; /* defined in violite.h */
enum my_lex_states next_state;
enum enum_duplicates duplicates;
enum enum_tx_isolation tx_isolation;
enum enum_ha_read_modes ha_read_mode;
......@@ -1137,7 +1190,7 @@ typedef struct st_lex : public Query_tables_list
uint8 create_view_algorithm;
uint8 create_view_check;
bool drop_if_exists, drop_temporary, local_file, one_shot_set;
bool in_comment, ignore_space, verbose, no_write_to_binlog;
bool in_comment, verbose, no_write_to_binlog;
bool tx_chain, tx_release;
/*
Special JOIN::prepare mode: changing of query is prohibited.
......@@ -1147,11 +1200,6 @@ typedef struct st_lex : public Query_tables_list
to an .frm file. We need this definition to stay untouched.
*/
bool view_prepare_mode;
/*
TRUE if we're parsing a prepared statement: in this mode
we should allow placeholders and disallow multistatements.
*/
bool stmt_prepare_mode;
bool safe_to_cache_query;
bool subqueries, ignore;
st_parsing_options parsing_options;
......@@ -1214,7 +1262,8 @@ typedef struct st_lex : public Query_tables_list
Pointers to part of LOAD DATA statement that should be rewritten
during replication ("LOCAL 'filename' REPLACE INTO" part).
*/
const char *fname_start, *fname_end;
const char *fname_start;
const char *fname_end;
/*
Reference to a struct that contains information in various commands
......@@ -1333,7 +1382,7 @@ struct st_lex_local: public st_lex
extern void lex_init(void);
extern void lex_free(void);
extern void lex_start(THD *thd, const char *buf, uint length);
extern void lex_start(THD *thd);
extern void lex_end(LEX *lex);
extern int MYSQLlex(void *arg, void *yythd);
extern const char *skip_rear_comments(const char *ubegin, const char *uend);
......
......@@ -300,6 +300,7 @@ pthread_handler_t handle_bootstrap(void *arg)
THD *thd=(THD*) arg;
FILE *file=bootstrap_file;
char *buff;
const char* found_semicolon= NULL;
/* The following must be called before DBUG_ENTER */
thd->thread_stack= (char*) &thd;
......@@ -380,7 +381,7 @@ pthread_handler_t handle_bootstrap(void *arg)
*/
thd->query_id=next_query_id();
thd->set_time();
mysql_parse(thd,thd->query,length);
mysql_parse(thd, thd->query, length, & found_semicolon);
close_thread_tables(thd); // Free tables
if (thd->is_fatal_error)
......@@ -894,17 +895,19 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
char *packet_end= thd->query + thd->query_length;
/* 'b' stands for 'buffer' parameter', special for 'my_snprintf' */
const char *format= "%.*b";
const char* found_semicolon= NULL;
general_log_print(thd, command, format, thd->query_length, thd->query);
DBUG_PRINT("query",("%-.4096s",thd->query));
if (!(specialflag & SPECIAL_NO_PRIOR))
my_pthread_setprio(pthread_self(),QUERY_PRIOR);
mysql_parse(thd,thd->query, thd->query_length);
mysql_parse(thd, thd->query, thd->query_length, & found_semicolon);
while (!thd->killed && thd->lex->found_semicolon && !thd->net.report_error)
while (!thd->killed && found_semicolon && !thd->net.report_error)
{
char *next_packet= thd->lex->found_semicolon;
char *next_packet= (char*) found_semicolon;
net->no_send_error= 0;
/*
Multiple queries exits, execute them individually
......@@ -929,7 +932,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
thd->set_time(); /* Reset the query start time. */
/* TODO: set thd->lex->sql_command to SQLCOM_END here */
VOID(pthread_mutex_unlock(&LOCK_thread_count));
mysql_parse(thd, next_packet, length);
mysql_parse(thd, next_packet, length, & found_semicolon);
}
if (!(specialflag & SPECIAL_NO_PRIOR))
......@@ -951,7 +954,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
uint dummy;
/* used as fields initializator */
lex_start(thd, 0, 0);
lex_start(thd);
statistic_increment(thd->status_var.com_stat[SQLCOM_SHOW_FIELDS],
&LOCK_status);
......@@ -990,7 +993,10 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
break;
/* init structures for VIEW processing */
table_list.select_lex= &(thd->lex->select_lex);
mysql_init_query(thd, "", 0);
lex_start(thd);
mysql_reset_thd_for_next_command(thd);
thd->lex->
select_lex.table_list.link_in_list((byte*) &table_list,
(byte**) &table_list.next_local);
......@@ -2158,7 +2164,13 @@ mysql_execute_command(THD *thd)
select_lex->options|= SELECT_NO_UNLOCK;
unit->set_limit(select_lex);
if (!(res= open_and_lock_tables(thd, select_tables)))
if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
{
lex->link_first_table_back(create_table, link_to_local);
create_table->create= TRUE;
}
if (!(res= open_and_lock_tables(thd, lex->query_tables)))
{
/*
Is table which we are changing used somewhere in other parts
......@@ -2167,6 +2179,7 @@ mysql_execute_command(THD *thd)
if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
{
TABLE_LIST *duplicate;
create_table= lex->unlink_first_table(&link_to_local);
if ((duplicate= unique_table(thd, create_table, select_tables, 0)))
{
update_non_unique_table_error(create_table, "CREATE", duplicate);
......@@ -2192,6 +2205,12 @@ mysql_execute_command(THD *thd)
}
}
/*
FIXME Temporary hack which will go away once Kostja pushes
his uber-fix for ALTER/CREATE TABLE.
*/
lex->create_info.table_existed= 0;
if ((result= new select_create(create_table,
&lex->create_info,
lex->create_list,
......@@ -2211,6 +2230,9 @@ mysql_execute_command(THD *thd)
lex->create_list.empty();
lex->key_list.empty();
}
else if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
create_table= lex->unlink_first_table(&link_to_local);
}
else
{
......@@ -5044,20 +5066,6 @@ bool my_yyoverflow(short **yyss, YYSTYPE **yyvs, ulong *yystacksize)
}
/****************************************************************************
Initialize global thd variables needed for query
****************************************************************************/
void
mysql_init_query(THD *thd, const char *buf, uint length)
{
DBUG_ENTER("mysql_init_query");
lex_start(thd, buf, length);
mysql_reset_thd_for_next_command(thd);
DBUG_VOID_RETURN;
}
/*
Reset THD part responsible for command processing state.
......@@ -5269,22 +5277,55 @@ void mysql_init_multi_delete(LEX *lex)
mysql_test_parse_for_slave() in this same file.
*/
void mysql_parse(THD *thd, char *inBuf, uint length)
/**
Parse a query.
@param thd Current thread
@param inBuf Begining of the query text
@param length Length of the query text
@param [out] semicolon For multi queries, position of the character of
the next query in the query text.
*/
void mysql_parse(THD *thd, const char *inBuf, uint length,
const char ** found_semicolon)
{
DBUG_ENTER("mysql_parse");
DBUG_EXECUTE_IF("parser_debug", turn_parser_debug_on(););
mysql_init_query(thd, inBuf, length);
/*
Warning.
The purpose of query_cache_send_result_to_client() is to lookup the
query in the query cache first, to avoid parsing and executing it.
So, the natural implementation would be to:
- first, call query_cache_send_result_to_client,
- second, if caching failed, initialise the lexical and syntactic parser.
The problem is that the query cache depends on a clean initialization
of (among others) lex->safe_to_cache_query and thd->server_status,
which are reset respectively in
- lex_start()
- mysql_reset_thd_for_next_command()
So, initializing the lexical analyser *before* using the query cache
is required for the cache to work properly.
FIXME: cleanup the dependencies in the code to simplify this.
*/
lex_start(thd);
mysql_reset_thd_for_next_command(thd);
if (query_cache_send_result_to_client(thd, inBuf, length) <= 0)
if (query_cache_send_result_to_client(thd, (char*) inBuf, length) <= 0)
{
LEX *lex= thd->lex;
sp_cache_flush_obsolete(&thd->sp_proc_cache);
sp_cache_flush_obsolete(&thd->sp_func_cache);
if (!MYSQLparse((void *)thd) && ! thd->is_fatal_error)
Lex_input_stream lip(thd, inBuf, length);
thd->m_lip= &lip;
int err= MYSQLparse(thd);
*found_semicolon= lip.found_semicolon;
if (!err && ! thd->is_fatal_error)
{
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (mqh_used && thd->user_connect &&
......@@ -5307,8 +5348,8 @@ void mysql_parse(THD *thd, char *inBuf, uint length)
PROCESSLIST.
Note that we don't need LOCK_thread_count to modify query_length.
*/
if (lex->found_semicolon &&
(thd->query_length= (ulong)(lex->found_semicolon - thd->query)))
if (lip.found_semicolon &&
(thd->query_length= (ulong)(lip.found_semicolon - thd->query)))
thd->query_length--;
/* Actually execute the query */
mysql_execute_command(thd);
......@@ -5335,6 +5376,12 @@ void mysql_parse(THD *thd, char *inBuf, uint length)
thd->cleanup_after_query();
DBUG_ASSERT(thd->change_list.is_empty());
}
else
{
/* There are no multi queries in the cache. */
*found_semicolon= NULL;
}
DBUG_VOID_RETURN;
}
......@@ -5355,8 +5402,13 @@ bool mysql_test_parse_for_slave(THD *thd, char *inBuf, uint length)
bool error= 0;
DBUG_ENTER("mysql_test_parse_for_slave");
mysql_init_query(thd, inBuf, length);
if (!MYSQLparse((void*) thd) && ! thd->is_fatal_error &&
Lex_input_stream lip(thd, inBuf, length);
thd->m_lip= &lip;
lex_start(thd);
mysql_reset_thd_for_next_command(thd);
int err= MYSQLparse((void*) thd);
if (!err && ! thd->is_fatal_error &&
all_tables_not_ok(thd,(TABLE_LIST*) lex->select_lex.table_list.first))
error= 1; /* Ignore question */
thd->end_statement();
......@@ -6407,8 +6459,9 @@ bool check_simple_select()
if (lex->current_select != &lex->select_lex)
{
char command[80];
strmake(command, lex->yylval->symbol.str,
min(lex->yylval->symbol.length, sizeof(command)-1));
Lex_input_stream *lip= thd->m_lip;
strmake(command, lip->yylval->symbol.str,
min(lip->yylval->symbol.length, sizeof(command)-1));
my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);
return 1;
}
......
......@@ -3718,7 +3718,11 @@ bool mysql_unpack_partition(THD *thd,
thd->lex= &lex;
thd->variables.character_set_client= system_charset_info;
lex_start(thd, part_buf, part_info_len);
Lex_input_stream lip(thd, part_buf, part_info_len);
thd->m_lip= &lip;
lex_start(thd);
/*
We need to use the current SELECT_LEX since I need to keep the
Name_resolution_context object which is referenced from the
......
......@@ -1493,8 +1493,21 @@ static bool mysql_test_create_table(Prepared_statement *stmt)
if (select_lex->item_list.elements)
{
if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
{
lex->link_first_table_back(create_table, link_to_local);
create_table->create= TRUE;
}
if (open_normal_and_derived_tables(stmt->thd, lex->query_tables, 0))
DBUG_RETURN(TRUE);
if (!(lex->create_info.options & HA_LEX_CREATE_TMP_TABLE))
create_table= lex->unlink_first_table(&link_to_local);
select_lex->context.resolve_in_select_list= TRUE;
res= select_like_stmt_test_with_open(stmt, tables, 0, 0);
res= select_like_stmt_test(stmt, 0, 0);
}
/* put tables back for PS rexecuting */
......@@ -1795,6 +1808,9 @@ static bool check_prepared_statement(Prepared_statement *stmt,
case SQLCOM_KILL:
break;
case SQLCOM_PREPARE:
case SQLCOM_EXECUTE:
case SQLCOM_DEALLOCATE_PREPARE:
default:
/*
Trivial check of all status commands. This is easier than having
......@@ -2851,10 +2867,14 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
old_stmt_arena= thd->stmt_arena;
thd->stmt_arena= this;
lex_start(thd, thd->query, thd->query_length);
lex->stmt_prepare_mode= TRUE;
error= MYSQLparse((void *)thd) || thd->is_fatal_error ||
Lex_input_stream lip(thd, thd->query, thd->query_length);
lip.stmt_prepare_mode= TRUE;
thd->m_lip= &lip;
lex_start(thd);
int err= MYSQLparse((void *)thd);
error= err || thd->is_fatal_error ||
thd->net.report_error || init_param_array(this);
/*
......
This diff is collapsed.
......@@ -279,7 +279,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
/* We also don't allow creation of triggers on views. */
tables->required_type= FRMTYPE_TABLE;
if (reopen_name_locked_table(thd, tables))
if (reopen_name_locked_table(thd, tables, TRUE))
{
unlock_table_name(thd, tables);
goto end;
......@@ -976,10 +976,14 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
LEX_STRING *trg_definer= it_definer++;
thd->variables.sql_mode= (ulong)*trg_sql_mode;
lex_start(thd, trg_create_str->str, trg_create_str->length);
thd->spcont= 0;
if (MYSQLparse((void *)thd) || thd->is_fatal_error)
Lex_input_stream lip(thd, trg_create_str->str, trg_create_str->length);
thd->m_lip= &lip;
lex_start(thd);
thd->spcont= 0;
int err= MYSQLparse((void *)thd);
if (err || thd->is_fatal_error)
{
/* Currently sphead is always deleted in case of a parse error */
DBUG_ASSERT(lex.sphead == 0);
......
......@@ -985,10 +985,14 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
now Lex placed in statement memory
*/
table->view= lex= thd->lex= (LEX*) new(thd->mem_root) st_lex_local;
lex_start(thd, table->query.str, table->query.length);
view_select= &lex->select_lex;
view_select->select_number= ++thd->select_number;
{
Lex_input_stream lip(thd, table->query.str, table->query.length);
thd->m_lip= &lip;
lex_start(thd);
view_select= &lex->select_lex;
view_select->select_number= ++thd->select_number;
ulong save_mode= thd->variables.sql_mode;
/* switch off modes which can prevent normal parsing of VIEW
- MODE_REAL_AS_FLOAT affect only CREATE TABLE parsing
......
This diff is collapsed.
......@@ -304,6 +304,8 @@ typedef struct st_table_share
} TABLE_SHARE;
extern ulong refresh_version;
/* Information for one open table */
enum index_hint_type
{
......@@ -319,8 +321,8 @@ struct st_table {
handler *file;
#ifdef NOT_YET
struct st_table *used_next, **used_prev; /* Link to used tables */
#endif
struct st_table *open_next, **open_prev; /* Link to open tables */
#endif
struct st_table *next, *prev;
THD *in_use; /* Which thread uses this */
......@@ -436,7 +438,24 @@ struct st_table {
my_bool force_index;
my_bool distinct,const_table,no_rows;
my_bool key_read, no_keyread;
my_bool locked_by_flush;
/*
Placeholder for an open table which prevents other connections
from taking name-locks on this table. Typically used with
TABLE_SHARE::version member to take an exclusive name-lock on
this table name -- a name lock that not only prevents other
threads from opening the table, but also blocks other name
locks. This is achieved by:
- setting open_placeholder to 1 - this will block other name
locks, as wait_for_locked_table_name will be forced to wait,
see table_is_used for details.
- setting version to 0 - this will force other threads to close
the instance of this table and wait (this is the same approach
as used for usual name locks).
An exclusively name-locked table currently can have no handler
object associated with it (db_stat is always 0), but please do
not rely on that.
*/
my_bool open_placeholder;
my_bool locked_by_logger;
my_bool no_replicate;
my_bool locked_by_name;
......@@ -497,7 +516,13 @@ struct st_table {
read_set= &def_read_set;
write_set= &def_write_set;
}
/* Is table open or should be treated as such by name-locking? */
inline bool is_name_opened() { return db_stat || open_placeholder; }
/*
Is this instance of the table should be reopen or represents a name-lock?
*/
inline bool needs_reopen_or_name_lock()
{ return s->version != refresh_version; }
};
enum enum_schema_table_state
......@@ -893,6 +918,12 @@ typedef struct st_table_list
used for implicit LOCK TABLES only and won't be used in real statement.
*/
bool prelocking_placeholder;
/*
This TABLE_LIST object corresponds to the table to be created
so it is possible that it does not exist (used in CREATE TABLE
... SELECT implementation).
*/
bool create;
enum enum_schema_table_state schema_table_state;
void calc_md5(char *buffer);
......@@ -900,7 +931,11 @@ typedef struct st_table_list
int view_check_option(THD *thd, bool ignore_failure);
bool setup_underlying(THD *thd);
void cleanup_items();
bool placeholder() {return derived || view || schema_table || !table; }
bool placeholder()
{
return derived || view || schema_table || create && !table->db_stat ||
!table;
}
void print(THD *thd, String *str);
bool check_single_table(st_table_list **table, table_map map,
st_table_list *view);
......
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