Commit cb4bf952 authored by Axel Schwenke's avatar Axel Schwenke

merged in MDEV-11 "Generic storage engine test suite"

see https://mariadb.atlassian.net/browse/MDEV-11
parents 79c4b4e4 1b1b36ab
......@@ -621,6 +621,8 @@ void free_all_replace(){
free_replace_column();
}
void var_set_int(const char* name, int value);
class LogFile {
FILE* m_file;
......@@ -1275,6 +1277,8 @@ void handle_command_error(struct st_command *command, uint error,
{
DBUG_ENTER("handle_command_error");
DBUG_PRINT("enter", ("error: %d", error));
var_set_int("$sys_errno",sys_errno);
var_set_int("$errno",error);
if (error != 0)
{
int i;
......@@ -5201,15 +5205,32 @@ const char *get_errname_from_code (uint error_code)
void do_get_errcodes(struct st_command *command)
{
struct st_match_err *to= saved_expected_errors.err;
char *p= command->first_argument;
uint count= 0;
char *next;
DBUG_ENTER("do_get_errcodes");
if (!*p)
if (!*command->first_argument)
die("Missing argument(s) to 'error'");
/* TODO: Potentially, there is a possibility of variables
being expanded twice, e.g.
let $errcodes = 1,\$a;
let $a = 1051;
error $errcodes;
DROP TABLE unknown_table;
...
Got one of the listed errors
But since it requires manual escaping, it does not seem
particularly dangerous or error-prone.
*/
DYNAMIC_STRING ds;
init_dynamic_string(&ds, 0, command->query_len + 64, 256);
do_eval(&ds, command->first_argument, command->end, !is_windows);
char *p= ds.str;
uint count= 0;
char *next;
do
{
char *end;
......@@ -5319,11 +5340,15 @@ void do_get_errcodes(struct st_command *command)
} while (*p);
command->last_argument= p;
command->last_argument= command->first_argument;
while (*command->last_argument)
command->last_argument++;
to->type= ERR_EMPTY; /* End of data */
DBUG_PRINT("info", ("Expected errors: %d", count));
saved_expected_errors.count= count;
dynstr_free(&ds);
DBUG_VOID_RETURN;
}
......
......@@ -690,6 +690,7 @@ Got one of the listed errors
insert into t1 values ("Abcd");
Got one of the listed errors
garbage;
SELECT * FROM non_existing_table;
drop table t2;
create table t1 ( f1 char(10));
insert into t1 values ("Abcd");
......
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a <INT_COLUMN>, b <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
SHOW CREATE TABLE t1;
SHOW COLUMNS IN t1;
INSERT INTO t1 VALUES (1,'a');
INSERT INTO t1 (a,b) VALUES (2,'b');
SELECT * FROM t1;
a b
1 a
2 b
DROP TABLE t1;
#
# This test checks some very basic capabilities
# which will be used in almost every other test,
# and will not be checked through support* variables.
# If this test does not pass, there is no point
# at executing other ones.
#
# Minimal requirements:
# - supported column types: INT, CHAR (default CHAR(8), INT(11));
# - column attributes as declared in define_engine.inc ($default_col_opts)
# (by default empty, which means no additional attributes apart from the type);
# - table attributes as declared in define_engine.inc ($default_tbl_opts)
# (by default empty, which means no additional attributes apart from ENGINE);
# - CREATE TABLE .. (column1 <column options>, column2 <column options>) ENGINE=<storage_engine>;
# - INSERT INTO TABLE .. VALUES (val1,val2);
# - DROP TABLE ..
# - SELECT * FROM ..
# - SHOW CREATE TABLE ..
# - SHOW COLUMNS IN ...
#
--source have_engine.inc
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = CREATE TABLE
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--disable_result_log
SHOW CREATE TABLE t1;
if ($mysql_errname)
{
--let $functionality = SHOW CREATE TABLE
--source unexpected_result.inc
}
SHOW COLUMNS IN t1;
if ($mysql_errname)
{
--let $functionality = SHOW COLUMNS
--source unexpected_result.inc
}
--enable_result_log
INSERT INTO t1 VALUES (1,'a');
if ($mysql_errname)
{
--let $functionality = INSERT INTO .. VALUES
--source unexpected_result.inc
}
INSERT INTO t1 (a,b) VALUES (2,'b');
if ($mysql_errname)
{
--let $functionality = INSERT INTO .. (column_list) VALUES
--source unexpected_result.inc
}
SELECT * FROM t1;
if ($mysql_errname)
{
--let $functionality = SELECT * FROM ..
--source unexpected_result.inc
}
DROP TABLE t1;
if ($mysql_errname)
{
--let $functionality = DROP TABLE
--source unexpected_result.inc
}
}
--source cleanup_engine.inc
##################################
#
# This include file will be used for all ALTER TABLE statements in the suite.
# If you need to add additional steps or change the logic, copy the file
# to storage/<engine>/mysql-test/storage_engine/ folder and modify it there.
#
##################
#
# Parameters:
#
# --let $alter_definition = <alter definition> # mandatory, everything that goes after the table name in ALTER statement
# --let $table_name = <table name> # optional, default t1
# --let $error_codes = <expected error codes, as in --error> # optional, default 0
# --let $online = [0|1] # optional, default 0 (1 adds ONLINE)
# --let $rename_to = <new table name> # optional, default empty.
# # If set, means we are running RENAME TO, then alter definition is ignored
#
# Usage examples:
#
# --let $alter_definition = ADD COLUMN b $char_col DEFAULT ''
#
if ($rename_to)
{
--let $alter_definition = RENAME TO $rename_to
}
if (!$alter_definition)
{
--die # The ALTER statement is empty
}
--let $alter_statement = ALTER
if ($online)
{
--let $alter_statement = $alter_statement ONLINE
}
if (!$table_name)
{
--let $table_name = t1
}
--let $alter_statement = $alter_statement TABLE $table_name $alter_definition
# We now have the complete ALTER statement in $alter_statement.
# If your ALTER statement should be composed differently,
# modify the logic above.
#####################
# Here you can add logic needed BEFORE the main statement
# (e.g. base tables need to be altered, etc.).
# Surround it by --disable_query_log/--enable_query_log
# if you don't want it to appear in the result output.
#####################
--source obfuscate.inc
eval $alter_statement;
--source check_errors.inc
# Make sure you don't add any statements between the main ALTER (above)
# and saving mysql_errno and mysql_errname (below)
# They are saved in case you want to add more logic after the main ALTER,
# because we need the result code of the statement.
# Also, do not change $alter_statement after it is executed!
--let $my_errno = $mysql_errno
--let $my_errname = $mysql_errname
#####################
# Here you can add logic needed AFTER the main statement.
# Surround it by --disable_query_log/--enable_query_log
# if you don't want it to appear in the result output.
#####################
# Unset the parameters, we don't want them to be accidentally reused later
--let $alter_definition =
--let $table_name =
--let $error_codes =
--let $online = 0
--let $rename_to =
# Restore the error codes of the main statement
--let $mysql_errno = $my_errno
--let $mysql_errname = $my_errname
# Make sure you don't add any SQL statements after restoring
# mysql_errno and mysql_errname (above)
DROP TABLE IF EXISTS t1, t2;
CREATE TABLE t1 (a <INT_COLUMN>, c <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a,c) VALUES (1,'a'),(5,'z');
ALTER TABLE t1 ADD COLUMN b <INT_COLUMN>;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`c` char(8) DEFAULT NULL,
`b` int(11) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
ALTER TABLE t1 ALTER COLUMN a SET DEFAULT '0';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT '0',
`c` char(8) DEFAULT NULL,
`b` int(11) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
ALTER TABLE t1 ALTER a DROP DEFAULT;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11),
`c` char(8) DEFAULT NULL,
`b` int(11) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
ALTER TABLE t1 CHANGE COLUMN b b1 <CHAR_COLUMN> FIRST;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`b1` char(8) DEFAULT NULL,
`a` int(11),
`c` char(8) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
ALTER TABLE t1 CHANGE b1 b <INT_COLUMN> AFTER c;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11),
`c` char(8) DEFAULT NULL,
`b` int(11) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
ALTER TABLE t1 CHANGE b b <CHAR_COLUMN>;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11),
`c` char(8) DEFAULT NULL,
`b` char(8) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
ALTER TABLE t1 MODIFY COLUMN b <INT_COLUMN>;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11),
`c` char(8) DEFAULT NULL,
`b` int(11) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
ALTER TABLE t1 MODIFY COLUMN b <CHAR_COLUMN> FIRST;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`b` char(8) DEFAULT NULL,
`a` int(11),
`c` char(8) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
ALTER TABLE t1 MODIFY COLUMN b <INT_COLUMN> AFTER a;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11),
`b` int(11) DEFAULT NULL,
`c` char(8) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
ALTER TABLE t1 DROP COLUMN b;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11),
`c` char(8) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
ALTER TABLE t1 RENAME TO t2;
SHOW CREATE TABLE t1;
ERROR 42S02: Table 'test.t1' doesn't exist
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11),
`c` char(8) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
DROP TABLE t2;
CREATE TABLE t1 (a <INT_COLUMN>, b <INT_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a,b) VALUES (1,5),(2,2),(4,3);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
ALTER TABLE t1 ORDER BY b ASC, a DESC;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
SELECT * FROM t1;
a b
2 2
4 3
1 5
DROP TABLE t1;
CREATE TABLE t1 (a <INT_COLUMN>, b <CHAR_COLUMN>, c <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS> CHARACTER SET latin1 COLLATE latin1_general_cs;
INSERT INTO t1 (a,b,c) VALUES (5,'z','t');
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` char(8) COLLATE latin1_general_cs DEFAULT NULL,
`c` char(8) COLLATE latin1_general_cs DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs
ALTER TABLE t1 CONVERT TO CHARACTER SET utf8;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` char(8) DEFAULT NULL,
`c` char(8) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=utf8
ALTER TABLE t1 DEFAULT CHARACTER SET = latin1 COLLATE latin1_general_ci;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` char(8) CHARACTER SET utf8 DEFAULT NULL,
`c` char(8) CHARACTER SET utf8 DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci
ALTER TABLE t1 FORCE;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` char(8) CHARACTER SET utf8 DEFAULT NULL,
`c` char(8) CHARACTER SET utf8 DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci
DROP TABLE t1;
#
# Basic ALTER TABLE statements.
#
# USAGE of table options in ALTER statements
# is covered in tbl_standard_opts and tbl_opt*.tests.
#
# Index operations are covered in index* tests.
#
# ALTER ONLINE syntax is covered in alter_online_table.test
# ALTER OFFLINE is not covered as it is not supported, as of 5.5.23
#
# ALTER TABLE ... DISCARD|IMPORT TABLESPACE is covered in alter_tablespace.test
#
--source have_engine.inc
--disable_warnings
DROP TABLE IF EXISTS t1, t2;
--enable_warnings
--let $create_definition = a $int_col, c $char_col
--source create_table.inc
INSERT INTO t1 (a,c) VALUES (1,'a'),(5,'z');
# Column operations
--let $alter_definition = ADD COLUMN b $int_col
--source alter_table.inc
if ($mysql_errname)
{
--source unexpected_result.inc
}
--source mask_engine.inc
SHOW CREATE TABLE t1;
--let $alter_definition = ALTER COLUMN a SET DEFAULT '0'
--source alter_table.inc
--source mask_engine.inc
SHOW CREATE TABLE t1;
--let $alter_definition = ALTER a DROP DEFAULT
--source alter_table.inc
--source mask_engine.inc
SHOW CREATE TABLE t1;
--let $alter_definition = CHANGE COLUMN b b1 $char_col FIRST
--source alter_table.inc
--source mask_engine.inc
SHOW CREATE TABLE t1;
--let $alter_definition = CHANGE b1 b $int_col AFTER c
--source alter_table.inc
--source mask_engine.inc
SHOW CREATE TABLE t1;
--let $alter_definition = CHANGE b b $char_col
--source alter_table.inc
--source mask_engine.inc
SHOW CREATE TABLE t1;
--let $alter_definition = MODIFY COLUMN b $int_col
--source alter_table.inc
--source mask_engine.inc
SHOW CREATE TABLE t1;
--let $alter_definition = MODIFY COLUMN b $char_col FIRST
--source alter_table.inc
--source mask_engine.inc
SHOW CREATE TABLE t1;
--let $alter_definition = MODIFY COLUMN b $int_col AFTER a
--source alter_table.inc
--source mask_engine.inc
SHOW CREATE TABLE t1;
--let $alter_definition = DROP COLUMN b
--source alter_table.inc
--source mask_engine.inc
SHOW CREATE TABLE t1;
# Rename table
--let $rename_to = t2
--source alter_table.inc
--let $error_codes = ER_NO_SUCH_TABLE
SHOW CREATE TABLE t1;
--source check_errors.inc
if ($mysql_errname != 'ER_NO_SUCH_TABLE')
{
--let $functionality = ALTER TABLE
--source unexpected_result.inc
DROP TABLE t1;
}
if ($mysql_errname == ER_NO_SUCH_TABLE)
{
--source mask_engine.inc
SHOW CREATE TABLE t2;
DROP TABLE t2;
}
# ORDER BY
--let $create_definition = a $int_col, b $int_col
--source create_table.inc
INSERT INTO t1 (a,b) VALUES (1,5),(2,2),(4,3);
--source mask_engine.inc
SHOW CREATE TABLE t1;
--let $alter_definition = ORDER BY b ASC, a DESC
--source alter_table.inc
--source mask_engine.inc
SHOW CREATE TABLE t1;
SELECT * FROM t1;
DROP TABLE t1;
# Character set, collate
--let $table_options = CHARACTER SET latin1 COLLATE latin1_general_cs
--let $create_definition = a $int_col, b $char_col, c $char_col
--source create_table.inc
INSERT INTO t1 (a,b,c) VALUES (5,'z','t');
--source mask_engine.inc
SHOW CREATE TABLE t1;
--let $alter_definition = CONVERT TO CHARACTER SET utf8
--source alter_table.inc
--source mask_engine.inc
SHOW CREATE TABLE t1;
--let $alter_definition = DEFAULT CHARACTER SET = latin1 COLLATE latin1_general_ci
--source alter_table.inc
--source mask_engine.inc
SHOW CREATE TABLE t1;
# A 'null' ALTER operation
--let $alter_definition = FORCE
--source alter_table.inc
--source mask_engine.inc
SHOW CREATE TABLE t1;
# Cleanup
DROP TABLE t1;
--source cleanup_engine.inc
DROP TABLE IF EXISTS t1,t2,t3;
CREATE TABLE t1 (a <INT_COLUMN>, b <INT_COLUMN>, c <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a,b,c) VALUES (1,100,'a'),(2,200,'b'),(3,300,'c');
ALTER ONLINE TABLE t1 MODIFY b <INT_COLUMN> DEFAULT 5;
ALTER ONLINE TABLE t1 CHANGE b new_name <INT_COLUMN>;
ALTER ONLINE TABLE t1 COMMENT 'new comment';
ALTER ONLINE TABLE t1 RENAME TO t2;
DROP TABLE IF EXISTS t2;
CREATE TEMPORARY TABLE t1 (a <INT_COLUMN>, b <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'),(3,'c');
ALTER ONLINE TABLE t1 MODIFY b <INT_COLUMN> DEFAULT 5;
ERROR HY000: Can't execute the given 'ALTER' command as online
ALTER ONLINE TABLE t1 CHANGE b new_name <INT_COLUMN>;
ERROR HY000: Can't execute the given 'ALTER' command as online
ALTER ONLINE TABLE t1 COMMENT 'new comment';
ERROR HY000: Can't execute the given 'ALTER' command as online
ALTER ONLINE TABLE t1 RENAME TO t2;
ERROR HY000: Can't execute the given 'ALTER' command as online
DROP TABLE t1;
CREATE TABLE t1 (a <INT_COLUMN>, b <INT_COLUMN>, c <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a,b,c) VALUES (1,100,'a'),(2,200,'b'),(3,300,'c');
ALTER ONLINE TABLE t1 DROP COLUMN b, ADD b <INT_COLUMN>;
ERROR HY000: Can't execute the given 'ALTER' command as online
ALTER ONLINE TABLE t1 MODIFY b BIGINT <CUSTOM_COL_OPTIONS>;
ERROR HY000: Can't execute the given 'ALTER' command as online
ALTER ONLINE TABLE t1 ENGINE=MEMORY;
ERROR HY000: Can't execute the given 'ALTER' command as online
DROP TABLE t1;
CREATE TABLE t1 (a <INT_COLUMN>, b <INT_COLUMN>, c <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
ALTER ONLINE TABLE t1 ADD INDEX (b);
ERROR HY000: Can't execute the given 'ALTER' command as online
ALTER TABLE t1 ADD INDEX (b);
ALTER ONLINE TABLE t1 DROP INDEX b;
ERROR HY000: Can't execute the given 'ALTER' command as online
DROP TABLE t1;
#
# ALTER ONLINE TABLE
#
--source have_engine.inc
--disable_warnings
DROP TABLE IF EXISTS t1,t2,t3;
--enable_warnings
#
# Test of things that can be done online
# We are repeating notification here, because for some engines
# only a part of these ALTER ONLINE statements might be supported.
#
let $create_definition = a $int_col, b $int_col, c $char_col;
--source create_table.inc
INSERT INTO t1 (a,b,c) VALUES (1,100,'a'),(2,200,'b'),(3,300,'c');
--let $online = 1
--let $alter_definition = MODIFY b $int_col DEFAULT 5
--source alter_table.inc
if ($mysql_errname)
{
--source unexpected_result.inc
}
--let $online = 1
--let $alter_definition = CHANGE b new_name $int_col
--source alter_table.inc
if ($mysql_errname)
{
--source unexpected_result.inc
}
--let $online = 1
--let $alter_definition = COMMENT 'new comment'
--source alter_table.inc
if ($mysql_errname)
{
--source unexpected_result.inc
}
--let $online = 1
--let $rename_to = t2
--source alter_table.inc
if ($mysql_errname)
{
--source unexpected_result.inc
DROP TABLE t1;
}
DROP TABLE IF EXISTS t2;
#
# temporary tables always require a copy
#
--let $temporary = 1
--source create_table.inc
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'),(3,'c');
--let $error_codes = ER_CANT_DO_ONLINE
--let $online = 1
--let $alter_definition = MODIFY b $int_col DEFAULT 5
--source alter_table.inc
if ($mysql_errname != ER_CANT_DO_ONLINE)
{
--source unexpected_result.inc
}
--let $error_codes = ER_CANT_DO_ONLINE
--let $online = 1
--let $alter_definition = CHANGE b new_name $int_col
--source alter_table.inc
--let $error_codes = ER_CANT_DO_ONLINE
--let $online = 1
--let $alter_definition = COMMENT 'new comment'
--source alter_table.inc
--let $error_codes = ER_CANT_DO_ONLINE
--let $online = 1
--let $rename_to = t2
--source alter_table.inc
DROP TABLE t1;
#
# Test of things that is not possible to do online
#
--let $create_definition = a $int_col, b $int_col, c $char_col
--source create_table.inc
INSERT INTO t1 (a,b,c) VALUES (1,100,'a'),(2,200,'b'),(3,300,'c');
--let $error_codes = ER_CANT_DO_ONLINE
--let $online = 1
--let $alter_definition = DROP COLUMN b, ADD b $int_col
--source alter_table.inc
if ($mysql_errname!=ER_CANT_DO_ONLINE)
{
--source unexpected_result.inc
}
--let $error_codes = ER_CANT_DO_ONLINE
--let $online = 1
--let $alter_definition = MODIFY b BIGINT $default_col_opts
--source alter_table.inc
--let $alternative_engine = `SELECT engine FROM information_schema.engines WHERE engine != '$storage_engine' AND support IN ('YES','DEFAULT')`
--let $error_codes = ER_CANT_DO_ONLINE
--let $online = 1
--let $alter_definition = ENGINE=$alternative_engine
--source alter_table.inc
DROP TABLE t1;
--let $create_definition = a $int_col, b $int_indexed_col, c $char_col
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = Column options
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--let $error_codes = ER_CANT_DO_ONLINE
--let $online = 1
--let $alter_definition = ADD INDEX (b)
--source alter_table.inc
if ($mysql_errname!=ER_CANT_DO_ONLINE)
{
--let $functionality = Adding an index or ALTER ONLINE
--source unexpected_result.inc
}
--let $alter_definition = ADD INDEX (b)
--source alter_table.inc
if ($mysql_errname)
{
--let $functionality = Adding an index or ALTER TABLE
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--let $error_codes = ER_CANT_DO_ONLINE
--let $online = 1
--let $alter_definition = DROP INDEX b
--source alter_table.inc
}
DROP TABLE t1;
}
--source cleanup_engine.inc
DROP TABLE IF EXISTS t1, t2;
CREATE TABLE t1 (a <INT_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
ALTER TABLE t1 DISCARD TABLESPACE;
DROP TABLE t1;
CREATE TABLE t1 (a <INT_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a) VALUES (1),(2);
SELECT * FROM t1;
a
1
2
ALTER TABLE t1 DISCARD TABLESPACE;
SELECT * FROM t1;
ERROR HY000: Got error -1 from storage engine
ALTER TABLE t1 IMPORT TABLESPACE;
SELECT * FROM t1;
a
1
2
DROP TABLE t1;
#
# IMPORT / DISCARD TABLESPACE
#
# The test might require additional engine options,
# e.g. for InnoDB it is --innodb-file-per-table
--source have_engine.inc
--disable_warnings
DROP TABLE IF EXISTS t1, t2;
--enable_warnings
--let $create_definition = a $int_col
--source create_table.inc
--let $alter_definition = DISCARD TABLESPACE
--source alter_table.inc
if ($mysql_errname)
{
--let $my_last_stmt = $alter_statement
--let $functionality = Tablespace operations
--source unexpected_result.inc
}
if (!$mysql_errname)
{
DROP TABLE t1;
--let $create_definition = a $int_col
--source create_table.inc
INSERT INTO t1 (a) VALUES (1),(2);
--sorted_result
SELECT * FROM t1;
# http://dev.mysql.com/doc/mysql-enterprise-backup/3.5/en/partial.restoring.single.html
# To get a "clean" backup we need to either use innobackup, or to monitor show engine innodb status,
# and the documented conditions do not look exactly feasible. So, we will go a simple way:
# just restart the server, and take the backup while the server is down.
# (And we need to have a really clean backup, see MySQL:65429 / LP:1004910)
--let $datadir = `SELECT @@datadir`
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
restart
wait
EOF
--enable_reconnect
--shutdown_server 60
--source include/wait_until_disconnected.inc
--replace_result $datadir <DATADIR>
--copy_file $datadir/test/t1.ibd $datadir/test/t1.ibd.save
--remove_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
restart
EOF
--source include/wait_until_connected_again.inc
--let $alter_definition = DISCARD TABLESPACE
--source alter_table.inc
--let $error_codes = ER_GET_ERRNO
SELECT * FROM t1;
--source check_errors.inc
if ($mysql_errname != ER_GET_ERRNO)
{
--let $functionality = Tablespace operations
--source unexpected_result.inc
}
--move_file $datadir/test/t1.ibd.save $datadir/test/t1.ibd
--let $alter_definition = IMPORT TABLESPACE
--source alter_table.inc
--sorted_result
SELECT * FROM t1;
# Adding a warning suppression based on what InnoDB currently does
# when it attempts to access a table without an *.ibd file
--disable_query_log
eval CALL mtr.add_suppression('$storage_engine: Error:.*');
--enable_query_log
}
DROP TABLE t1;
--source cleanup_engine.inc
#
# ANALYZE TABLE statements
#
# Note: the output is likely to be different for the engine under test,
# in which case rdiff will be needed. Or, the output might say that
# the storage engine does not support ANALYZE.
#
--disable_warnings
DROP TABLE IF EXISTS t1,t2;
--enable_warnings
--let $create_definition = a $int_col, b $char_col
--source create_table.inc
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b');
--let $create_definition = a $int_col, b $char_col
--let $table_name = t2
--source create_table.inc
INSERT INTO t1 (a,b) VALUES (3,'c');
ANALYZE TABLE t1;
INSERT INTO t2 (a,b) VALUES (4,'d');
ANALYZE NO_WRITE_TO_BINLOG TABLE t2;
INSERT INTO t1 (a,b) VALUES (5,'e');
INSERT INTO t2 (a,b) VALUES (6,'f');
ANALYZE LOCAL TABLE t1, t2;
DROP TABLE t1, t2;
--let $continue = 1
--source have_default_index.inc
if ($have_default_index)
{
--let $create_definition = a $int_indexed_col, $default_index(a)
--source create_table.inc
INSERT INTO t1 (a) VALUES (1),(2),(4),(7);
ANALYZE TABLE t1;
INSERT INTO t1 (a) VALUES (8),(10),(11),(12);
ANALYZE TABLE t1;
DROP TABLE t1;
}
DROP TABLE IF EXISTS t1,t2;
CREATE TABLE t1 (a <INT_COLUMN>, b <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b');
CREATE TABLE t2 (a <INT_COLUMN>, b <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a,b) VALUES (3,'c');
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
INSERT INTO t2 (a,b) VALUES (4,'d');
ANALYZE NO_WRITE_TO_BINLOG TABLE t2;
Table Op Msg_type Msg_text
test.t2 analyze status OK
INSERT INTO t1 (a,b) VALUES (5,'e');
INSERT INTO t2 (a,b) VALUES (6,'f');
ANALYZE LOCAL TABLE t1, t2;
Table Op Msg_type Msg_text
test.t1 analyze status OK
test.t2 analyze status OK
DROP TABLE t1, t2;
CREATE TABLE t1 (a <INT_COLUMN>, <CUSTOM_INDEX>(a)) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a) VALUES (1),(2),(4),(7);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
INSERT INTO t1 (a) VALUES (8),(10),(11),(12);
ANALYZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
DROP TABLE t1;
#
# ANALYZE TABLE statements
#
# Note: the output is likely to be different for the engine under test,
# in which case rdiff will be needed. Or, the output might say that
# the storage engine does not support ANALYZE.
#
--source have_engine.inc
--source analyze_table.inc
--source cleanup_engine.inc
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a <INT_COLUMN> AUTO_INCREMENT, b <CHAR_COLUMN>, PRIMARY KEY (a,b)) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (b) VALUES ('a'),('b'),('b'),('c'),('a');
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
1
SELECT * FROM t1;
a b
1 a
2 b
3 b
4 c
5 a
DROP TABLE t1;
CREATE TABLE t1 (a <CHAR_COLUMN>, b <INT_COLUMN> AUTO_INCREMENT, PRIMARY KEY (a,b)) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a) VALUES ('a'),('b'),('b'),('c'),('a');
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
1
SELECT * FROM t1;
a b
a 1
a 2
b 1
b 2
c 1
DROP TABLE t1;
CREATE TABLE t1 (a <CHAR_COLUMN>, b <INT_COLUMN> AUTO_INCREMENT, PRIMARY KEY (a,b), <CUSTOM_INDEX>(b)) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a) VALUES ('a'),('b'),('b'),('c'),('a');
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
1
SELECT * FROM t1;
a b
a 1
a 5
b 2
b 3
c 4
DROP TABLE t1;
#
# AUTO_INCREMENT on a secondary column in a multi-part key
#
--source have_engine.inc
--source have_default_index.inc
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
#
# AUTO_INCREMENT is the primary column in a multiple-column index
#
--let $create_definition = a $int_col AUTO_INCREMENT, b $char_col, PRIMARY KEY (a,b)
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = Multi-part keys or PK or AUTO_INCREMENT (on a primary column)
--source unexpected_result.inc
}
if (!$mysql_errname)
{
INSERT INTO t1 (b) VALUES ('a'),('b'),('b'),('c'),('a');
SELECT LAST_INSERT_ID();
--sorted_result
SELECT * FROM t1;
DROP TABLE t1;
}
#
# AUTO_INCREMENT is the secondary column in a multiple-column index
#
--let $create_definition = a $char_col, b $int_col AUTO_INCREMENT, PRIMARY KEY (a,b)
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = Multi-part keys or PK or AUTO_INCREMENT (on a secondary column)
--source unexpected_result.inc
}
if (!$mysql_errname)
{
INSERT INTO t1 (a) VALUES ('a'),('b'),('b'),('c'),('a');
SELECT LAST_INSERT_ID();
--sorted_result
SELECT * FROM t1;
DROP TABLE t1;
}
# AUTO_INCREMENT is the secondary column in a multiple-column index,
# and primary in another index
#
--let $create_definition = a $char_col, b $int_indexed_col AUTO_INCREMENT, PRIMARY KEY (a,b), $default_index(b)
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = Multi-part keys or AUTO_INCREMENT (on the secondary column) or multiple keys
--source unexpected_result.inc
}
if (!$mysql_errname)
{
INSERT INTO t1 (a) VALUES ('a'),('b'),('b'),('c'),('a');
SELECT LAST_INSERT_ID();
--sorted_result
SELECT * FROM t1;
DROP TABLE t1;
}
--source cleanup_engine.inc
DROP TABLE IF EXISTS t1;
SET auto_increment_offset = 200;
CREATE TABLE t1 (a <INT_COLUMN> AUTO_INCREMENT, b <CHAR_COLUMN>, <CUSTOM_INDEX>(a)) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a,b) VALUES (NULL,'a'),(NULL,'b'),(NULL,'c');
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
1
SELECT * FROM t1;
a b
1 a
2 b
3 c
SET auto_increment_increment = 300;
INSERT INTO t1 (a,b) VALUES (NULL,'d'),(NULL,'e'),(NULL,'f');
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
200
SELECT * FROM t1;
a b
1 a
2 b
200 d
3 c
500 e
800 f
SET auto_increment_increment = 50;
INSERT INTO t1 (a,b) VALUES (NULL,'g'),(NULL,'h'),(NULL,'i');
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
850
SELECT * FROM t1;
a b
1 a
2 b
200 d
3 c
500 e
800 f
850 g
900 h
950 i
DROP TABLE t1;
SET auto_increment_increment = 500;
SET auto_increment_offset = 300;
CREATE TABLE t1 (a TINYINT <CUSTOM_COL_OPTIONS> AUTO_INCREMENT, <CUSTOM_INDEX>(a)) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a) VALUES (NULL);
Warnings:
Warning 1264 Out of range value for column 'a' at row 1
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
127
SELECT * FROM t1;
a
127
DROP TABLE t1;
#
# auto-increment-offset and auto-increment-increment
#
--source have_engine.inc
--source have_default_index.inc
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
# auto_increment_offset
SET auto_increment_offset = 200;
--let $create_definition = a $int_indexed_col AUTO_INCREMENT, b $char_col, $default_index(a)
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = AUTO_INCREMENT
--source unexpected_result.inc
}
if (!$mysql_errname)
{
# If auto_increment_offset is greater than auto_increment_increment,
# the offset is ignored
INSERT INTO t1 (a,b) VALUES (NULL,'a'),(NULL,'b'),(NULL,'c');
SELECT LAST_INSERT_ID();
--sorted_result
SELECT * FROM t1;
# auto_increment_increment
SET auto_increment_increment = 300;
# offset should not be ignored anymore
INSERT INTO t1 (a,b) VALUES (NULL,'d'),(NULL,'e'),(NULL,'f');
SELECT LAST_INSERT_ID();
--sorted_result
SELECT * FROM t1;
SET auto_increment_increment = 50;
INSERT INTO t1 (a,b) VALUES (NULL,'g'),(NULL,'h'),(NULL,'i');
SELECT LAST_INSERT_ID();
--sorted_result
SELECT * FROM t1;
DROP TABLE t1;
}
# offset is greater than the max value
SET auto_increment_increment = 500;
SET auto_increment_offset = 300;
--let $create_definition = a TINYINT $default_col_indexed_opts AUTO_INCREMENT, $default_index(a)
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = AUTO_INCREMENT
--source unexpected_result.inc
}
if (!$mysql_errname)
{
INSERT INTO t1 (a) VALUES (NULL);
SELECT LAST_INSERT_ID();
--sorted_result
SELECT * FROM t1;
DROP TABLE t1;
}
--source cleanup_engine.inc
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a <INT_COLUMN> AUTO_INCREMENT, b <CHAR_COLUMN>, <CUSTOM_INDEX>(a)) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) NOT NULL AUTO_INCREMENT,
`b` char(8) DEFAULT NULL,
KEY `a` (`a`)
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
INSERT INTO t1 (b) VALUES ('a'),('b');
SELECT * FROM t1 ORDER BY a;
a b
1 a
2 b
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
1
INSERT INTO t1 (a,b) VALUES (NULL,'c'),(0,'d');
SELECT * FROM t1 ORDER BY a;
a b
1 a
2 b
3 c
4 d
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
3
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
INSERT INTO t1 (a,b) VALUES (NULL,'e');
SELECT * FROM t1 ORDER BY a;
a b
1 a
2 b
3 c
4 d
5 e
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
5
INSERT INTO t1 (a,b) VALUES (0,'f');
SELECT * FROM t1 ORDER BY a;
a b
0 f
1 a
2 b
3 c
4 d
5 e
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
5
SET sql_mode = '<INITIAL_SQL_MODE>';
SHOW TABLE STATUS FROM test LIKE 't1';
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
t1 <STORAGE_ENGINE> # # # # # # # # 6 # # # # # # #
INSERT INTO t1 (a,b) VALUES (6,'g'),(7,'h');
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
5
SHOW TABLE STATUS FROM test LIKE 't1';
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
t1 # # # # # # # # # 8 # # # # # # #
INSERT INTO t1 (a,b) VALUES (NULL,'i'),(9,'j');
SELECT * FROM t1 ORDER BY a;
a b
0 f
1 a
2 b
3 c
4 d
5 e
6 g
7 h
8 i
9 j
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
8
SHOW TABLE STATUS FROM test LIKE 't1';
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
t1 # # # # # # # # # 10 # # # # # # #
INSERT INTO t1 (a,b) VALUES (20,'k');
SHOW TABLE STATUS FROM test LIKE 't1';
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
t1 # # # # # # # # # 21 # # # # # # #
INSERT INTO t1 (a,b) VALUES (NULL,'l');
SELECT * FROM t1 ORDER BY a;
a b
0 f
1 a
2 b
3 c
4 d
5 e
6 g
7 h
8 i
9 j
20 k
21 l
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
21
SHOW TABLE STATUS FROM test LIKE 't1';
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
t1 # # # # # # # # # 22 # # # # # # #
INSERT INTO t1 (a,b) VALUES (-5,'m');
SELECT * FROM t1 ORDER BY a;
a b
-5 m
0 f
1 a
2 b
3 c
4 d
5 e
6 g
7 h
8 i
9 j
20 k
21 l
DROP TABLE t1;
CREATE TABLE t1 (a <INT_COLUMN> AUTO_INCREMENT, b <CHAR_COLUMN>, <CUSTOM_INDEX>(a)) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS> AUTO_INCREMENT = 100;
INSERT INTO t1 (a,b) VALUES (NULL,'a'),(NULL,'b');
SELECT * FROM t1;
a b
100 a
101 b
SELECT LAST_INSERT_ID();
LAST_INSERT_ID()
100
DROP TABLE t1;
#
# Basic AUTO_INCREMENT capabilities
#
--source have_engine.inc
--let $skip = 1
--source have_default_index.inc
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
--let $create_definition = a $int_indexed_col AUTO_INCREMENT, b $char_col, $default_index(a)
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = AUTO_INCREMENT
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--source mask_engine.inc
SHOW CREATE TABLE t1;
# Automatic values
INSERT INTO t1 (b) VALUES ('a'),('b');
SELECT * FROM t1 ORDER BY a;
SELECT LAST_INSERT_ID();
INSERT INTO t1 (a,b) VALUES (NULL,'c'),(0,'d');
SELECT * FROM t1 ORDER BY a;
SELECT LAST_INSERT_ID();
let $sql_mode = `SELECT @@sql_mode`;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
INSERT INTO t1 (a,b) VALUES (NULL,'e');
SELECT * FROM t1 ORDER BY a;
SELECT LAST_INSERT_ID();
INSERT INTO t1 (a,b) VALUES (0,'f');
SELECT * FROM t1 ORDER BY a;
SELECT LAST_INSERT_ID();
--replace_result $sql_mode <INITIAL_SQL_MODE>
eval SET sql_mode = '$sql_mode';
# SHOW TABLE STATUS shows the auto-increment value in column 11,
# that's all we need here and further
--source mask_engine.inc
--replace_column 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 #
SHOW TABLE STATUS FROM test LIKE 't1';
# Mix of automatic and explicit values
INSERT INTO t1 (a,b) VALUES (6,'g'),(7,'h');
SELECT LAST_INSERT_ID();
--replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 #
SHOW TABLE STATUS FROM test LIKE 't1';
INSERT INTO t1 (a,b) VALUES (NULL,'i'),(9,'j');
SELECT * FROM t1 ORDER BY a;
SELECT LAST_INSERT_ID();
--replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 #
SHOW TABLE STATUS FROM test LIKE 't1';
# Creating a gap in the sequence
INSERT INTO t1 (a,b) VALUES (20,'k');
--replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 #
SHOW TABLE STATUS FROM test LIKE 't1';
INSERT INTO t1 (a,b) VALUES (NULL,'l');
SELECT * FROM t1 ORDER BY a;
SELECT LAST_INSERT_ID();
--replace_column 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 10 # 12 # 13 # 14 # 15 # 16 # 17 # 18 #
SHOW TABLE STATUS FROM test LIKE 't1';
# Negative values: we will try to insert one just to check that it does not cause a crash,
# but won't check what happens to the sequence after that, since the behavior is undefined
INSERT INTO t1 (a,b) VALUES (-5,'m');
SELECT * FROM t1 ORDER BY a;
DROP TABLE t1;
}
# Autoincrement with table option AUTO_INCREMENT
--let $create_definition = a $int_indexed_col AUTO_INCREMENT, b $char_col, $default_index(a)
--let $table_options = AUTO_INCREMENT = 100
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = AUTO_INCREMENT column or table option
--source unexpected_result.inc
}
if (!$mysql_errname)
{
INSERT INTO t1 (a,b) VALUES (NULL,'a'),(NULL,'b');
--sorted_result
SELECT * FROM t1;
SELECT LAST_INSERT_ID();
DROP TABLE t1;
}
--source cleanup_engine.inc
DROP TABLE IF EXISTS t1, t2;
CREATE TABLE t1 (a <INT_COLUMN>,
b <CHAR_COLUMN>,
<CUSTOM_INDEX> (a)
) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
CREATE TABLE t2 (a <INT_COLUMN>,
b <CHAR_COLUMN>,
<CUSTOM_INDEX> (b)
) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
CACHE INDEX t1 INDEX (a), t2 IN <CACHE_NAME>;
ERROR HY000: Unknown key cache '<CACHE_NAME>'
SET GLOBAL <CACHE_NAME>.key_buffer_size=128*1024;
CACHE INDEX t1 INDEX (a), t2 IN <CACHE_NAME>;
Table Op Msg_type Msg_text
test.t1 assign_to_keycache status OK
test.t2 assign_to_keycache status OK
LOAD INDEX INTO CACHE t1, t2;
Table Op Msg_type Msg_text
test.t1 preload_keys status OK
test.t2 preload_keys status OK
INSERT INTO t1 (a,b) VALUES (3,'c'),(4,'d');
SET GLOBAL <CACHE_NAME>.key_buffer_size=8*1024;
LOAD INDEX INTO CACHE t1, t2 IGNORE LEAVES;
Table Op Msg_type Msg_text
test.t1 preload_keys status OK
test.t2 preload_keys status OK
SET GLOBAL <CACHE_NAME>.key_cache_age_threshold = 100, <CACHE_NAME>.key_cache_block_size = 512, <CACHE_NAME>.key_cache_division_limit = 1, <CACHE_NAME>.key_cache_segments=2;
INSERT INTO t1 (a,b) VALUES (5,'e'),(6,'f');
LOAD INDEX INTO CACHE t1;
Table Op Msg_type Msg_text
test.t1 preload_keys status OK
SET GLOBAL new_<CACHE_NAME>.key_buffer_size=128*1024;
CACHE INDEX t1 IN new_<CACHE_NAME>;
Table Op Msg_type Msg_text
test.t1 assign_to_keycache status OK
INSERT INTO t1 (a,b) VALUES (7,'g'),(8,'h');
LOAD INDEX INTO CACHE t1 IGNORE LEAVES;
Table Op Msg_type Msg_text
test.t1 preload_keys status OK
INSERT INTO t1 (a,b) VALUES (9,'i');
DROP TABLE t2;
DROP TABLE t1;
CREATE TABLE t1 (a <INT_COLUMN>,
b <CHAR_COLUMN>,
<CUSTOM_INDEX> (a),
<CUSTOM_INDEX> (b)
) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
CACHE INDEX t1 IN <CACHE_NAME>;
Table Op Msg_type Msg_text
test.t1 assign_to_keycache status OK
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b');
LOAD INDEX INTO CACHE t1;
Table Op Msg_type Msg_text
test.t1 preload_keys status OK
DROP TABLE t1;
CREATE TABLE t1 (a <INT_COLUMN>,
b <CHAR_COLUMN>,
<CUSTOM_INDEX> a_b (a,b)
) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
CACHE INDEX t1 IN <CACHE_NAME>;
Table Op Msg_type Msg_text
test.t1 assign_to_keycache status OK
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b');
LOAD INDEX INTO CACHE t1;
Table Op Msg_type Msg_text
test.t1 preload_keys status OK
DROP TABLE t1;
SET GLOBAL <CACHE_NAME>.key_buffer_size=0;
SET GLOBAL new_<CACHE_NAME>.key_buffer_size=0;
#
# CACHE INDEX and LOAD INDEX INTO CACHE
#
--source have_engine.inc
--source have_default_index.inc
# Due to ancient MySQL bug#16111 we need to generate a unique cache name
--let $cache_name = `SELECT CONNECTION_ID()`
--let $cache_name = my_cache_$cache_name
--disable_warnings
DROP TABLE IF EXISTS t1, t2;
--enable_warnings
let $create_definition =
a $int_indexed_col,
b $char_col,
$default_index (a)
;
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = Indexes on INT columns
--source unexpected_result.inc
}
if (!$mysql_errname)
{
let $create_definition =
a $int_col,
b $char_indexed_col,
$default_index (b)
;
let $table_name = t2;
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = Indexes on CHAR columns
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--replace_result $cache_name <CACHE_NAME>
--let $error_codes = ER_UNKNOWN_KEY_CACHE
eval CACHE INDEX t1 INDEX (a), t2 IN $cache_name;
--source check_errors.inc
if ($mysql_errname != ER_UNKNOWN_KEY_CACHE)
{
--let $functionality = Key cache or indexes
--source unexpected_result.inc
}
--replace_result $cache_name <CACHE_NAME>
eval SET GLOBAL $cache_name.key_buffer_size=128*1024;
--replace_result $cache_name <CACHE_NAME>
eval CACHE INDEX t1 INDEX (a), t2 IN $cache_name;
if ($mysql_errname)
{
--let $functionality = Indexes
--source unexpected_result.inc
}
LOAD INDEX INTO CACHE t1, t2;
if ($mysql_errname)
{
--let $functionality = Indexes
--source unexpected_result.inc
}
INSERT INTO t1 (a,b) VALUES (3,'c'),(4,'d');
--replace_result $cache_name <CACHE_NAME>
eval SET GLOBAL $cache_name.key_buffer_size=8*1024;
LOAD INDEX INTO CACHE t1, t2 IGNORE LEAVES;
--replace_result $cache_name <CACHE_NAME>
eval SET GLOBAL $cache_name.key_cache_age_threshold = 100, $cache_name.key_cache_block_size = 512, $cache_name.key_cache_division_limit = 1, $cache_name.key_cache_segments=2;
INSERT INTO t1 (a,b) VALUES (5,'e'),(6,'f');
LOAD INDEX INTO CACHE t1;
--replace_result $cache_name <CACHE_NAME>
eval SET GLOBAL new_$cache_name.key_buffer_size=128*1024;
--replace_result $cache_name <CACHE_NAME>
eval CACHE INDEX t1 IN new_$cache_name;
INSERT INTO t1 (a,b) VALUES (7,'g'),(8,'h');
LOAD INDEX INTO CACHE t1 IGNORE LEAVES;
INSERT INTO t1 (a,b) VALUES (9,'i');
DROP TABLE t2;
}
DROP TABLE t1;
}
let $create_definition =
a $int_indexed_col,
b $char_indexed_col,
$default_index (a),
$default_index (b)
;
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = Multiple keys or indexes on INT or CHAR columns
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--replace_result $cache_name <CACHE_NAME>
eval CACHE INDEX t1 IN $cache_name;
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b');
LOAD INDEX INTO CACHE t1;
DROP TABLE t1;
let $create_definition =
a $int_indexed_col,
b $char_indexed_col,
$default_index a_b (a,b)
;
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = Multi-part keys
--source unexpected_result.inc
}
--replace_result $cache_name <CACHE_NAME>
eval CACHE INDEX t1 IN $cache_name;
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b');
LOAD INDEX INTO CACHE t1;
DROP TABLE t1;
}
# Cleanup
--replace_result $cache_name <CACHE_NAME>
eval SET GLOBAL $cache_name.key_buffer_size=0;
--replace_result $cache_name <CACHE_NAME>
eval SET GLOBAL new_$cache_name.key_buffer_size=0;
--source cleanup_engine.inc
#
# Since we run tests in disable_abort_on_error mode, we cannot use --error command,
# and need to check the result manually.
# Usage in a test:
# --let $error_codes = <comma-separated list> # optional, default ''
# --let $mysql_errname = <error name> # optional, default current $mysql_errname (from the last SQL command)
# --let $mysql_errno = <error code> # optional, default current $mysql_errno (from the last SQL command)
#
if ($error_codes == '0')
{
--let $error_codes =
}
if ($error_codes == '')
{
if ($mysql_errname)
{
--echo # ERROR: Statement ended with errno $mysql_errno, errname $mysql_errname (expected to succeed)
}
# If both error_codes and mysql_errname are false, all is good, no logic needed
}
if ($error_codes != '')
{
# If mysql_errname or mysql_errno is equal to $error_codes, it's good too, nothing to do
if ($mysql_errname != $error_codes)
{
if ($mysql_errno != $error_codes)
{
--let $save_errno = $mysql_errno
--let $save_errname = $mysql_errname
--let $codeline = `SELECT CONCAT('\'',REPLACE('$error_codes',',','\',\''),'\'')`
--let $result = `SELECT '$save_errname' IN($codeline) or '$save_errno' IN ($codeline)`
--let $mysql_errno = $save_errno
--let $mysql_errname = $save_errname
if (!$result)
{
if ($mysql_errname)
{
--echo # ERROR: Statement ended with errno $mysql_errno, errname $mysql_errname (expected results: $error_codes)
}
if (!$mysql_errname)
{
--echo # ERROR: Statement succeeded (expected results: $error_codes)
}
}
# If a list contained more than one error, it could be on one of two reasons:
# first, we do not care which code it is, as long as it is one of the listed errors.
# In this case we will suggest to add an rdiff file if the message differs.
# Second, check_errors might be called from a generalized include file or test,
# which runs with different parameters and thus might produce different results for the same statement.
# Then, the message will be stricter, as the difference with the result file is actually a problem
# which needs to be checked at least.
if ($result)
{
if (!$strict_check)
{
--echo # Statement ended with one of expected results ($error_codes).
--echo # If you got a difference in error message, just add it to rdiff file
}
if ($strict_check)
{
--echo # WARNING: Statement ended with errno $mysql_errno, errname '$mysql_errname'.
--echo # If it differs from the result file, it might indicate a problem.
}
}
}
}
}
# Don't want the variables to be accidentally reused later
--let $error_codes =
--let $strict_check =
#
# CHECK TABLE statements
#
# Note: the output is likely to be different for the engine under test,
# in which case rdiff will be needed. Or, the output might say that
# the storage engine does not support CHECK.
#
--disable_warnings
DROP TABLE IF EXISTS t1,t2;
--enable_warnings
--let $create_definition = a $int_col, b $char_col
--source create_table.inc
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b');
--let $table_name = t2
--let $create_definition = a $int_col, b $char_col
--source create_table.inc
CHECK TABLE t1;
INSERT INTO t1 (a,b) VALUES (3,'c');
INSERT INTO t2 (a,b) VALUES (4,'d');
CHECK TABLE t1, t2 FOR UPGRADE;
INSERT INTO t2 (a,b) VALUES (5,'e');
CHECK TABLE t2 QUICK;
INSERT INTO t1 (a,b) VALUES (6,'f');
CHECK TABLE t1 FAST;
INSERT INTO t1 (a,b) VALUES (7,'g');
INSERT INTO t2 (a,b) VALUES (8,'h');
CHECK TABLE t2, t1 MEDIUM;
INSERT INTO t1 (a,b) VALUES (9,'i');
INSERT INTO t2 (a,b) VALUES (10,'j');
CHECK TABLE t1, t2 EXTENDED;
INSERT INTO t1 (a,b) VALUES (11,'k');
CHECK TABLE t1 CHANGED;
DROP TABLE t1, t2;
--let $continue = 1
--source have_default_index.inc
if ($have_default_index)
{
--let $create_definition = a $int_indexed_col, $default_index(a)
--source create_table.inc
INSERT INTO t1 (a) VALUES (1),(2),(5);
CHECK TABLE t1;
INSERT INTO t1 (a) VALUES (6),(8),(12);
CHECK TABLE t1 FOR UPGRADE;
INSERT INTO t1 (a) VALUES (13),(15),(16);
CHECK TABLE t1 QUICK;
INSERT INTO t1 (a) VALUES (17),(120),(132);
CHECK TABLE t1 FAST;
INSERT INTO t1 (a) VALUES (801),(900),(7714);
CHECK TABLE t1 MEDIUM;
INSERT INTO t1 (a) VALUES (8760),(10023),(12000);
CHECK TABLE t1 EXTENDED;
INSERT INTO t1 (a) VALUES (13345),(24456),(78302),(143028);
CHECK TABLE t1 CHANGED;
DROP TABLE t1;
}
DROP TABLE IF EXISTS t1,t2;
CREATE TABLE t1 (a <INT_COLUMN>, b <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b');
CREATE TABLE t2 (a <INT_COLUMN>, b <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
INSERT INTO t1 (a,b) VALUES (3,'c');
INSERT INTO t2 (a,b) VALUES (4,'d');
CHECK TABLE t1, t2 FOR UPGRADE;
Table Op Msg_type Msg_text
test.t1 check status OK
test.t2 check status OK
INSERT INTO t2 (a,b) VALUES (5,'e');
CHECK TABLE t2 QUICK;
Table Op Msg_type Msg_text
test.t2 check status OK
INSERT INTO t1 (a,b) VALUES (6,'f');
CHECK TABLE t1 FAST;
Table Op Msg_type Msg_text
test.t1 check status OK
INSERT INTO t1 (a,b) VALUES (7,'g');
INSERT INTO t2 (a,b) VALUES (8,'h');
CHECK TABLE t2, t1 MEDIUM;
Table Op Msg_type Msg_text
test.t2 check status OK
test.t1 check status OK
INSERT INTO t1 (a,b) VALUES (9,'i');
INSERT INTO t2 (a,b) VALUES (10,'j');
CHECK TABLE t1, t2 EXTENDED;
Table Op Msg_type Msg_text
test.t1 check status OK
test.t2 check status OK
INSERT INTO t1 (a,b) VALUES (11,'k');
CHECK TABLE t1 CHANGED;
Table Op Msg_type Msg_text
test.t1 check status OK
DROP TABLE t1, t2;
CREATE TABLE t1 (a <INT_COLUMN>, <CUSTOM_INDEX>(a)) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a) VALUES (1),(2),(5);
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
INSERT INTO t1 (a) VALUES (6),(8),(12);
CHECK TABLE t1 FOR UPGRADE;
Table Op Msg_type Msg_text
test.t1 check status OK
INSERT INTO t1 (a) VALUES (13),(15),(16);
CHECK TABLE t1 QUICK;
Table Op Msg_type Msg_text
test.t1 check status OK
INSERT INTO t1 (a) VALUES (17),(120),(132);
CHECK TABLE t1 FAST;
Table Op Msg_type Msg_text
test.t1 check status OK
INSERT INTO t1 (a) VALUES (801),(900),(7714);
CHECK TABLE t1 MEDIUM;
Table Op Msg_type Msg_text
test.t1 check status OK
INSERT INTO t1 (a) VALUES (8760),(10023),(12000);
CHECK TABLE t1 EXTENDED;
Table Op Msg_type Msg_text
test.t1 check status OK
INSERT INTO t1 (a) VALUES (13345),(24456),(78302),(143028);
CHECK TABLE t1 CHANGED;
Table Op Msg_type Msg_text
test.t1 check status OK
DROP TABLE t1;
#
# CHECK TABLE statements
#
# Note: the output is likely to be different for the engine under test,
# in which case rdiff will be needed. Or, the output might say that
# the storage engine does not support CHECK.
#
--source have_engine.inc
--source check_table.inc
--source cleanup_engine.inc
#
# CHECKSUM TABLE statements for standard CHECKSUM properties.
# Live checksums are covered in checksum_table_live.test
#
--disable_warnings
DROP TABLE IF EXISTS t1,t2;
--enable_warnings
# For most engines CHECKSUM=0 option will be ignored,
# but we are setting it here for those which have it 1 by default
# (there will be another test for live checksum)
--let $table_options = CHECKSUM=0
--let $create_definition = a $int_col, b $char_col
--source create_table.inc
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b');
--let $table_name = t2
--let $table_options = CHECKSUM=0
--let $create_definition = a $int_col, b $char_col
--source create_table.inc
CHECKSUM TABLE t1;
CHECKSUM TABLE t2, t1;
CHECKSUM TABLE t1, t2 QUICK;
CHECKSUM TABLE t1, t2 EXTENDED;
DROP TABLE t1, t2;
DROP TABLE IF EXISTS t1,t2;
CREATE TABLE t1 (a <INT_COLUMN>, b <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS> CHECKSUM=0;
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b');
CREATE TABLE t2 (a <INT_COLUMN>, b <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS> CHECKSUM=0;
CHECKSUM TABLE t1;
Table Checksum
test.t1 4272806499
CHECKSUM TABLE t2, t1;
Table Checksum
test.t2 0
test.t1 4272806499
CHECKSUM TABLE t1, t2 QUICK;
Table Checksum
test.t1 NULL
test.t2 NULL
CHECKSUM TABLE t1, t2 EXTENDED;
Table Checksum
test.t1 4272806499
test.t2 0
DROP TABLE t1, t2;
#
# CHECKSUM TABLE statements for standard CHECKSUM properties.
# Live checksums are covered in checksum_table_live.test
#
--source have_engine.inc
--source checksum_table.inc
--source cleanup_engine.inc
#
# CHECKSUM TABLE statements for live CHECKSUM.
#
# Note: the feature is likely to be unsupported, in which case
# instead of numeric values some CHECKSUMs will produce NULL
#
--disable_warnings
DROP TABLE IF EXISTS t1,t2;
--enable_warnings
# For most engines CHECKSUM=1 option will be ignored,
# and the results will be different
--let $table_options = CHECKSUM=1
--let $create_definition = a $int_col, b $char_col
--source create_table.inc
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b');
--let $table_name = t2
--let $table_options = CHECKSUM=1
--let $create_definition = a $int_col, b $char_col
--source create_table.inc
CHECKSUM TABLE t1;
CHECKSUM TABLE t2, t1;
CHECKSUM TABLE t1, t2 QUICK;
CHECKSUM TABLE t1, t2 EXTENDED;
DROP TABLE t1, t2;
DROP TABLE IF EXISTS t1,t2;
CREATE TABLE t1 (a <INT_COLUMN>, b <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS> CHECKSUM=1;
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b');
CREATE TABLE t2 (a <INT_COLUMN>, b <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS> CHECKSUM=1;
CHECKSUM TABLE t1;
Table Checksum
test.t1 4272806499
CHECKSUM TABLE t2, t1;
Table Checksum
test.t2 0
test.t1 4272806499
CHECKSUM TABLE t1, t2 QUICK;
Table Checksum
test.t1 4272806499
test.t2 0
CHECKSUM TABLE t1, t2 EXTENDED;
Table Checksum
test.t1 4272806499
test.t2 0
DROP TABLE t1, t2;
#
# CHECKSUM TABLE statements for live CHECKSUM.
#
# Note: the feature is likely to be unsupported, in which case
# instead of numeric values some CHECKSUMs will produce NULL
#
--source have_engine.inc
--source checksum_table_live.inc
--source cleanup_engine.inc
###########################################
#
# This is a stub of the include file cleanup_engine.inc which
# should be placed in storage/<engine>/mysql-test/storage_engine folder.
#
################################
#
# Here you can add whatever is needed to cleanup
# in case your define_engine.inc created any artefacts,
# e.g. an additional schema and/or tables.
#
# NOT NULL attribute in columns
#
# Usage:
# let $col_definition = <column type (and possibly more options)>;
# let $col_default = <default non-null value for a column>;
# --source col_not_null.inc
#
# We will add NOT NULL at the end of $col;
#
# Also, if $col_default is defined,
# we will create a table with 2 columns
# (one with DEFAULT $col_default, and one without any default),
# and will also attempt to add a column with DEFAULT NULL.
#
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
--let $create_definition = c $col_definition NOT NULL
--source create_table.inc
if ($mysql_errname)
{
--source unexpected_result.inc
}
if (!$mysql_errname)
{
SHOW COLUMNS IN t1;
--let $error_codes = ER_BAD_NULL_ERROR
INSERT INTO t1 (c) VALUES (NULL);
--source check_errors.inc
DROP TABLE t1;
}
if ($col_default != '')
{
let $create_definition =
c $col_definition NOT NULL,
c2 $col_definition NOT NULL DEFAULT $col_default
;
--source create_table.inc
if ($mysql_errname)
{
--source unexpected_result.inc
}
if (!$mysql_errname)
{
SHOW COLUMNS IN t1;
--let $error_codes = ER_INVALID_DEFAULT
--let $alter_definition = ADD COLUMN err $col_definition NOT NULL DEFAULT NULL
--source alter_table.inc
if ($mysql_errname != ER_INVALID_DEFAULT)
{
--let $functionality = ALTER or DEFAULT
--source unexpected_result.inc
}
--let $error_codes = ER_BAD_NULL_ERROR
INSERT INTO t1 (c) VALUES (NULL);
--source check_errors.inc
if ($mysql_errname != ER_BAD_NULL_ERROR)
{
--let $functionality = NOT NULL columns
--source unexpected_result.inc
}
# HEX should be universal for all column types
SELECT HEX(c), HEX(c2) FROM t1;
--let $error_codes = ER_BAD_NULL_ERROR
INSERT INTO t1 (c2) VALUES (NULL);
--source check_errors.inc
--eval INSERT INTO t1 (c) VALUES ($col_default)
if ($mysql_errname)
{
--let $functionality = DEFAULT
--source unexpected_result.inc
}
SELECT COUNT(c), COUNT(c2) FROM t1;
DROP TABLE t1;
}
}
# We don't want to preserve it
let $col_default = ;
#
# NULL attribute and DEFAULT NULL in columns
#
# Usage:
# let $col_definition = <column type (and possibly more options)>;
# let $col_default = <default non-null value for a column>;
# --source col_null.inc
#
# We will add NULL at the end of $col;
#
# Also, if $col_default is defined,
# we will create a table with 3 columns (one with DEFAULT NULL,
# one with DEFAULT $col_default, and one without any default)
#
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
--let $create_definition = c $col_definition NULL
--source create_table.inc
SHOW COLUMNS IN t1;
if ($mysql_errname)
{
--source unexpected_result.inc
}
if (!$mysql_errname)
{
INSERT INTO t1 (c) VALUES (NULL);
if ($mysql_errname)
{
--let $functionality = NULLable columns
--source unexpected_result.inc
}
SELECT COUNT(c), COUNT(*) FROM t1;
DROP TABLE t1;
}
if ($col_default != '')
{
let $create_definition =
c $col_definition NULL,
c1 $col_definition NULL DEFAULT NULL,
c2 $col_definition NULL DEFAULT $col_default
;
--source create_table.inc
if ($mysql_errname)
{
--source unexpected_result.inc
}
if (!$mysql_errname)
{
SHOW COLUMNS IN t1;
INSERT INTO t1 (c) VALUES (NULL);
SELECT COUNT(c2), COUNT(c1), COUNT(c), COUNT(*) FROM t1;
DROP TABLE t1;
}
}
# We don't want to preserve it
let $col_default = ;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a <INT_COLUMN> DEFAULT '0') ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
SHOW COLUMNS IN t1;
Field Type Null Key Default Extra
a int(11) # 0
INSERT INTO t1 (a) VALUES (1);
SELECT * FROM t1;
a
1
ALTER TABLE t1 ADD COLUMN b <CHAR_COLUMN> DEFAULT '';
SHOW COLUMNS IN t1;
Field Type Null Key Default Extra
a int(11) # 0
b char(8) #
INSERT INTO t1 (b) VALUES ('a');
SELECT * FROM t1;
a b
0 a
1
DROP TABLE t1;
#
# Check whether DEFAULT column attribute
# is supported in CREATE and ALTER TABLE.
# If the attribute is supported at all, it will be covered
# in more details in col_option_null and col_option_not_null tests.
#
--source have_engine.inc
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
--let $create_definition = a $int_col DEFAULT '0'
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = DEFAULT values
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--replace_column 3 #
SHOW COLUMNS IN t1;
INSERT INTO t1 (a) VALUES (1);
--sorted_result
SELECT * FROM t1;
--let $alter_definition = ADD COLUMN b $char_col DEFAULT ''
--source alter_table.inc
if ($mysql_errname)
{
--let $functionality = ALTER or DEFAULT
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--replace_column 3 #
SHOW COLUMNS IN t1;
INSERT INTO t1 (b) VALUES ('a');
--sorted_result
SELECT * FROM t1;
}
DROP TABLE t1;
}
--source cleanup_engine.inc
This source diff could not be displayed because it is too large. You can view the blob instead.
#
# NOT NULL column attribute
#
let $extra_col_opts = NOT NULL;
--source have_engine.inc
--echo #
--echo # BINARY columns
--echo #
--source type_binary.inc
--let $col_definition = BINARY $default_col_opts
--let $col_default = 0
--source col_not_null.inc
--echo #
--echo # VARBINARY columns
--echo #
--source type_varbinary.inc
--let $col_definition = VARBINARY(64) $default_col_opts
--let $col_default = 'test'
--source col_not_null.inc
--echo #
--echo # BIT columns
--echo #
--source type_bit.inc
--let $col_definition = BIT $default_col_opts
--let $col_default = 1
--source col_not_null.inc
--echo #
--echo # BLOB columns
--echo #
--source type_blob.inc
--let $col_definition = BLOB $default_col_opts
--source col_not_null.inc
--let $col_definition = TINYBLOB $default_col_opts
--source col_not_null.inc
--let $col_definition = MEDIUMBLOB $default_col_opts
--source col_not_null.inc
--let $col_definition = LONGBLOB $default_col_opts
--source col_not_null.inc
--echo #
--echo # BOOL columns
--echo #
--source type_bool.inc
--let $col_definition = BOOL $default_col_opts
--let $col_default = '0'
--source col_not_null.inc
--echo #
--echo # CHAR columns
--echo #
--source type_char.inc
--let $col_definition = CHAR $default_col_opts
--let $col_default = '_'
--source col_not_null.inc
--echo #
--echo # VARCHAR columns
--echo #
--source type_varchar.inc
--let $col_definition = VARCHAR(64) $default_col_opts
--let $col_default = 'test default'
--source col_not_null.inc
--echo #
--echo # date and time columns
--echo #
--source type_date_time.inc
--let $col_definition = DATE $default_col_opts
--let $col_default = '2012-12-21'
--source col_not_null.inc
--let $col_definition = DATETIME $default_col_opts
--let $col_default = '2012-12-21 12:21:12'
--source col_not_null.inc
# For TIMESTAMP the behavior is non-standard
# $col_opts already contains NOT NULL part (it's set in have_engine.inc)
let $create_definition =
c TIMESTAMP $col_opts,
c2 TIMESTAMP $col_opts DEFAULT '2012-02-21 12:21:12'
;
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = TIMESTAMP type or NOT NULL columns or DEFAULT
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--let $error_codes = ER_INVALID_DEFAULT
--let $alter_definition = ADD COLUMN err TIMESTAMP $col_opts DEFAULT NULL
--source alter_table.inc
if ($mysql_errname!=ER_INVALID_DEFAULT)
{
--let $functionality = ALTER or DEFAULT
--source unexpected_result.inc
}
INSERT INTO t1 (c) VALUES (NULL);
INSERT INTO t1 (c2) VALUES (NULL);
--replace_regex /2012-02-21 12:21:12/<DEFAULT_TIMESTAMP>/ /[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}/<TIMESTAMP>/
SELECT c, c2 FROM t1;
DROP TABLE t1;
}
--let $create_definition = c TIMESTAMP $col_opts
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = TIMESTAMP type
--source unexpected_result.inc
}
if (!$mysql_errname)
{
SHOW COLUMNS IN t1;
INSERT INTO t1 (c) VALUES (NULL);
if ($mysql_errname)
{
--let $functionality = TIMESTAMP
--source unexpected_result.inc
}
--replace_regex /[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}/<TIMESTAMP>/
SELECT * FROM t1;
DROP TABLE t1;
}
# End of TIMESTAMP exception
--let $col_definition = TIME $default_col_opts
--let $col_default = '12:21:12'
--source col_not_null.inc
--let $col_definition = YEAR $default_col_opts
--let $col_default = '2012'
--source col_not_null.inc
--let $col_definition = YEAR(2) $default_col_opts
--let $col_default = '12'
--source col_not_null.inc
--echo #
--echo # ENUM columns
--echo #
--source type_enum.inc
--let $col_definition = ENUM('test1','test2','test3') $default_col_opts
--let $col_default = 'test2'
--source col_not_null.inc
--echo #
--echo # Fixed point columns (NUMERIC, DECIMAL)
--echo #
--source type_fixed.inc
--let $col_definition = DECIMAL $default_col_opts
--let $col_default = 1.1
--source col_not_null.inc
--let $col_definition = NUMERIC $default_col_opts
--let $col_default = 0
--source col_not_null.inc
--echo #
--echo # Floating point columns (FLOAT, DOUBLE)
--echo #
--source type_float.inc
--let $col_definition = FLOAT $default_col_opts
--let $col_default = 1.1
--source col_not_null.inc
--let $col_definition = DOUBLE $default_col_opts
--let $col_default = 0
--source col_not_null.inc
--echo #
--echo # INT columns
--echo #
--source type_int.inc
--let $col_definition = INT $default_col_opts
--let $col_default = 2147483647
--source col_not_null.inc
--let $col_definition = TINYINT $default_col_opts
--let $col_default = 127
--source col_not_null.inc
--let $col_definition = SMALLINT $default_col_opts
--let $col_default = 0
--source col_not_null.inc
--let $col_definition = MEDIUMINT $default_col_opts
--let $col_default = 1
--source col_not_null.inc
--let $col_definition = BIGINT $default_col_opts
--let $col_default = 9223372036854775807
--source col_not_null.inc
--echo #
--echo # SET columns
--echo #
--source type_set.inc
--let $col_definition = SET('test1','test2','test3') $default_col_opts
--let $col_default = 'test2,test3'
--source col_not_null.inc
--echo #
--echo # TEXT columns
--echo #
--source type_text.inc
--let $col_definition = TEXT $default_col_opts
--source col_not_null.inc
--let $col_definition = TINYTEXT $default_col_opts
--source col_not_null.inc
--let $col_definition = MEDIUMTEXT $default_col_opts
--source col_not_null.inc
--let $col_definition = LONGTEXT $default_col_opts
--source col_not_null.inc
--source cleanup_engine.inc
This source diff could not be displayed because it is too large. You can view the blob instead.
#
# NULL column attribute
#
let $extra_col_opts = NULL;
--source have_engine.inc
--echo #
--echo # BINARY columns
--echo #
--source type_binary.inc
--let $col_definition = BINARY $default_col_opts
--let $col_default = 0
--source col_null.inc
--echo #
--echo # VARBINARY columns
--echo #
--source type_varbinary.inc
--let $col_definition = VARBINARY(64) $default_col_opts
--let $col_default = 'test'
--source col_null.inc
--echo #
--echo # BIT columns
--echo #
--source type_bit.inc
--let $col_definition = BIT $default_col_opts
--let $col_default = 1
--source col_null.inc
--echo #
--echo # BLOB columns
--echo #
--source type_blob.inc
--let $col_definition = BLOB $default_col_opts
--source col_null.inc
--let $col_definition = TINYBLOB $default_col_opts
--source col_null.inc
--let $col_definition = MEDIUMBLOB $default_col_opts
--source col_null.inc
--let $col_definition = LONGBLOB $default_col_opts
--source col_null.inc
--echo #
--echo # BOOL columns
--echo #
--source type_bool.inc
--let $col_definition = BOOL $default_col_opts
--let $col_default = '0'
--source col_null.inc
--echo #
--echo # CHAR columns
--echo #
--source type_char.inc
--let $col_definition = CHAR $default_col_opts
--let $col_default = '_'
--source col_null.inc
--echo #
--echo # VARCHAR columns
--echo #
--source type_varchar.inc
--let $col_definition = VARCHAR(64) $default_col_opts
--let $col_default = 'test default'
--source col_null.inc
--echo #
--echo # date and time columns
--echo #
--source type_date_time.inc
--let $col_definition = DATE $default_col_opts
--let $col_default = '2012-12-21'
--source col_null.inc
--let $col_definition = DATETIME $default_col_opts
--let $col_default = '2012-12-21 12:21:12'
--source col_null.inc
--let $col_definition = TIMESTAMP $default_col_opts
--let $col_default = '2012-12-21 12:21:12'
--source col_null.inc
--let $col_definition = TIME $default_col_opts
--let $col_default = '12:21:12'
--source col_null.inc
--let $col_definition = YEAR $default_col_opts
--let $col_default = '2012'
--source col_null.inc
--let $col_definition = YEAR(2) $default_col_opts
--let $col_default = '12'
--source col_null.inc
--echo #
--echo # ENUM columns
--echo #
--source type_enum.inc
--let $col_definition = ENUM('test1','test2','test3') $default_col_opts
--let $col_default = 'test2'
--source col_null.inc
--echo #
--echo # Fixed point columns (NUMERIC, DECIMAL)
--echo #
--source type_fixed.inc
--let $col_definition = DECIMAL $default_col_opts
--let $col_default = 1.1
--source col_null.inc
--let $col_definition = NUMERIC $default_col_opts
--let $col_default = 0
--source col_null.inc
--echo #
--echo # Floating point columns (FLOAT, DOUBLE)
--echo #
--source type_float.inc
--let $col_definition = FLOAT $default_col_opts
--let $col_default = 1.1
--source col_null.inc
--let $col_definition = DOUBLE $default_col_opts
--let $col_default = 0
--source col_null.inc
--echo #
--echo # INT columns
--echo #
--source type_int.inc
--let $col_definition = INT $default_col_opts
--let $col_default = 2147483647
--source col_null.inc
--let $col_definition = TINYINT $default_col_opts
--let $col_default = 127
--source col_null.inc
--let $col_definition = SMALLINT $default_col_opts
--let $col_default = 0
--source col_null.inc
--let $col_definition = MEDIUMINT $default_col_opts
--let $col_default = 1
--source col_null.inc
--let $col_definition = BIGINT $default_col_opts
--let $col_default = 9223372036854775807
--source col_null.inc
--echo #
--echo # SET columns
--echo #
--source type_set.inc
--let $col_definition = SET('test1','test2','test3') $default_col_opts
--let $col_default = 'test2,test3'
--source col_null.inc
--echo #
--echo # TEXT columns
--echo #
--source type_text.inc
--let $col_definition = TEXT $default_col_opts
--source col_null.inc
--let $col_definition = TINYTEXT $default_col_opts
--source col_null.inc
--let $col_definition = MEDIUMTEXT $default_col_opts
--source col_null.inc
--let $col_definition = LONGTEXT $default_col_opts
--source col_null.inc
--source cleanup_engine.inc
This diff is collapsed.
#
# UNSIGNED column attribute
#
let $extra_type_opts = UNSIGNED;
--source have_engine.inc
--echo #
--echo # Fixed point columns (NUMERIC, DECIMAL)
--echo #
--source type_fixed.inc
let $create_definition =
a DECIMAL $col_opts,
b NUMERIC $col_opts
;
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = Fixed point types or UNSIGNED columns
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--replace_column 3 # 4 # 5 # 6 #
SHOW COLUMNS IN t1;
INSERT INTO t1 (a,b) VALUES (1.0,-1.0);
INSERT INTO t1 (a,b) VALUES (-100,100);
--sorted_result
SELECT * FROM t1;
DROP TABLE t1;
}
--echo #
--echo # Floating point columns (FLOAT, DOUBLE)
--echo #
--source type_float.inc
let $create_definition =
a DOUBLE $col_opts,
b FLOAT $col_opts
;
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = Floating point types or UNSIGNED columns
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--replace_column 3 # 4 # 5 # 6 #
SHOW COLUMNS IN t1;
INSERT INTO t1 (a,b) VALUES (1.0,-1.0);
INSERT INTO t1 (a,b) VALUES (-100,100);
--sorted_result
SELECT * FROM t1;
DROP TABLE t1;
}
--echo #
--echo # INT columns
--echo #
--source type_int.inc
let $create_definition =
t TINYINT $col_opts,
s SMALLINT $col_opts,
m MEDIUMINT $col_opts,
i INT $col_opts,
b BIGINT $col_opts
;
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = INT types or UNSIGNED columns
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--replace_column 3 # 4 # 5 # 6 #
SHOW COLUMNS IN t1;
INSERT INTO t1 (t,s,m,i,b) VALUES (255,65535,16777215,4294967295,18446744073709551615);
INSERT INTO t1 (t,s,m,i,b) VALUES (-1,-1,-1,-1,-1);
--sorted_result
SELECT * FROM t1;
DROP TABLE t1;
}
--source cleanup_engine.inc
This diff is collapsed.
#
# ZEROFILL column attribute
#
let $extra_type_opts = ZEROFILL;
--source have_engine.inc
--echo #
--echo # Fixed point columns (NUMERIC, DECIMAL)
--echo #
--source type_fixed.inc
let $create_definition =
a DECIMAL $col_opts,
b NUMERIC $col_opts
;
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = Fixed point types or ZEROFILL columns
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--replace_column 3 # 4 # 5 # 6 #
SHOW COLUMNS IN t1;
INSERT INTO t1 (a,b) VALUES (1.1,1234);
SELECT * FROM t1;
DROP TABLE t1;
}
--echo #
--echo # Floating point columns (FLOAT, DOUBLE)
--echo #
--source type_float.inc
let $create_definition =
a DOUBLE $col_opts,
b FLOAT $col_opts
;
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = Floating point types or ZEROFILL columns
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--replace_column 3 # 4 # 5 # 6 #
SHOW COLUMNS IN t1;
INSERT INTO t1 (a,b) VALUES (1,1234.5);
SELECT * FROM t1;
DROP TABLE t1;
}
--echo #
--echo # INT columns
--echo #
--source type_int.inc
let $create_definition =
t TINYINT $col_opts,
s SMALLINT $col_opts,
m MEDIUMINT $col_opts,
i INT $col_opts,
b BIGINT $col_opts
;
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = INT types or UNSIGNED columns
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--replace_column 3 # 4 # 5 # 6 #
SHOW COLUMNS IN t1;
INSERT INTO t1 (t,s,m,i,b) VALUES (1,10,100,1000,0);
SELECT * FROM t1;
DROP TABLE t1;
}
--source cleanup_engine.inc
##################################
#
# This include file will be used for all CREATE TABLE statements in the suite.
# If you need to add additional steps or change the logic, copy the file
# to storage/<engine>/mysql-test/storage_engine/ folder and modify it there.
#
##################
#
# Parameters:
#
# --let $create_definition = <column names, types, indexes) # optional, default a $int_col, b $char_col (based on defaults)
# --let $table_name = <table name> # optional, default t1
# --let $table_options = <table options> # optional, default based on define_engine.inc
# --let $partition_options = <partitioning definition> # optional, default none
# --let $as_select = <SELECT statement> # optional, default empty
# --let $error_codes = <expected error codes, as in --error> # optional, default 0
# --let $if_not_exists = [0|1] # optional, default 0 (1 adds IF NOT EXISTS clause)
# --let $default_engine = [0|1] # optional, default 0 (with 1 will rely on default engine, no ENGINE=)
# --let $temporary = [0|1] # optional, default 0 (1 adds TEMPORARY)
# --let $disable_query_log = [0|1] # optional, default 0 (1 disables logging of CREATE)
#
# Usage examples:
#
# --source create_table.inc -- creates a default table
#
# --let $create_definition = a INT NOT NULL, b CHAR(1) PRIMARY KEY, INDEX(a)
# --let $table_options = AUTO_INCREMENT = 100
# --let $partition_options = PARTITION BY HASH(a) PARTITIONS 2
# --let $as_select = SELECT 1, 'a'
# --source create_table.inc
#
# Additionally, a test can define $extra_tbl_options. The difference with $table_options
# is that its value is persistent and will be used until it is unset explicitly, or
# until the test ends. The purpose of it is to allow one test to call another test,
# when the called test does not know about specific options the calling test might require,
# and thus cannot set them on per-create basis.
--let $create_statement = CREATE
if ($temporary)
{
--let $create_statement = $create_statement TEMPORARY
}
--let $create_statement = $create_statement TABLE
if ($if_not_exists)
{
--let $create_statement = $create_statement IF NOT EXISTS
}
if (!$table_name)
{
--let $table_name = t1
}
--let $create_statement = $create_statement $table_name
if (!$create_definition)
{
# If $create_definition is not defined, and AS SELECT is requested,
# we should not set $create_definition to the default value,
# because it might be inconsistent with the SELECT.
if (!$as_select)
{
--let $create_definition = a $int_col, b $char_col
}
}
if ($create_definition)
{
--let $create_statement = $create_statement ($create_definition)
}
# If $default_engine is set, we will rely on the default storage engine
if (!$default_engine)
{
--let $create_statement = $create_statement ENGINE=$storage_engine
}
# Default table options from define_engine.inc
--let $create_statement = $create_statement $default_tbl_opts
# The calling script could request additional table options
if ($table_options)
{
--let $create_statement = $create_statement $table_options
}
# The difference between $extra_tbl_opts and $table_options
# is that its $extra_tbl_opts is persistent -- it will not be unset at the end of this file,
# and will be used until it is unset explicitly by the calling test,
# or until the test ends. The purpose of it is to allow one test to call another test,
# when the called test does not know about specific options the calling test might require,
# and thus cannot set them on per-create basis.
if ($extra_tbl_opts)
{
--let $create_statement = $create_statement $extra_tbl_opts
}
if ($as_select)
{
--let $create_statement = $create_statement AS $as_select
}
if ($partition_options)
{
--let $create_statement = $create_statement $partition_options
}
# We now have the complete CREATE statement in $create_statement.
# If your CREATE statement should be composed differently,
# modify the logic above.
#####################
# Here you can add logic needed BEFORE the main table creation
# (e.g. the table needs a base table, a reference table, etc.).
# Surround it by --disable_query_log/--enable_query_log
# if you don't want it to appear in the result output.
#####################
if ($disable_query_log)
{
--disable_query_log
}
--source obfuscate.inc
eval $create_statement;
--source strict_check_errors.inc
# Make sure you don't add any statements between the main CREATE (above)
# and saving mysql_errno and mysql_errname (below)
# They are saved in case you want to add more logic after the main CREATE,
# because we need the result code of the table creation.
# Also, do not change $create_statement after it is executed!
--let $my_errno = $mysql_errno
--let $my_errname = $mysql_errname
if ($disable_query_log)
{
--enable_query_log
}
#####################
# Here you can add logic needed AFTER the main table creation,
# e.g. triggers creation.
# Surround it by --disable_query_log/--enable_query_log
# if you don't want it to appear in the result output.
#####################
# Unset the parameters, we don't want them to be accidentally reused later
--let $create_definition =
--let $table_name = t1
--let $table_options =
--let $partition_options =
--let $as_select = 0
--let $error_codes =
--let $if_not_exists = 0
--let $default_engine = 0
--let $temporary = 0
--let $disable_query_log = 0
# Restore the error codes of the main statement
--let $mysql_errno = $my_errno
--let $mysql_errname = $my_errname
# Make sure you don't add any SQL statements after restoring
# mysql_errno and mysql_errname (above)
DROP TABLE IF EXISTS t1,t2;
CREATE TABLE t1 (a <INT_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
CREATE TABLE IF NOT EXISTS t1 (a <INT_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
Warnings:
Note 1050 Table 't1' already exists
CREATE TABLE t2 LIKE t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
CREATE TEMPORARY TABLE t2 LIKE t1;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TEMPORARY TABLE `t2` (
`a` int(11) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
DROP TEMPORARY TABLE t2;
DROP TABLE t2;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS> AS SELECT 1 UNION SELECT 2;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`1` bigint(20) NOT NULL DEFAULT '0'
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
SELECT * FROM t1;
1
1
2
DROP TABLE t1;
SET storage_engine = <STORAGE_ENGINE>;
CREATE TABLE t1 (a <INT_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
FLUSH LOGS;
DROP TABLE IF EXISTS t1;
#
# Basic CREATE TABLE statements
#
--source have_engine.inc
--disable_warnings
DROP TABLE IF EXISTS t1,t2;
--enable_warnings
# Simple create table with minimal table options
# which are defined in have_engine.inc
# (default empty) plus ENGINE=
--let $create_definition = a $int_col
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = CREATE TABLE
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--source mask_engine.inc
SHOW CREATE TABLE t1;
# IF NOT EXISTS
--let $if_not_exists = 1
--let $create_definition = a $int_col
--source create_table.inc
}
# CREATE .. LIKE
CREATE TABLE t2 LIKE t1;
if ($mysql_errname)
{
--let $functionality = CREATE TABLE .. LIKE
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--source mask_engine.inc
SHOW CREATE TABLE t2;
eval
CREATE TEMPORARY TABLE t2 LIKE t1;
if ($mysql_errname)
{
--let $functionality = Temporary tables
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--source mask_engine.inc
SHOW CREATE TABLE t2;
DROP TEMPORARY TABLE t2;
}
DROP TABLE t2;
}
DROP TABLE IF EXISTS t1;
# CREATE .. AS SELECT
--let $as_select = SELECT 1 UNION SELECT 2
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = CREATE TABLE .. AS SELECT
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--source mask_engine.inc
SHOW CREATE TABLE t1;
--sorted_result
SELECT * FROM t1;
DROP TABLE t1;
}
# Use the engine as default
--source mask_engine.inc
eval SET storage_engine = $storage_engine;
--let $tbl_opts = $default_tbl_opts
--let $create_definition = a $int_col
--source create_table.inc
if ($mysql_errname)
{
--let $functionality = CREATE TABLE or using the engine as default
--source unexpected_result.inc
}
if (!$mysql_errname)
{
--source mask_engine.inc
SHOW CREATE TABLE t1;
}
# Just to add FLUSH LOGS into the mix while we are in the most common test
FLUSH LOGS;
DROP TABLE IF EXISTS t1;
--source cleanup_engine.inc
###########################################
#
# This is a template of the include file define_engine.inc which
# should be placed in storage/<engine>/mysql-test/storage_engine folder.
#
################################
#
# The name of the engine under test must be defined in $ENGINE variable.
# You can set it either here (uncomment and edit) or in your environment.
#
# let $ENGINE =;
#
################################
#
# The following three variables define specific options for columns and tables.
# Normally there should be none needed, but for some engines it can be different.
# If the engine requires specific column option for all or indexed columns,
# set them inside the comment, e.g. /*!NOT NULL*/.
# Do the same for table options if needed, e.g. /*!INSERT_METHOD=LAST*/
let $default_col_opts = /*!*/;
let $default_col_indexed_opts = /*!*/;
let $default_tbl_opts = /*!*/;
# INDEX, UNIQUE INDEX, PRIMARY KEY, special index type - choose the fist that the engine allows,
# or set it to /*!*/ if none is supported
let $default_index = /*!INDEX*/;
# If the engine does not support the following types, replace them with the closest possible
let $default_int_type = INT(11);
let $default_char_type = CHAR(8);
################################
--disable_query_log
--disable_result_log
# Here you can place your custom MTR code which needs to be executed before each test,
# e.g. creation of an additional schema or table, etc.
# The cleanup part should be defined in cleanup_engine.inc
--enable_query_log
--enable_result_log
DROP TABLE IF EXISTS t1,t2;
CREATE TABLE t1 (a <INT_COLUMN>, b <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a,b) VALUES (10000,'foobar'),(1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e');
INSERT INTO t1 (a,b) SELECT a, b FROM t1;
DELETE FROM t1 WHERE b IN ('c');
SELECT * FROM t1;
a b
1 a
1 a
10000 foobar
10000 foobar
2 b
2 b
4 d
4 d
5 e
5 e
DELETE FROM t1 WHERE a < 0 OR b = 'a';
SELECT * FROM t1;
a b
10000 foobar
10000 foobar
2 b
2 b
4 d
4 d
5 e
5 e
DELETE FROM t1 WHERE a <= 4 ORDER BY b DESC LIMIT 1;
SELECT * FROM t1;
a b
10000 foobar
10000 foobar
2 b
2 b
4 d
5 e
5 e
CREATE TABLE t2 (c <CHAR_COLUMN>, d <INT_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t2 (c,d) SELECT b, a FROM t1;
SELECT * FROM t2;
c d
b 2
b 2
d 4
e 5
e 5
foobar 10000
foobar 10000
DELETE t2.* FROM t1, t2 WHERE c < b AND a + d != 1;
SELECT * FROM t1;
a b
10000 foobar
10000 foobar
2 b
2 b
4 d
5 e
5 e
SELECT * FROM t2;
c d
foobar 10000
foobar 10000
DELETE FROM t2, t1.* USING t2, t1 WHERE c = 'foobar' and b = c;
SELECT * FROM t1;
a b
2 b
2 b
4 d
5 e
5 e
SELECT * FROM t2;
c d
DELETE FROM t1;
SELECT * FROM t1;
a b
DROP TABLE t1, t2;
#
# Basic DELETE statements.
# DELETE LOW_PRIORITY is covered in delete_low_prio test
# DELETE QUICK is covered in delete_quick test (syntax only)
# DELETE IGNORE is covered in delete_ignore test
#
--source have_engine.inc
--disable_warnings
DROP TABLE IF EXISTS t1,t2;
--enable_warnings
--let $create_definition = a $int_col, b $char_col
--source create_table.inc
INSERT INTO t1 (a,b) VALUES (10000,'foobar'),(1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e');
INSERT INTO t1 (a,b) SELECT a, b FROM t1;
# Single-table DELETE
DELETE FROM t1 WHERE b IN ('c');
if ($mysql_errname)
{
--let $functionality = DELETE FROM
--source unexpected_result.inc
}
--sorted_result
SELECT * FROM t1;
DELETE FROM t1 WHERE a < 0 OR b = 'a';
--sorted_result
SELECT * FROM t1;
# ORDER BY and LIMIT
DELETE FROM t1 WHERE a <= 4 ORDER BY b DESC LIMIT 1;
--sorted_result
SELECT * FROM t1;
# Multi-table DELETE
--let $create_definition = c $char_col, d $int_col
--let $table_name = t2
--source create_table.inc
INSERT INTO t2 (c,d) SELECT b, a FROM t1;
--sorted_result
SELECT * FROM t2;
DELETE t2.* FROM t1, t2 WHERE c < b AND a + d != 1;
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM t2;
DELETE FROM t2, t1.* USING t2, t1 WHERE c = 'foobar' and b = c;
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM t2;
DELETE FROM t1;
--sorted_result
SELECT * FROM t1;
# Cleanup
DROP TABLE t1, t2;
--source cleanup_engine.inc
DROP TABLE IF EXISTS t1,t2;
CREATE TABLE t1 (a <INT_COLUMN>, b <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a,b) VALUES (10000,'foobar'),(1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e');
INSERT INTO t1 (a,b) SELECT a, b FROM t1;
CREATE TABLE t2 (c <CHAR_COLUMN>, d <INT_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t2 (c,d) SELECT b, a FROM t1;
SELECT * FROM t1;
a b
1 a
1 a
10000 foobar
10000 foobar
2 b
2 b
3 c
3 c
4 d
4 d
5 e
5 e
SELECT * FROM t2;
c d
a 1
a 1
b 2
b 2
c 3
c 3
d 4
d 4
e 5
e 5
foobar 10000
foobar 10000
DELETE IGNORE FROM t1 WHERE b IS NOT NULL ORDER BY a LIMIT 1;
SELECT * FROM t1;
a b
1 a
10000 foobar
10000 foobar
2 b
2 b
3 c
3 c
4 d
4 d
5 e
5 e
DELETE IGNORE t1.*, t2.* FROM t1, t2 WHERE c < b OR a != ( SELECT 1 UNION SELECT 2 );
Warnings:
Warning 1242 Subquery returns more than 1 row
SELECT * FROM t1;
a b
1 a
SELECT * FROM t2;
c d
foobar 10000
foobar 10000
DROP TABLE t1, t2;
#
# DELETE IGNORE
#
--source have_engine.inc
--disable_warnings
DROP TABLE IF EXISTS t1,t2;
--enable_warnings
--let $create_definition = a $int_col, b $char_col
--source create_table.inc
INSERT INTO t1 (a,b) VALUES (10000,'foobar'),(1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e');
INSERT INTO t1 (a,b) SELECT a, b FROM t1;
--let $create_definition = c $char_col, d $int_col
--let $table_name = t2
--source create_table.inc
INSERT INTO t2 (c,d) SELECT b, a FROM t1;
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM t2;
DELETE IGNORE FROM t1 WHERE b IS NOT NULL ORDER BY a LIMIT 1;
if ($mysql_errname)
{
--let $functionality = DELETE IGNORE FROM ..
--source unexpected_result.inc
}
--sorted_result
SELECT * FROM t1;
DELETE IGNORE t1.*, t2.* FROM t1, t2 WHERE c < b OR a != ( SELECT 1 UNION SELECT 2 );
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM t2;
# Cleanup
DROP TABLE t1, t2;
--source cleanup_engine.inc
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a <INT_COLUMN>, b <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a,b) VALUES (1,'f'),(2,'b');
SET LOW_PRIORITY_UPDATES = 0;
SET lock_wait_timeout = 4;
connect con1,localhost,root,,;
SET lock_wait_timeout = 2;
SELECT SLEEP(1) FROM t1;
connection default;
DELETE FROM t1;
connect con2,localhost,root,,;
SET lock_wait_timeout = 3;
SELECT SLEEP(1) FROM t1;
SLEEP(1)
connection con1;
SLEEP(1)
0
0
connection default;
SELECT * FROM t1;
a b
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b');
connection con1;
SELECT SLEEP(1) FROM t1;
connection default;
DELETE LOW_PRIORITY FROM t1;
connection con2;
SELECT SLEEP(1) FROM t1;
SLEEP(1)
0
0
connection con1;
SLEEP(1)
0
0
connection default;
SELECT * FROM t1;
a b
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b');
SET LOW_PRIORITY_UPDATES = 1;
connection con1;
SELECT SLEEP(1) FROM t1;
connection default;
DELETE FROM t1;
connection con2;
SELECT SLEEP(1) FROM t1;
SLEEP(1)
0
0
connection con1;
SLEEP(1)
0
0
connection default;
SELECT * FROM t1;
a b
disconnect con1;
disconnect con2;
DROP TABLE t1;
This diff is collapsed.
DROP TABLE IF EXISTS t1,t2;
CREATE TABLE t1 (a <INT_COLUMN>, <CUSTOM_INDEX> (a), b <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e');
DELETE QUICK FROM t1 WHERE a = 1 OR b > 'foo';
SELECT * FROM t1;
a b
2 b
3 c
4 d
5 e
CREATE TABLE t2 (c <CHAR_COLUMN>, d <INT_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t2 SELECT b, a FROM t1;
SELECT * FROM t2;
c d
b 2
c 3
d 4
e 5
DELETE QUICK FROM t2, t1.* USING t2, t1 WHERE c IS NULL OR a = d;
SELECT * FROM t1;
a b
SELECT * FROM t2;
c d
DROP TABLE t2;
DROP TABLE t1;
This diff is collapsed.
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a <INT_COLUMN>, b <CHAR_COLUMN>, <CUSTOM_INDEX> (b)) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e'),(6,'x'),(7,'y'),(8,'z');
DELETE FROM t1 WHERE b > 'y';
DELETE FROM t1 WHERE a=2;
SELECT * FROM t1;
a b
1 a
3 c
4 d
5 e
6 x
7 y
DELETE FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a <INT_COLUMN> PRIMARY KEY, b <CHAR_COLUMN>) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e'),(6,'x'),(7,'y'),(8,'z');
DELETE FROM t1 WHERE b > 'y';
DELETE FROM t1 WHERE a=2;
SELECT * FROM t1;
a b
1 a
3 c
4 d
5 e
6 x
7 y
DELETE FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a <INT_COLUMN>, b <INT_COLUMN>, c <INT_COLUMN>, <CUSTOM_INDEX>(a), <CUSTOM_INDEX>(b)) ENGINE=<STORAGE_ENGINE> <CUSTOM_TABLE_OPTIONS>;
INSERT INTO t1 (a,b,c) VALUES (1,2,3),(4,5,6),(7,8,9);
DELETE FROM t1 WHERE a = 10 OR b = 20 ORDER BY c LIMIT 1;
SELECT * FROM t1;
a b c
1 2 3
4 5 6
7 8 9
DROP TABLE t1;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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