revision-id: 65c5ef9b495bac078ad2a502a75801c7cfe5b95a (mariadb-10.3.12-43-g65c5ef9b495) parent(s): 7293ce0ee81f05b1ec3ac9ddcc88bfbee4030e55 625994b7cc4ebd0bc2652ae80b93386aa4b766ac author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2019-02-07 13:59:31 +0100 message: dirty merge CMakeLists.txt | 10 +- client/mysqlbinlog.cc | 27 +- client/mysqltest.cc | 7 +- cmake/build_configurations/mysql_release.cmake | 1 - cmake/wsrep.cmake | 2 +- config.h.cmake | 6 +- extra/mariabackup/xtrabackup.cc | 34 +- include/my_sys.h | 4 +- include/my_valgrind.h | 4 +- include/mysql.h | 2 +- include/mysql.h.pp | 2 +- mysql-test/include/check-testcase.test | 1 - mysql-test/main/alter_table.result | 49 + mysql-test/main/alter_table.test | 17 + mysql-test/main/alter_table_errors.result | 6 + mysql-test/main/alter_table_errors.test | 10 + mysql-test/main/check.result | 7 + mysql-test/main/check.test | 9 + mysql-test/main/check_constraint.result | 2 +- mysql-test/main/check_constraint.test | 1 - mysql-test/main/check_constraint_innodb.result | 9 + mysql-test/main/check_constraint_innodb.test | 14 + mysql-test/main/disabled.def | 1 + mysql-test/main/error_simulation.result | 5 +- mysql-test/main/error_simulation.test | 7 +- mysql-test/main/func_misc.result | 8 + mysql-test/main/func_misc.test | 8 + mysql-test/main/gis.test | 1 - mysql-test/main/mysql.result | 15 + mysql-test/main/mysql.test | 23 + mysql-test/main/mysqlbinlog_row_minimal.result | 145 +- mysql-test/main/mysqlbinlog_row_minimal.test | 41 + mysql-test/main/row-checksum-old.result | 16 + mysql-test/main/row-checksum.result | 16 + mysql-test/main/row-checksum.test | 17 + mysql-test/main/subselect2.result | 22 + mysql-test/main/subselect2.test | 20 + mysql-test/main/subselect_mat.result | 16 + mysql-test/main/subselect_mat.test | 13 + mysql-test/suite/archive/partition_archive.result | 4 +- mysql-test/suite/archive/partition_archive.test | 3 +- .../suite/binlog/r/binlog_base64_flag.result | 19 + .../binlog/r/binlog_mysqlbinlog_row_frag.result | 24 + mysql-test/suite/binlog/t/binlog_base64_flag.test | 22 + .../binlog/t/binlog_mysqlbinlog_row_frag.test | 46 + .../encryption/r/innodb-encryption-alter.result | 4 +- .../suite/encryption/r/innodb-spatial-index.result | 2 +- .../encryption/t/innodb-encryption-alter.test | 2 - .../suite/encryption/t/innodb-spatial-index.test | 2 - mysql-test/suite/galera/r/galera_defaults.result | 1 + .../suite/galera_3nodes/r/galera_pc_weight.result | 14 + .../r/galera_safe_to_bootstrap.result | 20 + mysql-test/suite/galera_3nodes/suite.pm | 40 + .../t/galera_innobackupex_backup.test | 2 +- .../galera_3nodes/t/galera_ipv6_xtrabackup-v2.opt | 1 + .../suite/gcol/inc/gcol_column_def_options.inc | 1 - mysql-test/suite/gcol/inc/gcol_keys.inc | 1 - mysql-test/suite/gcol/r/gcol_keys_innodb.result | 2 +- mysql-test/suite/gcol/r/innodb_virtual_fk.result | 4 +- mysql-test/suite/gcol/t/innodb_virtual_fk.test | 2 - mysql-test/suite/innodb/r/add_constraint.result | 2 +- .../suite/innodb/r/alter_foreign_crash.result | 2 +- .../suite/innodb/r/alter_varchar_change.result | 9 + mysql-test/suite/innodb/r/foreign_key.result | 35 +- .../suite/innodb/r/innodb-fk-warnings.result | 24 +- mysql-test/suite/innodb/r/innodb-fk.result | 6 +- .../suite/innodb/r/innodb-index-online.result | 2 +- mysql-test/suite/innodb/r/innodb-index.result | 10 +- .../suite/innodb/r/innodb_force_recovery.result | 8 +- .../suite/innodb/r/instant_varchar_enlarge.result | 9 - mysql-test/suite/innodb/t/add_constraint.test | 1 - .../suite/innodb/t/alter_varchar_change.test | 7 + mysql-test/suite/innodb/t/foreign_key.test | 32 +- mysql-test/suite/innodb/t/innodb-fk-warnings.test | 18 - mysql-test/suite/innodb/t/innodb-fk.test | 2 - mysql-test/suite/innodb/t/innodb-index-online.test | 1 - mysql-test/suite/innodb/t/innodb-index.test | 5 - .../innodb/t/innodb-page_compression_tables.test | 4 - .../suite/innodb/t/innodb_force_recovery.test | 4 - .../suite/innodb/t/instant_varchar_enlarge.test | 8 - mysql-test/suite/innodb_gis/r/point_basic.result | 14 +- mysql-test/suite/innodb_gis/t/point_basic.test | 6 - .../perfschema/r/dml_setup_instruments.result | 4 +- .../suite/perfschema/t/dml_setup_instruments.test | 5 +- mysql-test/suite/plugins/t/audit_null.test | 2 +- mysql-test/suite/rpl/r/rpl_set_statement.test | 0 mysql-test/suite/sys_vars/r/all_vars.result | 1 + .../r/sysvars_innodb,32bit,xtradb.rdiff-disabled | 1236 +++++++++++ .../r/sysvars_innodb,xtradb.rdiff-disabled | 697 ++++++ mysql-test/suite/sys_vars/r/sysvars_wsrep.result | 14 + .../sys_vars/r/tmp_disk_table_size_func.result | 2 +- .../suite/sys_vars/t/tmp_disk_table_size_func.test | 1 - mysql-test/suite/vcol/inc/vcol_keys.inc | 1 - mysql-test/suite/vcol/r/vcol_keys_innodb.result | 2 +- mysys/mf_iocache2.c | 61 +- mysys/my_file.c | 7 +- mysys/my_malloc.c | 1 + plugin/wsrep_info/mysql-test/wsrep_info/suite.pm | 2 + scripts/mysql_install_db.sh | 21 +- scripts/wsrep_sst_mariabackup.sh | 6 +- scripts/wsrep_sst_rsync.sh | 2 +- sql-common/client.c | 30 +- sql/field.cc | 4 +- sql/item.cc | 25 +- sql/item_func.cc | 2 +- sql/item_func.h | 4 + sql/log.cc | 6 +- sql/log_event.cc | 378 +++- sql/log_event.h | 24 +- sql/log_event_old.cc | 16 +- sql/rpl_tblmap.cc | 20 +- sql/rpl_tblmap.h | 10 +- sql/sql_binlog.cc | 91 +- sql/sql_class.cc | 23 +- sql/sql_lex.cc | 3 +- sql/sql_lex.h | 4 + sql/sql_repl.cc | 6 +- sql/sql_select.cc | 21 +- sql/sql_table.cc | 186 +- sql/sql_time.cc | 2 +- sql/sql_yacc.yy | 41 +- sql/sys_vars.cc | 13 + sql/table.cc | 2 +- sql/table.h | 12 +- sql/wsrep_mysqld.cc | 1 + sql/wsrep_mysqld.h | 1 + sql/wsrep_mysqld_c.h | 30 + storage/connect/ha_connect.cc | 45 +- storage/connect/jsonudf.cpp | 48 +- storage/connect/jsonudf.h | 5 + .../mysql-test/connect/r/jdbc_postgresql.result | 2 +- .../connect/mysql-test/connect/r/part_table.result | 4 +- .../connect/mysql-test/connect/t/part_table.test | 2 +- storage/connect/tabext.cpp | 43 +- storage/connect/tabext.h | 5 +- storage/connect/tabjdbc.cpp | 89 +- storage/connect/tabjson.cpp | 46 +- storage/connect/tabjson.h | 2 +- storage/connect/tabxml.cpp | 279 +-- storage/connect/tabxml.h | 1 + storage/innobase/buf/buf0buf.cc | 24 +- storage/innobase/handler/ha_innodb.cc | 84 +- storage/innobase/handler/ha_innodb.h | 14 +- storage/innobase/handler/handler0alter.cc | 75 +- storage/innobase/row/row0ins.cc | 42 +- storage/innobase/row/row0mysql.cc | 3 - storage/innobase/row/row0sel.cc | 45 +- storage/tokudb/PerconaFT/COPYING.APACHEv2 | 174 ++ storage/tokudb/PerconaFT/README.md | 5 +- storage/tokudb/PerconaFT/ft/txn/txn_manager.h | 4 +- .../tokudb/PerconaFT/locktree/concurrent_tree.cc | 14 + .../tokudb/PerconaFT/locktree/concurrent_tree.h | 14 + storage/tokudb/PerconaFT/locktree/keyrange.cc | 13 + storage/tokudb/PerconaFT/locktree/keyrange.h | 13 + storage/tokudb/PerconaFT/locktree/lock_request.cc | 13 + storage/tokudb/PerconaFT/locktree/lock_request.h | 13 + storage/tokudb/PerconaFT/locktree/locktree.cc | 13 + storage/tokudb/PerconaFT/locktree/locktree.h | 13 + storage/tokudb/PerconaFT/locktree/manager.cc | 13 + storage/tokudb/PerconaFT/locktree/range_buffer.cc | 13 + storage/tokudb/PerconaFT/locktree/range_buffer.h | 13 + storage/tokudb/PerconaFT/locktree/treenode.cc | 13 + storage/tokudb/PerconaFT/locktree/treenode.h | 13 + storage/tokudb/PerconaFT/locktree/txnid_set.cc | 13 + storage/tokudb/PerconaFT/locktree/txnid_set.h | 13 + storage/tokudb/PerconaFT/locktree/wfg.cc | 13 + storage/tokudb/PerconaFT/locktree/wfg.h | 13 + .../PerconaFT/portability/toku_instr_mysql.cc | 12 +- .../PerconaFT/portability/toku_instr_mysql.h | 11 +- .../tokudb/PerconaFT/portability/toku_pthread.h | 78 +- storage/tokudb/PerconaFT/util/growable_array.h | 13 + storage/tokudb/PerconaFT/util/omt.cc | 2261 +++++++++++--------- storage/tokudb/PerconaFT/util/omt.h | 13 + storage/tokudb/ha_tokudb.cc | 10 + storage/tokudb/hatoku_hton.cc | 4 +- storage/tokudb/hatoku_hton.h | 1 - .../tokudb/mysql-test/tokudb_bugs/r/PS-4979.result | 2 + .../tokudb/mysql-test/tokudb_bugs/t/PS-4979.test | 13 + storage/tokudb/tokudb_background.cc | 4 +- storage/tokudb/tokudb_sysvars.cc | 14 +- storage/tokudb/tokudb_sysvars.h | 4 +- support-files/mysql.server.sh | 6 +- unittest/mysys/thr_template.c | 4 +- unittest/sql/mf_iocache-t.cc | 70 +- win/packaging/heidisql.cmake | 2 +- 185 files changed, 5958 insertions(+), 1871 deletions(-) diff --cc client/mysqlbinlog.cc index 14656705805,559117749f2..58d3b0f372c --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@@ -852,9 -845,13 +853,15 @@@ write_event_header_and_base64(Log_even DBUG_ENTER("write_event_header_and_base64"); /* Write header and base64 output to cache */ - if (ev->print_header(head, print_event_info, FALSE) || - ev->print_base64(body, print_event_info, FALSE)) - ev->print_header(head, print_event_info, FALSE); ++ if (ev->print_header(head, print_event_info, FALSE)) ++ DBUG_RETURN(ERROR_STOP); + + DBUG_ASSERT(print_event_info->base64_output_mode == BASE64_OUTPUT_ALWAYS); + - ev->print_base64(body, print_event_info, - print_event_info->base64_output_mode != - BASE64_OUTPUT_DECODE_ROWS); ++ if (ev->print_base64(body, print_event_info, ++ print_event_info->base64_output_mode != ++ BASE64_OUTPUT_DECODE_ROWS)) + DBUG_RETURN(ERROR_STOP); /* Read data from cache and write to result file */ if (copy_event_cache_to_file_and_reinit(head, result_file) || diff --cc include/my_sys.h index 13ab7b12320,3d233f8b6a6..9a3acffe41d --- a/include/my_sys.h +++ b/include/my_sys.h @@@ -609,12 -606,14 +609,14 @@@ static inline my_off_t my_b_get_pos_in_ static inline size_t my_b_bytes_in_cache(const IO_CACHE *info) { if (info->type == WRITE_CACHE) { - return info->write_end - info->write_pos; + return (size_t) (info->write_end - info->write_pos); } - return info->read_end - info->read_pos; + return (size_t) (info->read_end - info->read_pos); } - int my_b_copy_to_file(IO_CACHE *cache, FILE *file); + int my_b_copy_to_file (IO_CACHE *cache, FILE *file, size_t count); + int my_b_copy_all_to_file(IO_CACHE *cache, FILE *file); + my_off_t my_b_append_tell(IO_CACHE* info); my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */ int my_b_pread(IO_CACHE *info, uchar *Buffer, size_t Count, my_off_t pos); diff --cc include/my_valgrind.h index 5ba288cedc3,cf3037da98b..575ed46a0ee --- a/include/my_valgrind.h +++ b/include/my_valgrind.h @@@ -48,10 -48,10 +48,10 @@@ https://github.com/google/sanitizers/wi # define MEM_CHECK_DEFINED(a,len) ((void) 0) #endif /* HAVE_VALGRIND_MEMCHECK_H */ -#ifndef DBUG_OFF +#if !defined(DBUG_OFF) || defined(TRASH_FREED_MEMORY) #define TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); MEM_UNDEFINED(A, trash_tmp); memset(A, C, trash_tmp); } while (0) #else - #define TRASH_FILL(A,B,C) do { const size_t trash_tmp __attribute__((unused))= (B); MEM_UNDEFINED(A,trash_tmp); } while (0) + #define TRASH_FILL(A,B,C) do { MEM_UNDEFINED((A), (B)); } while (0) #endif #define TRASH_ALLOC(A,B) do { TRASH_FILL(A,B,0xA5); MEM_UNDEFINED(A,B); } while(0) diff --cc mysql-test/main/alter_table.result index a896d24d510,00000000000..7a88f9165da mode 100644,000000..100644 --- a/mysql-test/main/alter_table.result +++ b/mysql-test/main/alter_table.result @@@ -1,2492 -1,0 +1,2541 @@@ +drop table if exists t1,t2; +drop database if exists mysqltest; +create table t1 ( +col1 int not null auto_increment primary key, +col2 varchar(30) not null, +col3 varchar (20) not null, +col4 varchar(4) not null, +col5 enum('PENDING', 'ACTIVE', 'DISABLED') not null, +col6 int not null, to_be_deleted int); +insert into t1 values (2,4,3,5,"PENDING",1,7); +alter table t1 +add column col4_5 varchar(20) not null after col4, +add column col7 varchar(30) not null after col5, +add column col8 datetime not null, drop column to_be_deleted, +change column col2 fourth varchar(30) not null after col3, +modify column col6 int not null first; +select * from t1; +col6 col1 col3 fourth col4 col4_5 col5 col7 col8 +1 2 3 4 5 PENDING 0000-00-00 00:00:00 +drop table t1; +create table t1 (bandID MEDIUMINT UNSIGNED NOT NULL PRIMARY KEY, payoutID SMALLINT UNSIGNED NOT NULL); +insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12); +alter table t1 add column new_col int, order by payoutid,bandid; +select * from t1; +bandID payoutID new_col +6 1 NULL +3 4 NULL +1 6 NULL +2 6 NULL +4 9 NULL +5 10 NULL +7 12 NULL +8 12 NULL +alter table t1 order by bandid,payoutid; +select * from t1; +bandID payoutID new_col +1 6 NULL +2 6 NULL +3 4 NULL +4 9 NULL +5 10 NULL +6 1 NULL +7 12 NULL +8 12 NULL +drop table t1; +CREATE TABLE t1 ( +GROUP_ID int(10) unsigned DEFAULT '0' NOT NULL, +LANG_ID smallint(5) unsigned DEFAULT '0' NOT NULL, +NAME varchar(80) DEFAULT '' NOT NULL, +PRIMARY KEY (GROUP_ID,LANG_ID), +KEY NAME (NAME)); +ALTER TABLE t1 CHANGE NAME NAME CHAR(80) not null; +SHOW FULL COLUMNS FROM t1; +Field Type Collation Null Key Default Extra Privileges Comment +GROUP_ID int(10) unsigned NULL NO PRI 0 # +LANG_ID smallint(5) unsigned NULL NO PRI 0 # +NAME char(80) latin1_swedish_ci NO MUL NULL # +DROP TABLE t1; +create table t1 (n int); +insert into t1 values(9),(3),(12),(10); +alter table t1 order by n; +select * from t1; +n +3 +9 +10 +12 +drop table t1; +CREATE TABLE t1 ( +id int(11) unsigned NOT NULL default '0', +category_id tinyint(4) unsigned NOT NULL default '0', +type_id tinyint(4) unsigned NOT NULL default '0', +body text NOT NULL, +user_id int(11) unsigned NOT NULL default '0', +status enum('new','old') NOT NULL default 'new', +PRIMARY KEY (id) +) ENGINE=MyISAM; +ALTER TABLE t1 ORDER BY t1.id, t1.status, t1.type_id, t1.user_id, t1.body; +DROP TABLE t1; +CREATE TABLE t1 (AnamneseId int(10) unsigned NOT NULL auto_increment,B BLOB,PRIMARY KEY (AnamneseId)) engine=myisam; +insert into t1 values (null,"hello"); +LOCK TABLES t1 WRITE; +ALTER TABLE t1 ADD Column new_col int not null; +UNLOCK TABLES; +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize status OK +DROP TABLE t1; +create table t1 (i int unsigned not null auto_increment primary key); +insert into t1 values (null),(null),(null),(null); +alter table t1 drop i,add i int unsigned not null auto_increment, drop primary key, add primary key (i); +select * from t1; +i +1 +2 +3 +4 +drop table t1; +create table t1 (name char(15)); +insert into t1 (name) values ("current"); +create database mysqltest; +create table mysqltest.t1 (name char(15)); +insert into mysqltest.t1 (name) values ("mysqltest"); +select * from t1; +name +current +select * from mysqltest.t1; +name +mysqltest +alter table t1 rename mysqltest.t1; +ERROR 42S01: Table 't1' already exists +select * from t1; +name +current +select * from mysqltest.t1; +name +mysqltest +drop table t1; +drop database mysqltest; +create table t1 (n1 int not null, n2 int, n3 int, n4 float, +unique(n1), +key (n1, n2, n3, n4), +key (n2, n3, n4, n1), +key (n3, n4, n1, n2), +key (n4, n1, n2, n3) ); +alter table t1 disable keys; +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 n1 1 n1 A 0 NULL NULL BTREE +t1 1 n1_2 1 n1 A NULL NULL NULL BTREE disabled +t1 1 n1_2 2 n2 A NULL NULL NULL YES BTREE disabled +t1 1 n1_2 3 n3 A NULL NULL NULL YES BTREE disabled +t1 1 n1_2 4 n4 A NULL NULL NULL YES BTREE disabled +t1 1 n2 1 n2 A NULL NULL NULL YES BTREE disabled +t1 1 n2 2 n3 A NULL NULL NULL YES BTREE disabled +t1 1 n2 3 n4 A NULL NULL NULL YES BTREE disabled +t1 1 n2 4 n1 A NULL NULL NULL BTREE disabled +t1 1 n3 1 n3 A NULL NULL NULL YES BTREE disabled +t1 1 n3 2 n4 A NULL NULL NULL YES BTREE disabled +t1 1 n3 3 n1 A NULL NULL NULL BTREE disabled +t1 1 n3 4 n2 A NULL NULL NULL YES BTREE disabled +t1 1 n4 1 n4 A NULL NULL NULL YES BTREE disabled +t1 1 n4 2 n1 A NULL NULL NULL BTREE disabled +t1 1 n4 3 n2 A NULL NULL NULL YES BTREE disabled +t1 1 n4 4 n3 A NULL NULL NULL YES BTREE disabled +alter table t1 enable keys; +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 n1 1 n1 A 10 NULL NULL BTREE +t1 1 n1_2 1 n1 A 10 NULL NULL BTREE +t1 1 n1_2 2 n2 A 10 NULL NULL YES BTREE +t1 1 n1_2 3 n3 A 10 NULL NULL YES BTREE +t1 1 n1_2 4 n4 A 10 NULL NULL YES BTREE +t1 1 n2 1 n2 A 10 NULL NULL YES BTREE +t1 1 n2 2 n3 A 10 NULL NULL YES BTREE +t1 1 n2 3 n4 A 10 NULL NULL YES BTREE +t1 1 n2 4 n1 A 10 NULL NULL BTREE +t1 1 n3 1 n3 A 10 NULL NULL YES BTREE +t1 1 n3 2 n4 A 10 NULL NULL YES BTREE +t1 1 n3 3 n1 A 10 NULL NULL BTREE +t1 1 n3 4 n2 A 10 NULL NULL YES BTREE +t1 1 n4 1 n4 A 10 NULL NULL YES BTREE +t1 1 n4 2 n1 A 10 NULL NULL BTREE +t1 1 n4 3 n2 A 10 NULL NULL YES BTREE +t1 1 n4 4 n3 A 10 NULL NULL YES BTREE +drop table t1; +create table t1 (i int unsigned not null auto_increment primary key); +alter table t1 rename t2; +alter table t2 rename t1, add c char(10) comment "no comment"; +show columns from t1; +Field Type Null Key Default Extra +i int(10) unsigned NO PRI NULL auto_increment +c char(10) YES NULL +drop table t1; +create table t1 (a int, b int); +alter table t1 add unique (a,b), add key (b); +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A 3 NULL NULL YES BTREE +t1 0 a 2 b A 300 NULL NULL YES BTREE +t1 1 b 1 b A 100 NULL NULL YES BTREE +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A 3 NULL NULL YES BTREE +t1 0 a 2 b A 300 NULL NULL YES BTREE +t1 1 b 1 b A 100 NULL NULL YES BTREE +drop table t1; +CREATE TABLE t1 (i int(10), index(i) ) ENGINE=MyISAM; +ALTER TABLE t1 DISABLE KEYS; +INSERT DELAYED INTO t1 VALUES(1),(2),(3); +ALTER TABLE t1 ENABLE KEYS; +drop table t1; +CREATE TABLE t1 ( +Host varchar(16) binary NOT NULL default '', +User varchar(16) binary NOT NULL default '', +PRIMARY KEY (Host,User) +) ENGINE=MyISAM; +ALTER TABLE t1 DISABLE KEYS; +LOCK TABLES t1 WRITE; +INSERT INTO t1 VALUES ('localhost','root'),('localhost',''),('games','monty'); +SHOW INDEX FROM t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 PRIMARY 1 Host A NULL NULL NULL BTREE +t1 0 PRIMARY 2 User A 0 NULL NULL BTREE +ALTER TABLE t1 ENABLE KEYS; +UNLOCK TABLES; +CHECK TABLES t1; +Table Op Msg_type Msg_text +test.t1 check status OK +DROP TABLE t1; +CREATE TABLE t1 ( +Host varchar(16) binary NOT NULL default '', +User varchar(16) binary NOT NULL default '', +PRIMARY KEY (Host,User), +KEY (Host) +) ENGINE=MyISAM; +ALTER TABLE t1 DISABLE KEYS; +SHOW INDEX FROM t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 PRIMARY 1 Host A NULL NULL NULL BTREE +t1 0 PRIMARY 2 User A 0 NULL NULL BTREE +t1 1 Host 1 Host A NULL NULL NULL BTREE disabled +LOCK TABLES t1 WRITE; +INSERT INTO t1 VALUES ('localhost','root'),('localhost',''); +SHOW INDEX FROM t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 PRIMARY 1 Host A NULL NULL NULL BTREE +t1 0 PRIMARY 2 User A 0 NULL NULL BTREE +t1 1 Host 1 Host A NULL NULL NULL BTREE disabled +ALTER TABLE t1 ENABLE KEYS; +SHOW INDEX FROM t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 PRIMARY 1 Host A NULL NULL NULL BTREE +t1 0 PRIMARY 2 User A 2 NULL NULL BTREE +t1 1 Host 1 Host A 1 NULL NULL BTREE +UNLOCK TABLES; +CHECK TABLES t1; +Table Op Msg_type Msg_text +test.t1 check status OK +LOCK TABLES t1 WRITE; +ALTER TABLE t1 RENAME t2; +UNLOCK TABLES; +select * from t2; +Host User +localhost +localhost root +DROP TABLE t2; +CREATE TABLE t1 ( +Host varchar(16) binary NOT NULL default '', +User varchar(16) binary NOT NULL default '', +PRIMARY KEY (Host,User), +KEY (Host) +) ENGINE=MyISAM; +LOCK TABLES t1 WRITE; +ALTER TABLE t1 DISABLE KEYS; +SHOW INDEX FROM t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 PRIMARY 1 Host A NULL NULL NULL BTREE +t1 0 PRIMARY 2 User A 0 NULL NULL BTREE +t1 1 Host 1 Host A NULL NULL NULL BTREE disabled +DROP TABLE t1; +create table t1 (a int); +alter table t1 rename to ``; +ERROR 42000: Incorrect table name '' +rename table t1 to ``; +ERROR 42000: Incorrect table name '' +drop table t1; +drop table if exists t1, t2; +Warnings: +Note 1051 Unknown table 'test.t1' +Note 1051 Unknown table 'test.t2' +create table t1 ( a varchar(10) not null primary key ) engine=myisam; +create table t2 ( a varchar(10) not null primary key ) engine=merge union=(t1); +flush tables; +alter table t1 modify a varchar(10); +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` varchar(10) NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 UNION=(`t1`) +flush tables; +alter table t1 modify a varchar(10) not null; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` varchar(10) NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 UNION=(`t1`) +drop table if exists t1, t2; +create table t1 (a int, b int, c int, d int, e int, f int, g int, h int,i int, primary key (a,b,c,d,e,f,g,i,h)) engine=MyISAM; +insert ignore into t1 (a) values(1); +Warnings: +Warning 1364 Field 'b' doesn't have a default value +Warning 1364 Field 'c' doesn't have a default value +Warning 1364 Field 'd' doesn't have a default value +Warning 1364 Field 'e' doesn't have a default value +Warning 1364 Field 'f' doesn't have a default value +Warning 1364 Field 'g' doesn't have a default value +Warning 1364 Field 'h' doesn't have a default value +Warning 1364 Field 'i' doesn't have a default value +show table status 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 Max_index_length Temporary +t1 MyISAM 10 Fixed 1 37 X X X X X X X X latin1_swedish_ci NULL X N +alter table t1 modify a int; +show table status 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 Max_index_length Temporary +t1 MyISAM 10 Fixed 1 37 X X X X X X X X latin1_swedish_ci NULL X N +drop table t1; +create table t1 (a int not null, b int not null, c int not null, d int not null, e int not null, f int not null, g int not null, h int not null,i int not null, primary key (a,b,c,d,e,f,g,i,h)) engine=MyISAM; +insert ignore into t1 (a) values(1); +Warnings: +Warning 1364 Field 'b' doesn't have a default value +Warning 1364 Field 'c' doesn't have a default value +Warning 1364 Field 'd' doesn't have a default value +Warning 1364 Field 'e' doesn't have a default value +Warning 1364 Field 'f' doesn't have a default value +Warning 1364 Field 'g' doesn't have a default value +Warning 1364 Field 'h' doesn't have a default value +Warning 1364 Field 'i' doesn't have a default value +show table status 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 Max_index_length Temporary +t1 MyISAM 10 Fixed 1 37 X X X X X X X X latin1_swedish_ci NULL X N +drop table t1; +set names koi8r; +create table t1 (a char(10) character set koi8r); +insert into t1 values ('����'); +select a,hex(a) from t1; +a hex(a) +���� D4C5D3D4 +alter table t1 change a a char(10) character set cp1251; +select a,hex(a) from t1; +a hex(a) +���� F2E5F1F2 +alter table t1 change a a binary(4); +select a,hex(a) from t1; +a hex(a) +���� F2E5F1F2 +alter table t1 change a a char(10) character set cp1251; +select a,hex(a) from t1; +a hex(a) +���� F2E5F1F2 +alter table t1 change a a char(10) character set koi8r; +select a,hex(a) from t1; +a hex(a) +���� D4C5D3D4 +alter table t1 change a a varchar(10) character set cp1251; +select a,hex(a) from t1; +a hex(a) +���� F2E5F1F2 +alter table t1 change a a char(10) character set koi8r; +select a,hex(a) from t1; +a hex(a) +���� D4C5D3D4 +alter table t1 change a a text character set cp1251; +select a,hex(a) from t1; +a hex(a) +���� F2E5F1F2 +alter table t1 change a a char(10) character set koi8r; +select a,hex(a) from t1; +a hex(a) +���� D4C5D3D4 +delete from t1; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` char(10) CHARACTER SET koi8r DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +alter table t1 DEFAULT CHARACTER SET latin1; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` char(10) CHARACTER SET koi8r DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +alter table t1 CONVERT TO CHARACTER SET latin1; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` char(10) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +alter table t1 DEFAULT CHARACTER SET cp1251; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` char(10) CHARACTER SET latin1 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=cp1251 +drop table t1; +create table t1 (myblob longblob,mytext longtext) +default charset latin1 collate latin1_general_cs; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `myblob` longblob DEFAULT NULL, + `mytext` longtext COLLATE latin1_general_cs DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs +alter table t1 character set latin2; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `myblob` longblob DEFAULT NULL, + `mytext` longtext CHARACTER SET latin1 COLLATE latin1_general_cs DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin2 +drop table t1; +CREATE TABLE t1 (a int PRIMARY KEY, b INT UNIQUE); +ALTER TABLE t1 DROP PRIMARY KEY; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` int(11) DEFAULT NULL, + UNIQUE KEY `b` (`b`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +ALTER TABLE t1 DROP PRIMARY KEY; +ERROR 42000: Can't DROP INDEX `PRIMARY`; check that it exists +DROP TABLE t1; +create table t1 (a int, b int, key(a)); +insert into t1 values (1,1), (2,2); +alter table t1 drop key no_such_key; +ERROR 42000: Can't DROP INDEX `no_such_key`; check that it exists +alter table t1 drop key a; +drop table t1; +CREATE TABLE T12207(a int) ENGINE=MYISAM; +ALTER TABLE T12207 DISCARD TABLESPACE; +ERROR HY000: Storage engine MyISAM of the table `test`.`T12207` doesn't have this option +DROP TABLE T12207; +create table t1 (a text) character set koi8r; +insert into t1 values (_koi8r'����'); +select hex(a) from t1; +hex(a) +D4C5D3D4 +alter table t1 convert to character set cp1251; +select hex(a) from t1; +hex(a) +F2E5F1F2 +drop table t1; +create table t1 ( a timestamp ); +alter table t1 add unique ( a(1) ); +ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys +drop table t1; +drop table if exists t1; +create table t1 (a int, key(a)); +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 1 a 1 a A NULL NULL NULL YES BTREE +"this used not to disable the index" +alter table t1 modify a int, disable keys; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 1 a 1 a A NULL NULL NULL YES BTREE disabled +alter table t1 enable keys; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 1 a 1 a A NULL NULL NULL YES BTREE +alter table t1 modify a bigint, disable keys; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 1 a 1 a A NULL NULL NULL YES BTREE disabled +alter table t1 enable keys; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 1 a 1 a A NULL NULL NULL YES BTREE +alter table t1 add b char(10), disable keys; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 1 a 1 a A NULL NULL NULL YES BTREE disabled +alter table t1 add c decimal(10,2), enable keys; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 1 a 1 a A NULL NULL NULL YES BTREE +"this however did" +alter table t1 disable keys; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 1 a 1 a A NULL NULL NULL YES BTREE disabled +desc t1; +Field Type Null Key Default Extra +a bigint(20) YES MUL NULL +b char(10) YES NULL +c decimal(10,2) YES NULL +alter table t1 add d decimal(15,5); +"The key should still be disabled" +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 1 a 1 a A NULL NULL NULL YES BTREE disabled +drop table t1; +"Now will test with one unique index" +create table t1(a int, b char(10), unique(a)); +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES BTREE +alter table t1 disable keys; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES BTREE +alter table t1 enable keys; +"If no copy on noop change, this won't touch the data file" +"Unique index, no change" +alter table t1 modify a int, disable keys; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES BTREE +"Change the type implying data copy" +"Unique index, no change" +alter table t1 modify a bigint, disable keys; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES BTREE +alter table t1 modify a bigint; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES BTREE +alter table t1 modify a int; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES BTREE +drop table t1; +"Now will test with one unique and one non-unique index" +create table t1(a int, b char(10), unique(a), key(b)); +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES BTREE +t1 1 b 1 b A NULL NULL NULL YES BTREE +alter table t1 disable keys; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES BTREE +t1 1 b 1 b A NULL NULL NULL YES BTREE disabled +alter table t1 enable keys; +"If no copy on noop change, this won't touch the data file" +"The non-unique index will be disabled" +alter table t1 modify a int, disable keys; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES BTREE +t1 1 b 1 b A NULL NULL NULL YES BTREE disabled +alter table t1 enable keys; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES BTREE +t1 1 b 1 b A NULL NULL NULL YES BTREE +"Change the type implying data copy" +"The non-unique index will be disabled" +alter table t1 modify a bigint, disable keys; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES BTREE +t1 1 b 1 b A NULL NULL NULL YES BTREE disabled +"Change again the type, but leave the indexes as_is" +alter table t1 modify a int; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES BTREE +t1 1 b 1 b A NULL NULL NULL YES BTREE disabled +"Try the same. When data is no copied on similar tables, this is noop" +alter table t1 modify a int; +show indexes from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES BTREE +t1 1 b 1 b A NULL NULL NULL YES BTREE disabled +drop table t1; +create database mysqltest; +create table t1 (c1 int); +alter table t1 rename mysqltest.t1; +drop table t1; +ERROR 42S02: Unknown table 'test.t1' +alter table mysqltest.t1 rename t1; +drop table t1; +create table t1 (c1 int); +use mysqltest; +drop database mysqltest; +alter table test.t1 rename t1; +ERROR 3D000: No database selected +alter table test.t1 rename test.t1; +use test; +drop table t1; +CREATE TABLE t1(a INT) ROW_FORMAT=FIXED; +CREATE INDEX i1 ON t1(a); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + KEY `i1` (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=FIXED +DROP INDEX i1 ON t1; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=FIXED +DROP TABLE t1; +DROP TABLE IF EXISTS bug24219; +DROP TABLE IF EXISTS bug24219_2; +CREATE TABLE bug24219 (a INT, INDEX(a)); +SHOW INDEX FROM bug24219; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +bug24219 1 a 1 a A NULL NULL NULL YES BTREE +ALTER TABLE bug24219 RENAME TO bug24219_2, DISABLE KEYS; +SHOW INDEX FROM bug24219_2; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +bug24219_2 1 a 1 a A NULL NULL NULL YES BTREE disabled +DROP TABLE bug24219_2; +drop table if exists table_24562; +create table table_24562( +section int, +subsection int, +title varchar(50)); +insert into table_24562 values +(1, 0, "Introduction"), +(1, 1, "Authors"), +(1, 2, "Acknowledgements"), +(2, 0, "Basics"), +(2, 1, "Syntax"), +(2, 2, "Client"), +(2, 3, "Server"), +(3, 0, "Intermediate"), +(3, 1, "Complex queries"), +(3, 2, "Stored Procedures"), +(3, 3, "Stored Functions"), +(4, 0, "Advanced"), +(4, 1, "Replication"), +(4, 2, "Load balancing"), +(4, 3, "High availability"), +(5, 0, "Conclusion"); +select * from table_24562; +section subsection title +1 0 Introduction +1 1 Authors +1 2 Acknowledgements +2 0 Basics +2 1 Syntax +2 2 Client +2 3 Server +3 0 Intermediate +3 1 Complex queries +3 2 Stored Procedures +3 3 Stored Functions +4 0 Advanced +4 1 Replication +4 2 Load balancing +4 3 High availability +5 0 Conclusion +alter table table_24562 add column reviewer varchar(20), +order by title; +select * from table_24562; +section subsection title reviewer +1 2 Acknowledgements NULL +4 0 Advanced NULL +1 1 Authors NULL +2 0 Basics NULL +2 2 Client NULL +3 1 Complex queries NULL +5 0 Conclusion NULL +4 3 High availability NULL +3 0 Intermediate NULL +1 0 Introduction NULL +4 2 Load balancing NULL +4 1 Replication NULL +2 3 Server NULL +3 3 Stored Functions NULL +3 2 Stored Procedures NULL +2 1 Syntax NULL +update table_24562 set reviewer="Me" where section=2; +update table_24562 set reviewer="You" where section=3; +alter table table_24562 +order by section ASC, subsection DESC; +select * from table_24562; +section subsection title reviewer +1 2 Acknowledgements NULL +1 1 Authors NULL +1 0 Introduction NULL +2 3 Server Me +2 2 Client Me +2 1 Syntax Me +2 0 Basics Me +3 3 Stored Functions You +3 2 Stored Procedures You +3 1 Complex queries You +3 0 Intermediate You +4 3 High availability NULL +4 2 Load balancing NULL +4 1 Replication NULL +4 0 Advanced NULL +5 0 Conclusion NULL +alter table table_24562 +order by table_24562.subsection ASC, table_24562.section DESC; +select * from table_24562; +section subsection title reviewer +5 0 Conclusion NULL +4 0 Advanced NULL +3 0 Intermediate You +2 0 Basics Me +1 0 Introduction NULL +4 1 Replication NULL +3 1 Complex queries You +2 1 Syntax Me +1 1 Authors NULL +4 2 Load balancing NULL +3 2 Stored Procedures You +2 2 Client Me +1 2 Acknowledgements NULL +4 3 High availability NULL +3 3 Stored Functions You +2 3 Server Me +alter table table_24562 order by 12; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '12' at line 1 +alter table table_24562 order by (section + 12); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(section + 12)' at line 1 +alter table table_24562 order by length(title); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(title)' at line 1 +alter table table_24562 order by (select 12 from dual); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(select 12 from dual)' at line 1 +alter table table_24562 order by no_such_col; +ERROR 42S22: Unknown column 'no_such_col' in 'order clause' +drop table table_24562; +create table t1 (mycol int(10) not null); +alter table t1 alter column mycol set default 0; +desc t1; +Field Type Null Key Default Extra +mycol int(10) NO 0 +drop table t1; +create table t1(id int(8) primary key auto_increment) engine=heap; +insert into t1 values (null); +insert into t1 values (null); +select * from t1; +id +1 +2 +alter table t1 auto_increment = 50; +alter table t1 engine = myisam; +insert into t1 values (null); +select * from t1; +id +1 +2 +50 +alter table t1 engine = heap; +insert into t1 values (null); +select * from t1; +id +1 +2 +50 +51 +drop table t1; +set @orig_sql_mode = @@sql_mode; +set sql_mode="no_zero_date"; +create table t1(f1 int); +alter table t1 add column f2 datetime not null, add column f21 date not null; +insert into t1 values(1,'2000-01-01','2000-01-01'); +alter table t1 add column f3 datetime not null; +ERROR 22007: Incorrect datetime value: '0000-00-00 00:00:00' for column `test`.`t1`.`f3` at row 1 +alter table t1 add column f3 date not null; +ERROR 22007: Incorrect date value: '0000-00-00' for column `test`.`t1`.`f3` at row 1 +alter table t1 add column f4 datetime not null default '2002-02-02', +add column f41 date not null; +ERROR 22007: Incorrect date value: '0000-00-00' for column `test`.`t1`.`f41` at row 1 +alter table t1 add column f4 datetime not null default '2002-02-02', +add column f41 date not null default '2002-02-02'; +select * from t1; +f1 f2 f21 f4 f41 +1 2000-01-01 00:00:00 2000-01-01 2002-02-02 00:00:00 2002-02-02 +drop table t1; +set sql_mode= @orig_sql_mode; +create table t1 (v varchar(32)); +insert into t1 values ('def'),('abc'),('hij'),('3r4f'); +select * from t1; +v +def +abc +hij +3r4f +alter table t1 change v v2 varchar(32); +select * from t1; +v2 +def +abc +hij +3r4f +alter table t1 change v2 v varchar(64); +select * from t1; +v +def +abc +hij +3r4f +update t1 set v = 'lmn' where v = 'hij'; +select * from t1; +v +def +abc +lmn +3r4f +alter table t1 add i int auto_increment not null primary key first; +select * from t1; +i v +1 def +2 abc +3 lmn +4 3r4f +update t1 set i=5 where i=3; +select * from t1; +i v +1 def +2 abc +5 lmn +4 3r4f +alter table t1 change i i bigint; +select * from t1; +i v +1 def +2 abc +5 lmn +4 3r4f +alter table t1 add unique key (i, v); +select * from t1 where i between 2 and 4 and v in ('def','3r4f','lmn'); +i v +4 3r4f +drop table t1; +create table t1 (t varchar(255) default null, key t (t(80))) +engine=myisam default charset=latin1; +alter table t1 change t t text; +drop table t1; +CREATE TABLE t1 (a varchar(500)); +ALTER TABLE t1 ADD b GEOMETRY NOT NULL, ADD SPATIAL INDEX(b); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(500) DEFAULT NULL, + `b` geometry NOT NULL, + SPATIAL KEY `b` (`b`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +ALTER TABLE t1 ADD KEY(b(50)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(500) DEFAULT NULL, + `b` geometry NOT NULL, + SPATIAL KEY `b` (`b`), + KEY `b_2` (`b`(50)) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +ALTER TABLE t1 ADD c POINT; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(500) DEFAULT NULL, + `b` geometry NOT NULL, + `c` point DEFAULT NULL, + SPATIAL KEY `b` (`b`), + KEY `b_2` (`b`(50)) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +CREATE TABLE t2 (a INT, KEY (a(20))); +ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys +ALTER TABLE t1 ADD d INT; +ALTER TABLE t1 ADD KEY (d(20)); +ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys +ALTER TABLE t1 ADD e GEOMETRY NOT NULL, ADD SPATIAL KEY (e(30)); +ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys +DROP TABLE t1; +CREATE TABLE t1 (s CHAR(8) BINARY); +INSERT INTO t1 VALUES ('test'); +SELECT LENGTH(s) FROM t1; +LENGTH(s) +4 +ALTER TABLE t1 MODIFY s CHAR(10) BINARY; +SELECT LENGTH(s) FROM t1; +LENGTH(s) +4 +DROP TABLE t1; +CREATE TABLE t1 (s BINARY(8)); +INSERT INTO t1 VALUES ('test'); +SELECT LENGTH(s) FROM t1; +LENGTH(s) +8 +SELECT HEX(s) FROM t1; +HEX(s) +7465737400000000 +ALTER TABLE t1 MODIFY s BINARY(10); +SELECT HEX(s) FROM t1; +HEX(s) +74657374000000000000 +SELECT LENGTH(s) FROM t1; +LENGTH(s) +10 +DROP TABLE t1; +CREATE TABLE t1 (v VARCHAR(3), b INT); +INSERT INTO t1 VALUES ('abc', 5); +SELECT * FROM t1; +v b +abc 5 +ALTER TABLE t1 MODIFY COLUMN v VARCHAR(4); +SELECT * FROM t1; +v b +abc 5 +DROP TABLE t1; +create table t1 (a tinytext character set latin1); +alter table t1 convert to character set utf8; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` text DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8 +drop table t1; +create table t1 (a mediumtext character set latin1); +alter table t1 convert to character set utf8; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` longtext DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8 +drop table t1; +End of 5.0 tests +drop table if exists t1, t2, t3; +create table t1 (i int); +create table t3 (j int); +insert into t1 values (); +insert into t3 values (); +lock table t1 write, t3 read; +alter table t1 modify i int default 1; +insert into t1 values (); +select * from t1; +i +NULL +1 +alter table t1 change i c char(10) default "Two"; +insert into t1 values (); +select * from t1; +c +NULL +1 +Two +alter table t1 modify c char(10) default "Three", rename to t2; +select * from t1; +ERROR HY000: Table 't1' was not locked with LOCK TABLES +select * from t2; +ERROR HY000: Table 't2' was not locked with LOCK TABLES +select * from t3; +j +NULL +unlock tables; +insert into t2 values (); +select * from t2; +c +NULL +1 +Two +Three +lock table t2 write, t3 read; +alter table t2 change c vc varchar(100) default "Four", rename to t1; +select * from t1; +ERROR HY000: Table 't1' was not locked with LOCK TABLES +select * from t2; +ERROR HY000: Table 't2' was not locked with LOCK TABLES +select * from t3; +j +NULL +unlock tables; +insert into t1 values (); +select * from t1; +vc +NULL +1 +Two +Three +Four +drop tables t1, t3; +DROP TABLE IF EXISTS `t+1`, `t+2`; +CREATE TABLE `t+1` (c1 INT); +ALTER TABLE `t+1` RENAME `t+2`; +CREATE TABLE `t+1` (c1 INT); +ALTER TABLE `t+1` RENAME `t+2`; +ERROR 42S01: Table 't+2' already exists +DROP TABLE `t+1`, `t+2`; +CREATE TEMPORARY TABLE `tt+1` (c1 INT); +ALTER TABLE `tt+1` RENAME `tt+2`; +CREATE TEMPORARY TABLE `tt+1` (c1 INT); +ALTER TABLE `tt+1` RENAME `tt+2`; +ERROR 42S01: Table 'tt+2' already exists +SHOW CREATE TABLE `tt+1`; +Table Create Table +tt+1 CREATE TEMPORARY TABLE `tt+1` ( + `c1` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SHOW CREATE TABLE `tt+2`; +Table Create Table +tt+2 CREATE TEMPORARY TABLE `tt+2` ( + `c1` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE `tt+1`, `tt+2`; +CREATE TABLE `#sql1` (c1 INT); +CREATE TABLE `@0023sql2` (c1 INT); +SHOW TABLES; +Tables_in_test +#sql1 +@0023sql2 +RENAME TABLE `#sql1` TO `@0023sql1`; +RENAME TABLE `@0023sql2` TO `#sql2`; +SHOW TABLES; +Tables_in_test +#sql2 +@0023sql1 +ALTER TABLE `@0023sql1` RENAME `#sql-1`; +ALTER TABLE `#sql2` RENAME `@0023sql-2`; +SHOW TABLES; +Tables_in_test +#sql-1 +@0023sql-2 +INSERT INTO `#sql-1` VALUES (1); +INSERT INTO `@0023sql-2` VALUES (2); +DROP TABLE `#sql-1`, `@0023sql-2`; +CREATE TEMPORARY TABLE `#sql1` (c1 INT); +CREATE TEMPORARY TABLE `@0023sql2` (c1 INT); +SHOW TABLES; +Tables_in_test +ALTER TABLE `#sql1` RENAME `@0023sql1`; +ALTER TABLE `@0023sql2` RENAME `#sql2`; +SHOW TABLES; +Tables_in_test +INSERT INTO `#sql2` VALUES (1); +INSERT INTO `@0023sql1` VALUES (2); +SHOW CREATE TABLE `#sql2`; +Table Create Table +#sql2 CREATE TEMPORARY TABLE `#sql2` ( + `c1` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SHOW CREATE TABLE `@0023sql1`; +Table Create Table +@0023sql1 CREATE TEMPORARY TABLE `@0023sql1` ( + `c1` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE `#sql2`, `@0023sql1`; +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +CREATE TABLE t1 ( +int_field INTEGER UNSIGNED NOT NULL, +char_field CHAR(10), +INDEX(`int_field`) +); +DESCRIBE t1; +Field Type Null Key Default Extra +int_field int(10) unsigned NO MUL NULL +char_field char(10) YES NULL +SHOW INDEXES FROM t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 1 int_field 1 int_field A NULL NULL NULL BTREE +INSERT INTO t1 VALUES (1, "edno"), (1, "edno"), (2, "dve"), (3, "tri"), (5, "pet"); +"Non-copy data change - new frm, but old data and index files" +ALTER TABLE t1 +CHANGE int_field unsigned_int_field INTEGER UNSIGNED NOT NULL, +RENAME t2; +SELECT * FROM t1 ORDER BY int_field; +ERROR 42S02: Table 'test.t1' doesn't exist +SELECT * FROM t2 ORDER BY unsigned_int_field; +unsigned_int_field char_field +1 edno +1 edno +2 dve +3 tri +5 pet +DESCRIBE t2; +Field Type Null Key Default Extra +unsigned_int_field int(10) unsigned NO MUL NULL +char_field char(10) YES NULL +DESCRIBE t2; +Field Type Null Key Default Extra +unsigned_int_field int(10) unsigned NO MUL NULL +char_field char(10) YES NULL +ALTER TABLE t2 MODIFY unsigned_int_field BIGINT UNSIGNED NOT NULL; +DESCRIBE t2; +Field Type Null Key Default Extra +unsigned_int_field bigint(20) unsigned NO MUL NULL +char_field char(10) YES NULL +DROP TABLE t2; +CREATE TABLE t1 (f1 INT, f2 INT, f3 INT); +INSERT INTO t1 VALUES (1, 2, NULL); +SELECT * FROM t1; +f1 f2 f3 +1 2 NULL +ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f1; +SELECT * FROM t1; +f1 f3 f2 +1 NULL 2 +ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f2; +SELECT * FROM t1; +f1 f2 f3 +1 2 NULL +DROP TABLE t1; +create table t1 (c char(10) default "Two"); +lock table t1 write; +insert into t1 values (); +alter table t1 modify c char(10) default "Three"; +unlock tables; +select * from t1; +c +Two +check table t1; +Table Op Msg_type Msg_text +test.t1 check status OK +drop table t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (id int, c int) character set latin1; +INSERT INTO t1 VALUES (1,1); +ALTER TABLE t1 CHANGE c d int; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 CHANGE d c int; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 MODIFY c VARCHAR(10); +affected rows: 1 +info: Records: 1 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 CHANGE c d varchar(10); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 CHANGE d c varchar(10); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (id int, c int) character set utf8; +INSERT INTO t1 VALUES (1,1); +ALTER TABLE t1 CHANGE c d int; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 CHANGE d c int; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 MODIFY c VARCHAR(10); +affected rows: 1 +info: Records: 1 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 CHANGE c d varchar(10); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 CHANGE d c varchar(10); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +DROP TABLE t1; +create table t1(f1 int not null, f2 int not null, key (f1), key (f2)); +select index_length into @unpaked_keys_size from +information_schema.tables where table_name='t1'; +alter table t1 pack_keys=1; +select index_length into @paked_keys_size from +information_schema.tables where table_name='t1'; +select (@unpaked_keys_size > @paked_keys_size); +(@unpaked_keys_size > @paked_keys_size) +1 +select max_data_length into @orig_max_data_length from +information_schema.tables where table_name='t1'; +alter table t1 max_rows=100; +select max_data_length into @changed_max_data_length from +information_schema.tables where table_name='t1'; +select (@orig_max_data_length > @changed_max_data_length); +(@orig_max_data_length > @changed_max_data_length) +1 +drop table t1; +CREATE TABLE t1(a INT AUTO_INCREMENT PRIMARY KEY, +b ENUM('a', 'b', 'c') NOT NULL); +INSERT INTO t1 (b) VALUES ('a'), ('c'), ('b'), ('b'), ('a'); +ALTER TABLE t1 MODIFY b ENUM('a', 'z', 'b', 'c') NOT NULL; +SELECT * FROM t1; +a b +1 a +2 c +3 b +4 b +5 a +DROP TABLE t1; +SET @save_sql_mode=@@sql_mode; +SET sql_mode=strict_all_tables; +CREATE TABLE t1 (a int NOT NULL default 42); +INSERT INTO t1 values (); +SELECT * FROM t1; +a +42 +ALTER TABLE t1 ALTER COLUMN a DROP DEFAULT; +INSERT INTO t1 values (); +ERROR HY000: Field 'a' doesn't have a default value +INSERT INTO t1 (a) VALUES (11); +SELECT * FROM t1 ORDER BY a; +a +11 +42 +DROP TABLE t1; +SET @@sql_mode=@save_sql_mode; +# +# Bug#45567: Fast ALTER TABLE broken for enum and set +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a ENUM('a1','a2')); +INSERT INTO t1 VALUES ('a1'),('a2'); +# No copy: No modification +ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2'); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +# No copy: Add new enumeration to the end +ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','a3'); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +# Copy: Modify and add new to the end +ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','xx','a5'); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +# Copy: Remove from the end +ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','xx'); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +# Copy: Add new enumeration +ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','a0','xx'); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +# No copy: Add new enumerations to the end +ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','a0','xx','a5','a6'); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +DROP TABLE t1; +CREATE TABLE t1 (a SET('a1','a2')); +INSERT INTO t1 VALUES ('a1'),('a2'); +# No copy: No modification +ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2'); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +# No copy: Add new to the end +ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a3'); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +# Copy: Modify and add new to the end +ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','xx','a5'); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +# Copy: Remove from the end +ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','xx'); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +# Copy: Add new member +ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a0','xx'); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +# No copy: Add new to the end +ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a0','xx','a5','a6'); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +# Copy: Numerical incrase (pack lenght) +ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a0','xx','a5','a6','a7','a8','a9','a10'); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +DROP TABLE t1; +CREATE TABLE t1 (f1 TIMESTAMP NULL DEFAULT NULL, +f2 INT(11) DEFAULT NULL) ENGINE=MYISAM DEFAULT CHARSET=utf8; +INSERT INTO t1 VALUES (NULL, NULL), ("2009-10-09 11:46:19", 2); +this should affect no rows as there is no real change +ALTER TABLE t1 CHANGE COLUMN f1 f1_no_real_change TIMESTAMP NULL DEFAULT NULL; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +DROP TABLE t1; +# +# Bug #31145: ALTER TABLE DROP COLUMN, ADD COLUMN crashes (linux) +# or freezes (win) the server +# +CREATE TABLE t1 (a TEXT, id INT, b INT); +ALTER TABLE t1 DROP COLUMN a, ADD COLUMN c TEXT FIRST; +DROP TABLE t1; +# +# Test for bug #12652385 - "61493: REORDERING COLUMNS TO POSITION +# FIRST CAN CAUSE DATA TO BE CORRUPTED". +# +drop table if exists t1; +# Use MyISAM engine as the fact that InnoDB doesn't support +# in-place ALTER TABLE in cases when columns are being renamed +# hides some bugs. +create table t1 (i int, j int) engine=myisam; +insert into t1 value (1, 2); +# First, test for original problem described in the bug report. +select * from t1; +i j +1 2 +# Change of column order by the below ALTER TABLE statement should +# affect both column names and column contents. +alter table t1 modify column j int first; +select * from t1; +j i +2 1 +# Now test for similar problem with the same root. +# The below ALTER TABLE should change not only the name but +# also the value for the last column of the table. +alter table t1 drop column i, add column k int default 0; +select * from t1; +j k +2 0 +# Clean-up. +drop table t1; +End of 5.1 tests +CREATE TABLE t1(c CHAR(10), +i INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY); +INSERT INTO t1 VALUES('a',2),('b',4),('c',6); +ALTER TABLE t1 +DROP i, +ADD i INT UNSIGNED NOT NULL AUTO_INCREMENT, +AUTO_INCREMENT = 1; +DROP TABLE t1; +CREATE TABLE t1 (a CHAR(1), PRIMARY KEY (a(255))); +ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys +CREATE TABLE t1 (a CHAR(1)); +ALTER TABLE t1 ADD PRIMARY KEY (a(20)); +ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys +ALTER TABLE t1 ADD KEY (a(20)); +ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys +CREATE UNIQUE INDEX i1 ON t1 (a(20)); +ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys +CREATE INDEX i2 ON t1 (a(20)); +ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys +DROP TABLE t1; +CREATE TABLE t1 (id int); +INSERT INTO t1 VALUES (1), (2); +ALTER TABLE t1 ADD COLUMN (f1 INT), ADD COLUMN (f2 INT), ADD KEY f2k(f2); +DROP TABLE t1; +# +# Test for bug #53820 "ALTER a MEDIUMINT column table causes full +# table copy". +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a INT, b MEDIUMINT); +INSERT INTO t1 VALUES (1, 1), (2, 2); +# The below ALTER should not copy table and so no rows should +# be shown as affected. +ALTER TABLE t1 CHANGE a id INT; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +DROP TABLE t1; +# +# Bug#11754461 CANNOT ALTER TABLE WHEN KEY PREFIX TOO LONG +# +DROP DATABASE IF EXISTS db1; +CREATE DATABASE db1 CHARACTER SET utf8; +CREATE TABLE db1.t1 (bar TINYTEXT, KEY (bar(100))); +ALTER TABLE db1.t1 ADD baz INT; +DROP DATABASE db1; +# Additional coverage for refactoring which is made as part +# of fix for bug #27480 "Extend CREATE TEMPORARY TABLES privilege +# to allow temp table operations". +# +# At some point the below test case failed on assertion. +DROP TABLE IF EXISTS t1; +CREATE TEMPORARY TABLE t1 (i int) ENGINE=MyISAM; +ALTER TABLE t1 DISCARD TABLESPACE; +ERROR HY000: Storage engine MyISAM of the table `test`.`t1` doesn't have this option +DROP TABLE t1; +# +# Bug#11938039 RE-EXECUTION OF FRM-ONLY ALTER TABLE WITH RENAME +# CLAUSE FAILS OR ABORTS SERVER. +# +drop table if exists t1; +create table t1 (a int); +prepare stmt1 from 'alter table t1 alter column a set default 1, rename to t2'; +execute stmt1; +rename table t2 to t1; +# The below statement should succeed and not emit error or abort server. +execute stmt1; +deallocate prepare stmt1; +drop table t2; +# +# MDEV-8960 Can't refer the same column twice in one ALTER TABLE +# +CREATE TABLE t1 ( +`a` int(11) DEFAULT NULL +) DEFAULT CHARSET=utf8; +ALTER TABLE t1 ADD COLUMN `consultant_id` integer NOT NULL, +ALTER COLUMN `consultant_id` DROP DEFAULT; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `consultant_id` int(11) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8 +DROP TABLE t1; +CREATE TABLE t1 ( +`a` int(11) DEFAULT NULL +) DEFAULT CHARSET=utf8; +ALTER TABLE t1 ADD COLUMN `consultant_id` integer NOT NULL, +ALTER COLUMN `consultant_id` SET DEFAULT 2; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `consultant_id` int(11) NOT NULL DEFAULT 2 +) ENGINE=MyISAM DEFAULT CHARSET=utf8 +DROP TABLE t1; +CREATE TABLE t1 ( +`a` int(11) DEFAULT NULL +) DEFAULT CHARSET=utf8; +ALTER TABLE t1 ADD COLUMN `consultant_id` integer NOT NULL DEFAULT 2, +ALTER COLUMN `consultant_id` DROP DEFAULT; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `consultant_id` int(11) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8 +DROP TABLE t1; +CREATE TABLE t1 ( +`a` int(11) DEFAULT NULL +) DEFAULT CHARSET=utf8; +ALTER TABLE t1 ADD COLUMN `consultant_id` integer NOT NULL DEFAULT 2, +ALTER COLUMN `consultant_id` DROP DEFAULT, +MODIFY COLUMN `consultant_id` BIGINT; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `consultant_id` bigint(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8 +DROP TABLE t1; +# +# BUG#27788685: NO WARNING WHEN TRUNCATING A STRING WITH DATA LOSS +# +SET GLOBAL max_allowed_packet=17825792; +connect con1, localhost, root,,; +CREATE TABLE t1 (t1_fld1 TEXT); +CREATE TABLE t2 (t2_fld1 MEDIUMTEXT); +CREATE TABLE t3 (t3_fld1 LONGTEXT); +INSERT INTO t1 VALUES (REPEAT('a',300)); +INSERT INTO t2 VALUES (REPEAT('b',65680)); +INSERT INTO t3 VALUES (REPEAT('c',16777300)); +SELECT LENGTH(t1_fld1) FROM t1; +LENGTH(t1_fld1) +300 +SELECT LENGTH(t2_fld1) FROM t2; +LENGTH(t2_fld1) +65680 +SELECT LENGTH(t3_fld1) FROM t3; +LENGTH(t3_fld1) +16777300 +# With strict mode +SET SQL_MODE='STRICT_ALL_TABLES'; +ALTER TABLE t1 CHANGE `t1_fld1` `my_t1_fld1` TINYTEXT; +ERROR 22001: Data too long for column 'my_t1_fld1' at row 1 +ALTER TABLE t2 CHANGE `t2_fld1` `my_t2_fld1` TEXT; +ERROR 22001: Data too long for column 'my_t2_fld1' at row 1 +ALTER TABLE t3 CHANGE `t3_fld1` `my_t3_fld1` MEDIUMTEXT; +ERROR 22001: Data too long for column 'my_t3_fld1' at row 1 +# With non-strict mode +SET SQL_MODE=''; +ALTER TABLE t1 CHANGE `t1_fld1` `my_t1_fld1` TINYTEXT; +Warnings: +Warning 1265 Data truncated for column 'my_t1_fld1' at row 1 +ALTER TABLE t2 CHANGE `t2_fld1` `my_t2_fld1` TEXT; +Warnings: +Warning 1265 Data truncated for column 'my_t2_fld1' at row 1 +ALTER TABLE t3 CHANGE `t3_fld1` `my_t3_fld1` MEDIUMTEXT; +Warnings: +Warning 1265 Data truncated for column 'my_t3_fld1' at row 1 +SELECT LENGTH(my_t1_fld1) FROM t1; +LENGTH(my_t1_fld1) +255 +SELECT LENGTH(my_t2_fld1) FROM t2; +LENGTH(my_t2_fld1) +65535 +SELECT LENGTH(my_t3_fld1) FROM t3; +LENGTH(my_t3_fld1) +16777215 +disconnect con1; +connection default; +DROP TABLE t1, t2, t3; +SET SQL_MODE=default; +SET GLOBAL max_allowed_packet=default; +CREATE TABLE t1 ( +id INT(11) NOT NULL, +x_param INT(11) DEFAULT NULL, +PRIMARY KEY (id) +) ENGINE=MYISAM; +ALTER TABLE t1 ADD COLUMN IF NOT EXISTS id INT, +ADD COLUMN IF NOT EXISTS lol INT AFTER id; +Warnings: +Note 1060 Duplicate column name 'id' +ALTER TABLE t1 ADD COLUMN IF NOT EXISTS lol INT AFTER id; +Warnings: +Note 1060 Duplicate column name 'lol' +ALTER TABLE t1 DROP COLUMN IF EXISTS lol; +ALTER TABLE t1 DROP COLUMN IF EXISTS lol; +Warnings: +Note 1091 Can't DROP COLUMN `lol`; check that it exists +ALTER TABLE t1 ADD KEY IF NOT EXISTS x_param(x_param); +ALTER TABLE t1 ADD KEY IF NOT EXISTS x_param(x_param); +Warnings: +Note 1061 Duplicate key name 'x_param' +ALTER TABLE t1 MODIFY IF EXISTS lol INT; +Warnings: +Note 1054 Unknown column 'lol' in 't1' +DROP INDEX IF EXISTS x_param ON t1; +DROP INDEX IF EXISTS x_param ON t1; +Warnings: +Note 1091 Can't DROP INDEX `x_param`; check that it exists +CREATE INDEX IF NOT EXISTS x_param1 ON t1(x_param); +CREATE INDEX IF NOT EXISTS x_param1 ON t1(x_param); +Warnings: +Note 1061 Duplicate key name 'x_param1' +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL, + `x_param` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `x_param1` (`x_param`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( +id INT(11) NOT NULL, +x_param INT(11) DEFAULT NULL, +PRIMARY KEY (id) +) ENGINE=INNODB; +CREATE TABLE t2 ( +id INT(11) NOT NULL) ENGINE=INNODB; +ALTER TABLE t1 ADD COLUMN IF NOT EXISTS id INT, +ADD COLUMN IF NOT EXISTS lol INT AFTER id; +Warnings: +Note 1060 Duplicate column name 'id' +ALTER TABLE t1 ADD COLUMN IF NOT EXISTS lol INT AFTER id; +Warnings: +Note 1060 Duplicate column name 'lol' +ALTER TABLE t1 DROP COLUMN IF EXISTS lol; +ALTER TABLE t1 DROP COLUMN IF EXISTS lol; +Warnings: +Note 1091 Can't DROP COLUMN `lol`; check that it exists +ALTER TABLE t1 ADD KEY IF NOT EXISTS x_param(x_param); +ALTER TABLE t1 ADD KEY IF NOT EXISTS x_param(x_param); +Warnings: +Note 1061 Duplicate key name 'x_param' +ALTER TABLE t1 MODIFY IF EXISTS lol INT; +Warnings: +Note 1054 Unknown column 'lol' in 't1' +DROP INDEX IF EXISTS x_param ON t1; +DROP INDEX IF EXISTS x_param ON t1; +Warnings: +Note 1091 Can't DROP INDEX `x_param`; check that it exists +CREATE INDEX IF NOT EXISTS x_param1 ON t1(x_param); +CREATE INDEX IF NOT EXISTS x_param1 ON t1(x_param); +Warnings: +Note 1061 Duplicate key name 'x_param1' +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL, + `x_param` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `x_param1` (`x_param`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS fk(id) REFERENCES t1(id); +ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS fk(id) REFERENCES t1(id); +Warnings: +Note 1061 Duplicate key name 'fk' +ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS fk; +ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS fk; +Warnings: +Note 1091 Can't DROP FOREIGN KEY `fk`; check that it exists +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `id` int(11) NOT NULL, + KEY `fk` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +ALTER TABLE t2 ADD FOREIGN KEY (id) REFERENCES t1(id); +ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS t2_ibfk_1(id) REFERENCES t1(id); +Warnings: +Note 1061 Duplicate key name 't2_ibfk_1' +ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS t2_ibfk_1; +ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS t2_ibfk_1; +Warnings: +Note 1091 Can't DROP FOREIGN KEY `t2_ibfk_1`; check that it exists +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `id` int(11) NOT NULL, + KEY `id` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +DROP TABLE t2; +CREATE TABLE t2 ( +id INT(11) NOT NULL); +ALTER TABLE t2 ADD COLUMN a INT, ADD COLUMN IF NOT EXISTS a INT; +Warnings: +Note 1060 Duplicate column name 'a' +ALTER TABLE t2 ADD KEY k_id(id), ADD KEY IF NOT EXISTS k_id(id); +Warnings: +Note 1061 Duplicate key name 'k_id' +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `id` int(11) NOT NULL, + `a` int(11) DEFAULT NULL, + KEY `k_id` (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +ALTER TABLE t2 DROP KEY k_id, DROP KEY IF EXISTS k_id; +Warnings: +Note 1091 Can't DROP INDEX `k_id`; check that it exists +ALTER TABLE t2 DROP COLUMN a, DROP COLUMN IF EXISTS a; +Warnings: +Note 1091 Can't DROP COLUMN `a`; check that it exists +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `id` int(11) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +`transaction_id` int(11) NOT NULL DEFAULT '0', +KEY `transaction_id` (`transaction_id`)); +ALTER TABLE t1 DROP KEY IF EXISTS transaction_id, ADD PRIMARY KEY IF NOT EXISTS (transaction_id); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `transaction_id` int(11) NOT NULL DEFAULT 0, + PRIMARY KEY (`transaction_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +# Bug#11748057 (formerly known as 34972): ALTER TABLE statement doesn't +# identify correct column name. +# +CREATE TABLE t1 (c1 int unsigned , c2 char(100) not null default ''); +ALTER TABLE t1 ADD c3 char(16) NOT NULL DEFAULT '' AFTER c2, +MODIFY c2 char(100) NOT NULL DEFAULT '' AFTER c1; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` int(10) unsigned DEFAULT NULL, + `c2` char(100) NOT NULL DEFAULT '', + `c3` char(16) NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +# +# WL#5534 Online ALTER, Phase 1 +# +# Single thread tests. +# See innodb_mysql_sync.test for multi thread tests. +DROP TABLE IF EXISTS t1; +CREATE TABLE t1(a INT PRIMARY KEY, b INT) engine=InnoDB; +CREATE TABLE m1(a INT PRIMARY KEY, b INT) engine=MyISAM; +INSERT INTO t1 VALUES (1,1), (2,2); +INSERT INTO m1 VALUES (1,1), (2,2); +# +# 1: Test ALGORITHM keyword +# +# --enable_info allows us to see how many rows were updated +# by ALTER TABLE. in-place will show 0 rows, while copy > 0. +ALTER TABLE t1 ADD INDEX i1(b); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= DEFAULT; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Note 1831 Duplicate index `i2`. This is deprecated and will be disallowed in a future release +ALTER TABLE t1 ADD INDEX i3(b), ALGORITHM= COPY; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 1 +Warnings: +Note 1831 Duplicate index `i3`. This is deprecated and will be disallowed in a future release +ALTER TABLE t1 ADD INDEX i4(b), ALGORITHM= INPLACE; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Note 1831 Duplicate index `i4`. This is deprecated and will be disallowed in a future release +ALTER TABLE t1 ADD INDEX i5(b), ALGORITHM= INVALID; +ERROR HY000: Unknown ALGORITHM 'INVALID' +ALTER TABLE m1 ENABLE KEYS; +affected rows: 0 +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= DEFAULT; +affected rows: 0 +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE; +affected rows: 0 +ALTER TABLE t1 DROP INDEX i1, DROP INDEX i2, DROP INDEX i3, DROP INDEX i4; +# +# 2: Test ALGORITHM + old_alter_table +# +SET SESSION old_alter_table= 1; +affected rows: 0 +ALTER TABLE t1 ADD INDEX i1(b); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= DEFAULT; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 1 +Warnings: +Note 1831 Duplicate index `i2`. This is deprecated and will be disallowed in a future release +ALTER TABLE t1 ADD INDEX i3(b), ALGORITHM= COPY; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 1 +Warnings: +Note 1831 Duplicate index `i3`. This is deprecated and will be disallowed in a future release +ALTER TABLE t1 ADD INDEX i4(b), ALGORITHM= INPLACE; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Note 1831 Duplicate index `i4`. This is deprecated and will be disallowed in a future release +SET SESSION old_alter_table= 0; +affected rows: 0 +ALTER TABLE t1 DROP INDEX i1, DROP INDEX i2, DROP INDEX i3, DROP INDEX i4; +# +# 3: Test unsupported in-place operation +# +ALTER TABLE t1 ADD COLUMN (c1 INT); +ALTER TABLE t1 ADD COLUMN (c2 INT), ALGORITHM= DEFAULT; +ALTER TABLE t1 ADD COLUMN (c3 INT), ALGORITHM= COPY; +ALTER TABLE t1 ADD COLUMN (c4 INT), ALGORITHM= INPLACE; +ALTER TABLE t1 DROP COLUMN c1, DROP COLUMN c2, DROP COLUMN c3, DROP COLUMN c4; +# +# 4: Test LOCK keyword +# +ALTER TABLE t1 ADD INDEX i1(b), LOCK= DEFAULT; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 ADD INDEX i2(b), LOCK= NONE; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Note 1831 Duplicate index `i2`. This is deprecated and will be disallowed in a future release +ALTER TABLE t1 ADD INDEX i3(b), LOCK= SHARED; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Note 1831 Duplicate index `i3`. This is deprecated and will be disallowed in a future release +ALTER TABLE t1 ADD INDEX i4(b), LOCK= EXCLUSIVE; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Note 1831 Duplicate index `i4`. This is deprecated and will be disallowed in a future release +ALTER TABLE t1 ADD INDEX i5(b), LOCK= INVALID; +ERROR HY000: Unknown LOCK type 'INVALID' +ALTER TABLE m1 ENABLE KEYS, LOCK= DEFAULT; +ALTER TABLE m1 ENABLE KEYS, LOCK= NONE; +ERROR 0A000: LOCK=NONE/SHARED is not supported for this operation. Try LOCK=EXCLUSIVE +ALTER TABLE m1 ENABLE KEYS, LOCK= SHARED; +ERROR 0A000: LOCK=NONE/SHARED is not supported for this operation. Try LOCK=EXCLUSIVE +ALTER TABLE m1 ENABLE KEYS, LOCK= EXCLUSIVE; +ALTER TABLE t1 DROP INDEX i1, DROP INDEX i2, DROP INDEX i3, DROP INDEX i4; +# +# 5: Test ALGORITHM + LOCK +# +ALTER TABLE t1 ADD INDEX i1(b), ALGORITHM= INPLACE, LOCK= NONE; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= INPLACE, LOCK= SHARED; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Note 1831 Duplicate index `i2`. This is deprecated and will be disallowed in a future release +ALTER TABLE t1 ADD INDEX i3(b), ALGORITHM= INPLACE, LOCK= EXCLUSIVE; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Note 1831 Duplicate index `i3`. This is deprecated and will be disallowed in a future release +ALTER TABLE t1 ADD INDEX i4(b), ALGORITHM= COPY, LOCK= NONE; +ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED +ALTER TABLE t1 ADD INDEX i5(b), ALGORITHM= COPY, LOCK= SHARED; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 1 +Warnings: +Note 1831 Duplicate index `i5`. This is deprecated and will be disallowed in a future release +ALTER TABLE t1 ADD INDEX i6(b), ALGORITHM= COPY, LOCK= EXCLUSIVE; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 1 +Warnings: +Note 1831 Duplicate index `i6`. This is deprecated and will be disallowed in a future release +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE, LOCK= NONE; +ERROR 0A000: LOCK=NONE/SHARED is not supported for this operation. Try LOCK=EXCLUSIVE +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE, LOCK= SHARED; +ERROR 0A000: LOCK=NONE/SHARED is not supported for this operation. Try LOCK=EXCLUSIVE +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE, LOCK= EXCLUSIVE; +affected rows: 0 +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY, LOCK= NONE; +ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED +ALTER ONLINE TABLE m1 ADD COLUMN c int; +ERROR 0A000: LOCK=NONE is not supported for this operation. Try LOCK=SHARED +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY, LOCK= SHARED; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY, LOCK= EXCLUSIVE; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +DROP TABLE t1, m1; +# +# 6: Possible deadlock involving thr_lock.c +# +CREATE TABLE t1(a INT PRIMARY KEY, b INT); +INSERT INTO t1 VALUES (1,1), (2,2); +START TRANSACTION; +INSERT INTO t1 VALUES (3,3); +connect con1, localhost, root; +# Sending: +ALTER TABLE t1 DISABLE KEYS; +connection default; +# Waiting until ALTER TABLE is blocked. +UPDATE t1 SET b = 4; +COMMIT; +connection con1; +# Reaping: ALTER TABLE t1 DISABLE KEYS +disconnect con1; +connection default; +DROP TABLE t1; +# +# 7: Which operations require copy and which can be done in-place? +# +# Test which ALTER TABLE operations are done in-place and +# which operations are done using temporary table copy. +# +# --enable_info allows us to see how many rows were updated +# by ALTER TABLE. in-place will show 0 rows, while copy > 0. +# +DROP TABLE IF EXISTS ti1, ti2, ti3, tm1, tm2, tm3; +# Single operation tests +CREATE TABLE ti1(a INT NOT NULL, b INT, c INT) engine=InnoDB; +CREATE TABLE tm1(a INT NOT NULL, b INT, c INT) engine=MyISAM; +CREATE TABLE ti2(a INT PRIMARY KEY AUTO_INCREMENT, b INT, c INT) engine=InnoDB; +CREATE TABLE tm2(a INT PRIMARY KEY AUTO_INCREMENT, b INT, c INT) engine=MyISAM; +INSERT INTO ti1 VALUES (1,1,1), (2,2,2); +INSERT INTO ti2 VALUES (1,1,1), (2,2,2); +INSERT INTO tm1 VALUES (1,1,1), (2,2,2); +INSERT INTO tm2 VALUES (1,1,1), (2,2,2); +ALTER TABLE ti1; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 ADD COLUMN d VARCHAR(200); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 ADD COLUMN d VARCHAR(200); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 ADD COLUMN d2 VARCHAR(200); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 ADD COLUMN d2 VARCHAR(200); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 ADD COLUMN e ENUM('a', 'b') FIRST; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 ADD COLUMN e ENUM('a', 'b') FIRST; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 ADD COLUMN f INT AFTER a; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 ADD COLUMN f INT AFTER a; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 ADD INDEX ii1(b); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 ADD INDEX im1(b); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 ADD UNIQUE INDEX ii2 (c); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 ADD UNIQUE INDEX im2 (c); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 ADD FULLTEXT INDEX ii3 (d); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 ADD FULLTEXT INDEX im3 (d); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 ADD FULLTEXT INDEX ii4 (d2); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 ADD FULLTEXT INDEX im4 (d2); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 ADD PRIMARY KEY(a), ALGORITHM=INPLACE; +ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: InnoDB presently supports one FULLTEXT index creation at a time. Try ALGORITHM=COPY +ALTER TABLE ti1 ADD PRIMARY KEY(a); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 ADD PRIMARY KEY(a); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 DROP INDEX ii3; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 DROP INDEX im3; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 DROP COLUMN d2; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 DROP COLUMN d2; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 ADD CONSTRAINT fi1 FOREIGN KEY (b) REFERENCES ti2(a); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 ADD CONSTRAINT fm1 FOREIGN KEY (b) REFERENCES tm2(a); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 ALTER COLUMN b SET DEFAULT 1; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 ALTER COLUMN b SET DEFAULT 1; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 ALTER COLUMN b DROP DEFAULT; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 ALTER COLUMN b DROP DEFAULT; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 CHANGE COLUMN f g INT; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 CHANGE COLUMN f g INT; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 CHANGE COLUMN g h VARCHAR(20); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 CHANGE COLUMN g h VARCHAR(20); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 MODIFY COLUMN e ENUM('a', 'b', 'c'); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 MODIFY COLUMN e ENUM('a', 'b', 'c'); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 MODIFY COLUMN e INT; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 MODIFY COLUMN e INT; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 MODIFY COLUMN e INT AFTER h; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 MODIFY COLUMN e INT AFTER h; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 MODIFY COLUMN e INT FIRST; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 MODIFY COLUMN e INT FIRST; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +SET @orig_sql_mode = @@sql_mode; +SET @@sql_mode = 'STRICT_TRANS_TABLES'; +ALTER TABLE ti1 MODIFY COLUMN c INT NOT NULL; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +SET @@sql_mode = @orig_sql_mode; +ALTER TABLE tm1 MODIFY COLUMN c INT NOT NULL; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 MODIFY COLUMN c INT NULL; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 MODIFY COLUMN c INT NULL; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 MODIFY COLUMN h VARCHAR(30); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 MODIFY COLUMN h VARCHAR(30); +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 MODIFY COLUMN h VARCHAR(30) AFTER d; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 MODIFY COLUMN h VARCHAR(30) AFTER d; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 DROP COLUMN h; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 DROP COLUMN h; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 DROP INDEX ii2; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 DROP INDEX im2; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 DROP PRIMARY KEY; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 DROP PRIMARY KEY; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 DROP FOREIGN KEY fi1; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 DROP FOREIGN KEY fm1; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 RENAME TO ti3; +affected rows: 0 +ALTER TABLE tm1 RENAME TO tm3; +affected rows: 0 +ALTER TABLE ti3 RENAME TO ti1; +affected rows: 0 +ALTER TABLE tm3 RENAME TO tm1; +affected rows: 0 +ALTER TABLE ti1 ORDER BY b; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 ORDER BY b; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 CONVERT TO CHARACTER SET utf16; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 CONVERT TO CHARACTER SET utf16; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 DEFAULT CHARACTER SET utf8; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 DEFAULT CHARACTER SET utf8; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 FORCE; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 FORCE; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 AUTO_INCREMENT 3; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 AUTO_INCREMENT 3; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 AVG_ROW_LENGTH 10; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 AVG_ROW_LENGTH 10; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 CHECKSUM 1; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 CHECKSUM 1; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 COMMENT 'test'; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 COMMENT 'test'; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 MAX_ROWS 100; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 MAX_ROWS 100; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 MIN_ROWS 1; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 MIN_ROWS 1; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE ti1 PACK_KEYS 1; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE tm1 PACK_KEYS 1; +affected rows: 2 +info: Records: 2 Duplicates: 0 Warnings: 0 +DROP TABLE ti1, ti2, tm1, tm2; +# Tests of >1 operation (InnoDB) +CREATE TABLE ti1(a INT PRIMARY KEY AUTO_INCREMENT, b INT) engine=InnoDB; +INSERT INTO ti1(b) VALUES (1), (2); +ALTER TABLE ti1 RENAME TO ti3, ADD INDEX ii1(b); +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +ALTER TABLE ti3 DROP INDEX ii1, AUTO_INCREMENT 5; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +INSERT INTO ti3(b) VALUES (5); +ALTER TABLE ti3 ADD INDEX ii1(b), AUTO_INCREMENT 7; +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 +INSERT INTO ti3(b) VALUES (7); +SELECT * FROM ti3; +a b +1 1 +2 2 +5 5 +7 7 +DROP TABLE ti3; +# +# 8: Scenario in which ALTER TABLE was returning an unwarranted +# ER_ILLEGAL_HA error at some point during work on this WL. +# +CREATE TABLE tm1(i INT DEFAULT 1) engine=MyISAM; +ALTER TABLE tm1 ADD INDEX ii1(i), ALTER COLUMN i DROP DEFAULT; +DROP TABLE tm1; +create table if not exists t1 (i int); +alter table t1 add key (i); +alter table t1 add key if not exists (i); +Warnings: +Note 1061 Duplicate key name 'i' +DROP TABLE t1; +create table t1 (a int); +alter table t1 change column if exists a b bigint; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` bigint(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +create table t1 (i int); +alter table t1 add unique index if not exists idx(i); +alter table t1 add unique index if not exists idx(i); +Warnings: +Note 1061 Duplicate key name 'idx' +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `i` int(11) DEFAULT NULL, + UNIQUE KEY `idx` (`i`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( +`event_id` bigint(20) unsigned NOT NULL DEFAULT '0', +`market_id` bigint(20) unsigned NOT NULL DEFAULT '0', +PRIMARY KEY (`event_id`,`market_id`) +); +ALTER TABLE t1 ADD PRIMARY KEY IF NOT EXISTS event_id (event_id,market_id); +Warnings: +Note 1061 Multiple primary key defined +DROP TABLE t1; +# +# MDEV-11126 Crash while altering persistent virtual column +# +CREATE TABLE `tab1` ( +`id` bigint(20) NOT NULL AUTO_INCREMENT, +`field2` set('option1','option2','option3','option4') NOT NULL, +`field3` set('option1','option2','option3','option4','option5') NOT NULL, +`field4` set('option1','option2','option3','option4') NOT NULL, +`field5` varchar(32) NOT NULL, +`field6` varchar(32) NOT NULL, +`field7` varchar(32) NOT NULL, +`field8` varchar(32) NOT NULL, +`field9` int(11) NOT NULL DEFAULT '1', +`field10` varchar(16) NOT NULL, +`field11` enum('option1','option2','option3') NOT NULL DEFAULT 'option1', +`v_col` varchar(128) AS (IF(field11='option1',CONCAT_WS(":","field1",field2,field3,field4,field5,field6,field7,field8,field9,field10), CONCAT_WS(":","field1",field11,field2,field3,field4,field5,field6,field7,field8,field9,field10))) PERSISTENT, +PRIMARY KEY (`id`) +) DEFAULT CHARSET=latin1; +ALTER TABLE `tab1` CHANGE COLUMN v_col `v_col` varchar(128); +SHOW CREATE TABLE `tab1`; +Table Create Table +tab1 CREATE TABLE `tab1` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `field2` set('option1','option2','option3','option4') NOT NULL, + `field3` set('option1','option2','option3','option4','option5') NOT NULL, + `field4` set('option1','option2','option3','option4') NOT NULL, + `field5` varchar(32) NOT NULL, + `field6` varchar(32) NOT NULL, + `field7` varchar(32) NOT NULL, + `field8` varchar(32) NOT NULL, + `field9` int(11) NOT NULL DEFAULT 1, + `field10` varchar(16) NOT NULL, + `field11` enum('option1','option2','option3') NOT NULL DEFAULT 'option1', + `v_col` varchar(128) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +ALTER TABLE `tab1` CHANGE COLUMN v_col `v_col` varchar(128) AS (IF(field11='option1',CONCAT_WS(":","field1",field2,field3,field4,field5,field6,field7,field8,field9,field10), CONCAT_WS(":","field1",field11,field2,field3,field4,field5,field6,field7,field8,field9,field10))) PERSISTENT; +SHOW CREATE TABLE `tab1`; +Table Create Table +tab1 CREATE TABLE `tab1` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `field2` set('option1','option2','option3','option4') NOT NULL, + `field3` set('option1','option2','option3','option4','option5') NOT NULL, + `field4` set('option1','option2','option3','option4') NOT NULL, + `field5` varchar(32) NOT NULL, + `field6` varchar(32) NOT NULL, + `field7` varchar(32) NOT NULL, + `field8` varchar(32) NOT NULL, + `field9` int(11) NOT NULL DEFAULT 1, + `field10` varchar(16) NOT NULL, + `field11` enum('option1','option2','option3') NOT NULL DEFAULT 'option1', + `v_col` varchar(128) GENERATED ALWAYS AS (if(`field11` = 'option1',concat_ws(':','field1',`field2`,`field3`,`field4`,`field5`,`field6`,`field7`,`field8`,`field9`,`field10`),concat_ws(':','field1',`field11`,`field2`,`field3`,`field4`,`field5`,`field6`,`field7`,`field8`,`field9`,`field10`))) STORED, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE `tab1`; +# +# MDEV-11548 Reproducible server crash after the 2nd ALTER TABLE ADD FOREIGN KEY IF NOT EXISTS +# +CREATE TABLE t1 (id INT UNSIGNED NOT NULL PRIMARY KEY); +CREATE TABLE t2 (id1 INT UNSIGNED NOT NULL); +ALTER TABLE t2 +ADD FOREIGN KEY IF NOT EXISTS (id1) +REFERENCES t1 (id); +ALTER TABLE t2 +ADD FOREIGN KEY IF NOT EXISTS (id1) +REFERENCES t1 (id); +Warnings: +Note 1061 Duplicate key name 'id1' +DROP TABLE t2; +DROP TABLE t1; +# +# MDEV-6390 CONVERT TO CHARACTER SET utf8 doesn't change DEFAULT CHARSET. +# +CREATE TABLE t1 (id int(11) NOT NULL, a int(11) NOT NULL, b int(11)) +ENGINE=InnoDB DEFAULT CHARSET=latin1; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL, + `a` int(11) NOT NULL, + `b` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +ALTER TABLE t1 CONVERT TO CHARACTER SET utf8; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL, + `a` int(11) NOT NULL, + `b` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8 +DROP TABLE t1; +# +# MDEV-15308 +# Assertion `ha_alter_info->alter_info->drop_list.elements > 0' failed +# in ha_innodb::prepare_inplace_alter_table +# +CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB; +ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP COLUMN b; +Warnings: +Note 1091 Can't DROP FOREIGN KEY `fk`; check that it exists +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB; +ALTER TABLE t1 DROP INDEX IF EXISTS fk, DROP COLUMN b; +Warnings: +Note 1091 Can't DROP INDEX `fk`; check that it exists +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 (a INT, b INT, c INT, KEY(c)) ENGINE=InnoDB; +ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP COLUMN c; +Warnings: +Note 1091 Can't DROP FOREIGN KEY `fk`; check that it exists +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 (a INT, b INT, c INT, KEY c1(c)) ENGINE=InnoDB; +ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP INDEX c1; +Warnings: +Note 1091 Can't DROP FOREIGN KEY `fk`; check that it exists +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB; +ALTER TABLE t1 DROP INDEX IF EXISTS fk, DROP COLUMN IF EXISTS c; +Warnings: +Note 1091 Can't DROP INDEX `fk`; check that it exists +Note 1091 Can't DROP COLUMN `c`; check that it exists +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +DROP TABLE t1; +# +# MDEV-14668 ADD PRIMARY KEY IF NOT EXISTS on composite key +# +CREATE TABLE t1 ( +`ID` BIGINT(20) NOT NULL, +`RANK` MEDIUMINT(4) NOT NULL, +`CHECK_POINT` BIGINT(20) NOT NULL, +UNIQUE INDEX `HORIZON_UIDX01` (`ID`, `RANK`) +) ENGINE=InnoDB; +ALTER TABLE t1 ADD PRIMARY KEY IF NOT EXISTS (`ID`, `CHECK_POINT`); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `ID` bigint(20) NOT NULL, + `RANK` mediumint(4) NOT NULL, + `CHECK_POINT` bigint(20) NOT NULL, + PRIMARY KEY (`ID`,`CHECK_POINT`), + UNIQUE KEY `HORIZON_UIDX01` (`ID`,`RANK`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +ALTER TABLE t1 ADD PRIMARY KEY IF NOT EXISTS (`ID`, `CHECK_POINT`); +Warnings: +Note 1061 Multiple primary key defined +DROP TABLE t1; +# +# End of 10.0 tests +# +# +# MDEV-7374 : Losing connection to MySQL while running ALTER TABLE +# +CREATE TABLE t1(i INT) ENGINE=INNODB; +INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8); +INSERT INTO t1 SELECT a.* FROM t1 a, t1 b, t1 c, t1 d, t1 e; +ALTER TABLE t1 MODIFY i FLOAT; +DROP TABLE t1; +# +# MDEV-7816 ALTER with DROP INDEX and ADD INDEX .. COMMENT='comment2' ignores the new comment +# +CREATE TABLE t1(a INT); +CREATE INDEX i1 ON t1(a) COMMENT 'comment1'; +ALTER TABLE t1 DROP INDEX i1, ADD INDEX i1(a) COMMENT 'comment2'; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + KEY `i1` (`a`) COMMENT 'comment2' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +# +# End of 10.1 tests +# +# +# MDEV-10421 duplicate CHECK CONSTRAINTs +# +CREATE TABLE t1 (a INT, b INT) engine=myisam; +ALTER TABLE t1 ADD CONSTRAINT IF NOT EXISTS `min` CHECK (a+b > 100); +ALTER TABLE t1 ADD CONSTRAINT `min` CHECK (a+b > 100); +ERROR HY000: Duplicate CHECK constraint name 'min' +ALTER TABLE t1 ADD CONSTRAINT IF NOT EXISTS `min` CHECK (a+b > 100); +Warnings: +Note 1826 Duplicate CHECK constraint name 'min' +ALTER TABLE t1 ADD CONSTRAINT `mini` CHECK (a+b > 100); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL, + CONSTRAINT `min` CHECK (`a` + `b` > 100), + CONSTRAINT `mini` CHECK (`a` + `b` > 100) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1(a INT, b INT, CONSTRAINT min check (a>5), +CONSTRAINT min check (b>5)); +ERROR HY000: Duplicate CHECK constraint name 'min' +create table t1 (a int, b int, check(a>b)); +alter table t1 drop column a; +ERROR 42S22: Unknown column 'a' in 'CHECK' +alter table t1 drop column b, add column b bigint first; +ERROR 42S22: Unknown column 'b' in 'CHECK' +alter table t1 drop column a, drop constraint constraint_1; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +create table t1 (a int, b int, check(a>0)); +alter table t1 drop column a; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +create table t1 (a int, b int, check(a>0)); +alter table t1 drop column a, add column a bigint first; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` bigint(20) DEFAULT NULL, + `b` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +create table t1 (a int, b int, c int, unique(a)); +alter table t1 drop column a; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) DEFAULT NULL, + `c` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +create table t1 (a int, b int, c int, unique(a,b)); +alter table t1 drop column a; +ERROR 42000: Key column 'a' doesn't exist in table +alter table t1 drop column a, drop index a; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) DEFAULT NULL, + `c` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +create table t1 (i int); +alter table t1 alter column if exists a set default 1; +Warnings: +Note 1054 Unknown column 'a' in 't1' +alter table t1 alter column if exists a drop default; +Warnings: +Note 1054 Unknown column 'a' in 't1' +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `i` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +# +# MDEV-13508 Check that rename of columns changes defaults, virtual +# columns and constraints +# +create table t1 (a int, b int, check(a>b)); +alter table t1 change column a b int, change column b a int; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) DEFAULT NULL, + `a` int(11) DEFAULT NULL, + CONSTRAINT `CONSTRAINT_1` CHECK (`b` > `a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +create table t1 (a int primary key, b int, c int default (a+b) check (a+b>0), +d int as (a+b), +key (b), +constraint test check (a+b > 1)); +alter table t1 change b new_b int not null, add column b char(1), add constraint new check (length(b) > 0); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `new_b` int(11) NOT NULL, + `c` int(11) DEFAULT (`a` + `new_b`) CHECK (`a` + `new_b` > 0), + `d` int(11) GENERATED ALWAYS AS (`a` + `new_b`) VIRTUAL, + `b` char(1) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `b` (`new_b`), + CONSTRAINT `test` CHECK (`a` + `new_b` > 1), + CONSTRAINT `new` CHECK (octet_length(`b`) > 0) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +# +# MDEV-11071: Assertion `thd->transaction.stmt.is_empty()' failed +# in Locked_tables_list::unlock_locked_tables +# +CREATE TABLE t1 (d DATETIME DEFAULT CURRENT_TIMESTAMP, i INT) ENGINE=InnoDB; +INSERT INTO t1 (i) VALUES (1),(1); +LOCK TABLE t1 WRITE; +ALTER TABLE t1 ADD UNIQUE(i); +ERROR 23000: Duplicate entry '1' for key 'i' +UNLOCK TABLES; +DROP TABLE t1; +# ++# MDEV-17599 ALTER TABLE DROP CONSTRAINT does not work for foreign keys. ++# ++CREATE TABLE t1(id INT PRIMARY KEY, c1 INT) ENGINE= INNODB; ++CREATE TABLE t2(id INT PRIMARY KEY, c1 INT, c2 INT NOT NULL, ++CONSTRAINT sid FOREIGN KEY (`c1`) REFERENCES t1 (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, ++CONSTRAINT UNIQUE `ui`(c2)) ENGINE= INNODB; ++SHOW CREATE TABLE t2; ++Table Create Table ++t2 CREATE TABLE `t2` ( ++ `id` int(11) NOT NULL, ++ `c1` int(11) DEFAULT NULL, ++ `c2` int(11) NOT NULL, ++ PRIMARY KEY (`id`), ++ UNIQUE KEY `ui` (`c2`), ++ KEY `sid` (`c1`), ++ CONSTRAINT `sid` FOREIGN KEY (`c1`) REFERENCES `t1` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ++) ENGINE=InnoDB DEFAULT CHARSET=latin1 ++ALTER TABLE t2 DROP CONSTRAINT sid; ++SHOW CREATE TABLE t2; ++Table Create Table ++t2 CREATE TABLE `t2` ( ++ `id` int(11) NOT NULL, ++ `c1` int(11) DEFAULT NULL, ++ `c2` int(11) NOT NULL, ++ PRIMARY KEY (`id`), ++ UNIQUE KEY `ui` (`c2`), ++ KEY `sid` (`c1`) ++) ENGINE=InnoDB DEFAULT CHARSET=latin1 ++ALTER TABLE t2 DROP CONSTRAINT ui; ++SHOW CREATE TABLE t2; ++Table Create Table ++t2 CREATE TABLE `t2` ( ++ `id` int(11) NOT NULL, ++ `c1` int(11) DEFAULT NULL, ++ `c2` int(11) NOT NULL, ++ PRIMARY KEY (`id`), ++ KEY `sid` (`c1`) ++) ENGINE=InnoDB DEFAULT CHARSET=latin1 ++ALTER TABLE t2 DROP CONSTRAINT PRIMARY KEY; ++SHOW CREATE TABLE t2; ++Table Create Table ++t2 CREATE TABLE `t2` ( ++ `id` int(11) NOT NULL, ++ `c1` int(11) DEFAULT NULL, ++ `c2` int(11) NOT NULL, ++ KEY `sid` (`c1`) ++) ENGINE=InnoDB DEFAULT CHARSET=latin1 ++DROP TABLE t2, t1; ++# +# End of 10.2 tests +# +# +# MDEV-17778: Alter table leads to a truncation warning with ANALYZE command +# +set @save_use_stat_tables= @@use_stat_tables; +set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity; +set @@optimizer_use_condition_selectivity=4; +set @@use_stat_tables=PREFERABLY; +create table t1 (a int)engine=InnoDB; +insert into t1 values (1),(1),(2),(3); +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status OK +alter table t1 change a b int; +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status OK +set @@use_stat_tables= @save_use_stat_tables; +set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; +drop table t1; diff --cc mysql-test/main/alter_table.test index 829f4013cb3,00000000000..0fab5575f13 mode 100644,000000..100644 --- a/mysql-test/main/alter_table.test +++ b/mysql-test/main/alter_table.test @@@ -1,2042 -1,0 +1,2059 @@@ +--source include/have_innodb.inc +# +# Test of alter table +# +--disable_warnings +drop table if exists t1,t2; +drop database if exists mysqltest; +--enable_warnings + +create table t1 ( +col1 int not null auto_increment primary key, +col2 varchar(30) not null, +col3 varchar (20) not null, +col4 varchar(4) not null, +col5 enum('PENDING', 'ACTIVE', 'DISABLED') not null, +col6 int not null, to_be_deleted int); +insert into t1 values (2,4,3,5,"PENDING",1,7); +alter table t1 +add column col4_5 varchar(20) not null after col4, +add column col7 varchar(30) not null after col5, +add column col8 datetime not null, drop column to_be_deleted, +change column col2 fourth varchar(30) not null after col3, +modify column col6 int not null first; +select * from t1; +drop table t1; + +create table t1 (bandID MEDIUMINT UNSIGNED NOT NULL PRIMARY KEY, payoutID SMALLINT UNSIGNED NOT NULL); +insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12); +alter table t1 add column new_col int, order by payoutid,bandid; +select * from t1; +alter table t1 order by bandid,payoutid; +select * from t1; +drop table t1; + +# Check that pack_keys and dynamic length rows are not forced. + +CREATE TABLE t1 ( +GROUP_ID int(10) unsigned DEFAULT '0' NOT NULL, +LANG_ID smallint(5) unsigned DEFAULT '0' NOT NULL, +NAME varchar(80) DEFAULT '' NOT NULL, +PRIMARY KEY (GROUP_ID,LANG_ID), +KEY NAME (NAME)); +#show table status like "t1"; +ALTER TABLE t1 CHANGE NAME NAME CHAR(80) not null; +--replace_column 8 # +SHOW FULL COLUMNS FROM t1; +DROP TABLE t1; + +# +# Test of ALTER TABLE ... ORDER BY +# + +create table t1 (n int); +insert into t1 values(9),(3),(12),(10); +alter table t1 order by n; +select * from t1; +drop table t1; + +CREATE TABLE t1 ( + id int(11) unsigned NOT NULL default '0', + category_id tinyint(4) unsigned NOT NULL default '0', + type_id tinyint(4) unsigned NOT NULL default '0', + body text NOT NULL, + user_id int(11) unsigned NOT NULL default '0', + status enum('new','old') NOT NULL default 'new', + PRIMARY KEY (id) +) ENGINE=MyISAM; + +ALTER TABLE t1 ORDER BY t1.id, t1.status, t1.type_id, t1.user_id, t1.body; +DROP TABLE t1; + +# +# The following combination found a hang-bug in MyISAM +# + +CREATE TABLE t1 (AnamneseId int(10) unsigned NOT NULL auto_increment,B BLOB,PRIMARY KEY (AnamneseId)) engine=myisam; +insert into t1 values (null,"hello"); +LOCK TABLES t1 WRITE; +ALTER TABLE t1 ADD Column new_col int not null; +UNLOCK TABLES; +OPTIMIZE TABLE t1; +DROP TABLE t1; + +# +# Drop and add an auto_increment column +# + +create table t1 (i int unsigned not null auto_increment primary key); +insert into t1 values (null),(null),(null),(null); +alter table t1 drop i,add i int unsigned not null auto_increment, drop primary key, add primary key (i); +select * from t1; +drop table t1; + +# +# Bug #2628: 'alter table t1 rename mysqltest.t1' silently drops mysqltest.t1 +# if it exists +# +create table t1 (name char(15)); +insert into t1 (name) values ("current"); +create database mysqltest; +create table mysqltest.t1 (name char(15)); +insert into mysqltest.t1 (name) values ("mysqltest"); +select * from t1; +select * from mysqltest.t1; +--error ER_TABLE_EXISTS_ERROR +alter table t1 rename mysqltest.t1; +select * from t1; +select * from mysqltest.t1; +drop table t1; +drop database mysqltest; + +# +# ALTER TABLE ... ENABLE/DISABLE KEYS + +create table t1 (n1 int not null, n2 int, n3 int, n4 float, + unique(n1), + key (n1, n2, n3, n4), + key (n2, n3, n4, n1), + key (n3, n4, n1, n2), + key (n4, n1, n2, n3) ); +alter table t1 disable keys; +show keys from t1; +#let $1=10000; +let $1=10; +--disable_query_log +begin; +while ($1) +{ + eval insert into t1 values($1,RAND()*1000,RAND()*1000,RAND()); + dec $1; +} +commit; +--enable_query_log +alter table t1 enable keys; +show keys from t1; +drop table t1; + +# +# Alter table and rename +# + +create table t1 (i int unsigned not null auto_increment primary key); +alter table t1 rename t2; +alter table t2 rename t1, add c char(10) comment "no comment"; +show columns from t1; +drop table t1; + +# implicit analyze + +create table t1 (a int, b int); +let $1=100; +--disable_query_log +begin; +while ($1) +{ + eval insert into t1 values(1,$1), (2,$1), (3, $1); + dec $1; +} +commit; +--enable_query_log +alter table t1 add unique (a,b), add key (b); +show keys from t1; +analyze table t1; +show keys from t1; +drop table t1; + +# +# Test of ALTER TABLE DELAYED +# + +CREATE TABLE t1 (i int(10), index(i) ) ENGINE=MyISAM; +ALTER TABLE t1 DISABLE KEYS; +INSERT DELAYED INTO t1 VALUES(1),(2),(3); +ALTER TABLE t1 ENABLE KEYS; +drop table t1; + +# +# Test ALTER TABLE ENABLE/DISABLE keys when things are locked +# + +CREATE TABLE t1 ( + Host varchar(16) binary NOT NULL default '', + User varchar(16) binary NOT NULL default '', + PRIMARY KEY (Host,User) +) ENGINE=MyISAM; + +ALTER TABLE t1 DISABLE KEYS; +LOCK TABLES t1 WRITE; +INSERT INTO t1 VALUES ('localhost','root'),('localhost',''),('games','monty'); +SHOW INDEX FROM t1; +ALTER TABLE t1 ENABLE KEYS; +UNLOCK TABLES; +CHECK TABLES t1; +DROP TABLE t1; + +# +# Test with two keys +# + +CREATE TABLE t1 ( + Host varchar(16) binary NOT NULL default '', + User varchar(16) binary NOT NULL default '', + PRIMARY KEY (Host,User), + KEY (Host) +) ENGINE=MyISAM; + +ALTER TABLE t1 DISABLE KEYS; +SHOW INDEX FROM t1; +LOCK TABLES t1 WRITE; +INSERT INTO t1 VALUES ('localhost','root'),('localhost',''); +SHOW INDEX FROM t1; +ALTER TABLE t1 ENABLE KEYS; +SHOW INDEX FROM t1; +UNLOCK TABLES; +CHECK TABLES t1; + +# Test RENAME with LOCK TABLES +LOCK TABLES t1 WRITE; +ALTER TABLE t1 RENAME t2; +UNLOCK TABLES; +select * from t2; +DROP TABLE t2; + +# +# Test disable keys with locking +# +CREATE TABLE t1 ( + Host varchar(16) binary NOT NULL default '', + User varchar(16) binary NOT NULL default '', + PRIMARY KEY (Host,User), + KEY (Host) +) ENGINE=MyISAM; + +LOCK TABLES t1 WRITE; +ALTER TABLE t1 DISABLE KEYS; +SHOW INDEX FROM t1; +DROP TABLE t1; + +# +# BUG#4717 - check for valid table names +# +create table t1 (a int); +--error ER_WRONG_TABLE_NAME +alter table t1 rename to ``; +--error ER_WRONG_TABLE_NAME +rename table t1 to ``; +drop table t1; + +# +# BUG#6236 - ALTER TABLE MODIFY should set implicit NOT NULL on PK columns +# +drop table if exists t1, t2; +create table t1 ( a varchar(10) not null primary key ) engine=myisam; +create table t2 ( a varchar(10) not null primary key ) engine=merge union=(t1); +flush tables; +alter table t1 modify a varchar(10); +show create table t2; +flush tables; +alter table t1 modify a varchar(10) not null; +show create table t2; +drop table if exists t1, t2; + +# The following is also part of bug #6236 (CREATE TABLE didn't properly count +# not null columns for primary keys) + +create table t1 (a int, b int, c int, d int, e int, f int, g int, h int,i int, primary key (a,b,c,d,e,f,g,i,h)) engine=MyISAM; +insert ignore into t1 (a) values(1); +--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X 19 X +show table status like 't1'; +alter table t1 modify a int; +--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X 19 X +show table status like 't1'; +drop table t1; +create table t1 (a int not null, b int not null, c int not null, d int not null, e int not null, f int not null, g int not null, h int not null,i int not null, primary key (a,b,c,d,e,f,g,i,h)) engine=MyISAM; +insert ignore into t1 (a) values(1); +--replace_column 7 X 8 X 9 X 10 X 11 X 12 X 13 X 14 X 19 X +show table status like 't1'; +drop table t1; + +# +# Test that data get converted when character set is changed +# Test that data doesn't get converted when src or dst is BINARY/BLOB +# +set names koi8r; +create table t1 (a char(10) character set koi8r); +insert into t1 values ('����'); +select a,hex(a) from t1; +alter table t1 change a a char(10) character set cp1251; +select a,hex(a) from t1; +alter table t1 change a a binary(4); +select a,hex(a) from t1; +alter table t1 change a a char(10) character set cp1251; +select a,hex(a) from t1; +alter table t1 change a a char(10) character set koi8r; +select a,hex(a) from t1; +alter table t1 change a a varchar(10) character set cp1251; +select a,hex(a) from t1; +alter table t1 change a a char(10) character set koi8r; +select a,hex(a) from t1; +alter table t1 change a a text character set cp1251; +select a,hex(a) from t1; +alter table t1 change a a char(10) character set koi8r; +select a,hex(a) from t1; +delete from t1; + +# +# Test ALTER TABLE .. CHARACTER SET .. +# +show create table t1; +alter table t1 DEFAULT CHARACTER SET latin1; +show create table t1; +alter table t1 CONVERT TO CHARACTER SET latin1; +show create table t1; +alter table t1 DEFAULT CHARACTER SET cp1251; +show create table t1; + +drop table t1; + +# +# Bug#2821 +# Test that table CHARACTER SET does not affect blobs +# +create table t1 (myblob longblob,mytext longtext) +default charset latin1 collate latin1_general_cs; +show create table t1; +alter table t1 character set latin2; +show create table t1; +drop table t1; + +# +# Bug 2361 (Don't drop UNIQUE with DROP PRIMARY KEY) +# + +CREATE TABLE t1 (a int PRIMARY KEY, b INT UNIQUE); +ALTER TABLE t1 DROP PRIMARY KEY; +SHOW CREATE TABLE t1; +--error ER_CANT_DROP_FIELD_OR_KEY +ALTER TABLE t1 DROP PRIMARY KEY; +DROP TABLE t1; + +# BUG#3899 +create table t1 (a int, b int, key(a)); +insert into t1 values (1,1), (2,2); +--error ER_CANT_DROP_FIELD_OR_KEY +alter table t1 drop key no_such_key; +alter table t1 drop key a; +drop table t1; + +# +# BUG 12207 alter table ... discard table space on MyISAM table causes ERROR 2013 (HY000) +# +# Some platforms (Mac OS X, Windows) will send the error message using small letters. +CREATE TABLE T12207(a int) ENGINE=MYISAM; +--replace_result t12207 T12207 +--error ER_ILLEGAL_HA +ALTER TABLE T12207 DISCARD TABLESPACE; +DROP TABLE T12207; + +# +# Bug #6479 ALTER TABLE ... changing charset fails for TEXT columns +# +# The column's character set was changed but the actual data was not +# modified. In other words, the values were reinterpreted +# as UTF8 instead of being converted. +create table t1 (a text) character set koi8r; +insert into t1 values (_koi8r'����'); +select hex(a) from t1; +alter table t1 convert to character set cp1251; +select hex(a) from t1; +drop table t1; + +# +# Test for bug #7884 "Able to add invalid unique index on TIMESTAMP prefix" +# MySQL should not think that packed field with non-zero decimals is +# geometry field and allow to create prefix index which is +# shorter than packed field length. +# +create table t1 ( a timestamp ); +--error ER_WRONG_SUB_KEY +alter table t1 add unique ( a(1) ); +drop table t1; + +# +# Bug #24395: ALTER TABLE DISABLE KEYS doesn't work when modifying the table +# +# This problem happens if the data change is compatible. +# Changing to the same type is compatible for example. +# +--disable_warnings +drop table if exists t1; +--enable_warnings +create table t1 (a int, key(a)); +show indexes from t1; +--echo "this used not to disable the index" +alter table t1 modify a int, disable keys; +show indexes from t1; + +alter table t1 enable keys; +show indexes from t1; + +alter table t1 modify a bigint, disable keys; +show indexes from t1; + +alter table t1 enable keys; +show indexes from t1; + +alter table t1 add b char(10), disable keys; +show indexes from t1; + +alter table t1 add c decimal(10,2), enable keys; +show indexes from t1; + +--echo "this however did" +alter table t1 disable keys; +show indexes from t1; + +desc t1; + +alter table t1 add d decimal(15,5); +--echo "The key should still be disabled" +show indexes from t1; + +drop table t1; + +--echo "Now will test with one unique index" +create table t1(a int, b char(10), unique(a)); +show indexes from t1; +alter table t1 disable keys; +show indexes from t1; +alter table t1 enable keys; + +--echo "If no copy on noop change, this won't touch the data file" +--echo "Unique index, no change" +alter table t1 modify a int, disable keys; +show indexes from t1; + +--echo "Change the type implying data copy" +--echo "Unique index, no change" +alter table t1 modify a bigint, disable keys; +show indexes from t1; + +alter table t1 modify a bigint; +show indexes from t1; + +alter table t1 modify a int; +show indexes from t1; + +drop table t1; + +--echo "Now will test with one unique and one non-unique index" +create table t1(a int, b char(10), unique(a), key(b)); +show indexes from t1; +alter table t1 disable keys; +show indexes from t1; +alter table t1 enable keys; + + +--echo "If no copy on noop change, this won't touch the data file" +--echo "The non-unique index will be disabled" +alter table t1 modify a int, disable keys; +show indexes from t1; +alter table t1 enable keys; +show indexes from t1; + +--echo "Change the type implying data copy" +--echo "The non-unique index will be disabled" +alter table t1 modify a bigint, disable keys; +show indexes from t1; + +--echo "Change again the type, but leave the indexes as_is" +alter table t1 modify a int; +show indexes from t1; +--echo "Try the same. When data is no copied on similar tables, this is noop" +alter table t1 modify a int; +show indexes from t1; + +drop table t1; + + +# +# Bug#11493 - Alter table rename to default database does not work without +# db name qualifying +# +create database mysqltest; +create table t1 (c1 int); +# Move table to other database. +alter table t1 rename mysqltest.t1; +# Assure that it has moved. +--error ER_BAD_TABLE_ERROR +drop table t1; +# Move table back. +alter table mysqltest.t1 rename t1; +# Assure that it is back. +drop table t1; +# Now test for correct message if no database is selected. +# Create t1 in 'test'. +create table t1 (c1 int); +# Change to other db. +use mysqltest; +# Drop the current db. This de-selects any db. +drop database mysqltest; +# Now test for correct message. +--error ER_NO_DB_ERROR +alter table test.t1 rename t1; +# Check that explicit qualifying works even with no selected db. +alter table test.t1 rename test.t1; +# Go back to standard 'test' db. +use test; +drop table t1; + +# +# BUG#23404 - ROW_FORMAT=FIXED option is lost is an index is added to the +# table +# +CREATE TABLE t1(a INT) ROW_FORMAT=FIXED; +CREATE INDEX i1 ON t1(a); +SHOW CREATE TABLE t1; +DROP INDEX i1 ON t1; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +# +# Bug#24219 - ALTER TABLE ... RENAME TO ... , DISABLE KEYS leads to crash +# +--disable_warnings +DROP TABLE IF EXISTS bug24219; +DROP TABLE IF EXISTS bug24219_2; +--enable_warnings + +CREATE TABLE bug24219 (a INT, INDEX(a)); + +SHOW INDEX FROM bug24219; + +ALTER TABLE bug24219 RENAME TO bug24219_2, DISABLE KEYS; + +SHOW INDEX FROM bug24219_2; + +DROP TABLE bug24219_2; + +# +# Bug#24562 (ALTER TABLE ... ORDER BY ... with complex expression asserts) +# + +--disable_warnings +drop table if exists table_24562; +--enable_warnings + +create table table_24562( + section int, + subsection int, + title varchar(50)); + +insert into table_24562 values +(1, 0, "Introduction"), +(1, 1, "Authors"), +(1, 2, "Acknowledgements"), +(2, 0, "Basics"), +(2, 1, "Syntax"), +(2, 2, "Client"), +(2, 3, "Server"), +(3, 0, "Intermediate"), +(3, 1, "Complex queries"), +(3, 2, "Stored Procedures"), +(3, 3, "Stored Functions"), +(4, 0, "Advanced"), +(4, 1, "Replication"), +(4, 2, "Load balancing"), +(4, 3, "High availability"), +(5, 0, "Conclusion"); + +select * from table_24562; + +alter table table_24562 add column reviewer varchar(20), +order by title; + +select * from table_24562; + +update table_24562 set reviewer="Me" where section=2; +update table_24562 set reviewer="You" where section=3; + +alter table table_24562 +order by section ASC, subsection DESC; + +select * from table_24562; + +alter table table_24562 +order by table_24562.subsection ASC, table_24562.section DESC; + +select * from table_24562; + +--error ER_PARSE_ERROR +alter table table_24562 order by 12; +--error ER_PARSE_ERROR +alter table table_24562 order by (section + 12); +--error ER_PARSE_ERROR +alter table table_24562 order by length(title); +--error ER_PARSE_ERROR +alter table table_24562 order by (select 12 from dual); + +--error ER_BAD_FIELD_ERROR +alter table table_24562 order by no_such_col; + +drop table table_24562; + +# End of 4.1 tests + +# +# Bug #14693 (ALTER SET DEFAULT doesn't work) +# + +create table t1 (mycol int(10) not null); +alter table t1 alter column mycol set default 0; +desc t1; +drop table t1; + +# +# Bug#25262 Auto Increment lost when changing Engine type +# + +create table t1(id int(8) primary key auto_increment) engine=heap; + +insert into t1 values (null); +insert into t1 values (null); + +select * from t1; + +# Set auto increment to 50 +alter table t1 auto_increment = 50; + +# Alter to myisam +alter table t1 engine = myisam; + +# This insert should get id 50 +insert into t1 values (null); +select * from t1; + +# Alter to heap again +alter table t1 engine = heap; +insert into t1 values (null); +select * from t1; + +drop table t1; + +# +# Bug#27507: Wrong DATETIME value was allowed by ALTER TABLE in the +# NO_ZERO_DATE mode. +# +set @orig_sql_mode = @@sql_mode; +set sql_mode="no_zero_date"; +create table t1(f1 int); +alter table t1 add column f2 datetime not null, add column f21 date not null; +insert into t1 values(1,'2000-01-01','2000-01-01'); +--error 1292 +alter table t1 add column f3 datetime not null; +--error 1292 +alter table t1 add column f3 date not null; +--error 1292 +alter table t1 add column f4 datetime not null default '2002-02-02', + add column f41 date not null; +alter table t1 add column f4 datetime not null default '2002-02-02', + add column f41 date not null default '2002-02-02'; +select * from t1; +drop table t1; +set sql_mode= @orig_sql_mode; + +# +# Some additional tests for new, faster alter table. Note that most of the +# whole alter table code is being tested all around the test suite already. +# + +create table t1 (v varchar(32)); +insert into t1 values ('def'),('abc'),('hij'),('3r4f'); +select * from t1; +# Fast alter, no copy performed +alter table t1 change v v2 varchar(32); +select * from t1; +# Fast alter, no copy performed +alter table t1 change v2 v varchar(64); +select * from t1; +update t1 set v = 'lmn' where v = 'hij'; +select * from t1; +# Regular alter table +alter table t1 add i int auto_increment not null primary key first; +select * from t1; +update t1 set i=5 where i=3; +select * from t1; +alter table t1 change i i bigint; +select * from t1; +alter table t1 add unique key (i, v); +select * from t1 where i between 2 and 4 and v in ('def','3r4f','lmn'); +drop table t1; + +# +# Bug#6073 "ALTER table minor glich": ALTER TABLE complains that an index +# without # prefix is not allowed for TEXT columns, while index +# is defined with prefix. +# +create table t1 (t varchar(255) default null, key t (t(80))) +engine=myisam default charset=latin1; +alter table t1 change t t text; +drop table t1; + +# +# Bug #26794: Adding an index with a prefix on a SPATIAL type breaks ALTER +# TABLE +# +CREATE TABLE t1 (a varchar(500)); + +ALTER TABLE t1 ADD b GEOMETRY NOT NULL, ADD SPATIAL INDEX(b); +SHOW CREATE TABLE t1; +ALTER TABLE t1 ADD KEY(b(50)); +SHOW CREATE TABLE t1; + +ALTER TABLE t1 ADD c POINT; +SHOW CREATE TABLE t1; + +--error ER_WRONG_SUB_KEY +CREATE TABLE t2 (a INT, KEY (a(20))); + +ALTER TABLE t1 ADD d INT; +--error ER_WRONG_SUB_KEY +ALTER TABLE t1 ADD KEY (d(20)); + +# the 5.1 part of the test +--error ER_WRONG_SUB_KEY +ALTER TABLE t1 ADD e GEOMETRY NOT NULL, ADD SPATIAL KEY (e(30)); + +DROP TABLE t1; + +# +# Bug#18038 MySQL server corrupts binary columns data +# + +CREATE TABLE t1 (s CHAR(8) BINARY); +INSERT INTO t1 VALUES ('test'); +SELECT LENGTH(s) FROM t1; +ALTER TABLE t1 MODIFY s CHAR(10) BINARY; +SELECT LENGTH(s) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (s BINARY(8)); +INSERT INTO t1 VALUES ('test'); +SELECT LENGTH(s) FROM t1; +SELECT HEX(s) FROM t1; +ALTER TABLE t1 MODIFY s BINARY(10); +SELECT HEX(s) FROM t1; +SELECT LENGTH(s) FROM t1; +DROP TABLE t1; + +# +# Bug#19386: Multiple alter causes crashed table +# The trailing column would get corrupted data, or server could not even read +# it. +# + +CREATE TABLE t1 (v VARCHAR(3), b INT); +INSERT INTO t1 VALUES ('abc', 5); +SELECT * FROM t1; +ALTER TABLE t1 MODIFY COLUMN v VARCHAR(4); +SELECT * FROM t1; +DROP TABLE t1; + + +# +# Bug#31291 ALTER TABLE CONVERT TO CHARACTER SET does not change some data types +# +create table t1 (a tinytext character set latin1); +alter table t1 convert to character set utf8; +show create table t1; +drop table t1; +create table t1 (a mediumtext character set latin1); +alter table t1 convert to character set utf8; +show create table t1; +drop table t1; + +--echo End of 5.0 tests + +# +# Extended test coverage for ALTER TABLE behaviour under LOCK TABLES +# It should be consistent across all platforms and for all engines +# (Before 5.1 this was not true as behavior was different between +# Unix/Windows and transactional/non-transactional tables). +# See also innodb_mysql.test +# +--disable_warnings +drop table if exists t1, t2, t3; +--enable_warnings +create table t1 (i int); +create table t3 (j int); +insert into t1 values (); +insert into t3 values (); +# Table which is altered under LOCK TABLES it should stay in list of locked +# tables and be available after alter takes place unless ALTER contains RENAME +# clause. We should see the new definition of table, of course. +lock table t1 write, t3 read; +# Example of so-called 'fast' ALTER TABLE +alter table t1 modify i int default 1; +insert into t1 values (); +select * from t1; +# And now full-blown ALTER TABLE +alter table t1 change i c char(10) default "Two"; +insert into t1 values (); +select * from t1; +# If table is renamed then it should be removed from the list +# of locked tables. 'Fast' ALTER TABLE with RENAME clause: +alter table t1 modify c char(10) default "Three", rename to t2; +--error ER_TABLE_NOT_LOCKED +select * from t1; +--error ER_TABLE_NOT_LOCKED +select * from t2; +select * from t3; +unlock tables; +insert into t2 values (); +select * from t2; +lock table t2 write, t3 read; +# Full ALTER TABLE with RENAME +alter table t2 change c vc varchar(100) default "Four", rename to t1; +--error ER_TABLE_NOT_LOCKED +select * from t1; +--error ER_TABLE_NOT_LOCKED +select * from t2; +select * from t3; +unlock tables; +insert into t1 values (); +select * from t1; +drop tables t1, t3; + + +# +# Bug#18775 - Temporary table from alter table visible to other threads +# +# Check if special characters work and duplicates are detected. +--disable_warnings +DROP TABLE IF EXISTS `t+1`, `t+2`; +--enable_warnings +CREATE TABLE `t+1` (c1 INT); +ALTER TABLE `t+1` RENAME `t+2`; +CREATE TABLE `t+1` (c1 INT); +--error ER_TABLE_EXISTS_ERROR +ALTER TABLE `t+1` RENAME `t+2`; +DROP TABLE `t+1`, `t+2`; +# +# Same for temporary tables though these names do not become file names. +CREATE TEMPORARY TABLE `tt+1` (c1 INT); +ALTER TABLE `tt+1` RENAME `tt+2`; +CREATE TEMPORARY TABLE `tt+1` (c1 INT); +--error ER_TABLE_EXISTS_ERROR +ALTER TABLE `tt+1` RENAME `tt+2`; +SHOW CREATE TABLE `tt+1`; +SHOW CREATE TABLE `tt+2`; +DROP TABLE `tt+1`, `tt+2`; +# +# Check if special characters as in tmp_file_prefix work. +CREATE TABLE `#sql1` (c1 INT); +CREATE TABLE `@0023sql2` (c1 INT); +SHOW TABLES; +RENAME TABLE `#sql1` TO `@0023sql1`; +RENAME TABLE `@0023sql2` TO `#sql2`; +SHOW TABLES; +ALTER TABLE `@0023sql1` RENAME `#sql-1`; +ALTER TABLE `#sql2` RENAME `@0023sql-2`; +SHOW TABLES; +INSERT INTO `#sql-1` VALUES (1); +INSERT INTO `@0023sql-2` VALUES (2); +DROP TABLE `#sql-1`, `@0023sql-2`; +# +# Same for temporary tables though these names do not become file names. +CREATE TEMPORARY TABLE `#sql1` (c1 INT); +CREATE TEMPORARY TABLE `@0023sql2` (c1 INT); +SHOW TABLES; +ALTER TABLE `#sql1` RENAME `@0023sql1`; +ALTER TABLE `@0023sql2` RENAME `#sql2`; +SHOW TABLES; +INSERT INTO `#sql2` VALUES (1); +INSERT INTO `@0023sql1` VALUES (2); +SHOW CREATE TABLE `#sql2`; +SHOW CREATE TABLE `@0023sql1`; +DROP TABLE `#sql2`, `@0023sql1`; + +# +# Bug #22369: Alter table rename combined with other alterations causes lost tables +# +# This problem happens if the data change is compatible. +# Changing to the same type is compatible for example. +# +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +--enable_warnings +CREATE TABLE t1 ( + int_field INTEGER UNSIGNED NOT NULL, + char_field CHAR(10), + INDEX(`int_field`) +); + +DESCRIBE t1; + +SHOW INDEXES FROM t1; + +INSERT INTO t1 VALUES (1, "edno"), (1, "edno"), (2, "dve"), (3, "tri"), (5, "pet"); +--echo "Non-copy data change - new frm, but old data and index files" +ALTER TABLE t1 + CHANGE int_field unsigned_int_field INTEGER UNSIGNED NOT NULL, + RENAME t2; + +--error ER_NO_SUCH_TABLE +SELECT * FROM t1 ORDER BY int_field; +SELECT * FROM t2 ORDER BY unsigned_int_field; +DESCRIBE t2; +DESCRIBE t2; +ALTER TABLE t2 MODIFY unsigned_int_field BIGINT UNSIGNED NOT NULL; +DESCRIBE t2; + +DROP TABLE t2; + +# +# Bug#28427: Columns were renamed instead of moving by ALTER TABLE. +# +CREATE TABLE t1 (f1 INT, f2 INT, f3 INT); +INSERT INTO t1 VALUES (1, 2, NULL); +SELECT * FROM t1; +ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f1; +SELECT * FROM t1; +ALTER TABLE t1 MODIFY COLUMN f3 INT AFTER f2; +SELECT * FROM t1; +DROP TABLE t1; + +# +# BUG#29957 - alter_table.test fails +# +create table t1 (c char(10) default "Two"); +lock table t1 write; +insert into t1 values (); +alter table t1 modify c char(10) default "Three"; +unlock tables; +select * from t1; +check table t1; +drop table t1; + +# +# Bug#33873: Fast ALTER TABLE doesn't work with multibyte character sets +# + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +CREATE TABLE t1 (id int, c int) character set latin1; +INSERT INTO t1 VALUES (1,1); +--enable_info +ALTER TABLE t1 CHANGE c d int; +ALTER TABLE t1 CHANGE d c int; +ALTER TABLE t1 MODIFY c VARCHAR(10); +ALTER TABLE t1 CHANGE c d varchar(10); +ALTER TABLE t1 CHANGE d c varchar(10); +--disable_info +DROP TABLE t1; + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +CREATE TABLE t1 (id int, c int) character set utf8; +INSERT INTO t1 VALUES (1,1); +--enable_info +ALTER TABLE t1 CHANGE c d int; +ALTER TABLE t1 CHANGE d c int; +ALTER TABLE t1 MODIFY c VARCHAR(10); +ALTER TABLE t1 CHANGE c d varchar(10); +ALTER TABLE t1 CHANGE d c varchar(10); +--disable_info +DROP TABLE t1; + +# +# Bug#39372 "Smart" ALTER TABLE not so smart after all. +# +create table t1(f1 int not null, f2 int not null, key (f1), key (f2)); +let $count= 50; +--disable_query_log +begin; +while ($count) +{ + EVAL insert into t1 values (1,1),(1,1),(1,1),(1,1),(1,1); + EVAL insert into t1 values (2,2),(2,2),(2,2),(2,2),(2,2); + dec $count ; +} +commit; +--enable_query_log + +select index_length into @unpaked_keys_size from +information_schema.tables where table_name='t1'; +alter table t1 pack_keys=1; +select index_length into @paked_keys_size from +information_schema.tables where table_name='t1'; +select (@unpaked_keys_size > @paked_keys_size); + +select max_data_length into @orig_max_data_length from +information_schema.tables where table_name='t1'; +alter table t1 max_rows=100; +select max_data_length into @changed_max_data_length from +information_schema.tables where table_name='t1'; +select (@orig_max_data_length > @changed_max_data_length); + +drop table t1; + +# +# Bug #23113: Different behavior on altering ENUM fields between 5.0 and 5.1 +# +CREATE TABLE t1(a INT AUTO_INCREMENT PRIMARY KEY, + b ENUM('a', 'b', 'c') NOT NULL); +INSERT INTO t1 (b) VALUES ('a'), ('c'), ('b'), ('b'), ('a'); +ALTER TABLE t1 MODIFY b ENUM('a', 'z', 'b', 'c') NOT NULL; +SELECT * FROM t1; +DROP TABLE t1; + +# +# Test for ALTER column DROP DEFAULT +# + +SET @save_sql_mode=@@sql_mode; +SET sql_mode=strict_all_tables; + +CREATE TABLE t1 (a int NOT NULL default 42); +INSERT INTO t1 values (); +SELECT * FROM t1; +ALTER TABLE t1 ALTER COLUMN a DROP DEFAULT; +--error 1364 +INSERT INTO t1 values (); +INSERT INTO t1 (a) VALUES (11); +SELECT * FROM t1 ORDER BY a; +DROP TABLE t1; +SET @@sql_mode=@save_sql_mode; +--echo # +--echo # Bug#45567: Fast ALTER TABLE broken for enum and set +--echo # + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (a ENUM('a1','a2')); +INSERT INTO t1 VALUES ('a1'),('a2'); +--enable_info +--echo # No copy: No modification +ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2'); +--echo # No copy: Add new enumeration to the end +ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','a3'); +--echo # Copy: Modify and add new to the end +ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','xx','a5'); +--echo # Copy: Remove from the end +ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','xx'); +--echo # Copy: Add new enumeration +ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','a0','xx'); +--echo # No copy: Add new enumerations to the end +ALTER TABLE t1 MODIFY COLUMN a ENUM('a1','a2','a0','xx','a5','a6'); +--disable_info +DROP TABLE t1; + +CREATE TABLE t1 (a SET('a1','a2')); +INSERT INTO t1 VALUES ('a1'),('a2'); +--enable_info +--echo # No copy: No modification +ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2'); +--echo # No copy: Add new to the end +ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a3'); +--echo # Copy: Modify and add new to the end +ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','xx','a5'); +--echo # Copy: Remove from the end +ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','xx'); +--echo # Copy: Add new member +ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a0','xx'); +--echo # No copy: Add new to the end +ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a0','xx','a5','a6'); +--echo # Copy: Numerical incrase (pack lenght) +ALTER TABLE t1 MODIFY COLUMN a SET('a1','a2','a0','xx','a5','a6','a7','a8','a9','a10'); +--disable_info +DROP TABLE t1; + +# +# Bug#43508: Renaming timestamp or date column triggers table copy +# + +CREATE TABLE t1 (f1 TIMESTAMP NULL DEFAULT NULL, + f2 INT(11) DEFAULT NULL) ENGINE=MYISAM DEFAULT CHARSET=utf8; + +INSERT INTO t1 VALUES (NULL, NULL), ("2009-10-09 11:46:19", 2); + +--echo this should affect no rows as there is no real change +--enable_info +ALTER TABLE t1 CHANGE COLUMN f1 f1_no_real_change TIMESTAMP NULL DEFAULT NULL; +--disable_info +DROP TABLE t1; + + +--echo # +--echo # Bug #31145: ALTER TABLE DROP COLUMN, ADD COLUMN crashes (linux) +--echo # or freezes (win) the server +--echo # + +CREATE TABLE t1 (a TEXT, id INT, b INT); +ALTER TABLE t1 DROP COLUMN a, ADD COLUMN c TEXT FIRST; + +DROP TABLE t1; + + +--echo # +--echo # Test for bug #12652385 - "61493: REORDERING COLUMNS TO POSITION +--echo # FIRST CAN CAUSE DATA TO BE CORRUPTED". +--echo # +--disable_warnings +drop table if exists t1; +--enable_warnings +--echo # Use MyISAM engine as the fact that InnoDB doesn't support +--echo # in-place ALTER TABLE in cases when columns are being renamed +--echo # hides some bugs. +create table t1 (i int, j int) engine=myisam; +insert into t1 value (1, 2); +--echo # First, test for original problem described in the bug report. +select * from t1; +--echo # Change of column order by the below ALTER TABLE statement should +--echo # affect both column names and column contents. +alter table t1 modify column j int first; +select * from t1; +--echo # Now test for similar problem with the same root. +--echo # The below ALTER TABLE should change not only the name but +--echo # also the value for the last column of the table. +alter table t1 drop column i, add column k int default 0; +select * from t1; +--echo # Clean-up. +drop table t1; + + +--echo End of 5.1 tests + +# +# Bug #31031 ALTER TABLE regression in 5.0 +# +# The ALTER TABLE operation failed with +# ERROR 1089 (HY000): Incorrect sub part key; ... +# +CREATE TABLE t1(c CHAR(10), + i INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY); +INSERT INTO t1 VALUES('a',2),('b',4),('c',6); +ALTER TABLE t1 + DROP i, + ADD i INT UNSIGNED NOT NULL AUTO_INCREMENT, + AUTO_INCREMENT = 1; +DROP TABLE t1; + + +# +# Bug#50542 5.5.x doesn't check length of key prefixes: +# corruption and crash results +# +# This case is related to Bug#31031 (above) +# A statement where the index key is larger/wider than +# the column type, should cause an error +# +--error ER_WRONG_SUB_KEY +CREATE TABLE t1 (a CHAR(1), PRIMARY KEY (a(255))); + +# Test other variants of creating indices +CREATE TABLE t1 (a CHAR(1)); +# ALTER TABLE +--error ER_WRONG_SUB_KEY +ALTER TABLE t1 ADD PRIMARY KEY (a(20)); +--error ER_WRONG_SUB_KEY +ALTER TABLE t1 ADD KEY (a(20)); +# CREATE INDEX +--error ER_WRONG_SUB_KEY +CREATE UNIQUE INDEX i1 ON t1 (a(20)); +--error ER_WRONG_SUB_KEY +CREATE INDEX i2 ON t1 (a(20)); +# cleanup +DROP TABLE t1; + + +# +# Bug #45052 ALTER TABLE ADD COLUMN crashes server with multiple foreign key columns +# The alter table fails if 2 or more new fields added and +# also added a key with these fields +# +CREATE TABLE t1 (id int); +INSERT INTO t1 VALUES (1), (2); +ALTER TABLE t1 ADD COLUMN (f1 INT), ADD COLUMN (f2 INT), ADD KEY f2k(f2); +DROP TABLE t1; + + +--echo # +--echo # Test for bug #53820 "ALTER a MEDIUMINT column table causes full +--echo # table copy". +--echo # +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +CREATE TABLE t1 (a INT, b MEDIUMINT); +INSERT INTO t1 VALUES (1, 1), (2, 2); +--echo # The below ALTER should not copy table and so no rows should +--echo # be shown as affected. +--enable_info +ALTER TABLE t1 CHANGE a id INT; +--disable_info +DROP TABLE t1; + + +--echo # +--echo # Bug#11754461 CANNOT ALTER TABLE WHEN KEY PREFIX TOO LONG +--echo # + +--disable_warnings +DROP DATABASE IF EXISTS db1; +--enable_warnings + +CREATE DATABASE db1 CHARACTER SET utf8; +CREATE TABLE db1.t1 (bar TINYTEXT, KEY (bar(100))); +ALTER TABLE db1.t1 ADD baz INT; + +DROP DATABASE db1; + + +--echo # Additional coverage for refactoring which is made as part +--echo # of fix for bug #27480 "Extend CREATE TEMPORARY TABLES privilege +--echo # to allow temp table operations". +--echo # +--echo # At some point the below test case failed on assertion. + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TEMPORARY TABLE t1 (i int) ENGINE=MyISAM; + +--error ER_ILLEGAL_HA +ALTER TABLE t1 DISCARD TABLESPACE; + +DROP TABLE t1; + + +--echo # +--echo # Bug#11938039 RE-EXECUTION OF FRM-ONLY ALTER TABLE WITH RENAME +--echo # CLAUSE FAILS OR ABORTS SERVER. +--echo # +--disable_warnings +drop table if exists t1; +--enable_warnings +create table t1 (a int); +prepare stmt1 from 'alter table t1 alter column a set default 1, rename to t2'; +execute stmt1; +rename table t2 to t1; +--echo # The below statement should succeed and not emit error or abort server. +execute stmt1; +deallocate prepare stmt1; +drop table t2; + +--echo # +--echo # MDEV-8960 Can't refer the same column twice in one ALTER TABLE +--echo # + +CREATE TABLE t1 ( + `a` int(11) DEFAULT NULL +) DEFAULT CHARSET=utf8; + +ALTER TABLE t1 ADD COLUMN `consultant_id` integer NOT NULL, +ALTER COLUMN `consultant_id` DROP DEFAULT; + +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + `a` int(11) DEFAULT NULL +) DEFAULT CHARSET=utf8; + +ALTER TABLE t1 ADD COLUMN `consultant_id` integer NOT NULL, +ALTER COLUMN `consultant_id` SET DEFAULT 2; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + `a` int(11) DEFAULT NULL +) DEFAULT CHARSET=utf8; + +ALTER TABLE t1 ADD COLUMN `consultant_id` integer NOT NULL DEFAULT 2, +ALTER COLUMN `consultant_id` DROP DEFAULT; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + `a` int(11) DEFAULT NULL +) DEFAULT CHARSET=utf8; + +ALTER TABLE t1 ADD COLUMN `consultant_id` integer NOT NULL DEFAULT 2, +ALTER COLUMN `consultant_id` DROP DEFAULT, +MODIFY COLUMN `consultant_id` BIGINT; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo # +--echo # BUG#27788685: NO WARNING WHEN TRUNCATING A STRING WITH DATA LOSS +--echo # + +SET GLOBAL max_allowed_packet=17825792; + +--connect(con1, localhost, root,,) +CREATE TABLE t1 (t1_fld1 TEXT); +CREATE TABLE t2 (t2_fld1 MEDIUMTEXT); +CREATE TABLE t3 (t3_fld1 LONGTEXT); + +INSERT INTO t1 VALUES (REPEAT('a',300)); +INSERT INTO t2 VALUES (REPEAT('b',65680)); +INSERT INTO t3 VALUES (REPEAT('c',16777300)); + +SELECT LENGTH(t1_fld1) FROM t1; +SELECT LENGTH(t2_fld1) FROM t2; +SELECT LENGTH(t3_fld1) FROM t3; + +--echo # With strict mode +SET SQL_MODE='STRICT_ALL_TABLES'; + +--error ER_DATA_TOO_LONG +ALTER TABLE t1 CHANGE `t1_fld1` `my_t1_fld1` TINYTEXT; +--error ER_DATA_TOO_LONG +ALTER TABLE t2 CHANGE `t2_fld1` `my_t2_fld1` TEXT; +--error ER_DATA_TOO_LONG +ALTER TABLE t3 CHANGE `t3_fld1` `my_t3_fld1` MEDIUMTEXT; + +--echo # With non-strict mode +SET SQL_MODE=''; + +ALTER TABLE t1 CHANGE `t1_fld1` `my_t1_fld1` TINYTEXT; +ALTER TABLE t2 CHANGE `t2_fld1` `my_t2_fld1` TEXT; +ALTER TABLE t3 CHANGE `t3_fld1` `my_t3_fld1` MEDIUMTEXT; + +SELECT LENGTH(my_t1_fld1) FROM t1; +SELECT LENGTH(my_t2_fld1) FROM t2; +SELECT LENGTH(my_t3_fld1) FROM t3; + +# Cleanup +--disconnect con1 +--source include/wait_until_disconnected.inc + +--connection default +DROP TABLE t1, t2, t3; + +SET SQL_MODE=default; +SET GLOBAL max_allowed_packet=default; + +# +# Test of ALTER TABLE IF [NOT] EXISTS +# + +CREATE TABLE t1 ( + id INT(11) NOT NULL, + x_param INT(11) DEFAULT NULL, + PRIMARY KEY (id) +) ENGINE=MYISAM; + +ALTER TABLE t1 ADD COLUMN IF NOT EXISTS id INT, + ADD COLUMN IF NOT EXISTS lol INT AFTER id; +ALTER TABLE t1 ADD COLUMN IF NOT EXISTS lol INT AFTER id; +ALTER TABLE t1 DROP COLUMN IF EXISTS lol; +ALTER TABLE t1 DROP COLUMN IF EXISTS lol; + +ALTER TABLE t1 ADD KEY IF NOT EXISTS x_param(x_param); +ALTER TABLE t1 ADD KEY IF NOT EXISTS x_param(x_param); +ALTER TABLE t1 MODIFY IF EXISTS lol INT; + +DROP INDEX IF EXISTS x_param ON t1; +DROP INDEX IF EXISTS x_param ON t1; +CREATE INDEX IF NOT EXISTS x_param1 ON t1(x_param); +CREATE INDEX IF NOT EXISTS x_param1 ON t1(x_param); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + id INT(11) NOT NULL, + x_param INT(11) DEFAULT NULL, + PRIMARY KEY (id) +) ENGINE=INNODB; + +CREATE TABLE t2 ( + id INT(11) NOT NULL) ENGINE=INNODB; + +ALTER TABLE t1 ADD COLUMN IF NOT EXISTS id INT, + ADD COLUMN IF NOT EXISTS lol INT AFTER id; +ALTER TABLE t1 ADD COLUMN IF NOT EXISTS lol INT AFTER id; +ALTER TABLE t1 DROP COLUMN IF EXISTS lol; +ALTER TABLE t1 DROP COLUMN IF EXISTS lol; + +ALTER TABLE t1 ADD KEY IF NOT EXISTS x_param(x_param); +ALTER TABLE t1 ADD KEY IF NOT EXISTS x_param(x_param); +ALTER TABLE t1 MODIFY IF EXISTS lol INT; + +DROP INDEX IF EXISTS x_param ON t1; +DROP INDEX IF EXISTS x_param ON t1; +CREATE INDEX IF NOT EXISTS x_param1 ON t1(x_param); +CREATE INDEX IF NOT EXISTS x_param1 ON t1(x_param); +SHOW CREATE TABLE t1; + +ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS fk(id) REFERENCES t1(id); +ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS fk(id) REFERENCES t1(id); +ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS fk; +ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS fk; +SHOW CREATE TABLE t2; +ALTER TABLE t2 ADD FOREIGN KEY (id) REFERENCES t1(id); +ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS t2_ibfk_1(id) REFERENCES t1(id); +ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS t2_ibfk_1; +ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS t2_ibfk_1; +SHOW CREATE TABLE t2; + +DROP TABLE t2; +CREATE TABLE t2 ( + id INT(11) NOT NULL); +ALTER TABLE t2 ADD COLUMN a INT, ADD COLUMN IF NOT EXISTS a INT; +ALTER TABLE t2 ADD KEY k_id(id), ADD KEY IF NOT EXISTS k_id(id); +SHOW CREATE TABLE t2; +ALTER TABLE t2 DROP KEY k_id, DROP KEY IF EXISTS k_id; +ALTER TABLE t2 DROP COLUMN a, DROP COLUMN IF EXISTS a; +SHOW CREATE TABLE t2; + +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + `transaction_id` int(11) NOT NULL DEFAULT '0', + KEY `transaction_id` (`transaction_id`)); +ALTER TABLE t1 DROP KEY IF EXISTS transaction_id, ADD PRIMARY KEY IF NOT EXISTS (transaction_id); +SHOW CREATE TABLE t1; + +DROP TABLE t1; + +--echo # Bug#11748057 (formerly known as 34972): ALTER TABLE statement doesn't +--echo # identify correct column name. +--echo # + +CREATE TABLE t1 (c1 int unsigned , c2 char(100) not null default ''); +ALTER TABLE t1 ADD c3 char(16) NOT NULL DEFAULT '' AFTER c2, + MODIFY c2 char(100) NOT NULL DEFAULT '' AFTER c1; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo # +--echo # WL#5534 Online ALTER, Phase 1 +--echo # + +--echo # Single thread tests. +--echo # See innodb_mysql_sync.test for multi thread tests. + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1(a INT PRIMARY KEY, b INT) engine=InnoDB; +CREATE TABLE m1(a INT PRIMARY KEY, b INT) engine=MyISAM; +INSERT INTO t1 VALUES (1,1), (2,2); +INSERT INTO m1 VALUES (1,1), (2,2); + +--echo # +--echo # 1: Test ALGORITHM keyword +--echo # + +--echo # --enable_info allows us to see how many rows were updated +--echo # by ALTER TABLE. in-place will show 0 rows, while copy > 0. + +--enable_info +ALTER TABLE t1 ADD INDEX i1(b); +ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= DEFAULT; +ALTER TABLE t1 ADD INDEX i3(b), ALGORITHM= COPY; +ALTER TABLE t1 ADD INDEX i4(b), ALGORITHM= INPLACE; +--error ER_UNKNOWN_ALTER_ALGORITHM +ALTER TABLE t1 ADD INDEX i5(b), ALGORITHM= INVALID; + +ALTER TABLE m1 ENABLE KEYS; +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= DEFAULT; +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY; +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE; +--disable_info + +ALTER TABLE t1 DROP INDEX i1, DROP INDEX i2, DROP INDEX i3, DROP INDEX i4; + +--echo # +--echo # 2: Test ALGORITHM + old_alter_table +--echo # + +--enable_info +SET SESSION old_alter_table= 1; +ALTER TABLE t1 ADD INDEX i1(b); +ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= DEFAULT; +ALTER TABLE t1 ADD INDEX i3(b), ALGORITHM= COPY; +ALTER TABLE t1 ADD INDEX i4(b), ALGORITHM= INPLACE; +SET SESSION old_alter_table= 0; +--disable_info + +ALTER TABLE t1 DROP INDEX i1, DROP INDEX i2, DROP INDEX i3, DROP INDEX i4; + +--echo # +--echo # 3: Test unsupported in-place operation +--echo # + +ALTER TABLE t1 ADD COLUMN (c1 INT); +ALTER TABLE t1 ADD COLUMN (c2 INT), ALGORITHM= DEFAULT; +ALTER TABLE t1 ADD COLUMN (c3 INT), ALGORITHM= COPY; +ALTER TABLE t1 ADD COLUMN (c4 INT), ALGORITHM= INPLACE; + +ALTER TABLE t1 DROP COLUMN c1, DROP COLUMN c2, DROP COLUMN c3, DROP COLUMN c4; + +--echo # +--echo # 4: Test LOCK keyword +--echo # + +--enable_info +ALTER TABLE t1 ADD INDEX i1(b), LOCK= DEFAULT; +ALTER TABLE t1 ADD INDEX i2(b), LOCK= NONE; +ALTER TABLE t1 ADD INDEX i3(b), LOCK= SHARED; +ALTER TABLE t1 ADD INDEX i4(b), LOCK= EXCLUSIVE; +--error ER_UNKNOWN_ALTER_LOCK +ALTER TABLE t1 ADD INDEX i5(b), LOCK= INVALID; +--disable_info + +ALTER TABLE m1 ENABLE KEYS, LOCK= DEFAULT; +--error ER_ALTER_OPERATION_NOT_SUPPORTED +ALTER TABLE m1 ENABLE KEYS, LOCK= NONE; +--error ER_ALTER_OPERATION_NOT_SUPPORTED +ALTER TABLE m1 ENABLE KEYS, LOCK= SHARED; +ALTER TABLE m1 ENABLE KEYS, LOCK= EXCLUSIVE; + +ALTER TABLE t1 DROP INDEX i1, DROP INDEX i2, DROP INDEX i3, DROP INDEX i4; + +--echo # +--echo # 5: Test ALGORITHM + LOCK +--echo # + +--enable_info +ALTER TABLE t1 ADD INDEX i1(b), ALGORITHM= INPLACE, LOCK= NONE; +ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= INPLACE, LOCK= SHARED; +ALTER TABLE t1 ADD INDEX i3(b), ALGORITHM= INPLACE, LOCK= EXCLUSIVE; +--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON +ALTER TABLE t1 ADD INDEX i4(b), ALGORITHM= COPY, LOCK= NONE; +ALTER TABLE t1 ADD INDEX i5(b), ALGORITHM= COPY, LOCK= SHARED; +ALTER TABLE t1 ADD INDEX i6(b), ALGORITHM= COPY, LOCK= EXCLUSIVE; + +--error ER_ALTER_OPERATION_NOT_SUPPORTED +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE, LOCK= NONE; +--error ER_ALTER_OPERATION_NOT_SUPPORTED +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE, LOCK= SHARED; +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= INPLACE, LOCK= EXCLUSIVE; +--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY, LOCK= NONE; +--error ER_ALTER_OPERATION_NOT_SUPPORTED +ALTER ONLINE TABLE m1 ADD COLUMN c int; +# This works because the lock will be SNW for the copy phase. +# It will still require exclusive lock for actually enabling keys. +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY, LOCK= SHARED; +ALTER TABLE m1 ENABLE KEYS, ALGORITHM= COPY, LOCK= EXCLUSIVE; +--disable_info + +DROP TABLE t1, m1; + +--echo # +--echo # 6: Possible deadlock involving thr_lock.c +--echo # + +CREATE TABLE t1(a INT PRIMARY KEY, b INT); +INSERT INTO t1 VALUES (1,1), (2,2); + +START TRANSACTION; +INSERT INTO t1 VALUES (3,3); + +connect (con1, localhost, root); +--echo # Sending: +--send ALTER TABLE t1 DISABLE KEYS + +connection default; +--echo # Waiting until ALTER TABLE is blocked. +let $wait_condition= + SELECT COUNT(*) = 1 FROM information_schema.processlist + WHERE state = "Waiting for table metadata lock" AND + info = "ALTER TABLE t1 DISABLE KEYS"; +--source include/wait_condition.inc +UPDATE t1 SET b = 4; +COMMIT; + +connection con1; +--echo # Reaping: ALTER TABLE t1 DISABLE KEYS +--reap +disconnect con1; +--source include/wait_until_disconnected.inc + +connection default; +DROP TABLE t1; + +--echo # +--echo # 7: Which operations require copy and which can be done in-place? +--echo # +--echo # Test which ALTER TABLE operations are done in-place and +--echo # which operations are done using temporary table copy. +--echo # +--echo # --enable_info allows us to see how many rows were updated +--echo # by ALTER TABLE. in-place will show 0 rows, while copy > 0. +--echo # + +--disable_warnings +DROP TABLE IF EXISTS ti1, ti2, ti3, tm1, tm2, tm3; +--enable_warnings + +--echo # Single operation tests + +CREATE TABLE ti1(a INT NOT NULL, b INT, c INT) engine=InnoDB; +CREATE TABLE tm1(a INT NOT NULL, b INT, c INT) engine=MyISAM; +CREATE TABLE ti2(a INT PRIMARY KEY AUTO_INCREMENT, b INT, c INT) engine=InnoDB; +CREATE TABLE tm2(a INT PRIMARY KEY AUTO_INCREMENT, b INT, c INT) engine=MyISAM; +INSERT INTO ti1 VALUES (1,1,1), (2,2,2); +INSERT INTO ti2 VALUES (1,1,1), (2,2,2); +INSERT INTO tm1 VALUES (1,1,1), (2,2,2); +INSERT INTO tm2 VALUES (1,1,1), (2,2,2); + +--enable_info +ALTER TABLE ti1; +ALTER TABLE tm1; + +ALTER TABLE ti1 ADD COLUMN d VARCHAR(200); +ALTER TABLE tm1 ADD COLUMN d VARCHAR(200); +ALTER TABLE ti1 ADD COLUMN d2 VARCHAR(200); +ALTER TABLE tm1 ADD COLUMN d2 VARCHAR(200); +ALTER TABLE ti1 ADD COLUMN e ENUM('a', 'b') FIRST; +ALTER TABLE tm1 ADD COLUMN e ENUM('a', 'b') FIRST; +ALTER TABLE ti1 ADD COLUMN f INT AFTER a; +ALTER TABLE tm1 ADD COLUMN f INT AFTER a; + +ALTER TABLE ti1 ADD INDEX ii1(b); +ALTER TABLE tm1 ADD INDEX im1(b); +ALTER TABLE ti1 ADD UNIQUE INDEX ii2 (c); +ALTER TABLE tm1 ADD UNIQUE INDEX im2 (c); +ALTER TABLE ti1 ADD FULLTEXT INDEX ii3 (d); +ALTER TABLE tm1 ADD FULLTEXT INDEX im3 (d); +ALTER TABLE ti1 ADD FULLTEXT INDEX ii4 (d2); +ALTER TABLE tm1 ADD FULLTEXT INDEX im4 (d2); + +# Bug#14140038 INCONSISTENT HANDLING OF FULLTEXT INDEXES IN ALTER TABLE +--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON +ALTER TABLE ti1 ADD PRIMARY KEY(a), ALGORITHM=INPLACE; +ALTER TABLE ti1 ADD PRIMARY KEY(a); +ALTER TABLE tm1 ADD PRIMARY KEY(a); + +ALTER TABLE ti1 DROP INDEX ii3; +ALTER TABLE tm1 DROP INDEX im3; + +ALTER TABLE ti1 DROP COLUMN d2; +ALTER TABLE tm1 DROP COLUMN d2; + +ALTER TABLE ti1 ADD CONSTRAINT fi1 FOREIGN KEY (b) REFERENCES ti2(a); +ALTER TABLE tm1 ADD CONSTRAINT fm1 FOREIGN KEY (b) REFERENCES tm2(a); + +ALTER TABLE ti1 ALTER COLUMN b SET DEFAULT 1; +ALTER TABLE tm1 ALTER COLUMN b SET DEFAULT 1; +ALTER TABLE ti1 ALTER COLUMN b DROP DEFAULT; +ALTER TABLE tm1 ALTER COLUMN b DROP DEFAULT; + +# This will set both ALTER_COLUMN_NAME and COLUMN_DEFAULT_VALUE +ALTER TABLE ti1 CHANGE COLUMN f g INT; +ALTER TABLE tm1 CHANGE COLUMN f g INT; +ALTER TABLE ti1 CHANGE COLUMN g h VARCHAR(20); +ALTER TABLE tm1 CHANGE COLUMN g h VARCHAR(20); +ALTER TABLE ti1 MODIFY COLUMN e ENUM('a', 'b', 'c'); +ALTER TABLE tm1 MODIFY COLUMN e ENUM('a', 'b', 'c'); +ALTER TABLE ti1 MODIFY COLUMN e INT; +ALTER TABLE tm1 MODIFY COLUMN e INT; +# This will set both ALTER_COLUMN_ORDER and COLUMN_DEFAULT_VALUE +ALTER TABLE ti1 MODIFY COLUMN e INT AFTER h; +ALTER TABLE tm1 MODIFY COLUMN e INT AFTER h; +ALTER TABLE ti1 MODIFY COLUMN e INT FIRST; +ALTER TABLE tm1 MODIFY COLUMN e INT FIRST; +# This will set both ALTER_COLUMN_NOT_NULLABLE and COLUMN_DEFAULT_VALUE +--disable_info +# NULL -> NOT NULL only allowed INPLACE if strict sql_mode is on. +SET @orig_sql_mode = @@sql_mode; +SET @@sql_mode = 'STRICT_TRANS_TABLES'; +--enable_info +ALTER TABLE ti1 MODIFY COLUMN c INT NOT NULL; +--disable_info +SET @@sql_mode = @orig_sql_mode; +--enable_info +ALTER TABLE tm1 MODIFY COLUMN c INT NOT NULL; +# This will set both ALTER_COLUMN_NULLABLE and COLUMN_DEFAULT_VALUE +ALTER TABLE ti1 MODIFY COLUMN c INT NULL; +ALTER TABLE tm1 MODIFY COLUMN c INT NULL; +# This will set both ALTER_COLUMN_EQUAL_PACK_LENGTH and COLUMN_DEFAULT_VALUE +ALTER TABLE ti1 MODIFY COLUMN h VARCHAR(30); +ALTER TABLE tm1 MODIFY COLUMN h VARCHAR(30); +ALTER TABLE ti1 MODIFY COLUMN h VARCHAR(30) AFTER d; +ALTER TABLE tm1 MODIFY COLUMN h VARCHAR(30) AFTER d; + +ALTER TABLE ti1 DROP COLUMN h; +ALTER TABLE tm1 DROP COLUMN h; + +ALTER TABLE ti1 DROP INDEX ii2; +ALTER TABLE tm1 DROP INDEX im2; +ALTER TABLE ti1 DROP PRIMARY KEY; +ALTER TABLE tm1 DROP PRIMARY KEY; + +ALTER TABLE ti1 DROP FOREIGN KEY fi1; +ALTER TABLE tm1 DROP FOREIGN KEY fm1; + +ALTER TABLE ti1 RENAME TO ti3; +ALTER TABLE tm1 RENAME TO tm3; +ALTER TABLE ti3 RENAME TO ti1; +ALTER TABLE tm3 RENAME TO tm1; + +ALTER TABLE ti1 ORDER BY b; +ALTER TABLE tm1 ORDER BY b; + +ALTER TABLE ti1 CONVERT TO CHARACTER SET utf16; +ALTER TABLE tm1 CONVERT TO CHARACTER SET utf16; +ALTER TABLE ti1 DEFAULT CHARACTER SET utf8; +ALTER TABLE tm1 DEFAULT CHARACTER SET utf8; + +ALTER TABLE ti1 FORCE; +ALTER TABLE tm1 FORCE; + +ALTER TABLE ti1 AUTO_INCREMENT 3; +ALTER TABLE tm1 AUTO_INCREMENT 3; +ALTER TABLE ti1 AVG_ROW_LENGTH 10; +ALTER TABLE tm1 AVG_ROW_LENGTH 10; +ALTER TABLE ti1 CHECKSUM 1; +ALTER TABLE tm1 CHECKSUM 1; +ALTER TABLE ti1 COMMENT 'test'; +ALTER TABLE tm1 COMMENT 'test'; +ALTER TABLE ti1 MAX_ROWS 100; +ALTER TABLE tm1 MAX_ROWS 100; +ALTER TABLE ti1 MIN_ROWS 1; +ALTER TABLE tm1 MIN_ROWS 1; +ALTER TABLE ti1 PACK_KEYS 1; +ALTER TABLE tm1 PACK_KEYS 1; + +--disable_info +DROP TABLE ti1, ti2, tm1, tm2; + +--echo # Tests of >1 operation (InnoDB) + +CREATE TABLE ti1(a INT PRIMARY KEY AUTO_INCREMENT, b INT) engine=InnoDB; +INSERT INTO ti1(b) VALUES (1), (2); + +--enable_info +ALTER TABLE ti1 RENAME TO ti3, ADD INDEX ii1(b); + +ALTER TABLE ti3 DROP INDEX ii1, AUTO_INCREMENT 5; +--disable_info +INSERT INTO ti3(b) VALUES (5); +--enable_info +ALTER TABLE ti3 ADD INDEX ii1(b), AUTO_INCREMENT 7; +--disable_info +INSERT INTO ti3(b) VALUES (7); +SELECT * FROM ti3; + +DROP TABLE ti3; + +--echo # +--echo # 8: Scenario in which ALTER TABLE was returning an unwarranted +--echo # ER_ILLEGAL_HA error at some point during work on this WL. +--echo # + +CREATE TABLE tm1(i INT DEFAULT 1) engine=MyISAM; +ALTER TABLE tm1 ADD INDEX ii1(i), ALTER COLUMN i DROP DEFAULT; +DROP TABLE tm1; + +# +# MDEV-4435 Server crashes in my_strcasecmp_utf8 on ADD KEY IF NOT EXISTS with implicit name when the key exists. +# +create table if not exists t1 (i int); +alter table t1 add key (i); +alter table t1 add key if not exists (i); +DROP TABLE t1; + +# +# MDEV-4436 CHANGE COLUMN IF EXISTS does not work and throws wrong warning. +# +create table t1 (a int); +alter table t1 change column if exists a b bigint; +show create table t1; +DROP TABLE t1; + +# +# MDEV-4437 ALTER TABLE .. ADD UNIQUE INDEX IF NOT EXISTS causes syntax error. +# + +create table t1 (i int); +alter table t1 add unique index if not exists idx(i); +alter table t1 add unique index if not exists idx(i); +show create table t1; +DROP TABLE t1; + +# +# MDEV-8358 ADD PRIMARY KEY IF NOT EXISTS -> ERROR 1068 (42000): Multiple primary key +# + +CREATE TABLE t1 ( + `event_id` bigint(20) unsigned NOT NULL DEFAULT '0', + `market_id` bigint(20) unsigned NOT NULL DEFAULT '0', + PRIMARY KEY (`event_id`,`market_id`) + ); +ALTER TABLE t1 ADD PRIMARY KEY IF NOT EXISTS event_id (event_id,market_id); +DROP TABLE t1; + +--echo # +--echo # MDEV-11126 Crash while altering persistent virtual column +--echo # + +CREATE TABLE `tab1` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `field2` set('option1','option2','option3','option4') NOT NULL, + `field3` set('option1','option2','option3','option4','option5') NOT NULL, + `field4` set('option1','option2','option3','option4') NOT NULL, + `field5` varchar(32) NOT NULL, + `field6` varchar(32) NOT NULL, + `field7` varchar(32) NOT NULL, + `field8` varchar(32) NOT NULL, + `field9` int(11) NOT NULL DEFAULT '1', + `field10` varchar(16) NOT NULL, + `field11` enum('option1','option2','option3') NOT NULL DEFAULT 'option1', + `v_col` varchar(128) AS (IF(field11='option1',CONCAT_WS(":","field1",field2,field3,field4,field5,field6,field7,field8,field9,field10), CONCAT_WS(":","field1",field11,field2,field3,field4,field5,field6,field7,field8,field9,field10))) PERSISTENT, + PRIMARY KEY (`id`) +) DEFAULT CHARSET=latin1; + +ALTER TABLE `tab1` CHANGE COLUMN v_col `v_col` varchar(128); +SHOW CREATE TABLE `tab1`; +ALTER TABLE `tab1` CHANGE COLUMN v_col `v_col` varchar(128) AS (IF(field11='option1',CONCAT_WS(":","field1",field2,field3,field4,field5,field6,field7,field8,field9,field10), CONCAT_WS(":","field1",field11,field2,field3,field4,field5,field6,field7,field8,field9,field10))) PERSISTENT; +SHOW CREATE TABLE `tab1`; +DROP TABLE `tab1`; + +--echo # +--echo # MDEV-11548 Reproducible server crash after the 2nd ALTER TABLE ADD FOREIGN KEY IF NOT EXISTS +--echo # + +CREATE TABLE t1 (id INT UNSIGNED NOT NULL PRIMARY KEY); +CREATE TABLE t2 (id1 INT UNSIGNED NOT NULL); + +ALTER TABLE t2 +ADD FOREIGN KEY IF NOT EXISTS (id1) + REFERENCES t1 (id); + +ALTER TABLE t2 +ADD FOREIGN KEY IF NOT EXISTS (id1) +REFERENCES t1 (id); + +DROP TABLE t2; +DROP TABLE t1; + +--echo # +--echo # MDEV-6390 CONVERT TO CHARACTER SET utf8 doesn't change DEFAULT CHARSET. +--echo # + +CREATE TABLE t1 (id int(11) NOT NULL, a int(11) NOT NULL, b int(11)) + ENGINE=InnoDB DEFAULT CHARSET=latin1; +SHOW CREATE TABLE t1; +ALTER TABLE t1 CONVERT TO CHARACTER SET utf8; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-15308 +--echo # Assertion `ha_alter_info->alter_info->drop_list.elements > 0' failed +--echo # in ha_innodb::prepare_inplace_alter_table +--echo # + +CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB; +ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP COLUMN b; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB; +ALTER TABLE t1 DROP INDEX IF EXISTS fk, DROP COLUMN b; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, c INT, KEY(c)) ENGINE=InnoDB; +ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP COLUMN c; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT, c INT, KEY c1(c)) ENGINE=InnoDB; +ALTER TABLE t1 DROP FOREIGN KEY IF EXISTS fk, DROP INDEX c1; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INT, b INT) ENGINE=InnoDB; +ALTER TABLE t1 DROP INDEX IF EXISTS fk, DROP COLUMN IF EXISTS c; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-14668 ADD PRIMARY KEY IF NOT EXISTS on composite key +--echo # +CREATE TABLE t1 ( + `ID` BIGINT(20) NOT NULL, + `RANK` MEDIUMINT(4) NOT NULL, + `CHECK_POINT` BIGINT(20) NOT NULL, + UNIQUE INDEX `HORIZON_UIDX01` (`ID`, `RANK`) + ) ENGINE=InnoDB; + +ALTER TABLE t1 ADD PRIMARY KEY IF NOT EXISTS (`ID`, `CHECK_POINT`); +SHOW CREATE TABLE t1; +ALTER TABLE t1 ADD PRIMARY KEY IF NOT EXISTS (`ID`, `CHECK_POINT`); +DROP TABLE t1; + +--echo # +--echo # End of 10.0 tests +--echo # + +--echo # +--echo # MDEV-7374 : Losing connection to MySQL while running ALTER TABLE +--echo # +CREATE TABLE t1(i INT) ENGINE=INNODB; +INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8); +INSERT INTO t1 SELECT a.* FROM t1 a, t1 b, t1 c, t1 d, t1 e; +ALTER TABLE t1 MODIFY i FLOAT; +DROP TABLE t1; + +--echo # +--echo # MDEV-7816 ALTER with DROP INDEX and ADD INDEX .. COMMENT='comment2' ignores the new comment +--echo # +CREATE TABLE t1(a INT); +CREATE INDEX i1 ON t1(a) COMMENT 'comment1'; +ALTER TABLE t1 DROP INDEX i1, ADD INDEX i1(a) COMMENT 'comment2'; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo # +--echo # End of 10.1 tests +--echo # + +--echo # +--echo # MDEV-10421 duplicate CHECK CONSTRAINTs +--echo # +CREATE TABLE t1 (a INT, b INT) engine=myisam; +ALTER TABLE t1 ADD CONSTRAINT IF NOT EXISTS `min` CHECK (a+b > 100); +--error ER_DUP_CONSTRAINT_NAME +ALTER TABLE t1 ADD CONSTRAINT `min` CHECK (a+b > 100); +ALTER TABLE t1 ADD CONSTRAINT IF NOT EXISTS `min` CHECK (a+b > 100); +ALTER TABLE t1 ADD CONSTRAINT `mini` CHECK (a+b > 100); +SHOW CREATE TABLE t1; +DROP TABLE t1; +--error ER_DUP_CONSTRAINT_NAME +CREATE TABLE t1(a INT, b INT, CONSTRAINT min check (a>5), + CONSTRAINT min check (b>5)); + +# +# MDEV-11114 Cannot drop column referenced by CHECK constraint +# +create table t1 (a int, b int, check(a>b)); +--error ER_BAD_FIELD_ERROR +alter table t1 drop column a; +--error ER_BAD_FIELD_ERROR +alter table t1 drop column b, add column b bigint first; +alter table t1 drop column a, drop constraint constraint_1; +show create table t1; +drop table t1; + +create table t1 (a int, b int, check(a>0)); +alter table t1 drop column a; +show create table t1; +drop table t1; + +create table t1 (a int, b int, check(a>0)); +alter table t1 drop column a, add column a bigint first; +show create table t1; +drop table t1; + +create table t1 (a int, b int, c int, unique(a)); +alter table t1 drop column a; +show create table t1; +drop table t1; + +create table t1 (a int, b int, c int, unique(a,b)); +--error ER_KEY_COLUMN_DOES_NOT_EXITS +alter table t1 drop column a; +alter table t1 drop column a, drop index a; +show create table t1; +drop table t1; + +# +# MDEV-14694 ALTER COLUMN IF EXISTS .. causes syntax error +# + +create table t1 (i int); +alter table t1 alter column if exists a set default 1; +alter table t1 alter column if exists a drop default; +show create table t1; +drop table t1; + +--echo # +--echo # MDEV-13508 Check that rename of columns changes defaults, virtual +--echo # columns and constraints +--echo # + +create table t1 (a int, b int, check(a>b)); +alter table t1 change column a b int, change column b a int; +show create table t1; +drop table t1; + +create table t1 (a int primary key, b int, c int default (a+b) check (a+b>0), + d int as (a+b), + key (b), + constraint test check (a+b > 1)); +alter table t1 change b new_b int not null, add column b char(1), add constraint new check (length(b) > 0); +show create table t1; +drop table t1; + +--echo # +--echo # MDEV-11071: Assertion `thd->transaction.stmt.is_empty()' failed +--echo # in Locked_tables_list::unlock_locked_tables +--echo # + +CREATE TABLE t1 (d DATETIME DEFAULT CURRENT_TIMESTAMP, i INT) ENGINE=InnoDB; +INSERT INTO t1 (i) VALUES (1),(1); +LOCK TABLE t1 WRITE; +--error ER_DUP_ENTRY +ALTER TABLE t1 ADD UNIQUE(i); + +# Cleanup +UNLOCK TABLES; +DROP TABLE t1; + + ++--echo # ++--echo # MDEV-17599 ALTER TABLE DROP CONSTRAINT does not work for foreign keys. ++--echo # ++ ++CREATE TABLE t1(id INT PRIMARY KEY, c1 INT) ENGINE= INNODB; ++CREATE TABLE t2(id INT PRIMARY KEY, c1 INT, c2 INT NOT NULL, ++ CONSTRAINT sid FOREIGN KEY (`c1`) REFERENCES t1 (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, ++ CONSTRAINT UNIQUE `ui`(c2)) ENGINE= INNODB; ++SHOW CREATE TABLE t2; ++ALTER TABLE t2 DROP CONSTRAINT sid; ++SHOW CREATE TABLE t2; ++ALTER TABLE t2 DROP CONSTRAINT ui; ++SHOW CREATE TABLE t2; ++ALTER TABLE t2 DROP CONSTRAINT PRIMARY KEY; ++SHOW CREATE TABLE t2; ++DROP TABLE t2, t1; ++ +--echo # +--echo # End of 10.2 tests +--echo # + +--echo # +--echo # MDEV-17778: Alter table leads to a truncation warning with ANALYZE command +--echo # + +set @save_use_stat_tables= @@use_stat_tables; +set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity; +set @@optimizer_use_condition_selectivity=4; +set @@use_stat_tables=PREFERABLY; + +create table t1 (a int)engine=InnoDB; +insert into t1 values (1),(1),(2),(3); + +analyze table t1; +alter table t1 change a b int; +analyze table t1; +set @@use_stat_tables= @save_use_stat_tables; +set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; +drop table t1; diff --cc mysql-test/main/check_constraint_innodb.result index 00000000000,45af3f512b7..45af3f512b7 mode 000000,100644..100644 --- a/mysql-test/main/check_constraint_innodb.result +++ b/mysql-test/main/check_constraint_innodb.result diff --cc mysql-test/main/check_constraint_innodb.test index 00000000000,d02aa320e84..d02aa320e84 mode 000000,100644..100644 --- a/mysql-test/main/check_constraint_innodb.test +++ b/mysql-test/main/check_constraint_innodb.test diff --cc mysql-test/main/func_misc.result index 0ab07664e6c,00000000000..49f08356471 mode 100644,000000..100644 --- a/mysql-test/main/func_misc.result +++ b/mysql-test/main/func_misc.result @@@ -1,1584 -1,0 +1,1592 @@@ +DROP TABLE IF EXISTS t1, t2; +select format(1.5555,0),format(123.5555,1),format(1234.5555,2),format(12345.55555,3),format(123456.5555,4),format(1234567.5555,5),format("12345.2399",2); +format(1.5555,0) format(123.5555,1) format(1234.5555,2) format(12345.55555,3) format(123456.5555,4) format(1234567.5555,5) format("12345.2399",2) +2 123.6 1,234.56 12,345.556 123,456.5555 1,234,567.55550 12,345.24 +select inet_ntoa(inet_aton("255.255.255.255.255.255.255.255")); +inet_ntoa(inet_aton("255.255.255.255.255.255.255.255")) +NULL +select inet_aton("255.255.255.255.255"),inet_aton("255.255.1.255"),inet_aton("0.1.255"); +inet_aton("255.255.255.255.255") inet_aton("255.255.1.255") inet_aton("0.1.255") +1099511627775 4294902271 65791 +select inet_ntoa(1099511627775),inet_ntoa(4294902271),inet_ntoa(511); +inet_ntoa(1099511627775) inet_ntoa(4294902271) inet_ntoa(511) +NULL 255.255.1.255 0.0.1.255 +select hex(inet_aton('127')); +hex(inet_aton('127')) +7F +select hex(inet_aton('127.1')); +hex(inet_aton('127.1')) +7F000001 +select hex(inet_aton('127.1.1')); +hex(inet_aton('127.1.1')) +7F010001 +select length(uuid()), charset(uuid()), length(unhex(replace(uuid(),_utf8'-',_utf8''))); +length(uuid()) charset(uuid()) length(unhex(replace(uuid(),_utf8'-',_utf8''))) +36 utf8 16 +set @a= uuid_short(); +set @b= uuid_short(); +select @b - @a; +@b - @a +1 +select length(format('nan', 2)) > 0; +length(format('nan', 2)) > 0 +1 +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: 'nan' +select concat("$",format(2500,2)); +concat("$",format(2500,2)) +$2,500.00 +create table t1 ( a timestamp ); +insert into t1 values ( '2004-01-06 12:34' ); +select a from t1 where left(a+0,6) in ( left(20040106,6) ); +a +2004-01-06 12:34:00 +select a from t1 where left(a+0,6) = ( left(20040106,6) ); +a +2004-01-06 12:34:00 +select a from t1 where right(a+0,6) in ( right(20040106123400,6) ); +a +2004-01-06 12:34:00 +select a from t1 where right(a+0,6) = ( right(20040106123400,6) ); +a +2004-01-06 12:34:00 +select a from t1 where mid(a+0,6,3) in ( mid(20040106123400,6,3) ); +a +2004-01-06 12:34:00 +select a from t1 where mid(a+0,6,3) = ( mid(20040106123400,6,3) ); +a +2004-01-06 12:34:00 +drop table t1; +CREATE TABLE t1 (conn CHAR(7), connection_id INT); +INSERT INTO t1 VALUES ('default', CONNECTION_ID()); +SELECT GET_LOCK('bug16501',600); +GET_LOCK('bug16501',600) +1 +connect con1,localhost,root,,; +INSERT INTO t1 VALUES ('con1', CONNECTION_ID()); +SELECT IS_USED_LOCK('bug16501') = connection_id +FROM t1 +WHERE conn = 'default'; +IS_USED_LOCK('bug16501') = connection_id +1 +SELECT GET_LOCK('bug16501',600); +connection default; +SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID(); +IS_USED_LOCK('bug16501') = CONNECTION_ID() +1 +SELECT RELEASE_LOCK('bug16501'); +RELEASE_LOCK('bug16501') +1 +connection con1; +GET_LOCK('bug16501',600) +1 +connection default; +SELECT IS_USED_LOCK('bug16501') = connection_id +FROM t1 +WHERE conn = 'con1'; +IS_USED_LOCK('bug16501') = connection_id +1 +connection con1; +SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID(); +IS_USED_LOCK('bug16501') = CONNECTION_ID() +1 +SELECT RELEASE_LOCK('bug16501'); +RELEASE_LOCK('bug16501') +1 +SELECT IS_USED_LOCK('bug16501'); +IS_USED_LOCK('bug16501') +NULL +disconnect con1; +connection default; +DROP TABLE t1; +select export_set(3, _latin1'foo', _utf8'bar', ',', 4); +export_set(3, _latin1'foo', _utf8'bar', ',', 4) +foo,foo,bar,bar +End of 4.1 tests +create table t1 as select uuid(), length(uuid()); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `uuid()` varchar(36) CHARACTER SET utf8 DEFAULT NULL, + `length(uuid())` int(10) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +create table t1 select INET_ATON('255.255.0.1') as `a`; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` bigint(21) unsigned DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +drop table if exists table_26093; +drop function if exists func_26093_a; +drop function if exists func_26093_b; +create table table_26093(a int); +insert into table_26093 values +(1), (2), (3), (4), (5), +(6), (7), (8), (9), (10); +create function func_26093_a(x int) returns int +begin +set @invoked := @invoked + 1; +return x; +end// +create function func_26093_b(x int, y int) returns int +begin +set @invoked := @invoked + 1; +return x; +end// +select avg(a) from table_26093; +avg(a) +5.5000 +select benchmark(100, (select avg(a) from table_26093)); +benchmark(100, (select avg(a) from table_26093)) +0 +set @invoked := 0; +select benchmark(100, (select avg(func_26093_a(a)) from table_26093)); +benchmark(100, (select avg(func_26093_a(a)) from table_26093)) +0 +select @invoked; +@invoked +10 +set @invoked := 0; +select benchmark(100, (select avg(func_26093_b(a, rand())) from table_26093)); +benchmark(100, (select avg(func_26093_b(a, rand())) from table_26093)) +0 +select @invoked; +@invoked +1000 +select benchmark(100, (select (a) from table_26093)); +ERROR 21000: Subquery returns more than 1 row +select benchmark(100, (select 1, 1)); +ERROR 21000: Operand should contain 1 column(s) +drop table table_26093; +drop function func_26093_a; +drop function func_26093_b; +SELECT NAME_CONST('test', NOW()); +ERROR HY000: Incorrect arguments to NAME_CONST +SELECT NAME_CONST('test', UPPER('test')); +ERROR HY000: Incorrect arguments to NAME_CONST +SELECT NAME_CONST('test', NULL); +test +NULL +SELECT NAME_CONST('test', 1); +test +1 +SELECT NAME_CONST('test', -1); +test +-1 +SELECT NAME_CONST('test', 1.0); +test +1.0 +SELECT NAME_CONST('test', -1.0); +test +-1.0 +SELECT NAME_CONST('test', 'test'); +test +test +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2),(3); +SELECT NAME_CONST('flag',1) * MAX(a) FROM t1; +NAME_CONST('flag',1) * MAX(a) +3 +SELECT NAME_CONST('flag',1.5) * MAX(a) FROM t1; +NAME_CONST('flag',1.5) * MAX(a) +4.5 +SELECT NAME_CONST('flag',-1) * MAX(a) FROM t1; +NAME_CONST('flag',-1) * MAX(a) +-3 +SELECT NAME_CONST('flag',-1.5) * MAX(a) FROM t1; +NAME_CONST('flag',-1.5) * MAX(a) +-4.5 +SELECT NAME_CONST('flag', SQRT(4)) * MAX(a) FROM t1; +ERROR HY000: Incorrect arguments to NAME_CONST +SELECT NAME_CONST('flag',-SQRT(4)) * MAX(a) FROM t1; +ERROR HY000: Incorrect arguments to NAME_CONST +DROP TABLE t1; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (5), (2); +SELECT NAME_CONST(x,2) FROM (SELECT a x FROM t1) t; +ERROR HY000: Incorrect arguments to NAME_CONST +DROP TABLE t1; +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUES (), (), (); +SELECT NAME_CONST(a, '1') FROM t1; +ERROR HY000: Incorrect arguments to NAME_CONST +SET INSERT_ID= NAME_CONST(a, a); +ERROR HY000: Incorrect arguments to NAME_CONST +DROP TABLE t1; +create table t1 (a int not null); +insert into t1 values (-1), (-2); +select min(a) from t1 group by inet_ntoa(a); +min(a) +-2 +drop table t1; +SELECT NAME_CONST('var', 'value') COLLATE latin1_general_cs; +NAME_CONST('var', 'value') COLLATE latin1_general_cs +value +select @@session.time_zone into @save_tz; +set @@session.time_zone='UTC'; +select uuid() into @my_uuid; +select mid(@my_uuid,15,1); +mid(@my_uuid,15,1) +1 +select 24 * 60 * 60 * 1000 * 1000 * 10 into @my_uuid_one_day; +select concat('0',mid(@my_uuid,16,3),mid(@my_uuid,10,4),left(@my_uuid,8)) into @my_uuidate; +select floor(conv(@my_uuidate,16,10)/@my_uuid_one_day) into @my_uuid_date; +select 141427 + datediff(curdate(),'1970-01-01') into @my_uuid_synthetic; +select @my_uuid_date - @my_uuid_synthetic; +@my_uuid_date - @my_uuid_synthetic +0 +set @@session.time_zone=@save_tz; +CREATE TABLE t1 (a DATE); +SELECT * FROM t1 WHERE a = NAME_CONST('reportDate', +_binary'2009-01-09' COLLATE 'binary'); +a +DROP TABLE t1; +select NAME_CONST('_id',1234) as id; +id +1234 +End of 5.0 tests +select connection_id() > 0; +connection_id() > 0 +1 +# +# Bug #54461: crash with longblob and union or update with subquery +# +CREATE TABLE t1 (a INT, b LONGBLOB); +INSERT INTO t1 VALUES (1, '2'), (2, '3'), (3, '2'); +SELECT DISTINCT LEAST(a, (SELECT b FROM t1 LIMIT 1)) FROM t1 UNION SELECT 1; +LEAST(a, (SELECT b FROM t1 LIMIT 1)) +1 +2 +SELECT DISTINCT GREATEST(a, (SELECT b FROM t1 LIMIT 1)) FROM t1 UNION SELECT 1; +GREATEST(a, (SELECT b FROM t1 LIMIT 1)) +2 +3 +1 +DROP TABLE t1; +SELECT INET_NTOA(0); +INET_NTOA(0) +0.0.0.0 +SELECT '1' IN ('1', INET_NTOA(0)); +'1' IN ('1', INET_NTOA(0)) +1 +SELECT NAME_CONST('a', -(1 OR 2)) OR 1; +ERROR HY000: Incorrect arguments to NAME_CONST +SELECT NAME_CONST('a', -(1 AND 2)) AND 1; +ERROR HY000: Incorrect arguments to NAME_CONST +SELECT NAME_CONST('a', -(1)) OR 1; +NAME_CONST('a', -(1)) OR 1 +1 +# +#MDEV-5446: Assertion `!table || (!table->read_set || +#bitmap_is_set(table->read_set, field_index))' fails on +#EXPLAIN EXTENDED with VALUES function +# +CREATE TABLE t1 (a INT, b INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1,10); +CREATE VIEW v1 AS SELECT * FROM t1; +EXPLAIN EXTENDED SELECT VALUE(b) FROM v1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 system NULL NULL NULL NULL 1 100.00 +Warnings: +Note 1003 select value(10) AS `VALUE(b)` from dual +drop view v1; +drop table t1; +End of 5.3 tests +# +# Bug #52165: Assertion failed: file .\dtoa.c, line 465 +# +CREATE TABLE t1 (a SET('a'), b INT); +INSERT INTO t1 VALUES ('', 0); +SELECT COALESCE(a) = COALESCE(b) FROM t1; +COALESCE(a) = COALESCE(b) +1 +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: '' +DROP TABLE t1; +# +# Bug #54461: crash with longblob and union or update with subquery +# +CREATE TABLE t1 (a INT, b LONGBLOB); +INSERT INTO t1 VALUES (1, '2'), (2, '3'), (3, '2'); +SELECT DISTINCT LEAST(a, (SELECT b FROM t1 LIMIT 1)) FROM t1 UNION SELECT 1; +LEAST(a, (SELECT b FROM t1 LIMIT 1)) +1 +2 +SELECT DISTINCT GREATEST(a, (SELECT b FROM t1 LIMIT 1)) FROM t1 UNION SELECT 1; +GREATEST(a, (SELECT b FROM t1 LIMIT 1)) +2 +3 +1 +DROP TABLE t1; +SELECT INET_NTOA(0); +INET_NTOA(0) +0.0.0.0 +SELECT '1' IN ('1', INET_NTOA(0)); +'1' IN ('1', INET_NTOA(0)) +1 +# +# End of 5.1 tests +# +# +# Bug #58199: name_const in the having clause crashes +# +CREATE TABLE t1 (a INT); +SELECT 1 from t1 HAVING NAME_CONST('', a); +ERROR HY000: Incorrect arguments to NAME_CONST +DROP TABLE t1; +# +# Test or correct maybe_null of last_value +# +CREATE TABLE t1 (a char(2) not null ); +INSERT INTO t1 VALUES (4),(7),(1); +set @optimizer_switch_save= @@optimizer_switch; +set optimizer_switch='materialization=off'; +CREATE TABLE tv (e char(2) not null ); +INSERT INTO tv VALUES (1); +CREATE ALGORITHM=MERGE VIEW v_merge AS SELECT * FROM tv; +CREATE ALGORITHM=MERGE VIEW vm AS SELECT * FROM tv; +explain extended +select a from t1 left join v_merge on (a=e) where last_value(NULL,e) not in (select last_value(NULL,e) from vm); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY tv ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY tv system NULL NULL NULL NULL 1 100.00 +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` left join (`test`.`tv`) on(`test`.`tv`.`e` = `test`.`t1`.`a`) where !<expr_cache><last_value(NULL,`test`.`tv`.`e`)>(<in_optimizer>(last_value(NULL,`test`.`tv`.`e`),<exists>(/* select#2 */ select last_value(NULL,'1') from dual where trigcond(<cache>(last_value(NULL,`test`.`tv`.`e`)) = last_value(NULL,'1'))))) +explain extended +select a from t1 left join v_merge on (a=e) where e not in (select last_value(NULL,e) from vm); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY tv ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY tv system NULL NULL NULL NULL 1 100.00 +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` left join (`test`.`tv`) on(`test`.`tv`.`e` = `test`.`t1`.`a`) where !<expr_cache><`test`.`tv`.`e`>(<in_optimizer>(`test`.`tv`.`e`,<exists>(/* select#2 */ select last_value(NULL,'1') from dual where trigcond(<cache>(`test`.`tv`.`e`) = last_value(NULL,'1'))))) +set optimizer_switch=@optimizer_switch_save; +drop view v_merge, vm; +drop table t1,tv; +# +# MDEV-4017 - GET_LOCK() with negative timeouts has strange behavior +# +SELECT GET_LOCK('ul1', NULL); +GET_LOCK('ul1', NULL) +NULL +Warnings: +Warning 1411 Incorrect timeout value: 'NULL' for function get_lock +SELECT GET_LOCK('ul1', -1); +GET_LOCK('ul1', -1) +NULL +Warnings: +Warning 1411 Incorrect timeout value: '-1' for function get_lock +# +# MDEV-8624 MariaDB hangs on query with many logical condition +# +CREATE TABLE `t1` ( +`id` int(11) NOT NULL AUTO_INCREMENT, +`submitdate` datetime DEFAULT NULL, +`lastpage` int(11) DEFAULT NULL, +`startlanguage` varchar(20) COLLATE utf8_unicode_ci NOT NULL, +`token` varchar(36) COLLATE utf8_unicode_ci DEFAULT NULL, +`datestamp` datetime NOT NULL, +`startdate` datetime NOT NULL, +`ipaddr` text COLLATE utf8_unicode_ci, +`refurl` text COLLATE utf8_unicode_ci, +`57813X540X1723` text COLLATE utf8_unicode_ci, +`57813X540X1724` text COLLATE utf8_unicode_ci, +`57813X540X1725` text COLLATE utf8_unicode_ci, +`57813X540X1726` double DEFAULT NULL, +`57813X540X1909` double DEFAULT NULL, +`57813X541X17271` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X541X17272` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X541X17273` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X541X17274` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X541X17275` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X541X17276` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X541X17281` text COLLATE utf8_unicode_ci, +`57813X541X17282` text COLLATE utf8_unicode_ci, +`57813X541X17283` text COLLATE utf8_unicode_ci, +`57813X541X17284` text COLLATE utf8_unicode_ci, +`57813X541X17285` text COLLATE utf8_unicode_ci, +`57813X541X17286` text COLLATE utf8_unicode_ci, +`57813X542X18131` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X542X18132` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X542X18133` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X542X18134` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X542X18135` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X542X18136` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X542X18137` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X542X18138` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X542X18139` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X542X18141` text COLLATE utf8_unicode_ci, +`57813X542X18142` text COLLATE utf8_unicode_ci, +`57813X542X18143` text COLLATE utf8_unicode_ci, +`57813X542X18144` text COLLATE utf8_unicode_ci, +`57813X542X18145` text COLLATE utf8_unicode_ci, +`57813X542X18146` text COLLATE utf8_unicode_ci, +`57813X542X18147` text COLLATE utf8_unicode_ci, +`57813X542X18148` text COLLATE utf8_unicode_ci, +`57813X542X18149` text COLLATE utf8_unicode_ci, +`57813X543X18451` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X543X18452` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X543X18453` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X543X18454` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X543X18455` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X543X18456` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X543X18461` text COLLATE utf8_unicode_ci, +`57813X543X18462` text COLLATE utf8_unicode_ci, +`57813X543X18463` text COLLATE utf8_unicode_ci, +`57813X543X18464` text COLLATE utf8_unicode_ci, +`57813X543X18465` text COLLATE utf8_unicode_ci, +`57813X543X18466` text COLLATE utf8_unicode_ci, +`57813X544X18711` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X544X18712` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X544X18713` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X544X18714` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X544X18715` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X544X18716` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X544X18717` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X544X18718` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X544X18721` text COLLATE utf8_unicode_ci, +`57813X544X18722` text COLLATE utf8_unicode_ci, +`57813X544X18723` text COLLATE utf8_unicode_ci, +`57813X544X18724` text COLLATE utf8_unicode_ci, +`57813X544X18725` text COLLATE utf8_unicode_ci, +`57813X544X18726` text COLLATE utf8_unicode_ci, +`57813X544X18727` text COLLATE utf8_unicode_ci, +`57813X544X18728` text COLLATE utf8_unicode_ci, +`57813X546X1902` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X546X1903` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X546X1904` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, +`57813X545X1901` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, +PRIMARY KEY (`id`), +KEY `lime_survey_57813_idx` (`token`), +KEY `57813X540X1723` (`57813X540X1723`(100)), +KEY `57813X540X1724` (`57813X540X1724`(100)), +KEY `57813X540X1726` (`57813X540X1726`), +KEY `57813X540X1725` (`57813X540X1725`(100)), +KEY `57813X546X1902` (`57813X546X1902`), +KEY `57813X546X1903` (`57813X546X1903`), +KEY `57813X546X1904` (`57813X546X1904`) +); +SELECT +COUNT(*) as `N`, +ROUND( +( +SUM( +( +( +IF( 57813X541X17271 IS NOT NULL AND 57813X541X17271 != '' AND 57813X541X17271 != '99', 57813X541X17271, 0 ) + +IF( 57813X541X17272 IS NOT NULL AND 57813X541X17272 != '' AND 57813X541X17272 != '99', 57813X541X17272, 0 ) + +IF( 57813X541X17273 IS NOT NULL AND 57813X541X17273 != '' AND 57813X541X17273 != '99', 57813X541X17273, 0 ) + +IF( 57813X541X17274 IS NOT NULL AND 57813X541X17274 != '' AND 57813X541X17274 != '99', 57813X541X17274, 0 ) + +IF( 57813X541X17275 IS NOT NULL AND 57813X541X17275 != '' AND 57813X541X17275 != '99', 57813X541X17275, 0 ) + +IF( 57813X541X17276 IS NOT NULL AND 57813X541X17276 != '' AND 57813X541X17276 != '99', 57813X541X17276, 0 ) + +IF( 57813X542X18131 IS NOT NULL AND 57813X542X18131 != '' AND 57813X542X18131 != '99', 57813X542X18131, 0 ) + +IF( 57813X542X18132 IS NOT NULL AND 57813X542X18132 != '' AND 57813X542X18132 != '99', 57813X542X18132, 0 ) + +IF( 57813X542X18133 IS NOT NULL AND 57813X542X18133 != '' AND 57813X542X18133 != '99', 57813X542X18133, 0 ) + +IF( 57813X542X18134 IS NOT NULL AND 57813X542X18134 != '' AND 57813X542X18134 != '99', 57813X542X18134, 0 ) + +IF( 57813X542X18135 IS NOT NULL AND 57813X542X18135 != '' AND 57813X542X18135 != '99', 57813X542X18135, 0 ) + +IF( 57813X542X18136 IS NOT NULL AND 57813X542X18136 != '' AND 57813X542X18136 != '99', 57813X542X18136, 0 ) + +IF( 57813X542X18137 IS NOT NULL AND 57813X542X18137 != '' AND 57813X542X18137 != '99', 57813X542X18137, 0 ) + +IF( 57813X542X18138 IS NOT NULL AND 57813X542X18138 != '' AND 57813X542X18138 != '99', 57813X542X18138, 0 ) + +IF( 57813X542X18139 IS NOT NULL AND 57813X542X18139 != '' AND 57813X542X18139 != '99', 57813X542X18139, 0 ) + +IF( 57813X543X18451 IS NOT NULL AND 57813X543X18451 != '' AND 57813X543X18451 != '99', 57813X543X18451, 0 ) + +IF( 57813X543X18452 IS NOT NULL AND 57813X543X18452 != '' AND 57813X543X18452 != '99', 57813X543X18452, 0 ) + +IF( 57813X543X18453 IS NOT NULL AND 57813X543X18453 != '' AND 57813X543X18453 != '99', 57813X543X18453, 0 ) + +IF( 57813X543X18454 IS NOT NULL AND 57813X543X18454 != '' AND 57813X543X18454 != '99', 57813X543X18454, 0 ) + +IF( 57813X543X18455 IS NOT NULL AND 57813X543X18455 != '' AND 57813X543X18455 != '99', 57813X543X18455, 0 ) + +IF( 57813X543X18456 IS NOT NULL AND 57813X543X18456 != '' AND 57813X543X18456 != '99', 57813X543X18456, 0 ) + +IF( 57813X544X18711 IS NOT NULL AND 57813X544X18711 != '' AND 57813X544X18711 != '99', 57813X544X18711, 0 ) + +IF( 57813X544X18712 IS NOT NULL AND 57813X544X18712 != '' AND 57813X544X18712 != '99', 57813X544X18712, 0 ) + +IF( 57813X544X18713 IS NOT NULL AND 57813X544X18713 != '' AND 57813X544X18713 != '99', 57813X544X18713, 0 ) + +IF( 57813X544X18714 IS NOT NULL AND 57813X544X18714 != '' AND 57813X544X18714 != '99', 57813X544X18714, 0 ) + +IF( 57813X544X18715 IS NOT NULL AND 57813X544X18715 != '' AND 57813X544X18715 != '99', 57813X544X18715, 0 ) + +IF( 57813X544X18716 IS NOT NULL AND 57813X544X18716 != '' AND 57813X544X18716 != '99', 57813X544X18716, 0 ) + +IF( 57813X544X18717 IS NOT NULL AND 57813X544X18717 != '' AND 57813X544X18717 != '99', 57813X544X18717, 0 ) + +IF( 57813X544X18718 IS NOT NULL AND 57813X544X18718 != '' AND 57813X544X18718 != '99', 57813X544X18718, 0 ) +) +/ +( +IF( 57813X541X17271 IS NOT NULL AND 57813X541X17271 != '' AND 57813X541X17271 != '99', 1, 0 ) + +IF( 57813X541X17272 IS NOT NULL AND 57813X541X17272 != '' AND 57813X541X17272 != '99', 1, 0 ) + +IF( 57813X541X17273 IS NOT NULL AND 57813X541X17273 != '' AND 57813X541X17273 != '99', 1, 0 ) + +IF( 57813X541X17274 IS NOT NULL AND 57813X541X17274 != '' AND 57813X541X17274 != '99', 1, 0 ) + +IF( 57813X541X17275 IS NOT NULL AND 57813X541X17275 != '' AND 57813X541X17275 != '99', 1, 0 ) + +IF( 57813X541X17276 IS NOT NULL AND 57813X541X17276 != '' AND 57813X541X17276 != '99', 1, 0 ) + +IF( 57813X542X18131 IS NOT NULL AND 57813X542X18131 != '' AND 57813X542X18131 != '99', 1, 0 ) + +IF( 57813X542X18132 IS NOT NULL AND 57813X542X18132 != '' AND 57813X542X18132 != '99', 1, 0 ) + +IF( 57813X542X18133 IS NOT NULL AND 57813X542X18133 != '' AND 57813X542X18133 != '99', 1, 0 ) + +IF( 57813X542X18134 IS NOT NULL AND 57813X542X18134 != '' AND 57813X542X18134 != '99', 1, 0 ) + +IF( 57813X542X18135 IS NOT NULL AND 57813X542X18135 != '' AND 57813X542X18135 != '99', 1, 0 ) + +IF( 57813X542X18136 IS NOT NULL AND 57813X542X18136 != '' AND 57813X542X18136 != '99', 1, 0 ) + +IF( 57813X542X18137 IS NOT NULL AND 57813X542X18137 != '' AND 57813X542X18137 != '99', 1, 0 ) + +IF( 57813X542X18138 IS NOT NULL AND 57813X542X18138 != '' AND 57813X542X18138 != '99', 1, 0 ) + +IF( 57813X542X18139 IS NOT NULL AND 57813X542X18139 != '' AND 57813X542X18139 != '99', 1, 0 ) + +IF( 57813X543X18451 IS NOT NULL AND 57813X543X18451 != '' AND 57813X543X18451 != '99', 1, 0 ) + +IF( 57813X543X18452 IS NOT NULL AND 57813X543X18452 != '' AND 57813X543X18452 != '99', 1, 0 ) + +IF( 57813X543X18453 IS NOT NULL AND 57813X543X18453 != '' AND 57813X543X18453 != '99', 1, 0 ) + +IF( 57813X543X18454 IS NOT NULL AND 57813X543X18454 != '' AND 57813X543X18454 != '99', 1, 0 ) + +IF( 57813X543X18455 IS NOT NULL AND 57813X543X18455 != '' AND 57813X543X18455 != '99', 1, 0 ) + +IF( 57813X543X18456 IS NOT NULL AND 57813X543X18456 != '' AND 57813X543X18456 != '99', 1, 0 ) + +IF( 57813X544X18711 IS NOT NULL AND 57813X544X18711 != '' AND 57813X544X18711 != '99', 1, 0 ) + +IF( 57813X544X18712 IS NOT NULL AND 57813X544X18712 != '' AND 57813X544X18712 != '99', 1, 0 ) + +IF( 57813X544X18713 IS NOT NULL AND 57813X544X18713 != '' AND 57813X544X18713 != '99', 1, 0 ) + +IF( 57813X544X18714 IS NOT NULL AND 57813X544X18714 != '' AND 57813X544X18714 != '99', 1, 0 ) + +IF( 57813X544X18715 IS NOT NULL AND 57813X544X18715 != '' AND 57813X544X18715 != '99', 1, 0 ) + +IF( 57813X544X18716 IS NOT NULL AND 57813X544X18716 != '' AND 57813X544X18716 != '99', 1, 0 ) + +IF( 57813X544X18717 IS NOT NULL AND 57813X544X18717 != '' AND 57813X544X18717 != '99', 1, 0 ) + +IF( 57813X544X18718 IS NOT NULL AND 57813X544X18718 != '' AND 57813X544X18718 != '99', 1, 0 ) +) +) +) +/ COUNT(*) ), 4) as `AVG` +FROM `t1` +WHERE `submitdate` IS NOT NULL +AND ( +( 57813X541X17271 IS NOT NULL AND 57813X541X17271 != '' AND 57813X541X17271 != '99' ) OR +( 57813X541X17272 IS NOT NULL AND 57813X541X17272 != '' AND 57813X541X17272 != '99' ) OR +( 57813X541X17273 IS NOT NULL AND 57813X541X17273 != '' AND 57813X541X17273 != '99' ) OR +( 57813X541X17274 IS NOT NULL AND 57813X541X17274 != '' AND 57813X541X17274 != '99' ) OR +( 57813X541X17275 IS NOT NULL AND 57813X541X17275 != '' AND 57813X541X17275 != '99' ) OR +( 57813X541X17276 IS NOT NULL AND 57813X541X17276 != '' AND 57813X541X17276 != '99' ) OR +( 57813X542X18131 IS NOT NULL AND 57813X542X18131 != '' AND 57813X542X18131 != '99' ) OR +( 57813X542X18132 IS NOT NULL AND 57813X542X18132 != '' AND 57813X542X18132 != '99' ) OR +( 57813X542X18133 IS NOT NULL AND 57813X542X18133 != '' AND 57813X542X18133 != '99' ) OR +( 57813X542X18134 IS NOT NULL AND 57813X542X18134 != '' AND 57813X542X18134 != '99' ) OR +( 57813X542X18135 IS NOT NULL AND 57813X542X18135 != '' AND 57813X542X18135 != '99' ) OR +( 57813X542X18136 IS NOT NULL AND 57813X542X18136 != '' AND 57813X542X18136 != '99' ) OR +( 57813X542X18137 IS NOT NULL AND 57813X542X18137 != '' AND 57813X542X18137 != '99' ) OR +( 57813X542X18138 IS NOT NULL AND 57813X542X18138 != '' AND 57813X542X18138 != '99' ) OR +( 57813X542X18139 IS NOT NULL AND 57813X542X18139 != '' AND 57813X542X18139 != '99' ) OR +( 57813X543X18451 IS NOT NULL AND 57813X543X18451 != '' AND 57813X543X18451 != '99' ) OR +( 57813X543X18452 IS NOT NULL AND 57813X543X18452 != '' AND 57813X543X18452 != '99' ) OR +( 57813X543X18453 IS NOT NULL AND 57813X543X18453 != '' AND 57813X543X18453 != '99' ) OR +( 57813X543X18454 IS NOT NULL AND 57813X543X18454 != '' AND 57813X543X18454 != '99' ) OR +( 57813X543X18455 IS NOT NULL AND 57813X543X18455 != '' AND 57813X543X18455 != '99' ) OR +( 57813X543X18456 IS NOT NULL AND 57813X543X18456 != '' AND 57813X543X18456 != '99' ) OR +( 57813X544X18711 IS NOT NULL AND 57813X544X18711 != '' AND 57813X544X18711 != '99' ) OR +( 57813X544X18712 IS NOT NULL AND 57813X544X18712 != '' AND 57813X544X18712 != '99' ) OR +( 57813X544X18713 IS NOT NULL AND 57813X544X18713 != '' AND 57813X544X18713 != '99' ) OR +( 57813X544X18714 IS NOT NULL AND 57813X544X18714 != '' AND 57813X544X18714 != '99' ) OR +( 57813X544X18715 IS NOT NULL AND 57813X544X18715 != '' AND 57813X544X18715 != '99' ) OR +( 57813X544X18716 IS NOT NULL AND 57813X544X18716 != '' AND 57813X544X18716 != '99' ) OR +( 57813X544X18717 IS NOT NULL AND 57813X544X18717 != '' AND 57813X544X18717 != '99' ) OR +( 57813X544X18718 IS NOT NULL AND 57813X544X18718 != '' AND 57813X544X18718 != '99' ) ) +AND 57813X540X1723 = 'Test'; +N AVG +0 NULL +drop table t1; +SELECT NAME_CONST('a', -(1 OR 2)) OR 1; +ERROR HY000: Incorrect arguments to NAME_CONST +SELECT NAME_CONST('a', -(1 AND 2)) OR 1; +ERROR HY000: Incorrect arguments to NAME_CONST +SELECT NAME_CONST('a', -(1)) OR 1; +NAME_CONST('a', -(1)) OR 1 +1 +# +# MDEV-15630 uuid() function evaluates at wrong time in query +# +CREATE TABLE t1 (id INT); +INSERT INTO t1 VALUES (1),(2),(3); +SELECT COUNT(1), UUID() as uid FROM t1 GROUP BY uid; +COUNT(1) uid +1 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx +1 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx +1 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx +DROP TABLE t1; +# +# End of 5.5 tests +# +# +# GET_LOCK, RELEASE_LOCK, IS_USED_LOCK functions test +# +# IS_USED_LOCK, IS_FREE_LOCK: the lock is not acquired +# Note: IS_USED_LOCK returns NULL if the lock is unused +select is_used_lock('test'); +is_used_lock('test') +NULL +select is_free_lock('test'); +is_free_lock('test') +1 +# GET_LOCK returns 1 if it manages to acquire a lock +select get_lock('test', 0); +get_lock('test', 0) +1 +# IS_USED_LOCK, IS_FREE_LOCK: the lock is acquired +select is_free_lock('test'); +is_free_lock('test') +0 +select is_used_lock('test') = connection_id(); +is_used_lock('test') = connection_id() +1 +connect con1,localhost,root,,; +connection con1; +# IS_USED_LOCK, IS_FREE_LOCK: the lock is acquired in another +# connection +select is_used_lock('test') = connection_id(); +is_used_lock('test') = connection_id() +0 +select is_free_lock('test'); +is_free_lock('test') +0 +# GET_LOCK returns 0 if it can't acquire a lock (wait timeout) +select get_lock('test', 0); +get_lock('test', 0) +0 +# RELEASE_LOCK returns 0 if the lock belongs to another connection +select release_lock('test'); +release_lock('test') +0 +connection default; +# RELEASE_LOCK returns 1 if it successfully releases a lock +select release_lock('test'); +release_lock('test') +1 +# RELEASE_LOCK returns NULL if it doesn't release a lock and there is no such lock +select release_lock('test'); +release_lock('test') +NULL +# Test that get_lock() returns NULL if error. +select get_lock('test', 0); +get_lock('test', 0) +1 +connection con1; +create table t1 select connection_id() as id; +select get_lock('test', 7200); +connection default; +select (@id := id) - id from t1; +(@id := id) - id +0 +kill query @id; +connection con1; +get_lock('test', 7200) +NULL +connection default; +# GET_LOCK() works recursively +select get_lock('test', 0); +get_lock('test', 0) +1 +select get_lock('test', 0); +get_lock('test', 0) +1 +select get_lock('test', 0); +get_lock('test', 0) +1 +# RELEASE_LOCK() needs to be called recursively then, too +select release_lock('test'); +release_lock('test') +1 +select release_lock('test'); +release_lock('test') +1 +select release_lock('test'); +release_lock('test') +1 +# Once the last instance of the lock is released, +# the next call returns NULL +select release_lock('test'); +release_lock('test') +1 +# Multiple locks in the same session are OK +select get_lock('test1', 0); +get_lock('test1', 0) +1 +select get_lock('test2', 0); +get_lock('test2', 0) +1 +select get_lock('test3', 0); +get_lock('test3', 0) +1 +select release_lock('test1'); +release_lock('test1') +1 +select release_lock('test2'); +release_lock('test2') +1 +select release_lock('test3'); +release_lock('test3') +1 +# Deadlocks are detected e.g. in case of a mutual wait +select get_lock('test1', 0); +get_lock('test1', 0) +1 +connection con1; +select get_lock('test2', 0); +get_lock('test2', 0) +1 +select get_lock('test1', 7200); +connection default; +select get_lock('test2', 7200); +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +select release_lock('test1'); +release_lock('test1') +1 +connection con1; +get_lock('test1', 7200) +1 +select release_lock('test2'); +release_lock('test2') +1 +select release_lock('test1'); +release_lock('test1') +1 +connection default; +# LOCK/UNLOCK TABLES works fine with a user lock. +lock table t1 write; +select get_lock('test', 0); +get_lock('test', 0) +1 +unlock tables; +commit; +select release_lock('test'); +release_lock('test') +1 +# GLOBAL READ LOCK works with fine with user locks +select get_lock('test1', 0); +get_lock('test1', 0) +1 +flush tables with read lock; +select get_lock('test2', 0); +get_lock('test2', 0) +1 +unlock tables; +commit; +select release_lock('test1'); +release_lock('test1') +1 +select release_lock('test2'); +release_lock('test2') +1 +# BEGIN/COMMIT/ROLLBACK don't unlock user locks. +begin; +select get_lock('test1', 0); +get_lock('test1', 0) +1 +select get_lock('test2', 0); +get_lock('test2', 0) +1 +select count(*) from t1; +count(*) +1 +rollback; +select release_lock('test1'); +release_lock('test1') +1 +select release_lock('test2'); +release_lock('test2') +1 +# Deadlocks between user locks and LOCK TABLES locks +# are detected OK. +select get_lock('test', 0); +get_lock('test', 0) +1 +connection con1; +lock table t1 write; +select get_lock('test', 7200); +connection default; +lock table t1 read; +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +select release_lock('test'); +release_lock('test') +1 +connection con1; +get_lock('test', 7200) +1 +select release_lock('test'); +release_lock('test') +1 +unlock tables; +# cleanup +disconnect con1; +connection default; +drop table t1; +# check too long identifier names +select get_lock(repeat('a', 192), 0); +get_lock(repeat('a', 192), 0) +1 +select is_used_lock(repeat('a', 192)) = connection_id(); +is_used_lock(repeat('a', 192)) = connection_id() +1 +select is_free_lock(repeat('a', 192)); +is_free_lock(repeat('a', 192)) +0 +select release_lock(repeat('a', 192)); +release_lock(repeat('a', 192)) +1 +select get_lock(repeat('a', 193), 0); +ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long +select is_used_lock(repeat('a', 193)); +ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long +select is_free_lock(repeat('a', 193)); +ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long +select release_lock(repeat('a', 193)); +ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long + +# -- +# -- WL#5787: IPv6-capable INET_ATON and INET_NTOA functions. +# -- + +# -- INET6_ATON: checking NULL, invalid types, out-of range values... + +SELECT INET6_ATON(NULL) IS NULL; +INET6_ATON(NULL) IS NULL +1 +SELECT INET6_ATON(123) IS NULL; +INET6_ATON(123) IS NULL +1 +SELECT INET6_ATON(123.45) IS NULL; +INET6_ATON(123.45) IS NULL +1 +SELECT INET6_ATON(NOW()) IS NULL; +INET6_ATON(NOW()) IS NULL +1 +SELECT INET6_ATON('1.2.3') IS NULL; +INET6_ATON('1.2.3') IS NULL +1 +SELECT INET6_ATON('1.2.3.') IS NULL; +INET6_ATON('1.2.3.') IS NULL +1 +SELECT INET6_ATON('1..3.4') IS NULL; +INET6_ATON('1..3.4') IS NULL +1 +SELECT INET6_ATON('-1.2.3.4') IS NULL; +INET6_ATON('-1.2.3.4') IS NULL +1 +SELECT INET6_ATON('1.2.3.256') IS NULL; +INET6_ATON('1.2.3.256') IS NULL +1 +SELECT INET6_ATON('1.2.3.4.5') IS NULL; +INET6_ATON('1.2.3.4.5') IS NULL +1 +SELECT INET6_ATON('0001.2.3.4') IS NULL; +INET6_ATON('0001.2.3.4') IS NULL +1 +SELECT INET6_ATON('0x1.2.3.4') IS NULL; +INET6_ATON('0x1.2.3.4') IS NULL +1 +SELECT INET6_ATON('a.2.3.4') IS NULL; +INET6_ATON('a.2.3.4') IS NULL +1 +SELECT INET6_ATON('1.2.3.4:80') IS NULL; +INET6_ATON('1.2.3.4:80') IS NULL +1 +SELECT INET6_ATON('1.2.3.4/32') IS NULL; +INET6_ATON('1.2.3.4/32') IS NULL +1 +SELECT INET6_ATON('mysql.com') IS NULL; +INET6_ATON('mysql.com') IS NULL +1 +SELECT INET6_ATON(':::') IS NULL; +INET6_ATON(':::') IS NULL +1 +SELECT INET6_ATON(':1:2:3') IS NULL; +INET6_ATON(':1:2:3') IS NULL +1 +SELECT INET6_ATON('1:2:3:') IS NULL; +INET6_ATON('1:2:3:') IS NULL +1 +SELECT INET6_ATON(':1::2:3') IS NULL; +INET6_ATON(':1::2:3') IS NULL +1 +SELECT INET6_ATON('1::2:3:') IS NULL; +INET6_ATON('1::2:3:') IS NULL +1 +SELECT INET6_ATON('::00001') IS NULL; +INET6_ATON('::00001') IS NULL +1 +SELECT INET6_ATON('::00001:2') IS NULL; +INET6_ATON('::00001:2') IS NULL +1 +SELECT INET6_ATON('::12345') IS NULL; +INET6_ATON('::12345') IS NULL +1 +SELECT INET6_ATON('1020::3040::5060') IS NULL; +INET6_ATON('1020::3040::5060') IS NULL +1 +SELECT INET6_ATON('::ABCZ') IS NULL; +INET6_ATON('::ABCZ') IS NULL +1 +SELECT INET6_ATON('::0x1.2.3.4') IS NULL; +INET6_ATON('::0x1.2.3.4') IS NULL +1 +SELECT INET6_ATON('::1.0x2.3.4') IS NULL; +INET6_ATON('::1.0x2.3.4') IS NULL +1 +SELECT INET6_ATON('::a.b.c.d') IS NULL; +INET6_ATON('::a.b.c.d') IS NULL +1 +SELECT INET6_ATON('::FFFF:0x1.2.3.4') IS NULL; +INET6_ATON('::FFFF:0x1.2.3.4') IS NULL +1 +SELECT INET6_ATON('::FFFF:1.0x2.3.4') IS NULL; +INET6_ATON('::FFFF:1.0x2.3.4') IS NULL +1 +SELECT INET6_ATON('::FFFF:a.b.c.d') IS NULL; +INET6_ATON('::FFFF:a.b.c.d') IS NULL +1 +SELECT INET6_ATON('::1.2.3.4:ABCD') IS NULL; +INET6_ATON('::1.2.3.4:ABCD') IS NULL +1 +# NOTE: such addresses are supported because getaddrinfo() supports them. +# This is just to record the current behaviour. +SELECT HEX(INET6_ATON('::ABCD:1.2.3.4')); +HEX(INET6_ATON('::ABCD:1.2.3.4')) +00000000000000000000ABCD01020304 + +# -- INET6_ATON: checking binary representation... + +SELECT HEX(INET6_ATON('0.0.0.0')); +HEX(INET6_ATON('0.0.0.0')) +00000000 +SELECT HEX(INET6_ATON('00.00.00.00')); +HEX(INET6_ATON('00.00.00.00')) +00000000 +SELECT HEX(INET6_ATON('000.000.000.000')); +HEX(INET6_ATON('000.000.000.000')) +00000000 +SELECT HEX(INET6_ATON('1.2.3.4')); +HEX(INET6_ATON('1.2.3.4')) +01020304 +SELECT HEX(INET6_ATON('01.02.03.04')); +HEX(INET6_ATON('01.02.03.04')) +01020304 +SELECT HEX(INET6_ATON('001.002.003.004')); +HEX(INET6_ATON('001.002.003.004')) +01020304 +SELECT HEX(INET6_ATON('255.255.255.255')); +HEX(INET6_ATON('255.255.255.255')) +FFFFFFFF +SELECT HEX(INET6_ATON('::')); +HEX(INET6_ATON('::')) +00000000000000000000000000000000 +SELECT HEX(INET6_ATON('0::0')); +HEX(INET6_ATON('0::0')) +00000000000000000000000000000000 +SELECT HEX(INET6_ATON('1::2')); +HEX(INET6_ATON('1::2')) +00010000000000000000000000000002 +SELECT HEX(INET6_ATON('0::')); +HEX(INET6_ATON('0::')) +00000000000000000000000000000000 +SELECT HEX(INET6_ATON('1::')); +HEX(INET6_ATON('1::')) +00010000000000000000000000000000 +SELECT HEX(INET6_ATON('::0')); +HEX(INET6_ATON('::0')) +00000000000000000000000000000000 +SELECT HEX(INET6_ATON('::1')); +HEX(INET6_ATON('::1')) +00000000000000000000000000000001 +SELECT HEX(INET6_ATON('1:2:3:4:5:6:7:8')); +HEX(INET6_ATON('1:2:3:4:5:6:7:8')) +00010002000300040005000600070008 +SELECT HEX(INET6_ATON('::2:3:4:5:6:7:8')); +HEX(INET6_ATON('::2:3:4:5:6:7:8')) +00000002000300040005000600070008 +SELECT HEX(INET6_ATON('1::3:4:5:6:7:8')); +HEX(INET6_ATON('1::3:4:5:6:7:8')) +00010000000300040005000600070008 +SELECT HEX(INET6_ATON('1:2::4:5:6:7:8')); +HEX(INET6_ATON('1:2::4:5:6:7:8')) +00010002000000040005000600070008 +SELECT HEX(INET6_ATON('1:2:3::5:6:7:8')); +HEX(INET6_ATON('1:2:3::5:6:7:8')) +00010002000300000005000600070008 +SELECT HEX(INET6_ATON('1:2:3:4::6:7:8')); +HEX(INET6_ATON('1:2:3:4::6:7:8')) +00010002000300040000000600070008 +SELECT HEX(INET6_ATON('1:2:3:4:5::7:8')); +HEX(INET6_ATON('1:2:3:4:5::7:8')) +00010002000300040005000000070008 +SELECT HEX(INET6_ATON('1:2:3:4:5:6::8')); +HEX(INET6_ATON('1:2:3:4:5:6::8')) +00010002000300040005000600000008 +SELECT HEX(INET6_ATON('1:2:3:4:5:6:7::')); +HEX(INET6_ATON('1:2:3:4:5:6:7::')) +00010002000300040005000600070000 +SELECT HEX(INET6_ATON('0000:0000::0000:0001')); +HEX(INET6_ATON('0000:0000::0000:0001')) +00000000000000000000000000000001 +SELECT HEX(INET6_ATON('1234:5678:9abc:def0:4321:8765:cba9:0fed')); +HEX(INET6_ATON('1234:5678:9abc:def0:4321:8765:cba9:0fed')) +123456789ABCDEF043218765CBA90FED +SELECT HEX(INET6_ATON('0000:0000:0000:0000:0000:0000:0000:0001')); +HEX(INET6_ATON('0000:0000:0000:0000:0000:0000:0000:0001')) +00000000000000000000000000000001 +SELECT HEX(INET6_ATON('::C0A8:0102')); +HEX(INET6_ATON('::C0A8:0102')) +000000000000000000000000C0A80102 +SELECT HEX(INET6_ATON('::c0a8:0102')); +HEX(INET6_ATON('::c0a8:0102')) +000000000000000000000000C0A80102 +SELECT HEX(INET6_ATON('::192.168.1.2')); +HEX(INET6_ATON('::192.168.1.2')) +000000000000000000000000C0A80102 +SELECT HEX(INET6_ATON('::FfFf:C0a8:0102')); +HEX(INET6_ATON('::FfFf:C0a8:0102')) +00000000000000000000FFFFC0A80102 +SELECT HEX(INET6_ATON('::ffff:c0a8:0102')); +HEX(INET6_ATON('::ffff:c0a8:0102')) +00000000000000000000FFFFC0A80102 +SELECT HEX(INET6_ATON('::ffff:192.168.1.2')); +HEX(INET6_ATON('::ffff:192.168.1.2')) +00000000000000000000FFFFC0A80102 +SELECT HEX(INET6_ATON('::01.2.3.4')); +HEX(INET6_ATON('::01.2.3.4')) +00000000000000000000000001020304 +SELECT HEX(INET6_ATON('::1.02.3.4')); +HEX(INET6_ATON('::1.02.3.4')) +00000000000000000000000001020304 +SELECT HEX(INET6_ATON('::1.2.03.4')); +HEX(INET6_ATON('::1.2.03.4')) +00000000000000000000000001020304 +SELECT HEX(INET6_ATON('::1.2.3.04')); +HEX(INET6_ATON('::1.2.3.04')) +00000000000000000000000001020304 +SELECT HEX(INET6_ATON('::1.2.3.00')); +HEX(INET6_ATON('::1.2.3.00')) +00000000000000000000000001020300 +SELECT HEX(INET6_ATON('::FFFF:01.2.3.4')); +HEX(INET6_ATON('::FFFF:01.2.3.4')) +00000000000000000000FFFF01020304 +SELECT HEX(INET6_ATON('::FFFF:1.02.3.4')); +HEX(INET6_ATON('::FFFF:1.02.3.4')) +00000000000000000000FFFF01020304 +SELECT HEX(INET6_ATON('::FFFF:1.2.03.4')); +HEX(INET6_ATON('::FFFF:1.2.03.4')) +00000000000000000000FFFF01020304 +SELECT HEX(INET6_ATON('::FFFF:1.2.3.04')); +HEX(INET6_ATON('::FFFF:1.2.3.04')) +00000000000000000000FFFF01020304 +SELECT HEX(INET6_ATON('::FFFF:1.2.3.00')); +HEX(INET6_ATON('::FFFF:1.2.3.00')) +00000000000000000000FFFF01020300 + +# -- INET6_ATON: checking the length is either 4 or 16... + +SELECT LENGTH(INET6_ATON('0.0.0.0')); +LENGTH(INET6_ATON('0.0.0.0')) +4 +SELECT LENGTH(INET6_ATON('255.255.255.255')); +LENGTH(INET6_ATON('255.255.255.255')) +4 +SELECT LENGTH(INET6_ATON('::')); +LENGTH(INET6_ATON('::')) +16 +SELECT LENGTH(INET6_ATON('1020:3040:5060:7080:90A0:B0C0:D0E0:F010')); +LENGTH(INET6_ATON('1020:3040:5060:7080:90A0:B0C0:D0E0:F010')) +16 + +# -- INET6_NTOA: checking NULL, invalid types, out-of range values... + +SELECT INET6_NTOA(NULL); +INET6_NTOA(NULL) +NULL +SELECT INET6_NTOA(123); +INET6_NTOA(123) +NULL +SELECT INET6_NTOA(123.456); +INET6_NTOA(123.456) +NULL +SELECT INET6_NTOA(NOW()); +INET6_NTOA(NOW()) +NULL +SELECT INET6_NTOA(UNHEX('C0A801')); +INET6_NTOA(UNHEX('C0A801')) +NULL +SELECT INET6_NTOA(UNHEX('C0A80102')); +INET6_NTOA(UNHEX('C0A80102')) +192.168.1.2 +SELECT INET6_NTOA(UNHEX('C0A8010203')); +INET6_NTOA(UNHEX('C0A8010203')) +NULL +SELECT INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F')); +INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F')) +NULL +SELECT INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F10')); +INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F10')) +102:304:506:708:90a:b0c:d0e:f10 +SELECT INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F1011')); +INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F1011')) +NULL +SELECT INET6_NTOA('1234'), INET6_NTOA(BINARY('1234')); +INET6_NTOA('1234') INET6_NTOA(BINARY('1234')) +NULL 49.50.51.52 +SELECT INET6_NTOA('0123456789abcdef'), INET6_NTOA(BINARY('0123456789abcdef')); +INET6_NTOA('0123456789abcdef') INET6_NTOA(BINARY('0123456789abcdef')) +NULL 3031:3233:3435:3637:3839:6162:6364:6566 + +# -- Checking double-conversion... + +SELECT INET6_NTOA(INET6_ATON('::')); +INET6_NTOA(INET6_ATON('::')) +:: +SELECT INET6_NTOA(INET6_ATON('0::0')); +INET6_NTOA(INET6_ATON('0::0')) +:: +SELECT INET6_NTOA(INET6_ATON('1::2')); +INET6_NTOA(INET6_ATON('1::2')) +1::2 +SELECT INET6_NTOA(INET6_ATON('0::')); +INET6_NTOA(INET6_ATON('0::')) +:: +SELECT INET6_NTOA(INET6_ATON('1::')); +INET6_NTOA(INET6_ATON('1::')) +1:: +SELECT INET6_NTOA(INET6_ATON('::0')); +INET6_NTOA(INET6_ATON('::0')) +:: +SELECT INET6_NTOA(INET6_ATON('::1')); +INET6_NTOA(INET6_ATON('::1')) +::1 +SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5:6:7:8')); +INET6_NTOA(INET6_ATON('1:2:3:4:5:6:7:8')) +1:2:3:4:5:6:7:8 +SELECT INET6_NTOA(INET6_ATON('::2:3:4:5:6:7:8')); +INET6_NTOA(INET6_ATON('::2:3:4:5:6:7:8')) +::2:3:4:5:6:7:8 +SELECT INET6_NTOA(INET6_ATON('1::3:4:5:6:7:8')); +INET6_NTOA(INET6_ATON('1::3:4:5:6:7:8')) +1::3:4:5:6:7:8 +SELECT INET6_NTOA(INET6_ATON('1:2::4:5:6:7:8')); +INET6_NTOA(INET6_ATON('1:2::4:5:6:7:8')) +1:2::4:5:6:7:8 +SELECT INET6_NTOA(INET6_ATON('1:2:3::5:6:7:8')); +INET6_NTOA(INET6_ATON('1:2:3::5:6:7:8')) +1:2:3::5:6:7:8 +SELECT INET6_NTOA(INET6_ATON('1:2:3:4::6:7:8')); +INET6_NTOA(INET6_ATON('1:2:3:4::6:7:8')) +1:2:3:4::6:7:8 +SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5::7:8')); +INET6_NTOA(INET6_ATON('1:2:3:4:5::7:8')) +1:2:3:4:5::7:8 +SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5:6::8')); +INET6_NTOA(INET6_ATON('1:2:3:4:5:6::8')) +1:2:3:4:5:6::8 +SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5:6:7::')); +INET6_NTOA(INET6_ATON('1:2:3:4:5:6:7::')) +1:2:3:4:5:6:7:: +SELECT INET6_NTOA(INET6_ATON('0000:0000::0000:0001')); +INET6_NTOA(INET6_ATON('0000:0000::0000:0001')) +::1 +SELECT INET6_NTOA(INET6_ATON('1234:5678:9abc:def0:4321:8765:cba9:0fed')); +INET6_NTOA(INET6_ATON('1234:5678:9abc:def0:4321:8765:cba9:0fed')) +1234:5678:9abc:def0:4321:8765:cba9:fed +SELECT INET6_NTOA(INET6_ATON('0000:0000:0000:0000:0000:0000:0000:0001')); +INET6_NTOA(INET6_ATON('0000:0000:0000:0000:0000:0000:0000:0001')) +::1 +SELECT INET6_NTOA(INET6_ATON('::C0A8:0102')); +INET6_NTOA(INET6_ATON('::C0A8:0102')) +::192.168.1.2 +SELECT INET6_NTOA(INET6_ATON('::c0a8:0102')); +INET6_NTOA(INET6_ATON('::c0a8:0102')) +::192.168.1.2 +SELECT INET6_NTOA(INET6_ATON('::192.168.1.2')); +INET6_NTOA(INET6_ATON('::192.168.1.2')) +::192.168.1.2 +SELECT INET6_NTOA(INET6_ATON('::FfFf:C0a8:0102')); +INET6_NTOA(INET6_ATON('::FfFf:C0a8:0102')) +::ffff:192.168.1.2 +SELECT INET6_NTOA(INET6_ATON('::ffff:c0a8:0102')); +INET6_NTOA(INET6_ATON('::ffff:c0a8:0102')) +::ffff:192.168.1.2 +SELECT INET6_NTOA(INET6_ATON('::ffff:192.168.1.2')); +INET6_NTOA(INET6_ATON('::ffff:192.168.1.2')) +::ffff:192.168.1.2 +SELECT INET6_NTOA(INET6_ATON('::01.2.3.4')); +INET6_NTOA(INET6_ATON('::01.2.3.4')) +::1.2.3.4 +SELECT INET6_NTOA(INET6_ATON('::1.02.3.4')); +INET6_NTOA(INET6_ATON('::1.02.3.4')) +::1.2.3.4 +SELECT INET6_NTOA(INET6_ATON('::1.2.03.4')); +INET6_NTOA(INET6_ATON('::1.2.03.4')) +::1.2.3.4 +SELECT INET6_NTOA(INET6_ATON('::1.2.3.04')); +INET6_NTOA(INET6_ATON('::1.2.3.04')) +::1.2.3.4 +SELECT INET6_NTOA(INET6_ATON('::1.2.3.00')); +INET6_NTOA(INET6_ATON('::1.2.3.00')) +::1.2.3.0 +SELECT INET6_NTOA(INET6_ATON('::FFFF:01.2.3.4')); +INET6_NTOA(INET6_ATON('::FFFF:01.2.3.4')) +::ffff:1.2.3.4 +SELECT INET6_NTOA(INET6_ATON('::FFFF:1.02.3.4')); +INET6_NTOA(INET6_ATON('::FFFF:1.02.3.4')) +::ffff:1.2.3.4 +SELECT INET6_NTOA(INET6_ATON('::FFFF:1.2.03.4')); +INET6_NTOA(INET6_ATON('::FFFF:1.2.03.4')) +::ffff:1.2.3.4 +SELECT INET6_NTOA(INET6_ATON('::FFFF:1.2.3.04')); +INET6_NTOA(INET6_ATON('::FFFF:1.2.3.04')) +::ffff:1.2.3.4 +SELECT INET6_NTOA(INET6_ATON('::FFFF:1.2.3.00')); +INET6_NTOA(INET6_ATON('::FFFF:1.2.3.00')) +::ffff:1.2.3.0 + +# -- Comparing INET_ATON() and INET6_ATON()... + +SELECT HEX(INET_ATON('192.168.1.2')); +HEX(INET_ATON('192.168.1.2')) +C0A80102 +SELECT HEX(INET6_ATON('192.168.1.2')); +HEX(INET6_ATON('192.168.1.2')) +C0A80102 +SELECT HEX(INET_ATON('255.255.255.255')); +HEX(INET_ATON('255.255.255.255')) +FFFFFFFF +SELECT HEX(INET6_ATON('255.255.255.255')); +HEX(INET6_ATON('255.255.255.255')) +FFFFFFFF +SELECT HEX(INET_ATON('192.168.08.2')); +HEX(INET_ATON('192.168.08.2')) +C0A80802 +SELECT HEX(INET6_ATON('192.168.08.2')); +HEX(INET6_ATON('192.168.08.2')) +C0A80802 +SELECT HEX(INET_ATON('192.168.0x8.2')); +HEX(INET_ATON('192.168.0x8.2')) +NULL +SELECT HEX(INET6_ATON('192.168.0x8.2')); +HEX(INET6_ATON('192.168.0x8.2')) +NULL +SELECT HEX(INET_ATON('1.2.255')); +HEX(INET_ATON('1.2.255')) +10200FF +SELECT HEX(INET6_ATON('1.2.255')); +HEX(INET6_ATON('1.2.255')) +NULL +SELECT HEX(INET_ATON('1.2.256')); +HEX(INET_ATON('1.2.256')) +NULL +SELECT HEX(INET6_ATON('1.2.256')); +HEX(INET6_ATON('1.2.256')) +NULL +SELECT HEX(INET_ATON('1.0002.3.4')); +HEX(INET_ATON('1.0002.3.4')) +1020304 +SELECT HEX(INET6_ATON('1.0002.3.4')); +HEX(INET6_ATON('1.0002.3.4')) +NULL +SELECT HEX(INET_ATON('1.2.3.4.5')); +HEX(INET_ATON('1.2.3.4.5')) +102030405 +SELECT HEX(INET6_ATON('1.2.3.4.5')); +HEX(INET6_ATON('1.2.3.4.5')) +NULL + +# -- Checking mix of INET- and INET6- functions... + +SELECT HEX(INET6_ATON(INET_NTOA(INET_ATON('1.2.3.4')))) AS x; +x +01020304 + +# -- Checking IS_IPV4() / IS_IPV6()... + +SELECT IS_IPV4(NULL); +IS_IPV4(NULL) +0 +SELECT IS_IPV4(1); +IS_IPV4(1) +0 +SELECT IS_IPV4(1.0); +IS_IPV4(1.0) +0 +SELECT IS_IPV4('1.2.3.4'); +IS_IPV4('1.2.3.4') +1 +SELECT IS_IPV4('001.02.000.255'); +IS_IPV4('001.02.000.255') +1 +SELECT IS_IPV4('::1.2.0.255'); +IS_IPV4('::1.2.0.255') +0 +SELECT IS_IPV4('::1'); +IS_IPV4('::1') +0 +SELECT IS_IPV4(BINARY('1.2.3.4')); +IS_IPV4(BINARY('1.2.3.4')) +1 +SELECT IS_IPV6(NULL); +IS_IPV6(NULL) +0 +SELECT IS_IPV6(1); +IS_IPV6(1) +0 +SELECT IS_IPV6(1.0); +IS_IPV6(1.0) +0 +SELECT IS_IPV6('1.2.3.4'); +IS_IPV6('1.2.3.4') +0 +SELECT IS_IPV6('001.02.000.255'); +IS_IPV6('001.02.000.255') +0 +SELECT IS_IPV6('::001.02.000.255'); +IS_IPV6('::001.02.000.255') +1 +SELECT IS_IPV6('::1.2.0.255'); +IS_IPV6('::1.2.0.255') +1 +SELECT IS_IPV6('::1'); +IS_IPV6('::1') +1 +SELECT IS_IPV6('0000:0000:0000:0000:0000:0000:0000:0001'); +IS_IPV6('0000:0000:0000:0000:0000:0000:0000:0001') +1 +SELECT IS_IPV6(BINARY('0000:0000:0000:0000:0000:0000:0000:0001')); +IS_IPV6(BINARY('0000:0000:0000:0000:0000:0000:0000:0001')) +1 + +# -- Checking IS_IPV4_MAPPED() and IS_IPV4_COMPAT()... + +SELECT IS_IPV4_MAPPED(INET6_ATON('1.2.3.4')), +IS_IPV4_COMPAT(INET6_ATON('1.2.3.4')); +IS_IPV4_MAPPED(INET6_ATON('1.2.3.4')) IS_IPV4_COMPAT(INET6_ATON('1.2.3.4')) +0 0 +SELECT IS_IPV4_MAPPED(INET6_ATON('::1.2.3.4')), +IS_IPV4_COMPAT(INET6_ATON('::1.2.3.4')); +IS_IPV4_MAPPED(INET6_ATON('::1.2.3.4')) IS_IPV4_COMPAT(INET6_ATON('::1.2.3.4')) +0 1 +SELECT IS_IPV4_MAPPED(INET6_ATON('::FFFF:1.2.3.4')), +IS_IPV4_COMPAT(INET6_ATON('::FFFF:1.2.3.4')); +IS_IPV4_MAPPED(INET6_ATON('::FFFF:1.2.3.4')) IS_IPV4_COMPAT(INET6_ATON('::FFFF:1.2.3.4')) +1 0 +SELECT IS_IPV4_MAPPED(INET6_ATON('::ABCD:1.2.3.4')), +IS_IPV4_COMPAT(INET6_ATON('::ABCD:1.2.3.4')); +IS_IPV4_MAPPED(INET6_ATON('::ABCD:1.2.3.4')) IS_IPV4_COMPAT(INET6_ATON('::ABCD:1.2.3.4')) +0 0 +SELECT IS_IPV4_MAPPED(INET6_ATON('::1')), +IS_IPV4_COMPAT(INET6_ATON('::1')); +IS_IPV4_MAPPED(INET6_ATON('::1')) IS_IPV4_COMPAT(INET6_ATON('::1')) +0 0 +SELECT IS_IPV4_MAPPED(INET6_ATON('::')), +IS_IPV4_COMPAT(INET6_ATON('::')); +IS_IPV4_MAPPED(INET6_ATON('::')) IS_IPV4_COMPAT(INET6_ATON('::')) +0 0 + +# -- Checking IS_IPV4_COMPAT()... + + +# -- Working with a table... + +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +CREATE TABLE t1(ip INT UNSIGNED); +CREATE TABLE t2(ip VARBINARY(16)); + +INSERT INTO t1 VALUES +(INET_ATON('1.2.3.4')), (INET_ATON('255.255.255.255')); +SELECT INET_NTOA(ip) FROM t1; +INET_NTOA(ip) +1.2.3.4 +255.255.255.255 + +INSERT INTO t2 SELECT INET6_ATON(INET_NTOA(ip)) FROM t1; +SELECT INET6_NTOA(ip), HEX(ip), LENGTH(ip) FROM t2; +INET6_NTOA(ip) HEX(ip) LENGTH(ip) +1.2.3.4 01020304 4 +255.255.255.255 FFFFFFFF 4 +DELETE FROM t2; + +INSERT INTO t2 VALUES +(INET6_ATON('1.2.3.4')), (INET6_ATON('255.255.255.255')), +(INET6_ATON('::1.2.3.4')), (INET6_ATON('::ffff:255.255.255.255')), +(INET6_ATON('::')), (INET6_ATON('::1')), +(INET6_ATON('1020:3040:5060:7080:90A0:B0C0:D0E0:F010')); +SELECT INET6_NTOA(ip), HEX(ip), LENGTH(ip) FROM t2; +INET6_NTOA(ip) HEX(ip) LENGTH(ip) +1.2.3.4 01020304 4 +255.255.255.255 FFFFFFFF 4 +::1.2.3.4 00000000000000000000000001020304 16 +::ffff:255.255.255.255 00000000000000000000FFFFFFFFFFFF 16 +:: 00000000000000000000000000000000 16 +::1 00000000000000000000000000000001 16 +1020:3040:5060:7080:90a0:b0c0:d0e0:f010 102030405060708090A0B0C0D0E0F010 16 + +DROP TABLE t1; +DROP TABLE t2; +# +# MDEV-4018 : Microseconds in GET_LOCK() +# +connection default; +select is_used_lock('test') = connection_id(); +is_used_lock('test') = connection_id() +NULL +# GET_LOCK returns 1 if it manages to acquire a lock +select get_lock('test', 0); +get_lock('test', 0) +1 +connect con1,localhost,root,,; +connection con1; +select is_used_lock('test') = connection_id(); +is_used_lock('test') = connection_id() +0 +select get_lock('test', 0); +get_lock('test', 0) +0 +select get_lock('test', 1.0); +get_lock('test', 1.0) +0 +select get_lock('test', 1.5); +get_lock('test', 1.5) +0 +select get_lock('test', 0.1); +get_lock('test', 0.1) +0 +select get_lock('test', 0.000001); +get_lock('test', 0.000001) +0 +select get_lock('test', 0.0000000000000001); +get_lock('test', 0.0000000000000001) +0 +connection default; +select is_used_lock('test') = connection_id(); +is_used_lock('test') = connection_id() +1 +select release_lock('test'); +release_lock('test') +1 + +# -- Done. + +# +# MDEV-13685 Can not replay binary log due to Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation 'concat' +# +SET NAMES utf8; +SELECT COERCIBILITY(NAME_CONST('name','test')); +COERCIBILITY(NAME_CONST('name','test')) +2 +SELECT COERCIBILITY(NAME_CONST('name',TIME'00:00:00')); +COERCIBILITY(NAME_CONST('name',TIME'00:00:00')) +5 +SELECT COERCIBILITY(NAME_CONST('name',15)); +COERCIBILITY(NAME_CONST('name',15)) +5 +SELECT CONCAT(NAME_CONST('name',15),'오'); +CONCAT(NAME_CONST('name',15),'오') +15오 +SET NAMES latin1; +# +# MDEV-14116 INET6_NTOA output is set as null to varchar(39) variable +# +CREATE PROCEDURE p1() +BEGIN +DECLARE ip_full_addr varchar(39) DEFAULT ""; +SELECT INET6_NTOA(UNHEX('20000000000000000000000000000000')) into ip_full_addr; +SELECT ip_full_addr; +END; +$$ +CALL p1(); +ip_full_addr +2000:: +DROP PROCEDURE p1; +# ++# MDEV-18195 ASAN use-after-poison in my_strcasecmp_utf8 / Item::eq upon prepared statement with ORDER BY NAME_CONST ++# ++PREPARE stmt FROM "SELECT 'x' ORDER BY NAME_CONST( 'f', 'foo' )"; ++EXECUTE stmt; ++x ++x ++DEALLOCATE PREPARE stmt; ++# +# Start of 10.2 tests +# +# +# MDEV-10134 Add full support for DEFAULT +# +CREATE TABLE t1 ( +a VARCHAR(30), +b BIGINT DEFAULT INET_ATON(a), +a1 VARCHAR(30) DEFAULT INET_NTOA(b), +c INT DEFAULT IS_IPV4(a), +d INT DEFAULT IS_IPV6(a) +); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(30) DEFAULT NULL, + `b` bigint(20) DEFAULT inet_aton(`a`), + `a1` varchar(30) DEFAULT inet_ntoa(`b`), + `c` int(11) DEFAULT is_ipv4(`a`), + `d` int(11) DEFAULT is_ipv6(`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 (a) VALUES ('192.168.001.001'),('::1'),('xxx'); +SELECT * FROM t1; +a b a1 c d +192.168.001.001 3232235777 192.168.1.1 1 0 +::1 NULL NULL 0 1 +xxx NULL NULL 0 0 +DROP TABLE t1; +CREATE TABLE t1 ( +str VARCHAR(128), +addr VARBINARY(16) DEFAULT INET6_ATON(str), +str1 VARCHAR(128) DEFAULT INET6_NTOA(addr), +b INT DEFAULT IS_IPV4_COMPAT(addr), +c INT DEFAULT IS_IPV4_MAPPED(addr) +); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `str` varchar(128) DEFAULT NULL, + `addr` varbinary(16) DEFAULT inet6_aton(`str`), + `str1` varchar(128) DEFAULT inet6_ntoa(`addr`), + `b` int(11) DEFAULT is_ipv4_compat(`addr`), + `c` int(11) DEFAULT is_ipv4_mapped(`addr`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t1 (str) VALUES ('::FFFF:192.168.0.1'),('::10.0.5.9'); +SELECT str, str1, b,c FROM t1; +str str1 b c +::FFFF:192.168.0.1 ::ffff:192.168.0.1 0 1 +::10.0.5.9 ::10.0.5.9 1 0 +DROP TABLE t1; +# +# MDEV-14613: Assertion `fixed == 0' failed in Item_func::fix_fields +# +CREATE TABLE `t1` ( +`numgtfmt` char(10) COLLATE utf8_bin NOT NULL +) DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +create view v1(numgtfmt) +as +select 'x' from t1 +union +select 'x' from t1 ; +SELECT * FROM v1 WHERE numgtfmt = NAME_CONST('wnumgtfmt',_utf8'QEDITIONS' COLLATE 'utf8_bin'); +numgtfmt +DROP VIEW v1; +DROP TABLE t1; +# +# End of 10.2 tests +# +# +# Start of 10.3 tests +# +# +# MDEV-12854 Synchronize CREATE..SELECT data type and result set metadata data type for INT functions +# +SELECT INET_ATON("255.255.255.255.255.255.255.255"); +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def INET_ATON("255.255.255.255.255.255.255.255") 8 21 20 Y 32928 0 63 +INET_ATON("255.255.255.255.255.255.255.255") +18446744073709551615 +# +# MDEV-8049 name_const() is not consistent about its signess +# +SELECT 18446744073709551615 AS c1, name_const('a',18446744073709551615) AS c2; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def c1 8 20 20 N 32929 0 63 +def c2 8 20 20 Y 32928 0 63 +c1 c2 +18446744073709551615 18446744073709551615 +CREATE TABLE t1 AS SELECT 18446744073709551615 AS c1, name_const('a',18446744073709551615) AS c2; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` bigint(20) unsigned NOT NULL, + `c2` bigint(20) unsigned DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t1; +c1 c2 +18446744073709551615 18446744073709551615 +DROP TABLE t1; diff --cc mysql-test/main/func_misc.test index f8f2147e182,00000000000..e4a2cd22f69 mode 100644,000000..100644 --- a/mysql-test/main/func_misc.test +++ b/mysql-test/main/func_misc.test @@@ -1,1220 -1,0 +1,1228 @@@ +# +# Testing of misc functions +# + +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +--enable_warnings + +select format(1.5555,0),format(123.5555,1),format(1234.5555,2),format(12345.55555,3),format(123456.5555,4),format(1234567.5555,5),format("12345.2399",2); + +select inet_ntoa(inet_aton("255.255.255.255.255.255.255.255")); +select inet_aton("255.255.255.255.255"),inet_aton("255.255.1.255"),inet_aton("0.1.255"); +select inet_ntoa(1099511627775),inet_ntoa(4294902271),inet_ntoa(511); + +select hex(inet_aton('127')); +select hex(inet_aton('127.1')); +select hex(inet_aton('127.1.1')); + +select length(uuid()), charset(uuid()), length(unhex(replace(uuid(),_utf8'-',_utf8''))); + +# As we can assume we are the only user for the mysqld server, the difference +# between two calls should be -1 +set @a= uuid_short(); +set @b= uuid_short(); +select @b - @a; + +# +# Test for core dump with nan +# +select length(format('nan', 2)) > 0; + +# +# Test for bug #628 +# +select concat("$",format(2500,2)); + +# Test for BUG#7716 +create table t1 ( a timestamp ); +insert into t1 values ( '2004-01-06 12:34' ); +select a from t1 where left(a+0,6) in ( left(20040106,6) ); +select a from t1 where left(a+0,6) = ( left(20040106,6) ); + +select a from t1 where right(a+0,6) in ( right(20040106123400,6) ); +select a from t1 where right(a+0,6) = ( right(20040106123400,6) ); + +select a from t1 where mid(a+0,6,3) in ( mid(20040106123400,6,3) ); +select a from t1 where mid(a+0,6,3) = ( mid(20040106123400,6,3) ); + +drop table t1; + + +# +# Bug#16501: IS_USED_LOCK does not appear to work +# + +CREATE TABLE t1 (conn CHAR(7), connection_id INT); +INSERT INTO t1 VALUES ('default', CONNECTION_ID()); + +SELECT GET_LOCK('bug16501',600); + +connect (con1,localhost,root,,); +INSERT INTO t1 VALUES ('con1', CONNECTION_ID()); +SELECT IS_USED_LOCK('bug16501') = connection_id +FROM t1 +WHERE conn = 'default'; +send SELECT GET_LOCK('bug16501',600); + +connection default; +SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID(); +SELECT RELEASE_LOCK('bug16501'); +connection con1; +reap; +connection default; +SELECT IS_USED_LOCK('bug16501') = connection_id +FROM t1 +WHERE conn = 'con1'; + +connection con1; +SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID(); +SELECT RELEASE_LOCK('bug16501'); +SELECT IS_USED_LOCK('bug16501'); + +disconnect con1; +connection default; + +DROP TABLE t1; + +# +# Bug #21531: EXPORT_SET() doesn't accept args with coercible character sets +# +select export_set(3, _latin1'foo', _utf8'bar', ',', 4); + +--echo End of 4.1 tests + + +# +# Test for BUG#9535 +# +--disable_warnings +create table t1 as select uuid(), length(uuid()); +--enable_warnings +show create table t1; +drop table t1; + +# +# Bug #21466: INET_ATON() returns signed, not unsigned +# + +create table t1 select INET_ATON('255.255.0.1') as `a`; +show create table t1; +drop table t1; + +# +# Bug#26093 (SELECT BENCHMARK() for SELECT statements does not produce +# valid results) +# + +--disable_warnings +drop table if exists table_26093; +drop function if exists func_26093_a; +drop function if exists func_26093_b; +--enable_warnings + +create table table_26093(a int); +insert into table_26093 values +(1), (2), (3), (4), (5), +(6), (7), (8), (9), (10); + +delimiter //; + +create function func_26093_a(x int) returns int +begin + set @invoked := @invoked + 1; + return x; +end// + +create function func_26093_b(x int, y int) returns int +begin + set @invoked := @invoked + 1; + return x; +end// + +delimiter ;// + +select avg(a) from table_26093; + +select benchmark(100, (select avg(a) from table_26093)); + +set @invoked := 0; +select benchmark(100, (select avg(func_26093_a(a)) from table_26093)); +# Returns only 10, since intermediate results are cached. +select @invoked; + +set @invoked := 0; +select benchmark(100, (select avg(func_26093_b(a, rand())) from table_26093)); +# Returns 1000, due to rand() preventing caching. +select @invoked; + +--error ER_SUBQUERY_NO_1_ROW +select benchmark(100, (select (a) from table_26093)); + +--error ER_OPERAND_COLUMNS +select benchmark(100, (select 1, 1)); + +drop table table_26093; +drop function func_26093_a; +drop function func_26093_b; + +# +# Bug #30832: Assertion + crash with select name_const('test',now()); +# +--error ER_WRONG_ARGUMENTS +SELECT NAME_CONST('test', NOW()); +--error ER_WRONG_ARGUMENTS +SELECT NAME_CONST('test', UPPER('test')); + +SELECT NAME_CONST('test', NULL); +SELECT NAME_CONST('test', 1); +SELECT NAME_CONST('test', -1); +SELECT NAME_CONST('test', 1.0); +SELECT NAME_CONST('test', -1.0); +SELECT NAME_CONST('test', 'test'); + +# +# Bug #34749: Server crash when using NAME_CONST() with an aggregate function +# + +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2),(3); +# NAME_CONST() + aggregate. +SELECT NAME_CONST('flag',1) * MAX(a) FROM t1; +SELECT NAME_CONST('flag',1.5) * MAX(a) FROM t1; +# Now, wrap the INT_ITEM in Item_func_neg and watch the pretty explosions +SELECT NAME_CONST('flag',-1) * MAX(a) FROM t1; +SELECT NAME_CONST('flag',-1.5) * MAX(a) FROM t1; +--error ER_WRONG_ARGUMENTS +SELECT NAME_CONST('flag', SQRT(4)) * MAX(a) FROM t1; +--error ER_WRONG_ARGUMENTS +SELECT NAME_CONST('flag',-SQRT(4)) * MAX(a) FROM t1; +DROP TABLE t1; + +# +# Bug #27545: erroneous usage of NAME_CONST with a name as the first parameter +# resolved against a column name of a derived table hangs the client +# + +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (5), (2); + +--error ER_WRONG_ARGUMENTS +SELECT NAME_CONST(x,2) FROM (SELECT a x FROM t1) t; + +DROP TABLE t1; + + +# +# Bug #32559: connection hangs on query with name_const +# +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUES (), (), (); +--error ER_WRONG_ARGUMENTS +SELECT NAME_CONST(a, '1') FROM t1; +--error ER_WRONG_ARGUMENTS +SET INSERT_ID= NAME_CONST(a, a); +DROP TABLE t1; + +# +# Bug #31349: ERROR 1062 (23000): Duplicate entry '' for key 'group_key' +# +create table t1 (a int not null); +insert into t1 values (-1), (-2); +select min(a) from t1 group by inet_ntoa(a); +drop table t1; + +# +# BUG#34289 - Incorrect NAME_CONST substitution in stored procedures breaks +# replication +# +SELECT NAME_CONST('var', 'value') COLLATE latin1_general_cs; + +# +# Bug #35848: UUID() returns UUIDs with the wrong time +# +select @@session.time_zone into @save_tz; + +# make sure all times are UTC so the DayNr won't differ +set @@session.time_zone='UTC'; +select uuid() into @my_uuid; +# if version nibble isn't 1, the following calculations will be rubbish +select mid(@my_uuid,15,1); +select 24 * 60 * 60 * 1000 * 1000 * 10 into @my_uuid_one_day; +select concat('0',mid(@my_uuid,16,3),mid(@my_uuid,10,4),left(@my_uuid,8)) into @my_uuidate; +select floor(conv(@my_uuidate,16,10)/@my_uuid_one_day) into @my_uuid_date; +select 141427 + datediff(curdate(),'1970-01-01') into @my_uuid_synthetic; +# these should be identical; date part of UUID should be current date +select @my_uuid_date - @my_uuid_synthetic; + +set @@session.time_zone=@save_tz; + + +# +# Bug#42014: Crash, name_const with collate +# +CREATE TABLE t1 (a DATE); +SELECT * FROM t1 WHERE a = NAME_CONST('reportDate', + _binary'2009-01-09' COLLATE 'binary'); +DROP TABLE t1; + +# +# Bug#35515: Aliases of variables in binary log are ignored with NAME_CONST +# +select NAME_CONST('_id',1234) as id; + +--echo End of 5.0 tests + +# +# Bug #30389: connection_id() always return 0 in embedded server +# + +select connection_id() > 0; + +--echo # +--echo # Bug #54461: crash with longblob and union or update with subquery +--echo # + +CREATE TABLE t1 (a INT, b LONGBLOB); +INSERT INTO t1 VALUES (1, '2'), (2, '3'), (3, '2'); + +SELECT DISTINCT LEAST(a, (SELECT b FROM t1 LIMIT 1)) FROM t1 UNION SELECT 1; +SELECT DISTINCT GREATEST(a, (SELECT b FROM t1 LIMIT 1)) FROM t1 UNION SELECT 1; + +DROP TABLE t1; + + +# +# Bug #57283: inet_ntoa() crashes +# +SELECT INET_NTOA(0); +SELECT '1' IN ('1', INET_NTOA(0)); + +# +# MDEV-5655 Server crashes on NAME_CONST containing AND/OR expressions +# +--error ER_WRONG_ARGUMENTS +SELECT NAME_CONST('a', -(1 OR 2)) OR 1; +--error ER_WRONG_ARGUMENTS +SELECT NAME_CONST('a', -(1 AND 2)) AND 1; +SELECT NAME_CONST('a', -(1)) OR 1; + +--echo # +--echo #MDEV-5446: Assertion `!table || (!table->read_set || +--echo #bitmap_is_set(table->read_set, field_index))' fails on +--echo #EXPLAIN EXTENDED with VALUES function +--echo # +CREATE TABLE t1 (a INT, b INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1,10); +CREATE VIEW v1 AS SELECT * FROM t1; + +EXPLAIN EXTENDED SELECT VALUE(b) FROM v1; + +drop view v1; +drop table t1; + +--echo End of 5.3 tests + +--echo # +--echo # Bug #52165: Assertion failed: file .\dtoa.c, line 465 +--echo # + +CREATE TABLE t1 (a SET('a'), b INT); +INSERT INTO t1 VALUES ('', 0); + +SELECT COALESCE(a) = COALESCE(b) FROM t1; + +DROP TABLE t1; + + +--echo # +--echo # Bug #54461: crash with longblob and union or update with subquery +--echo # + +CREATE TABLE t1 (a INT, b LONGBLOB); +INSERT INTO t1 VALUES (1, '2'), (2, '3'), (3, '2'); + +SELECT DISTINCT LEAST(a, (SELECT b FROM t1 LIMIT 1)) FROM t1 UNION SELECT 1; +SELECT DISTINCT GREATEST(a, (SELECT b FROM t1 LIMIT 1)) FROM t1 UNION SELECT 1; + +DROP TABLE t1; + + +# +# Bug #57283: inet_ntoa() crashes +# +SELECT INET_NTOA(0); +SELECT '1' IN ('1', INET_NTOA(0)); + + +--echo # +--echo # End of 5.1 tests +--echo # + + +--echo # +--echo # Bug #58199: name_const in the having clause crashes +--echo # + +CREATE TABLE t1 (a INT); + +# NAME_CONST() would seg.fault when used wrongly in a HAVING clause +--error ER_WRONG_ARGUMENTS +SELECT 1 from t1 HAVING NAME_CONST('', a); + +DROP TABLE t1; + +--echo # +--echo # Test or correct maybe_null of last_value +--echo # +CREATE TABLE t1 (a char(2) not null ); +INSERT INTO t1 VALUES (4),(7),(1); +set @optimizer_switch_save= @@optimizer_switch; +set optimizer_switch='materialization=off'; +CREATE TABLE tv (e char(2) not null ); +INSERT INTO tv VALUES (1); +CREATE ALGORITHM=MERGE VIEW v_merge AS SELECT * FROM tv; +CREATE ALGORITHM=MERGE VIEW vm AS SELECT * FROM tv; +explain extended +select a from t1 left join v_merge on (a=e) where last_value(NULL,e) not in (select last_value(NULL,e) from vm); +explain extended +select a from t1 left join v_merge on (a=e) where e not in (select last_value(NULL,e) from vm); +set optimizer_switch=@optimizer_switch_save; +drop view v_merge, vm; +drop table t1,tv; + +--echo # +--echo # MDEV-4017 - GET_LOCK() with negative timeouts has strange behavior +--echo # +SELECT GET_LOCK('ul1', NULL); +SELECT GET_LOCK('ul1', -1); + +--echo # +--echo # MDEV-8624 MariaDB hangs on query with many logical condition +--echo # +CREATE TABLE `t1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `submitdate` datetime DEFAULT NULL, + `lastpage` int(11) DEFAULT NULL, + `startlanguage` varchar(20) COLLATE utf8_unicode_ci NOT NULL, + `token` varchar(36) COLLATE utf8_unicode_ci DEFAULT NULL, + `datestamp` datetime NOT NULL, + `startdate` datetime NOT NULL, + `ipaddr` text COLLATE utf8_unicode_ci, + `refurl` text COLLATE utf8_unicode_ci, + `57813X540X1723` text COLLATE utf8_unicode_ci, + `57813X540X1724` text COLLATE utf8_unicode_ci, + `57813X540X1725` text COLLATE utf8_unicode_ci, + `57813X540X1726` double DEFAULT NULL, + `57813X540X1909` double DEFAULT NULL, + `57813X541X17271` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X541X17272` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X541X17273` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X541X17274` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X541X17275` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X541X17276` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X541X17281` text COLLATE utf8_unicode_ci, + `57813X541X17282` text COLLATE utf8_unicode_ci, + `57813X541X17283` text COLLATE utf8_unicode_ci, + `57813X541X17284` text COLLATE utf8_unicode_ci, + `57813X541X17285` text COLLATE utf8_unicode_ci, + `57813X541X17286` text COLLATE utf8_unicode_ci, + `57813X542X18131` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X542X18132` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X542X18133` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X542X18134` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X542X18135` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X542X18136` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X542X18137` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X542X18138` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X542X18139` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X542X18141` text COLLATE utf8_unicode_ci, + `57813X542X18142` text COLLATE utf8_unicode_ci, + `57813X542X18143` text COLLATE utf8_unicode_ci, + `57813X542X18144` text COLLATE utf8_unicode_ci, + `57813X542X18145` text COLLATE utf8_unicode_ci, + `57813X542X18146` text COLLATE utf8_unicode_ci, + `57813X542X18147` text COLLATE utf8_unicode_ci, + `57813X542X18148` text COLLATE utf8_unicode_ci, + `57813X542X18149` text COLLATE utf8_unicode_ci, + `57813X543X18451` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X543X18452` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X543X18453` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X543X18454` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X543X18455` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X543X18456` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X543X18461` text COLLATE utf8_unicode_ci, + `57813X543X18462` text COLLATE utf8_unicode_ci, + `57813X543X18463` text COLLATE utf8_unicode_ci, + `57813X543X18464` text COLLATE utf8_unicode_ci, + `57813X543X18465` text COLLATE utf8_unicode_ci, + `57813X543X18466` text COLLATE utf8_unicode_ci, + `57813X544X18711` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X544X18712` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X544X18713` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X544X18714` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X544X18715` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X544X18716` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X544X18717` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X544X18718` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X544X18721` text COLLATE utf8_unicode_ci, + `57813X544X18722` text COLLATE utf8_unicode_ci, + `57813X544X18723` text COLLATE utf8_unicode_ci, + `57813X544X18724` text COLLATE utf8_unicode_ci, + `57813X544X18725` text COLLATE utf8_unicode_ci, + `57813X544X18726` text COLLATE utf8_unicode_ci, + `57813X544X18727` text COLLATE utf8_unicode_ci, + `57813X544X18728` text COLLATE utf8_unicode_ci, + `57813X546X1902` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X546X1903` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X546X1904` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `57813X545X1901` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `lime_survey_57813_idx` (`token`), + KEY `57813X540X1723` (`57813X540X1723`(100)), + KEY `57813X540X1724` (`57813X540X1724`(100)), + KEY `57813X540X1726` (`57813X540X1726`), + KEY `57813X540X1725` (`57813X540X1725`(100)), + KEY `57813X546X1902` (`57813X546X1902`), + KEY `57813X546X1903` (`57813X546X1903`), + KEY `57813X546X1904` (`57813X546X1904`) +); + +SELECT +COUNT(*) as `N`, +ROUND( + ( + SUM( + ( + ( + IF( 57813X541X17271 IS NOT NULL AND 57813X541X17271 != '' AND 57813X541X17271 != '99', 57813X541X17271, 0 ) + + IF( 57813X541X17272 IS NOT NULL AND 57813X541X17272 != '' AND 57813X541X17272 != '99', 57813X541X17272, 0 ) + + IF( 57813X541X17273 IS NOT NULL AND 57813X541X17273 != '' AND 57813X541X17273 != '99', 57813X541X17273, 0 ) + + IF( 57813X541X17274 IS NOT NULL AND 57813X541X17274 != '' AND 57813X541X17274 != '99', 57813X541X17274, 0 ) + + IF( 57813X541X17275 IS NOT NULL AND 57813X541X17275 != '' AND 57813X541X17275 != '99', 57813X541X17275, 0 ) + + IF( 57813X541X17276 IS NOT NULL AND 57813X541X17276 != '' AND 57813X541X17276 != '99', 57813X541X17276, 0 ) + + IF( 57813X542X18131 IS NOT NULL AND 57813X542X18131 != '' AND 57813X542X18131 != '99', 57813X542X18131, 0 ) + + IF( 57813X542X18132 IS NOT NULL AND 57813X542X18132 != '' AND 57813X542X18132 != '99', 57813X542X18132, 0 ) + + IF( 57813X542X18133 IS NOT NULL AND 57813X542X18133 != '' AND 57813X542X18133 != '99', 57813X542X18133, 0 ) + + IF( 57813X542X18134 IS NOT NULL AND 57813X542X18134 != '' AND 57813X542X18134 != '99', 57813X542X18134, 0 ) + + IF( 57813X542X18135 IS NOT NULL AND 57813X542X18135 != '' AND 57813X542X18135 != '99', 57813X542X18135, 0 ) + + IF( 57813X542X18136 IS NOT NULL AND 57813X542X18136 != '' AND 57813X542X18136 != '99', 57813X542X18136, 0 ) + + IF( 57813X542X18137 IS NOT NULL AND 57813X542X18137 != '' AND 57813X542X18137 != '99', 57813X542X18137, 0 ) + + IF( 57813X542X18138 IS NOT NULL AND 57813X542X18138 != '' AND 57813X542X18138 != '99', 57813X542X18138, 0 ) + + IF( 57813X542X18139 IS NOT NULL AND 57813X542X18139 != '' AND 57813X542X18139 != '99', 57813X542X18139, 0 ) + + IF( 57813X543X18451 IS NOT NULL AND 57813X543X18451 != '' AND 57813X543X18451 != '99', 57813X543X18451, 0 ) + + IF( 57813X543X18452 IS NOT NULL AND 57813X543X18452 != '' AND 57813X543X18452 != '99', 57813X543X18452, 0 ) + + IF( 57813X543X18453 IS NOT NULL AND 57813X543X18453 != '' AND 57813X543X18453 != '99', 57813X543X18453, 0 ) + + IF( 57813X543X18454 IS NOT NULL AND 57813X543X18454 != '' AND 57813X543X18454 != '99', 57813X543X18454, 0 ) + + IF( 57813X543X18455 IS NOT NULL AND 57813X543X18455 != '' AND 57813X543X18455 != '99', 57813X543X18455, 0 ) + + IF( 57813X543X18456 IS NOT NULL AND 57813X543X18456 != '' AND 57813X543X18456 != '99', 57813X543X18456, 0 ) + + IF( 57813X544X18711 IS NOT NULL AND 57813X544X18711 != '' AND 57813X544X18711 != '99', 57813X544X18711, 0 ) + + IF( 57813X544X18712 IS NOT NULL AND 57813X544X18712 != '' AND 57813X544X18712 != '99', 57813X544X18712, 0 ) + + IF( 57813X544X18713 IS NOT NULL AND 57813X544X18713 != '' AND 57813X544X18713 != '99', 57813X544X18713, 0 ) + + IF( 57813X544X18714 IS NOT NULL AND 57813X544X18714 != '' AND 57813X544X18714 != '99', 57813X544X18714, 0 ) + + IF( 57813X544X18715 IS NOT NULL AND 57813X544X18715 != '' AND 57813X544X18715 != '99', 57813X544X18715, 0 ) + + IF( 57813X544X18716 IS NOT NULL AND 57813X544X18716 != '' AND 57813X544X18716 != '99', 57813X544X18716, 0 ) + + IF( 57813X544X18717 IS NOT NULL AND 57813X544X18717 != '' AND 57813X544X18717 != '99', 57813X544X18717, 0 ) + + IF( 57813X544X18718 IS NOT NULL AND 57813X544X18718 != '' AND 57813X544X18718 != '99', 57813X544X18718, 0 ) + ) + / + ( + IF( 57813X541X17271 IS NOT NULL AND 57813X541X17271 != '' AND 57813X541X17271 != '99', 1, 0 ) + + IF( 57813X541X17272 IS NOT NULL AND 57813X541X17272 != '' AND 57813X541X17272 != '99', 1, 0 ) + + IF( 57813X541X17273 IS NOT NULL AND 57813X541X17273 != '' AND 57813X541X17273 != '99', 1, 0 ) + + IF( 57813X541X17274 IS NOT NULL AND 57813X541X17274 != '' AND 57813X541X17274 != '99', 1, 0 ) + + IF( 57813X541X17275 IS NOT NULL AND 57813X541X17275 != '' AND 57813X541X17275 != '99', 1, 0 ) + + IF( 57813X541X17276 IS NOT NULL AND 57813X541X17276 != '' AND 57813X541X17276 != '99', 1, 0 ) + + IF( 57813X542X18131 IS NOT NULL AND 57813X542X18131 != '' AND 57813X542X18131 != '99', 1, 0 ) + + IF( 57813X542X18132 IS NOT NULL AND 57813X542X18132 != '' AND 57813X542X18132 != '99', 1, 0 ) + + IF( 57813X542X18133 IS NOT NULL AND 57813X542X18133 != '' AND 57813X542X18133 != '99', 1, 0 ) + + IF( 57813X542X18134 IS NOT NULL AND 57813X542X18134 != '' AND 57813X542X18134 != '99', 1, 0 ) + + IF( 57813X542X18135 IS NOT NULL AND 57813X542X18135 != '' AND 57813X542X18135 != '99', 1, 0 ) + + IF( 57813X542X18136 IS NOT NULL AND 57813X542X18136 != '' AND 57813X542X18136 != '99', 1, 0 ) + + IF( 57813X542X18137 IS NOT NULL AND 57813X542X18137 != '' AND 57813X542X18137 != '99', 1, 0 ) + + IF( 57813X542X18138 IS NOT NULL AND 57813X542X18138 != '' AND 57813X542X18138 != '99', 1, 0 ) + + IF( 57813X542X18139 IS NOT NULL AND 57813X542X18139 != '' AND 57813X542X18139 != '99', 1, 0 ) + + IF( 57813X543X18451 IS NOT NULL AND 57813X543X18451 != '' AND 57813X543X18451 != '99', 1, 0 ) + + IF( 57813X543X18452 IS NOT NULL AND 57813X543X18452 != '' AND 57813X543X18452 != '99', 1, 0 ) + + IF( 57813X543X18453 IS NOT NULL AND 57813X543X18453 != '' AND 57813X543X18453 != '99', 1, 0 ) + + IF( 57813X543X18454 IS NOT NULL AND 57813X543X18454 != '' AND 57813X543X18454 != '99', 1, 0 ) + + IF( 57813X543X18455 IS NOT NULL AND 57813X543X18455 != '' AND 57813X543X18455 != '99', 1, 0 ) + + IF( 57813X543X18456 IS NOT NULL AND 57813X543X18456 != '' AND 57813X543X18456 != '99', 1, 0 ) + + IF( 57813X544X18711 IS NOT NULL AND 57813X544X18711 != '' AND 57813X544X18711 != '99', 1, 0 ) + + IF( 57813X544X18712 IS NOT NULL AND 57813X544X18712 != '' AND 57813X544X18712 != '99', 1, 0 ) + + IF( 57813X544X18713 IS NOT NULL AND 57813X544X18713 != '' AND 57813X544X18713 != '99', 1, 0 ) + + IF( 57813X544X18714 IS NOT NULL AND 57813X544X18714 != '' AND 57813X544X18714 != '99', 1, 0 ) + + IF( 57813X544X18715 IS NOT NULL AND 57813X544X18715 != '' AND 57813X544X18715 != '99', 1, 0 ) + + IF( 57813X544X18716 IS NOT NULL AND 57813X544X18716 != '' AND 57813X544X18716 != '99', 1, 0 ) + + IF( 57813X544X18717 IS NOT NULL AND 57813X544X18717 != '' AND 57813X544X18717 != '99', 1, 0 ) + + IF( 57813X544X18718 IS NOT NULL AND 57813X544X18718 != '' AND 57813X544X18718 != '99', 1, 0 ) + ) + ) + ) + / COUNT(*) ), 4) as `AVG` +FROM `t1` +WHERE `submitdate` IS NOT NULL +AND ( + ( 57813X541X17271 IS NOT NULL AND 57813X541X17271 != '' AND 57813X541X17271 != '99' ) OR + ( 57813X541X17272 IS NOT NULL AND 57813X541X17272 != '' AND 57813X541X17272 != '99' ) OR + ( 57813X541X17273 IS NOT NULL AND 57813X541X17273 != '' AND 57813X541X17273 != '99' ) OR + ( 57813X541X17274 IS NOT NULL AND 57813X541X17274 != '' AND 57813X541X17274 != '99' ) OR + ( 57813X541X17275 IS NOT NULL AND 57813X541X17275 != '' AND 57813X541X17275 != '99' ) OR + ( 57813X541X17276 IS NOT NULL AND 57813X541X17276 != '' AND 57813X541X17276 != '99' ) OR + ( 57813X542X18131 IS NOT NULL AND 57813X542X18131 != '' AND 57813X542X18131 != '99' ) OR + ( 57813X542X18132 IS NOT NULL AND 57813X542X18132 != '' AND 57813X542X18132 != '99' ) OR + ( 57813X542X18133 IS NOT NULL AND 57813X542X18133 != '' AND 57813X542X18133 != '99' ) OR + ( 57813X542X18134 IS NOT NULL AND 57813X542X18134 != '' AND 57813X542X18134 != '99' ) OR + ( 57813X542X18135 IS NOT NULL AND 57813X542X18135 != '' AND 57813X542X18135 != '99' ) OR + ( 57813X542X18136 IS NOT NULL AND 57813X542X18136 != '' AND 57813X542X18136 != '99' ) OR + ( 57813X542X18137 IS NOT NULL AND 57813X542X18137 != '' AND 57813X542X18137 != '99' ) OR + ( 57813X542X18138 IS NOT NULL AND 57813X542X18138 != '' AND 57813X542X18138 != '99' ) OR + ( 57813X542X18139 IS NOT NULL AND 57813X542X18139 != '' AND 57813X542X18139 != '99' ) OR + ( 57813X543X18451 IS NOT NULL AND 57813X543X18451 != '' AND 57813X543X18451 != '99' ) OR + ( 57813X543X18452 IS NOT NULL AND 57813X543X18452 != '' AND 57813X543X18452 != '99' ) OR + ( 57813X543X18453 IS NOT NULL AND 57813X543X18453 != '' AND 57813X543X18453 != '99' ) OR + ( 57813X543X18454 IS NOT NULL AND 57813X543X18454 != '' AND 57813X543X18454 != '99' ) OR + ( 57813X543X18455 IS NOT NULL AND 57813X543X18455 != '' AND 57813X543X18455 != '99' ) OR + ( 57813X543X18456 IS NOT NULL AND 57813X543X18456 != '' AND 57813X543X18456 != '99' ) OR + ( 57813X544X18711 IS NOT NULL AND 57813X544X18711 != '' AND 57813X544X18711 != '99' ) OR + ( 57813X544X18712 IS NOT NULL AND 57813X544X18712 != '' AND 57813X544X18712 != '99' ) OR + ( 57813X544X18713 IS NOT NULL AND 57813X544X18713 != '' AND 57813X544X18713 != '99' ) OR + ( 57813X544X18714 IS NOT NULL AND 57813X544X18714 != '' AND 57813X544X18714 != '99' ) OR + ( 57813X544X18715 IS NOT NULL AND 57813X544X18715 != '' AND 57813X544X18715 != '99' ) OR + ( 57813X544X18716 IS NOT NULL AND 57813X544X18716 != '' AND 57813X544X18716 != '99' ) OR + ( 57813X544X18717 IS NOT NULL AND 57813X544X18717 != '' AND 57813X544X18717 != '99' ) OR + ( 57813X544X18718 IS NOT NULL AND 57813X544X18718 != '' AND 57813X544X18718 != '99' ) ) +AND 57813X540X1723 = 'Test'; + +drop table t1; + +# +# Bug#12735545 - PARSER STACK OVERFLOW WITH NAME_CONST +# CONTAINING OR EXPRESSION +# +--error ER_WRONG_ARGUMENTS +SELECT NAME_CONST('a', -(1 OR 2)) OR 1; +--error ER_WRONG_ARGUMENTS +SELECT NAME_CONST('a', -(1 AND 2)) OR 1; +SELECT NAME_CONST('a', -(1)) OR 1; + +--echo # +--echo # MDEV-15630 uuid() function evaluates at wrong time in query +--echo # + +CREATE TABLE t1 (id INT); +INSERT INTO t1 VALUES (1),(2),(3); +--replace_column 2 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx +SELECT COUNT(1), UUID() as uid FROM t1 GROUP BY uid; +DROP TABLE t1; + + +--echo # +--echo # End of 5.5 tests +--echo # + +--echo # +--echo # GET_LOCK, RELEASE_LOCK, IS_USED_LOCK functions test +--echo # + +--echo # IS_USED_LOCK, IS_FREE_LOCK: the lock is not acquired +--echo # Note: IS_USED_LOCK returns NULL if the lock is unused +select is_used_lock('test'); +select is_free_lock('test'); + +--echo # GET_LOCK returns 1 if it manages to acquire a lock +select get_lock('test', 0); + +--echo # IS_USED_LOCK, IS_FREE_LOCK: the lock is acquired +select is_free_lock('test'); +select is_used_lock('test') = connection_id(); + +connect (con1,localhost,root,,); +connection con1; +--echo # IS_USED_LOCK, IS_FREE_LOCK: the lock is acquired in another +--echo # connection +select is_used_lock('test') = connection_id(); +select is_free_lock('test'); + +--echo # GET_LOCK returns 0 if it can't acquire a lock (wait timeout) +select get_lock('test', 0); + +--echo # RELEASE_LOCK returns 0 if the lock belongs to another connection +select release_lock('test'); + +connection default; + +--echo # RELEASE_LOCK returns 1 if it successfully releases a lock +select release_lock('test'); +--echo # RELEASE_LOCK returns NULL if it doesn't release a lock and there is no such lock +select release_lock('test'); + +--echo # Test that get_lock() returns NULL if error. +select get_lock('test', 0); +connection con1; +create table t1 select connection_id() as id; +send select get_lock('test', 7200); + +connection default; +let $wait_condition= SELECT count(*) > 0 FROM information_schema.processlist WHERE info LIKE 'select%' AND state='User lock'; +source include/wait_condition.inc; +select (@id := id) - id from t1; +kill query @id; + +connection con1; +reap; + +connection default; + +--echo # GET_LOCK() works recursively +select get_lock('test', 0); +select get_lock('test', 0); +select get_lock('test', 0); + +--echo # RELEASE_LOCK() needs to be called recursively then, too +select release_lock('test'); +select release_lock('test'); +select release_lock('test'); + +--echo # Once the last instance of the lock is released, +--echo # the next call returns NULL +select release_lock('test'); + + +--echo # Multiple locks in the same session are OK +select get_lock('test1', 0); +select get_lock('test2', 0); +select get_lock('test3', 0); + +select release_lock('test1'); +select release_lock('test2'); +select release_lock('test3'); + +--echo # Deadlocks are detected e.g. in case of a mutual wait +select get_lock('test1', 0); + +connection con1; +select get_lock('test2', 0); +send select get_lock('test1', 7200); + +connection default; +let $wait_condition= SELECT count(*) > 0 FROM information_schema.processlist WHERE info LIKE 'select%' AND state='User lock'; +source include/wait_condition.inc; +--error ER_LOCK_DEADLOCK +select get_lock('test2', 7200); + +select release_lock('test1'); + +connection con1; +reap; +select release_lock('test2'); +select release_lock('test1'); + +connection default; + +--echo # LOCK/UNLOCK TABLES works fine with a user lock. +lock table t1 write; +select get_lock('test', 0); +unlock tables; +commit; +select release_lock('test'); + +--echo # GLOBAL READ LOCK works with fine with user locks +select get_lock('test1', 0); +flush tables with read lock; +select get_lock('test2', 0); +unlock tables; +commit; +select release_lock('test1'); +select release_lock('test2'); + +--echo # BEGIN/COMMIT/ROLLBACK don't unlock user locks. +begin; +select get_lock('test1', 0); +select get_lock('test2', 0); +select count(*) from t1; +rollback; +select release_lock('test1'); +select release_lock('test2'); + +--echo # Deadlocks between user locks and LOCK TABLES locks +--echo # are detected OK. +select get_lock('test', 0); + +connection con1; +lock table t1 write; +send select get_lock('test', 7200); + +connection default; +let $wait_condition= SELECT count(*) > 0 FROM information_schema.processlist WHERE info LIKE 'select%' AND state = 'User lock'; +source include/wait_condition.inc; +--error ER_LOCK_DEADLOCK +lock table t1 read; + +select release_lock('test'); + +connection con1; +reap; +select release_lock('test'); +unlock tables; + +--echo # cleanup +disconnect con1; +connection default; +drop table t1; + +--echo # check too long identifier names +select get_lock(repeat('a', 192), 0); +select is_used_lock(repeat('a', 192)) = connection_id(); +select is_free_lock(repeat('a', 192)); +select release_lock(repeat('a', 192)); +--error ER_TOO_LONG_IDENT +select get_lock(repeat('a', 193), 0); +--error ER_TOO_LONG_IDENT +select is_used_lock(repeat('a', 193)); +--error ER_TOO_LONG_IDENT +select is_free_lock(repeat('a', 193)); +--error ER_TOO_LONG_IDENT +select release_lock(repeat('a', 193)); + + +--echo +--echo # -- +--echo # -- WL#5787: IPv6-capable INET_ATON and INET_NTOA functions. +--echo # -- + +--echo +--echo # -- INET6_ATON: checking NULL, invalid types, out-of range values... +--echo + +SELECT INET6_ATON(NULL) IS NULL; +SELECT INET6_ATON(123) IS NULL; +SELECT INET6_ATON(123.45) IS NULL; +SELECT INET6_ATON(NOW()) IS NULL; + +SELECT INET6_ATON('1.2.3') IS NULL; +SELECT INET6_ATON('1.2.3.') IS NULL; +SELECT INET6_ATON('1..3.4') IS NULL; +SELECT INET6_ATON('-1.2.3.4') IS NULL; +SELECT INET6_ATON('1.2.3.256') IS NULL; +SELECT INET6_ATON('1.2.3.4.5') IS NULL; +SELECT INET6_ATON('0001.2.3.4') IS NULL; +SELECT INET6_ATON('0x1.2.3.4') IS NULL; +SELECT INET6_ATON('a.2.3.4') IS NULL; + +SELECT INET6_ATON('1.2.3.4:80') IS NULL; +SELECT INET6_ATON('1.2.3.4/32') IS NULL; + +SELECT INET6_ATON('mysql.com') IS NULL; + +SELECT INET6_ATON(':::') IS NULL; +SELECT INET6_ATON(':1:2:3') IS NULL; +SELECT INET6_ATON('1:2:3:') IS NULL; +SELECT INET6_ATON(':1::2:3') IS NULL; +SELECT INET6_ATON('1::2:3:') IS NULL; +SELECT INET6_ATON('::00001') IS NULL; +SELECT INET6_ATON('::00001:2') IS NULL; +SELECT INET6_ATON('::12345') IS NULL; +SELECT INET6_ATON('1020::3040::5060') IS NULL; +SELECT INET6_ATON('::ABCZ') IS NULL; + +SELECT INET6_ATON('::0x1.2.3.4') IS NULL; +SELECT INET6_ATON('::1.0x2.3.4') IS NULL; +SELECT INET6_ATON('::a.b.c.d') IS NULL; + +SELECT INET6_ATON('::FFFF:0x1.2.3.4') IS NULL; +SELECT INET6_ATON('::FFFF:1.0x2.3.4') IS NULL; +SELECT INET6_ATON('::FFFF:a.b.c.d') IS NULL; + +SELECT INET6_ATON('::1.2.3.4:ABCD') IS NULL; + +--echo # NOTE: such addresses are supported because getaddrinfo() supports them. +--echo # This is just to record the current behaviour. +SELECT HEX(INET6_ATON('::ABCD:1.2.3.4')); + +--echo +--echo # -- INET6_ATON: checking binary representation... +--echo + +SELECT HEX(INET6_ATON('0.0.0.0')); +SELECT HEX(INET6_ATON('00.00.00.00')); +SELECT HEX(INET6_ATON('000.000.000.000')); +SELECT HEX(INET6_ATON('1.2.3.4')); +SELECT HEX(INET6_ATON('01.02.03.04')); +SELECT HEX(INET6_ATON('001.002.003.004')); +SELECT HEX(INET6_ATON('255.255.255.255')); +SELECT HEX(INET6_ATON('::')); +SELECT HEX(INET6_ATON('0::0')); +SELECT HEX(INET6_ATON('1::2')); +SELECT HEX(INET6_ATON('0::')); +SELECT HEX(INET6_ATON('1::')); +SELECT HEX(INET6_ATON('::0')); +SELECT HEX(INET6_ATON('::1')); +SELECT HEX(INET6_ATON('1:2:3:4:5:6:7:8')); +SELECT HEX(INET6_ATON('::2:3:4:5:6:7:8')); +SELECT HEX(INET6_ATON('1::3:4:5:6:7:8')); +SELECT HEX(INET6_ATON('1:2::4:5:6:7:8')); +SELECT HEX(INET6_ATON('1:2:3::5:6:7:8')); +SELECT HEX(INET6_ATON('1:2:3:4::6:7:8')); +SELECT HEX(INET6_ATON('1:2:3:4:5::7:8')); +SELECT HEX(INET6_ATON('1:2:3:4:5:6::8')); +SELECT HEX(INET6_ATON('1:2:3:4:5:6:7::')); +SELECT HEX(INET6_ATON('0000:0000::0000:0001')); +SELECT HEX(INET6_ATON('1234:5678:9abc:def0:4321:8765:cba9:0fed')); +SELECT HEX(INET6_ATON('0000:0000:0000:0000:0000:0000:0000:0001')); +SELECT HEX(INET6_ATON('::C0A8:0102')); +SELECT HEX(INET6_ATON('::c0a8:0102')); +SELECT HEX(INET6_ATON('::192.168.1.2')); +SELECT HEX(INET6_ATON('::FfFf:C0a8:0102')); +SELECT HEX(INET6_ATON('::ffff:c0a8:0102')); +SELECT HEX(INET6_ATON('::ffff:192.168.1.2')); +SELECT HEX(INET6_ATON('::01.2.3.4')); +SELECT HEX(INET6_ATON('::1.02.3.4')); +SELECT HEX(INET6_ATON('::1.2.03.4')); +SELECT HEX(INET6_ATON('::1.2.3.04')); +SELECT HEX(INET6_ATON('::1.2.3.00')); +SELECT HEX(INET6_ATON('::FFFF:01.2.3.4')); +SELECT HEX(INET6_ATON('::FFFF:1.02.3.4')); +SELECT HEX(INET6_ATON('::FFFF:1.2.03.4')); +SELECT HEX(INET6_ATON('::FFFF:1.2.3.04')); +SELECT HEX(INET6_ATON('::FFFF:1.2.3.00')); + +--echo +--echo # -- INET6_ATON: checking the length is either 4 or 16... +--echo + +SELECT LENGTH(INET6_ATON('0.0.0.0')); +SELECT LENGTH(INET6_ATON('255.255.255.255')); +SELECT LENGTH(INET6_ATON('::')); +SELECT LENGTH(INET6_ATON('1020:3040:5060:7080:90A0:B0C0:D0E0:F010')); + +--echo +--echo # -- INET6_NTOA: checking NULL, invalid types, out-of range values... +--echo + +SELECT INET6_NTOA(NULL); +SELECT INET6_NTOA(123); +SELECT INET6_NTOA(123.456); +SELECT INET6_NTOA(NOW()); +SELECT INET6_NTOA(UNHEX('C0A801')); # 3 bytes -> NULL +SELECT INET6_NTOA(UNHEX('C0A80102')); # 4 bytes -> 192.168.1.2 +SELECT INET6_NTOA(UNHEX('C0A8010203')); # 5 bytes -> NULL +SELECT INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F')); # 15 bytes -> NULL +SELECT INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F10')); # 16 bytes -> IP +SELECT INET6_NTOA(UNHEX('0102030405060708090A0B0C0D0E0F1011')); # 17 bytes -> NULL + +SELECT INET6_NTOA('1234'), INET6_NTOA(BINARY('1234')); +SELECT INET6_NTOA('0123456789abcdef'), INET6_NTOA(BINARY('0123456789abcdef')); + +--echo +--echo # -- Checking double-conversion... +--echo + +SELECT INET6_NTOA(INET6_ATON('::')); +SELECT INET6_NTOA(INET6_ATON('0::0')); +SELECT INET6_NTOA(INET6_ATON('1::2')); +SELECT INET6_NTOA(INET6_ATON('0::')); +SELECT INET6_NTOA(INET6_ATON('1::')); +SELECT INET6_NTOA(INET6_ATON('::0')); +SELECT INET6_NTOA(INET6_ATON('::1')); +SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5:6:7:8')); +SELECT INET6_NTOA(INET6_ATON('::2:3:4:5:6:7:8')); +SELECT INET6_NTOA(INET6_ATON('1::3:4:5:6:7:8')); +SELECT INET6_NTOA(INET6_ATON('1:2::4:5:6:7:8')); +SELECT INET6_NTOA(INET6_ATON('1:2:3::5:6:7:8')); +SELECT INET6_NTOA(INET6_ATON('1:2:3:4::6:7:8')); +SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5::7:8')); +SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5:6::8')); +SELECT INET6_NTOA(INET6_ATON('1:2:3:4:5:6:7::')); +SELECT INET6_NTOA(INET6_ATON('0000:0000::0000:0001')); +SELECT INET6_NTOA(INET6_ATON('1234:5678:9abc:def0:4321:8765:cba9:0fed')); +SELECT INET6_NTOA(INET6_ATON('0000:0000:0000:0000:0000:0000:0000:0001')); +SELECT INET6_NTOA(INET6_ATON('::C0A8:0102')); +SELECT INET6_NTOA(INET6_ATON('::c0a8:0102')); +SELECT INET6_NTOA(INET6_ATON('::192.168.1.2')); +SELECT INET6_NTOA(INET6_ATON('::FfFf:C0a8:0102')); +SELECT INET6_NTOA(INET6_ATON('::ffff:c0a8:0102')); +SELECT INET6_NTOA(INET6_ATON('::ffff:192.168.1.2')); +SELECT INET6_NTOA(INET6_ATON('::01.2.3.4')); +SELECT INET6_NTOA(INET6_ATON('::1.02.3.4')); +SELECT INET6_NTOA(INET6_ATON('::1.2.03.4')); +SELECT INET6_NTOA(INET6_ATON('::1.2.3.04')); +SELECT INET6_NTOA(INET6_ATON('::1.2.3.00')); +SELECT INET6_NTOA(INET6_ATON('::FFFF:01.2.3.4')); +SELECT INET6_NTOA(INET6_ATON('::FFFF:1.02.3.4')); +SELECT INET6_NTOA(INET6_ATON('::FFFF:1.2.03.4')); +SELECT INET6_NTOA(INET6_ATON('::FFFF:1.2.3.04')); +SELECT INET6_NTOA(INET6_ATON('::FFFF:1.2.3.00')); + +--echo +--echo # -- Comparing INET_ATON() and INET6_ATON()... +--echo + +SELECT HEX(INET_ATON('192.168.1.2')); +SELECT HEX(INET6_ATON('192.168.1.2')); + +SELECT HEX(INET_ATON('255.255.255.255')); +SELECT HEX(INET6_ATON('255.255.255.255')); + +SELECT HEX(INET_ATON('192.168.08.2')); +SELECT HEX(INET6_ATON('192.168.08.2')); + +SELECT HEX(INET_ATON('192.168.0x8.2')); +SELECT HEX(INET6_ATON('192.168.0x8.2')); + +SELECT HEX(INET_ATON('1.2.255')); +SELECT HEX(INET6_ATON('1.2.255')); + +SELECT HEX(INET_ATON('1.2.256')); +SELECT HEX(INET6_ATON('1.2.256')); + +SELECT HEX(INET_ATON('1.0002.3.4')); +SELECT HEX(INET6_ATON('1.0002.3.4')); + +SELECT HEX(INET_ATON('1.2.3.4.5')); +SELECT HEX(INET6_ATON('1.2.3.4.5')); + +--echo +--echo # -- Checking mix of INET- and INET6- functions... +--echo + +SELECT HEX(INET6_ATON(INET_NTOA(INET_ATON('1.2.3.4')))) AS x; + +--echo +--echo # -- Checking IS_IPV4() / IS_IPV6()... +--echo + +SELECT IS_IPV4(NULL); +SELECT IS_IPV4(1); +SELECT IS_IPV4(1.0); +SELECT IS_IPV4('1.2.3.4'); +SELECT IS_IPV4('001.02.000.255'); +SELECT IS_IPV4('::1.2.0.255'); +SELECT IS_IPV4('::1'); +SELECT IS_IPV4(BINARY('1.2.3.4')); + +SELECT IS_IPV6(NULL); +SELECT IS_IPV6(1); +SELECT IS_IPV6(1.0); +SELECT IS_IPV6('1.2.3.4'); +SELECT IS_IPV6('001.02.000.255'); +SELECT IS_IPV6('::001.02.000.255'); +SELECT IS_IPV6('::1.2.0.255'); +SELECT IS_IPV6('::1'); +SELECT IS_IPV6('0000:0000:0000:0000:0000:0000:0000:0001'); +SELECT IS_IPV6(BINARY('0000:0000:0000:0000:0000:0000:0000:0001')); + +--echo +--echo # -- Checking IS_IPV4_MAPPED() and IS_IPV4_COMPAT()... +--echo + +SELECT IS_IPV4_MAPPED(INET6_ATON('1.2.3.4')), + IS_IPV4_COMPAT(INET6_ATON('1.2.3.4')); +SELECT IS_IPV4_MAPPED(INET6_ATON('::1.2.3.4')), + IS_IPV4_COMPAT(INET6_ATON('::1.2.3.4')); +SELECT IS_IPV4_MAPPED(INET6_ATON('::FFFF:1.2.3.4')), + IS_IPV4_COMPAT(INET6_ATON('::FFFF:1.2.3.4')); +SELECT IS_IPV4_MAPPED(INET6_ATON('::ABCD:1.2.3.4')), + IS_IPV4_COMPAT(INET6_ATON('::ABCD:1.2.3.4')); +SELECT IS_IPV4_MAPPED(INET6_ATON('::1')), + IS_IPV4_COMPAT(INET6_ATON('::1')); +SELECT IS_IPV4_MAPPED(INET6_ATON('::')), + IS_IPV4_COMPAT(INET6_ATON('::')); + +# NOTE: IS_IPV4_COMPAT() / IS_IPV4_MAPPED() could work with "regular strings in +# binary collation" too, but there is no way to create a "regular string" +# starting with \0. + +--echo +--echo # -- Checking IS_IPV4_COMPAT()... +--echo + +--echo +--echo # -- Working with a table... +--echo + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +--enable_warnings + +CREATE TABLE t1(ip INT UNSIGNED); +CREATE TABLE t2(ip VARBINARY(16)); + +--echo + +INSERT INTO t1 VALUES + (INET_ATON('1.2.3.4')), (INET_ATON('255.255.255.255')); +SELECT INET_NTOA(ip) FROM t1; + +--echo + +INSERT INTO t2 SELECT INET6_ATON(INET_NTOA(ip)) FROM t1; +SELECT INET6_NTOA(ip), HEX(ip), LENGTH(ip) FROM t2; +DELETE FROM t2; + +--echo + +INSERT INTO t2 VALUES + (INET6_ATON('1.2.3.4')), (INET6_ATON('255.255.255.255')), + (INET6_ATON('::1.2.3.4')), (INET6_ATON('::ffff:255.255.255.255')), + (INET6_ATON('::')), (INET6_ATON('::1')), + (INET6_ATON('1020:3040:5060:7080:90A0:B0C0:D0E0:F010')); +SELECT INET6_NTOA(ip), HEX(ip), LENGTH(ip) FROM t2; + +--echo + +DROP TABLE t1; +DROP TABLE t2; + +--echo # +--echo # MDEV-4018 : Microseconds in GET_LOCK() +--echo # + +connection default; +select is_used_lock('test') = connection_id(); + +--echo # GET_LOCK returns 1 if it manages to acquire a lock +select get_lock('test', 0); + +connect (con1,localhost,root,,); +connection con1; +select is_used_lock('test') = connection_id(); +select get_lock('test', 0); +select get_lock('test', 1.0); +select get_lock('test', 1.5); +select get_lock('test', 0.1); +select get_lock('test', 0.000001); +select get_lock('test', 0.0000000000000001); + +connection default; +select is_used_lock('test') = connection_id(); +select release_lock('test'); + +--echo +--echo # -- Done. +--echo + + +--echo # +--echo # MDEV-13685 Can not replay binary log due to Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation 'concat' +--echo # +SET NAMES utf8; +SELECT COERCIBILITY(NAME_CONST('name','test')); +SELECT COERCIBILITY(NAME_CONST('name',TIME'00:00:00')); +SELECT COERCIBILITY(NAME_CONST('name',15)); +SELECT CONCAT(NAME_CONST('name',15),'오'); +SET NAMES latin1; + +--echo # +--echo # MDEV-14116 INET6_NTOA output is set as null to varchar(39) variable +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1() +BEGIN + DECLARE ip_full_addr varchar(39) DEFAULT ""; + SELECT INET6_NTOA(UNHEX('20000000000000000000000000000000')) into ip_full_addr; + SELECT ip_full_addr; +END; +$$ +DELIMITER ;$$ +CALL p1(); +DROP PROCEDURE p1; + ++--echo # ++--echo # MDEV-18195 ASAN use-after-poison in my_strcasecmp_utf8 / Item::eq upon prepared statement with ORDER BY NAME_CONST ++--echo # ++ ++PREPARE stmt FROM "SELECT 'x' ORDER BY NAME_CONST( 'f', 'foo' )"; ++EXECUTE stmt; ++DEALLOCATE PREPARE stmt; ++ + +--echo # +--echo # Start of 10.2 tests +--echo # + +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # + +CREATE TABLE t1 ( + a VARCHAR(30), + b BIGINT DEFAULT INET_ATON(a), + a1 VARCHAR(30) DEFAULT INET_NTOA(b), + c INT DEFAULT IS_IPV4(a), + d INT DEFAULT IS_IPV6(a) +); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('192.168.001.001'),('::1'),('xxx'); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + str VARCHAR(128), + addr VARBINARY(16) DEFAULT INET6_ATON(str), + str1 VARCHAR(128) DEFAULT INET6_NTOA(addr), + b INT DEFAULT IS_IPV4_COMPAT(addr), + c INT DEFAULT IS_IPV4_MAPPED(addr) +); +SHOW CREATE TABLE t1; +INSERT INTO t1 (str) VALUES ('::FFFF:192.168.0.1'),('::10.0.5.9'); +SELECT str, str1, b,c FROM t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-14613: Assertion `fixed == 0' failed in Item_func::fix_fields +--echo # + +CREATE TABLE `t1` ( + `numgtfmt` char(10) COLLATE utf8_bin NOT NULL +) DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +create view v1(numgtfmt) +as +select 'x' from t1 +union +select 'x' from t1 ; + +SELECT * FROM v1 WHERE numgtfmt = NAME_CONST('wnumgtfmt',_utf8'QEDITIONS' COLLATE 'utf8_bin'); + +# Cleanup +DROP VIEW v1; +DROP TABLE t1; + + +--echo # +--echo # End of 10.2 tests +--echo # + +--echo # +--echo # Start of 10.3 tests +--echo # + +--echo # +--echo # MDEV-12854 Synchronize CREATE..SELECT data type and result set metadata data type for INT functions +--echo # + +--enable_metadata +--disable_ps_protocol + +SELECT INET_ATON("255.255.255.255.255.255.255.255"); + +--enable_ps_protocol +--disable_metadata + +--echo # +--echo # MDEV-8049 name_const() is not consistent about its signess +--echo # + +--enable_metadata +--disable_ps_protocol +SELECT 18446744073709551615 AS c1, name_const('a',18446744073709551615) AS c2; +--enable_ps_protocol +--disable_metadata + +CREATE TABLE t1 AS SELECT 18446744073709551615 AS c1, name_const('a',18446744073709551615) AS c2; +SHOW CREATE TABLE t1; +SELECT * FROM t1; +DROP TABLE t1; diff --cc mysql-test/main/gis.test index d22591bbe69,00000000000..fbc130fcb7e mode 100644,000000..100644 --- a/mysql-test/main/gis.test +++ b/mysql-test/main/gis.test @@@ -1,3007 -1,0 +1,3006 @@@ +-- source include/have_geometry.inc + + +# +# Spatial objects +# + +CREATE TABLE gis_point (fid INTEGER NOT NULL PRIMARY KEY, g POINT); +CREATE TABLE gis_line (fid INTEGER NOT NULL PRIMARY KEY, g LINESTRING); +CREATE TABLE gis_polygon (fid INTEGER NOT NULL PRIMARY KEY, g POLYGON); +CREATE TABLE gis_multi_point (fid INTEGER NOT NULL PRIMARY KEY, g MULTIPOINT); +CREATE TABLE gis_multi_line (fid INTEGER NOT NULL PRIMARY KEY, g MULTILINESTRING); +CREATE TABLE gis_multi_polygon (fid INTEGER NOT NULL PRIMARY KEY, g MULTIPOLYGON); +CREATE TABLE gis_geometrycollection (fid INTEGER NOT NULL PRIMARY KEY, g GEOMETRYCOLLECTION); +CREATE TABLE gis_geometry (fid INTEGER NOT NULL PRIMARY KEY, g GEOMETRY); + +SHOW FIELDS FROM gis_point; +SHOW FIELDS FROM gis_line; +SHOW FIELDS FROM gis_polygon; +SHOW FIELDS FROM gis_multi_point; +SHOW FIELDS FROM gis_multi_line; +SHOW FIELDS FROM gis_multi_polygon; +SHOW FIELDS FROM gis_geometrycollection; +SHOW FIELDS FROM gis_geometry; + + +INSERT INTO gis_point VALUES +(101, PointFromText('POINT(10 10)')), +(102, PointFromText('POINT(20 10)')), +(103, PointFromText('POINT(20 20)')), +(104, PointFromWKB(AsWKB(PointFromText('POINT(10 20)')))); + +INSERT INTO gis_line VALUES +(105, LineFromText('LINESTRING(0 0,0 10,10 0)')), +(106, LineStringFromText('LINESTRING(10 10,20 10,20 20,10 20,10 10)')), +(107, LineStringFromWKB(AsWKB(LineString(Point(10, 10), Point(40, 10))))); + +INSERT INTO gis_polygon VALUES +(108, PolygonFromText('POLYGON((10 10,20 10,20 20,10 20,10 10))')), +(109, PolyFromText('POLYGON((0 0,50 0,50 50,0 50,0 0), (10 10,20 10,20 20,10 20,10 10))')), +(110, PolyFromWKB(AsWKB(Polygon(LineString(Point(0, 0), Point(30, 0), Point(30, 30), Point(0, 0)))))); + +INSERT INTO gis_multi_point VALUES +(111, MultiPointFromText('MULTIPOINT(0 0,10 10,10 20,20 20)')), +(112, MPointFromText('MULTIPOINT(1 1,11 11,11 21,21 21)')), +(113, MPointFromWKB(AsWKB(MultiPoint(Point(3, 6), Point(4, 10))))); + +INSERT INTO gis_multi_line VALUES +(114, MultiLineStringFromText('MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48))')), +(115, MLineFromText('MULTILINESTRING((10 48,10 21,10 0))')), +(116, MLineFromWKB(AsWKB(MultiLineString(LineString(Point(1, 2), Point(3, 5)), LineString(Point(2, 5), Point(5, 8), Point(21, 7)))))); + + +INSERT INTO gis_multi_polygon VALUES +(117, MultiPolygonFromText('MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))')), +(118, MPolyFromText('MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))')), +(119, MPolyFromWKB(AsWKB(MultiPolygon(Polygon(LineString(Point(0, 3), Point(3, 3), Point(3, 0), Point(0, 3))))))); + +INSERT INTO gis_geometrycollection VALUES +(120, GeomCollFromText('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(0 0,10 10))')), +(121, GeometryFromWKB(AsWKB(GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9)))))), +(122, GeomFromText('GeometryCollection()')), +(123, GeomFromText('GeometryCollection EMPTY')); + +INSERT into gis_geometry SELECT * FROM gis_point; +INSERT into gis_geometry SELECT * FROM gis_line; +INSERT into gis_geometry SELECT * FROM gis_polygon; +INSERT into gis_geometry SELECT * FROM gis_multi_point; +INSERT into gis_geometry SELECT * FROM gis_multi_line; +INSERT into gis_geometry SELECT * FROM gis_multi_polygon; +INSERT into gis_geometry SELECT * FROM gis_geometrycollection; + +SELECT fid, AsText(g) FROM gis_point; +SELECT fid, AsText(g) FROM gis_line; +SELECT fid, AsText(g) FROM gis_polygon; +SELECT fid, AsText(g) FROM gis_multi_point; +SELECT fid, AsText(g) FROM gis_multi_line; +SELECT fid, AsText(g) FROM gis_multi_polygon; +SELECT fid, AsText(g) FROM gis_geometrycollection; +SELECT fid, AsText(g) FROM gis_geometry; + +SELECT fid, Dimension(g) FROM gis_geometry; +SELECT fid, GeometryType(g) FROM gis_geometry; +SELECT fid, IsEmpty(g) FROM gis_geometry; +SELECT fid, AsText(Envelope(g)) FROM gis_geometry; +explain extended select Dimension(g), GeometryType(g), IsEmpty(g), AsText(Envelope(g)) from gis_geometry; + +SELECT fid, X(g) FROM gis_point; +SELECT fid, Y(g) FROM gis_point; +explain extended select X(g),Y(g) FROM gis_point; + +SELECT fid, AsText(StartPoint(g)) FROM gis_line; +SELECT fid, AsText(EndPoint(g)) FROM gis_line; +SELECT fid, GLength(g) FROM gis_line; +SELECT fid, NumPoints(g) FROM gis_line; +SELECT fid, AsText(PointN(g, 2)) FROM gis_line; +SELECT fid, IsClosed(g) FROM gis_line; +explain extended select AsText(StartPoint(g)),AsText(EndPoint(g)),GLength(g),NumPoints(g),AsText(PointN(g, 2)),IsClosed(g) FROM gis_line; + +SELECT fid, AsText(Centroid(g)) FROM gis_polygon; +SELECT fid, Area(g) FROM gis_polygon; +SELECT fid, AsText(ExteriorRing(g)) FROM gis_polygon; +SELECT fid, NumInteriorRings(g) FROM gis_polygon; +SELECT fid, AsText(InteriorRingN(g, 1)) FROM gis_polygon; +explain extended select AsText(Centroid(g)),Area(g),AsText(ExteriorRing(g)),NumInteriorRings(g),AsText(InteriorRingN(g, 1)) FROM gis_polygon; + +SELECT fid, IsClosed(g) FROM gis_multi_line; + +SELECT fid, AsText(Centroid(g)) FROM gis_multi_polygon; +SELECT fid, Area(g) FROM gis_multi_polygon; + +SELECT fid, NumGeometries(g) from gis_multi_point; +SELECT fid, NumGeometries(g) from gis_multi_line; +SELECT fid, NumGeometries(g) from gis_multi_polygon; +SELECT fid, NumGeometries(g) from gis_geometrycollection; +explain extended SELECT fid, NumGeometries(g) from gis_multi_point; + +SELECT fid, AsText(GeometryN(g, 2)) from gis_multi_point; +SELECT fid, AsText(GeometryN(g, 2)) from gis_multi_line; +SELECT fid, AsText(GeometryN(g, 2)) from gis_multi_polygon; +SELECT fid, AsText(GeometryN(g, 2)) from gis_geometrycollection; +SELECT fid, AsText(GeometryN(g, 1)) from gis_geometrycollection; +explain extended SELECT fid, AsText(GeometryN(g, 2)) from gis_multi_point; + +SELECT g1.fid as first, g2.fid as second, +Within(g1.g, g2.g) as w, Contains(g1.g, g2.g) as c, Overlaps(g1.g, g2.g) as o, +Equals(g1.g, g2.g) as e, Disjoint(g1.g, g2.g) as d, Touches(g1.g, g2.g) as t, +Intersects(g1.g, g2.g) as i, Crosses(g1.g, g2.g) as r +FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second; +explain extended SELECT g1.fid as first, g2.fid as second, +Within(g1.g, g2.g) as w, Contains(g1.g, g2.g) as c, Overlaps(g1.g, g2.g) as o, +Equals(g1.g, g2.g) as e, Disjoint(g1.g, g2.g) as d, Touches(g1.g, g2.g) as t, +Intersects(g1.g, g2.g) as i, Crosses(g1.g, g2.g) as r +FROM gis_geometrycollection g1, gis_geometrycollection g2 ORDER BY first, second; + +DROP TABLE gis_point, gis_line, gis_polygon, gis_multi_point, gis_multi_line, gis_multi_polygon, gis_geometrycollection, gis_geometry; + +# +# Check that ALTER TABLE doesn't loose geometry type +# +CREATE TABLE t1 ( + gp point, + ln linestring, + pg polygon, + mp multipoint, + mln multilinestring, + mpg multipolygon, + gc geometrycollection, + gm geometry +); + +SHOW FIELDS FROM t1; +ALTER TABLE t1 ADD fid INT NOT NULL; +SHOW FIELDS FROM t1; +DROP TABLE t1; + +SELECT AsText(GeometryFromWKB(AsWKB(GeometryFromText('POINT(1 4)')))); +explain extended SELECT AsText(GeometryFromWKB(AsWKB(GeometryFromText('POINT(1 4)')))); +explain extended SELECT AsText(GeometryFromWKB(AsWKB(PointFromText('POINT(1 4)')))); +SELECT SRID(GeomFromText('LineString(1 1,2 2)',101)); +explain extended SELECT SRID(GeomFromText('LineString(1 1,2 2)',101)); +#select issimple(MultiPoint(Point(3, 6), Point(4, 10))), issimple(Point(3, 6)),issimple(PolygonFromText('POLYGON((10 10,20 10,20 20,10 20,10 10))')),issimple(GeometryFromText('POINT(1 4)')), issimple(AsWKB(GeometryFromText('POINT(1 4)'))); +explain extended select issimple(MultiPoint(Point(3, 6), Point(4, 10))), issimple(Point(3, 6)); + +create table t1 (a geometry not null); +insert into t1 values (GeomFromText('Point(1 2)')); +-- error 1416 +insert into t1 values ('Garbage'); +-- error 1416 +insert IGNORE into t1 values ('Garbage'); +alter table t1 add spatial index(a); + +drop table t1; + +# +# Bug #5219: problem with range optimizer +# + +create table t1(a geometry not null, spatial index(a)); +insert into t1 values +(GeomFromText('POINT(1 1)')), (GeomFromText('POINT(3 3)')), +(GeomFromText('POINT(4 4)')), (GeomFromText('POINT(6 6)')); +select AsText(a) from t1 where + MBRContains(GeomFromText('Polygon((0 0, 0 2, 2 2, 2 0, 0 0))'), a) + or + MBRContains(GeomFromText('Polygon((2 2, 2 5, 5 5, 5 2, 2 2))'), a); +select AsText(a) from t1 where + MBRContains(GeomFromText('Polygon((0 0, 0 2, 2 2, 2 0, 0 0))'), a) + and + MBRContains(GeomFromText('Polygon((0 0, 0 7, 7 7, 7 0, 0 0))'), a); +drop table t1; + +CREATE TABLE t1 (Coordinates POINT NOT NULL, SPATIAL INDEX(Coordinates)); +INSERT INTO t1 VALUES(GeomFromText('POINT(383293632 1754448)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(564952612 157516260)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(903994614 180726515)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(98128178 141127631)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(862547902 799334546)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(341989013 850270906)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(803302376 93039099)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(857439153 817431356)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(319757546 343162742)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(826341972 717484432)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(305066789 201736238)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(626068992 616241497)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(55789424 755830108)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(802874458 312435220)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(153795660 551723671)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(242207428 537089292)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(553478119 807160039)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(694605552 457472733)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(987886554 792733729)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(598600363 850434457)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(592068275 940589376)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(700705362 395370650)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(33628474 558144514)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(212802006 353386020)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(901307256 39143977)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(70870451 206374045)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(240880214 696939443)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(822615542 296669638)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(452769551 625489999)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(609104858 606565210)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(177213669 851312285)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(143654501 730691787)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(658472325 838260052)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(188164520 646358878)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(630993781 786764883)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(496793334 223062055)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(727354258 197498696)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(618432704 760982731)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(755643210 831234710)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(114368751 656950466)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(870378686 185239202)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(863324511 111258900)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(882178645 685940052)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(407928538 334948195)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(311430051 17033395)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(941513405 488643719)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(868345680 85167906)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(219335507 526818004)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(923427958 407500026)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(173176882 554421738)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(194264908 669970217)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(777483793 921619165)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(867468912 395916497)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(682601897 623112122)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(227151206 796970647)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(280062588 97529892)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(982209849 143387099)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(208788792 864388493)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(829327151 616717329)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(199336688 140757201)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(633750724 140850093)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(629400920 502096404)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(226017998 848736426)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(28914408 149445955)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(256236452 202091290)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(703867693 450501360)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(872061506 481351486)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(372120524 739530418)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(877267982 54722420)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(362642540 104419188)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(851693067 642705127)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(201949080 833902916)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(786092225 410737872)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(698291409 615419376)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(27455201 897628096)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(756176576 661205925)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(38478189 385577496)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(163302328 264496186)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(234313922 192216735)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(413942141 490550373)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(394308025 117809834)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(941051732 266369530)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(599161319 313172256)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(5899948 476429301)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(367894677 368542487)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(580848489 219587743)')); +INSERT INTO t1 VALUES(GeomFromText('POINT(11247614 782797569)')); +drop table t1; + +create table t1 select GeomFromWKB(POINT(1,3)); +show create table t1; +drop table t1; + +CREATE TABLE `t1` (`object_id` bigint(20) unsigned NOT NULL default '0', `geo` +geometry NOT NULL default '') ENGINE=MyISAM ; + +insert into t1 values ('85984',GeomFromText('MULTIPOLYGON(((-115.006363 +36.305435,-114.992394 36.305202,-114.991219 36.305975,-114.991163 +36.306845,-114.989432 36.309452,-114.978275 36.312642,-114.977363 +36.311978,-114.975327 36.312344,-114.96502 36.31597,-114.963364 +36.313629,-114.961723 36.313721,-114.956398 36.316057,-114.951882 +36.320979,-114.947073 36.323475,-114.945207 36.326451,-114.945207 +36.326451,-114.944132 36.326061,-114.94003 36.326588,-114.924017 +36.334484,-114.923281 36.334146,-114.92564 36.331504,-114.94072 +36.319282,-114.945348 36.314812,-114.948091 36.314762,-114.951755 +36.316211,-114.952446 36.313883,-114.952644 36.309488,-114.944725 +36.313083,-114.93706 36.32043,-114.932478 36.323497,-114.924556 +36.327708,-114.922608 36.329715,-114.92009 36.328695,-114.912105 +36.323566,-114.901647 36.317952,-114.897436 36.313968,-114.895344 +36.309573,-114.891699 36.304398,-114.890569 36.303551,-114.886356 +36.302702,-114.885141 36.301351,-114.885709 36.297391,-114.892499 +36.290893,-114.902142 36.288974,-114.904941 36.288838,-114.905308 +36.289845,-114.906325 36.290395,-114.909916 36.289549,-114.914527 +36.287535,-114.918797 36.284423,-114.922982 36.279731,-114.924113 +36.277282,-114.924057 36.275817,-114.927733 36.27053,-114.929354 +36.269029,-114.929354 36.269029,-114.950856 36.268715,-114.950768 +36.264324,-114.960206 36.264293,-114.960301 36.268943,-115.006662 +36.268929,-115.008583 36.265619,-115.00665 36.264247,-115.006659 +36.246873,-115.006659 36.246873,-115.006838 36.247697,-115.010764 +36.247774,-115.015609 36.25113,-115.015765 36.254505,-115.029517 +36.254619,-115.038573 36.249317,-115.038573 36.249317,-115.023403 +36.25841,-115.023873 36.258994,-115.031845 36.259829,-115.03183 +36.261053,-115.025561 36.261095,-115.036417 36.274632,-115.033729 +36.276041,-115.032217 36.274851,-115.029845 36.273959,-115.029934 +36.274966,-115.025763 36.274896,-115.025406 36.281044,-115.028731 +36.284471,-115.036497 36.290377,-115.042071 36.291039,-115.026759 +36.298478,-115.008995 36.301966,-115.006363 36.305435),(-115.079835 +36.244369,-115.079735 36.260186,-115.076435 36.262369,-115.069758 +36.265,-115.070235 36.268757,-115.064542 36.268655,-115.061843 +36.269857,-115.062676 36.270693,-115.06305 36.272344,-115.059051 +36.281023,-115.05918 36.283008,-115.060591 36.285246,-115.061913 +36.290022,-115.062499 36.306353,-115.062499 36.306353,-115.060918 +36.30642,-115.06112 36.289779,-115.05713 36.2825,-115.057314 +36.279446,-115.060779 36.274659,-115.061366 36.27209,-115.057858 +36.26557,-115.055805 36.262883,-115.054688 36.262874,-115.047335 +36.25037,-115.044234 36.24637,-115.052434 36.24047,-115.061734 +36.23507,-115.061934 36.22677,-115.061934 36.22677,-115.061491 +36.225267,-115.062024 36.218194,-115.060134 36.218278,-115.060133 +36.210771,-115.057833 36.210771,-115.057433 36.196271,-115.062233 +36.196271,-115.062233 36.190371,-115.062233 36.190371,-115.065533 +36.190371,-115.071333 36.188571,-115.098331 36.188275,-115.098331 +36.188275,-115.098435 36.237569,-115.097535 36.240369,-115.097535 +36.240369,-115.093235 36.240369,-115.089135 36.240469,-115.083135 +36.240569,-115.083135 36.240569,-115.079835 +36.244369)))')),('85998',GeomFromText('MULTIPOLYGON(((-115.333107 +36.264587,-115.333168 36.280638,-115.333168 36.280638,-115.32226 +36.280643,-115.322538 36.274311,-115.327222 36.274258,-115.32733 +36.263026,-115.330675 36.262984,-115.332132 36.264673,-115.333107 +36.264587),(-115.247239 36.247066,-115.247438 36.218267,-115.247438 +36.218267,-115.278525 36.219263,-115.278525 36.219263,-115.301545 +36.219559,-115.332748 36.219197,-115.332757 36.220041,-115.332757 +36.220041,-115.332895 36.233514,-115.349023 36.233479,-115.351489 +36.234475,-115.353681 36.237021,-115.357106 36.239789,-115.36519 +36.243331,-115.368156 36.243487,-115.367389 36.244902,-115.364553 +36.246014,-115.359219 36.24616,-115.356186 36.248025,-115.353347 +36.248004,-115.350813 36.249507,-115.339673 36.25387,-115.333069 +36.255018,-115.333069 36.255018,-115.333042 36.247767,-115.279039 +36.248666,-115.263639 36.247466,-115.263839 36.252766,-115.261439 +36.252666,-115.261439 36.247366,-115.247239 36.247066)))')); + +# Expected results are 115.2970604672862 and 36.23335610879993, but IA64 returns +# slightly different values due to fused multiply-add instructions. +--replace_result 115.29706047613604 115.2970604672862 36.23335611157958 36.23335610879993 +select object_id, geometrytype(geo), ISSIMPLE(GEO), ASTEXT(centroid(geo)) from +t1 where object_id=85998; + +# Expected result is 36.34725218253213, but IA64 returns 36.34725217627852 +# due to fused multiply-add instructions. +--replace_result 36.34725217627852 36.34725218253213 -114.86854470090232 -114.86854472054372 +select object_id, geometrytype(geo), ISSIMPLE(GEO), ASTEXT(centroid(geo)) from +t1 where object_id=85984; + +drop table t1; + +create table t1 (fl geometry not null); +--error 1416 +insert into t1 values (1); +--error 1416 +insert into t1 values (1.11); +--error 1416 +insert into t1 values ("qwerty"); +--error 1048 +insert into t1 values (pointfromtext('point(1,1)')); + +drop table t1; + +select (asWKT(geomfromwkb((0x000000000140240000000000004024000000000000)))); +select (asWKT(geomfromwkb((0x010100000000000000000024400000000000002440)))); + +--enable_metadata +create table t1 (g GEOMETRY); +select * from t1; +select asbinary(g) from t1; +--disable_metadata +drop table t1; + +create table t1 (a TEXT, b GEOMETRY NOT NULL, SPATIAL KEY(b)); +alter table t1 disable keys; +--error 1263 +load data infile '../../std_data/bad_gis_data.dat' into table t1; +alter table t1 enable keys; +drop table t1; + +# +# Bug #26038: is null and bad data +# + +create table t1 (a int, b blob); +insert into t1 values (1, ''), (2, NULL), (3, '1'); +select * from t1; + +--error ER_ILLEGAL_VALUE_FOR_TYPE +select + geometryfromtext(b) IS NULL, geometryfromwkb(b) IS NULL, astext(b) IS NULL, + aswkb(b) IS NULL, geometrytype(b) IS NULL, centroid(b) IS NULL, + envelope(b) IS NULL, startpoint(b) IS NULL, endpoint(b) IS NULL, + exteriorring(b) IS NULL, pointn(b, 1) IS NULL, geometryn(b, 1) IS NULL, + interiorringn(b, 1) IS NULL, multipoint(b) IS NULL, isempty(b) IS NULL, + issimple(b) IS NULL, isclosed(b) IS NULL, dimension(b) IS NULL, + numgeometries(b) IS NULL, numinteriorrings(b) IS NULL, numpoints(b) IS NULL, + area(b) IS NULL, glength(b) IS NULL, srid(b) IS NULL, x(b) IS NULL, + y(b) IS NULL +from t1; + +select + within(b, b) IS NULL, contains(b, b) IS NULL, overlaps(b, b) IS NULL, + equals(b, b) IS NULL, disjoint(b, b) IS NULL, touches(b, b) IS NULL, + intersects(b, b) IS NULL, crosses(b, b) IS NULL +from t1; + +--error ER_ILLEGAL_VALUE_FOR_TYPE +select + point(b, b) IS NULL, linestring(b) IS NULL, polygon(b) IS NULL, multipoint(b) IS NULL, + multilinestring(b) IS NULL, multipolygon(b) IS NULL, + geometrycollection(b) IS NULL +from t1; + +drop table t1; + +# +# Bug #27164: Crash when mixing InnoDB and MyISAM Geospatial tables +# +CREATE TABLE t1(a POINT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (NULL); +SELECT * FROM t1; +DROP TABLE t1; + +# +# Bug #30955 geomfromtext() crasher +# +CREATE TABLE `t1` ( `col9` set('a'), `col89` date); +INSERT INTO `t1` VALUES ('','0000-00-00'); +select geomfromtext(col9,col89) as a from t1; +DROP TABLE t1; + +# +# Bug #31158 Spatial, Union, LONGBLOB vs BLOB bug (crops data) +# + +CREATE TABLE t1 ( + geomdata polygon NOT NULL, + SPATIAL KEY index_geom (geomdata) +) ENGINE=MyISAM DEFAULT CHARSET=latin2 DELAY_KEY_WRITE=1 ROW_FORMAT=FIXED; + +CREATE TABLE t2 ( + geomdata polygon NOT NULL, + SPATIAL KEY index_geom (geomdata) +) ENGINE=MyISAM DEFAULT CHARSET=latin2 DELAY_KEY_WRITE=1 ROW_FORMAT=FIXED; + +CREATE TABLE t3 +select + aswkb(ws.geomdata) AS geomdatawkb + from + t1 ws +union + select + aswkb(ws.geomdata) AS geomdatawkb + from + t2 ws; + +describe t3; + +drop table t1; +drop table t2; +drop table t3; + +# +# Bug #30284 spatial key corruption +# + +create table t1(col1 geometry default null,col15 geometrycollection not +null,spatial index(col15),index(col1(15)))engine=myisam; +insert into t1 set col15 = GeomFromText('POINT(6 5)'); +insert into t1 set col15 = GeomFromText('POINT(6 5)'); +check table t1 extended; +drop table t1; + +--echo End of 4.1 tests + +# +# Bug #12281 (Geometry: crash in trigger) +# + +create table t1 (s1 geometry not null,s2 char(100)); +create trigger t1_bu before update on t1 for each row set new.s1 = null; +--error 1048 +insert into t1 values (null,null); +drop table t1; + +# +# Bug #10499 (function creation with GEOMETRY datatype) +# +--disable_warnings +drop procedure if exists fn3; +--enable_warnings +create function fn3 () returns point deterministic return GeomFromText("point(1 1)"); +show create function fn3; +select astext(fn3()); +drop function fn3; + +# +# Bug #12267 (primary key over GIS) +# +create table t1(pt POINT); +alter table t1 add primary key pti(pt); +drop table t1; +create table t1(pt GEOMETRY); +--error 1170 +alter table t1 add primary key pti(pt); +alter table t1 add primary key pti(pt(20)); +drop table t1; + + +create table t1 select GeomFromText('point(1 1)'); +desc t1; +drop table t1; + +# +# Bug #20691 (DEFAULT over NOT NULL field) +# +create table t1 (g geometry not null); +--error ER_CANT_CREATE_GEOMETRY_OBJECT +insert into t1 values(default); +drop table t1; + +# +# Bug #27300: create view with geometry functions lost columns types +# +CREATE TABLE t1 (a GEOMETRY); +CREATE VIEW v1 AS SELECT GeomFromwkb(ASBINARY(a)) FROM t1; +CREATE VIEW v2 AS SELECT a FROM t1; +DESCRIBE v1; +DESCRIBE v2; + +DROP VIEW v1,v2; +DROP TABLE t1; + +# +# Bug#24563: MBROverlaps does not seem to function propertly +# Bug#54888: MBROverlaps missing in 5.1? +# + +# Test all MBR* functions and their non-MBR-prefixed aliases, +# using shifted squares to verify the spatial relations. + +create table t1 (name VARCHAR(100), square GEOMETRY); + +INSERT INTO t1 VALUES("center", GeomFromText('POLYGON (( 0 0, 0 2, 2 2, 2 0, 0 0))')); + +INSERT INTO t1 VALUES("small", GeomFromText('POLYGON (( 0 0, 0 1, 1 1, 1 0, 0 0))')); +INSERT INTO t1 VALUES("big", GeomFromText('POLYGON (( 0 0, 0 3, 3 3, 3 0, 0 0))')); + +INSERT INTO t1 VALUES("up", GeomFromText('POLYGON (( 0 1, 0 3, 2 3, 2 1, 0 1))')); +INSERT INTO t1 VALUES("up2", GeomFromText('POLYGON (( 0 2, 0 4, 2 4, 2 2, 0 2))')); +INSERT INTO t1 VALUES("up3", GeomFromText('POLYGON (( 0 3, 0 5, 2 5, 2 3, 0 3))')); + +INSERT INTO t1 VALUES("down", GeomFromText('POLYGON (( 0 -1, 0 1, 2 1, 2 -1, 0 -1))')); +INSERT INTO t1 VALUES("down2", GeomFromText('POLYGON (( 0 -2, 0 0, 2 0, 2 -2, 0 -2))')); +INSERT INTO t1 VALUES("down3", GeomFromText('POLYGON (( 0 -3, 0 -1, 2 -1, 2 -3, 0 -3))')); + +INSERT INTO t1 VALUES("right", GeomFromText('POLYGON (( 1 0, 1 2, 3 2, 3 0, 1 0))')); +INSERT INTO t1 VALUES("right2", GeomFromText('POLYGON (( 2 0, 2 2, 4 2, 4 0, 2 0))')); +INSERT INTO t1 VALUES("right3", GeomFromText('POLYGON (( 3 0, 3 2, 5 2, 5 0, 3 0))')); + +INSERT INTO t1 VALUES("left", GeomFromText('POLYGON (( -1 0, -1 2, 1 2, 1 0, -1 0))')); +INSERT INTO t1 VALUES("left2", GeomFromText('POLYGON (( -2 0, -2 2, 0 2, 0 0, -2 0))')); +INSERT INTO t1 VALUES("left3", GeomFromText('POLYGON (( -3 0, -3 2, -1 2, -1 0, -3 0))')); + +SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrcontains FROM t1 a1 JOIN t1 a2 ON MBRContains( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; +SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrdisjoint FROM t1 a1 JOIN t1 a2 ON MBRDisjoint( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; +SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrequal FROM t1 a1 JOIN t1 a2 ON MBREqual( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; +SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrintersect FROM t1 a1 JOIN t1 a2 ON MBRIntersects( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; +SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbroverlaps FROM t1 a1 JOIN t1 a2 ON MBROverlaps( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; +SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrtouches FROM t1 a1 JOIN t1 a2 ON MBRTouches( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; +SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS mbrwithin FROM t1 a1 JOIN t1 a2 ON MBRWithin( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; + +SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS contains FROM t1 a1 JOIN t1 a2 ON Contains( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; +SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS disjoint FROM t1 a1 JOIN t1 a2 ON Disjoint( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; +SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS equals FROM t1 a1 JOIN t1 a2 ON Equals( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; +SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS intersects FROM t1 a1 JOIN t1 a2 ON Intersects( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; +SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS overlaps FROM t1 a1 JOIN t1 a2 ON Overlaps( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; +SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS touches FROM t1 a1 JOIN t1 a2 ON Touches( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; +SELECT GROUP_CONCAT(a2.name ORDER BY a2.name) AS within FROM t1 a1 JOIN t1 a2 ON Within( a1.square, a2.square) WHERE a1.name = "center" GROUP BY a1.name; + +# Overlaps needs a few more tests, with point and line dimensions + +SET @vert1 = GeomFromText('POLYGON ((0 -2, 0 2, 0 -2))'); +SET @horiz1 = GeomFromText('POLYGON ((-2 0, 2 0, -2 0))'); +SET @horiz2 = GeomFromText('POLYGON ((-1 0, 3 0, -1 0))'); +SET @horiz3 = GeomFromText('POLYGON ((2 0, 3 0, 2 0))'); +SET @point1 = GeomFromText('POLYGON ((0 0))'); +SET @point2 = GeomFromText('POLYGON ((-2 0))'); + +SELECT GROUP_CONCAT(a1.name ORDER BY a1.name) AS overlaps FROM t1 a1 WHERE Overlaps(a1.square, @vert1) GROUP BY a1.name; +SELECT GROUP_CONCAT(a1.name ORDER BY a1.name) AS overlaps FROM t1 a1 WHERE Overlaps(a1.square, @horiz1) GROUP BY a1.name; +SELECT Overlaps(@horiz1, @vert1) FROM DUAL; +SELECT Overlaps(@horiz1, @horiz2) FROM DUAL; +SELECT Overlaps(@horiz1, @horiz3) FROM DUAL; +SELECT Overlaps(@horiz1, @point1) FROM DUAL; +SELECT Overlaps(@horiz1, @point2) FROM DUAL; + +DROP TABLE t1; + +# +# Bug#28763: Selecting geometry fields in UNION caused server crash. +# +create table t1(f1 geometry, f2 linestring, f3 linestring); +select f1 from t1 union select f1 from t1; +insert into t1 (f2,f3) values (GeomFromText('LINESTRING(1 1, 2 2)'), + GeomFromText('LINESTRING(0 0,1 1,2 2)')); +select AsText(f2),AsText(f3) from t1; +select AsText(a) from (select f2 as a from t1 union select f3 from t1) t; +create table t2 as select f2 as a from t1 union select f3 from t1; +desc t2; +select AsText(a) from t2; +drop table t1, t2; + +# +# Bug #29166: MYsql crash when query is run +# + +# The test query itself is not logged : too large output. +# The real test is the second query : see if the first hasn't crashed the +# server +--disable_query_log +--disable_result_log +SELECT AsText(GeometryFromText(CONCAT( + 'MULTIPOLYGON(((', + REPEAT ('-0.00000000001234567890123456789012 -0.123456789012345678,', 1000), + '-0.00000000001234567890123456789012 -0.123456789012345678', + ')))' +))) AS a; +--enable_result_log +--enable_query_log +SELECT 1; + +-- source include/gis_keys.inc + +# +# Bug #31155 gis types in union'd select cause crash +# + +create table `t1` (`col002` point)engine=myisam; +insert into t1 values (),(),(); +select min(`col002`) from t1 union select `col002` from t1; +drop table t1; + +--echo # +--echo # Bug #47780: crash when comparing GIS items from subquery +--echo # + +CREATE TABLE t1(a INT, b MULTIPOLYGON); +INSERT INTO t1 VALUES + (0, + GEOMFROMTEXT( + 'multipolygon(((1 2,3 4,5 6,7 8,9 8),(7 6,5 4,3 2,1 2,3 4)))')); + +--echo # must not crash +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 FROM t1 WHERE a <> (SELECT GEOMETRYCOLLECTIONFROMWKB(b) FROM t1); + +DROP TABLE t1; + +--echo # +--echo # Bug #49250 : spatial btree index corruption and crash +--echo # Part one : spatial syntax check +--echo # + +--error ER_PARSE_ERROR +CREATE TABLE t1(col1 MULTIPOLYGON NOT NULL, + SPATIAL INDEX USING BTREE (col1)); +CREATE TABLE t2(col1 MULTIPOLYGON NOT NULL); +--error ER_PARSE_ERROR +CREATE SPATIAL INDEX USING BTREE ON t2(col); +--error ER_PARSE_ERROR +ALTER TABLE t2 ADD SPATIAL INDEX USING BTREE (col1); + +DROP TABLE t2; + +--echo End of 5.0 tests + + +# +# Bug #11335 View redefines column types +# +create table t1 (f1 tinyint(1), f2 char(1), f3 varchar(1), f4 geometry, f5 datetime); +create view v1 as select * from t1; +desc v1; +drop view v1; +drop table t1; + +# +# Bug#44684: valgrind reports invalid reads in +# Item_func_spatial_collection::val_str +# +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT MultiPoint(12345,''); +#SELECT MultiPoint(123451,''); +#SELECT MultiPoint(1234512,''); +#SELECT MultiPoint(12345123,''); + +--error ER_ILLEGAL_VALUE_FOR_TYPE +#SELECT MultiLineString(12345,''); +#SELECT MultiLineString(123451,''); +#SELECT MultiLineString(1234512,''); +#SELECT MultiLineString(12345123,''); + +--error ER_ILLEGAL_VALUE_FOR_TYPE +#SELECT LineString(12345,''); +#SELECT LineString(123451,''); +#SELECT LineString(1234512,''); +#SELECT LineString(12345123,''); + +--error ER_ILLEGAL_VALUE_FOR_TYPE +#SELECT Polygon(12345,''); +#SELECT Polygon(123451,''); +#SELECT Polygon(1234512,''); +#SELECT Polygon(12345123,''); + +# +# Bug55531 crash with conversions of geometry types / strings +# +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT 1 FROM (SELECT GREATEST(1,GEOMETRYCOLLECTION('00000','00000')) b FROM DUAL) AS d WHERE (LINESTRING(d.b)); + + +--echo # +--echo # BUG#51875: crash when loading data into geometry function polyfromwkb +--echo # +SET @a=0x00000000030000000100000000000000000000000000144000000000000014400000000000001840000000000000184000000000000014400000000000001440; +SET @a=POLYFROMWKB(@a); +SET @a=0x00000000030000000000000000000000000000000000144000000000000014400000000000001840000000000000184000000000000014400000000000001440; +SET @a=POLYFROMWKB(@a); + + +# +# Bug #57321 crashes and valgrind errors from spatial types +# + +create table t1(a geometry NOT NULL)engine=myisam; +insert into t1 values (geomfromtext("point(0 1)")); +insert into t1 values (geomfromtext("point(1 0)")); +select * from (select polygon(t1.a) as p from t1 order by t1.a) d; +drop table t1; + + +--echo # +--echo # Test for bug #59888 "debug assertion when attempt to create spatial index +--echo # on char > 31 bytes". +--echo # +create table t1(a char(32) not null) engine=myisam; - --replace_regex /'[^']*test\.#sql-[0-9a-f_]*'/'#sql-temporary'/ +--error ER_WRONG_ARGUMENTS +create spatial index i on t1 (a); +drop table t1; + + +# +# Bug#11767480 - SPATIAL INDEXES ON NON-SPATIAL COLUMNS CAUSE CRASHES. +# +CREATE TABLE t0 (a BINARY(32) NOT NULL); +--error ER_WRONG_ARGUMENTS +CREATE SPATIAL INDEX i on t0 (a); +INSERT INTO t0 VALUES (1); + +--error ER_WRONG_ARGUMENTS +CREATE TABLE t1( + col0 BINARY NOT NULL, + col2 TIMESTAMP, + SPATIAL INDEX i1 (col0) +) ENGINE=MyISAM; + +# Test other ways to add indices +CREATE TABLE t1 ( + col0 BINARY NOT NULL, + col2 TIMESTAMP +) ENGINE=MyISAM; + +--error ER_WRONG_ARGUMENTS +CREATE SPATIAL INDEX idx0 ON t1(col0); + +--error ER_WRONG_ARGUMENTS +ALTER TABLE t1 ADD SPATIAL INDEX i1 (col0); + +CREATE TABLE t2 ( + col0 INTEGER NOT NULL, + col1 POINT, + col2 POINT +); + +--error ER_WRONG_ARGUMENTS +CREATE SPATIAL INDEX idx0 ON t2 (col1, col2); + +--error ER_WRONG_ARGUMENTS +CREATE TABLE t3 ( + col0 INTEGER NOT NULL, + col1 POINT, + col2 LINESTRING, + SPATIAL INDEX i1 (col1, col2) +); + +# cleanup +DROP TABLE t0, t1, t2; + + +--echo # +--echo # BUG#12414917 - ISCLOSED() CRASHES ON 64-BIT BUILDS +--echo # +SELECT ISCLOSED(CONVERT(CONCAT(' ', 0x2), BINARY(20))); + +--echo # +--echo # BUG#12537203 - CRASH WHEN SUBSELECTING GLOBAL VARIABLES IN +--echo # GEOMETRY FUNCTION ARGUMENTS +--echo # +--replace_regex /non geometric .* value/non geometric '' value/ +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT GEOMETRYCOLLECTION((SELECT @@OLD)); + +--echo # +--echo # MDEV-4252 geometry query crashes server +--echo # +select astext(0x0100000000030000000100000000000010); +select astext(st_centroid(0x0100000000030000000100000000000010)); +select astext(st_exteriorring(0x0100000000030000000100000000000010)); +select envelope(0x0100000000030000000100000000000010); +select geometryn(0x0100000000070000000100000001030000000200000000000000ffff0000, 1); +select geometryn(0x0100000000070000000100000001030000000200000000000000ffffff0f, 1); + +--echo # +--echo # MDEV-4296 Assertion `n_linear_rings > 0' fails in Gis_polygon::centroid_xy +--echo # + +SELECT Centroid( AsBinary( LineString(Point(0,0), Point(0,0), Point(0,0) ))); + +--echo # +--echo # MDEV-4295 Server crashes in get_point on a query with Area, AsBinary, MultiPoint +--echo # +SELECT Area(AsBinary(MultiPoint(Point(0,9), Point(0,1), Point(2,2)))); +--echo End of 5.1 tests + +#bug 850775 ST_AREA does not work on GEOMETRYCOLLECTIONs in maria-5.3-gis +select ST_AREA(ST_GEOMCOLLFROMTEXT(' GEOMETRYCOLLECTION(LINESTRING(100 100, 31 10, 77 80), POLYGON((0 0,4 7,1 1,0 0)), POINT(20 20))')); + +#bug 855336 ST_LENGTH does not work on GEOMETRYCOLLECTIONs +select ST_LENGTH(ST_GEOMCOLLFROMTEXT(' GEOMETRYCOLLECTION(LINESTRING(100 100, 100 30, 20 30), POINT(3 3), LINESTRING(20 20, 30 20))')); + + +# Conformance tests +# +# C.3.3 Geometry types and functions +# + +--disable_warnings +DROP DATABASE IF EXISTS gis_ogs; +--enable_warnings + +CREATE DATABASE gis_ogs; +USE gis_ogs; + +--echo # +--echo # C.3.3.1 Geometry types and functions schema construction +--echo # + +# TODO: WL#2377 +#CREATE TABLE spatial_ref_sys ( +#srid INTEGER NOT NULL PRIMARY KEY, +#auth_name CHARACTER VARYING, +#auth_srid INTEGER, +#srtext CHARACTER VARYING(2048)); + +CREATE TABLE lakes ( + fid INTEGER NOT NULL PRIMARY KEY, + name CHARACTER VARYING(64), + shore POLYGON); + +CREATE TABLE road_segments ( + fid INTEGER NOT NULL PRIMARY KEY, + name CHARACTER VARYING(64), + aliases CHARACTER VARYING(64), + num_lanes INTEGER, + centerline LINESTRING); + +CREATE TABLE divided_routes ( + fid INTEGER NOT NULL PRIMARY KEY, + name CHARACTER VARYING(64), + num_lanes INTEGER, + centerlines MULTILINESTRING); + +CREATE TABLE forests ( + fid INTEGER NOT NULL PRIMARY KEY, + name CHARACTER VARYING(64), + boundary MULTIPOLYGON); + +CREATE TABLE bridges ( + fid INTEGER NOT NULL PRIMARY KEY, + name CHARACTER VARYING(64), + position POINT); + +CREATE TABLE streams ( + fid INTEGER NOT NULL PRIMARY KEY, + name CHARACTER VARYING(64), + centerline LINESTRING); + +CREATE TABLE buildings ( + fid INTEGER NOT NULL PRIMARY KEY, + address CHARACTER VARYING(64), + position POINT, + footprint POLYGON); + +CREATE TABLE ponds ( + fid INTEGER NOT NULL PRIMARY KEY, + name CHARACTER VARYING(64), + type CHARACTER VARYING(64), + shores MULTIPOLYGON); + +CREATE TABLE named_places ( + fid INTEGER NOT NULL PRIMARY KEY, + name CHARACTER VARYING(64), + boundary POLYGON); + +CREATE TABLE map_neatlines ( + fid INTEGER NOT NULL PRIMARY KEY, + neatline POLYGON); + +--echo # +--echo # C.3.3.2 Geometry types and functions schema data loading +--echo # + +# TODO: WL#2377 +#-- Spatial Reference System +#INSERT INTO spatial_ref_sys VALUES +#(101, 'POSC', 32214, 'PROJCS["UTM_ZONE_14N", +#GEOGCS["World Geodetic System 72", +#DATUM["WGS_72", +#ELLIPSOID["NWL_10D", 6378135, 298.26]], +#PRIMEM["Greenwich", 0], +#UNIT["Meter", 1.0]], +#PROJECTION["Transverse_Mercator"], +#PARAMETER["False_Easting", 500000.0], +#PARAMETER["False_Northing", 0.0], +#PARAMETER["Central_Meridian", -99.0], +#PARAMETER["Scale_Factor", 0.9996], +#PARAMETER["Latitude_of_origin", 0.0], +#UNIT["Meter", 1.0]]'); + +--echo # Lakes +INSERT INTO lakes VALUES ( +101, 'BLUE LAKE', +PolyFromText( +'POLYGON( +(52 18,66 23,73 9,48 6,52 18), +(59 18,67 18,67 13,59 13,59 18) +)', +101)); + + +--echo # Road Segments + +INSERT INTO road_segments VALUES(102, 'Route 5', NULL, 2, +LineFromText( +'LINESTRING( 0 18, 10 21, 16 23, 28 26, 44 31 )' ,101)); + +INSERT INTO road_segments VALUES(103, 'Route 5', 'Main Street', 4, +LineFromText( +'LINESTRING( 44 31, 56 34, 70 38 )' ,101)); + +INSERT INTO road_segments VALUES(104, 'Route 5', NULL, 2, +LineFromText( +'LINESTRING( 70 38, 72 48 )' ,101)); + +INSERT INTO road_segments VALUES(105, 'Main Street', NULL, 4, +LineFromText( +'LINESTRING( 70 38, 84 42 )' ,101)); + +INSERT INTO road_segments VALUES(106, 'Dirt Road by Green Forest', NULL, +1, +LineFromText( +'LINESTRING( 28 26, 28 0 )',101)); + +--echo # DividedRoutes + +INSERT INTO divided_routes VALUES(119, 'Route 75', 4, +MLineFromText( +'MULTILINESTRING((10 48,10 21,10 0), +(16 0,16 23,16 48))', 101)); + +--echo # Forests + +INSERT INTO forests VALUES(109, 'Green Forest', +MPolyFromText( +'MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26), +(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))', +101)); + +--echo # Bridges + +INSERT INTO bridges VALUES(110, 'Cam Bridge', PointFromText( +'POINT( 44 31 )', 101)); + +--echo # Streams + +INSERT INTO streams VALUES(111, 'Cam Stream', +LineFromText( +'LINESTRING( 38 48, 44 41, 41 36, 44 31, 52 18 )', 101)); + +INSERT INTO streams VALUES(112, NULL, +LineFromText( +'LINESTRING( 76 0, 78 4, 73 9 )', 101)); + +--echo # Buildings + +INSERT INTO buildings VALUES(113, '123 Main Street', +PointFromText( +'POINT( 52 30 )', 101), +PolyFromText( +'POLYGON( ( 50 31, 54 31, 54 29, 50 29, 50 31) )', 101)); + +INSERT INTO buildings VALUES(114, '215 Main Street', +PointFromText( +'POINT( 64 33 )', 101), +PolyFromText( +'POLYGON( ( 66 34, 62 34, 62 32, 66 32, 66 34) )', 101)); + + +--echo # Ponds + +INSERT INTO ponds VALUES(120, NULL, 'Stock Pond', +MPolyFromText( +'MULTIPOLYGON( ( ( 24 44, 22 42, 24 40, 24 44) ), +( ( 26 44, 26 40, 28 42, 26 44) ) )', 101)); + +--echo # Named Places + +INSERT INTO named_places VALUES(117, 'Ashton', +PolyFromText( +'POLYGON( ( 62 48, 84 48, 84 30, 56 30, 56 34, 62 48) )', 101)); + +INSERT INTO named_places VALUES(118, 'Goose Island', +PolyFromText( +'POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )', 101)); + +--echo # Map Neatlines + +INSERT INTO map_neatlines VALUES(115, +PolyFromText( +'POLYGON( ( 0 0, 0 48, 84 48, 84 0, 0 0 ) )', 101)); + +--echo # +--echo # C.3.3.3 Geometry types and functions schema test queries +--echo + +# TODO: WL#2377 +#--echo # Conformance Item T1 +#SELECT f_table_name +#FROM geometry_columns; +# +#--echo # Conformance Item T2 +#SELECT f_geometry_column +#FROM geometry_columns +#WHERE f_table_name = 'streams'; +# +#--echo # Conformance Item T3 +#SELECT coord_dimension +#FROM geometry_columns +#WHERE f_table_name = 'streams'; +# +#--echo # Conformance Item T4 +# +#SELECT srid +#FROM geometry_columns +#WHERE f_table_name = 'streams'; +# +#--echo # Conformance Item T5 +# +#SELECT srtext +#FROM SPATIAL_REF_SYS +#WHERE SRID = 101; +# + + +--echo # Conformance Item T6 +# TODO: ST_Dimension() alias +SELECT Dimension(shore) +FROM lakes +WHERE name = 'Blue Lake'; + +--echo # Conformance Item T7 +# TODO: ST_GeometryType() alias +SELECT GeometryType(centerlines) +FROM divided_routes +WHERE name = 'Route 75'; + +--echo # Conformance Item T8 +# TODO: ST_AsText() alias +SELECT AsText(boundary) +FROM named_places +WHERE name = 'Goose Island'; + +--echo # Conformance Item T9 +# TODO: ST_AsBinary(), ST_PolyFromWKB() aliases +SELECT AsText(PolyFromWKB(AsBinary(boundary),101)) +FROM named_places +WHERE name = 'Goose Island'; + +--echo # Conformance Item T10 +SELECT SRID(boundary) +FROM named_places +WHERE name = 'Goose Island'; + +--echo # Conformance Item T11 +SELECT IsEmpty(centerline) +FROM road_segments +WHERE name = 'Route 5' +AND aliases = 'Main Street'; + +--echo # Conformance Item T12 +SELECT IsSimple(shore) +FROM lakes +WHERE name = 'Blue Lake'; + +--echo # Conformance Item T13 +SELECT AsText(ST_Boundary(boundary)) +FROM named_places +WHERE name = 'Goose Island'; + +--echo # Conformance Item T14 +# FIXME: we get anticlockwise, GIS suggests clockwise +SELECT AsText(Envelope(boundary)) +FROM named_places +WHERE name = 'Goose Island'; + +--echo # Conformance Item T15 +# TODO: ST_X() alias +SELECT X(position) +FROM bridges +WHERE name = 'Cam Bridge'; + +--echo # Conformance Item T16 +# TODO: ST_Y() alias +SELECT Y(position) +FROM bridges +WHERE name = 'Cam Bridge'; + +--echo # Conformance Item T17 +# TODO: ST_StartPoint() alias +SELECT AsText(StartPoint(centerline)) +FROM road_segments +WHERE fid = 102; + +--echo # Conformance Item T18 +SELECT AsText(EndPoint(centerline)) +FROM road_segments +WHERE fid = 102; + +SELECT IsClosed(LineFromWKB(AsBinary(Boundary(boundary)),SRID(boundary))) +FROM named_places +WHERE name = 'Goose Island'; + +--echo # Conformance Item T20 +SELECT IsRing(LineFromWKB(AsBinary(Boundary(boundary)),SRID(boundary))) +FROM named_places +WHERE name = 'Goose Island'; + +--echo # Conformance Item T21 +SELECT GLength(centerline) +FROM road_segments +WHERE fid = 106; + +--echo # Conformance Item T22 +SELECT NumPoints(centerline) +FROM road_segments +WHERE fid = 102; + +--echo # Conformance Item T23 +SELECT AsText(PointN(centerline, 1)) +FROM road_segments +WHERE fid = 102; + +--echo # Conformance Item T24 +SELECT AsText(Centroid(boundary)) +FROM named_places +WHERE name = 'Goose Island'; + +SELECT ST_Contains(boundary, PointOnSurface(boundary)) +FROM named_places +WHERE name = 'Goose Island'; + +--echo # Conformance Item T26 +SELECT Area(boundary) +FROM named_places +WHERE name = 'Goose Island'; + +--echo # Conformance Item T27 +SELECT AsText(ExteriorRing(shore)) +FROM lakes +WHERE name = 'Blue Lake'; + +--echo # Conformance Item T28 +SELECT NumInteriorRings(shore) +FROM lakes +WHERE name = 'Blue Lake'; + +--echo # Conformance Item T29 +SELECT AsText(InteriorRingN(shore, 1)) +FROM lakes +WHERE name = 'Blue Lake'; + +--echo # Conformance Item T30 +SELECT NumGeometries(centerlines) +FROM divided_routes +WHERE name = 'Route 75'; + +--echo # Conformance Item T31 +SELECT AsText(GeometryN(centerlines, 2)) +FROM divided_routes +WHERE name = 'Route 75'; + +--echo # Conformance Item T32 +SELECT IsClosed(centerlines) +FROM divided_routes +WHERE name = 'Route 75'; + +--echo # Conformance Item T33 +SELECT GLength(centerlines) +FROM divided_routes +WHERE name = 'Route 75'; + +--echo # Conformance Item T34 +SELECT AsText(Centroid(shores)) +FROM ponds +WHERE fid = 120; + +# TODO: WL#2377 +--echo # Conformance Item T35 +SELECT Contains(shores, PointOnSurface(shores)) +FROM ponds +WHERE fid = 120; + +--echo # Conformance Item T36 +SELECT Area(shores) +FROM ponds +WHERE fid = 120; + +--echo # Conformance Item T37 +SELECT ST_Equals(boundary, +PolyFromText('POLYGON( ( 67 13, 67 18, 59 18, 59 13, 67 13) )',1)) +FROM named_places +WHERE name = 'Goose Island'; + +--echo # Conformance Item T38 +SELECT ST_Disjoint(centerlines, boundary) +FROM divided_routes, named_places +WHERE divided_routes.name = 'Route 75' +AND named_places.name = 'Ashton'; + +--echo # Conformance Item T39 +SELECT ST_Touches(centerline, shore) +FROM streams, lakes +WHERE streams.name = 'Cam Stream' +AND lakes.name = 'Blue Lake'; + +--echo # Conformance Item T40 +SELECT ST_Within(footprint, boundary) +FROM named_places, buildings +WHERE named_places.name = 'Ashton' +AND buildings.address = '215 Main Street'; + +--echo # Conformance Item T41 +SELECT ST_Overlaps(forests.boundary, named_places.boundary) +FROM forests, named_places +WHERE forests.name = 'Green Forest' +AND named_places.name = 'Ashton'; + +--echo # Conformance Item T42 +SELECT Crosses(road_segments.centerline, divided_routes.centerlines) +FROM road_segments, divided_routes +WHERE road_segments.fid = 102 +AND divided_routes.name = 'Route 75'; + +--echo # Conformance Item T43 +SELECT ST_Intersects(road_segments.centerline, divided_routes.centerlines) +FROM road_segments, divided_routes +WHERE road_segments.fid = 102 +AND divided_routes.name = 'Route 75'; + +--echo # Conformance Item T44 +SELECT ST_Contains(forests.boundary, named_places.boundary) +FROM forests, named_places +WHERE forests.name = 'Green Forest' +AND named_places.name = 'Ashton'; + +--echo # Conformance Item T45 +SELECT ST_Relate(forests.boundary, named_places.boundary, 'TTTTTTTTT') +FROM forests, named_places +WHERE forests.name = 'Green Forest' +AND named_places.name = 'Ashton'; + +--echo # Conformance Item T46 +SELECT ST_Distance(position, boundary) +FROM bridges, named_places +WHERE bridges.name = 'Cam Bridge' +AND named_places.name = 'Ashton'; + +--echo # Conformance Item T47 +SELECT AsText(ST_Intersection(centerline, shore)) +FROM streams, lakes +WHERE streams.name = 'Cam Stream' +AND lakes.name = 'Blue Lake'; + +--echo # Conformance Item T48 +SELECT AsText(ST_Difference(named_places.boundary, forests.boundary)) +FROM named_places, forests +WHERE named_places.name = 'Ashton' +AND forests.name = 'Green Forest'; + +#--echo # Conformance Item T49 +SELECT AsText(ST_Union(shore, boundary)) +FROM lakes, named_places +WHERE lakes.name = 'Blue Lake' +AND named_places.name = 'Goose Island'; + +--echo # Conformance Item T50 +SELECT AsText(ST_SymDifference(shore, boundary)) +FROM lakes, named_places +WHERE lakes.name = 'Blue Lake' +AND named_places.name = 'Ashton'; + +--echo # Conformance Item T51 +SELECT count(*) +FROM buildings, bridges +WHERE ST_Contains(ST_Buffer(bridges.position, 15.0), buildings.footprint) = 1; + +--echo # Conformance Item T52 +SELECT AsText(ConvexHull(shore)) +FROM lakes +WHERE lakes.name = 'Blue Lake'; + +DROP DATABASE gis_ogs; +USE test; + +--echo # +--echo # BUG #1043845 st_distance() results are incorrect depending on variable order +--echo # + +select st_distance(geomfromtext('LINESTRING(-95.9673005697771 36.13509598461, + -95.9673057475387 36.1344478941074, + -95.9673063519371 36.134484524621, + -95.9673049102515 36.1343976584193)'), + geomfromtext('point(-95.96269500000000000000 36.14181833333330000000)')) ; +select st_distance(geomfromtext('point(-95.96269500000000000000 36.14181833333330000000)'), + geomfromtext('LINESTRING(-95.9673005697771 36.13509598461, + -95.9673057475387 36.1344478941074, + -95.9673063519371 36.134484524621, + -95.9673049102515 36.1343976584193) ')) ; + +--echo # +--echo # MDEV-4310 geometry function equals hangs forever. +--echo # +create table t1(a geometry not null)engine=myisam; +insert into t1 values(geomfromtext("POINT(0 0)")); +insert into t1 values(geomfromtext("POINT(0 9.2233720368548e18)")); +insert into t1 values(geomfromtext("POINT(0 9.2233720368548e18)")); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +select equals(`a`,convert(`a` using utf8)) from `t1`; +select equals(`a`,left(`a`,23)) from `t1`; +drop table t1; + +--echo # +--echo # MDEV-6883 ST_WITHIN crashes server if (0,0) is matched to POLYGON((0 0)) +--echo # +select st_within(GeomFromText('Polygon((0 0))'), Point(0,0)); + +--echo End of 5.3 tests + +--echo # +--echo # Bug#11908153: CRASH AND/OR VALGRIND ERRORS IN FIELD_BLOB::GET_KEY_IMAGE +--echo # + +CREATE TABLE g1 +(a geometry NOT NULL, UNIQUE KEY i (a(151))) engine=myisam; + +INSERT INTO g1 VALUES (geomfromtext('point(1 1)')); +INSERT INTO g1 VALUES (geomfromtext('point(1 2)')); + +FLUSH TABLES; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 FROM g1 +FORCE INDEX(i) WHERE a = date_sub(now(), interval 2808.4 year_month) +; + +DROP TABLE g1; + +--echo # +--echo # Bug#13013970 MORE CRASHES IN FIELD_BLOB::GET_KEY_IMAGE +--echo # + +CREATE TABLE g1(a TEXT NOT NULL, KEY(a(255))); + +INSERT INTO g1 VALUES ('a'),('a'); +SELECT 1 FROM g1 WHERE a >= ANY +(SELECT 1 FROM g1 WHERE a = geomfromtext('') OR a) ; + +DROP TABLE g1; + +--echo # +--echo # Bug#16451878 GEOMETRY QUERY CRASHES SERVER +--echo # + +--echo # should not crash +SELECT ASTEXT(0x0100000000030000000100000000000010); + +--echo #should not crash +SELECT ENVELOPE(0x0100000000030000000100000000000010); + +--echo #should not crash +SELECT + GEOMETRYN(0x0100000000070000000100000001030000000200000000000000ffff0000, 1); + +--echo #should not crash +SELECT + GEOMETRYN(0x0100000000070000000100000001030000000200000000000000ffffff0f, 1); + +--echo # +--echo # MDEV-3819 missing constraints for spatial column types +--echo # + +create table t1 (pt point); +--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD +insert into t1 values(Geomfromtext('POLYGON((1 1, 2 2, 2 1, 1 1))')); +drop table t1; + +# +# MDEV-7516 Assertion `!cur_p->event' failed in Gcalc_scan_iterator::arrange_event(int, int) +# +SELECT st_astext(ST_Buffer(ST_PolygonFromText('POLYGON((3 5, 2 4, 2 5, 3 5))'), -100)); + +# +# MDEV-7779 View definition changes upon creation +# +CREATE VIEW v1 AS SELECT POINT(1,1) AS p; +SHOW CREATE VIEW v1; +SELECT ASTEXT(p) FROM v1; +DROP VIEW v1; + +# --echo End of 5.5 tests + +--echo # +--echo # Start of 10.0 tests +--echo # + +--echo # +--echo # MDEV-12495 Conditional jump depends on uninitialised value for: SELECT NULL UNION geom_expression +--echo # +SELECT AsText(g) FROM (SELECT NULL AS g UNION SELECT Point(1,1)) AS t1; + +--echo # +--echo # MDEV-10306 Wrong results with combination of CONCAT, SUBSTR and CONVERT in subquery +--echo # + +SET @save_optimizer_switch=@@optimizer_switch; +SET optimizer_switch='derived_merge=on'; +CREATE TABLE t1 (x INT, y INT); +INSERT INTO t1 VALUES(0,0); +SELECT LENGTH(t2) c2 FROM (SELECT ST_BUFFER(POINT(x,y), 0) t2 FROM t1) sub; +SELECT LENGTH(CONCAT(t2,'-',t2)) c2 FROM (SELECT ST_BUFFER(POINT(x,y), 0) t2 FROM t1) sub; +SELECT LENGTH(CONCAT(t2,'--',t2)) c2 FROM (SELECT ST_BUFFER(POINT(x,y), 0) t2 FROM t1) sub; +DROP TABLE t1; +SET optimizer_switch=@save_optimizer_switch; + +--echo # +--echo # MDEV-16995: ER_CANT_CREATE_GEOMETRY_OBJECT encountered for a query with +--echo # optimizer_use_condition_selectivity>=3 +--echo # + +CREATE TABLE t1 (a POINT); +INSERT INTO t1 VALUES (POINT(1,1)),(POINT(1,2)),(POINT(1,3)); +set @save_use_stat_tables= @@use_stat_tables; +set @save_optimizer_use_condition_selectivity= @@optimizer_use_condition_selectivity; +set @@use_stat_tables= PREFERABLY; +set @@optimizer_use_condition_selectivity=3; +SELECT COUNT(*) FROM t1 WHERE a IN ('test','test1'); +set @@use_stat_tables= @save_use_stat_tables; +set @@optimizer_use_condition_selectivity= @save_optimizer_use_condition_selectivity; +drop table t1; + +--echo # +--echo # End 10.0 tests +--echo # + +SHOW CREATE TABLE information_schema.geometry_columns; +SHOW CREATE TABLE information_schema.spatial_ref_sys; + +create table t1(g GEOMETRY, pt POINT); +create table t2(g LINESTRING, pl POLYGON); +--sorted_result +select * from information_schema.geometry_columns where f_table_schema='test'; +drop table t1, t2; + +--echo 10.1 tests +create table t1(g GEOMETRY(9,4) REF_SYSTEM_ID=101, pt POINT(8,2), pg GEOMETRY REF_SYSTEM_ID=102); +SELECT SRID from information_schema.geometry_columns WHERE f_table_schema='test' and G_TABLE_NAME='t1'; +drop table t1; + +-- echo # Expect an int(1) column to be created +CREATE TABLE t1 AS SELECT CONTAINS(NULL, NULL); +SHOW CREATE TABLE t1; +DROP TABLE t1; + + +--echo # +--echo # MDEV-7334 valgrind warning "unitialized bytes" in 10.1. +--echo # +CREATE TABLE t1 ( + gp point, + ln linestring, + pg polygon, + mp multipoint, + mln multilinestring, + mpg multipolygon, + gc geometrycollection, + gm geometry +); +ALTER TABLE t1 ADD fid INT NOT NULL; +select SRID from information_schema.geometry_columns where F_TABLE_NAME='t1'; +drop table t1; + +--echo # +--echo # MDEV-7510 GIS: IsRing returns false for a primitive triangle. +--echo # +select ST_IsRing(ST_LineFromText('LINESTRING(0 0,0 10,10 10,0 0)')); +select ST_IsRing(ST_LineFromText('LINESTRING(0 0,0 10,10 10,-10 -10, 0 -10, 0 0)')); + +--echo # +--echo # MDEV-7514 GIS: PointOnSurface returns NULL instead of the point. +--echo # +SELECT ST_GEOMETRYTYPE(ST_PointOnSurface(ST_PolyFromText('POLYGON((-70.916 42.1002,-70.9468 42.0946,-70.9754 42.0875,-70.9749 42.0879,-70.9759 42.0897,-70.916 42.1002))'))); + +--echo # +--echo # MDEV-7529 GIS: ST_Relate returns unexpected results for POINT relations +--echo # +select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(0 0)'),'T*F**FFF*') AS equals; +select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(0 0)'),'T*****FF*') AS contains; +select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(0 0)'),'T*F**F***') AS within; +select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(1 1)'),'FF*FF****') as disjoint; +select ST_Relate(ST_PointFromText('POINT(0 0)'),ST_PointFromText('POINT(0 0)'),'FF*FF****') as disjoint; + + +--echo # +--echo # MDEV-7528 GIS: Functions return NULL instead of specified -1 for NULL arguments. +--echo # + +select ST_IsRing(NULL); + +--echo # +--echo # MDEV-8675 Different results of GIS functions on NULL vs NOT NULL columns +--echo # +CREATE TABLE t1 (g1 GEOMETRY NOT NULL,g2 GEOMETRY NULL); +CREATE TABLE t2 AS SELECT WITHIN(g1,g1) as w1,WITHIN(g2,g2) AS w2 FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t1,t2; + +--echo # +--echo # Start of 10.2 tests +--echo # + +# +# Item_func_spatial_collection::print() +# +create view v1 as select AsWKT(GeometryCollection(Point(44, 6), LineString(Point(3, 6), Point(7, 9)))); +show create view v1; +select * from v1; +drop view v1; + +--echo # +--echo # MDEV-10134 Add full support for DEFAULT +--echo # + +CREATE TABLE t1 (a POINT, x DOUBLE DEFAULT x(a), y DOUBLE DEFAULT y(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (Point(1,2)); +SELECT x,y FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (g GEOMETRY, area DOUBLE DEFAULT ST_AREA(g)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (g) VALUES (GeomFromText('POLYGON((0 0,20 0,20 20,0 20,0 0))')); +SELECT area FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (g GEOMETRY, length DOUBLE DEFAULT ST_LENGTH(g)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (g) VALUES (GeomFromText('LINESTRING(0 0,20 0,20 20,0 20,0 0)')); +SELECT length FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (g POINT, distance DOUBLE DEFAULT ST_DISTANCE(g, POINT(0,0))); +SHOW CREATE TABLE t1; +INSERT INTO t1 (g) VALUES (Point(1,0)); +SELECT distance FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TEXT, g GEOMETRY DEFAULT GeomFromText(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES ('point(1 1)'); +SELECT AsText(g) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (x INT, y INT, g GEOMETRY DEFAULT POINT(x,y)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (x,y) VALUES (10,20); +SELECT AsText(g) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT PointN(a,2)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('LineString(1 1,2 2,3 3)')); +SELECT AsText(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT StartPoint(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('LineString(1 1,2 2,3 3)')); +SELECT AsText(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY, c GEOMETRY DEFAULT GeometryCollection(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (Point(1,1), Point(2,2)); +SELECT AsText(c) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT GeomFromWKB(AsBinary(a),20)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('POINT(1 1)', 10)); +SELECT AsText(a), SRID(a), AsText(b), SRID(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT BOUNDARY(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))')); +SELECT AsText(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT BUFFER(a,10)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))')); +SELECT GeometryType(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT CENTROID(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))')); +SELECT AsText(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT ENVELOPE(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('LineString(1 1,4 4)')); +SELECT AsText(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT PointOnSurface(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('POLYGON((10 10, 10 20, 20 20, 20 10, 10 10))')); +SELECT GeometryType(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY DEFAULT Point(1,1), c GEOMETRY DEFAULT ST_UNION(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (Point(0,0)); +SELECT AsText(c) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b VARCHAR(20) DEFAULT GeometryType(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (Point(0, 0)); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT IsSimple(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (Point(0, 0)); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT IsEmpty(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (Point(0, 0)); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT IsRing(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('LineString(0 0,0 1,1 1,1 0,0 0)')); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT IsClosed(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('LineString(0 0,0 1,1 1,1 0,0 0)')); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT Dimension(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (Buffer(Point(1,1),1)); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT NumGeometries(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (ST_UNION(Point(1,1),Point(0,0))); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT NumInteriorRings(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))')); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT NumPoints(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (LineString(Point(1,1),Point(0,0))); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b INT DEFAULT SRID(a)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a) VALUES (GeomFromText('Point(1 1)', 100)); +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY, c INT DEFAULT MBRDisjoint(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (Point(1,1),Point(1,1)); +SELECT c FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY, c INT DEFAULT ST_Disjoint(a,b)); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (Point(1,1),Point(1,1)); +SELECT c FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a GEOMETRY, b GEOMETRY, c INT DEFAULT ST_Relate(a,b,'T*F**FFF*')); +SHOW CREATE TABLE t1; +INSERT INTO t1 (a,b) VALUES (Point(1,1),Point(1,1)); +SELECT c FROM t1; +DROP TABLE t1; + +--echo # +--echo # Start of 10.3 tests +--echo # + +--echo # +--echo # MDEV-11478 Result data type aggregation for pluggable data types +--echo # + +DELIMITER $$; +CREATE PROCEDURE p2(query TEXT) +BEGIN + DECLARE errcount INT DEFAULT 0; + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + SET errcount = errcount+1; + #SHOW WARNINGS; + GET DIAGNOSTICS CONDITION 1 @p= MESSAGE_TEXT; + SELECT @p AS `ERROR: `; + END; + SELECT query AS ``; + EXECUTE IMMEDIATE query; + IF errcount = 0 + THEN + SHOW CREATE TABLE t2; + DROP TABLE t2; + END IF; +END; +$$ +CREATE PROCEDURE p1(query TEXT) +BEGIN + SELECT query AS `-------------------------------------`; + EXECUTE IMMEDIATE query; + CALL p2('CREATE TABLE t2 AS SELECT CASE WHEN TRUE THEN a ELSE b END FROM t1'); + CALL p2('CREATE TABLE t2 AS SELECT COALESCE(a,b) FROM t1'); + CALL p2('CREATE TABLE t2 AS SELECT IF(TRUE,a,b) FROM t1'); + CALL p2('CREATE TABLE t2 AS SELECT IFNULL(a,b) FROM t1'); + CALL p2('CREATE TABLE t2 AS SELECT a FROM t1 UNION SELECT b FROM t1'); + DROP TABLE t1; +END; +$$ +DELIMITER ;$$ + +--disable_query_log +CALL p1('CREATE TABLE t1 (a CHAR(10), b Point)'); +CALL p1('CREATE TABLE t1 (a VARCHAR(10), b Point)'); +CALL p1('CREATE TABLE t1 (a TINYTEXT, b Point)'); +CALL p1('CREATE TABLE t1 (a TEXT, b Point)'); +CALL p1('CREATE TABLE t1 (a MEDIUMTEXT, b Point)'); +CALL p1('CREATE TABLE t1 (a LONGTEXT, b Point)'); + +CALL p1('CREATE TABLE t1 (a TINYINT, b Point)'); +CALL p1('CREATE TABLE t1 (a SMALLINT, b Point)'); +CALL p1('CREATE TABLE t1 (a MEDIUMINT, b Point)'); +CALL p1('CREATE TABLE t1 (a INT, b Point)'); +CALL p1('CREATE TABLE t1 (a BIGINT, b Point)'); +CALL p1('CREATE TABLE t1 (a FLOAT, b Point)'); +CALL p1('CREATE TABLE t1 (a DOUBLE, b Point)'); +CALL p1('CREATE TABLE t1 (a DECIMAL(10,2), b Point)'); +CALL p1('CREATE TABLE t1 (a BIT(8), b Point)'); + +CALL p1('CREATE TABLE t1 (a TIME, b Point)'); +CALL p1('CREATE TABLE t1 (a DATE, b Point)'); +CALL p1('CREATE TABLE t1 (a DATETIME, b Point)'); +CALL p1('CREATE TABLE t1 (a TIMESTAMP, b Point)'); +CALL p1('CREATE TABLE t1 (a YEAR, b Point)'); + +--echo # This creates BLOB with hybrid functions, but fails on error with UNION (MDEV-11458) +CALL p1('CREATE TABLE t1 (a ENUM(0x61), b Point)'); +CALL p1('CREATE TABLE t1 (a SET(0x61), b Point)'); +--enable_query_log + +CREATE TABLE t1 AS SELECT COALESCE(NULL, Point(1,1)); +SHOW CREATE TABLE t1; +DROP TABLE t1; +CREATE TABLE t1 AS SELECT NULL UNION SELECT Point(1,1); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +DROP PROCEDURE p1; +DROP PROCEDURE p2; + + +--echo # +--echo # MDEV-11692 Comparison data type aggregation for pluggable data types +--echo # + +DELIMITER $$; +CREATE PROCEDURE p2(query TEXT) +BEGIN + DECLARE errcount INT DEFAULT 0; + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + SET errcount = errcount+1; + GET DIAGNOSTICS CONDITION 1 @p= MESSAGE_TEXT; + SELECT @p AS `ERROR: `; + END; + SELECT query AS ``; + EXECUTE IMMEDIATE query; +END; +$$ +CREATE PROCEDURE p1(query TEXT) +BEGIN + SELECT query AS `-------------------------------------`; + EXECUTE IMMEDIATE query; + CALL p2('SELECT a=b FROM t1'); + CALL p2('SELECT b=a FROM t1'); + CALL p2('SELECT a BETWEEN b AND c FROM t1'); + CALL p2('SELECT a IN (b,c) FROM t1'); + CALL p2('SELECT CASE a WHEN b THEN "a" WHEN c THEN "b" END FROM t1'); + CALL p2('SELECT a=POINT(1,1) FROM t1'); + CALL p2('SELECT POINT(1,1)=a FROM t1'); + CALL p2('SELECT a BETWEEN POINT(1,1) AND POINT(1,2) FROM t1'); + CALL p2('SELECT a IN (POINT(1,1),POINT(1,2)) FROM t1'); + CALL p2('SELECT CASE a WHEN POINT(1,1) THEN "a" WHEN POINT(1,2) THEN "b" END FROM t1'); + DROP TABLE t1; +END; +$$ +DELIMITER ;$$ + +CALL p1('CREATE TABLE t1 (a CHAR(10), b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a VARCHAR(10), b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a TINYTEXT, b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a TEXT, b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a MEDIUMTEXT, b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a LONGTEXT, b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a ENUM("a","b"), b Point, c Point)'); + +CALL p1('CREATE TABLE t1 (a TINYINT, b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a SMALLINT, b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a MEDIUMINT, b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a INT, b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a BIGINT, b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a FLOAT, b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a DOUBLE, b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a DECIMAL(10,2), b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a BIT(8), b Point, c Point)'); + +CALL p1('CREATE TABLE t1 (a TIME, b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a DATE, b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a DATETIME, b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a TIMESTAMP, b Point, c Point)'); +CALL p1('CREATE TABLE t1 (a YEAR, b Point, c Point)'); + +CALL p1('CREATE TABLE t1 (a Point, b Point, c Point)'); + + +DROP PROCEDURE p1; +DROP PROCEDURE p2; + + +--echo # +--echo # MDEV-12506 Split Item_func_min_max::fix_length_and_dec() into methods in Type_handler +--echo # + +DELIMITER $$; +CREATE PROCEDURE p2(query TEXT) +BEGIN + DECLARE errcount INT DEFAULT 0; + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + SET errcount = errcount+1; + #SHOW WARNINGS; + GET DIAGNOSTICS CONDITION 1 @p= MESSAGE_TEXT; + SELECT @p AS `ERROR: `; + END; + SELECT query AS ``; + EXECUTE IMMEDIATE query; + IF errcount = 0 + THEN + SHOW CREATE TABLE t2; + DROP TABLE t2; + END IF; +END; +$$ +CREATE PROCEDURE p1(query TEXT) +BEGIN + SELECT query AS `-------------------------------------`; + EXECUTE IMMEDIATE query; + CALL p2('CREATE TABLE t2 AS SELECT LEAST(a,b) FROM t1'); + DROP TABLE t1; +END; +$$ +DELIMITER ;$$ + +--disable_query_log +CALL p1('CREATE TABLE t1 (a CHAR(10), b Point)'); +CALL p1('CREATE TABLE t1 (a VARCHAR(10), b Point)'); +CALL p1('CREATE TABLE t1 (a TINYTEXT, b Point)'); +CALL p1('CREATE TABLE t1 (a TEXT, b Point)'); +CALL p1('CREATE TABLE t1 (a MEDIUMTEXT, b Point)'); +CALL p1('CREATE TABLE t1 (a LONGTEXT, b Point)'); + +CALL p1('CREATE TABLE t1 (a TINYINT, b Point)'); +CALL p1('CREATE TABLE t1 (a SMALLINT, b Point)'); +CALL p1('CREATE TABLE t1 (a MEDIUMINT, b Point)'); +CALL p1('CREATE TABLE t1 (a INT, b Point)'); +CALL p1('CREATE TABLE t1 (a BIGINT, b Point)'); +CALL p1('CREATE TABLE t1 (a FLOAT, b Point)'); +CALL p1('CREATE TABLE t1 (a DOUBLE, b Point)'); +CALL p1('CREATE TABLE t1 (a DECIMAL(10,2), b Point)'); +CALL p1('CREATE TABLE t1 (a BIT(8), b Point)'); + +CALL p1('CREATE TABLE t1 (a TIME, b Point)'); +CALL p1('CREATE TABLE t1 (a DATE, b Point)'); +CALL p1('CREATE TABLE t1 (a DATETIME, b Point)'); +CALL p1('CREATE TABLE t1 (a TIMESTAMP, b Point)'); +CALL p1('CREATE TABLE t1 (a YEAR, b Point)'); + +--echo # This LEAST(ENUM,GEOMETRY) creates BLOB, but fails on error with UNION (see MDEV-12503) +CALL p1('CREATE TABLE t1 (a ENUM(0x61), b Point)'); +CALL p1('CREATE TABLE t1 (a SET(0x61), b Point)'); +--enable_query_log + +CREATE TABLE t1 AS SELECT LEAST(NULL, Point(1,1)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +DROP PROCEDURE p1; +DROP PROCEDURE p2; + +--echo # +--echo # MDEV-12001 Split Item_func_round::fix_length_and_dec to virtual methods in Type_handler +--echo # + +CREATE TABLE t1 (a GEOMETRY); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ROUND(a) FROM t1; +DROP TABLE t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ROUND(POINT(1,1)); + + +--echo # +--echo # MDEV-12199 Split Item_func_{abs|neg|int_val}::fix_length_and_dec() into methods in Type_handler +--echo # + +CREATE TABLE t1 (a GEOMETRY); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT -a FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ABS(a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CEILING(a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT FLOOR(a) FROM t1; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT -COALESCE(a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ABS(COALESCE(a)) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CEILING(COALESCE(a)) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT FLOOR(COALESCE(a)) FROM t1; +DROP TABLE t1; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT -POINT(1,1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ABS(POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CEILING(POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT FLOOR(POINT(1,1)); + + +--echo # +--echo # MDEV-12239 Add Type_handler::Item_sum_{sum|avg|variance}_fix_length_and_dec() +--echo # + +CREATE TABLE t1 (a GEOMETRY); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT SUM(POINT(1,1)) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT SUM(a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT SUM(COALESCE(a)) FROM t1; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT AVG(POINT(1,1)) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT AVG(a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT AVG(COALESCE(a)) FROM t1; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT VARIANCE(POINT(1,1)) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT VARIANCE(a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT VARIANCE(COALESCE(a)) FROM t1; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT STDDEV(POINT(1,1)) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT STDDEV(a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT STDDEV(COALESCE(a)) FROM t1; + +DROP TABLE t1; + +--echo # +--echo # MDEV-12303 Add Type_handler::Item_xxx_fix_length_and_dec() for CAST classes +--echo # + +CREATE TABLE t1 (a GEOMETRY); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(POINT(1,1) AS SIGNED) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(POINT(1,1) AS UNSIGNED) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(POINT(1,1) AS DOUBLE) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(POINT(1,1) AS DECIMAL(10,1)) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(POINT(1,1) AS CHAR) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(POINT(1,1) AS TIME) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(POINT(1,1) AS DATE) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(POINT(1,1) AS DATETIME) FROM t1; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(a AS SIGNED) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(a AS UNSIGNED) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(a AS DOUBLE) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(a AS DECIMAL(10,1)) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(a AS CHAR) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(a AS TIME) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(a AS DATE) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(a AS DATETIME) FROM t1; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(COALESCE(a) AS SIGNED) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(COALESCE(a) AS UNSIGNED) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(COALESCE(a) AS DOUBLE) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(COALESCE(a) AS DECIMAL(10,1)) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(COALESCE(a) AS CHAR) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(COALESCE(a) AS TIME) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(COALESCE(a) AS DATE) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(COALESCE(a) AS DATETIME) FROM t1; + +# CAST from GEOMETRY to BINARY is OK +SELECT LENGTH(CAST(POINT(1,1) AS BINARY)) FROM t1; +SELECT LENGTH(CAST(a AS BINARY)) FROM t1; +SELECT LENGTH(CAST(COALESCE(a) AS BINARY)) FROM t1; + +DROP TABLE t1; + +--echo # +--echo # MDEV-12238 Add Type_handler::Item_func_{plus|minus|mul|div|mod}_fix_length_and_dec() +--echo # + +CREATE TABLE t1 (a GEOMETRY); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT POINT(1,1) + 1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT POINT(1,1) - 1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT POINT(1,1) * 1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT POINT(1,1) / 1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT POINT(1,1) MOD 1; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 + POINT(1,1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 - POINT(1,1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 * POINT(1,1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 / POINT(1,1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 MOD POINT(1,1); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT a + 1 FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT a - 1 FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT a * 1 FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT a / 1 FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT a MOD 1 FROM t1; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 + a FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 - a FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 * a FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 / a FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 MOD a FROM t1; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(a) + 1 FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(a) - 1 FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(a) * 1 FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(a) / 1 FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(a) MOD 1 FROM t1; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 + COALESCE(a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 - COALESCE(a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 * COALESCE(a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 / COALESCE(a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT 1 MOD COALESCE(a) FROM t1; + +DROP TABLE t1; + +--echo # +--echo # MDEV-12514 Split Item_temporal_func::fix_length_and_dec() +--echo # + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT DATE_ADD(POINT(1,1), INTERVAL 10 DAY); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT DATE_SUB(POINT(1,1), INTERVAL 10 DAY); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT POINT(1,1) + INTERVAL 10 DAY; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT POINT(1,1) - INTERVAL 10 DAY; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT INTERVAL 10 DAY + POINT(1,1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT INTERVAL 10 DAY + POINT(1,1); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT ADDTIME(POINT(1,1), '10:10:10'); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT ADDTIME('10:10:10', POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT ADDTIME(POINT(1,1), TIME'10:10:10'); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT ADDTIME(TIME'10:10:10', POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT ADDTIME(POINT(1,1), TIMESTAMP'2001-01-01 10:10:10'); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT ADDTIME(TIMESTAMP'2001-01-01 10:10:10', POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT STR_TO_DATE(POINT(1,1),'%M %d,%Y'); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT STR_TO_DATE('2001-01-01', POINT(1,1)); + +--echo # +--echo # MDEV-12665 Hybrid functions do not preserve geometry type +--echo # + +CREATE TABLE t1 AS SELECT + Point(0,0) AS p0, + COALESCE(Point(0,0)) AS p1, + CASE WHEN 0 THEN Point(0,0) ELSE Point(1,1) END AS p2; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 AS SELECT LEAST(Point(0,0),Point(0,0)) AS p1; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + c_geometry GEOMETRY, + c_point POINT, + c_linestring LINESTRING, + c_polygon POLYGON, + c_multipoint MULTIPOINT, + c_multilinestring MULTILINESTRING, + c_multipolygon MULTIPOLYGON, + c_geometrycollection GEOMETRYCOLLECTION +); + +CREATE TABLE t2 AS SELECT + COALESCE(NULL, c_geometry), + COALESCE(NULL, c_point), + COALESCE(NULL, c_linestring), + COALESCE(NULL, c_polygon), + COALESCE(NULL, c_multipoint), + COALESCE(NULL, c_multilinestring), + COALESCE(NULL, c_multipolygon), + COALESCE(NULL, c_geometrycollection) +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; + +CREATE TABLE t2 AS SELECT + COALESCE(c_geometry, NULL), + COALESCE(c_point, NULL), + COALESCE(c_linestring, NULL), + COALESCE(c_polygon, NULL), + COALESCE(c_multipoint, NULL), + COALESCE(c_multilinestring, NULL), + COALESCE(c_multipolygon, NULL), + COALESCE(c_geometrycollection, NULL) +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; + +CREATE TABLE t2 AS SELECT + COALESCE(c_geometry, c_geometry), + COALESCE(c_point, c_point), + COALESCE(c_linestring, c_linestring), + COALESCE(c_polygon, c_polygon), + COALESCE(c_multipoint, c_multipoint), + COALESCE(c_multilinestring, c_multilinestring), + COALESCE(c_multipolygon, c_multipolygon), + COALESCE(c_geometrycollection, c_geometrycollection) +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; + +DROP TABLE t1; + + +--echo # +--echo # MDEV-12560 Wrong data type for SELECT NULL UNION SELECT Point(1,1) +--echo # + +CREATE TABLE t1 AS SELECT NULL AS c1 UNION SELECT POINT(1,1); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +DELIMITER $$; +CREATE PROCEDURE p1(name TEXT) +BEGIN + EXECUTE IMMEDIATE CONCAT('CREATE TABLE t1 (a ', name, ')'); + CREATE TABLE t2 AS + SELECT a AS a1, a AS a2, NULL AS a3 FROM t1 UNION + SELECT a AS a1, NULL AS a2, a AS a3 FROM t1; + SHOW CREATE TABLE t2; + DROP TABLE t2; + DROP TABLE t1; +END; +$$ +DELIMITER ;$$ +CALL p1('geometry'); +CALL p1('point'); +CALL p1('linestring'); +CALL p1('polygon'); +CALL p1('multipoint'); +CALL p1('multilinestring'); +CALL p1('multipolygon'); +CALL p1('geometrycollection'); +DROP PROCEDURE p1; + +--echo # +--echo # MDEV-12798 Item_param does not preserve exact field type in EXECUTE IMMEDIATE 'CREATE TABLE AS SELECT ?' USING POINT(1,1) +--echo # +EXECUTE IMMEDIATE 'CREATE TABLE t1 AS SELECT ?' USING POINT(1,1); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +PREPARE stmt FROM 'CREATE OR REPLACE TABLE t1 AS SELECT ?'; +EXECUTE stmt USING POINT(1,1); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-12854 Synchronize CREATE..SELECT data type and result set metadata data type for INT functions +--echo # + +--enable_metadata +--disable_ps_protocol +SELECT + ST_ISSIMPLE(POINT(1,1)), + ST_ISRING(POINT(1,1)), + ST_ISCLOSED(POINT(1,1)), + ST_DIMENSION(POINT(1,1)), + ST_NUMGEOMETRIES(POINT(1,1)), + ST_NUMINTERIORRINGS(POINT(1,1)), + ST_NUMPOINTS(POINT(1,1)), + ST_SRID(POINT(1,1)); +--enable_ps_protocol +--disable_metadata + + +--echo # +--echo # MDEV-12803 Improve function parameter data type control +--echo # + +--echo # +--echo # Item_geometry_func_args_geometry +--echo # + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_CENTROID(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ENVELOPE(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_BOUNDARY(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_STARTPOINT(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_POINTONSURFACE(1); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_POINTN(1,1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_POINTN(LineString(Point(1,1)),Point(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_BUFFER(1, 1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_BUFFER(Point(1,1), Point(1,1)); + + +PREPARE stmt FROM 'CREATE TABLE t1 AS SELECT ST_ENVELOPE(?) AS g'; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +EXECUTE stmt USING 1; +EXECUTE stmt USING POINT(1,1); +SHOW CREATE TABLE t1; +SELECT ST_ASTEXT(g) FROM t1; +DROP TABLE t1; +DEALLOCATE PREPARE stmt; + +PREPARE stmt FROM 'CREATE TABLE t1 AS SELECT ST_BUFFER(?,?) AS g'; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +EXECUTE stmt USING 1,1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +EXECUTE stmt USING POINT(1,1),POINT(1,1); +EXECUTE stmt USING POINT(1,1),0; +SHOW CREATE TABLE t1; +SELECT ST_GEOMETRYTYPE(g) FROM t1; +DROP TABLE t1; +DEALLOCATE PREPARE stmt; + +--echo # +--echo # Functions created GEOMETRY from non-GEOMETRY +--echo # + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_GEOMETRYFROMTEXT(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_GEOMETRYFROMTEXT(Point(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_GEOMETRYFROMTEXT(Point(1,1), 1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_GEOMETRYFROMTEXT('test', Point(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_GEOMETRYFROMWKB(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_GEOMETRYFROMWKB(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_GEOMETRYFROMWKB(1, 1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_GEOMETRYFROMWKB(Point(1,1), Point(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_GEOMFROMGEOJSON(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_GEOMFROMGEOJSON(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_GEOMFROMGEOJSON(1,1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_GEOMFROMGEOJSON(Point(1,1), Point(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT POINT(ROW(1,1),1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT POINT(POINT(1,1),1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT POINT(1,ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT POINT(1,POINT(1,1)); + + +PREPARE stmt FROM 'CREATE TABLE t1 AS SELECT ST_GEOMFROMTEXT(?,?) AS g'; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +EXECUTE stmt USING 1,1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +EXECUTE stmt USING POINT(1,1),POINT(1,1); +EXECUTE stmt USING 'POINT(1 1)',1; +SHOW CREATE TABLE t1; +SELECT ST_ASTEXT(g), SRID(g) FROM t1; +DROP TABLE t1; +DEALLOCATE PREPARE stmt; + + + +--echo # Item_func_spatial_collection + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT GEOMETRYCOLLECTION(ROW(1,1), POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT GEOMETRYCOLLECTION(POINT(1,1), ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT GEOMETRYCOLLECTION(1, POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT GEOMETRYCOLLECTION(POINT(1,1), 1); + +--echo # Item_func_spatial_operation + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_UNION(ROW(1,1), POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_UNION(POINT(1,1), ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_UNION(1, POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_UNION(POINT(1,1), 1); + +--echo # Item_binary_func_args_geometry + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ASWKB(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ASWKB(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ASWKB('test'); + + +--echo # Item_real_func_args_geometry + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_X(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_X(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_X('test'); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_Y(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_Y(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_Y('test'); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_AREA(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_AREA(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_AREA('test'); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_LENGTH(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_LENGTH(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_LENGTH('test'); + + +--echo # Item_real_func_geometry_args_geometry_geometry + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_DISTANCE(ROW(1,1), 1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_DISTANCE(1, 1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_DISTANCE('test', 1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_DISTANCE(POINT(1,1), ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_DISTANCE(POINT(1,1), 1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_DISTANCE(POINT(1,1), 'test'); + + +--echo # Item_int_func_args_geometry + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ISSIMPLE(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ISSIMPLE(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ISSIMPLE('test'); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ISRING(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ISRING(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ISRING('test'); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ISCLOSED(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ISCLOSED(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ISCLOSED('test'); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_DIMENSION(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_DIMENSION(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_DIMENSION('test'); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_NUMGEOMETRIES(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_NUMGEOMETRIES(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_NUMGEOMETRIES('test'); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_NUMINTERIORRINGS(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_NUMINTERIORRINGS(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_NUMINTERIORRINGS('test'); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_NUMPOINTS(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_NUMPOINTS(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_NUMPOINTS('test'); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_SRID(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_SRID(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_SRID('test'); + + +--echo # Item_bool_func_args_geometry + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ISEMPTY(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ISEMPTY(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ISEMPTY('test'); + +--echo # Item_bool_func_geometry_args_geometry_geometry + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_RELATE(ROW(1,1), POINT(1,1), 'T*F**FFF*'); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_RELATE(POINT(1,1), ROW(1,1), 'T*F**FFF*'); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_RELATE(1, POINT(1,1), 'T*F**FFF*'); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_RELATE(POINT(1,1), 1, 'T*F**FFF*'); +SELECT ST_RELATE(Point(1,1),Point(1,1),'T*F**FFF*') AS equals; +SELECT ST_RELATE(Point(1,1),Point(1,1),NULL); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_RELATE(Point(1,1),Point(1,1),ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_RELATE(Point(1,1),Point(1,1),1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_RELATE(Point(1,1),Point(1,1),1.0); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_RELATE(Point(1,1),Point(1,1),1e0); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_RELATE(Point(1,1),Point(1,1),TIME'10:10:10'); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_RELATE(Point(1,1),Point(1,1),DATE'2010-01-01'); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_RELATE(Point(1,1),Point(1,1),TIMESTAMP'2010-01-01 10:10:10'); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_RELATE(Point(1,1),Point(1,1),Point(1,1)); + + +--echo # Item_str_ascii_func_args_geometry + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ASTEXT(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ASTEXT(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ASTEXT('test'); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_GEOMETRYTYPE(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_GEOMETRYTYPE(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_GEOMETRYTYPE('test'); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ASGEOJSON(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ASGEOJSON(1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ASGEOJSON('test'); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ASGEOJSON(POINT(1,1), POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_ASGEOJSON(POINT(1,1), 1, POINT(1,1)); + +--echo # Item_func_spatial_rel + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_TOUCHES(ROW(1,1), POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_TOUCHES(POINT(1,1), ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_TOUCHES(1, POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_TOUCHES(POINT(1,1), 1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_TOUCHES('test', POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ST_TOUCHES(POINT(1,1), 'test'); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT MBRTOUCHES(ROW(1,1), POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT MBRTOUCHES(POINT(1,1), ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT MBRTOUCHES(1, POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT MBRTOUCHES(POINT(1,1), 1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT MBRTOUCHES('test', POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT MBRTOUCHES(POINT(1,1), 'test'); + + +--echo # +--echo # MDEV-13964 Parameter data type control for Item_real_func +--echo # + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT EXP(POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT LN(POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT LOG2(POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT LOG10(POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT SQRT(POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ACOS(POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ASIN(POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT COS(POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT SIN(POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT TAN(POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT COT(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT LOG(POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT LOG(POINT(1,1),POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT LOG(1, POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ATAN(POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ATAN(POINT(1,1),POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ATAN(1, POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT POW(POINT(1,1),POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT RAND(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT RADIANS(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT DEGREES(POINT(1,1)); + + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT EXP(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT LN(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT LOG2(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT LOG10(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT SQRT(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ACOS(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ASIN(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT COS(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT SIN(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT TAN(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT COT(ROW(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT LOG(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT LOG(ROW(1,1),ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT LOG(1, ROW(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ATAN(ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ATAN(ROW(1,1),ROW(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ATAN(1, ROW(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT POW(ROW(1,1),ROW(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT RAND(ROW(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT RADIANS(ROW(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT DEGREES(ROW(1,1)); + + +--echo # +--echo # MDEV-13965 Parameter data type control for Item_longlong_func +--echo # + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT POINT(1,1) | 1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT 1 | POINT(1,1); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT POINT(1,1) & 1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT 1 & POINT(1,1); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT POINT(1,1) << 1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT 1 << POINT(1,1); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT POINT(1,1) >> 1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT 1 >> POINT(1,1); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ~POINT(1,1); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT TO_SECONDS(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT TIMESTAMPDIFF(SECOND,POINT(1,1), 1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT TIMESTAMPDIFF(SECOND,1, POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT INET_ATON(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT LAST_INSERT_ID(POINT(1,1)); + + +--echo # +--echo # MDEV-13966 Parameter data type control for Item_temporal_func +--echo # + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT FROM_DAYS(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT MAKEDATE(POINT(1,1),1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT MAKEDATE(1, POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT LAST_DAY(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT SEC_TO_TIME(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT TIMEDIFF(POINT(1,1),1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT TIMEDIFF(1, POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT MAKETIME(POINT(1,1),1,1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT MAKETIME(1, POINT(1,1), 1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT MAKETIME(1, 1, POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT FROM_UNIXTIME(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CONVERT_TZ(POINT(1,1),1,1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CONVERT_TZ(1, POINT(1,1), 1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CONVERT_TZ(1, 1, POINT(1,1)); + + +--echo # +--echo # MDEV-13967 Parameter data type control for Item_long_func +--echo # + +SELECT STRCMP(POINT(1,1),POINT(1,1)); +SELECT CHAR_LENGTH(POINT(1,1)); +SELECT OCTET_LENGTH(POINT(1,1)); +SELECT UNCOMPRESSED_LENGTH(POINT(1,1)); +SELECT COERCIBILITY(POINT(1,1)); +SELECT ASCII(POINT(1,1)); +SELECT CRC32(POINT(1,1)); +SELECT ORD(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT SIGN(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT LOCATE('a','a',POINT(1,1)); + +SELECT LOCATE(POINT(1,1),POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT BIT_COUNT(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT BENCHMARK(POINT(1,1),''); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT SLEEP(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT GET_LOCK('x', POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT PERIOD_ADD(POINT(1,1),1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT PERIOD_ADD(1,POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT PERIOD_DIFF(POINT(1,1),1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT PERIOD_DIFF(1,POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT TO_DAYS(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT DAYOFMONTH(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT DAYOFYEAR(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT QUARTER(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT YEAR(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT YEARWEEK(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT WEEK(POINT(1,1)); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT WEEK(POINT(1,1),1); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT WEEK(1,POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT HOUR(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT MINUTE(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT SECOND(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT MICROSECOND(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT JSON_DEPTH(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT JSON_LENGTH(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT JSON_LENGTH('json', POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT JSON_LENGTH(POINT(1,1), POINT(1,1)); + +SELECT REGEXP_INSTR(POINT(1,1),''); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT REGEXP_INSTR('',POINT(1,1)); + +SELECT FIND_IN_SET(POINT(1,1),''); +SELECT FIND_IN_SET('',POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT RELEASE_LOCK(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT IS_FREE_LOCK(POINT(1,1)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT IS_USED_LOCK(POINT(1,1)); + + +--echo # +--echo # End of 10.3 tests +--echo # diff --cc mysql-test/main/mysql.test index c65860eb822,00000000000..66ccef18327 mode 100644,000000..100644 --- a/mysql-test/main/mysql.test +++ b/mysql-test/main/mysql.test @@@ -1,682 -1,0 +1,705 @@@ +-- source include/have_working_dns.inc +# This test should work in embedded server after we fix mysqltest +-- source include/not_embedded.inc +# +# Testing the MySQL command line client(mysql) +# +set GLOBAL sql_mode=""; +set LOCAL sql_mode=""; + +--disable_warnings +drop table if exists t1,t2,t3; +--enable_warnings + +# +# Test the "delimiter" functionality +# Bug#9879 +# +create table t1(a int); +insert into t1 values(1); + +# Test delimiters +--exec $MYSQL test 2>&1 < "./main/mysql_delimiter.sql" + +--disable_query_log +# Test delimiter : supplied on the command line +select "Test delimiter : from command line" as "_"; +--exec $MYSQL test --delimiter=":" -e "select * from t1:" +# Test delimiter :; supplied on the command line +select "Test delimiter :; from command line" as "_"; +--exec $MYSQL test --delimiter=":;" -e "select * from t1:;" +# Test 'go' command (vertical output) \G +select "Test 'go' command(vertical output) \G" as "_"; +--exec $MYSQL test -e "select * from t1\G" +# Test 'go' command \g +select "Test 'go' command \g" as "_"; +--exec $MYSQL test -e "select * from t1\g" +--enable_query_log +drop table t1; + +# +# BUG9998 - MySQL client hangs on USE "database" +# +create table t1(a int); +lock tables t1 write; +--exec $MYSQL -e "use test; select database();" +unlock tables; +drop table t1; + +# +# Bug#16859 -- NULLs in columns must not truncate data as if a C-language "string". +# +--exec $MYSQL -t test -e "create table t1 (col1 binary(4), col2 varchar(10), col3 int); insert into t1 values ('a', 'b', 123421),('a ', '0123456789', 4), ('abcd', '', 4); select concat('>',col1,'<'), col2, col3 from t1; drop table t1;" 2>&1 + +# +# Bug#17939 Wrong table format when using UTF8 strings +write_file $MYSQL_TMP_DIR/mysql_in; +SELECT 'John Doe' as '__tañgè Ñãmé'; +SELECT '__tañgè Ñãmé' as 'John Doe'; +EOF +--exec $MYSQL --default-character-set=utf8 --table < $MYSQL_TMP_DIR/mysql_in 2>&1 +remove_file $MYSQL_TMP_DIR/mysql_in; + +# +# Bug#18265 -- mysql client: No longer right-justifies numeric columns +# +write_file $MYSQL_TMP_DIR/mysql_in; +create table t1 (i int, j int, k char(25) charset utf8); insert into t1 (i) values (1); insert into t1 (k) values ('<----------------------->'); insert into t1 (k) values ('<-----'); insert into t1 (k) values ('Τη γλώσσα'); insert into t1 (k) values ('ᛖᚴ ᚷᛖᛏ'); select * from t1; DROP TABLE t1; +EOF +--exec $MYSQL -t --default-character-set utf8 test < $MYSQL_TMP_DIR/mysql_in +remove_file $MYSQL_TMP_DIR/mysql_in; + + +# +# "DESCRIBE" commands may return strange NULLness flags. +# +--exec $MYSQL --default-character-set utf8 test -e "create table t1 (i int, j int not null, k int); insert into t1 values (null, 1, null); select * from t1; describe t1; drop table t1;" +--exec $MYSQL -t --default-character-set utf8 test -e "create table t1 (i int, j int not null, k int); insert into t1 values (null, 1, null); select * from t1; describe t1; drop table t1;" + +# +# Bug#19564: mysql displays NULL instead of space +# +--exec $MYSQL test -e "create table b19564 (i int, s1 char(1)); insert into b19564 values (1, 'x'); insert into b19564 values (2, NULL); insert into b19564 values (3, ' '); select * from b19564 order by i; drop table b19564;" +--exec $MYSQL -t test -e "create table b19564 (i int, s1 char(1)); insert into b19564 values (1, 'x'); insert into b19564 values (2, NULL); insert into b19564 values (3, ' '); select * from b19564 order by i; drop table b19564;" + +# +# Bug#21618: NULL shown as empty string in client +# +--exec $MYSQL test -e "select unhex('zz');" +--exec $MYSQL -t test -e "select unhex('zz');" + +# Bug#19265 describe command does not work from mysql prompt +# + +create table t1(a int, b varchar(255), c int); +--exec $MYSQL test -e "desc t1" +--exec $MYSQL test -e "desc t1\g" +drop table t1; + +--disable_parsing +# +# Bug#21042 mysql client segfaults on importing a mysqldump export +# +--error 1 +--exec $MYSQL test -e "connect verylongdatabasenamethatshouldblowthe256byteslongbufferincom_connectfunctionxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxkxendcccccccdxxxxxxxxxxxxxxxxxkskskskskkskskskskskskskskskskkskskskskkskskskskskskskskskend" 2>&1 +--enable_parsing + + +# +# Bug #20432: mysql client interprets commands in comments +# + +--let $file = $MYSQLTEST_VARDIR/tmp/bug20432.sql + +# if the client sees the 'use' within the comment, we haven't fixed +--exec echo "/*" > $file +--exec echo "use" >> $file +--exec echo "*/" >> $file +--exec $MYSQL < $file 2>&1 + +# SQL can have embedded comments => workie +--exec echo "select /*" > $file +--exec echo "use" >> $file +--exec echo "*/ 1" >> $file +--exec $MYSQL < $file 2>&1 + +# client commands on the other hand must be at BOL => error +--exec echo "/*" > $file +--exec echo "xxx" >> $file +--exec echo "*/ use" >> $file +--error 1 +--exec $MYSQL < $file 2>&1 + +# client comment recognized, but parameter missing => error +--exec echo "use" > $file +--exec $MYSQL < $file 2>&1 + +# Test exceutable comments +--exec echo "SELECT 1 /*! +1 */;" > $file +--exec echo "SELECT 1 /*M! +1 */;" >> $file +--exec echo "SELECT 1 /*!00000 +1 */;" >> $file +--exec echo "SELECT 1 /*M!00000 +1 */" >> $file +--exec $MYSQL < $file 2>&1 + +--remove_file $file + +# +# Bug #20328: mysql client interprets commands in comments +# +--let $file1 = $MYSQLTEST_VARDIR/tmp/bug20328_1.result +--let $file2 = $MYSQLTEST_VARDIR/tmp/bug20328_2.result +--exec $MYSQL -e "help" > $file1 +--exec $MYSQL -e "help " > $file2 +--diff_files $file1 $file2 +--remove_file $file1 +--remove_file $file2 + +# +# Bug #19216: Client crashes on long SELECT +# +# Create large SELECT +# - 3400 * 20 makes 68000 columns that is more than the +# max number that can fit in a 16 bit number. + +--perl +open(FILE,">","$ENV{'MYSQLTEST_VARDIR'}/tmp/b19216.tmp") or die; +print FILE "select\n"; +print FILE "'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a',\n" x 3400; +print FILE "'b';\n"; +close FILE; +EOF + +--disable_query_log +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/b19216.tmp >/dev/null +--enable_query_log + +--remove_file $MYSQLTEST_VARDIR/tmp/b19216.tmp + +# +# Bug #20103: Escaping with backslash does not work +# +--let $file = $MYSQLTEST_VARDIR/tmp/bug20103.sql +--exec echo "SET SQL_MODE = 'NO_BACKSLASH_ESCAPES';" > $file +--exec echo "SELECT '\';" >> $file +--exec $MYSQL < $file 2>&1 + +--exec echo "SET SQL_MODE = '';" > $file +--exec echo "SELECT '\';';" >> $file +--exec $MYSQL < $file 2>&1 +--remove_file $file + +# +# Bug#17583: mysql drops connection when stdout is not writable +# +create table t17583 (a int); +insert into t17583 (a) values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +# Close to the minimal data needed to exercise bug. +select count(*) from t17583; +--exec echo "select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) fr om t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; " |$MYSQL test >&- +drop table t17583; + +# +# Bug#20984: Reproducible MySQL client segmentation fault +# + additional tests for the "com_connect" function in mysql +# +# +--echo Test connect without db- or host-name => reconnect +--exec $MYSQL test -e "\r" 2>&1 +--exec $MYSQL test -e "connect" 2>&1 + +--echo Test connect with dbname only => new dbname, old hostname +--exec $MYSQL test -e "\r test" 2>&1 +--exec $MYSQL test -e "connect test" 2>&1 +--exec $MYSQL test -e "\rtest" 2>&1 +--error 1 +--exec $MYSQL test -e "connecttest" 2>&1 + +--echo Test connect with _invalid_ dbname only => new invalid dbname, old hostname +--error 1 +--exec $MYSQL test -e "\r invalid" 2>&1 +--error 1 +--exec $MYSQL test -e "connect invalid" 2>&1 + +--echo Test connect with dbname + hostname +--exec $MYSQL test -e "\r test localhost" 2>&1 +--exec $MYSQL test -e "connect test localhost" 2>&1 + +--echo Test connect with dbname + _invalid_ hostname +# Mask the errno of the error message +--replace_regex /\([0-9|-]*\)/(errno)/ +--error 1 +--exec $MYSQL test -e "\r test invalid_hostname" 2>&1 +--replace_regex /\([0-9|-]*\)/(errno)/ +--error 1 +--exec $MYSQL test -e "connect test invalid_hostname" 2>&1 + +--echo The commands reported in the bug report +--replace_regex /\([0-9|-]*\)/(errno)/ +--error 1 +--exec $MYSQL test -e "\r\r\n\r\n cyril\ has\ found\ a\ bug\ :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 2>&1 + +#--replace_regex /\([0-9|-]*\)/(errno)/ +#--error 1 +#--exec echo '\r\r\n\r\n cyril\ has\ found\ a\ bug\ :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | $MYSQL 2>&1 + +--echo Too long dbname +--error 1 +--exec $MYSQL test -e "\r test_really_long_dbnamexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx localhost" 2>&1 + +--echo Too long hostname +--replace_regex /\([0-9|-]*\)/(errno)/ +--error 1 +--exec $MYSQL test -e "\r test cyrils_superlonghostnameXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 2>&1 + + +# +# Bug #21412: mysql cmdline client allows backslash(es) +# as delimiter but can't recognize them +# + +# This should work just fine... +--write_file $MYSQLTEST_VARDIR/tmp/bug21412.sql +DELIMITER / +SELECT 1/ +EOF +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug21412.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/bug21412.sql; + +# This should give an error... +--write_file $MYSQLTEST_VARDIR/tmp/bug21412.sql +DELIMITER \ +EOF +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug21412.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/bug21412.sql; + +# As should this... +--write_file $MYSQLTEST_VARDIR/tmp/bug21412.sql +DELIMITER \\ +EOF +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug21412.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/bug21412.sql; + +# +# Some coverage of not normally used parts +# + +--disable_query_log +--exec $MYSQL test -e "show status" 2>&1 > /dev/null +--exec $MYSQL --help 2>&1 > /dev/null +--exec $MYSQL --version 2>&1 > /dev/null +--enable_query_log + +# +# bug #26851: Mysql Client --pager Buffer Overflow +# + +# allow error 7(invalid argument) since --pager does not always exist in mysql +--error 0,7 +--exec $MYSQL --pager="540bytelengthstringxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -e "select 1" > /dev/null 2>&1 +--exec $MYSQL --character-sets-dir="540bytelengthstringxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -e "select 1" 2>&1 + +# +# bug #30164: Using client side macro inside server side comments generates broken queries +# +--exec $MYSQL test -e "/*! \C latin1 */ select 1;" + +# +# Bug#29323 mysql client only accetps ANSI encoded files +# +--write_file $MYSQLTEST_VARDIR/tmp/bug29323.sql +select "This is a file starting with UTF8 BOM 0xEFBBBF"; +EOF +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug29323.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/bug29323.sql; + +# +# Bug #33812: mysql client incorrectly parsing DELIMITER +# +# The space and ; after delimiter are important +--exec $MYSQL -e "select 1 delimiter ;" + +# +# Bug #38158: mysql client regression, can't read dump files +# +--write_file $MYSQLTEST_VARDIR/tmp/bug38158.sql +-- Testing +-- +delimiter || +select 2 || +EOF +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug38158.sql 2>&1 +--exec $MYSQL -c < $MYSQLTEST_VARDIR/tmp/bug38158.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/bug38158.sql; + +# +# Bug #41437: Value stored in 'case' lacks charset, causees segfault +# +--exec $MYSQL -e "select @z:='1',@z=database()" + + +# +# Bug #31060: MySQL CLI parser bug 2 +# + +--write_file $MYSQLTEST_VARDIR/tmp/bug31060.sql +;DELIMITER DELIMITER +; +SELECT 1DELIMITER +DELIMITER ; +SELECT 1; +EOF + +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug31060.sql 2>&1 + +remove_file $MYSQLTEST_VARDIR/tmp/bug31060.sql; + +# +# Bug #39101: client -i (--ignore-spaces) option does not seem to work +# +--exec $MYSQL -i -e "SELECT COUNT (*)" +--exec $MYSQL --ignore-spaces -e "SELECT COUNT (*)" +--exec $MYSQL -b -i -e "SELECT COUNT (*)" + +# +# Bug#37268 'binary' character set makes CLI-internal commands case sensitive +# +--replace_regex /\([0-9|-]*\)/(errno)/ +--error 1 +--exec $MYSQL --default-character-set=binary test -e "CONNECT test invalid_hostname" 2>&1 +--exec $MYSQL --default-character-set=binary test -e "DELIMITER //" 2>&1 + +--echo End of 5.0 tests + +# +# Bug #29903: The CMake build method does not produce the embedded library. +# +--disable_query_log +--exec $MYSQL --server-arg=no-defaults test -e "quit" +--enable_query_log + +# +# Bug#26780: patch to add auto vertical output option to the cli. +# +# Make this wide enough that it will wrap almost everywhere. +--exec $MYSQL test --auto-vertical-output --table -e "SELECT 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0;" +# Too short to wrap. +--exec $MYSQL test --auto-vertical-output --table -e "SELECT 1;" + +# +# Bug #25146: Some warnings/errors not shown when using --show-warnings +# + +# This one should succeed with no warnings +--exec $MYSQL --show-warnings test -e "create table t1 (id int)" + +# This should succeed, with warnings about conversion from nonexistent engine +--exec $MYSQL --show-warnings test -e "create table t2 (id int) engine=nonexistent" + +# This should fail, with warnings as well +--error 1 +--exec $MYSQL --show-warnings test -e "create table t2 (id int) engine=nonexistent2" + +drop tables t1, t2; + +# +# mysql client with 'init-command' option +# +--exec $MYSQL --init-command="SET lc_messages=ru_RU" -e "SHOW VARIABLES LIKE 'lc_messages';" + +# +# Bug #27884: mysql --html does not quote HTML special characters in output +# +--write_file $MYSQLTEST_VARDIR/tmp/bug27884.sql +SELECT '< & >' AS `<`; +EOF +--exec $MYSQL --html test < $MYSQLTEST_VARDIR/tmp/bug27884.sql + +remove_file $MYSQLTEST_VARDIR/tmp/bug27884.sql; + + +# +# Bug #28203: mysql client + null byte +# +create table t1 (a char(5)); +insert into t1 values ('\0b\0'); +--exec $MYSQL test -e "select a from t1" +--exec $MYSQL -r test -e "select a from t1" +--exec $MYSQL -s test -e "select a from t1" +--exec $MYSQL --table test -e "select a from t1" +--exec $MYSQL --vertical test -e "select a from t1" +--exec $MYSQL --html test -e "select a from t1" +--exec $MYSQL --xml test -e "select a from t1" +drop table t1; + +--echo +--echo Bug #47147: mysql client option --skip-column-names does not apply to vertical output +--echo +--exec $MYSQL --skip-column-names --vertical test -e "select 1 as a" + +# +# Bug#57450: mysql client enter in an infinite loop if the standard input is a directory +# +--error 1 +--exec $MYSQL < . + +--echo + +--echo # +--echo # Bug #54899: --one-database option cannot handle DROP/CREATE DATABASE +--echo # commands. +--echo # +--write_file $MYSQLTEST_VARDIR/tmp/bug54899.sql +DROP DATABASE connected_db; +CREATE DATABASE connected_db; +USE connected_db; +CREATE TABLE `table_in_connected_db`(a INT); +EOF + +CREATE DATABASE connected_db; +--exec $MYSQL --one-database connected_db < $MYSQLTEST_VARDIR/tmp/bug54899.sql +USE connected_db; +SHOW TABLES; +DROP DATABASE connected_db; +--remove_file $MYSQLTEST_VARDIR/tmp/bug54899.sql + +--echo + +--echo # +--echo # Testing --one-database option +--echo # +--write_file $MYSQLTEST_VARDIR/tmp/one_db.sql +CREATE TABLE t1 (i INT); +CREATE TABLE test.t1 (i INT); +USE test; +# Following statements should be filtered. +CREATE TABLE connected_db.t2 (i INT); +CREATE TABLE t2 (i INT); +EOF + +CREATE DATABASE connected_db; +--exec $MYSQL --one-database connected_db < $MYSQLTEST_VARDIR/tmp/one_db.sql +SHOW TABLES IN connected_db; +SHOW TABLES IN test; +USE test; +DROP TABLE t1; +DROP DATABASE connected_db; +--remove_file $MYSQLTEST_VARDIR/tmp/one_db.sql + +--echo +--write_file $MYSQLTEST_VARDIR/tmp/one_db.sql +CREATE DATABASE test1; +USE test1; +USE test1; +# Following statements should be filtered. +CREATE TABLE connected_db.t1 (i INT); +EOF + +--exec $MYSQL --one-database test < $MYSQLTEST_VARDIR/tmp/one_db.sql +SHOW TABLES IN test; +SHOW TABLES IN test1; +DROP DATABASE test1; +--remove_file $MYSQLTEST_VARDIR/tmp/one_db.sql + +--echo + +--echo # +--echo # Checking --one-database option followed by the execution of +--echo # connect command. +--echo # +--write_file $MYSQLTEST_VARDIR/tmp/one_db.sql +CREATE TABLE t1 (i INT); +CREATE TABLE test.t1 (i INT); +CONNECT test; +CREATE TABLE connected_db.t2 (i INT); +CREATE TABLE t2 (i INT); +USE connected_db; +# Following statements should be filtered. +CREATE TABLE connected_db.t3 (i INT); +CREATE TABLE t3 (i INT); +EOF + +CREATE DATABASE connected_db; +--exec $MYSQL --one-database connected_db < $MYSQLTEST_VARDIR/tmp/one_db.sql +SHOW TABLES IN connected_db; +SHOW TABLES IN test; +DROP TABLE test.t1; +DROP TABLE test.t2; +DROP DATABASE connected_db; +--remove_file $MYSQLTEST_VARDIR/tmp/one_db.sql + +--echo + +--echo # +--echo # Checking --one-database option with no database specified +--echo # at command-line. +--echo # +--write_file $MYSQLTEST_VARDIR/tmp/one_db.sql +# All following statements should be filtered. +CREATE TABLE t1 (i INT); +CREATE TABLE test.t1 (i INT); +USE test; +CREATE TABLE test.t2 (i INT); +CREATE TABLE t2 (i INT); +EOF + +--exec $MYSQL --one-database < $MYSQLTEST_VARDIR/tmp/one_db.sql +SHOW TABLES IN test; +--remove_file $MYSQLTEST_VARDIR/tmp/one_db.sql + +--echo + +--echo # +--echo # Checking --one-database option with non_existent_db +--echo # specified with USE command +--echo # + +# CASE 1 : When 'connected_db' database exists and passed at commandline. +--write_file $MYSQLTEST_VARDIR/tmp/one_db_1.sql +CREATE TABLE `table_in_connected_db`(i INT); +USE non_existent_db; +# Following statement should be filtered out. +CREATE TABLE `table_in_non_existent_db`(i INT); +EOF + +# CASE 2 : When 'connected_db' database exists but dropped and recreated in +# load file. +--write_file $MYSQLTEST_VARDIR/tmp/one_db_2.sql +DROP DATABASE connected_db; +CREATE DATABASE connected_db; +USE non_existent_db; +# Following statements should be filtered out. +CREATE TABLE `table_in_non_existent_db`(i INT); +USE connected_db; +# Following statements should not be filtered out. +CREATE TABLE `table_in_connected_db`(i INT); +EOF + +CREATE DATABASE connected_db; +--exec $MYSQL --one-database connected_db < $MYSQLTEST_VARDIR/tmp/one_db_1.sql +SHOW TABLES IN connected_db; +--echo +--exec $MYSQL --one-database connected_db < $MYSQLTEST_VARDIR/tmp/one_db_2.sql +SHOW TABLES IN connected_db; +DROP DATABASE connected_db; + +--remove_file $MYSQLTEST_VARDIR/tmp/one_db_1.sql +--remove_file $MYSQLTEST_VARDIR/tmp/one_db_2.sql + +# +# USE and names with backticks +# +--write_file $MYSQLTEST_VARDIR/tmp/backticks.sql +\u aa`bb``cc +SELECT DATABASE(); +USE test +SELECT DATABASE(); +USE aa`bb``cc +SELECT DATABASE(); +USE test +SELECT DATABASE(); +USE `aa``bb````cc` +SELECT DATABASE(); +EOF +create database `aa``bb````cc`; +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/backticks.sql +drop database `aa``bb````cc`; + +# +# MySQL Bug#13639125 DELIMITER STRIPS THE NEXT NEW LINE IN A SQL STATEMENT +# +--write_file $MYSQLTEST_VARDIR/tmp/13639125.sql +select ">> +delimiter +<<" as a; +EOF +--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/13639125.sql + +# +# --skip-column-names and alignment +# +--exec $MYSQL -t -N -e "SELECT 'a' union select 'aaaaaaaaaaaaaaaaa'" + +--echo # +--echo # Start of 10.1 tests +--echo # + +--echo # +--echo # MDEV-6572 "USE dbname" with a bad sequence erroneously connects to a wrong database +--echo # + +--echo # +--echo # End of 10.1 tests +--echo # + + +--write_file $MYSQLTEST_VARDIR/tmp/mdev-6572.sql +SET NAMES utf8; +USE test😁 ; +EOF +--error 1 +--exec $MYSQL --default-character-set=utf8 < $MYSQLTEST_VARDIR/tmp/mdev-6572.sql 2>&1 +--remove_file $MYSQLTEST_VARDIR/tmp/mdev-6572.sql + +set GLOBAL sql_mode=default; +--echo +--echo End of tests + +# +# MDEV-13187 incorrect backslash parsing in clients +# +create table `a1\``b1` (a int); +show tables; +insert `a1\``b1` values (1),(2); +show create table `a1\``b1`; +--exec $MYSQL_DUMP --compact test +--exec $MYSQL_DUMP test > $MYSQLTEST_VARDIR/tmp/bug.sql +insert `a1\``b1` values (4),(5); +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug.sql +show create table `a1\``b1`; +select * from `a1\``b1`; +drop table `a1\``b1`; + +# same with ansi_quotes +set sql_mode=ansi_quotes; +create table "a1\""b1" (a int); +show tables; +insert "a1\""b1" values (1),(2); +show create table "a1\""b1"; +--exec $MYSQL_DUMP --compact --compatible=postgres test +--exec $MYSQL_DUMP --compatible=postgres test > $MYSQLTEST_VARDIR/tmp/bug.sql +insert "a1\""b1" values (4),(5); +--exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/bug.sql +show create table "a1\""b1"; +select * from "a1\""b1"; +drop table "a1\""b1"; +set sql_mode=default; ++ ++# ++# mysql --local-infile ++# ++--let $ldli = load data local infile '$MYSQLTEST_VARDIR/tmp/bug.sql' into table test.t1; ++create table t1 (a text); ++--exec $MYSQL -e "$ldli" ++select count(*) from t1; truncate table t1; ++--exec $MYSQL --enable-local-infile -e "$ldli" ++select count(*) from t1; truncate table t1; ++--error 1 ++--exec $MYSQL --disable-local-infile -e "$ldli" ++select count(*) from t1; truncate table t1; ++--echo ### FIXME: update libmariadb ++#--error 1 ++#--exec $MYSQL -e "/*q*/$ldli" ++#select count(*) from t1; truncate table t1; ++#--exec $MYSQL --enable-local-infile -e "/*q*/$ldli" ++#select count(*) from t1; truncate table t1; ++# --error 1 ++# --exec $MYSQL --disable-local-infile -e "/*q*/$ldli" ++#select count(*) from t1; truncate table t1; ++drop table t1; diff --cc mysql-test/main/mysqlbinlog_row_minimal.result index 680fd8196a8,00000000000..a919cda529e mode 100644,000000..100644 --- a/mysql-test/main/mysqlbinlog_row_minimal.result +++ b/mysql-test/main/mysqlbinlog_row_minimal.result @@@ -1,332 -1,0 +1,447 @@@ +CREATE TABLE t1 (pk INT PRIMARY KEY, f1 INT, f2 INT, f3 TINYINT, f4 MEDIUMINT, f5 BIGINT, f6 INT, f7 INT, f8 char(1)); +CREATE TABLE t2 (pk INT PRIMARY KEY, f1 INT, f2 INT, f3 INT, f4 INT, f5 MEDIUMINT, f6 INT, f7 INT, f8 char(1)); +INSERT INTO t1 VALUES (10, 1, 2, 3, 4, 5, 6, 7, ""); +INSERT INTO t1 VALUES (11, 1, 2, 3, 4, 5, 6, 7, NULL); +INSERT INTO t1 VALUES (12, 1, 2, 3, NULL, 5, 6, 7, "A"); +INSERT INTO t1 VALUES (13, 1, 2, 3, 0, 5, 6, 7, "A"); +INSERT INTO t2 SELECT * FROM t1; +UPDATE t2 SET f4=5 WHERE f4>0 or f4 is NULL; +DELETE FROM t1; +DELETE FROM t2; +FLUSH BINARY LOGS; +/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; +/*!40019 SET @@session.max_insert_delayed_threads=0*/; +/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; +DELIMITER /*!*/; +# at 4 +#<date> server id 1 end_log_pos 256 CRC32 XXX Start: xxx +ROLLBACK/*!*/; +# at 256 +#<date> server id 1 end_log_pos 285 CRC32 XXX Gtid list [] +# at 285 +#<date> server id 1 end_log_pos 329 CRC32 XXX Binlog checkpoint master-bin.000001 +# at 329 +#<date> server id 1 end_log_pos 371 CRC32 XXX GTID 0-1-1 ddl +/*!100101 SET @@session.skip_parallel_replication=0*//*!*/; +/*!100001 SET @@session.gtid_domain_id=0*//*!*/; +/*!100001 SET @@session.server_id=1*//*!*/; +/*!100001 SET @@session.gtid_seq_no=1*//*!*/; +# at 371 +#<date> server id 1 end_log_pos 555 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 +use `test`/*!*/; +SET TIMESTAMP=X/*!*/; +SET @@session.pseudo_thread_id=5/*!*/; +SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1, @@session.check_constraint_checks=1/*!*/; +SET @@session.sql_mode=1411383296/*!*/; +SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; +/*!\C latin1 *//*!*/; +SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/; +SET @@session.lc_time_names=0/*!*/; +SET @@session.collation_database=DEFAULT/*!*/; +CREATE TABLE t1 (pk INT PRIMARY KEY, f1 INT, f2 INT, f3 TINYINT, f4 MEDIUMINT, f5 BIGINT, f6 INT, f7 INT, f8 char(1)) +/*!*/; +# at 555 +#<date> server id 1 end_log_pos 597 CRC32 XXX GTID 0-1-2 ddl +/*!100001 SET @@session.gtid_seq_no=2*//*!*/; +# at 597 +#<date> server id 1 end_log_pos 774 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 +SET TIMESTAMP=X/*!*/; +CREATE TABLE t2 (pk INT PRIMARY KEY, f1 INT, f2 INT, f3 INT, f4 INT, f5 MEDIUMINT, f6 INT, f7 INT, f8 char(1)) +/*!*/; +# at 774 +#<date> server id 1 end_log_pos 816 CRC32 XXX GTID 0-1-3 +/*!100001 SET @@session.gtid_seq_no=3*//*!*/; +BEGIN +/*!*/; +# at 816 +# at 890 +#<date> server id 1 end_log_pos 890 CRC32 XXX Annotate_rows: +#Q> INSERT INTO t1 VALUES (10, 1, 2, 3, 4, 5, 6, 7, "") +#<date> server id 1 end_log_pos 946 CRC32 XXX Table_map: `test`.`t1` mapped to number num +# at 946 +#<date> server id 1 end_log_pos 1015 CRC32 XXX Write_rows: table id 32 flags: STMT_END_F +### INSERT INTO `test`.`t1` +### SET +### @1=10 /* INT meta=0 nullable=0 is_null=0 */ +### @2=1 /* INT meta=0 nullable=1 is_null=0 */ +### @3=2 /* INT meta=0 nullable=1 is_null=0 */ +### @4=3 /* TINYINT meta=0 nullable=1 is_null=0 */ +### @5=4 /* MEDIUMINT meta=0 nullable=1 is_null=0 */ +### @6=5 /* LONGINT meta=0 nullable=1 is_null=0 */ +### @7=6 /* INT meta=0 nullable=1 is_null=0 */ +### @8=7 /* INT meta=0 nullable=1 is_null=0 */ +### @9='' /* STRING(1) meta=65025 nullable=1 is_null=0 */ +# Number of rows: 1 +# at 1015 +#<date> server id 1 end_log_pos 1088 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 +SET TIMESTAMP=X/*!*/; +COMMIT +/*!*/; +# at 1088 +#<date> server id 1 end_log_pos 1130 CRC32 XXX GTID 0-1-4 +/*!100001 SET @@session.gtid_seq_no=4*//*!*/; +BEGIN +/*!*/; +# at 1130 +# at 1206 +#<date> server id 1 end_log_pos 1206 CRC32 XXX Annotate_rows: +#Q> INSERT INTO t1 VALUES (11, 1, 2, 3, 4, 5, 6, 7, NULL) +#<date> server id 1 end_log_pos 1262 CRC32 XXX Table_map: `test`.`t1` mapped to number num +# at 1262 +#<date> server id 1 end_log_pos 1330 CRC32 XXX Write_rows: table id 32 flags: STMT_END_F +### INSERT INTO `test`.`t1` +### SET +### @1=11 /* INT meta=0 nullable=0 is_null=0 */ +### @2=1 /* INT meta=0 nullable=1 is_null=0 */ +### @3=2 /* INT meta=0 nullable=1 is_null=0 */ +### @4=3 /* TINYINT meta=0 nullable=1 is_null=0 */ +### @5=4 /* MEDIUMINT meta=0 nullable=1 is_null=0 */ +### @6=5 /* LONGINT meta=0 nullable=1 is_null=0 */ +### @7=6 /* INT meta=0 nullable=1 is_null=0 */ +### @8=7 /* INT meta=0 nullable=1 is_null=0 */ +### @9=NULL /* STRING(1) meta=65025 nullable=1 is_null=1 */ +# Number of rows: 1 +# at 1330 +#<date> server id 1 end_log_pos 1403 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 +SET TIMESTAMP=X/*!*/; +COMMIT +/*!*/; +# at 1403 +#<date> server id 1 end_log_pos 1445 CRC32 XXX GTID 0-1-5 +/*!100001 SET @@session.gtid_seq_no=5*//*!*/; +BEGIN +/*!*/; +# at 1445 +# at 1523 +#<date> server id 1 end_log_pos 1523 CRC32 XXX Annotate_rows: +#Q> INSERT INTO t1 VALUES (12, 1, 2, 3, NULL, 5, 6, 7, "A") +#<date> server id 1 end_log_pos 1579 CRC32 XXX Table_map: `test`.`t1` mapped to number num +# at 1579 +#<date> server id 1 end_log_pos 1646 CRC32 XXX Write_rows: table id 32 flags: STMT_END_F +### INSERT INTO `test`.`t1` +### SET +### @1=12 /* INT meta=0 nullable=0 is_null=0 */ +### @2=1 /* INT meta=0 nullable=1 is_null=0 */ +### @3=2 /* INT meta=0 nullable=1 is_null=0 */ +### @4=3 /* TINYINT meta=0 nullable=1 is_null=0 */ +### @5=NULL /* MEDIUMINT meta=0 nullable=1 is_null=1 */ +### @6=5 /* LONGINT meta=0 nullable=1 is_null=0 */ +### @7=6 /* INT meta=0 nullable=1 is_null=0 */ +### @8=7 /* INT meta=0 nullable=1 is_null=0 */ +### @9='A' /* STRING(1) meta=65025 nullable=1 is_null=0 */ +# Number of rows: 1 +# at 1646 +#<date> server id 1 end_log_pos 1719 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 +SET TIMESTAMP=X/*!*/; +COMMIT +/*!*/; +# at 1719 +#<date> server id 1 end_log_pos 1761 CRC32 XXX GTID 0-1-6 +/*!100001 SET @@session.gtid_seq_no=6*//*!*/; +BEGIN +/*!*/; +# at 1761 +# at 1836 +#<date> server id 1 end_log_pos 1836 CRC32 XXX Annotate_rows: +#Q> INSERT INTO t1 VALUES (13, 1, 2, 3, 0, 5, 6, 7, "A") +#<date> server id 1 end_log_pos 1892 CRC32 XXX Table_map: `test`.`t1` mapped to number num +# at 1892 +#<date> server id 1 end_log_pos 1962 CRC32 XXX Write_rows: table id 32 flags: STMT_END_F +### INSERT INTO `test`.`t1` +### SET +### @1=13 /* INT meta=0 nullable=0 is_null=0 */ +### @2=1 /* INT meta=0 nullable=1 is_null=0 */ +### @3=2 /* INT meta=0 nullable=1 is_null=0 */ +### @4=3 /* TINYINT meta=0 nullable=1 is_null=0 */ +### @5=0 /* MEDIUMINT meta=0 nullable=1 is_null=0 */ +### @6=5 /* LONGINT meta=0 nullable=1 is_null=0 */ +### @7=6 /* INT meta=0 nullable=1 is_null=0 */ +### @8=7 /* INT meta=0 nullable=1 is_null=0 */ +### @9='A' /* STRING(1) meta=65025 nullable=1 is_null=0 */ +# Number of rows: 1 +# at 1962 +#<date> server id 1 end_log_pos 2035 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 +SET TIMESTAMP=X/*!*/; +COMMIT +/*!*/; +# at 2035 +#<date> server id 1 end_log_pos 2077 CRC32 XXX GTID 0-1-7 +/*!100001 SET @@session.gtid_seq_no=7*//*!*/; +BEGIN +/*!*/; +# at 2077 +# at 2131 +#<date> server id 1 end_log_pos 2131 CRC32 XXX Annotate_rows: +#Q> INSERT INTO t2 SELECT * FROM t1 +#<date> server id 1 end_log_pos 2187 CRC32 XXX Table_map: `test`.`t2` mapped to number num +# at 2187 +#<date> server id 1 end_log_pos 2354 CRC32 XXX Write_rows: table id 33 flags: STMT_END_F +### INSERT INTO `test`.`t2` +### SET +### @1=10 /* INT meta=0 nullable=0 is_null=0 */ +### @2=1 /* INT meta=0 nullable=1 is_null=0 */ +### @3=2 /* INT meta=0 nullable=1 is_null=0 */ +### @4=3 /* INT meta=0 nullable=1 is_null=0 */ +### @5=4 /* INT meta=0 nullable=1 is_null=0 */ +### @6=5 /* MEDIUMINT meta=0 nullable=1 is_null=0 */ +### @7=6 /* INT meta=0 nullable=1 is_null=0 */ +### @8=7 /* INT meta=0 nullable=1 is_null=0 */ +### @9='' /* STRING(1) meta=65025 nullable=1 is_null=0 */ +### INSERT INTO `test`.`t2` +### SET +### @1=11 /* INT meta=0 nullable=0 is_null=0 */ +### @2=1 /* INT meta=0 nullable=1 is_null=0 */ +### @3=2 /* INT meta=0 nullable=1 is_null=0 */ +### @4=3 /* INT meta=0 nullable=1 is_null=0 */ +### @5=4 /* INT meta=0 nullable=1 is_null=0 */ +### @6=5 /* MEDIUMINT meta=0 nullable=1 is_null=0 */ +### @7=6 /* INT meta=0 nullable=1 is_null=0 */ +### @8=7 /* INT meta=0 nullable=1 is_null=0 */ +### @9=NULL /* STRING(1) meta=65025 nullable=1 is_null=1 */ +### INSERT INTO `test`.`t2` +### SET +### @1=12 /* INT meta=0 nullable=0 is_null=0 */ +### @2=1 /* INT meta=0 nullable=1 is_null=0 */ +### @3=2 /* INT meta=0 nullable=1 is_null=0 */ +### @4=3 /* INT meta=0 nullable=1 is_null=0 */ +### @5=NULL /* INT meta=0 nullable=1 is_null=1 */ +### @6=5 /* MEDIUMINT meta=0 nullable=1 is_null=0 */ +### @7=6 /* INT meta=0 nullable=1 is_null=0 */ +### @8=7 /* INT meta=0 nullable=1 is_null=0 */ +### @9='A' /* STRING(1) meta=65025 nullable=1 is_null=0 */ +### INSERT INTO `test`.`t2` +### SET +### @1=13 /* INT meta=0 nullable=0 is_null=0 */ +### @2=1 /* INT meta=0 nullable=1 is_null=0 */ +### @3=2 /* INT meta=0 nullable=1 is_null=0 */ +### @4=3 /* INT meta=0 nullable=1 is_null=0 */ +### @5=0 /* INT meta=0 nullable=1 is_null=0 */ +### @6=5 /* MEDIUMINT meta=0 nullable=1 is_null=0 */ +### @7=6 /* INT meta=0 nullable=1 is_null=0 */ +### @8=7 /* INT meta=0 nullable=1 is_null=0 */ +### @9='A' /* STRING(1) meta=65025 nullable=1 is_null=0 */ +# Number of rows: 4 +# at 2354 +#<date> server id 1 end_log_pos 2427 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 +SET TIMESTAMP=X/*!*/; +COMMIT +/*!*/; +# at 2427 +#<date> server id 1 end_log_pos 2469 CRC32 XXX GTID 0-1-8 +/*!100001 SET @@session.gtid_seq_no=8*//*!*/; +BEGIN +/*!*/; +# at 2469 +# at 2535 +#<date> server id 1 end_log_pos 2535 CRC32 XXX Annotate_rows: +#Q> UPDATE t2 SET f4=5 WHERE f4>0 or f4 is NULL +#<date> server id 1 end_log_pos 2591 CRC32 XXX Table_map: `test`.`t2` mapped to number num +# at 2591 ++<<<<<<< HEAD:mysql-test/main/mysqlbinlog_row_minimal.result +#<date> server id 1 end_log_pos 2665 CRC32 XXX Update_rows: table id 33 flags: STMT_END_F ++||||||| merged common ancestors ++#<date> server id 1 end_log_pos 2665 CRC32 XXX Update_rows: table id 32 flags: STMT_END_F ++======= ++#<date> server id 1 end_log_pos 2657 CRC32 XXX Update_rows: table id 32 flags: STMT_END_F ++>>>>>>> 10.2:mysql-test/r/mysqlbinlog_row_minimal.result +### UPDATE `test`.`t2` +### WHERE +### @1=10 /* INT meta=0 nullable=0 is_null=0 */ - ### @5=4 /* INT meta=0 nullable=1 is_null=0 */ +### SET +### @5=5 /* INT meta=0 nullable=1 is_null=0 */ +### UPDATE `test`.`t2` +### WHERE +### @1=11 /* INT meta=0 nullable=0 is_null=0 */ - ### @5=4 /* INT meta=0 nullable=1 is_null=0 */ +### SET +### @5=5 /* INT meta=0 nullable=1 is_null=0 */ +### UPDATE `test`.`t2` +### WHERE +### @1=12 /* INT meta=0 nullable=0 is_null=0 */ - ### @5=NULL /* INT meta=0 nullable=1 is_null=1 */ +### SET +### @5=5 /* INT meta=0 nullable=1 is_null=0 */ ++<<<<<<< HEAD:mysql-test/main/mysqlbinlog_row_minimal.result +# Number of rows: 3 +# at 2665 +#<date> server id 1 end_log_pos 2738 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 ++||||||| merged common ancestors ++# at 2665 ++#<date> server id 1 end_log_pos 2738 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 ++======= ++# at 2657 ++#<date> server id 1 end_log_pos 2730 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 ++>>>>>>> 10.2:mysql-test/r/mysqlbinlog_row_minimal.result +SET TIMESTAMP=X/*!*/; +COMMIT +/*!*/; - # at 2738 - #<date> server id 1 end_log_pos 2780 CRC32 XXX GTID 0-1-9 ++# at 2730 ++#<date> server id 1 end_log_pos 2772 CRC32 XXX GTID 0-1-9 +/*!100001 SET @@session.gtid_seq_no=9*//*!*/; +BEGIN +/*!*/; - # at 2780 - # at 2817 - #<date> server id 1 end_log_pos 2817 CRC32 XXX Annotate_rows: ++# at 2772 ++# at 2809 ++#<date> server id 1 end_log_pos 2809 CRC32 XXX Annotate_rows: +#Q> DELETE FROM t1 ++<<<<<<< HEAD:mysql-test/main/mysqlbinlog_row_minimal.result +#<date> server id 1 end_log_pos 2873 CRC32 XXX Table_map: `test`.`t1` mapped to number num +# at 2873 +#<date> server id 1 end_log_pos 2927 CRC32 XXX Delete_rows: table id 32 flags: STMT_END_F ++||||||| merged common ancestors ++#<date> server id 1 end_log_pos 2873 CRC32 XXX Table_map: `test`.`t1` mapped to number num ++# at 2873 ++#<date> server id 1 end_log_pos 2927 CRC32 XXX Delete_rows: table id 31 flags: STMT_END_F ++======= ++#<date> server id 1 end_log_pos 2865 CRC32 XXX Table_map: `test`.`t1` mapped to number num ++# at 2865 ++#<date> server id 1 end_log_pos 2919 CRC32 XXX Delete_rows: table id 31 flags: STMT_END_F ++>>>>>>> 10.2:mysql-test/r/mysqlbinlog_row_minimal.result +### DELETE FROM `test`.`t1` +### WHERE +### @1=10 /* INT meta=0 nullable=0 is_null=0 */ +### DELETE FROM `test`.`t1` +### WHERE +### @1=11 /* INT meta=0 nullable=0 is_null=0 */ +### DELETE FROM `test`.`t1` +### WHERE +### @1=12 /* INT meta=0 nullable=0 is_null=0 */ +### DELETE FROM `test`.`t1` +### WHERE +### @1=13 /* INT meta=0 nullable=0 is_null=0 */ ++<<<<<<< HEAD:mysql-test/main/mysqlbinlog_row_minimal.result +# Number of rows: 4 +# at 2927 +#<date> server id 1 end_log_pos 3000 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 ++||||||| merged common ancestors ++# at 2927 ++#<date> server id 1 end_log_pos 3000 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 ++======= ++# at 2919 ++#<date> server id 1 end_log_pos 2992 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 ++>>>>>>> 10.2:mysql-test/r/mysqlbinlog_row_minimal.result +SET TIMESTAMP=X/*!*/; +COMMIT +/*!*/; - # at 3000 - #<date> server id 1 end_log_pos 3042 CRC32 XXX GTID 0-1-10 ++# at 2992 ++#<date> server id 1 end_log_pos 3034 CRC32 XXX GTID 0-1-10 +/*!100001 SET @@session.gtid_seq_no=10*//*!*/; +BEGIN +/*!*/; - # at 3042 - # at 3079 - #<date> server id 1 end_log_pos 3079 CRC32 XXX Annotate_rows: ++# at 3034 ++# at 3071 ++#<date> server id 1 end_log_pos 3071 CRC32 XXX Annotate_rows: +#Q> DELETE FROM t2 ++<<<<<<< HEAD:mysql-test/main/mysqlbinlog_row_minimal.result +#<date> server id 1 end_log_pos 3135 CRC32 XXX Table_map: `test`.`t2` mapped to number num +# at 3135 +#<date> server id 1 end_log_pos 3189 CRC32 XXX Delete_rows: table id 33 flags: STMT_END_F ++||||||| merged common ancestors ++#<date> server id 1 end_log_pos 3135 CRC32 XXX Table_map: `test`.`t2` mapped to number num ++# at 3135 ++#<date> server id 1 end_log_pos 3189 CRC32 XXX Delete_rows: table id 32 flags: STMT_END_F ++======= ++#<date> server id 1 end_log_pos 3127 CRC32 XXX Table_map: `test`.`t2` mapped to number num ++# at 3127 ++#<date> server id 1 end_log_pos 3181 CRC32 XXX Delete_rows: table id 32 flags: STMT_END_F ++>>>>>>> 10.2:mysql-test/r/mysqlbinlog_row_minimal.result +### DELETE FROM `test`.`t2` +### WHERE +### @1=10 /* INT meta=0 nullable=0 is_null=0 */ +### DELETE FROM `test`.`t2` +### WHERE +### @1=11 /* INT meta=0 nullable=0 is_null=0 */ +### DELETE FROM `test`.`t2` +### WHERE +### @1=12 /* INT meta=0 nullable=0 is_null=0 */ +### DELETE FROM `test`.`t2` +### WHERE +### @1=13 /* INT meta=0 nullable=0 is_null=0 */ ++<<<<<<< HEAD:mysql-test/main/mysqlbinlog_row_minimal.result +# Number of rows: 4 +# at 3189 +#<date> server id 1 end_log_pos 3262 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 ++||||||| merged common ancestors ++# at 3189 ++#<date> server id 1 end_log_pos 3262 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 ++======= ++# at 3181 ++#<date> server id 1 end_log_pos 3254 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 ++>>>>>>> 10.2:mysql-test/r/mysqlbinlog_row_minimal.result +SET TIMESTAMP=X/*!*/; +COMMIT +/*!*/; - # at 3262 - #<date> server id 1 end_log_pos 3310 CRC32 XXX Rotate to master-bin.000002 pos: 4 ++# at 3254 ++#<date> server id 1 end_log_pos 3302 CRC32 XXX Rotate to master-bin.000002 pos: 4 ++DELIMITER ; ++# End of log file ++ROLLBACK /* added by mysqlbinlog */; ++/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; ++/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; ++DROP TABLE t1,t2; ++CREATE TABLE `t1` ( ++`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, ++`is_deleted` BIT(1) DEFAULT b'0', ++`last_updated` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, ++`ref_id` BIGINT(20) UNSIGNED NOT NULL, ++PRIMARY KEY (`id`), ++KEY `last_updated_KEY` (`last_updated`) ++); ++CREATE TABLE `t2` ( ++`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, ++`short_desc` VARCHAR(50) NOT NULL, ++PRIMARY KEY (`id`) ++); ++INSERT INTO t2 (id, short_desc) VALUES (1, 'test'); ++INSERT INTO t1 (id, is_deleted, ref_id) VALUES (1, b'0', 1); ++FLUSH BINARY LOGS; ++UPDATE t1 t1 INNER JOIN t2 t2 ON t1.ref_id = t2.id ++SET t1.is_deleted = TRUE ++WHERE t1.id = 1; ++FLUSH BINARY LOGS; ++/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/; ++/*!40019 SET @@session.max_insert_delayed_threads=0*/; ++/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; ++DELIMITER /*!*/; ++# at 387 ++#<date> server id 1 end_log_pos 429 CRC32 XXX GTID 0-1-16 ++/*!100101 SET @@session.skip_parallel_replication=0*//*!*/; ++/*!100001 SET @@session.gtid_domain_id=0*//*!*/; ++/*!100001 SET @@session.server_id=1*//*!*/; ++/*!100001 SET @@session.gtid_seq_no=16*//*!*/; ++BEGIN ++/*!*/; ++# at 429 ++# at 543 ++#<date> server id 1 end_log_pos 543 CRC32 XXX Annotate_rows: ++#Q> UPDATE t1 t1 INNER JOIN t2 t2 ON t1.ref_id = t2.id ++#Q> SET t1.is_deleted = TRUE ++#Q> WHERE t1.id = ++#<date> server id 1 end_log_pos 594 CRC32 XXX Table_map: `test`.`t1` mapped to number 34 ++# at 594 ++#<date> server id 1 end_log_pos 643 CRC32 XXX Update_rows: table id 34 flags: STMT_END_F ++### UPDATE `test`.`t1` ++### WHERE ++### @1=1 /* LONGINT meta=0 nullable=0 is_null=0 */ ++### SET ++### @2=b'1' /* BIT(1) meta=1 nullable=1 is_null=0 */ ++### @3=X /* TIMESTAMP(0) meta=0 nullable=0 is_null=0 */ ++# at 643 ++#<date> server id 1 end_log_pos 725 CRC32 XXX Query thread_id=5 exec_time=x error_code=0 ++SET TIMESTAMP=X/*!*/; ++SET @@session.pseudo_thread_id=5/*!*/; ++SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1, @@session.check_constraint_checks=1/*!*/; ++SET @@session.sql_mode=1411383296/*!*/; ++SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; ++/*!\C latin1 *//*!*/; ++SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/; ++SET @@session.lc_time_names=0/*!*/; ++SET @@session.collation_database=DEFAULT/*!*/; ++COMMIT ++/*!*/; ++# at 725 ++#<date> server id 1 end_log_pos 773 CRC32 XXX Rotate to master-bin.000004 pos: 4 +DELIMITER ; +# End of log file +ROLLBACK /* added by mysqlbinlog */; +/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; +/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; +DROP TABLE t1,t2; diff --cc mysql-test/main/subselect2.result index 31e7774734e,00000000000..cae0f2286c1 mode 100644,000000..100644 --- a/mysql-test/main/subselect2.result +++ b/mysql-test/main/subselect2.result @@@ -1,396 -1,0 +1,418 @@@ +drop table if exists t1, t2, t3, t4; +set @subselect2_test_tmp=@@optimizer_switch; +set optimizer_switch='semijoin=on,firstmatch=on,mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; +CREATE TABLE t1 +( +DOCID VARCHAR(32)BINARY NOT NULL +, UUID VARCHAR(32)BINARY NOT NULL +, MIMETYPE VARCHAR(80)BINARY +, CONTENTDATA LONGBLOB +, CONTENTSIZE INTEGER +, VERSIONID INTEGER +, REPID VARCHAR(32)BINARY +, MODIFIED TIMESTAMP +, MODIFIER VARCHAR(255)BINARY +, ORIGINATOR INTEGER +, PRIMARY KEY ( DOCID ) +) ENGINE=InnoDB +; +INSERT IGNORE INTO t1 (DOCID) VALUES ("1"), ("2"); +Warnings: +Warning 1364 Field 'UUID' doesn't have a default value +CREATE TABLE t2 +( +DOCID VARCHAR(32)BINARY NOT NULL +, DOCNAME VARCHAR(255)BINARY NOT NULL +, DOCTYPEID VARCHAR(32)BINARY NOT NULL +, FOLDERID VARCHAR(32)BINARY NOT NULL +, AUTHOR VARCHAR(255)BINARY +, CREATED TIMESTAMP NOT NULL +, TITLE VARCHAR(255)BINARY +, SUBTITLE VARCHAR(255)BINARY +, DOCABSTRACT LONGBLOB +, PUBLISHDATE TIMESTAMP +, EXPIRATIONDATE TIMESTAMP +, LOCKEDBY VARCHAR(80)BINARY +, STATUS VARCHAR(80)BINARY +, PARENTDOCID VARCHAR(32)BINARY +, REPID VARCHAR(32)BINARY +, MODIFIED TIMESTAMP NOT NULL +, MODIFIER VARCHAR(255)BINARY NOT NULL +, PUBLISHSTATUS INTEGER +, ORIGINATOR INTEGER +, PRIMARY KEY ( DOCID ) +) ENGINE=InnoDB +; +CREATE INDEX DDOCTYPEID_IDX ON t2 (DOCTYPEID); +CREATE INDEX DFOLDERID_IDX ON t2 (FOLDERID); +CREATE TABLE t3 +( +FOLDERID VARCHAR(32)BINARY NOT NULL +, FOLDERNAME VARCHAR(255)BINARY NOT NULL +, CREATOR VARCHAR(255)BINARY +, CREATED TIMESTAMP NOT NULL +, DESCRIPTION VARCHAR(255)BINARY +, FOLDERTYPE INTEGER NOT NULL +, MODIFIED TIMESTAMP +, MODIFIER VARCHAR(255)BINARY +, FOLDERSIZE INTEGER NOT NULL +, PARENTID VARCHAR(32)BINARY +, REPID VARCHAR(32)BINARY +, ORIGINATOR INTEGER +, PRIMARY KEY ( FOLDERID ) +) ENGINE=InnoDB; +CREATE INDEX FFOLDERID_IDX ON t3 (FOLDERID); +CREATE INDEX CMFLDRPARNT_IDX ON t3 (PARENTID); +CREATE TABLE t4 +( +DOCTYPEID VARCHAR(32)BINARY NOT NULL +, DOCTYPENAME VARCHAR(80)BINARY NOT NULL +, DESCRIPTION VARCHAR(255)BINARY +, EXTNDATA LONGBLOB +, MODIFIED TIMESTAMP +, MODIFIER VARCHAR(255)BINARY +, ORIGINATOR INTEGER +, PRIMARY KEY ( DOCTYPEID ) +) ENGINE=InnoDB; +INSERT INTO t2 VALUES("c373e9f59cf15a6c3e57444553544200", "c373e9f59cf15a6c3e57444553544200", "340d243d45f111d497b00010a4ef934d", "2f6161e879db43c1a5b82c21ddc49089", NULL, "2003-06-06 07:48:42", NULL, NULL, NULL, "2003-06-06 07:48:42", "2003-06-06 07:48:42", NULL, NULL, NULL, "03eea05112b845949f3fd03278b5fe43", "2003-06-06 07:48:42", "admin", "0", NULL); +INSERT INTO t2 VALUES("c373e9f5a472f43ba45e444553544200", "c373e9f5a472f43ba45e444553544200", "340d243d45f111d497b00010a4ef934d", "2f6161e879db43c1a5b82c21ddc49089", NULL, "2003-06-07 18:50:12", NULL, NULL, NULL, "2003-06-07 18:50:12", "2003-06-07 18:50:12", NULL, NULL, NULL, "03eea05112b845949f3fd03278b5fe43", "2003-06-07 18:50:12", "admin", "0", NULL); +INSERT INTO t2 VALUES("c373e9f5a4a0f56014eb444553544200", "c373e9f5a4a0f56014eb444553544200", "340d243d45f111d497b00010a4ef934d", "2f6161e879db43c1a5b82c21ddc49089", NULL, "2003-06-07 19:39:26", NULL, NULL, NULL, "2003-06-07 19:39:26", "2003-06-07 19:39:26", NULL, NULL, NULL, "03eea05112b845949f3fd03278b5fe43", "2003-06-07 19:39:26", "admin", "0", NULL); +INSERT INTO t2 VALUES("c373e9f5a4a0f8fa4a86444553544200", "c373e9f5a4a0f8fa4a86444553544200", "340d243d45f111d497b00010a4ef934d", "2f6161e879db43c1a5b82c21ddc49089", NULL, "2003-06-07 19:43:05", NULL, NULL, NULL, "2003-06-07 19:43:05", "2003-06-07 19:43:05", NULL, NULL, NULL, "03eea05112b845949f3fd03278b5fe43", "2003-06-07 19:43:05", "admin", "0", NULL); +INSERT INTO t2 VALUES("c373e9f5ac7b537205ce444553544200", "c373e9f5ac7b537205ce444553544200", "340d243d45f111d497b00010a4ef934d", "2f6161e879db43c1a5b82c21ddc49089", NULL, "2003-06-09 08:15:24", NULL, NULL, NULL, "2003-06-09 08:15:24", "2003-06-09 08:15:24", NULL, NULL, NULL, "03eea05112b845949f3fd03278b5fe43", "2003-06-09 08:15:24", "admin", "0", NULL); +INSERT INTO t2 VALUES("c373e9f5ad0792012454444553544200", "c373e9f5ad0792012454444553544200", "340d243d45f111d497b00010a4ef934d", "2f6161e879db43c1a5b82c21ddc49089", NULL, "2003-06-09 10:51:44", NULL, NULL, NULL, "2003-06-09 10:51:44", "2003-06-09 10:51:44", NULL, NULL, NULL, "03eea05112b845949f3fd03278b5fe43", "2003-06-09 10:51:44", "admin", "0", NULL); +INSERT INTO t2 VALUES("c373e9f5ad079821ef34444553544200", "First Discussion", "c373e9f5ad079174ff17444553544200", "c373e9f5ad0796c0eca4444553544200", "Goldilocks", "2003-06-09 11:16:50", "Title: First Discussion", NULL, NULL, "2003-06-09 10:51:26", "2003-06-09 10:51:26", NULL, NULL, NULL, "03eea05112b845949f3fd03278b5fe43", "2003-06-09 11:16:50", "admin", "0", NULL); +INSERT INTO t2 VALUES("c373e9f5ad07993f3859444553544200", "Last Discussion", "c373e9f5ad079174ff17444553544200", "c373e9f5ad0796c0eca4444553544200", "Goldilocks", "2003-06-09 11:21:06", "Title: Last Discussion", NULL, "Setting new abstract and keeping doc checked out", "2003-06-09 10:51:26", "2003-06-09 10:51:26", NULL, NULL, NULL, "03eea05112b845949f3fd03278b5fe43", "2003-06-09 11:21:06", "admin", "0", NULL); +INSERT INTO t2 VALUES("c373e9f5ad079a3219c4444553544200", "testdoclayout", "340d243c45f111d497b00010a4ef934d", "c373e9f5ad0796c0eca4444553544200", "Goldilocks", "2003-06-09 11:25:31", "Title: Test doc layout", "Subtitle: test doc layout", NULL, "2003-06-09 10:51:27", "2003-06-09 10:51:27", NULL, NULL, NULL, "03eea05112b845949f3fd03278b5fe43", "2003-06-09 11:25:31", "admin", "0", NULL); +INSERT INTO t3 VALUES("0c9aab05b15048c59bc35c8461507deb", "System", "System", "2003-06-05 16:30:00", "The system content repository folder.", "3", "2003-06-05 16:30:00", "System", "0", NULL, "9c9aab05b15048c59bc35c8461507deb", "1"); +INSERT INTO t3 VALUES("2f6161e879db43c1a5b82c21ddc49089", "Default", "System", "2003-06-09 10:52:02", "The default content repository folder.", "3", "2003-06-05 16:30:00", "System", "0", NULL, "03eea05112b845949f3fd03278b5fe43", "1"); +INSERT INTO t3 VALUES("c373e9f5ad0791724315444553544200", "AddDocumentTest", "admin", "2003-06-09 10:51:25", "Movie Reviews", "0", "2003-06-09 10:51:25", "admin", "0", "2f6161e879db43c1a5b82c21ddc49089", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad07919e1963444553544200", "NewDestDirectory", "admin", "2003-06-09 10:51:28", "Adding new directory", "128", "2003-06-09 10:51:28", "admin", "0", "2f6161e879db43c1a5b82c21ddc49089", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad07919fe525444553544200", "SubDestDirectory", "admin", "2003-06-09 10:51:28", "Adding new directory", "128", "2003-06-09 10:51:28", "admin", "0", "c373e9f5ad07919e1963444553544200", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad0791a0dab5444553544200", "Level1", "admin", "2003-06-09 10:51:29", NULL, "0", "2003-06-09 10:51:29", "admin", "0", "2f6161e879db43c1a5b82c21ddc49089", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad0791a14669444553544200", "Level2", "admin", "2003-06-09 10:51:29", NULL, "0", "2003-06-09 10:51:29", "admin", "0", "c373e9f5ad0791a0dab5444553544200", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad0791a23c0e444553544200", "Level3", "admin", "2003-06-09 10:51:29", NULL, "0", "2003-06-09 10:51:29", "admin", "0", "c373e9f5ad0791a14669444553544200", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad0791a6b11f444553544200", "Dir1", "admin", "2003-06-09 10:51:30", NULL, "0", "2003-06-09 10:51:30", "admin", "0", "2f6161e879db43c1a5b82c21ddc49089", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad0791a897d6444553544200", "Dir2", "admin", "2003-06-09 10:51:30", NULL, "0", "2003-06-09 10:51:30", "admin", "0", "c373e9f5ad0791a6b11f444553544200", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad0791a9a063444553544200", "NewDestDirectory", "admin", "2003-06-09 10:51:31", NULL, "0", "2003-06-09 10:51:31", "admin", "0", "c373e9f5ad0791a897d6444553544200", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad0791aa73e3444553544200", "LevelA", "admin", "2003-06-09 10:51:31", NULL, "0", "2003-06-09 10:51:31", "admin", "0", "c373e9f5ad0791a0dab5444553544200", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad0791ab034b444553544200", "LevelB", "admin", "2003-06-09 10:51:31", NULL, "0", "2003-06-09 10:51:31", "admin", "0", "c373e9f5ad0791aa73e3444553544200", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad0791ac7311444553544200", "LevelC", "admin", "2003-06-09 10:51:32", NULL, "0", "2003-06-09 10:51:32", "admin", "0", "c373e9f5ad0791ab034b444553544200", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad0791ad66cf444553544200", "test2", "admin", "2003-06-09 10:51:32", NULL, "0", "2003-06-09 10:51:32", "admin", "0", "c373e9f5ad0791724315444553544200", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad0791aebd87444553544200", "test3", "admin", "2003-06-09 10:51:33", NULL, "0", "2003-06-09 10:51:33", "admin", "0", "c373e9f5ad0791ad66cf444553544200", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad0791dbaac4444553544200", "Special Caf� Folder", "admin", "2003-06-09 10:51:43", "test folder names with special chars", "0", "2003-06-09 10:51:43", "admin", "0", "2f6161e879db43c1a5b82c21ddc49089", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad0796bf913f444553544200", "CopiedFolder", "admin", "2003-06-09 11:09:05", "Movie Reviews", "0", "2003-06-09 11:09:05", "admin", "0", "c373e9f5ad0791a23c0e444553544200", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad0796c0eca4444553544200", "Movie Reviews", "admin", "2003-06-09 11:09:13", "Movie Reviews", "0", "2003-06-09 11:09:13", "admin", "33", "c373e9f5ad0796bf913f444553544200", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad0796d9b895444553544200", "NewBookFolder", "admin", "2003-06-09 11:12:41", "NewBooks - folder", "0", "2003-06-09 11:12:41", "admin", "0", "c373e9f5ad0796c0eca4444553544200", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t3 VALUES("c373e9f5ad079b4c9355444553544200", "CopiedFolder", "admin", "2003-06-09 11:26:34", "Movie Reviews", "0", "2003-06-09 11:26:34", "admin", "0", "2f6161e879db43c1a5b82c21ddc49089", "03eea05112b845949f3fd03278b5fe43", NULL); +INSERT INTO t4 VALUES("340d243c45f111d497b00010a4ef934d", "Document Layout", "The system Document Layouts Document Type", NULL, "2003-06-05 16:30:00", "System", "1"); +INSERT INTO t4 VALUES("340d243d45f111d497b00010a4ef934d", "Default", "The default system Document Type", NULL, "2003-06-05 16:30:00", "System", "1"); +INSERT INTO t4 VALUES("4d09dd60850711d4998a204c4f4f5020", "__SystemResourceType", "The type for all the uploaded resources", NULL, "2003-06-05 16:30:00", "System", "1"); +INSERT INTO t4 VALUES("91d4d595478211d497b40010a4ef934d", "__PmcSystemDefaultType", "The type for all the default available fields", NULL, "2003-06-05 16:30:00", "System", "1"); +INSERT INTO t4 VALUES("c373e9f59cf15a59b08a444553544200", "NoFieldDocType", "plain doc type", NULL, "2003-06-06 07:48:40", "admin", NULL); +INSERT INTO t4 VALUES("c373e9f59cf15a5c6a99444553544200", "Movie Review", "This doc type is for movie reviews", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<props autocheckin=\"false\" autopublish=\"false\" binary=\"choice\" categories=\"none\" cleanup=\"false\" folder=\"none\"><![CDATA[Doc type for cm tests]]></props>\r\n", "2003-06-06 07:48:40", "admin", NULL); +INSERT INTO t4 VALUES("c373e9f59cf15a6116a5444553544200", "Special Doc�u20A4u20A4u0113����u016BType", "test special chars xxx� in doc type", NULL, "2003-06-06 07:48:41", "admin", NULL); +INSERT INTO t4 VALUES("c373e9f59cf15a695d47444553544200", "Movie", NULL, NULL, "2003-06-06 07:48:41", "admin", NULL); +INSERT INTO t4 VALUES("c373e9f5ad079174ff17444553544200", "Discussion", NULL, NULL, "2003-06-09 10:51:25", "admin", NULL); +INSERT INTO t4 VALUES("c373e9f5ad0791da7e2b444553544200", "Books", "list of recommended books", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<props autocheckin=\"false\" autopublish=\"false\" binary=\"choice\" categories=\"none\" cleanup=\"false\" folder=\"none\"><![CDATA[Doc type for cm tests]]><![CDATA[Doc type for book tests]]></props>\r\n", "2003-06-09 10:51:40", "admin", NULL); +ALTER TABLE t2 ADD FOREIGN KEY FK_DCMNTS_DCTYPES ( DOCTYPEID) +REFERENCES t4 (DOCTYPEID ); +ALTER TABLE t2 ADD FOREIGN KEY FK_DCMNTS_FLDRS ( FOLDERID) +REFERENCES t3 (FOLDERID ); +ALTER TABLE t3 ADD FOREIGN KEY FK_FLDRS_PRNTID ( PARENTID) +REFERENCES t3 (FOLDERID ); +SELECT t2.*, t4.DOCTYPENAME, t1.CONTENTSIZE,t1.MIMETYPE FROM t2 INNER JOIN t4 ON t2.DOCTYPEID = t4.DOCTYPEID LEFT OUTER JOIN t1 ON t2.DOCID = t1.DOCID WHERE t2.FOLDERID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID='2f6161e879db43c1a5b82c21ddc49089' AND t3.FOLDERNAME = 'Level1') AND t3.FOLDERNAME = 'Level2') AND t3.FOLDERNAME = 'Level3') AND t3.FOLDERNAME = 'CopiedFolder') AND t3.FOLDERNAME = 'Movie Reviews') AND t2.DOCNAME = 'Last Discussion'; +DOCID DOCNAME DOCTYPEID FOLDERID AUTHOR CREATED TITLE SUBTITLE DOCABSTRACT PUBLISHDATE EXPIRATIONDATE LOCKEDBY STATUS PARENTDOCID REPID MODIFIED MODIFIER PUBLISHSTATUS ORIGINATOR DOCTYPENAME CONTENTSIZE MIMETYPE +c373e9f5ad07993f3859444553544200 Last Discussion c373e9f5ad079174ff17444553544200 c373e9f5ad0796c0eca4444553544200 Goldilocks 2003-06-09 11:21:06 Title: Last Discussion NULL Setting new abstract and keeping doc checked out 2003-06-09 10:51:26 2003-06-09 10:51:26 NULL NULL NULL 03eea05112b845949f3fd03278b5fe43 2003-06-09 11:21:06 admin 0 NULL Discussion NULL NULL +EXPLAIN SELECT t2.*, t4.DOCTYPENAME, t1.CONTENTSIZE,t1.MIMETYPE FROM t2 INNER JOIN t4 ON t2.DOCTYPEID = t4.DOCTYPEID LEFT OUTER JOIN t1 ON t2.DOCID = t1.DOCID WHERE t2.FOLDERID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID='2f6161e879db43c1a5b82c21ddc49089' AND t3.FOLDERNAME = 'Level1') AND t3.FOLDERNAME = 'Level2') AND t3.FOLDERNAME = 'Level3') AND t3.FOLDERNAME = 'CopiedFolder') AND t3.FOLDERNAME = 'Movie Reviews') AND t2.DOCNAME = 'Last Discussion'; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL DDOCTYPEID_IDX,DFOLDERID_IDX NULL NULL NULL 9 Using where +1 PRIMARY t1 eq_ref PRIMARY PRIMARY 34 test.t2.DOCID 1 +1 PRIMARY t4 eq_ref PRIMARY PRIMARY 34 test.t2.DOCTYPEID 1 +1 PRIMARY t3 eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t2.FOLDERID 1 Using where +1 PRIMARY t3 eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3.PARENTID 1 Using where +1 PRIMARY t3 eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3.PARENTID 1 Using where +1 PRIMARY t3 eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3.PARENTID 1 Using where +1 PRIMARY t3 eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3.PARENTID 1 Using where +drop table t1, t2, t3, t4; +CREATE TABLE t1 (a int(10) , PRIMARY KEY (a)) Engine=InnoDB; +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (a int(10), PRIMARY KEY (a)) Engine=InnoDB; +INSERT INTO t2 VALUES (1); +CREATE TABLE t3 (a int(10), b int(10), c int(10), +PRIMARY KEY (a)) Engine=InnoDB; +INSERT INTO t3 VALUES (1,2,1); +SELECT t1.* FROM t1 WHERE (SELECT COUNT(*) FROM t3,t2 WHERE t3.c=t2.a +and t2.a='1' AND t1.a=t3.b) > 0; +a +2 +DROP TABLE t1,t2,t3; +# +# Bug #902356: DISTINCT in materialized subquery +# +CREATE TABLE t1 (pk int PRIMARY KEY, a int, KEY(a)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (0, 4), (8, 6); +CREATE TABLE t2 (pk int PRIMARY KEY, a int, KEY(a)) ENGINE=InnoDB; +INSERT INTO t2 VALUES (0, 4), (8, 6); +CREATE TABLE t3 (b INT, KEY(b)); +INSERT INTO t3 VALUES (7), (0), (4), (2); +CREATE VIEW v1 AS SELECT * FROM t1; +SET @tmp_optimizer_switch=@@optimizer_switch; +SET optimizer_switch='materialization=on,in_to_exists=on'; +EXPLAIN +SELECT * FROM t2,t3 WHERE (2,9) IN (SELECT DISTINCT a,pk FROM t1) OR a = b; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 index a a 5 NULL 2 Using where; Using index +1 PRIMARY t3 ref b b 5 test.t2.a 2 Using index +2 SUBQUERY t1 const PRIMARY,a PRIMARY 4 const 1 Using where +SELECT * FROM t2,t3 WHERE (2,9) IN (SELECT DISTINCT a,pk FROM t1) OR a = b; +pk a b +0 4 4 +EXPLAIN +SELECT * FROM t2,t3 WHERE (2,9) IN (SELECT DISTINCT a,pk FROM v1) OR a = b; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 index a a 5 NULL 2 Using where; Using index +1 PRIMARY t3 ref b b 5 test.t2.a 2 Using index +2 SUBQUERY t1 const PRIMARY,a PRIMARY 4 const 1 Using where +SELECT * FROM t2,t3 WHERE (2,9) IN (SELECT DISTINCT a,pk FROM v1) OR a = b; +pk a b +0 4 4 +SET optimizer_switch=@tmp_optimizer_switch; +DROP VIEW v1; +DROP TABLE t1,t2,t3; +# +# MDEV-536: LP:1050806 - different result for a query using subquery +# +DROP TABLE IF EXISTS `t1`; +Warnings: +Note 1051 Unknown table 'test.t1' +CREATE TABLE `t1` ( +`node_uid` bigint(20) unsigned DEFAULT NULL, +`date` datetime DEFAULT NULL, +`mirror_date` datetime DEFAULT NULL, +KEY `date` (`date`) +) ENGINE=MyISAM; +INSERT INTO `t1` VALUES (2085,'2012-01-01 00:00:00','2013-01-01 00:00:00'); +INSERT INTO `t1` VALUES (2084,'2012-02-01 00:00:00','2013-01-01 00:00:00'); +INSERT INTO `t1` VALUES (2088,'2012-03-01 00:00:00','2013-01-01 00:00:00'); +SELECT * FROM ( +SELECT node_uid, date, mirror_date, @result := 0 AS result +FROM t1 +WHERE date < '2012-12-12 12:12:12' + AND node_uid in (2085, 2084) +ORDER BY mirror_date ASC +) AS calculated_result; +node_uid date mirror_date result +2085 2012-01-01 00:00:00 2013-01-01 00:00:00 0 +2084 2012-02-01 00:00:00 2013-01-01 00:00:00 0 +DROP TABLE t1; +# +# MDEV-567: Wrong result from a query with correlated subquery if ICP is allowed +# +CREATE TABLE t1 (a int, b int, INDEX idx(a)); +INSERT INTO t1 VALUES (9,0), (7,1), (1,9), (7,3), (2,1); +CREATE TABLE t2 (a int, b int, INDEX idx(a)); +INSERT INTO t2 VALUES (2,1), (6,4), (7,6), (9,4); +CREATE TABLE t3 (a int, b int); +INSERT INTO t3 VALUES (1,0), (1,1), (1,3); +SELECT * FROM t3 +WHERE a = (SELECT COUNT(DISTINCT t2.b) FROM t1, t2 +WHERE t1.a = t2.a AND t2.a BETWEEN 7 AND 9 +AND t3.b = t1.b +GROUP BY t1.b); +a b +1 0 +1 1 +1 3 +set @tmp_mdev567=@@optimizer_switch; +set optimizer_switch='mrr=off'; +SELECT * FROM t3 +WHERE a = (SELECT COUNT(DISTINCT t2.b) FROM t1, t2 +WHERE t1.a = t2.a AND t2.a BETWEEN 7 AND 9 +AND t3.b = t1.b +GROUP BY t1.b); +a b +1 0 +1 1 +1 3 +DROP TABLE t1,t2,t3; +set optimizer_switch=@tmp_mdev567; +# +# MDEV-4996: degenerate OR formula in WHERE of a subquery +# +CREATE TABLE t1 (a int, c1 varchar(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,'x'), (8,'d'); +CREATE TABLE t2 (m int, n int, c2 varchar(1)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (0, 5, 'x'), (1, 4,'p'); +SELECT * FROM t1 WHERE c1 NOT IN ( +SELECT t2a.c2 FROM t2 AS t2a, t2 AS t2b, t2 AS t2c +WHERE t2c.c2 = t2b.c2 AND ( t2a.m = t2b.n OR 0 ) AND +( t2b.m != a OR t2b.m = t2a.m )); +a c1 +2 x +8 d +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE c1 NOT IN ( +SELECT t2a.c2 FROM t2 AS t2a, t2 AS t2b, t2 AS t2c +WHERE t2c.c2 = t2b.c2 AND ( t2a.m = t2b.n OR 0 ) AND +( t2b.m != a OR t2b.m = t2a.m )); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +2 DEPENDENT SUBQUERY t2a ALL NULL NULL NULL NULL 2 100.00 Using where +2 DEPENDENT SUBQUERY t2b ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t2c ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (incremental, BNL join) +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`c1` AS `c1` from `test`.`t1` where !<expr_cache><`test`.`t1`.`c1`,`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`c1`,<exists>(/* select#2 */ select `test`.`t2a`.`c2` from `test`.`t2` `t2a` join `test`.`t2` `t2b` join `test`.`t2` `t2c` where (`test`.`t2b`.`m` <> `test`.`t1`.`a` or `test`.`t2b`.`m` = `test`.`t2a`.`m`) and trigcond(<cache>(`test`.`t1`.`c1`) = `test`.`t2a`.`c2` or `test`.`t2a`.`c2` is null) and `test`.`t2c`.`c2` = `test`.`t2b`.`c2` and `test`.`t2b`.`n` = `test`.`t2a`.`m` having trigcond(`test`.`t2a`.`c2` is null)))) +DROP TABLE t1,t2; +# +# MDEV-614, also MDEV-536, also LP:1050806: +# different result for a query using subquery between 5.5.25 and 5.5.27 +# +CREATE TABLE `t1` ( +`node_uid` bigint(20) unsigned DEFAULT NULL, +`date` datetime DEFAULT NULL, +`mirror_date` datetime DEFAULT NULL, +KEY `date` (`date`) +) ENGINE=MyISAM; +INSERT INTO `t1` VALUES (2085,'2012-01-01 00:00:00','2013-01-01 00:00:00'); +INSERT INTO `t1` VALUES (2084,'2012-02-01 00:00:00','2013-01-01 00:00:00'); +INSERT INTO `t1` VALUES (2088,'2012-03-01 00:00:00','2013-01-01 00:00:00'); +explain +SELECT * FROM ( +SELECT node_uid, date, mirror_date, @result := 0 AS result +FROM t1 +WHERE date < '2012-12-12 12:12:12' + AND node_uid in (2085, 2084) +ORDER BY mirror_date ASC +) AS calculated_result; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 +2 DERIVED t1 range date date 6 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using filesort +SELECT * FROM ( +SELECT node_uid, date, mirror_date, @result := 0 AS result +FROM t1 +WHERE date < '2012-12-12 12:12:12' + AND node_uid in (2085, 2084) +ORDER BY mirror_date ASC +) AS calculated_result; +node_uid date mirror_date result +2085 2012-01-01 00:00:00 2013-01-01 00:00:00 0 +2084 2012-02-01 00:00:00 2013-01-01 00:00:00 0 +set @tmp_mdev614=@@optimizer_switch; +set optimizer_switch='mrr=off'; +explain +SELECT * FROM ( +SELECT node_uid, date, mirror_date, @result := 0 AS result +FROM t1 +WHERE date < '2012-12-12 12:12:12' + AND node_uid in (2085, 2084) +ORDER BY mirror_date ASC +) AS calculated_result; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 +2 DERIVED t1 range date date 6 NULL 2 Using index condition; Using where; Using filesort +SELECT * FROM ( +SELECT node_uid, date, mirror_date, @result := 0 AS result +FROM t1 +WHERE date < '2012-12-12 12:12:12' + AND node_uid in (2085, 2084) +ORDER BY mirror_date ASC +) AS calculated_result; +node_uid date mirror_date result +2085 2012-01-01 00:00:00 2013-01-01 00:00:00 0 +2084 2012-02-01 00:00:00 2013-01-01 00:00:00 0 +set optimizer_switch=@tmp_mdev614; +DROP TABLE t1; +# +# MDEV-4420: non-expensive single-value subquery used as +# used as an access key to join a table +# +create table t1 (a varchar(3)); +insert into t1 values ('USA'), ('FRA'); +create table t2 select * from t1; +insert into t2 values ('RUS'); +create table t3 select * from t2; +create index idx on t3(a); +explain extended +select * from t1, t2 left join t3 on ( t2.a = t3.a ) +where t1.a = t2.a and ( t1.a = ( select min(a) from t1 ) or 0 ); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t3 ref idx idx 6 func 2 100.00 Using where; Using index +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t2`.`a` AS `a`,`test`.`t3`.`a` AS `a` from `test`.`t1` join `test`.`t2` left join `test`.`t3` on(`test`.`t3`.`a` = `test`.`t1`.`a`) where `test`.`t1`.`a` = (/* select#2 */ select min(`test`.`t1`.`a`) from `test`.`t1`) and `test`.`t2`.`a` = (/* select#2 */ select min(`test`.`t1`.`a`) from `test`.`t1`) +select * from t1, t2 left join t3 on ( t2.a = t3.a ) +where t1.a = t2.a and ( t1.a = ( select min(a) from t1 ) or 0 ); +a a a +FRA FRA FRA +drop table t1,t2,t3; +# +# MDEV-10148: Database crashes in the query to the View +# +CREATE TABLE t1 ( +key_code INT(11) NOT NULL, +value_string VARCHAR(50) NULL DEFAULT NULL, +PRIMARY KEY (key_code) +) COLLATE='utf8_general_ci' ENGINE=InnoDB ; +CREATE TABLE t2 ( +key_code INT(11) NOT NULL, +target_date DATE NULL DEFAULT NULL, +PRIMARY KEY (key_code) +) COLLATE='utf8_general_ci' ENGINE=InnoDB ; +CREATE TABLE t3 ( +now_date DATE NOT NULL, +PRIMARY KEY (now_date) +) COLLATE='utf8_general_ci' ENGINE=InnoDB ; +CREATE VIEW v1 +AS +SELECT +B.key_code, +B.target_date +FROM +t2 B INNER JOIN t3 C ON +B.target_date = C.now_date +; +SET @s = 'SELECT A.* FROM t1 A WHERE A.key_code IN (SELECT key_code FROM v1)'; +PREPARE stmt FROM @s; +EXECUTE stmt; +key_code value_string +EXECUTE stmt; +key_code value_string +DEALLOCATE PREPARE stmt; +DROP VIEW v1; +DROP TABLE t1,t2,t3; +set optimizer_switch=@subselect2_test_tmp; +create table t1 (a int); +create table t2 (a int); +create table t3(a int); +insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +insert into t2 select a from t1; +insert into t3 select a from t1; +select null in (select a from t1 where a < out3.a union select a from t2 where +(select a from t3) +1 < out3.a+1) from t3 out3; +ERROR 21000: Subquery returns more than 1 row +drop table t1, t2, t3; ++CREATE TABLE t1( ++q11 int, q12 int, q13 int, q14 int, q15 int, q16 int, q17 int, q18 int, q19 int, ++q21 int, q22 int, q23 int, q24 int, q25 int, q26 int, q27 int, q28 int, q29 int, ++f1 int ++); ++CREATE TABLE t2(f2 int, f21 int, f3 timestamp, f4 int, f5 int, f6 int); ++INSERT INTO t1 (f1) VALUES (1),(1),(2),(2); ++INSERT INTO t2 VALUES (1,1,"2004-02-29 11:11:11",0,0,0), (2,2,"2004-02-29 11:11:11",0,0,0); ++SELECT f1, ++(SELECT t.f21 from t2 t where max( ++q11+q12+q13+q14+q15+q16+q17+q18+q19+ ++q21+q22+q23+q24+q25+q26+q27+q28+q29) = t.f2 UNION ++SELECT t.f3 FROM t2 AS t WHERE t1.f1=t.f2 AND t.f3=MAX(t1.f1) UNION ++SELECT 1 LIMIT 1) AS test ++FROM t1 GROUP BY f1; ++f1 test ++1 1 ++2 1 ++Warnings: ++Warning 1292 Incorrect datetime value: '1' ++Warning 1292 Incorrect datetime value: '2' ++DROP TABLE t1,t2; diff --cc mysql-test/main/subselect_mat.result index 2ba851808df,00000000000..3ee904b8d9f mode 100644,000000..100644 --- a/mysql-test/main/subselect_mat.result +++ b/mysql-test/main/subselect_mat.result @@@ -1,2881 -1,0 +1,2897 @@@ +set @subselect_mat_test_optimizer_switch_value='materialization=on,in_to_exists=off,semijoin=off'; +set @subselect_sj_mat_tmp= @@optimizer_switch; +set optimizer_switch=ifnull(@subselect_mat_test_optimizer_switch_value, 'semijoin=on,firstmatch=on,loosescan=on,semijoin_with_cache=on'); +set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; +set @optimizer_switch_local_default= @@optimizer_switch; +set @save_join_cache_level=@@join_cache_level; +set join_cache_level=1; +drop table if exists t1, t2, t3, t4, t5, t1i, t2i, t3i; +drop table if exists columns; +drop table if exists t1_16, t2_16, t3_16; +drop view if exists v1, v2, v1m, v2m; +create table t1 (a1 char(8), a2 char(8)); +create table t2 (b1 char(8), b2 char(8)); +create table t3 (c1 char(8), c2 char(8)); +insert into t1 values ('1 - 00', '2 - 00'); +insert into t1 values ('1 - 01', '2 - 01'); +insert into t1 values ('1 - 02', '2 - 02'); +insert into t2 values ('1 - 01', '2 - 01'); +insert into t2 values ('1 - 01', '2 - 01'); +insert into t2 values ('1 - 02', '2 - 02'); +insert into t2 values ('1 - 02', '2 - 02'); +insert into t2 values ('1 - 03', '2 - 03'); +insert into t3 values ('1 - 01', '2 - 01'); +insert into t3 values ('1 - 02', '2 - 02'); +insert into t3 values ('1 - 03', '2 - 03'); +insert into t3 values ('1 - 04', '2 - 04'); +create table t1i (a1 char(8), a2 char(8)); +create table t2i (b1 char(8), b2 char(8)); +create table t3i (c1 char(8), c2 char(8)); +create index it1i1 on t1i (a1); +create index it1i2 on t1i (a2); +create index it1i3 on t1i (a1, a2); +create index it2i1 on t2i (b1); +create index it2i2 on t2i (b2); +create index it2i3 on t2i (b1, b2); +create index it3i1 on t3i (c1); +create index it3i2 on t3i (c2); +create index it3i3 on t3i (c1, c2); +insert into t1i select * from t1; +insert into t2i select * from t2; +insert into t3i select * from t3; +set @@optimizer_switch='materialization=on,in_to_exists=off,firstmatch=off'; +/****************************************************************************** +* Simple tests. +******************************************************************************/ +# non-indexed nullable fields +explain extended +select * from t1 where a1 in (select b1 from t2 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t1`.`a1`,`test`.`t1`.`a1` in ( <materialize> (/* select#2 */ select `test`.`t2`.`b1` from `test`.`t2` where `test`.`t2`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1`)))) +select * from t1 where a1 in (select b1 from t2 where b1 > '0'); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t1`.`a1`,`test`.`t1`.`a1` in ( <materialize> (/* select#2 */ select `test`.`t2`.`b1` from `test`.`t2` where `test`.`t2`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1`)))) +select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where `test`.`t2`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1` and `test`.`t1`.`a2` = `<subquery2>`.`b2`)))) +select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Using temporary +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`b1`,min(`test`.`t2`.`b2`) from `test`.`t2` where `test`.`t2`.`b1` > '0' group by `test`.`t2`.`b1` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1` and `test`.`t1`.`a2` = `<subquery2>`.`min(b2)`)))) +select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1i where a1 in (select b1 from t2i where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1i index NULL _it1_idx # NULL 3 100.00 Using where; +2 MATERIALIZED t2i index it2i1,it2i3 it2i1 # NULL 5 100.00 Using where; +Warnings: +Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`>(<in_optimizer>(`test`.`t1i`.`a1`,`test`.`t1i`.`a1` in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1` from `test`.`t2i` where `test`.`t2i`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1`)))) +select * from t1i where a1 in (select b1 from t2i where b1 > '0'); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1i where a1 in (select max(b1) from t2i where b1 > '0' group by b1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1i index NULL # 18 # 3 100.00 # +2 MATERIALIZED t2i range it2i1,it2i3 # 9 # 5 100.00 # +Warnings: +Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`>(<in_optimizer>(`test`.`t1i`.`a1`,`test`.`t1i`.`a1` in ( <materialize> (/* select#2 */ select max(`test`.`t2i`.`b1`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`max(b1)`)))) +select * from t1i where a1 in (select max(b1) from t2i where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1i index NULL _it1_idx # NULL 3 100.00 Using where; +2 MATERIALIZED t2i index it2i1,it2i3 it2i3 # NULL 5 100.00 Using where; +Warnings: +Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1` and `test`.`t1i`.`a2` = `<subquery2>`.`b2`)))) +select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0'); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1i where (a1, a2) in (select b1, max(b2) from t2i where b1 > '0' group by b1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1i index NULL # # # 3 100.00 # +2 MATERIALIZED t2i range it2i1,it2i3 # # # 3 100.00 # +Warnings: +Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,max(`test`.`t2i`.`b2`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1` and `test`.`t1i`.`a2` = `<subquery2>`.`max(b2)`)))) +select * from t1i where (a1, a2) in (select b1, max(b2) from t2i where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1i index NULL # # # 3 100.00 # +2 MATERIALIZED t2i range it2i1,it2i3 # # # 3 100.00 # +Warnings: +Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,min(`test`.`t2i`.`b2`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1` and `test`.`t1i`.`a2` = `<subquery2>`.`min(b2)`)))) +select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2i range NULL it2i3 9 NULL 3 100.00 Using index for group-by +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,max(`test`.`t2i`.`b2`) from `test`.`t2i` group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1` and `test`.`t1`.`a2` = `<subquery2>`.`max(b2)`)))) +select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +prepare st1 from "explain select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1)"; +execute st1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where +2 MATERIALIZED t2i range NULL it2i3 9 NULL 3 Using index for group-by +execute st1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where +2 MATERIALIZED t2i range NULL it2i3 9 NULL 3 Using index for group-by +prepare st2 from "select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1)"; +execute st2; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +execute st2; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2i range it2i1,it2i3 it2i3 18 NULL 3 100.00 Using where; Using index for group-by +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,min(`test`.`t2i`.`b2`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1` and `test`.`t1`.`a2` = `<subquery2>`.`min(b2)`)))) +select * from t1 where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +select * from t1 where (a1, a2) in (select b1, min(b2) from t2i limit 1,1); +ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' +set @save_optimizer_switch=@@optimizer_switch; +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='semijoin=off'; +prepare st1 from +"select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)"; +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='materialization=off,in_to_exists=on'; +execute st1; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='semijoin=off'; +execute st1; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='materialization=off,in_to_exists=on'; +prepare st1 from +"select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)"; +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='semijoin=off'; +execute st1; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='materialization=off,in_to_exists=on'; +execute st1; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +set @@optimizer_switch=@save_optimizer_switch; +explain extended +select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` order by `test`.`t2`.`b1`,`test`.`t2`.`b2` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1` and `test`.`t1`.`a2` = `<subquery2>`.`b2`)))) +select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1i index NULL it1i3 18 NULL 3 100.00 Using where; Using index +2 MATERIALIZED t2i index NULL it2i3 18 NULL 5 100.00 Using index +Warnings: +Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` order by `test`.`t2i`.`b1`,`test`.`t2i`.`b2` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1` and `test`.`t1i`.`a2` = `<subquery2>`.`b2`)))) +select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +/****************************************************************************** +* Views, UNIONs, several levels of nesting. +******************************************************************************/ +# materialize the result of subquery over temp-table view +create algorithm=merge view v1 as +select b1, c2 from t2, t3 where b2 > c2; +create algorithm=merge view v2 as +select b1, c2 from t2, t3 group by b2, c2; +Warnings: +Warning 1354 View merge algorithm can't be used here for now (assumed undefined algorithm) +create algorithm=temptable view v1m as +select b1, c2 from t2, t3 where b2 > c2; +create algorithm=temptable view v2m as +select b1, c2 from t2, t3 group by b2, c2; +select * from v1 where (c2, b1) in (select c2, b1 from v2 where b1 is not null); +b1 c2 +1 - 02 2 - 01 +1 - 02 2 - 01 +1 - 03 2 - 01 +1 - 03 2 - 02 +select * from v1 where (c2, b1) in (select distinct c2, b1 from v2 where b1 is not null); +b1 c2 +1 - 02 2 - 01 +1 - 02 2 - 01 +1 - 03 2 - 01 +1 - 03 2 - 02 +select * from v1m where (c2, b1) in (select c2, b1 from v2m where b1 is not null); +b1 c2 +1 - 02 2 - 01 +1 - 02 2 - 01 +1 - 03 2 - 01 +1 - 03 2 - 02 +select * from v1m where (c2, b1) in (select distinct c2, b1 from v2m where b1 is not null); +b1 c2 +1 - 02 2 - 01 +1 - 02 2 - 01 +1 - 03 2 - 01 +1 - 03 2 - 02 +drop view v1, v2, v1m, v2m; +explain extended +select * from t1 +where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +3 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +4 MATERIALIZED t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where `test`.`t2`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1` and `test`.`t1`.`a2` = `<subquery2>`.`b2`)))) and <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#3 */ select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c1`,`test`.`t3`.`c2`>(<in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (/* select#4 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where `test`.`t3`.`c1` = `<subquery4>`.`b1` and `test`.`t3`.`c2` = `<subquery4>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery3>`.`c1` and `test`.`t1`.`a2` = `<subquery3>`.`c2`)))) +select * from t1 +where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1i +where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and +(a1, a2) in (select c1, c2 from t3i +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1i index NULL # # # 3 100.00 # +3 MATERIALIZED t3i index NULL # # # 4 100.00 # +4 MATERIALIZED t2i index it2i2 # # # 5 100.00 # +2 MATERIALIZED t2i index it2i1,it2i3 # # # 5 100.00 # +Warnings: +Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1` and `test`.`t1i`.`a2` = `<subquery2>`.`b2`)))) and <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#3 */ select `test`.`t3i`.`c1`,`test`.`t3i`.`c2` from `test`.`t3i` where <expr_cache><`test`.`t3i`.`c1`,`test`.`t3i`.`c2`>(<in_optimizer>((`test`.`t3i`.`c1`,`test`.`t3i`.`c2`),(`test`.`t3i`.`c1`,`test`.`t3i`.`c2`) in ( <materialize> (/* select#4 */ select `test`.`t2 i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3i`.`c1` in <temporary table> on distinct_key where `test`.`t3i`.`c1` = `<subquery4>`.`b1` and `test`.`t3i`.`c2` = `<subquery4>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery3>`.`c1` and `test`.`t1i`.`a2` = `<subquery3>`.`c2`)))) +select * from t1i +where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and +(a1, a2) in (select c1, c2 from t3i +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 where c2 LIKE '%02') or +b2 in (select c2 from t3 where c2 LIKE '%03')) and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +5 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +6 MATERIALIZED t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +3 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#3 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%02' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery3>`.`c2`)))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`)))) ), <primar y_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1` and `test`.`t1`.`a2` = `<subquery2>`.`b2`)))) and <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#5 */ select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c1`,`test`.`t3`.`c2`>(<in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (/* select#6 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where `test`.`t3`.`c1` = `<subquery6>`.`b1` and `test`.`t3`.`c2` = `<subquery6>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery5>`.`c1` and `test`.`t1`.`a2` = `<subquery5>` .`c2`)))) +select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 where c2 LIKE '%02') or +b2 in (select c2 from t3 where c2 LIKE '%03')) and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +a1 a2 +1 - 02 2 - 02 +explain extended +select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 t3a where c1 = a1) or +b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and +(a1, a2) in (select c1, c2 from t3 t3c +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +5 MATERIALIZED t3c ALL NULL NULL NULL NULL 4 100.00 Using where +6 MATERIALIZED t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where +4 MATERIALIZED t3b ALL NULL NULL NULL NULL 4 100.00 Using where +3 DEPENDENT SUBQUERY t3a ALL NULL NULL NULL NULL 4 100.00 Using where +Warnings: +Note 1276 Field or reference 'test.t1.a1' of SELECT #3 was resolved in SELECT #1 +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(/* select#2 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where (<expr_cache><`test`.`t2`.`b2`,`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t2`.`b2`,<exists>(/* select#3 */ select `test`.`t3a`.`c2` from `test`.`t3` `t3a` where `test`.`t3a`.`c1` = `test`.`t1`.`a1` and <cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3b`.`c2` from `test`.`t3` `t3b` where `test`.`t3b`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`))))) and <cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1` and <cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`))) and <expr_cache> <`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#5 */ select `test`.`t3c`.`c1`,`test`.`t3c`.`c2` from `test`.`t3` `t3c` where <expr_cache><`test`.`t3c`.`c1`,`test`.`t3c`.`c2`>(<in_optimizer>((`test`.`t3c`.`c1`,`test`.`t3c`.`c2`),(`test`.`t3c`.`c1`,`test`.`t3c`.`c2`) in ( <materialize> (/* select#6 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3c`.`c1` in <temporary table> on distinct_key where `test`.`t3c`.`c1` = `<subquery6>`.`b1` and `test`.`t3c`.`c2` = `<subquery6>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery5>`.`c1` and `test`.`t1`.`a2` = `<subquery5>`.`c2`)))) +select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 t3a where c1 = a1) or +b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and +(a1, a2) in (select c1, c2 from t3 t3c +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +(select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 where c2 LIKE '%02') or +b2 in (select c2 from t3 where c2 LIKE '%03') +group by b1, b2) and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0'))) +UNION +(select * from t1i +where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and +(a1, a2) in (select c1, c2 from t3i +where (c1, c2) in (select b1, b2 from t2i where b2 > '0'))); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL # # # 3 100.00 # +5 MATERIALIZED t3 ALL NULL # # # 4 100.00 # +6 MATERIALIZED t2i index it2i2 # # # 5 100.00 # +2 MATERIALIZED t2 ALL NULL # # # 5 100.00 # +4 MATERIALIZED t3 ALL NULL # # # 4 100.00 # +3 MATERIALIZED t3 ALL NULL # # # 4 100.00 # +7 UNION t1i index NULL # # # 3 100.00 # +9 MATERIALIZED t3i index NULL # # # 4 100.00 # +10 MATERIALIZED t2i index it2i2 # # # 5 100.00 # +8 MATERIALIZED t2i index it2i1,it2i3 # # # 5 100.00 # +NULL UNION RESULT <union1,7> ALL NULL # # # NULL NULL # +Warnings: +Note 1003 (/* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#3 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%02' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery3>`.`c2`)))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`)))) ), <prima ry_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1` and `test`.`t1`.`a2` = `<subquery2>`.`b2`)))) and <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#5 */ select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c1`,`test`.`t3`.`c2`>(<in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (/* select#6 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where `test`.`t3`.`c1` = `<subquery6>`.`b1` and `test`.`t3`.`c2` = `<subquery6>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery5>`.`c1` and `test`.`t1`.`a2` = `<subquery5> `.`c2`))))) union (/* select#7 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#8 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery8>`.`b1` and `test`.`t1i`.`a2` = `<subquery8>`.`b2`)))) and <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#9 */ select `test`.`t3i`.`c1`,`test`.`t3i`.`c2` from `test`.`t3i` where <expr_cache><`test`.`t3i`.`c1`,`test`.`t3i`.`c2`>(<in_optimizer>((`test`.`t3i`.`c1`,`test`.`t3i`.`c2`),(`test`.`t3i`.`c1`,`test`.`t3i`.`c2`) in ( <materialize> (/* select#10 */ select ` test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3i`.`c1` in <temporary table> on distinct_key where `test`.`t3i`.`c1` = `<subquery10>`.`b1` and `test`.`t3i`.`c2` = `<subquery10>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery9>`.`c1` and `test`.`t1i`.`a2` = `<subquery9>`.`c2`))))) +(select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 where c2 LIKE '%02') or +b2 in (select c2 from t3 where c2 LIKE '%03') +group by b1, b2) and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0'))) +UNION +(select * from t1i +where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and +(a1, a2) in (select c1, c2 from t3i +where (c1, c2) in (select b1, b2 from t2i where b2 > '0'))); +a1 a2 +1 - 02 2 - 02 +1 - 01 2 - 01 +explain extended +select * from t1 +where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +5 MATERIALIZED t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(/* select#2 */ select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where `test`.`t1`.`a1` > '0' and <cache>(`test`.`t1`.`a1`) = `test`.`t1`.`a1` and <cache>(`test`.`t1`.`a2`) = `test`.`t1`.`a2` union /* select#3 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where `test`.`t2`.`b1` < '9' and <cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1` and <cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`))) and <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#4 */ select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c1`,`test`.`t3`.`c2`>(<in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3` .`c2`) in ( <materialize> (/* select#5 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where `test`.`t3`.`c1` = `<subquery5>`.`b1` and `test`.`t3`.`c2` = `<subquery5>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery4>`.`c1` and `test`.`t1`.`a2` = `<subquery4>`.`c2`)))) +select * from t1 +where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1, t3 +where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and +(c1, c2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')) and +a1 = c1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY t3 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (flat, BNL join) +4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +5 MATERIALIZED t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t1` join `test`.`t3` where `test`.`t3`.`c1` = `test`.`t1`.`a1` and <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(/* select#2 */ select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where `test`.`t1`.`a1` > '0' and <cache>(`test`.`t1`.`a1`) = `test`.`t1`.`a1` and <cache>(`test`.`t1`.`a2`) = `test`.`t1`.`a2` union /* select#3 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where `test`.`t2`.`b1` < '9' and <cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1` and <cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`))) and <expr_cache><`test`.`t3`.`c1`,`test`.`t3`.`c2`>(<in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (/* select#4 */ select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <expr_cache><`test`.` t3`.`c1`,`test`.`t3`.`c2`>(<in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (/* select#5 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where `test`.`t3`.`c1` = `<subquery5>`.`b1` and `test`.`t3`.`c2` = `<subquery5>`.`b2`)))) ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where `test`.`t3`.`c1` = `<subquery4>`.`c1` and `test`.`t3`.`c2` = `<subquery4>`.`c2`)))) +select * from t1, t3 +where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and +(c1, c2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')) and +a1 = c1; +a1 a2 c1 c2 +1 - 01 2 - 01 1 - 01 2 - 01 +1 - 02 2 - 02 1 - 02 2 - 02 +/****************************************************************************** +* Negative tests, where materialization should not be applied. +******************************************************************************/ +# UNION in a subquery +explain extended +select * from t3 +where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t3 ALL NULL NULL NULL NULL 4 100.00 Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 /* select#1 */ select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c1`>(<in_optimizer>(`test`.`t3`.`c1`,<exists>(/* select#2 */ select `test`.`t1`.`a1` from `test`.`t1` where `test`.`t1`.`a1` > '0' and <cache>(`test`.`t3`.`c1`) = `test`.`t1`.`a1` union /* select#3 */ select `test`.`t2`.`b1` from `test`.`t2` where `test`.`t2`.`b1` < '9' and <cache>(`test`.`t3`.`c1`) = `test`.`t2`.`b1`))) +select * from t3 +where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9'); +c1 c2 +1 - 01 2 - 01 +1 - 02 2 - 02 +1 - 03 2 - 03 +explain extended +select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 t3a where c1 = a1) or +b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and +(a1, a2) in (select c1, c2 from t3 t3c +where (c1, c2) in (select b1, b2 from t2i where b2 > '0' or b2 = a2)); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +5 DEPENDENT SUBQUERY t3c ALL NULL NULL NULL NULL 4 100.00 Using where +6 DEPENDENT SUBQUERY t2i index_subquery it2i1,it2i2,it2i3 it2i3 18 func,func 2 100.00 Using index; Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where +4 MATERIALIZED t3b ALL NULL NULL NULL NULL 4 100.00 Using where +3 DEPENDENT SUBQUERY t3a ALL NULL NULL NULL NULL 4 100.00 Using where +Warnings: +Note 1276 Field or reference 'test.t1.a1' of SELECT #3 was resolved in SELECT #1 +Note 1276 Field or reference 'test.t1.a2' of SELECT #6 was resolved in SELECT #1 +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(/* select#2 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where (<expr_cache><`test`.`t2`.`b2`,`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t2`.`b2`,<exists>(/* select#3 */ select `test`.`t3a`.`c2` from `test`.`t3` `t3a` where `test`.`t3a`.`c1` = `test`.`t1`.`a1` and <cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3b`.`c2` from `test`.`t3` `t3b` where `test`.`t3b`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`))))) and <cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1` and <cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`))) and <expr_cache> <`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(/* select#5 */ select `test`.`t3c`.`c1`,`test`.`t3c`.`c2` from `test`.`t3` `t3c` where <expr_cache><`test`.`t3c`.`c1`,`test`.`t3c`.`c2`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t3c`.`c1`,`test`.`t3c`.`c2`),<exists>(<index_lookup>(<cache>(`test`.`t3c`.`c1`) in t2i on it2i3 where (`test`.`t2i`.`b2` > '0' or `test`.`t2i`.`b2` = `test`.`t1`.`a2`) and <cache>(`test`.`t3c`.`c1`) = `test`.`t2i`.`b1` and <cache>(`test`.`t3c`.`c2`) = `test`.`t2i`.`b2`)))) and <cache>(`test`.`t1`.`a1`) = `test`.`t3c`.`c1` and <cache>(`test`.`t1`.`a2`) = `test`.`t3c`.`c2`))) +explain extended +select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(/* select#2 */ select '1 - 01','2 - 01' having (<cache>(`test`.`t1`.`a1`) = '1 - 01' or /*always not null*/ 1 is null) and (<cache>(`test`.`t1`.`a2`) = '2 - 01' or /*always not null*/ 1 is null) and '1 - 01' is null and '2 - 01' is null))) +select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01'); +a1 a2 +1 - 01 2 - 01 +explain extended +select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01' from dual); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(/* select#2 */ select '1 - 01','2 - 01' having (<cache>(`test`.`t1`.`a1`) = '1 - 01' or /*always not null*/ 1 is null) and (<cache>(`test`.`t1`.`a2`) = '2 - 01' or /*always not null*/ 1 is null) and '1 - 01' is null and '2 - 01' is null))) +select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01' from dual); +a1 a2 +1 - 01 2 - 01 +/****************************************************************************** +* Subqueries in other uncovered clauses. +******************************************************************************/ +/* SELECT clause */ +select ((a1,a2) IN (select * from t2 where b2 > '0')) IS NULL from t1; +((a1,a2) IN (select * from t2 where b2 > '0')) IS NULL +0 +0 +0 +/* GROUP BY clause */ +create table columns (col int key); +insert into columns values (1), (2); +explain extended +select * from t1 group by (select col from columns limit 1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 +2 SUBQUERY columns index NULL PRIMARY 4 NULL 2 100.00 Using index +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` group by (/* select#2 */ select `test`.`columns`.`col` from `test`.`columns` limit 1) +select * from t1 group by (select col from columns limit 1); +a1 a2 +1 - 00 2 - 00 +explain extended +select * from t1 group by (a1 in (select col from columns)); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using temporary; Using filesort +2 DEPENDENT SUBQUERY columns unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index; Using where; Full scan on NULL key +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` group by <expr_cache><`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t1`.`a1`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`a1`) in columns on PRIMARY where trigcond(<cache>(`test`.`t1`.`a1`) = `test`.`columns`.`col`))))) +select * from t1 group by (a1 in (select col from columns)); +a1 a2 +1 - 00 2 - 00 +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: '1 - 00' +Warning 1292 Truncated incorrect DOUBLE value: '1 - 01' +Warning 1292 Truncated incorrect DOUBLE value: '1 - 02' +/* ORDER BY clause */ +explain extended +select * from t1 order by (select col from columns limit 1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 +2 SUBQUERY columns index NULL PRIMARY 4 NULL 2 100.00 Using index +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` order by (/* select#2 */ select `test`.`columns`.`col` from `test`.`columns` limit 1) +select * from t1 order by (select col from columns limit 1); +a1 a2 +1 - 00 2 - 00 +1 - 01 2 - 01 +1 - 02 2 - 02 +/****************************************************************************** +* Column types/sizes that affect materialization. +******************************************************************************/ +/* +Test that BLOBs are not materialized (except when arguments of some functions). +*/ +# force materialization to be always considered +set @prefix_len = 6; +set @blob_len = 16; +set @suffix_len = @blob_len - @prefix_len; +create table t1_16 (a1 blob(16), a2 blob(16)); +create table t2_16 (b1 blob(16), b2 blob(16)); +create table t3_16 (c1 blob(16), c2 blob(16)); +insert into t1_16 values +(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len))); +insert into t1_16 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t1_16 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_16 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t2_16 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_16 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_16 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t3_16 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t3_16 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_16 values +(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len))); +explain extended select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select b1 from t2_16 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`>(<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select `test`.`t2_16`.`b1` from `test`.`t2_16` where `test`.`t2_16`.`b1` > '0' and <cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))) +select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select b1 from t2_16 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_16 +where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`>(<in_optimizer>((`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`),<exists>(/* select#2 */ select `test`.`t2_16`.`b1`,`test`.`t2_16`.`b2` from `test`.`t2_16` where `test`.`t2_16`.`b1` > '0' and <cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1` and <cache>(`test`.`t1_16`.`a2`) = `test`.`t2_16`.`b2`))) +select left(a1,7), left(a2,7) +from t1_16 +where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`>(<in_optimizer>(`test`.`t1_16`.`a1`,`test`.`t1_16`.`a1` in ( <materialize> (/* select#2 */ select substr(`test`.`t2_16`.`b1`,1,16) from `test`.`t2_16` where `test`.`t2_16`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1_16`.`a1` in <temporary table> on distinct_key where `test`.`t1_16`.`a1` = `<subquery2>`.`substring(b1,1,16)`)))) +select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select group_concat(b1) from t2_16 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`>(<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select group_concat(`test`.`t2_16`.`b1` separator ',') from `test`.`t2_16` group by `test`.`t2_16`.`b2` having <cache>(`test`.`t1_16`.`a1`) = <ref_null_helper>(group_concat(`test`.`t2_16`.`b1` separator ','))))) +select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select group_concat(b1) from t2_16 group by b2); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +set @@group_concat_max_len = 256; +explain extended select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select group_concat(b1) from t2_16 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_16 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`>(<in_optimizer>(`test`.`t1_16`.`a1`,`test`.`t1_16`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_16`.`b1` separator ',') from `test`.`t2_16` group by `test`.`t2_16`.`b2` ), <primary_index_lookup>(`test`.`t1_16`.`a1` in <temporary table> on distinct_key where `test`.`t1_16`.`a1` = `<subquery2>`.`group_concat(b1)`)))) +select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select group_concat(b1) from t2_16 group by b2); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended +select * from t1 +where concat(a1,'x') IN +(select left(a1,8) from t1_16 +where (a1, a2) IN +(select t2_16.b1, t2_16.b2 from t2_16, t2 +where t2.b2 = substring(t2_16.b2,1,6) and +t2.b1 IN (select c1 from t3 where c2 > '0'))); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where +3 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where +3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join) +4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><concat(`test`.`t1`.`a1`,'x')>(<in_optimizer>(concat(`test`.`t1`.`a1`,'x'),<exists>(/* select#2 */ select left(`test`.`t1_16`.`a1`,8) from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`>(<in_optimizer>((`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`),<exists>(/* select#3 */ select `test`.`t2_16`.`b1`,`test`.`t2_16`.`b2` from `test`.`t2_16` join `test`.`t2` where `test`.`t2`.`b2` = substr(`test`.`t2_16`.`b2`,1,6) and <expr_cache><`test`.`t2`.`b1`>(<in_optimizer>(`test`.`t2`.`b1`,`test`.`t2`.`b1` in ( <materialize> (/* select#4 */ select `test`.`t3`.`c1` from `test`.`t3` where `test`.`t3`.`c2` > '0' ), <primary_index_lookup>(`test`.`t2`.`b1` in <temporary table> on distinct_key where `test`.`t2`.`b1` = `<subquery4>`.`c1`)))) and <cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1` and <cache>(`test`.`t1_16`.`a2`) = `test`.`t2_16`.`b2`))) and < cache>(concat(`test`.`t1`.`a1`,'x')) = left(`test`.`t1_16`.`a1`,8)))) +drop table t1_16, t2_16, t3_16; +set @blob_len = 512; +set @suffix_len = @blob_len - @prefix_len; +create table t1_512 (a1 blob(512), a2 blob(512)); +create table t2_512 (b1 blob(512), b2 blob(512)); +create table t3_512 (c1 blob(512), c2 blob(512)); +insert into t1_512 values +(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len))); +insert into t1_512 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t1_512 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_512 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t2_512 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_512 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_512 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t3_512 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t3_512 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_512 values +(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len))); +explain extended select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select b1 from t2_512 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <expr_cache><`test`.`t1_512`.`a1`>(<in_optimizer>(`test`.`t1_512`.`a1`,<exists>(/* select#2 */ select `test`.`t2_512`.`b1` from `test`.`t2_512` where `test`.`t2_512`.`b1` > '0' and <cache>(`test`.`t1_512`.`a1`) = `test`.`t2_512`.`b1`))) +select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select b1 from t2_512 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_512 +where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <expr_cache><`test`.`t1_512`.`a1`,`test`.`t1_512`.`a2`>(<in_optimizer>((`test`.`t1_512`.`a1`,`test`.`t1_512`.`a2`),<exists>(/* select#2 */ select `test`.`t2_512`.`b1`,`test`.`t2_512`.`b2` from `test`.`t2_512` where `test`.`t2_512`.`b1` > '0' and <cache>(`test`.`t1_512`.`a1`) = `test`.`t2_512`.`b1` and <cache>(`test`.`t1_512`.`a2`) = `test`.`t2_512`.`b2`))) +select left(a1,7), left(a2,7) +from t1_512 +where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <expr_cache><`test`.`t1_512`.`a1`>(<in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (/* select#2 */ select substr(`test`.`t2_512`.`b1`,1,512) from `test`.`t2_512` where `test`.`t2_512`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1_512`.`a1` in <temporary table> on distinct_key where `test`.`t1_512`.`a1` = `<subquery2>`.`substring(b1,1,512)`)))) +select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select group_concat(b1) from t2_512 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_512 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <expr_cache><`test`.`t1_512`.`a1`>(<in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_512`.`b1` separator ',') from `test`.`t2_512` group by `test`.`t2_512`.`b2` ), <primary_index_lookup>(`test`.`t1_512`.`a1` in <temporary table> on distinct_key where `test`.`t1_512`.`a1` = `<subquery2>`.`group_concat(b1)`)))) +select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select group_concat(b1) from t2_512 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +set @@group_concat_max_len = 256; +explain extended select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select group_concat(b1) from t2_512 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_512 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <expr_cache><`test`.`t1_512`.`a1`>(<in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_512`.`b1` separator ',') from `test`.`t2_512` group by `test`.`t2_512`.`b2` ), <primary_index_lookup>(`test`.`t1_512`.`a1` in <temporary table> on distinct_key where `test`.`t1_512`.`a1` = `<subquery2>`.`group_concat(b1)`)))) +select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select group_concat(b1) from t2_512 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +drop table t1_512, t2_512, t3_512; +set @blob_len = 1024; +set @suffix_len = @blob_len - @prefix_len; +create table t1_1024 (a1 blob(1024), a2 blob(1024)); +create table t2_1024 (b1 blob(1024), b2 blob(1024)); +create table t3_1024 (c1 blob(1024), c2 blob(1024)); +insert into t1_1024 values +(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len))); +insert into t1_1024 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t1_1024 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_1024 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t3_1024 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t3_1024 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_1024 values +(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len))); +explain extended select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select b1 from t2_1024 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <expr_cache><`test`.`t1_1024`.`a1`>(<in_optimizer>(`test`.`t1_1024`.`a1`,<exists>(/* select#2 */ select `test`.`t2_1024`.`b1` from `test`.`t2_1024` where `test`.`t2_1024`.`b1` > '0' and <cache>(`test`.`t1_1024`.`a1`) = `test`.`t2_1024`.`b1`))) +select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select b1 from t2_1024 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1024 +where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <expr_cache><`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a2`>(<in_optimizer>((`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a2`),<exists>(/* select#2 */ select `test`.`t2_1024`.`b1`,`test`.`t2_1024`.`b2` from `test`.`t2_1024` where `test`.`t2_1024`.`b1` > '0' and <cache>(`test`.`t1_1024`.`a1`) = `test`.`t2_1024`.`b1` and <cache>(`test`.`t1_1024`.`a2`) = `test`.`t2_1024`.`b2`))) +select left(a1,7), left(a2,7) +from t1_1024 +where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <expr_cache><`test`.`t1_1024`.`a1`>(<in_optimizer>(`test`.`t1_1024`.`a1`,<exists>(/* select#2 */ select substr(`test`.`t2_1024`.`b1`,1,1024) from `test`.`t2_1024` where `test`.`t2_1024`.`b1` > '0' and <cache>(`test`.`t1_1024`.`a1`) = substr(`test`.`t2_1024`.`b1`,1,1024)))) +select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select group_concat(b1) from t2_1024 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <expr_cache><`test`.`t1_1024`.`a1`>(<in_optimizer>(`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_1024`.`b1` separator ',') from `test`.`t2_1024` group by `test`.`t2_1024`.`b2` ), <primary_index_lookup>(`test`.`t1_1024`.`a1` in <temporary table> on distinct_key where `test`.`t1_1024`.`a1` = `<subquery2>`.`group_concat(b1)`)))) +select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select group_concat(b1) from t2_1024 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +set @@group_concat_max_len = 256; +explain extended select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select group_concat(b1) from t2_1024 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <expr_cache><`test`.`t1_1024`.`a1`>(<in_optimizer>(`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_1024`.`b1` separator ',') from `test`.`t2_1024` group by `test`.`t2_1024`.`b2` ), <primary_index_lookup>(`test`.`t1_1024`.`a1` in <temporary table> on distinct_key where `test`.`t1_1024`.`a1` = `<subquery2>`.`group_concat(b1)`)))) +select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select group_concat(b1) from t2_1024 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +drop table t1_1024, t2_1024, t3_1024; +set @blob_len = 1025; +set @suffix_len = @blob_len - @prefix_len; +create table t1_1025 (a1 blob(1025), a2 blob(1025)); +create table t2_1025 (b1 blob(1025), b2 blob(1025)); +create table t3_1025 (c1 blob(1025), c2 blob(1025)); +insert into t1_1025 values +(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len))); +insert into t1_1025 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t1_1025 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1025 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t2_1025 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1025 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_1025 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t3_1025 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t3_1025 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_1025 values +(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len))); +explain extended select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select b1 from t2_1025 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <expr_cache><`test`.`t1_1025`.`a1`>(<in_optimizer>(`test`.`t1_1025`.`a1`,<exists>(/* select#2 */ select `test`.`t2_1025`.`b1` from `test`.`t2_1025` where `test`.`t2_1025`.`b1` > '0' and <cache>(`test`.`t1_1025`.`a1`) = `test`.`t2_1025`.`b1`))) +select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select b1 from t2_1025 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1025 +where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <expr_cache><`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a2`>(<in_optimizer>((`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a2`),<exists>(/* select#2 */ select `test`.`t2_1025`.`b1`,`test`.`t2_1025`.`b2` from `test`.`t2_1025` where `test`.`t2_1025`.`b1` > '0' and <cache>(`test`.`t1_1025`.`a1`) = `test`.`t2_1025`.`b1` and <cache>(`test`.`t1_1025`.`a2`) = `test`.`t2_1025`.`b2`))) +select left(a1,7), left(a2,7) +from t1_1025 +where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <expr_cache><`test`.`t1_1025`.`a1`>(<in_optimizer>(`test`.`t1_1025`.`a1`,<exists>(/* select#2 */ select substr(`test`.`t2_1025`.`b1`,1,1025) from `test`.`t2_1025` where `test`.`t2_1025`.`b1` > '0' and <cache>(`test`.`t1_1025`.`a1`) = substr(`test`.`t2_1025`.`b1`,1,1025)))) +select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select group_concat(b1) from t2_1025 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <expr_cache><`test`.`t1_1025`.`a1`>(<in_optimizer>(`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_1025`.`b1` separator ',') from `test`.`t2_1025` group by `test`.`t2_1025`.`b2` ), <primary_index_lookup>(`test`.`t1_1025`.`a1` in <temporary table> on distinct_key where `test`.`t1_1025`.`a1` = `<subquery2>`.`group_concat(b1)`)))) +select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select group_concat(b1) from t2_1025 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +set @@group_concat_max_len = 256; +explain extended select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select group_concat(b1) from t2_1025 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <expr_cache><`test`.`t1_1025`.`a1`>(<in_optimizer>(`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_1025`.`b1` separator ',') from `test`.`t2_1025` group by `test`.`t2_1025`.`b2` ), <primary_index_lookup>(`test`.`t1_1025`.`a1` in <temporary table> on distinct_key where `test`.`t1_1025`.`a1` = `<subquery2>`.`group_concat(b1)`)))) +select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select group_concat(b1) from t2_1025 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +drop table t1_1025, t2_1025, t3_1025; +create table t1bit (a1 bit(3), a2 bit(3)); +create table t2bit (b1 bit(3), b2 bit(3)); +insert into t1bit values (b'000', b'100'); +insert into t1bit values (b'001', b'101'); +insert into t1bit values (b'010', b'110'); +insert into t2bit values (b'001', b'101'); +insert into t2bit values (b'010', b'110'); +insert into t2bit values (b'110', b'111'); +explain extended select bin(a1), bin(a2) +from t1bit +where (a1, a2) in (select b1, b2 from t2bit); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1bit ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2bit ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1003 /* select#1 */ select conv(`test`.`t1bit`.`a1`,10,2) AS `bin(a1)`,conv(`test`.`t1bit`.`a2`,10,2) AS `bin(a2)` from `test`.`t1bit` where <expr_cache><`test`.`t1bit`.`a1`,`test`.`t1bit`.`a2`>(<in_optimizer>((`test`.`t1bit`.`a1`,`test`.`t1bit`.`a2`),(`test`.`t1bit`.`a1`,`test`.`t1bit`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2bit`.`b1`,`test`.`t2bit`.`b2` from `test`.`t2bit` ), <primary_index_lookup>(`test`.`t1bit`.`a1` in <temporary table> on distinct_key where `test`.`t1bit`.`a1` = `<subquery2>`.`b1` and `test`.`t1bit`.`a2` = `<subquery2>`.`b2`)))) +select bin(a1), bin(a2) +from t1bit +where (a1, a2) in (select b1, b2 from t2bit); +bin(a1) bin(a2) +1 101 +10 110 +drop table t1bit, t2bit; +create table t1bb (a1 bit(3), a2 blob(3)); +create table t2bb (b1 bit(3), b2 blob(3)); +insert into t1bb values (b'000', '100'); +insert into t1bb values (b'001', '101'); +insert into t1bb values (b'010', '110'); +insert into t2bb values (b'001', '101'); +insert into t2bb values (b'010', '110'); +insert into t2bb values (b'110', '111'); +explain extended select bin(a1), a2 +from t1bb +where (a1, a2) in (select b1, b2 from t2bb); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1bb ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2bb ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select conv(`test`.`t1bb`.`a1`,10,2) AS `bin(a1)`,`test`.`t1bb`.`a2` AS `a2` from `test`.`t1bb` where <expr_cache><`test`.`t1bb`.`a1`,`test`.`t1bb`.`a2`>(<in_optimizer>((`test`.`t1bb`.`a1`,`test`.`t1bb`.`a2`),<exists>(/* select#2 */ select `test`.`t2bb`.`b1`,`test`.`t2bb`.`b2` from `test`.`t2bb` where <cache>(`test`.`t1bb`.`a1`) = `test`.`t2bb`.`b1` and <cache>(`test`.`t1bb`.`a2`) = `test`.`t2bb`.`b2`))) +select bin(a1), a2 +from t1bb +where (a1, a2) in (select b1, b2 from t2bb); +bin(a1) a2 +1 101 +10 110 +drop table t1bb, t2bb; +drop table t1, t2, t3, t1i, t2i, t3i, columns; +/****************************************************************************** +* Test the cache of the left operand of IN. +******************************************************************************/ +# Test that default values of Cached_item are not used for comparison +create table t1 (s1 int); +create table t2 (s2 int); +insert into t1 values (5),(1),(0); +insert into t2 values (0), (1); +select s2 from t2 where s2 in (select s1 from t1); +s2 +0 +1 +drop table t1, t2; +create table t1 (a int not null, b int not null); +create table t2 (c int not null, d int not null); +create table t3 (e int not null); +insert into t1 values (1,10); +insert into t1 values (1,20); +insert into t1 values (2,10); +insert into t1 values (2,20); +insert into t1 values (2,30); +insert into t1 values (3,20); +insert into t1 values (4,40); +insert into t2 values (2,10); +insert into t2 values (2,20); +insert into t2 values (2,40); +insert into t2 values (3,20); +insert into t2 values (4,10); +insert into t2 values (5,10); +insert into t3 values (10); +insert into t3 values (10); +insert into t3 values (20); +insert into t3 values (30); +explain extended +select a from t1 where a in (select c from t2 where d >= 20); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 7 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where `test`.`t2`.`d` >= 20 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`c`)))) +select a from t1 where a in (select c from t2 where d >= 20); +a +2 +2 +2 +3 +create index it1a on t1(a); +explain extended +select a from t1 where a in (select c from t2 where d >= 20); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using where; Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where `test`.`t2`.`d` >= 20 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`c`)))) +select a from t1 where a in (select c from t2 where d >= 20); +a +2 +2 +2 +3 +insert into t2 values (1,10); +explain extended +select a from t1 where a in (select c from t2 where d >= 20); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using where; Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 7 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where `test`.`t2`.`d` >= 20 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`c`)))) +select a from t1 where a in (select c from t2 where d >= 20); +a +2 +2 +2 +3 +explain extended +select a from t1 group by a having a in (select c from t2 where d >= 20); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 7 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where `test`.`t2`.`d` >= 20 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`c`)))) +select a from t1 group by a having a in (select c from t2 where d >= 20); +a +2 +3 +create index iab on t1(a, b); +explain extended +select a from t1 group by a having a in (select c from t2 where d >= 20); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 7 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where `test`.`t2`.`d` >= 20 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`c`)))) +select a from t1 group by a having a in (select c from t2 where d >= 20); +a +2 +3 +explain extended +select a from t1 group by a +having a in (select c from t2 where d >= some(select e from t3 where max(b)=e)); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL iab 8 NULL 7 100.00 Using index +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where +3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where +Warnings: +Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1 +Note 1981 Aggregate function 'max()' of SELECT #3 belongs to SELECT #1 +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`,max(`test`.`t1`.`b`),max(`test`.`t1`.`b`)>(<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`,max(`test`.`t1`.`b`),max(`test`.`t1`.`b`)>(<in_optimizer>(`test`.`t2`.`d`,<exists>(/* select#3 */ select `test`.`t3`.`e` from `test`.`t3` where max(`test`.`t1`.`b`) = `test`.`t3`.`e` having <cache>(`test`.`t2`.`d`) >= <ref_null_helper>(`test`.`t3`.`e`))))) and <cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`))) +select a from t1 group by a +having a in (select c from t2 where d >= some(select e from t3 where max(b)=e)); +a +2 +3 +explain extended +select a from t1 +where a in (select c from t2 where d >= some(select e from t3 where b=e)); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL iab 8 NULL 7 100.00 Using where; Using index +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where +3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where +Warnings: +Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1 +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where <expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(/* select#3 */ select `test`.`t3`.`e` from `test`.`t3` where `test`.`t1`.`b` = `test`.`t3`.`e` and <cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`)))) and <cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`))) +select a from t1 +where a in (select c from t2 where d >= some(select e from t3 where b=e)); +a +1 +2 +2 +2 +3 +drop table t1, t2, t3; +create table t2 (a int, b int, key(a), key(b)); +insert into t2 values (3,3),(3,3),(3,3); +select 1 from t2 where +t2.a > 1 +or +t2.a = 3 and not t2.a not in (select t2.b from t2); +1 +1 +1 +1 +drop table t2; +create table t1 (a1 int key); +create table t2 (b1 int); +insert into t1 values (5); +explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); +min(a1) +NULL +set @save_optimizer_switch=@@optimizer_switch; +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='materialization=off,in_to_exists=on'; +explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); +min(a1) +NULL +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='semijoin=off'; +explain select min(a1) from t1 where 7 in (select b1 from t2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +select min(a1) from t1 where 7 in (select b1 from t2); +min(a1) +NULL +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='materialization=off,in_to_exists=on'; +# with MariaDB and MWL#90, this particular case is solved: +explain select min(a1) from t1 where 7 in (select b1 from t2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +select min(a1) from t1 where 7 in (select b1 from t2); +min(a1) +NULL +# but when we go around MWL#90 code, the problem still shows up: +explain select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; +min(a1) +NULL +set @@optimizer_switch= @save_optimizer_switch; +drop table t1,t2; +create table t1 (a char(2), b varchar(10)); +insert into t1 values ('a', 'aaa'); +insert into t1 values ('aa', 'aaaa'); +explain select a,b from t1 where b in (select a from t1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +select a,b from t1 where b in (select a from t1); +a b +prepare st1 from "select a,b from t1 where b in (select a from t1)"; +execute st1; +a b +execute st1; +a b +drop table t1; +# +# BUG#49630: Segfault in select_describe() with double +# nested subquery and materialization +# +CREATE TABLE t1 (t1i int); +CREATE TABLE t2 (t2i int); +CREATE TABLE t3 (t3i int); +CREATE TABLE t4 (t4i int); +INSERT INTO t1 VALUES (1); +INSERT INTO t2 VALUES (1),(2); +INSERT INTO t3 VALUES (1),(2); +INSERT INTO t4 VALUES (1),(2); + +EXPLAIN +SELECT t1i +FROM t1 JOIN t4 ON t1i=t4i +WHERE (t1i) IN ( +SELECT t2i +FROM t2 +WHERE (t2i) IN ( +SELECT max(t3i) +FROM t3 +GROUP BY t3i +) +); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using where +3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 Using temporary +DROP TABLE t1,t2,t3,t4; +CREATE TABLE t1 ( +pk INTEGER AUTO_INCREMENT, +col_int_nokey INTEGER, +col_int_key INTEGER, +col_varchar_key VARCHAR(1), +PRIMARY KEY (pk), +KEY (col_int_key), +KEY (col_varchar_key, col_int_key) +) +; +INSERT INTO t1 ( +col_int_key, col_int_nokey, col_varchar_key +) +VALUES +(2, NULL, 'w'), +(9, 7, 'm'), +(3, 9, 'm'), +(9, 7, 'k'), +(NULL, 4, 'r'), +(9, 2, 't'), +(3, 6, 'j'), +(8, 8, 'u'), +(8, NULL, 'h'), +(53, 5, 'o'), +(0, NULL, NULL), +(5, 6, 'k'), +(166, 188, 'e'), +(3, 2, 'n'), +(0, 1, 't'), +(1, 1, 'c'), +(9, 0, 'm'), +(5, 9, 'y'), +(6, NULL, 'f'), +(2, 4, 'd') +; +SELECT table2.col_varchar_key AS field1, +table2.col_int_nokey AS field2 +FROM ( t1 AS table1 LEFT OUTER JOIN t1 AS table2 +ON (table2.col_varchar_key = table1.col_varchar_key ) ) +WHERE table1.pk = 6 +HAVING ( field2 ) IN +( SELECT SUBQUERY2_t2.col_int_nokey AS SUBQUERY2_field2 +FROM ( t1 AS SUBQUERY2_t1 JOIN t1 AS SUBQUERY2_t2 +ON (SUBQUERY2_t2.col_varchar_key = SUBQUERY2_t1.col_varchar_key ) ) ) +ORDER BY field2 +; +field1 field2 +t 1 +t 2 +drop table t1; +# +# BUG#53103: MTR test ps crashes in optimize_cond() +# when running with --debug +# +CREATE TABLE t1(track varchar(15)); +INSERT INTO t1 VALUES ('CAD'), ('CAD'); +PREPARE STMT FROM +"SELECT 1 FROM t1 + WHERE + track IN (SELECT track FROM t1 + GROUP BY track + HAVING track>='CAD')"; +EXECUTE STMT ; +1 +1 +1 +EXECUTE STMT ; +1 +1 +1 +DEALLOCATE PREPARE STMT; +DROP TABLE t1; +# End of BUG#53103 +# +# BUG#54511 - Assertion failed: cache != 0L in file +# sql_select.cc::sub_select_cache on HAVING +# +CREATE TABLE t1 (i int(11)); +CREATE TABLE t2 (c char(1)); +CREATE TABLE t3 (c char(1)); +INSERT INTO t1 VALUES (1), (2); +INSERT INTO t2 VALUES ('a'), ('b'); +INSERT INTO t3 VALUES ('x'), ('y'); +SELECT COUNT( i ),i +FROM t1 +HAVING ('c') +IN (SELECT t2.c FROM (t2 JOIN t3)); +COUNT( i ) i +DROP TABLE t1,t2,t3; +# End BUG#54511 +# +# BUG#56367 - Assertion exec_method != EXEC_MATERIALIZATION... +# on subquery in FROM +# +CREATE TABLE t1 (a INTEGER); +CREATE TABLE t2 (b INTEGER); +INSERT INTO t2 VALUES (1); +set @tmp_optimizer_switch=@@optimizer_switch; +set optimizer_switch='derived_merge=off,derived_with_keys=off'; +explain SELECT a FROM ( +SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a > 3 OR t2.b IN (SELECT a FROM t1) +) table1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 +2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +3 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +SELECT a FROM ( +SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a > 3 OR t2.b IN (SELECT a FROM t1) +) table1; +a +set optimizer_switch=@tmp_optimizer_switch; +DROP TABLE t1, t2; +# End BUG#56367 +# +# Bug#59833 - materialization=on/off leads to different result set +# when using IN +# +CREATE TABLE t1 ( +pk int NOT NULL, +f1 int DEFAULT NULL, +PRIMARY KEY (pk) +) ENGINE=MyISAM; +CREATE TABLE t2 ( +pk int NOT NULL, +f1 int DEFAULT NULL, +PRIMARY KEY (pk) +) ENGINE=MyISAM; +INSERT INTO t1 VALUES (10,0); +INSERT INTO t2 VALUES (10,0),(11,0); +explain SELECT * FROM t1 JOIN t2 USING (f1) +WHERE t1.f1 IN (SELECT t1.pk FROM t1 ORDER BY t1.f1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where +2 MATERIALIZED t1 system NULL NULL NULL NULL 1 +SELECT * FROM t1 JOIN t2 USING (f1) +WHERE t1.f1 IN (SELECT t1.pk FROM t1 ORDER BY t1.f1); +f1 pk pk +DROP TABLE t1, t2; +# End Bug#59833 +# +# Bug#11852644 - CRASH IN ITEM_REF::SAVE_IN_FIELD ON SELECT DISTINCT +# +CREATE TABLE t1 ( +col_varchar_key varchar(1) DEFAULT NULL, +col_varchar_nokey varchar(1) DEFAULT NULL, +KEY col_varchar_key (col_varchar_key)) +; +INSERT INTO t1 VALUES +('v','v'),('r','r'); +CREATE TABLE t2 ( +col_varchar_key varchar(1) DEFAULT NULL, +col_varchar_nokey varchar(1) DEFAULT NULL, +KEY col_varchar_key(col_varchar_key)) +; +INSERT INTO t2 VALUES +('r','r'),('c','c'); +CREATE VIEW v3 AS SELECT * FROM t2; +SELECT DISTINCT alias2.col_varchar_key +FROM t1 AS alias1 JOIN v3 AS alias2 +ON alias2.col_varchar_key = alias1.col_varchar_key +HAVING col_varchar_key IN (SELECT col_varchar_nokey FROM t2) +; +col_varchar_key +r +DROP TABLE t1, t2; +DROP VIEW v3; +# End Bug#11852644 + +# Bug#12668294 - GROUP BY ON EMPTY RESULT GIVES EMPTY ROW +# INSTEAD OF NULL WHEN MATERIALIZATION ON + +CREATE TABLE t1 (col_int_nokey INT) ENGINE=MEMORY; +CREATE TABLE t2 (col_int_nokey INT) ENGINE=MEMORY; +INSERT INTO t2 VALUES (8),(7); +CREATE TABLE t3 (col_int_nokey INT) ENGINE=MEMORY; +INSERT INTO t3 VALUES (7); +SELECT MIN(t3.col_int_nokey),t1.col_int_nokey AS field3 +FROM t3 +LEFT JOIN t1 +ON t1.col_int_nokey +WHERE (194, 200) IN ( +SELECT SQ4_alias1.col_int_nokey, +SQ4_alias2.col_int_nokey +FROM t2 AS SQ4_alias1 +JOIN +t2 AS SQ4_alias2 +ON SQ4_alias2.col_int_nokey = 5 +) +GROUP BY field3 ; +MIN(t3.col_int_nokey) field3 +DROP TABLE t1; +DROP TABLE t2; +DROP TABLE t3; +CREATE TABLE t1 (f1 INT, f2 DECIMAL(5,3)) ENGINE=MyISAM; +INSERT INTO t1 (f1, f2) VALUES (1, 1.789); +INSERT INTO t1 (f1, f2) VALUES (13, 1.454); +INSERT INTO t1 (f1, f2) VALUES (10, 1.668); +CREATE TABLE t2 LIKE t1; +INSERT INTO t2 VALUES (1, 1.789); +INSERT INTO t2 VALUES (13, 1.454); +set @save_optimizer_switch=@@optimizer_switch; +set @@optimizer_switch=@optimizer_switch_local_default; +SET @@optimizer_switch='semijoin=on,materialization=on'; +EXPLAIN SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2 +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 +SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2); +COUNT(*) +2 +set @@optimizer_switch= @save_optimizer_switch; +DROP TABLE t1, t2; +CREATE TABLE t1 ( +pk int, +a varchar(1), +b varchar(4), +c varchar(4), +d varchar(4), +PRIMARY KEY (pk) +); +INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo'),(2,'f','ffff','ffff','ffff'); +CREATE TABLE t2 LIKE t1; +INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff'); +set @save_optimizer_switch=@@optimizer_switch; +set @@optimizer_switch=@optimizer_switch_local_default; +SET @@optimizer_switch='semijoin=on,materialization=on'; +EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan +SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); +pk +2 +SELECT pk FROM t1 WHERE (b,c,d) IN (SELECT b,c,d FROM t2 WHERE pk > 0); +pk +2 +DROP TABLE t1, t2; +set optimizer_switch=@save_optimizer_switch; +# +# BUG#50019: Wrong result for IN-subquery with materialization +# +create table t1(i int); +insert into t1 values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +create table t2(i int); +insert into t2 values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +create table t3(i int); +insert into t3 values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +select * from t1 where t1.i in (select t2.i from t2 join t3 where t2.i + t3.i = 5); +i +1 +2 +3 +4 +set @save_optimizer_switch=@@optimizer_switch; +set session optimizer_switch='materialization=off,in_to_exists=on'; +select * from t1 where t1.i in (select t2.i from t2 join t3 where t2.i + t3.i = 5); +i +1 +2 +3 +4 +set session optimizer_switch=@save_optimizer_switch; +drop table t1, t2, t3; +create table t0 (a int); +insert into t0 values (0),(1),(2); +create table t1 (a int); +insert into t1 values (0),(1),(2); +explain select a, a in (select a from t1) from t0; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t0 ALL NULL NULL NULL NULL 3 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 +select a, a in (select a from t1) from t0; +a a in (select a from t1) +0 1 +1 1 +2 1 +prepare s from 'select a, a in (select a from t1) from t0'; +execute s; +a a in (select a from t1) +0 1 +1 1 +2 1 +update t1 set a=123; +execute s; +a a in (select a from t1) +0 0 +1 0 +2 0 +drop table t0, t1; +set optimizer_switch='firstmatch=on'; +# +# MWL#90, review feedback: check what happens when the subquery +# looks like candidate for MWL#90 checking at the first glance +# but then subselect_hash_sj_engine::init_permanent() discovers +# that it's not possible to perform duplicate removal for the +# selected datatypes, and so materialization isn't applicable after +# all. +# +set @blob_len = 1024; +set @suffix_len = @blob_len - @prefix_len; +create table t1_1024 (a1 blob(1024), a2 blob(1024)); +create table t2_1024 (b1 blob(1024), b2 blob(1024)); +insert into t1_1024 values +(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len))); +insert into t1_1024 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t1_1024 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +explain select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1,1,1024), count(*) from t2_1024 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 Using where +2 DEPENDENT SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 Using where +select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1,1,1024), count(*) from t2_1024 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +drop table t1_1024, t2_1024; +# +# BUG##836491: Crash in Item_field::Item_field from add_ref_to_table_cond() with semijoin+materialization +# +CREATE TABLE t1 (c int, d varchar(1), KEY(d)) ; +INSERT INTO t1 VALUES (2,'x'),(2,'x'),(2,'j'),(2,'c'); +CREATE TABLE t2 (a int, d varchar(1)) ; +INSERT INTO t2 VALUES (1,'x'); +CREATE TABLE t3 (d varchar(1)) ; +INSERT INTO t3 VALUES ('x'),('x'),('j'),('c'); +SELECT t2.a, t1.c +FROM t1, t2 +WHERE t2.d IN ( SELECT d FROM t3 ) +AND t1.d = t2.d +GROUP BY 1 , 2; +a c +1 2 +drop table t1,t2,t3; +# +# BUG#836523: Crash in JOIN::get_partial_cost_and_fanout with semijoin+materialization +# +CREATE TABLE t1 (a varchar(1)); +INSERT INTO t1 VALUES ('a'),('a'); +CREATE TABLE t2 (a varchar(1)); +CREATE TABLE t3 (a int); +INSERT INTO t3 VALUES (1),(2); +CREATE TABLE t4 (a varchar(1)); +INSERT INTO t4 VALUES ('a'),('a'); +SELECT t1.a +FROM t1 +WHERE t1.a IN ( +SELECT t2.a +FROM t2, t3 +) +HAVING a IN ( +SELECT a +FROM t4 +); +a +DROP TABLE t1, t2, t3, t4; +# +# BUG#836507: Crash in setup_sj_materialization_part1() with semijoin+materialization +# +CREATE TABLE t1 (a int) ; +INSERT IGNORE INTO t1 VALUES (1),(1); +CREATE TABLE t2 (a int); +INSERT INTO t2 VALUES (1); +CREATE TABLE t3 (a int); +CREATE TABLE t4 (a int); +INSERT INTO t4 VALUES (2),(2); +CREATE TABLE t5 (a int); +INSERT INTO t5 VALUES (1); +SELECT * FROM t1 +WHERE (a) IN ( +SELECT t5.a +FROM ( +t2 +LEFT JOIN ( t3 , t4 ) +ON 1 = 1 +) +JOIN t5 +); +a +1 +1 +DROP TABLE t1,t2,t3,t4,t5; +# +# BUG#836532: Crash in Item_equal_fields_iterator::get_curr_field with semijoin+materialization +# +CREATE TABLE t2 (a int); +INSERT IGNORE INTO t2 VALUES ('a'),('a'); +Warnings: +Warning 1366 Incorrect integer value: 'a' for column `test`.`t2`.`a` at row 1 +Warning 1366 Incorrect integer value: 'a' for column `test`.`t2`.`a` at row 2 +CREATE TABLE t4 (a varchar(1)); +INSERT INTO t4 VALUES ('m'),('o'); +CREATE TABLE t3 (a varchar(1) , b varchar(1) ) ; +INSERT INTO t3 VALUES ('b','b'); +CREATE TABLE t5 (a varchar(1), KEY (a)) ; +INSERT INTO t5 VALUES ('d'),('e'); +SELECT * +FROM t2 +WHERE t2.a = ALL ( +SELECT t4.a +FROM t4 +WHERE t4.a IN ( +SELECT t3.a +FROM t3 , t5 +WHERE ( t5.a = t3.b ) +) +); +a +0 +0 +DROP TABLE t2,t3,t4,t5; +# +# BUG#860300: Second crash with get_fanout_with_deps() with semijoin + materialization +# +set @tmp_860300=@@optimizer_switch; +set optimizer_switch='semijoin=on,materialization=on,loosescan=off,firstmatch=off'; +CREATE TABLE t1 (f2 int); +INSERT INTO t1 VALUES (9),(6); +CREATE TABLE t3 (f4 int); +CREATE TABLE t4 (f6 varchar(1)); +SELECT * +FROM t3 +WHERE 'h' IN (SELECT f6 +FROM t4 +WHERE 5 IN (SELECT f2 FROM t1) +GROUP BY t4.f6); +f4 +DROP TABLE t1,t3,t4; +set optimizer_switch=@tmp_860300; +# +# BUG#860535: Assertion `keypart_map' failed in mi_rkey with semijoin +# +set @tmp_860535=@@optimizer_switch; +set optimizer_switch='semijoin=on,materialization=on,loosescan=off,firstmatch=off'; +CREATE TABLE t1 (f3 int) ; +INSERT INTO t1 VALUES (1),(7); +CREATE TABLE t2 (f3 int , f5 varchar(1), KEY (f3)) ; +INSERT INTO t2 VALUES (7,'b'); +CREATE TABLE t3 (f3 int , f4 varchar(1) , KEY(f3), KEY (f4,f3)) ; +INSERT INTO t3 VALUES (1,'t'),(7,'g'); +CREATE TABLE t4 +SELECT f3 +FROM t1 WHERE ( f3 ) NOT IN ( +SELECT f3 +FROM t2 +WHERE f5 IN ( +SELECT f4 +FROM t3 +WHERE t3.f3 < 3 +) +); +SELECT * FROM t4; +f3 +1 +7 +DROP TABLE t1, t2, t3, t4; +set optimizer_switch=@tmp_860535; +# +# BUG#860553: Crash in create_ref_for_key with semijoin + materialization +# +CREATE TABLE t1 (f1 int) ; +CREATE TABLE t2 (f5 varchar(52) NOT NULL) ; +CREATE TABLE t3 (f1 varchar(3), f4 varchar(52) , KEY (f4), PRIMARY KEY (f1)); +CREATE TABLE t4 (f3 int, KEY (f3)); +INSERT INTO t4 VALUES (17),(20); +CREATE TABLE t5 (f2 int); +INSERT INTO t5 VALUES (0),(0); +SELECT * +FROM t1 +JOIN t2 +ON ( t2.f5 ) IN ( +SELECT t3.f4 +FROM t3 +WHERE ( 1 ) IN ( +SELECT t4.f3 +FROM t4 , t5 +) +); +f1 f5 +DROP TABLE t1, t2, t3, t4, t5; +# +# BUG#868908: Crash in check_simple_equality() with semijoin + materialization + prepared statement +# +CREATE TABLE t1 ( a int ); +CREATE TABLE t3 ( b int, c int) ; +CREATE TABLE t2 ( a int ) ; +CREATE TABLE t4 ( a int , c int) ; +PREPARE st1 FROM " +SELECT STRAIGHT_JOIN * +FROM t1 +WHERE ( 3 ) IN ( + SELECT t3.b + FROM t3 + LEFT JOIN ( + t2 STRAIGHT_JOIN t4 ON ( t4.c = t2.a ) + ) ON ( t4.a = t3.c ) +); +"; +EXECUTE st1; +a +EXECUTE st1; +a +DROP TABLE t1,t2,t3,t4; +# +# BUG#901032: Wrong result for MIN/MAX on an indexed column with materialization and semijoin +# +CREATE TABLE t1 ( a INT, KEY(a) ); +INSERT INTO t1 VALUES (1); +CREATE TABLE t2 ( b INT ); +INSERT INTO t2 VALUES (2); +CREATE TABLE t3 ( c INT ); +INSERT INTO t3 VALUES (2); +SELECT MIN(a) FROM t1, t2 WHERE b IN (SELECT c FROM t3 GROUP BY c); +MIN(a) +1 +DROP TABLE t1,t2,t3; +# +# +# BUG#902632: Crash or invalid read at st_join_table::cleanup, st_table::disable_keyread +# +CREATE TABLE t1 ( a INT ); +INSERT INTO t1 VALUES (1), (2); +CREATE TABLE t2 ( b INT ); +INSERT INTO t2 VALUES (3), (4); +CREATE TABLE t3 ( c INT ); +INSERT INTO t3 VALUES (5), (6); +SELECT * FROM t1 WHERE EXISTS ( +SELECT DISTINCT b FROM t2 +WHERE b <= a +AND b IN ( SELECT c FROM t3 GROUP BY c ) +); +a +DROP TABLE t1,t2,t3; +# +# BUG#901506: Crash in TABLE_LIST::print on EXPLAIN EXTENDED +# +CREATE TABLE t1 ( a INT, KEY(a) ); +INSERT INTO t1 VALUES (8); +EXPLAIN EXTENDED +SELECT * FROM t1 +WHERE a IN ( SELECT MIN(a) FROM t1 ); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +Warnings: +Note 1003 /* select#1 */ select 8 AS `a` from dual where <expr_cache><8>(<in_optimizer>(8,<exists>(/* select#2 */ select min(`test`.`t1`.`a`) from `test`.`t1` having <cache>(8) = <ref_null_helper>(min(`test`.`t1`.`a`))))) +DROP TABLE t1; +# +# BUG#904432: Wrong result with LEFT JOIN, constant table, semijoin=ON,materialization=ON +# +CREATE TABLE t1 ( a INT ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (4); +CREATE TABLE t2 ( b INT NOT NULL, c INT ); +INSERT INTO t2 VALUES (4,2),(4,2),(4,4),(1,1); +SELECT * FROM t1 LEFT JOIN t2 ON ( a = b ) +WHERE a IN ( SELECT c FROM t2 ); +a b c +4 4 2 +4 4 2 +4 4 4 +DROP TABLE t1,t2; +# +# BUG#922254: Assertion `0' failed at item_cmpfunc.cc:5899: Item* Item_equal::get_first(JOIN_TAB*, Item*) +# +CREATE TABLE t1 ( a VARCHAR(3) ); +CREATE TABLE t2 ( b VARCHAR(3), c VARCHAR(8), KEY(c) ); +INSERT INTO t2 VALUES ('USA','Abilene'),('USA','Akron'); +EXPLAIN +SELECT * FROM +( SELECT * FROM t1 ) AS alias1, +t2 AS alias2 +WHERE b = a AND a IN ( +SELECT alias3.c +FROM t2 AS alias3, t2 AS alias4 +WHERE alias4.c = alias3.b +); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +3 MATERIALIZED alias3 ALL NULL NULL NULL NULL 2 +3 MATERIALIZED alias4 index c c 11 NULL 2 Using where; Using index; Using join buffer (flat, BNL join) +DROP TABLE t1,t2; +# +# BUG#928048: Query containing IN subquery with OR in the where clause returns a wrong result +# +create table t1 (a int, b int); +insert into t1 values (7,5), (3,3), (5,4), (9,3); +create table t2 (a int, b int, index i_a(a)); +insert into t2 values +(4,2), (7,9), (7,4), (3,1), (5,3), (3,1), (9,4), (8,1); +explain select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where +2 MATERIALIZED t2 ALL i_a NULL NULL NULL 8 Using where +select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1); +a b +7 5 +3 3 +drop table t1,t2; +# +# BUG#933407: Valgrind warnings in mark_as_null_row with materialization+semijoin, STRAIGHT_JOIN, impossible WHERE +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0),(8); +SELECT STRAIGHT_JOIN MIN(a) FROM t1 +WHERE a IN ( +SELECT a FROM t1 +WHERE 'condition'='impossible' + ); +MIN(a) +NULL +DROP TABLE t1; +# +# BUG#938131: Subquery materialization is not used in CREATE TABLE SELECT +# +CREATE TABLE t1(a int); +INSERT INTO t1 values(1),(2); +CREATE TABLE t2(a int); +INSERT INTO t2 values(1),(2); +# Should use Materialization: +EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a HAVING a > 1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using temporary +flush status; +CREATE TABLE t3 SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a HAVING a > 1); +SHOW STATUS LIKE 'Created_tmp_tables'; +Variable_name Value +Created_tmp_tables 3 +DROP TABLE t1,t2,t3; +# +# BUG#939009: Crash with aggregate function in IN subquery +# +SET @save_optimizer_switch=@@optimizer_switch; +SET optimizer_switch='materialization=on,semijoin=on'; +CREATE TABLE t1 (a int, b int); +INSERT INTO t1 VALUES (7,1), (4,2), (7,7); +CREATE TABLE t2 ( c INT ); +INSERT INTO t2 VALUES (4), (7), (6); +EXPLAIN EXTENDED +SELECT * FROM t1 +WHERE a IN (SELECT MAX(c) FROM t2) AND b=7 AND (a IS NULL OR a=b); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from <materialize> (/* select#2 */ select max(`test`.`t2`.`c`) from `test`.`t2`) join `test`.`t1` where `test`.`t1`.`b` = 7 and `test`.`t1`.`a` = `<subquery2>`.`MAX(c)` and (<cache>(/*always not null*/ 1 is null) or `<subquery2>`.`MAX(c)` = 7) +SELECT * FROM t1 +WHERE a IN (SELECT MAX(c) FROM t2) AND b=7 AND (a IS NULL OR a=b); +a b +7 7 +EXPLAIN +SELECT * FROM t1 +WHERE a IN (SELECT MAX(c) FROM t2 WHERE c < 4) AND b=7 AND (a IS NULL OR a=b); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where +SELECT * FROM t1 +WHERE a IN (SELECT MAX(c) FROM t2 WHERE c < 4) AND b=7 AND (a IS NULL OR a=b); +a b +SET optimizer_switch=@save_optimizer_switch; +DROP TABLE t1,t2; +# +# BUG#946055: Crash with semijoin IN subquery when hash join is used +# +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (7); +CREATE TABLE t2 (b int, c int, d varchar(1), e varchar(1), KEY (c), KEY (d, c)); +INSERT INTO t2 VALUES +(4,2,'v','v'), (6,1,'v','v'), (0,5,'x','x'), (7,1,'x','x'), +(7,3,'i','i'), (7,1,'e','e'), (1,4,'p','p'), (1,2,'j','j'); +SET @save_optimizer_switch=@@optimizer_switch; +SET @save_join_cache_level=@@join_cache_level; +SET join_cache_level=2; +EXPLAIN +SELECT a, c FROM t1, t2 +WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 +WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +1 PRIMARY t2 index NULL c 5 NULL 8 Using where; Using index +2 MATERIALIZED s2 ref d d 4 const 2 Using where; Using index +2 MATERIALIZED s1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t2 ALL NULL NULL NULL NULL 8 +SELECT a, c FROM t1, t2 +WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 +WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2)); +a c +7 1 +7 1 +7 1 +SET optimizer_switch='join_cache_hashed=on'; +SET join_cache_level=4; +EXPLAIN +SELECT a, c FROM t1, t2 +WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 +WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +1 PRIMARY t2 index NULL c 5 NULL 8 Using where; Using index +2 MATERIALIZED s2 ref d d 4 const 2 Using where; Using index +2 MATERIALIZED s1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t2 ALL NULL NULL NULL NULL 8 +SELECT a, c FROM t1, t2 +WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 +WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2)); +a c +7 1 +7 1 +7 1 +SET optimizer_switch=@save_optimizer_switch; +SET join_cache_level=@save_join_cache_level; +DROP TABLE t1,t2; +# +# BUG#952297: Server crashes on 2nd execution of PS in Field::is_null with semijoin+materialization +# +CREATE TABLE t1 ( a VARCHAR(1) ); +INSERT INTO t1 VALUES ('y'),('z'); +CREATE TABLE t2 ( b VARCHAR(1), c VARCHAR(1) ); +INSERT INTO t2 VALUES ('v','v'),('v','v'); +CREATE VIEW v2 AS SELECT * FROM t2; +PREPARE ps FROM ' +SELECT a FROM t1, v2 +WHERE ( c, b ) IN ( SELECT b, b FROM t2 ) +GROUP BY a '; +EXECUTE ps; +a +y +z +EXECUTE ps; +a +y +z +DROP VIEW v2; +DROP TABLE t1, t2; +# +# BUG#1000269: Wrong result (extra rows) with semijoin+materialization, IN subqueries, join_cache_level>0 +# +CREATE TABLE t1 (a1 VARCHAR(1), a2 VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('b','b'),('e','e'); +CREATE TABLE t2 (b1 VARCHAR(1), b2 VARCHAR(1), KEY(b1)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('v','v'),('s','s'),('l','l'), ('y','y'),('c','c'),('i','i'); +SELECT * FROM t1, t2 WHERE b1 IN ( SELECT b2 FROM t2 WHERE b1 > 'o' ) AND ( b1 < 'l' OR a1 IN ('b','c') ); +a1 a2 b1 b2 +b b v v +b b s s +b b y y +DROP TABLE t1,t2; +# +# MDEV-4465: Reproducible crash (mysqld got signal 11) in multi_delete::initialize_tables with semijoin+materialization +# +CREATE TABLE t1 ( +id int(11) NOT NULL +); +CREATE TABLE t2 ( +id int(11) NOT NULL, +a_id int(11) DEFAULT NULL +); +insert into t1 values (1), (2), (3); +insert into t2 values (1, 1), (2, 1), (3, 1), (4, 2), (5, 3), (6, 3), (7, 3); +delete t2 from t2 where a_id in (select * from (select t1.id from t1 limit 2) as x); +drop table t1,t2; +# This must be at the end: +set optimizer_switch=@subselect_sj_mat_tmp; +set join_cache_level=@save_join_cache_level; +# +# MDEV-4908: Assertion `((Item_cond *) cond)->functype() == +# ((Item_cond *) new_item)->functype()' fails on a query with +# IN and equal conditions, AND/OR, materialization+semijoin +# +SET @save_optimizer_switch=@@optimizer_switch; +SET optimizer_switch = 'materialization=on,semijoin=on'; +CREATE TABLE t1 (pk INT, a INT, b INT, PRIMARY KEY(pk)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1,3,5),(2,4,6); +SELECT * FROM t1 WHERE 8 IN ( SELECT MIN(pk) FROM t1 ) AND ( pk = a OR pk = b ); +pk a b +drop table t1; +SET optimizer_switch=@save_optimizer_switch; +# +# MDEV-5011: ERROR Plugin 'MEMORY' has ref_count=1 after shutdown for SJM queries +# +CREATE TABLE t1 (pk INT, a INT, b INT, PRIMARY KEY(pk)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1,3,5),(2,4,6); +SELECT * FROM t1 WHERE 8 IN (SELECT MIN(pk) FROM t1) AND (pk = a OR pk = b); +pk a b +DROP TABLE t1; +# +# MDEV-5368: Server crashes in Item_in_subselect::optimize on 2nd +# execution of PS with IN subqueries, materialization+semijoin +# +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(3); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2; +INSERT INTO t2 VALUES (8),(9); +PREPARE stmt FROM " +SELECT * FROM t1 WHERE 1 IN ( SELECT b FROM v2 WHERE 2 IN ( SELECT MAX(a) FROM t1 ) ) +"; +EXECUTE stmt; +a +EXECUTE stmt; +a +DROP TABLE t1, t2; +DROP VIEW v2; +# +# MDEV-5811: Server crashes in best_access_path with materialization+semijoin and big_tables=ON +# +SET @tmp_mdev5811= @@big_tables; +SET big_tables = ON; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (3),(4); +SELECT * FROM t1 AS t1_1, t1 AS t1_2 +WHERE ( t1_1.a, t1_2.a ) IN ( SELECT MAX(b), MIN(b) FROM t2 ); +a a +DROP TABLE t1,t2; +SET big_tables=@tmp_mdev5811; +# End of 5.3 tests +# +# MDEV-5056: Wrong result (extra rows) with materialization+semijoin, IN subqueries +# +set @tmp_mdev5056=@@join_cache_level; +SET join_cache_level = 2; +CREATE TABLE t1 ( c1 VARCHAR(2), c2 VARCHAR(2), INDEX(c1) ) ENGINE=MyISAM; +INSERT INTO t1 VALUES +('JP','OM'),('VA','JP'),('CA','ML'),('ML','EG'),('DK','CA'), +('DK','QA'),('YE','PL'),('TR','ZW'),('DK','SK'),('SK','DK'), +('RO','ML'),('ML','BG'),('BG','ZW'),('ZW','GE'),('GE','JP'), +('PL','EG'),('QA','YE'),('WF','DK'),('DK','JP'),('EG','OM'); +CREATE TABLE t2 ( c3 VARCHAR(2), c4 VARCHAR(2) ) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('CA','ML'),('IN','HU'),('HU','IN'); +SELECT * FROM t1 AS alias1, t1 AS alias2 +WHERE ( alias2.c2, alias1.c1 ) IN ( SELECT c4, c3 FROM t2 ) AND alias1.c1 IN ( SELECT c2 FROM t1 ); +c1 c2 c1 c2 +CA ML CA ML +CA ML RO ML +DROP TABLE t1,t2; +set join_cache_level=@tmp_mdev5056; +# +# MDEV-5368: Server crashes in Item_in_subselect::optimize on 2nd +# execution of PS with IN subqueries, materialization+semijoin +# +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(3); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2; +INSERT INTO t2 VALUES (8),(9); +PREPARE stmt FROM " +SELECT * FROM t1 WHERE 1 IN ( SELECT b FROM v2 WHERE 2 IN ( SELECT MAX(a) FROM t1 ) ) +"; +EXECUTE stmt; +a +EXECUTE stmt; +a +DROP TABLE t1, t2; +DROP VIEW v2; +# +# MDEV-6289 : Unexpected results when querying information_schema +# +CREATE TABLE t1 ( +id int(11) unsigned NOT NULL AUTO_INCREMENT, +db varchar(254) NOT NULL DEFAULT '', +PRIMARY KEY (id), +UNIQUE KEY db (db) +) DEFAULT CHARSET=utf8; +INSERT INTO t1 (db) VALUES ('mysqltest1'),('mysqltest2'),('mysqltest3'),('mysqltest4'); +drop database if exists mysqltest1; +drop database if exists mysqltest2; +drop database if exists mysqltest3; +drop database if exists mysqltest4; +create database mysqltest1; +create database mysqltest2; +create database mysqltest3; +create database mysqltest4; +SELECT db FROM t1 WHERE db IN (SELECT SCHEMA_NAME FROM information_schema.schemata) ORDER BY db DESC; +db +mysqltest4 +mysqltest3 +mysqltest2 +mysqltest1 +EXPLAIN EXTENDED +SELECT db FROM t1 WHERE db IN (SELECT SCHEMA_NAME FROM information_schema.schemata) ORDER BY db DESC; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2 100.00 Using temporary; Using filesort +1 PRIMARY t1 eq_ref db db 764 information_schema.schemata.SCHEMA_NAME 1 100.00 Using where; Using index +2 MATERIALIZED schemata ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 select `test`.`t1`.`db` AS `db` from `test`.`t1` semi join (`information_schema`.`schemata`) where `test`.`t1`.`db` = `information_schema`.`schemata`.`SCHEMA_NAME` order by `test`.`t1`.`db` desc +drop table t1; +drop database mysqltest1; +drop database mysqltest2; +drop database mysqltest3; +drop database mysqltest4; +# +# MDEV-7810 Wrong result on execution of a query as a PS +# (both 1st and further executions) +CREATE TABLE t1 (a INT NOT NULL) ENGINE=MyISAM; +INSERT INTO t1 VALUES (0),(8); +SELECT a FROM (SELECT DISTINCT * FROM t1) AS sq WHERE a IN (SELECT MIN(t2.a) FROM (t1 AS t2)); +a +0 +PREPARE stmt FROM " +SELECT a FROM (SELECT DISTINCT * FROM t1) AS sq WHERE a IN (SELECT MIN(t2.a) FROM (t1 AS t2)) +"; +execute stmt; +a +0 +execute stmt; +a +0 +drop table t1; +# +# MDEV-12429: IN subquery used in WHERE of EXISTS subquery +# +CREATE TABLE t1 ( +pk INT, f1 INT NOT NULL, f2 VARCHAR(3), f3 INT NULL, PRIMARY KEY(pk)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1,1,'foo',8), (2,5,'bar',7); +SELECT sq1.f2 FROM t1 AS sq1 +WHERE EXISTS ( SELECT * FROM t1 AS sq2 +WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 ); +f2 +foo +set @save_optimizer_switch= @@optimizer_switch; +set optimizer_switch='exists_to_in=off'; +EXPLAIN +SELECT sq1.f2 FROM t1 AS sq1 +WHERE EXISTS ( SELECT * FROM t1 AS sq2 +WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY sq1 ALL NULL NULL NULL NULL 2 Using where +2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 +2 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +# this checks the result set above +set optimizer_switch= 'materialization=off,semijoin=off'; +SELECT sq1.f2 FROM t1 AS sq1 +WHERE EXISTS ( SELECT * FROM t1 AS sq2 +WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 ); +f2 +foo +set optimizer_switch= @save_optimizer_switch; +DROP TABLE t1; +# +# MDEV-12145: IN subquery used in WHERE of EXISTS subquery +# +CREATE TABLE t1 (f1 INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (4),(6); +CREATE TABLE t2 (i2 INT, KEY(i2)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (8),(7),(1); +CREATE TABLE t3 (f3 INT, i3 INT, KEY(i3)) ENGINE=MyISAM; +INSERT INTO t3 VALUES (8,0),(6,3),(2,8),(3,8),(1,6),(0,0),(1,0),(1,5); +set @save_optimizer_switch= @@optimizer_switch; +set optimizer_switch='exists_to_in=off'; +SELECT * FROM t1 +WHERE EXISTS ( SELECT * FROM t2, t3 +WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) ); +f1 +6 +EXPLAIN EXTENDED +SELECT * FROM t1 +WHERE EXISTS ( SELECT * FROM t2, t3 +WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) ); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 DEPENDENT SUBQUERY t2 index i2 i2 5 NULL 3 100.00 Using where; Using index; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t3 ref i3 i3 5 test.t2.i2 2 100.00 Using index +3 MATERIALIZED t3 ALL NULL NULL NULL NULL 8 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1 +Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where <expr_cache><`test`.`t1`.`f1`>(exists(/* select#2 */ select 1 from `test`.`t2` semi join (`test`.`t3`) join `test`.`t3` where `test`.`t3`.`i3` = `test`.`t2`.`i2` and `test`.`t1`.`f1` = `test`.`t3`.`f3`)) +# this checks the result set above +set optimizer_switch= 'materialization=off,semijoin=off'; +SELECT * FROM t1 +WHERE EXISTS ( SELECT * FROM t2, t3 +WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) ); +f1 +6 +set optimizer_switch= @save_optimizer_switch; +DROP TABLE t1,t2,t3; +# +# MDEV-9686: IN subquery used in WHERE of a subquery from select list +# +CREATE TABLE t1 (pk INT PRIMARY KEY, f1 INT); +INSERT INTO t1 VALUES (1, 4),(2, 3),(3, 3),(4, 6),(5, 3); +CREATE TABLE t2 (f2 INT); +INSERT INTO t2 VALUES (1),(2),(3),(4),(5); +# t1.pk is always IN ( SELECT f2 FROM t2 ), +# so the IN condition should be true for every row, +# and thus COUNT(*) should always return 5 +SELECT pk, f1, ( SELECT COUNT(*) FROM t2 +WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1; +pk f1 sq +1 4 5 +2 3 5 +3 3 5 +4 6 5 +5 3 5 +EXPLAIN EXTENDED +SELECT pk, f1, ( SELECT COUNT(*) FROM t2 +WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00 +2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join) +3 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1 +Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`f1` AS `f1`,<expr_cache><`test`.`t1`.`pk`>((/* select#2 */ select count(0) from `test`.`t2` semi join (`test`.`t2`) where `test`.`t1`.`pk` = `test`.`t2`.`f2`)) AS `sq` from `test`.`t1` +# this checks the result set above +set @save_optimizer_switch= @@optimizer_switch; +set optimizer_switch= 'materialization=off,semijoin=off'; +SELECT pk, f1, ( SELECT COUNT(*) FROM t2 +WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1; +pk f1 sq +1 4 5 +2 3 5 +3 3 5 +4 6 5 +5 3 5 +set optimizer_switch= @save_optimizer_switch; +DROP TABLE t1,t2; +# +# mdev-12838: scan of materialized of semi-join subquery in join +# +set @save_optimizer_switch=@@optimizer_switch; +CREATE TABLE t1 ( +dispatch_group varchar(32), +assignment_group varchar(32), +sys_id char(32), +PRIMARY KEY (sys_id), +KEY idx1 (dispatch_group), +KEY idx2 (assignment_group) +) ENGINE=MyISAM; +CREATE TABLE t2 ( +ugroup varchar(32), +user varchar(32), +sys_id char(32), +PRIMARY KEY (sys_id), +KEY idx3 (ugroup), +KEY idx4 (user) +) ENGINE=MyISAM; +CREATE TABLE t3 ( +type mediumtext, +sys_id char(32), +PRIMARY KEY (sys_id) +) ENGINE=MyISAM; +set optimizer_switch='materialization=off'; +explain SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +WHERE t2.ugroup = t3_i.sys_id AND +t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND +t2.user = '86826bf03710200044e0bfc8bcbe5d79'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where; Start temporary +1 PRIMARY t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where +1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t3_i.sys_id 2 Using index condition; Using where; End temporary +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 32 test.t1.assignment_group 1 Using where; Using index +SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +WHERE t2.ugroup = t3_i.sys_id AND +t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND +t2.user = '86826bf03710200044e0bfc8bcbe5d79'); +assignment_group +df50316637232000158bbfc8bcbe5d23 +e08fad2637232000158bbfc8bcbe5d39 +ec70316637232000158bbfc8bcbe5d60 +7b10fd2637232000158bbfc8bcbe5d30 +ebb4620037332000158bbfc8bcbe5d89 +set optimizer_switch='materialization=on'; +explain SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +WHERE t2.ugroup = t3_i.sys_id AND +t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND +t2.user = '86826bf03710200044e0bfc8bcbe5d79'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2 +1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t2.ugroup 2 Using where +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 32 test.t1.assignment_group 1 Using where; Using index +2 MATERIALIZED t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where +2 MATERIALIZED t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where +SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +WHERE t2.ugroup = t3_i.sys_id AND +t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND +t2.user = '86826bf03710200044e0bfc8bcbe5d79'); +assignment_group +df50316637232000158bbfc8bcbe5d23 +e08fad2637232000158bbfc8bcbe5d39 +ec70316637232000158bbfc8bcbe5d60 +7b10fd2637232000158bbfc8bcbe5d30 +ebb4620037332000158bbfc8bcbe5d89 +DROP TABLE t1,t2,t3; +set optimizer_switch=@save_optimizer_switch; +# +# MDEV-16751: Server crashes in st_join_table::cleanup or +# TABLE_LIST::is_with_table_recursive_reference with join_cache_level>2 +# +set @save_join_cache_level= @@join_cache_level; +set join_cache_level=4; +CREATE TABLE t1 ( id int NOT NULL); +INSERT INTO t1 VALUES (11),(12),(13),(14),(15),(16),(17),(18),(19); +CREATE TABLE t2 (i1 int NOT NULL, i2 int NOT NULL) ; +INSERT INTO t2 VALUES (11,11),(12,12),(13,13); +explain +SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t1 hash_ALL NULL #hash#$hj 4 test.t2.i1 9 Using where; Using join buffer (flat, BNLH join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where +SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2); +1 +1 +1 +1 +set @@join_cache_level= @save_join_cache_level; +alter table t1 add key(id); +explain +SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t1 ref id id 4 test.t2.i1 2 Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where +SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2); +1 +1 +1 +1 +drop table t1,t2; +# +# MDEV-15454: Nested SELECT IN returns wrong results +# +CREATE TABLE t1 ( a int NOT NULL PRIMARY KEY); +CREATE TABLE t2 ( a int, b int ); +INSERT INTO t2 VALUES (7878, 96),(3465, 96),(1403, 96),(4189, 96),(8732, 96), (5,96); +CREATE TABLE t3 (c int unsigned NOT NULL, b int unsigned NOT NULL, PRIMARY KEY (c,b)); +INSERT INTO t3 (c, b) VALUES (27, 96); +CREATE PROCEDURE prepare_data() +BEGIN +DECLARE i INT DEFAULT 1; +WHILE i < 1000 DO +INSERT INTO t1 (a) VALUES (i); +INSERT INTO t2 (a,b) VALUES (i,56); +INSERT INTO t3 (c,b) VALUES (i,i); +SET i = i + 1; +END WHILE; +END$$ +CALL prepare_data(); +SELECT t2.a FROM t2 WHERE t2.b IN (SELECT t3.b FROM t3 WHERE t3.c= 27); +a +7878 +3465 +1403 +4189 +8732 +5 +set @save_optimizer_switch= @@optimizer_switch; +SET optimizer_switch='materialization=off'; +SELECT t1.a FROM t1 +WHERE t1.a IN (SELECT t2.a FROM t2 WHERE t2.b IN (SELECT t3.b FROM t3 WHERE t3.c= 27)) LIMIT 5; +a +5 +SET optimizer_switch='materialization=on'; +SELECT t1.a FROM t1 +WHERE t1.a IN (SELECT t2.a FROM t2 WHERE t2.b IN (SELECT t3.b FROM t3 WHERE t3.c= 27)) LIMIT 5; +a +5 +drop procedure prepare_data; +set @@optimizer_switch= @save_optimizer_switch; +drop table t1,t2,t3; +CREATE TABLE t1 ( id int NOT NULL, key(id)); +INSERT INTO t1 VALUES (11),(12),(13),(14),(15),(16),(17),(18),(19); +CREATE TABLE t2 (i1 int NOT NULL, i2 int NOT NULL); +INSERT INTO t2 VALUES (11,11),(12,12),(13,13); +CREATE VIEW v1 AS SELECT t2.i1 FROM t2 where t2.i1 = t2.i2; +explain SELECT 1 FROM t1 where t1.id IN (SELECT v1.i1 from v1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t1 ref id id 4 test.t2.i1 2 Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where +SELECT 1 FROM t1 where t1.id IN (SELECT v1.i1 from v1); +1 +1 +1 +1 +drop table t1,t2; +drop view v1; +# End of 5.5 tests +# +# MDEV-7220: Materialization strategy is not used for REPLACE ... SELECT +# +create table t0(a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1 (a int, b int, c int); +insert into t1 +select A.a+B.a*10+C.a*100, A.a+B.a*10+C.a*100, A.a+B.a*10+C.a*100 +from t0 A, t0 B, t0 C; +create table t2 (a int, b int, c int); +insert into t2 select A.a, A.a, A.a from t1 A; +insert into t2 select * from t2; +insert into t2 select * from t2; +create table t3 as select * from t2 limit 1; +# The testcase only makes sense if the following uses Materialization: +explain +select * from t1 where (a,b) in (select max(a),b from t2 group by b); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 1000 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.b 1 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4000 Using temporary +flush status; +replace into t3 +select * from t1 where (a,b) in (select max(a),b from t2 group by b); +# Sequential reads: +# 1K is read from t1 +# 4K is read from t2 +# 1K groups is read from the tmp. table +# +# Lookups: +# 4K lookups in group by table +# 1K lookups in temp.table +# +# Writes: +# 2x 1K writes to temporary tables (grouping table and subquery materialization table +# +# The point is that neither counter should be in the millions (this +# will happen if Materialization is not used +show status where Variable_name like 'Handler_read%' or Variable_name like 'Handler_%write%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 5000 +Handler_read_last 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_retry 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 6003 +Handler_tmp_write 2000 +Handler_write 1000 +drop table t0,t1,t2,t3; +# +# MDEV-7971: Assertion `name != __null' failed in ACL_internal_schema_registry::lookup +# on 2nd execution os PS with multi-table update +# +CREATE TABLE t1 (f1 INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (f2 INT); +INSERT INTO t2 VALUES (3),(4); +CREATE TABLE t3 (f3 INT); +INSERT INTO t3 VALUES (5),(6); +PREPARE stmt FROM ' + UPDATE t1, t2 + SET f1 = 5 + WHERE 8 IN ( SELECT MIN(f3) FROM t3 ) +'; +EXECUTE stmt; +EXECUTE stmt; +DROP TABLE t1,t2,t3; +# +# MDEV-10389: Query returns different results on a debug vs non-debug build of the same revision +# +CREATE TABLE t1 (i1 INT, i2 INT NOT NULL); +INSERT INTO t1 VALUES (1,4),(2,6); +SELECT * FROM t1 AS alias1 +WHERE alias1.i1 IN ( +SELECT i1 FROM t1 WHERE alias1.i2 IN ( SELECT i2 FROM t1 HAVING i2 <> 7 ) +); +i1 i2 +1 4 +2 6 +DROP TABLE t1; +set @subselect_mat_test_optimizer_switch_value=null; +set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off'; +set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; +create table t0 (a int); +insert into t0 values (0),(1),(2); +create table t1 (a int); +insert into t1 values (0),(1),(2); +explain select a, a in (select a from t1) from t0; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t0 ALL NULL NULL NULL NULL 3 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 +select a, a in (select a from t1) from t0; +a a in (select a from t1) +0 1 +1 1 +2 1 +prepare s from 'select a, a in (select a from t1) from t0'; +execute s; +a a in (select a from t1) +0 1 +1 1 +2 1 +update t1 set a=123; +execute s; +a a in (select a from t1) +0 0 +1 0 +2 0 +drop table t0, t1; +# +# LPBUG#609121: RQG: wrong result on aggregate + NOT IN + HAVING and +# partial_match_table_scan=on +# +create table t1 (c1 int); +create table t2 (c2 int); +insert into t1 values (1); +insert into t2 values (2); +set @@optimizer_switch='semijoin=off'; +EXPLAIN +SELECT SUM(c1) c1_sum FROM t1 WHERE c1 IN (SELECT c2 FROM t2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +2 MATERIALIZED t2 system NULL NULL NULL NULL 1 +SELECT SUM(c1) c1_sum FROM t1 WHERE c1 IN (SELECT c2 FROM t2); +c1_sum +NULL +EXPLAIN +SELECT SUM(c1) c1_sum FROM t1 WHERE c1 IN (SELECT c2 FROM t2) HAVING c1_sum; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +2 MATERIALIZED t2 system NULL NULL NULL NULL 1 +SELECT SUM(c1) c1_sum FROM t1 WHERE c1 IN (SELECT c2 FROM t2) HAVING c1_sum; +c1_sum +drop table t1, t2; +# +# BUG#52344 - Subquery materialization: +# Assertion if subquery in on-clause of outer join +# +set @@optimizer_switch='semijoin=off'; +CREATE TABLE t1 (i INTEGER); +INSERT INTO t1 VALUES (10); +CREATE TABLE t2 (j INTEGER); +INSERT INTO t2 VALUES (5); +CREATE TABLE t3 (k INTEGER); +EXPLAIN +SELECT i FROM t1 LEFT JOIN t2 ON (j) IN (SELECT k FROM t3); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where +2 MATERIALIZED t3 system NULL NULL NULL NULL 0 Const row not found +SELECT i FROM t1 LEFT JOIN t2 ON (j) IN (SELECT k FROM t3); +i +10 +EXPLAIN +SELECT i FROM t1 LEFT JOIN t2 ON (j) IN (SELECT max(k) FROM t3); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where +2 MATERIALIZED t3 system NULL NULL NULL NULL 0 Const row not found +SELECT i FROM t1 LEFT JOIN t2 ON (j) IN (SELECT max(k) FROM t3); +i +10 +DROP TABLE t1, t2, t3; +# +# LPBUG#611622/BUG#52344: Subquery materialization: Assertion +# if subquery in on-clause of outer join +# +CREATE TABLE t1 (c1 int); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (c2 int); +INSERT INTO t2 VALUES (10); +PREPARE st1 FROM " +SELECT * +FROM t2 LEFT JOIN t2 t3 ON (8, 4) IN (SELECT c1, c1 FROM t1)"; +EXECUTE st1; +c2 c2 +10 NULL +EXECUTE st1; +c2 c2 +10 NULL +DROP TABLE t1, t2; +# +# Testcase backport: BUG#46548 IN-subqueries return 0 rows with materialization=on +# +CREATE TABLE t1 ( +pk int, +a varchar(1), +b varchar(4), +c varchar(4), +d varchar(4), +PRIMARY KEY (pk) +); +INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo'),(2,'f','ffff','ffff','ffff'); +CREATE TABLE t2 LIKE t1; +INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff'); +SET @@optimizer_switch='default,semijoin=on,materialization=on'; +EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where +SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); +pk +2 +SELECT pk FROM t1 WHERE (b,c,d) IN (SELECT b,c,d FROM t2 WHERE pk > 0); +pk +2 +DROP TABLE t1, t2; +# +# BUG#724228: Wrong result with materialization=on and three aggregates in maria-5.3-mwl90 +# +CREATE TABLE t1 ( f2 int(11)) ; +INSERT IGNORE INTO t1 VALUES ('7'),('9'),('7'),('4'),('2'),('6'),('8'),('5'),('6'),('188'),('2'),('1'),('1'),('0'),('9'),('4'); +CREATE TABLE t2 ( f1 int(11), f2 int(11)) ENGINE=MyISAM; +INSERT IGNORE INTO t2 VALUES ('1','1'); +CREATE TABLE t3 ( f1 int(11), f2 int(11), f3 int(11), PRIMARY KEY (f1)) ; +INSERT IGNORE INTO t3 VALUES ('16','6','1'),('18','3','4'),('19',NULL,'9'),('20','0','6'),('41','2','0'),('42','2','5'),('43','9','6'),('44','7','4'),('45','1','4'),('46','222','238'),('47','3','6'),('48','6','6'),('49',NULL,'1'),('50','5','1'); +SET @_save_join_cache_level = @@join_cache_level; +SET @_save_optimizer_switch = @@optimizer_switch; +SET join_cache_level = 1; +SET optimizer_switch='materialization=on'; +SELECT f1 FROM t3 +WHERE +f1 NOT IN (SELECT MAX(f2) FROM t1) AND +f3 IN (SELECT MIN(f1) FROM t2) AND +f1 IN (SELECT COUNT(f2) FROM t1); +f1 +16 +SET @@join_cache_level = @_save_join_cache_level; +SET @@optimizer_switch = @_save_optimizer_switch; +drop table t1, t2, t3; +# +# LPBUG#719198 Ordered_key::cmp_key_with_search_key(rownum_t): Assertion `!compare_pred[i]->null_value' +# failed with subquery on both sides of NOT IN and materialization +# +CREATE TABLE t1 (f1a int, f1b int) ; +INSERT IGNORE INTO t1 VALUES (1,1),(2,2); +CREATE TABLE t2 ( f2 int); +INSERT IGNORE INTO t2 VALUES (3),(4); +CREATE TABLE t3 (f3a int, f3b int); +set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,in_to_exists=off'; +EXPLAIN +SELECT * FROM t2 WHERE (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +SELECT * FROM t2 WHERE (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); +f2 +EXPLAIN +SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used +3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); +(SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1) +NULL +EXPLAIN +SELECT * FROM t2 WHERE (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +SELECT * FROM t2 WHERE (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1); +f2 +EXPLAIN +SELECT (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used +3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +SELECT (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1); +(SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1) +NULL +drop table t1, t2, t3; +# +# LPBUG#730604 Assertion `bit < (map)->n_bits' failed in maria-5.3 with +# partial_match_rowid_merge +# +CREATE TABLE t1 (f1 int NOT NULL, f2 int, f3 int) ; +CREATE TABLE t2 (f1 int NOT NULL, f2 int, f3 int) ; +INSERT INTO t1 VALUES (60, 3, null), (61, null, 77); +INSERT INTO t2 VALUES (1000,6,2); +set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,in_to_exists=off'; +EXPLAIN +SELECT (f1, f2, f3) NOT IN +(SELECT COUNT(DISTINCT f2), f1, f3 FROM t1 GROUP BY f1, f3) +FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 system NULL NULL NULL NULL 1 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 Using filesort +SELECT (f1, f2, f3) NOT IN +(SELECT COUNT(DISTINCT f2), f1, f3 FROM t1 GROUP BY f1, f3) +FROM t2; +(f1, f2, f3) NOT IN +(SELECT COUNT(DISTINCT f2), f1, f3 FROM t1 GROUP BY f1, f3) +1 +drop table t1, t2; +# +# LPBUG#702301: MAX in select + always false WHERE with SQ +# +CREATE TABLE t1 (a int, b int, KEY (b)); +INSERT INTO t1 VALUES (3,1), (4,2); +CREATE TABLE t2 (a int); +INSERT INTO t2 VALUES (7), (8); +set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off'; +SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); +max_res +NULL +EXPLAIN EXTENDED +SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00 +Warnings: +Note 1003 /* select#1 */ select max(`test`.`t1`.`b`) AS `max_res` from `test`.`t1` where 0 +set @@optimizer_switch='materialization=off,in_to_exists=on,semijoin=off'; +SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); +max_res +NULL +EXPLAIN EXTENDED +SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select max(`test`.`t1`.`b`) AS `max_res` from `test`.`t1` where 0 +DROP TABLE t1,t2; +# +# LPBUG#825095: Wrong result with materialization and NOT IN with 2 expressions +# +CREATE TABLE t1 (a int,b int); +INSERT INTO t1 VALUES (4,4),(4,2); +CREATE TABLE t2 (b int, a int); +INSERT INTO t2 VALUES (4,3),(8,4); +set @@optimizer_switch='semijoin=off,in_to_exists=off,materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off'; +EXPLAIN SELECT * +FROM t1 +WHERE (a, b) NOT IN (SELECT a, b FROM t2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 +SELECT * +FROM t1 +WHERE (a, b) NOT IN (SELECT a, b FROM t2); +a b +4 4 +4 2 +EXPLAIN +SELECT a, b, (a, b) NOT IN (SELECT a, b FROM t2) as sq +FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 +SELECT a, b, (a, b) NOT IN (SELECT a, b FROM t2) as sq +FROM t1; +a b sq +4 4 1 +4 2 1 +drop table t1, t2; +# +# MDEV-15235: Assertion `length > 0' failed in create_ref_for_key +# +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (f CHAR(1)); +INSERT INTO t2 VALUES ('a'),('b'); +explain +SELECT * FROM t2 WHERE f IN ( SELECT LEFT('foo',0) FROM t1 ORDER BY 1 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 +SELECT * FROM t2 WHERE f IN ( SELECT LEFT('foo',0) FROM t1 ORDER BY 1 ); +f +DROP TABLE t1, t2; +# ++# MDEV-18255: Server crashes in Bitmap<64u>::intersect ++# ++create table t1 (v1 varchar(1)) engine=myisam ; ++create table t2 (v1 varchar(1)) engine=myisam ; ++explain ++select 1 from t1 where exists ++(select 1 from t1 where t1.v1 in (select t2.v1 from t2 having t2.v1 < 'j')) ; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE ++2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table ++3 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL no matching row in const table ++select 1 from t1 where exists ++(select 1 from t1 where t1.v1 in (select t2.v1 from t2 having t2.v1 < 'j')) ; ++1 ++drop table t1,t2; ++# +# MDEV-9489: Assertion `0' failed in Protocol::end_statement() on +# UNION ALL +# +CREATE TABLE t1 (f1 INT); +CREATE TABLE t2 (f2 INT); +INSERT INTO t1 VALUES (1),(2); +( SELECT 1 FROM t1 WHERE f1 NOT IN ( SELECT f2 FROM t2 ) LIMIT 0 ) +UNION ALL +( SELECT 1 FROM t1 WHERE f1 NOT IN ( SELECT f2 FROM t2 ) ) +; +1 +1 +1 +drop table t1, t2; diff --cc mysql-test/main/subselect_mat.test index 7055b323906,00000000000..fc43d19ae11 mode 100644,000000..100644 --- a/mysql-test/main/subselect_mat.test +++ b/mysql-test/main/subselect_mat.test @@@ -1,285 -1,0 +1,298 @@@ +# +# Hash semi-join regression tests +# (WL#1110: Subquery optimization: materialization) +# + + +# force the use of materialization +set @subselect_mat_test_optimizer_switch_value='materialization=on,in_to_exists=off,semijoin=off'; + +--source subselect_sj_mat.test +set @subselect_mat_test_optimizer_switch_value=null; + +set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off'; +set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; +# +# Test that the contents of the temp table of a materialized subquery is +# cleaned up between PS re-executions. +# + +create table t0 (a int); +insert into t0 values (0),(1),(2); +create table t1 (a int); +insert into t1 values (0),(1),(2); +explain select a, a in (select a from t1) from t0; +select a, a in (select a from t1) from t0; +prepare s from 'select a, a in (select a from t1) from t0'; +execute s; +update t1 set a=123; +execute s; +drop table t0, t1; + + +--echo # +--echo # LPBUG#609121: RQG: wrong result on aggregate + NOT IN + HAVING and +--echo # partial_match_table_scan=on +--echo # + +create table t1 (c1 int); +create table t2 (c2 int); +insert into t1 values (1); +insert into t2 values (2); + +set @@optimizer_switch='semijoin=off'; + +EXPLAIN +SELECT SUM(c1) c1_sum FROM t1 WHERE c1 IN (SELECT c2 FROM t2); +SELECT SUM(c1) c1_sum FROM t1 WHERE c1 IN (SELECT c2 FROM t2); +EXPLAIN +SELECT SUM(c1) c1_sum FROM t1 WHERE c1 IN (SELECT c2 FROM t2) HAVING c1_sum; +SELECT SUM(c1) c1_sum FROM t1 WHERE c1 IN (SELECT c2 FROM t2) HAVING c1_sum; + +drop table t1, t2; + +--echo # +--echo # BUG#52344 - Subquery materialization: +--echo # Assertion if subquery in on-clause of outer join +--echo # + +set @@optimizer_switch='semijoin=off'; + +CREATE TABLE t1 (i INTEGER); +INSERT INTO t1 VALUES (10); + +CREATE TABLE t2 (j INTEGER); +INSERT INTO t2 VALUES (5); + +CREATE TABLE t3 (k INTEGER); + +EXPLAIN +SELECT i FROM t1 LEFT JOIN t2 ON (j) IN (SELECT k FROM t3); +SELECT i FROM t1 LEFT JOIN t2 ON (j) IN (SELECT k FROM t3); + +EXPLAIN +SELECT i FROM t1 LEFT JOIN t2 ON (j) IN (SELECT max(k) FROM t3); +SELECT i FROM t1 LEFT JOIN t2 ON (j) IN (SELECT max(k) FROM t3); + +DROP TABLE t1, t2, t3; + +--echo # +--echo # LPBUG#611622/BUG#52344: Subquery materialization: Assertion +--echo # if subquery in on-clause of outer join +--echo # + +CREATE TABLE t1 (c1 int); +INSERT INTO t1 VALUES (1),(2); + +CREATE TABLE t2 (c2 int); +INSERT INTO t2 VALUES (10); + +PREPARE st1 FROM " +SELECT * +FROM t2 LEFT JOIN t2 t3 ON (8, 4) IN (SELECT c1, c1 FROM t1)"; + +EXECUTE st1; +EXECUTE st1; + +DROP TABLE t1, t2; + +--echo # +--echo # Testcase backport: BUG#46548 IN-subqueries return 0 rows with materialization=on +--echo # +CREATE TABLE t1 ( + pk int, + a varchar(1), + b varchar(4), + c varchar(4), + d varchar(4), + PRIMARY KEY (pk) +); +INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo'),(2,'f','ffff','ffff','ffff'); + +CREATE TABLE t2 LIKE t1; +INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff'); + +SET @@optimizer_switch='default,semijoin=on,materialization=on'; +EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); +SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); +SELECT pk FROM t1 WHERE (b,c,d) IN (SELECT b,c,d FROM t2 WHERE pk > 0); +DROP TABLE t1, t2; + + +-- echo # +-- echo # BUG#724228: Wrong result with materialization=on and three aggregates in maria-5.3-mwl90 +-- echo # +CREATE TABLE t1 ( f2 int(11)) ; +INSERT IGNORE INTO t1 VALUES ('7'),('9'),('7'),('4'),('2'),('6'),('8'),('5'),('6'),('188'),('2'),('1'),('1'),('0'),('9'),('4'); + +CREATE TABLE t2 ( f1 int(11), f2 int(11)) ENGINE=MyISAM; +INSERT IGNORE INTO t2 VALUES ('1','1'); + +CREATE TABLE t3 ( f1 int(11), f2 int(11), f3 int(11), PRIMARY KEY (f1)) ; +INSERT IGNORE INTO t3 VALUES ('16','6','1'),('18','3','4'),('19',NULL,'9'),('20','0','6'),('41','2','0'),('42','2','5'),('43','9','6'),('44','7','4'),('45','1','4'),('46','222','238'),('47','3','6'),('48','6','6'),('49',NULL,'1'),('50','5','1'); + +SET @_save_join_cache_level = @@join_cache_level; +SET @_save_optimizer_switch = @@optimizer_switch; + +SET join_cache_level = 1; +SET optimizer_switch='materialization=on'; + +SELECT f1 FROM t3 +WHERE + f1 NOT IN (SELECT MAX(f2) FROM t1) AND + f3 IN (SELECT MIN(f1) FROM t2) AND + f1 IN (SELECT COUNT(f2) FROM t1); + +SET @@join_cache_level = @_save_join_cache_level; +SET @@optimizer_switch = @_save_optimizer_switch; + +drop table t1, t2, t3; + +--echo # +--echo # LPBUG#719198 Ordered_key::cmp_key_with_search_key(rownum_t): Assertion `!compare_pred[i]->null_value' +--echo # failed with subquery on both sides of NOT IN and materialization +--echo # + +CREATE TABLE t1 (f1a int, f1b int) ; +INSERT IGNORE INTO t1 VALUES (1,1),(2,2); +CREATE TABLE t2 ( f2 int); +INSERT IGNORE INTO t2 VALUES (3),(4); +CREATE TABLE t3 (f3a int, f3b int); + +set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,in_to_exists=off'; + +EXPLAIN +SELECT * FROM t2 WHERE (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); +SELECT * FROM t2 WHERE (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); + +EXPLAIN +SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); +SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); + +EXPLAIN +SELECT * FROM t2 WHERE (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1); +SELECT * FROM t2 WHERE (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1); + +EXPLAIN +SELECT (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1); +SELECT (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1); + +drop table t1, t2, t3; + +--echo # +--echo # LPBUG#730604 Assertion `bit < (map)->n_bits' failed in maria-5.3 with +--echo # partial_match_rowid_merge +--echo # + +CREATE TABLE t1 (f1 int NOT NULL, f2 int, f3 int) ; +CREATE TABLE t2 (f1 int NOT NULL, f2 int, f3 int) ; + +INSERT INTO t1 VALUES (60, 3, null), (61, null, 77); +INSERT INTO t2 VALUES (1000,6,2); + +set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,in_to_exists=off'; + +EXPLAIN +SELECT (f1, f2, f3) NOT IN + (SELECT COUNT(DISTINCT f2), f1, f3 FROM t1 GROUP BY f1, f3) +FROM t2; + +SELECT (f1, f2, f3) NOT IN + (SELECT COUNT(DISTINCT f2), f1, f3 FROM t1 GROUP BY f1, f3) +FROM t2; + +drop table t1, t2; + +--echo # +--echo # LPBUG#702301: MAX in select + always false WHERE with SQ +--echo # + +CREATE TABLE t1 (a int, b int, KEY (b)); +INSERT INTO t1 VALUES (3,1), (4,2); +CREATE TABLE t2 (a int); +INSERT INTO t2 VALUES (7), (8); + +set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off'; + +SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); +EXPLAIN EXTENDED +SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); + +set @@optimizer_switch='materialization=off,in_to_exists=on,semijoin=off'; + +SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); +EXPLAIN EXTENDED +SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); + +DROP TABLE t1,t2; + +--echo # +--echo # LPBUG#825095: Wrong result with materialization and NOT IN with 2 expressions +--echo # + +CREATE TABLE t1 (a int,b int); +INSERT INTO t1 VALUES (4,4),(4,2); + +CREATE TABLE t2 (b int, a int); +INSERT INTO t2 VALUES (4,3),(8,4); + +set @@optimizer_switch='semijoin=off,in_to_exists=off,materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off'; + +EXPLAIN SELECT * +FROM t1 +WHERE (a, b) NOT IN (SELECT a, b FROM t2); + +SELECT * +FROM t1 +WHERE (a, b) NOT IN (SELECT a, b FROM t2); + +EXPLAIN +SELECT a, b, (a, b) NOT IN (SELECT a, b FROM t2) as sq +FROM t1; + +SELECT a, b, (a, b) NOT IN (SELECT a, b FROM t2) as sq +FROM t1; + +drop table t1, t2; + +--echo # +--echo # MDEV-15235: Assertion `length > 0' failed in create_ref_for_key +--echo # + +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (f CHAR(1)); +INSERT INTO t2 VALUES ('a'),('b'); +explain +SELECT * FROM t2 WHERE f IN ( SELECT LEFT('foo',0) FROM t1 ORDER BY 1 ); +SELECT * FROM t2 WHERE f IN ( SELECT LEFT('foo',0) FROM t1 ORDER BY 1 ); +DROP TABLE t1, t2; + ++--echo # ++--echo # MDEV-18255: Server crashes in Bitmap<64u>::intersect ++--echo # ++create table t1 (v1 varchar(1)) engine=myisam ; ++create table t2 (v1 varchar(1)) engine=myisam ; ++ ++explain ++select 1 from t1 where exists ++ (select 1 from t1 where t1.v1 in (select t2.v1 from t2 having t2.v1 < 'j')) ; ++select 1 from t1 where exists ++ (select 1 from t1 where t1.v1 in (select t2.v1 from t2 having t2.v1 < 'j')) ; ++drop table t1,t2; ++ +--echo # +--echo # MDEV-9489: Assertion `0' failed in Protocol::end_statement() on +--echo # UNION ALL +--echo # + +CREATE TABLE t1 (f1 INT); +CREATE TABLE t2 (f2 INT); +INSERT INTO t1 VALUES (1),(2); + +( SELECT 1 FROM t1 WHERE f1 NOT IN ( SELECT f2 FROM t2 ) LIMIT 0 ) +UNION ALL +( SELECT 1 FROM t1 WHERE f1 NOT IN ( SELECT f2 FROM t2 ) ) +; + +drop table t1, t2; diff --cc mysql-test/suite/binlog/t/binlog_base64_flag.test index f17b51166e9,575a7307665..e1187cd895c --- a/mysql-test/suite/binlog/t/binlog_base64_flag.test +++ b/mysql-test/suite/binlog/t/binlog_base64_flag.test @@@ -67,8 -67,31 +67,30 @@@ TFtYRxcBAAAAIgAAAKEBAAAQABAAAAAAAAEAAf/ # The above line should succeed and 3 should be in the table select * from t1; + # The same as above with one-fragment BINLOG to prove + # equivalency with the fragmented BINLOG @frag_0, @frag_1. + DELETE FROM t1 WHERE a=3; + # This is a binlog statement containing a Format_description_log_event + # from the same version as the Table_map and Write_rows_log_event. + BINLOG ' + ODdYRw8BAAAAZgAAAGoAAAABAAQANS4xLjIzLXJjLWRlYnVnLWxvZwAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAA4N1hHEzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC + '; + + # This is a Table_map_log_event+Write_rows_log_event corresponding to: + # INSERT INTO TABLE test.t1 VALUES (3) + SET @binlog_fragment_0=' + TFtYRxMBAAAAKQAAAH8BAAAAABAAAAAAAAAABHRlc3QAAnQxAAEDAAE= + TFtYRxcBAAAAIgAAAKEBAAAQABAAAAAAAAEAAf/+AwAAAA== + '; + SET @binlog_fragment_1=''; + BINLOG @binlog_fragment_0, @binlog_fragment_1; + # The above line should succeed and 3 should be in the table: + select * from t1; + # show "one-shot" feature of binlog_fragment variables + SELECT @binlog_fragment_0, @binlog_fragment_1 as 'NULL','NULL'; -# Test that mysqlbinlog stops with an error message when the -# --base64-output=never flag is used on a binlog with base64 events. +# New mysqlbinlog supports --base64-output=never --echo ==== Test --base64-output=never on a binlog with row events ==== # mysqlbinlog should fail diff --cc mysql-test/suite/galera_3nodes/r/galera_pc_weight.result index 240232d9c96,5fb9c1b9d66..aca9a1d2059 --- a/mysql-test/suite/galera_3nodes/r/galera_pc_weight.result +++ b/mysql-test/suite/galera_3nodes/r/galera_pc_weight.result @@@ -74,7 -79,8 +79,13 @@@ VARIABLE_VALUE = 'Synced SET GLOBAL wsrep_provider_options = 'pc.weight=1'; SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_weight'; VARIABLE_VALUE = 1 ++<<<<<<< HEAD ++connection node_1; ++||||||| merged common ancestors ++======= + 1 connection node_1; ++>>>>>>> 10.2 SET GLOBAL wsrep_provider_options = 'gmcast.isolate=0'; connection node_2; connection node_3; diff --cc mysql-test/suite/galera_3nodes/r/galera_safe_to_bootstrap.result index 45b4d63fb4f,1676ef9b07b..56382eb6c98 --- a/mysql-test/suite/galera_3nodes/r/galera_safe_to_bootstrap.result +++ b/mysql-test/suite/galera_3nodes/r/galera_safe_to_bootstrap.result @@@ -11,8 -7,9 +11,15 @@@ connection node_1 include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0'] include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0'] include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0'] ++<<<<<<< HEAD +connection node_3; +connection node_1; ++||||||| merged common ancestors ++======= + connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3; + connection node_3; + connection node_1; ++>>>>>>> 10.2 include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0'] include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 0'] include/assert_grep.inc [grastate.dat does not have 'safe_to_bootstrap: 1'] @@@ -28,22 -25,12 +35,35 @@@ Killing server .. safe_to_bootstrap: 1 safe_to_bootstrap: 0 safe_to_bootstrap: 0 ++<<<<<<< HEAD connection node_1; connection node_2; connection node_3; connection node_2; +CALL mtr.add_suppression("WSREP: no nodes coming from prim view, prim not possible"); +CALL mtr.add_suppression("WSREP: It may not be safe to bootstrap the cluster from this node"); +CALL mtr.add_suppression("WSREP: wsrep::connect(.*) failed: 7"); +CALL mtr.add_suppression("Aborting"); +CALL mtr.add_suppression("WSREP: moving position backwards: [0-9]+ -> 0"); ++||||||| merged common ancestors ++======= ++connection node_1; ++connection node_2; ++connection node_3; ++connection node_2; ++>>>>>>> 10.2 CALL mtr.add_suppression("Failed to prepare for incremental state transfer"); ++<<<<<<< HEAD +connection node_3; +CALL mtr.add_suppression("WSREP: no nodes coming from prim view, prim not possible"); +CALL mtr.add_suppression("WSREP: It may not be safe to bootstrap the cluster from this node"); +CALL mtr.add_suppression("WSREP: wsrep::connect(.*) failed: 7"); +CALL mtr.add_suppression("Aborting"); +CALL mtr.add_suppression("WSREP: moving position backwards: [0-9]+ -> 0"); ++||||||| merged common ancestors ++======= + connection node_3; ++>>>>>>> 10.2 CALL mtr.add_suppression("Failed to prepare for incremental state transfer"); SHOW CREATE TABLE t1; Table Create Table diff --cc mysql-test/suite/galera_3nodes/suite.pm index 0c098bfc9f9,a7c1bf79c06..4949954e7bd --- a/mysql-test/suite/galera_3nodes/suite.pm +++ b/mysql-test/suite/galera_3nodes/suite.pm @@@ -49,10 -49,13 +49,25 @@@ push @::global_suppressions qr|WSREP: discarding established \(time wait\) .*|, qr(WSREP: There are no nodes in the same segment that will ever be able to become donors, yet there is a suitable donor outside. Will use that one.), qr(WSREP: evs::proto.*), ++<<<<<<< HEAD + qr|WSREP: Ignoring possible split-brain \(allowed by configuration\) from view:.*|, ++||||||| merged common ancestors ++ qr|WSREP: Ignoring possible split-brain (allowed by configuration) from view:.*|, ++======= + qr|WSREP: Ignoring possible split-brain \(allowed by configuration\) from view:.*|, + qr(WSREP: no nodes coming from prim view, prim not possible), ++>>>>>>> 10.2 qr(WSREP: Member .* requested state transfer from .* but it is impossible to select State Transfer donor: Resource temporarily unavailable), ++<<<<<<< HEAD ++ qr(WSREP: .* sending install message failed: Transport endpoint is not connected), ++ qr(WSREP: .* sending install message failed: Resource temporarily unavailable), ++||||||| merged common ancestors ++======= + qr(WSREP: user message in state LEAVING), qr(WSREP: .* sending install message failed: Transport endpoint is not connected), qr(WSREP: .* sending install message failed: Resource temporarily unavailable), + qr(WSREP: Sending JOIN failed: -107 \(Transport endpoint is not connected\). Will retry in new primary component.), ++>>>>>>> 10.2 qr(WSREP: Could not find peer:), qr|WSREP: gcs_caused\(\) returned .*|, qr|WSREP: Protocol violation. JOIN message sender .* is not in state transfer \(SYNCED\). Message ignored.|, @@@ -65,27 -68,27 +80,52 @@@ $ENV{PATH}="$epath:$ENV{PATH}"; $ENV{PATH}="$spath:$ENV{PATH}" unless $epath eq $spath; ++<<<<<<< HEAD +$ENV{PATH}="$cpath:$ENV{PATH}" unless $cpath eq $spath; +$ENV{PATH}="$bpath:$ENV{PATH}" unless $bpath eq $spath; + +if (which(socat)) { + $ENV{MTR_GALERA_TFMT}='socat'; +} elsif (which(nc)) { + $ENV{MTR_GALERA_TFMT}='nc'; +} + +sub skip_combinations { + my %skip = (); + $skip{'include/have_filekeymanagement.inc'} = 'needs file_key_management plugin' + unless $ENV{FILE_KEY_MANAGEMENT_SO}; + $skip{'include/have_mariabackup.inc'} = 'Need mariabackup' + unless which(mariabackup); + $skip{'include/have_mariabackup.inc'} = 'Need ss' + unless which(ss); + $skip{'include/have_mariabackup.inc'} = 'Need socat or nc' + unless $ENV{MTR_GALERA_TFMT}; + %skip; +} ++||||||| merged common ancestors ++======= + $ENV{PATH}="$cpath:$ENV{PATH}" unless $cpath eq $spath; + $ENV{PATH}="$bpath:$ENV{PATH}" unless $bpath eq $spath; + + if (which(socat)) { + $ENV{MTR_GALERA_TFMT}='socat'; + } elsif (which(nc)) { + $ENV{MTR_GALERA_TFMT}='nc'; + } + + sub skip_combinations { + my %skip = (); + $skip{'include/have_filekeymanagement.inc'} = 'needs file_key_management plugin' + unless $ENV{FILE_KEY_MANAGEMENT_SO}; + $skip{'suite/galera/include/have_mariabackup.inc'} = 'Need mariabackup' + unless which(mariabackup); + $skip{'suite/galera/include/have_mariabackup.inc'} = 'Need ss' + unless which(ss); + $skip{'suite/galera/include/have_mariabackup.inc'} = 'Need socat or nc' + unless $ENV{MTR_GALERA_TFMT}; + %skip; + } ++>>>>>>> 10.2 bless { }; diff --cc mysql-test/suite/innodb/r/innodb-fk-warnings.result index fc3f45f3d0a,01a46c8c7bd..9fd57cc6dc6 --- a/mysql-test/suite/innodb/r/innodb-fk-warnings.result +++ b/mysql-test/suite/innodb/r/innodb-fk-warnings.result @@@ -36,10 -36,10 +36,10 @@@ ERROR HY000: Can't create table `test`. show warnings; Level Code Message Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") -Warning 1215 Cannot add foreign key constraint +Warning 1215 Cannot add foreign key constraint for `t2` create table t2(a int, b int, constraint a foreign key a (a) references t1(a)) engine=innodb; alter table t2 add constraint b foreign key (b) references t2(b); - ERROR HY000: Can't create table `test`.`#sql-temporary` (errno: 150 "Foreign key constraint is incorrectly formed") + ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") show warnings; Level Code Message Warning 150 Alter table '`test`.`t2`' with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns near ' foreign key (b) references t2(b)'. @@@ -76,9 -76,9 +76,9 @@@ show warnings Level Code Message Warning 150 Create table `mysqld.1`.`t2` with foreign key constraint failed. Referenced table `mysqld.1`.`t1` not found in the data dictionary near 'foreign key(a) references t1(a)) engine=innodb'. Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") -Warning 1215 Cannot add foreign key constraint +Warning 1215 Cannot add foreign key constraint for `t2` alter table t1 add foreign key(b) references t1(a); - ERROR HY000: Can't create table `test`.`#sql-temporary` (errno: 150 "Foreign key constraint is incorrectly formed") + ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed") show warnings; Level Code Message Warning 150 Alter table `mysqld.1`.`t1` with foreign key constraint failed. Referenced table `mysqld.1`.`t1` not found in the data dictionary near 'foreign key(b) references t1(a)'. diff --cc mysql-test/suite/perfschema/r/dml_setup_instruments.result index ff184806e2e,10d576a0583..a5184782af8 --- a/mysql-test/suite/perfschema/r/dml_setup_instruments.result +++ b/mysql-test/suite/perfschema/r/dml_setup_instruments.result @@@ -14,9 -13,12 +14,11 @@@ wait/synch/mutex/sql/HA_DATA_PARTITION: wait/synch/mutex/sql/LOCK_active_mi YES YES wait/synch/mutex/sql/LOCK_after_binlog_sync YES YES wait/synch/mutex/sql/LOCK_audit_mask YES YES -wait/synch/mutex/sql/LOCK_binlog_state YES YES select * from performance_schema.setup_instruments where name like 'Wait/Synch/Rwlock/sql/%' - and name not in ('wait/synch/rwlock/sql/CRYPTO_dynlock_value::lock') + and name not in ( + 'wait/synch/rwlock/sql/CRYPTO_dynlock_value::lock', + 'wait/synch/rwlock/sql/LOCK_named_pipe_full_access_group') order by name limit 10; NAME ENABLED TIMED wait/synch/rwlock/sql/LOCK_dboptions YES YES diff --cc scripts/mysql_install_db.sh index fb3b32251ed,681b73dfc9f..8052eb994f5 --- a/scripts/mysql_install_db.sh +++ b/scripts/mysql_install_db.sh @@@ -37,10 -36,13 +37,13 @@@ force= in_rpm=0 ip_only=0 cross_bootstrap=0 -install_params="" auth_root_authentication_method=normal auth_root_socket_user='root' +skip_test_db=0 + dirname0=`dirname $0 2>/dev/null` + dirname0=`dirname $dirname0 2>/dev/null` + usage() { cat <<EOF diff --cc sql/item_func.cc index 72cfd284606,f755deea23b..3c299ebabbe --- a/sql/item_func.cc +++ b/sql/item_func.cc @@@ -4654,8 -4818,8 +4654,8 @@@ bool Item_func_set_user_var::register_f true failure */ - static bool + bool -update_hash(user_var_entry *entry, bool set_null, void *ptr, uint length, +update_hash(user_var_entry *entry, bool set_null, void *ptr, size_t length, Item_result type, CHARSET_INFO *cs, bool unsigned_arg) { diff --cc sql/item_func.h index fd789ffdc51,fea8c28f74f..194841c8337 --- a/sql/item_func.h +++ b/sql/item_func.h @@@ -3166,4 -2531,8 +3166,8 @@@ bool eval_const_cond(COND *cond) extern bool volatile mqh_used; -bool update_hash(user_var_entry *entry, bool set_null, void *ptr, uint length, ++bool update_hash(user_var_entry *entry, bool set_null, void *ptr, size_t length, + Item_result type, CHARSET_INFO *cs, + bool unsigned_arg); + #endif /* ITEM_FUNC_INCLUDED */ diff --cc sql/log_event.cc index ffcb1f9dfa2,947bcbf3509..db291d1f910 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@@ -3693,9 -3413,23 +3693,23 @@@ void free_table_map_log_event(Table_map delete event; } + /** + Encode the event, optionally per 'do_print_encoded' arg store the + result into the argument cache; optionally per event_info's + 'verbose' print into the cache a verbose representation of the event. + Note, no extra wrapping is done to the being io-cached data, like + to producing a BINLOG query. It's left for a routine that extracts from + the cache. + + @param file pointer to IO_CACHE + @param print_event_info pointer to print_event_info specializing + what out of and how to print the event + @param do_print_encoded whether to store base64-encoded event + into @file. + */ -void Log_event::print_base64(IO_CACHE* file, +bool Log_event::print_base64(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info, - bool more) + bool do_print_encoded) { uchar *ptr= (uchar *)temp_buf; uint32 size= uint4korr(ptr + EVENT_LEN_OFFSET); @@@ -3746,41 -3488,19 +3760,29 @@@ delete ev; } - if (print_event_info->base64_output_mode != BASE64_OUTPUT_NEVER && - print_event_info->base64_output_mode != BASE64_OUTPUT_DECODE_ROWS && - ! print_event_info->short_form) - if (my_base64_encode(ptr, (size_t) size, tmp_str)) ++ if (do_print_encoded) { - DBUG_ASSERT(0); - } + size_t const tmp_str_sz= my_base64_needed_encoded_length((int) size); - bool error= 0; + char *tmp_str; + if (!(tmp_str= (char *) my_malloc(tmp_str_sz, MYF(MY_WME)))) + goto err; + + if (my_base64_encode(ptr, (size_t) size, tmp_str)) + { + DBUG_ASSERT(0); + } - if (my_b_tell(file) == 0) - if (unlikely(my_b_write_string(file, "\nBINLOG '\n"))) - error= 1; - if (likely(!error) && unlikely(my_b_printf(file, "%s\n", tmp_str))) - error= 1; - if (!more && likely(!error)) - if (unlikely(my_b_printf(file, "'%s\n", print_event_info->delimiter))) - error= 1; - if (do_print_encoded) + my_b_printf(file, "%s\n", tmp_str); + my_free(tmp_str); - if (unlikely(error)) - goto err; + } #ifdef WHEN_FLASHBACK_REVIEW_READY - if (print_event_info->verbose || need_flashback_review) + if (print_event_info->verbose || print_event_info->print_row_count || + need_flashback_review) #else // Flashback need the table_map to parse the event - if (print_event_info->verbose || is_flashback) + if (print_event_info->verbose || print_event_info->print_row_count || + is_flashback) #endif { Rows_log_event *ev= NULL; @@@ -3885,19 -3588,25 +3887,32 @@@ } #else if (print_event_info->verbose) - error= ev->print_verbose(file, print_event_info); + { + /* + Verbose event printout can't start before encoded data + got enquoted. This is done at this point though multi-row + statement remain vulnerable. + TODO: fix MDEV-10362 to remove this workaround. + */ + if (print_event_info->base64_output_mode != + BASE64_OUTPUT_DECODE_ROWS) + my_b_printf(file, "'%s\n", print_event_info->delimiter); + ev->print_verbose(file, print_event_info); + } + else ++ { + ev->count_row_events(print_event_info); ++ } #endif delete ev; + if (unlikely(error)) + goto err; } } + DBUG_RETURN(0); - my_free(tmp_str); - DBUG_VOID_RETURN; +err: + DBUG_RETURN(1); } @@@ -5998,16 -5686,20 +6029,23 @@@ bool Start_log_event_v3::print(FILE* fi print_event_info->base64_output_mode != BASE64_OUTPUT_NEVER && !print_event_info->short_form) { - if (print_event_info->base64_output_mode != BASE64_OUTPUT_DECODE_ROWS) - if (my_b_printf(&cache, "BINLOG '\n")) - goto err; - if (print_base64(&cache, print_event_info, FALSE)) + /* BINLOG is matched with the delimiter below on the same level */ + bool do_print_encoded= + print_event_info->base64_output_mode != BASE64_OUTPUT_DECODE_ROWS; + if (do_print_encoded) + my_b_printf(&cache, "BINLOG '\n"); + - print_base64(&cache, print_event_info, do_print_encoded); ++ if (print_base64(&cache, print_event_info, do_print_encoded)) + goto err; + + if (do_print_encoded) + my_b_printf(&cache, "'%s\n", print_event_info->delimiter); + print_event_info->printed_fd_event= TRUE; } - DBUG_VOID_RETURN; + DBUG_RETURN(cache.flush_data()); +err: + DBUG_RETURN(1); } #endif /* MYSQL_CLIENT */ @@@ -11875,7 -11404,154 +11907,219 @@@ void Rows_log_event::pack_info(Protoco #endif #ifdef MYSQL_CLIENT -class my_String : public String ++ ++const char str_binlog[]= "\nBINLOG '\n"; ++const char fmt_delim[]= "'%s\n"; ++const char fmt_n_delim[]= "\n'%s"; ++const char fmt_frag[]= "\nSET @binlog_fragment_%d ='\n"; ++const char fmt_binlog2[]= "BINLOG @binlog_fragment_0, @binlog_fragment_1%s\n"; ++ ++/** ++ Print an event "body" cache to @c file possibly in two fragments. ++ Each fragement is optionally per @c do_wrap to produce an SQL statement. ++ ++ @param file a file to print to ++ @param body the "body" IO_CACHE of event ++ @param do_wrap whether to wrap base64-encoded strings with ++ SQL cover. ++ @param delimiter delimiter string ++ ++ @param is_verbose MDEV-10362 workraround parameter to pass ++ info on presence of verbose printout in cache encoded data ++ ++ The function signals on any error through setting @c body->error to -1. ++*/ ++bool copy_cache_to_file_wrapped(IO_CACHE *body, ++ FILE *file, ++ bool do_wrap, ++ const char *delimiter, ++ bool is_verbose) + { -public: - my_String() : String(), error(false) {}; - bool error; ++ const my_off_t cache_size= my_b_tell(body); + - bool append(const LEX_STRING *ls) ++ if (reinit_io_cache(body, READ_CACHE, 0L, FALSE, FALSE)) ++ goto err; ++ ++ if (!do_wrap) ++ { ++ my_b_copy_to_file(body, file, SIZE_T_MAX); ++ } ++ else if (4 + sizeof(str_binlog) + cache_size + sizeof(fmt_delim) > ++ opt_binlog_rows_event_max_encoded_size) + { - return error= error || String::append(ls); ++ /* ++ 2 fragments can always represent near 1GB row-based ++ base64-encoded event as two strings each of size less than ++ max(max_allowed_packet). Greater number of fragments does not ++ save from potential need to tweak (increase) @@max_allowed_packet ++ before to process the fragments. So 2 is safe and enough. ++ ++ Split the big query when its packet size's estimation exceeds a ++ limit. The estimate includes the maximum packet header ++ contribution of non-compressed packet. ++ */ ++ my_fprintf(file, fmt_frag, 0); ++ if (my_b_copy_to_file(body, file, cache_size/2 + 1)) ++ goto err; ++ my_fprintf(file, fmt_n_delim, delimiter); ++ ++ my_fprintf(file, fmt_frag, 1); ++ if (my_b_copy_to_file(body, file, SIZE_T_MAX)) ++ goto err; ++ if (!is_verbose) ++ my_fprintf(file, fmt_delim, delimiter); ++ ++ my_fprintf(file, fmt_binlog2, delimiter); + } - bool append(IO_CACHE* file, uint32 arg_length) ++ else + { - return error= error || String::append(file, arg_length); ++ my_fprintf(file, str_binlog); ++ if (my_b_copy_to_file(body, file, SIZE_T_MAX)) ++ goto err; ++ if (!is_verbose) ++ my_fprintf(file, fmt_delim, delimiter); + } -}; ++ reinit_io_cache(body, WRITE_CACHE, 0, FALSE, TRUE); ++ ++ return false; ++ ++err: ++ body->error = -1; ++ return true; ++} ++ + + /** + Print an event "body" cache to @c file possibly in two fragments. + Each fragement is optionally per @c do_wrap to produce an SQL statement. + + @param file a file to print to + @param body the "body" IO_CACHE of event + @param do_wrap whether to wrap base64-encoded strings with + SQL cover. + @param delimiter delimiter string + + The function signals on any error through setting @c body->error to -1. + */ -void copy_cache_to_string_wrapped(IO_CACHE *cache, ++bool copy_cache_to_string_wrapped(IO_CACHE *cache, + LEX_STRING *to, + bool do_wrap, + const char *delimiter, + bool is_verbose) + { - const char str_binlog[]= "\nBINLOG '\n"; - const char fmt_delim[]= "'%s\n"; - const char fmt_n_delim[]= "\n'%s"; - const char fmt_frag[]= "\nSET @binlog_fragment_%d ='\n"; + const my_off_t cache_size= my_b_tell(cache); - my_String ret; - /* - substring to hold parts of encoded possibly defragramented event - whose size is roughly estimated from the top. - */ - char tmp[sizeof(str_binlog) + 2*(sizeof(fmt_frag) + 2 /* %d */) + - sizeof(fmt_delim) + sizeof(fmt_n_delim) + - PRINT_EVENT_INFO::max_delimiter_size]; - LEX_STRING str_tmp= { tmp, 0 }; ++ // contribution to total size estimate of formating ++ const size_t fmt_size= ++ sizeof(str_binlog) + 2*(sizeof(fmt_frag) + 2 /* %d */) + ++ sizeof(fmt_delim) + sizeof(fmt_n_delim) + ++ sizeof(fmt_binlog2) + ++ 3*PRINT_EVENT_INFO::max_delimiter_size; + + if (reinit_io_cache(cache, READ_CACHE, 0L, FALSE, FALSE)) ++ goto err; ++ ++ if (!(to->str= (char*) my_malloc(cache->end_of_file + fmt_size, MYF(0)))) + { - cache->error= -1; - goto end; ++ perror("Out of memory: can't allocate memory in " ++ "copy_cache_to_string_wrapped()."); ++ goto err; + } + + if (!do_wrap) + { - if (ret.append(cache, (uint32) cache->end_of_file)) - { - cache->error= -1; - goto end; - } ++ if (my_b_read(cache, (uchar*) to->str, (to->length= cache->end_of_file))) ++ goto err; + } + else if (4 + sizeof(str_binlog) + cache_size + sizeof(fmt_delim) > + opt_binlog_rows_event_max_encoded_size) + { + /* + 2 fragments can always represent near 1GB row-based + base64-encoded event as two strings each of size less than + max(max_allowed_packet). Greater number of fragments does not + save from potential need to tweak (increase) @@max_allowed_packet + before to process the fragments. So 2 is safe and enough. + + Split the big query when its packet size's estimation exceeds a + limit. The estimate includes the maximum packet header + contribution of non-compressed packet. + */ - str_tmp.length= sprintf(str_tmp.str, fmt_frag, 0); - ret.append(&str_tmp); - ret.append(cache, (uint32) cache_size/2 + 1); - str_tmp.length= sprintf(str_tmp.str, fmt_n_delim, delimiter); - ret.append(&str_tmp); - - str_tmp.length= sprintf(str_tmp.str, fmt_frag, 1); - ret.append(&str_tmp); - ret.append(cache, uint32(cache->end_of_file - (cache_size/2 + 1))); ++ char *str= to->str; ++ size_t add_to_len; ++ ++ str += (to->length= sprintf(str, fmt_frag, 0)); ++ if (my_b_read(cache, (uchar*) str, (uint32) (cache_size/2 + 1))) ++ goto err; ++ str += (add_to_len = (uint32) (cache_size/2 + 1)); ++ to->length += add_to_len; ++ str += (add_to_len= sprintf(str, fmt_n_delim, delimiter)); ++ to->length += add_to_len; ++ ++ str += (add_to_len= sprintf(str, fmt_frag, 1)); ++ to->length += add_to_len; ++ if (my_b_read(cache, (uchar*) str, uint32(cache->end_of_file - (cache_size/2 + 1)))) ++ goto err; ++ str += (add_to_len= uint32(cache->end_of_file - (cache_size/2 + 1))); ++ to->length += add_to_len; + if (!is_verbose) + { - str_tmp.length= sprintf(str_tmp.str, fmt_delim, delimiter); - ret.append(&str_tmp); ++ str += (add_to_len= sprintf(str , fmt_delim, delimiter)); ++ to->length += add_to_len; + } - str_tmp.length= sprintf(str_tmp.str, "BINLOG @binlog_fragment_0, @binlog_fragment_1%s\n", - delimiter); - ret.append(&str_tmp); ++ to->length += sprintf(str, fmt_binlog2, delimiter); + } + else + { - str_tmp.length= sprintf(str_tmp.str, str_binlog); - ret.append(&str_tmp); - ret.append(cache, (uint32) cache->end_of_file); ++ char *str= to->str; ++ ++ str += (to->length= sprintf(str, str_binlog)); ++ if (my_b_read(cache, (uchar*) str, cache->end_of_file)) ++ goto err; ++ str += cache->end_of_file; ++ to->length += cache->end_of_file; + if (!is_verbose) - { - str_tmp.length= sprintf(str_tmp.str, fmt_delim, delimiter); - ret.append(&str_tmp); - } ++ to->length += sprintf(str , fmt_delim, delimiter); + } + - to->length= ret.length(); - to->str= ret.release(); - + reinit_io_cache(cache, WRITE_CACHE, 0, FALSE, TRUE); + - if (ret.error) - cache->error= -1; -end: - return; ++ return false; ++ ++err: ++ cache->error= -1; ++ return true; + } + + /** + The function invokes base64 encoder to run on the current + event string and store the result into two caches. + When the event ends the current statement the caches are is copied into + the argument file. + Copying is also concerned how to wrap the event, specifically to produce + a valid SQL syntax. + When the encoded data size is within max(MAX_ALLOWED_PACKET) + a regular BINLOG query is composed. Otherwise it is build as fragmented + + SET @binlog_fragment_0='...'; + SET @binlog_fragment_1='...'; + BINLOG @binlog_fragment_0, @binlog_fragment_1; + + where fragments are represented by a pair of indexed user + "one shot" variables. + + @note + If any changes made don't forget to duplicate them to + Old_rows_log_event as long as it's supported. + + @param file pointer to IO_CACHE + @param print_event_info pointer to print_event_info specializing + what out of and how to print the event + @param name the name of a table that the event operates on + + The function signals on any error of cache access through setting + that cache's @c error to -1. + */ -void Rows_log_event::print_helper(FILE *file, +bool Rows_log_event::print_helper(FILE *file, PRINT_EVENT_INFO *print_event_info, char const *const name) { @@@ -11884,51 -11560,45 +12128,63 @@@ #ifdef WHEN_FLASHBACK_REVIEW_READY IO_CACHE *const sql= &print_event_info->review_sql_cache; #endif + bool do_print_encoded= ++ print_event_info->base64_output_mode != BASE64_OUTPUT_NEVER && + print_event_info->base64_output_mode != BASE64_OUTPUT_DECODE_ROWS && + !print_event_info->short_form; + bool const last_stmt_event= get_flags(STMT_END_F); if (!print_event_info->short_form) { - - bool const last_stmt_event= get_flags(STMT_END_F); + char llbuff[22]; + print_header(head, print_event_info, !last_stmt_event); - if (my_b_printf(head, "\t%s: table id %lu%s\n", - name, m_table_id, - my_b_printf(head, "\t%s: table id %s%s\n", - name, ullstr(m_table_id, llbuff), - last_stmt_event ? " flags: STMT_END_F" : ""); - print_base64(body, print_event_info, do_print_encoded); ++ if (my_b_printf(head, "\t%s: table id %s%s\n", ++ name, ullstr(m_table_id, llbuff), + last_stmt_event ? " flags: STMT_END_F" : "")) + goto err; } + if (!print_event_info->short_form || print_event_info->print_row_count) - if (print_base64(body, print_event_info, !last_stmt_event)) ++ if (print_base64(body, print_event_info, do_print_encoded)) + goto err; - if (get_flags(STMT_END_F)) + if (last_stmt_event) { - LEX_STRING tmp_str; -#ifdef WHEN_FLASHBACK_REVIEW_READY - copy_event_cache_to_string_and_reinit(sql, &tmp_str); - output_buf.append(&tmp_str); - my_free(tmp_str.str); -#endif - if (copy_event_cache_to_string_and_reinit(head, &tmp_str)) + if (!is_flashback) { - head->error= -1; - return; + if (copy_event_cache_to_file_and_reinit(head, file) || - copy_event_cache_to_file_and_reinit(body, file)) ++ copy_cache_to_file_wrapped(body, file, do_print_encoded, ++ print_event_info->delimiter, ++ print_event_info->verbose)) + goto err; } - output_buf.append(&tmp_str); + else + { - LEX_STRING tmp_str; - if (copy_event_cache_to_string_and_reinit(head, &tmp_str)) - return 1; - output_buf.append(tmp_str.str, tmp_str.length); // Not \0 terminated - my_free(tmp_str.str); - if (copy_event_cache_to_string_and_reinit(body, &tmp_str)) - return 1; - output_buf.append(tmp_str.str, tmp_str.length); - my_free(tmp_str.str); ++ LEX_STRING tmp_str; ++ ++ if (copy_event_cache_to_string_and_reinit(head, &tmp_str)) ++ return 1; ++ output_buf.append(tmp_str.str, tmp_str.length); // Not \0 terminated); + my_free(tmp_str.str); + - copy_cache_to_string_wrapped(body, &tmp_str, do_print_encoded, - print_event_info->delimiter, - print_event_info->verbose); - output_buf.append(&tmp_str); ++ if (copy_cache_to_string_wrapped(body, &tmp_str, do_print_encoded, ++ print_event_info->delimiter, ++ print_event_info->verbose)) ++ return 1; ++ output_buf.append(tmp_str.str, tmp_str.length); ++ my_free(tmp_str.str); +#ifdef WHEN_FLASHBACK_REVIEW_READY - if (copy_event_cache_to_string_and_reinit(sql, &tmp_str)) - return 1; - output_buf.append(tmp_str.str, tmp_str.length); - my_free(tmp_str.str); ++ if (copy_event_cache_to_string_and_reinit(sql, &tmp_str)) ++ return 1; ++ output_buf.append(tmp_str.str, tmp_str.length); + my_free(tmp_str.str); +#endif + } } + + return 0; +err: + return 1; } #endif @@@ -12624,18 -12277,17 +12880,18 @@@ int Table_map_log_event::do_apply_event /* rewrite rules changed the database */ if (((ptr= (char*) filter->get_rewrite_db(db_mem, &dummy_len)) != db_mem)) - strmov(db_mem, ptr); + db_mem_length= strmov(db_mem, ptr) - db_mem; - table_list->init_one_table(db_mem, strlen(db_mem), - tname_mem, strlen(tname_mem), - tname_mem, TL_WRITE); + LEX_CSTRING tmp_db_name= {db_mem, db_mem_length }; + LEX_CSTRING tmp_tbl_name= {tname_mem, tname_mem_length }; + table_list->init_one_table(&tmp_db_name, &tmp_tbl_name, 0, TL_WRITE); table_list->table_id= DBUG_EVALUATE_IF("inject_tblmap_same_id_maps_diff_table", 0, m_table_id); table_list->updating= 1; - table_list->required_type= FRMTYPE_TABLE; + table_list->required_type= TABLE_TYPE_NORMAL; - DBUG_PRINT("debug", ("table: %s is mapped to %lu", - DBUG_PRINT("debug", ("table: %s is mapped to %llu", table_list->table_name, ++ DBUG_PRINT("debug", ("table: %s is mapped to %llu", + table_list->table_name.str, table_list->table_id)); table_list->master_had_triggers= ((m_flags & TM_BIT_HAS_TRIGGERS_F) ? 1 : 0); DBUG_PRINT("debug", ("table->master_had_triggers=%d", @@@ -12809,25 -12461,19 +13065,27 @@@ bool Table_map_log_event::print(FILE *f { if (!print_event_info->short_form) { + char llbuff[22]; + print_header(&print_event_info->head_cache, print_event_info, TRUE); - my_b_printf(&print_event_info->head_cache, - "\tTable_map: %`s.%`s mapped to number %s%s\n", - m_dbnam, m_tblnam, ullstr(m_table_id, llbuff), - ((m_flags & TM_BIT_HAS_TRIGGERS_F) ? - " (has triggers)" : "")); - print_base64(&print_event_info->body_cache, print_event_info, - print_event_info->base64_output_mode != - BASE64_OUTPUT_DECODE_ROWS); - copy_event_cache_to_file_and_reinit(&print_event_info->head_cache, file); + if (my_b_printf(&print_event_info->head_cache, - "\tTable_map: %`s.%`s mapped to number %lu%s\n", - m_dbnam, m_tblnam, m_table_id, ++ "\tTable_map: %`s.%`s mapped to number %s%s\n", ++ m_dbnam, m_tblnam, ullstr(m_table_id, llbuff), + ((m_flags & TM_BIT_HAS_TRIGGERS_F) ? + " (has triggers)" : ""))) + goto err; } + if (!print_event_info->short_form || print_event_info->print_row_count) + { + if (print_base64(&print_event_info->body_cache, print_event_info, TRUE) || + copy_event_cache_to_file_and_reinit(&print_event_info->head_cache, + file)) + goto err; + } + + return 0; +err: + return 1; } #endif @@@ -14714,38 -14253,7 +14972,38 @@@ st_print_event_info::st_print_event_inf open_cached_file(&review_sql_cache, NULL, NULL, 0, flags); #endif } -#endif + + +bool copy_event_cache_to_string_and_reinit(IO_CACHE *cache, LEX_STRING *to) +{ + reinit_io_cache(cache, READ_CACHE, 0L, FALSE, FALSE); + if (cache->end_of_file > SIZE_T_MAX || + !(to->str= (char*) my_malloc((to->length= (size_t)cache->end_of_file), MYF(0)))) + { + perror("Out of memory: can't allocate memory in copy_event_cache_to_string_and_reinit()."); + goto err; + } + if (my_b_read(cache, (uchar*) to->str, to->length)) + { + my_free(to->str); + perror("Can't read data from IO_CACHE"); + return true; + } + reinit_io_cache(cache, WRITE_CACHE, 0, FALSE, TRUE); + return false; + +err: + to->str= 0; + to->length= 0; + return true; +} +#endif /* MYSQL_CLIENT */ + +bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache, FILE *file) +{ - return (my_b_copy_to_file(cache, file) || ++ return (my_b_copy_all_to_file(cache, file) || + reinit_io_cache(cache, WRITE_CACHE, 0, FALSE, TRUE)); +} #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint event_len, diff --cc sql/log_event.h index 84025554ee9,4ecb3d49e63..9f598012e8a --- a/sql/log_event.h +++ b/sql/log_event.h @@@ -864,10 -836,33 +864,11 @@@ typedef struct st_print_event_inf bool domain_id_printed; bool allow_parallel; bool allow_parallel_printed; + bool found_row_event; + bool print_row_count; + static const uint max_delimiter_size= 16; - /* - Track when @@skip_replication changes so we need to output a SET - statement for it. - */ - int skip_replication; - - st_print_event_info(); - - ~st_print_event_info() { - close_cached_file(&head_cache); - close_cached_file(&body_cache); -#ifdef WHEN_FLASHBACK_REVIEW_READY - close_cached_file(&review_sql_cache); -#endif - } - bool init_ok() /* tells if construction was successful */ - { return my_b_inited(&head_cache) && my_b_inited(&body_cache) -#ifdef WHEN_FLASHBACK_REVIEW_READY - && my_b_inited(&review_sql_cache) -#endif - ; } - - /* Settings on how to print the events */ bool short_form; - enum_base64_output_mode base64_output_mode; /* This is set whenever a Format_description_event is printed. Later, when an event is printed in base64, this flag is tested: if @@@ -1259,13 -1230,13 +1260,13 @@@ public Log_event() : temp_buf(0), when(0), flags(0) {} ha_checksum crc; /* print*() functions are used by mysqlbinlog */ - virtual void print(FILE* file, PRINT_EVENT_INFO* print_event_info) = 0; - void print_timestamp(IO_CACHE* file, time_t *ts = 0); - void print_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info, + virtual bool print(FILE* file, PRINT_EVENT_INFO* print_event_info) = 0; + bool print_timestamp(IO_CACHE* file, time_t *ts = 0); + bool print_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info, bool is_more); - void print_base64(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info, + bool print_base64(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info, - bool is_more); + bool do_print_encoded); -#endif +#endif /* MYSQL_SERVER */ /* The following code used for Flashback */ #ifdef MYSQL_CLIENT @@@ -5140,6 -5091,46 +5141,19 @@@ public virtual int get_data_size() { return IGNORABLE_HEADER_LEN; } }; + #ifdef MYSQL_CLIENT -void copy_cache_to_string_wrapped(IO_CACHE *body, ++bool copy_cache_to_string_wrapped(IO_CACHE *body, + LEX_STRING *to, + bool do_wrap, + const char *delimiter, + bool is_verbose); ++bool copy_cache_to_file_wrapped(IO_CACHE *body, ++ FILE *file, ++ bool do_wrap, ++ const char *delimiter, ++ bool is_verbose); + #endif + -static inline bool copy_event_cache_to_string_and_reinit(IO_CACHE *cache, LEX_STRING *to) -{ - String tmp; - - reinit_io_cache(cache, READ_CACHE, 0L, FALSE, FALSE); - if (tmp.append(cache, (uint32)cache->end_of_file)) - goto err; - reinit_io_cache(cache, WRITE_CACHE, 0, FALSE, TRUE); - - /* - Can't change the order, because the String::release() will clear the - length. - */ - to->length= tmp.length(); - to->str= tmp.release(); - - return false; - -err: - perror("Out of memory: can't allocate memory in copy_event_cache_to_string_and_reinit()."); - return true; -} - -static inline bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache, - FILE *file) -{ - return - my_b_copy_all_to_file(cache, file) || - reinit_io_cache(cache, WRITE_CACHE, 0, FALSE, TRUE); -} - - #ifdef MYSQL_SERVER /***************************************************************************** diff --cc sql/log_event_old.cc index 66c4c2bef42,2b6509048ba..67a3e54f2dd --- a/sql/log_event_old.cc +++ b/sql/log_event_old.cc @@@ -1842,32 -1853,45 +1842,38 @@@ void Old_rows_log_event::pack_info(Prot #ifdef MYSQL_CLIENT + /* Method duplicates Rows_log_event's one */ -void Old_rows_log_event::print_helper(FILE *file, +bool Old_rows_log_event::print_helper(FILE *file, PRINT_EVENT_INFO *print_event_info, char const *const name) { IO_CACHE *const head= &print_event_info->head_cache; IO_CACHE *const body= &print_event_info->body_cache; + bool do_print_encoded= + print_event_info->base64_output_mode != BASE64_OUTPUT_DECODE_ROWS && + !print_event_info->short_form; + if (!print_event_info->short_form) { -- bool const last_stmt_event= get_flags(STMT_END_F); - if (print_header(head, print_event_info, !last_stmt_event) || - print_header(head, print_event_info, !last_stmt_event); - my_b_printf(head, "\t%s: table id %lu%s\n", - name, m_table_id, - last_stmt_event ? " flags: STMT_END_F" : ""); - print_base64(body, print_event_info, do_print_encoded); ++ if (print_header(head, print_event_info, !do_print_encoded) || + my_b_printf(head, "\t%s: table id %lu%s\n", + name, m_table_id, - last_stmt_event ? " flags: STMT_END_F" : "") || - print_base64(body, print_event_info, !last_stmt_event)) ++ do_print_encoded ? " flags: STMT_END_F" : "") || ++ print_base64(body, print_event_info, do_print_encoded)) + goto err; } if (get_flags(STMT_END_F)) { - LEX_STRING tmp_str; - - if (copy_event_cache_to_string_and_reinit(head, &tmp_str)) - { - head->error= -1; - return; - } - output_buf.append(&tmp_str); - my_free(tmp_str.str); - - copy_cache_to_string_wrapped(body, &tmp_str, do_print_encoded, - print_event_info->delimiter, - print_event_info->verbose); - output_buf.append(&tmp_str); - my_free(tmp_str.str); + if (copy_event_cache_to_file_and_reinit(head, file) || - copy_event_cache_to_file_and_reinit(body, file)) ++ copy_cache_to_file_wrapped(body, file, do_print_encoded, ++ print_event_info->delimiter, ++ print_event_info->verbose)) + goto err; } + return 0; +err: + return 1; } #endif diff --cc sql/rpl_tblmap.cc index 7284e4be15c,15bb8a054eb..02543a429b8 --- a/sql/rpl_tblmap.cc +++ b/sql/rpl_tblmap.cc @@@ -43,11 -43,10 +43,11 @@@ table_mapping::table_mapping( constructor is called at startup only. */ (void) my_hash_init(&m_table_ids,&my_charset_bin,TABLE_ID_HASH_SIZE, - offsetof(entry,table_id),sizeof(ulong), + offsetof(entry,table_id),sizeof(ulonglong), 0,0,0); /* We don't preallocate any block, this is consistent with m_free=0 above */ - init_alloc_root(&m_mem_root, TABLE_ID_HASH_SIZE*sizeof(entry), 0, MYF(0)); + init_alloc_root(&m_mem_root, "table_mapping", + TABLE_ID_HASH_SIZE*sizeof(entry), 0, MYF(0)); DBUG_VOID_RETURN; } diff --cc sql/sql_lex.h index 13e1a5c0cf8,53f2ec15341..0e916b6c1c1 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@@ -2854,7 -2587,11 +2854,11 @@@ struct LEX: public Query_tables_lis String *wild; /* Wildcard in SHOW {something} LIKE 'wild'*/ sql_exchange *exchange; select_result *result; + /** + @c the two may also hold BINLOG arguments: either comment holds a + base64-char string or both represent the BINLOG fragment user variables. + */ - LEX_STRING comment, ident; + LEX_CSTRING comment, ident; LEX_USER *grant_user; XID *xid; THD *thd; diff --cc sql/sql_select.cc index ff51eb101d2,5e5878ebf65..439853c2f66 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@@ -18158,10 -17539,9 +18158,9 @@@ bool Virtual_tmp_table::sp_set_all_fiel bool open_tmp_table(TABLE *table) { int error; - if (unlikely((error= table->file->ha_open(table, table->s->table_name.str, - O_RDWR, - if ((error= table->file->ha_open(table, table->s->path.str, O_RDWR, - HA_OPEN_TMP_TABLE | - HA_OPEN_INTERNAL_TABLE))) ++ if (unlikely((error= table->file->ha_open(table, table->s->path.str, O_RDWR, + HA_OPEN_TMP_TABLE | + HA_OPEN_INTERNAL_TABLE)))) { table->file->print_error(error, MYF(0)); /* purecov: inspected */ table->db_stat= 0; @@@ -18355,14 -17735,10 +18354,14 @@@ bool create_internal_tmp_table(TABLE *t } } - if (unlikely((error= maria_create(share->table_name.str, - if ((error= maria_create(share->path.str, file_type, share->keys, &keydef, - (uint) (*recinfo-start_recinfo), start_recinfo, - share->uniques, &uniquedef, &create_info, - create_flags))) ++ if (unlikely((error= maria_create(share->path.str, + file_type, + share->keys, &keydef, + (uint) (*recinfo-start_recinfo), + start_recinfo, + share->uniques, &uniquedef, + &create_info, + create_flags)))) { table->file->print_error(error,MYF(0)); /* purecov: inspected */ table->db_stat=0; @@@ -18510,17 -17887,13 +18509,17 @@@ bool create_internal_tmp_table(TABLE *t bzero((char*) &create_info,sizeof(create_info)); create_info.data_file_length= table->in_use->variables.tmp_disk_table_size; - if (unlikely((error= mi_create(share->table_name.str, share->keys, &keydef, - (uint) (*recinfo-start_recinfo), - if ((error=mi_create(share->path.str, share->keys, &keydef, - (uint) (*recinfo-start_recinfo), start_recinfo, - share->uniques, &uniquedef, &create_info, - HA_CREATE_TMP_TABLE | HA_CREATE_INTERNAL_TABLE | - ((share->db_create_options & HA_OPTION_PACK_RECORD) ? - HA_PACK_RECORD : 0) - ))) ++ if (unlikely((error= mi_create(share->path.str, share->keys, &keydef, ++ (uint) (*recinfo-start_recinfo), + start_recinfo, - share->uniques, &uniquedef, ++ share->uniques, &uniquedef, + &create_info, - HA_CREATE_TMP_TABLE | ++ HA_CREATE_TMP_TABLE | + HA_CREATE_INTERNAL_TABLE | + ((share->db_create_options & + HA_OPTION_PACK_RECORD) ? + HA_PACK_RECORD : 0) + )))) { table->file->print_error(error,MYF(0)); /* purecov: inspected */ table->db_stat=0; @@@ -18691,14 -18068,9 +18690,14 @@@ free_tmp_table(THD *thd, TABLE *entry { entry->file->ha_index_or_rnd_end(); if (entry->db_stat) + { + entry->file->info(HA_STATUS_VARIABLE); + thd->tmp_tables_size+= (entry->file->stats.data_file_length + + entry->file->stats.index_file_length); - entry->file->ha_drop_table(entry->s->table_name.str); + entry->file->ha_drop_table(entry->s->path.str); + } else - entry->file->ha_delete_table(entry->s->table_name.str); + entry->file->ha_delete_table(entry->s->path.str); delete entry->file; } diff --cc sql/sql_table.cc index c7602c832ef,1227f144348..3099486c3f8 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@@ -6502,10 -6307,8 +6501,9 @@@ static bool fill_alter_inplace_info(TH Create_field *new_field; KEY_PART_INFO *key_part, *new_part; KEY_PART_INFO *end; - uint candidate_key_count= 0; Alter_info *alter_info= ha_alter_info->alter_info; DBUG_ENTER("fill_alter_inplace_info"); + DBUG_PRINT("info", ("alter_info->flags: %llu", alter_info->flags)); /* Allocate result buffers. */ if (! (ha_alter_info->index_drop_buffer= @@@ -6806,8 -6637,13 +6804,13 @@@ Primary key index for the new table */ const KEY* const new_pk= (ha_alter_info->key_count > 0 && - is_candidate_key(ha_alter_info->key_info_buffer)) ? + (!my_strcasecmp(system_charset_info, - ha_alter_info->key_info_buffer->name, ++ ha_alter_info->key_info_buffer->name.str, + primary_key_name) || + is_candidate_key(ha_alter_info->key_info_buffer))) ? ha_alter_info->key_info_buffer : NULL; + const KEY *const old_pk= table->s->primary_key == MAX_KEY ? NULL : + table->key_info + table->s->primary_key; DBUG_PRINT("info", ("index count old: %d new: %d", table->s->keys, ha_alter_info->key_count)); @@@ -6998,24 -6816,13 +6984,13 @@@ if (table_key->flags & HA_NOSAME) { - /* - Unique key. Check for PRIMARY KEY. Also see comment about primary - and candidate keys above. - */ - if ((uint) (table_key - table->key_info) == table->s->primary_key) - { + if (table_key == old_pk) - ha_alter_info->handler_flags|= Alter_inplace_info::DROP_PK_INDEX; + ha_alter_info->handler_flags|= ALTER_DROP_PK_INDEX; - candidate_key_count--; - } else - { - ha_alter_info->handler_flags|= Alter_inplace_info::DROP_UNIQUE_INDEX; + ha_alter_info->handler_flags|= ALTER_DROP_UNIQUE_INDEX; - if (is_candidate_key(table_key)) - candidate_key_count--; - } } else - ha_alter_info->handler_flags|= Alter_inplace_info::DROP_INDEX; + ha_alter_info->handler_flags|= ALTER_DROP_NON_UNIQUE_NON_PRIM_INDEX; } /* Now figure out what kind of indexes we are adding. */ @@@ -7025,30 -6832,15 +7000,16 @@@ if (new_key->flags & HA_NOSAME) { - bool is_pk= !my_strcasecmp(system_charset_info, - new_key->name.str, primary_key_name); - - if ((!(new_key->flags & HA_KEY_HAS_PART_KEY_SEG) && - !(new_key->flags & HA_NULL_PART_KEY)) || - is_pk) - { - /* Candidate key or primary key! */ - if (candidate_key_count == 0 || is_pk) - ha_alter_info->handler_flags|= ALTER_ADD_PK_INDEX; - else - ha_alter_info->handler_flags|= ALTER_ADD_UNIQUE_INDEX; - candidate_key_count++; - } + if (new_key == new_pk) - ha_alter_info->handler_flags|= Alter_inplace_info::ADD_PK_INDEX; ++ ha_alter_info->handler_flags|= ALTER_ADD_PK_INDEX; else - { - ha_alter_info->handler_flags|= Alter_inplace_info::ADD_UNIQUE_INDEX; + ha_alter_info->handler_flags|= ALTER_ADD_UNIQUE_INDEX; - } } else - ha_alter_info->handler_flags|= Alter_inplace_info::ADD_INDEX; + ha_alter_info->handler_flags|= ALTER_ADD_NON_UNIQUE_NON_PRIM_INDEX; } + DBUG_PRINT("exit", ("handler_flags: %llu", ha_alter_info->handler_flags)); DBUG_RETURN(false); } @@@ -9787,29 -9503,18 +9811,20 @@@ do_continue: goto err_new_table_cleanup; if (ha_create_table(thd, alter_ctx.get_tmp_path(), - alter_ctx.new_db.str, alter_ctx.tmp_name.str, - alter_ctx.new_db, alter_ctx.new_name, ++ alter_ctx.new_db.str, alter_ctx.new_name.str, create_info, &frm)) goto err_new_table_cleanup; /* Mark that we have created table in storage engine. */ no_ha_table= false; - if (create_info->tmp_table()) - { - TABLE *tmp_table= - thd->create_and_open_tmp_table(new_db_type, &frm, - alter_ctx.get_tmp_path(), - alter_ctx.new_db.str, - alter_ctx.tmp_name.str, - true, true); - if (!tmp_table) - { - goto err_new_table_cleanup; - } - /* in case of alter temp table send the tracker in OK packet */ - SESSION_TRACKER_CHANGED(thd, SESSION_STATE_CHANGE_TRACKER, NULL); - } - + new_table= + thd->create_and_open_tmp_table(new_db_type, &frm, alter_ctx.get_tmp_path(), - alter_ctx.new_db, alter_ctx.new_name, true); ++ alter_ctx.new_db.str, ++ alter_ctx.new_name.str, ++ true, true); + if (!new_table) + goto err_new_table_cleanup; /* Open the table since we need to copy the data. */ if (table->s->tmp_table != NO_TMP_TABLE) diff --cc sql/sql_yacc.yy index 46eac699c04,14d084e7022..98ead67011c --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@@ -2129,9 -1998,7 +2129,10 @@@ bool my_yyoverflow(short **a, YYSTYPE * vcol_opt_attribute_list vcol_attribute opt_serial_attribute opt_serial_attribute_list serial_attribute explainable_command + opt_lock_wait_timeout opt_delete_gtid_domain + asrow_attribute ++ opt_constraint_no_id END_OF_INPUT %type <NONE> call sp_proc_stmts sp_proc_stmts1 sp_proc_stmt @@@ -6718,8 -6123,13 +6719,13 @@@ check_constraint } ; + opt_constraint_no_id: + /* Empty */ {} + | CONSTRAINT {} + ; + opt_constraint: - /* empty */ { $$= null_lex_str; } + /* empty */ { $$= null_clex_str; } | constraint { $$= $1; } ; @@@ -8372,12 -7653,12 +8378,12 @@@ alter_list_item LEX *lex=Lex; Alter_drop *ad= (new (thd->mem_root) Alter_drop(Alter_drop::FOREIGN_KEY, $5.str, $4)); - if (ad == NULL) + if (unlikely(ad == NULL)) MYSQL_YYABORT; lex->alter_info.drop_list.push_back(ad, thd->mem_root); - lex->alter_info.flags|= Alter_info::DROP_FOREIGN_KEY; + lex->alter_info.flags|= ALTER_DROP_FOREIGN_KEY; } - | DROP PRIMARY_SYM KEY_SYM + | DROP opt_constraint_no_id PRIMARY_SYM KEY_SYM { LEX *lex=Lex; Alter_drop *ad= (new (thd->mem_root) diff --cc sql/table.h index f33f5e048c2,c3c138c1278..9156390a0eb --- a/sql/table.h +++ b/sql/table.h @@@ -631,23 -618,13 +631,13 @@@ struct TABLE_SHAR should correspond to each other. To ensure this one can use set_table_cache() methods. */ - LEX_STRING table_cache_key; - LEX_STRING db; /* Pointer to db */ - LEX_STRING table_name; /* Table name (for open) */ - LEX_STRING path; /* Path to .frm file (from datadir) */ - LEX_STRING normalized_path; /* unpack_filename(path) */ - LEX_STRING connect_string; + LEX_CSTRING table_cache_key; + LEX_CSTRING db; /* Pointer to db */ + LEX_CSTRING table_name; /* Table name (for open) */ + LEX_CSTRING path; /* Path to .frm file (from datadir) */ + LEX_CSTRING normalized_path; /* unpack_filename(path) */ + LEX_CSTRING connect_string; - const char* orig_table_name; /* Original table name for this tmp table */ - const char* error_table_name() const /* Get table name for error messages */ - { - return tmp_table ? ( - orig_table_name ? - orig_table_name : - "(temporary)") : - table_name.str; - } - /* Set of keys in use, implemented as a Bitmap. Excludes keys disabled by ALTER TABLE ... DISABLE KEYS. diff --cc storage/innobase/handler/ha_innodb.cc index 509be41e48f,8641bedecba..2377778f0e7 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@@ -10326,9 -10504,11 +10344,10 @@@ wsrep_append_key THD *thd, trx_t *trx, TABLE_SHARE *table_share, - TABLE *table, const char* key, uint16_t key_len, - bool shared + wsrep_key_type key_type /*!< in: access type of this key + (shared, exclusive, semi...) */ ) { DBUG_ENTER("wsrep_append_key"); @@@ -10438,14 -10619,13 +10458,12 @@@ ha_innobase::wsrep_append_keys if (!is_null) { rcode = wsrep_append_key( - thd, trx, table_share, table, keyval, + thd, trx, table_share, keyval, - len, shared); + len, key_type); + - if (rcode) { - DBUG_RETURN(rcode); - } + if (rcode) DBUG_RETURN(rcode); - } - else - { - WSREP_DEBUG("NULL key skipped (proto 0): %s", + } else { + WSREP_DEBUG("NULL key skipped (proto 0): %s", wsrep_thd_query(thd)); } } else { @@@ -10492,14 -10672,12 +10510,12 @@@ record0, &is_null); if (!is_null) { rcode = wsrep_append_key( - thd, trx, table_share, table, + thd, trx, table_share, - keyval0, len+1, shared); - - if (rcode) { - DBUG_RETURN(rcode); - } + keyval0, len+1, key_type); + if (rcode) DBUG_RETURN(rcode); - if (key_info->flags & HA_NOSAME || shared) + if (key_info->flags & HA_NOSAME || + key_type == WSREP_KEY_SHARED) key_appended = true; } else { WSREP_DEBUG("NULL key skipped: %s", @@@ -10512,10 -10690,13 +10528,12 @@@ WSREP_MAX_SUPPORTED_KEY_LENGTH, record1, &is_null); - if (!is_null && memcmp(key0, key1, len)) { + if (!is_null + && memcmp(key0, key1, len)) { rcode = wsrep_append_key( thd, trx, table_share, - keyval1, len+1, shared); - table, + keyval1, len+1, - key_type); ++ key_type); if (rcode) DBUG_RETURN(rcode); } } @@@ -10528,20 -10709,20 +10546,20 @@@ uchar digest[16]; int rcode; - wsrep_calc_row_hash(digest, record0, table, m_prebuilt, thd); - if ((rcode = wsrep_append_key(thd, trx, table_share, table, + wsrep_calc_row_hash(digest, record0, table, m_prebuilt); + + if ((rcode = wsrep_append_key(thd, trx, table_share, (const char*) digest, 16, - shared))) { + key_type))) { DBUG_RETURN(rcode); } if (record1) { wsrep_calc_row_hash( - digest, record1, table, m_prebuilt, thd); + digest, record1, table, m_prebuilt); if ((rcode = wsrep_append_key(thd, trx, table_share, - table, (const char*) digest, - 16, shared))) { + 16, key_type))) { DBUG_RETURN(rcode); } } diff --cc storage/innobase/handler/handler0alter.cc index 587ae7f5402,886b841b9c4..58de40761c5 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@@ -8628,8 -7766,10 +8636,10 @@@ commit_try_rebuild DBUG_ASSERT(ctx->need_rebuild()); DBUG_ASSERT(trx->dict_operation_lock_mode == RW_X_LATCH); DBUG_ASSERT(!(ha_alter_info->handler_flags - & Alter_inplace_info::DROP_FOREIGN_KEY) + & ALTER_DROP_FOREIGN_KEY) || ctx->num_to_drop_fk > 0); + DBUG_ASSERT(ctx->num_to_drop_fk + <= ha_alter_info->alter_info->drop_list.elements); for (dict_index_t* index = dict_table_get_first_index(rebuilt_table); index; @@@ -8926,10 -8014,10 +8936,10 @@@ commit_try_norebuild DBUG_ASSERT(!ctx->need_rebuild()); DBUG_ASSERT(trx->dict_operation_lock_mode == RW_X_LATCH); DBUG_ASSERT(!(ha_alter_info->handler_flags - & Alter_inplace_info::DROP_FOREIGN_KEY) + & ALTER_DROP_FOREIGN_KEY) || ctx->num_to_drop_fk > 0); DBUG_ASSERT(ctx->num_to_drop_fk - == ha_alter_info->alter_info->drop_list.elements + <= ha_alter_info->alter_info->drop_list.elements || ctx->num_to_drop_vcol == ha_alter_info->alter_info->drop_list.elements); @@@ -9863,11 -8863,25 +9861,22 @@@ foreign_fail m_user_thd, Sql_condition::WARN_LEVEL_WARN, ER_ALTER_INFO, - "InnoDB: Could not add foreign" - " key constraints."); - } else { - commit_cache_norebuild(ha_alter_info, ctx, - table, trx); + "failed to load FOREIGN KEY" + " constraints"); + } + } else { + bool fk_fail = innobase_update_foreign_cache( + ctx, m_user_thd) != DB_SUCCESS; + - if (!commit_cache_norebuild(ctx, table, trx)) { - fk_fail = true; - ut_ad(!m_prebuilt->trx->check_foreigns); - } - ++ commit_cache_norebuild(ha_alter_info, ctx, ++ table, trx); + innobase_rename_or_enlarge_columns_cache( + ha_alter_info, table, ctx->new_table); + #ifdef MYSQL_RENAME_INDEX + rename_indexes_in_cache(ctx, ha_alter_info); + #endif + if (fk_fail && m_prebuilt->trx->check_foreigns) { + goto foreign_fail; } }