diff options
Diffstat (limited to 'mysql-test/r')
185 files changed, 26589 insertions, 876 deletions
diff --git a/mysql-test/r/1st.result b/mysql-test/r/1st.result index 792d9eaf2f1..51dec186915 100644 --- a/mysql-test/r/1st.result +++ b/mysql-test/r/1st.result @@ -7,23 +7,28 @@ performance_schema test show tables in mysql; Tables_in_mysql +column_stats columns_priv db event func general_log +gtid_slave_pos help_category help_keyword help_relation help_topic host +index_stats ndb_binlog_index plugin proc procs_priv proxies_priv +roles_mapping servers slow_log +table_stats tables_priv time_zone time_zone_leap_second diff --git a/mysql-test/r/alter_table-big.result b/mysql-test/r/alter_table-big.result index 33af60938a1..85d1c4a0f64 100644 --- a/mysql-test/r/alter_table-big.result +++ b/mysql-test/r/alter_table-big.result @@ -16,11 +16,12 @@ insert into t1 values (1, 1, 1);; set debug_sync='now SIGNAL go'; show binlog events from <binlog_start>; Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Query # # use `test`; insert into t2 values (1) master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; alter table t1 enable keys -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Query # # use `test`; insert into t1 values (1, 1, 1) master-bin.000001 # Query # # COMMIT drop tables t1, t2; @@ -59,19 +60,28 @@ set debug_sync='alter_table_before_main_binlog SIGNAL parked WAIT_FOR go'; set debug_sync='RESET'; show binlog events from <binlog_start>; Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; alter table t1 change i c char(10) default 'Test1' -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Query # # use `test`; insert into t1 values () master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; alter table t1 change c vc varchar(100) default 'Test2' +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; rename table t1 to t2 +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; DROP TABLE `t2` /* generated by server */ +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; create table t1 (i int) +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; alter table t1 change i c char(10) default 'Test3', rename to t2 -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Query # # use `test`; insert into t2 values() master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; alter table t2 change c vc varchar(100) default 'Test2', rename to t1 +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; rename table t1 to t3 +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; DROP TABLE `t3` /* generated by server */ End of 5.1 tests diff --git a/mysql-test/r/alter_table.result b/mysql-test/r/alter_table.result index 624cc7afa98..b6e99952c23 100644 --- a/mysql-test/r/alter_table.result +++ b/mysql-test/r/alter_table.result @@ -176,12 +176,12 @@ 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 NULL NULL NULL YES BTREE -t1 0 a 2 b A NULL NULL NULL YES BTREE +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 OK +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 @@ -415,7 +415,7 @@ alter table t1 drop key a; drop table t1; CREATE TABLE T12207(a int) ENGINE=MYISAM; ALTER TABLE T12207 DISCARD TABLESPACE; -ERROR HY000: Table storage engine for 'T12207' doesn't have this option +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'ÔÅÓÔ'); @@ -978,7 +978,7 @@ 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 +) ENGINE=MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1 DROP TABLE `tt+1`, `tt+2`; CREATE TABLE `#sql1` (c1 INT); CREATE TABLE `@0023sql2` (c1 INT); @@ -1015,12 +1015,12 @@ SHOW CREATE TABLE `#sql2`; Table Create Table #sql2 CREATE TEMPORARY TABLE `#sql2` ( `c1` int(11) DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 +) ENGINE=MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1 SHOW CREATE TABLE `@0023sql1`; Table Create Table @0023sql1 CREATE TEMPORARY TABLE `@0023sql1` ( `c1` int(11) DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 +) ENGINE=MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1 DROP TABLE `#sql2`, `@0023sql1`; DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t2; @@ -1340,3 +1340,43 @@ rename table t2 to t1; execute stmt1; deallocate prepare stmt1; drop table t2; +CREATE TABLE t1 ( +id INT(11) NOT NULL, +x_param INT(11) DEFAULT NULL, +PRIMARY KEY (id) +); +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 'lol'; check that column/key 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 'x_param'; check that column/key 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; diff --git a/mysql-test/r/alter_table_mdev539_maria.result b/mysql-test/r/alter_table_mdev539_maria.result new file mode 100644 index 00000000000..703908825d2 --- /dev/null +++ b/mysql-test/r/alter_table_mdev539_maria.result @@ -0,0 +1,252 @@ +# +set @@storage_engine= Aria; +# +# mdev-539: fast build of unique/primary indexes for MyISAM/Aria +# +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +drop index `primary` on lineitem; +show create table lineitem; +Table Create Table +lineitem CREATE TABLE `lineitem` ( + `l_orderkey` int(11) NOT NULL DEFAULT '0', + `l_partkey` int(11) DEFAULT NULL, + `l_suppkey` int(11) DEFAULT NULL, + `l_linenumber` int(11) NOT NULL DEFAULT '0', + `l_quantity` double DEFAULT NULL, + `l_extendedprice` double DEFAULT NULL, + `l_discount` double DEFAULT NULL, + `l_tax` double DEFAULT NULL, + `l_returnflag` char(1) DEFAULT NULL, + `l_linestatus` char(1) DEFAULT NULL, + `l_shipDATE` date DEFAULT NULL, + `l_commitDATE` date DEFAULT NULL, + `l_receiptDATE` date DEFAULT NULL, + `l_shipinstruct` char(25) DEFAULT NULL, + `l_shipmode` char(10) DEFAULT NULL, + `l_comment` varchar(44) DEFAULT NULL, + KEY `i_l_shipdate` (`l_shipDATE`), + KEY `i_l_suppkey_partkey` (`l_partkey`,`l_suppkey`), + KEY `i_l_partkey` (`l_partkey`), + KEY `i_l_suppkey` (`l_suppkey`), + KEY `i_l_receiptdate` (`l_receiptDATE`), + KEY `i_l_orderkey` (`l_orderkey`), + KEY `i_l_orderkey_quantity` (`l_orderkey`,`l_quantity`), + KEY `i_l_commitdate` (`l_commitDATE`) +) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1 +alter table lineitem add primary key (l_orderkey, l_linenumber); +show create table lineitem; +Table Create Table +lineitem CREATE TABLE `lineitem` ( + `l_orderkey` int(11) NOT NULL DEFAULT '0', + `l_partkey` int(11) DEFAULT NULL, + `l_suppkey` int(11) DEFAULT NULL, + `l_linenumber` int(11) NOT NULL DEFAULT '0', + `l_quantity` double DEFAULT NULL, + `l_extendedprice` double DEFAULT NULL, + `l_discount` double DEFAULT NULL, + `l_tax` double DEFAULT NULL, + `l_returnflag` char(1) DEFAULT NULL, + `l_linestatus` char(1) DEFAULT NULL, + `l_shipDATE` date DEFAULT NULL, + `l_commitDATE` date DEFAULT NULL, + `l_receiptDATE` date DEFAULT NULL, + `l_shipinstruct` char(25) DEFAULT NULL, + `l_shipmode` char(10) DEFAULT NULL, + `l_comment` varchar(44) DEFAULT NULL, + PRIMARY KEY (`l_orderkey`,`l_linenumber`), + KEY `i_l_shipdate` (`l_shipDATE`), + KEY `i_l_suppkey_partkey` (`l_partkey`,`l_suppkey`), + KEY `i_l_partkey` (`l_partkey`), + KEY `i_l_suppkey` (`l_suppkey`), + KEY `i_l_receiptdate` (`l_receiptDATE`), + KEY `i_l_orderkey` (`l_orderkey`), + KEY `i_l_orderkey_quantity` (`l_orderkey`,`l_quantity`), + KEY `i_l_commitdate` (`l_commitDATE`) +) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1 +drop index `primary` on lineitem; +select * from lineitem where l_orderkey=1 and l_linenumber=2; +l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipDATE l_commitDATE l_receiptDATE l_shipinstruct l_shipmode l_comment +1 68 9 2 36 34850.16 0.09 0.06 N O 1996-04-12 1996-02-28 1996-04-20 TAKE BACK RETURN MAIL slyly bold pinto beans detect s +insert into lineitem values +(1,68,9,2,36,34850.16,0.07,0.06,'N','O','1996-04-12','1996-02-28','1996-04-20','TAKE BACK RETURN','MAIL','slyly bold pinto beans detect s'); +select * from lineitem where l_orderkey=1 and l_linenumber=2; +l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipDATE l_commitDATE l_receiptDATE l_shipinstruct l_shipmode l_comment +1 68 9 2 36 34850.16 0.09 0.06 N O 1996-04-12 1996-02-28 1996-04-20 TAKE BACK RETURN MAIL slyly bold pinto beans detect s +1 68 9 2 36 34850.16 0.07 0.06 N O 1996-04-12 1996-02-28 1996-04-20 TAKE BACK RETURN MAIL slyly bold pinto beans detect s +alter table lineitem add primary key (l_orderkey, l_linenumber); +ERROR 23000: Duplicate entry '1-2' for key 'PRIMARY' +show create table lineitem; +Table Create Table +lineitem CREATE TABLE `lineitem` ( + `l_orderkey` int(11) NOT NULL DEFAULT '0', + `l_partkey` int(11) DEFAULT NULL, + `l_suppkey` int(11) DEFAULT NULL, + `l_linenumber` int(11) NOT NULL DEFAULT '0', + `l_quantity` double DEFAULT NULL, + `l_extendedprice` double DEFAULT NULL, + `l_discount` double DEFAULT NULL, + `l_tax` double DEFAULT NULL, + `l_returnflag` char(1) DEFAULT NULL, + `l_linestatus` char(1) DEFAULT NULL, + `l_shipDATE` date DEFAULT NULL, + `l_commitDATE` date DEFAULT NULL, + `l_receiptDATE` date DEFAULT NULL, + `l_shipinstruct` char(25) DEFAULT NULL, + `l_shipmode` char(10) DEFAULT NULL, + `l_comment` varchar(44) DEFAULT NULL, + KEY `i_l_shipdate` (`l_shipDATE`), + KEY `i_l_suppkey_partkey` (`l_partkey`,`l_suppkey`), + KEY `i_l_partkey` (`l_partkey`), + KEY `i_l_suppkey` (`l_suppkey`), + KEY `i_l_receiptdate` (`l_receiptDATE`), + KEY `i_l_orderkey` (`l_orderkey`), + KEY `i_l_orderkey_quantity` (`l_orderkey`,`l_quantity`), + KEY `i_l_commitdate` (`l_commitDATE`) +) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1 +select * from lineitem where l_orderkey=1 and l_linenumber=2; +l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipDATE l_commitDATE l_receiptDATE l_shipinstruct l_shipmode l_comment +1 68 9 2 36 34850.16 0.09 0.06 N O 1996-04-12 1996-02-28 1996-04-20 TAKE BACK RETURN MAIL slyly bold pinto beans detect s +1 68 9 2 36 34850.16 0.07 0.06 N O 1996-04-12 1996-02-28 1996-04-20 TAKE BACK RETURN MAIL slyly bold pinto beans detect s +delete from lineitem where l_orderkey=1 and l_linenumber=2 and l_discount=0.07; +alter table lineitem add primary key (l_orderkey, l_linenumber); +show create table lineitem; +Table Create Table +lineitem CREATE TABLE `lineitem` ( + `l_orderkey` int(11) NOT NULL DEFAULT '0', + `l_partkey` int(11) DEFAULT NULL, + `l_suppkey` int(11) DEFAULT NULL, + `l_linenumber` int(11) NOT NULL DEFAULT '0', + `l_quantity` double DEFAULT NULL, + `l_extendedprice` double DEFAULT NULL, + `l_discount` double DEFAULT NULL, + `l_tax` double DEFAULT NULL, + `l_returnflag` char(1) DEFAULT NULL, + `l_linestatus` char(1) DEFAULT NULL, + `l_shipDATE` date DEFAULT NULL, + `l_commitDATE` date DEFAULT NULL, + `l_receiptDATE` date DEFAULT NULL, + `l_shipinstruct` char(25) DEFAULT NULL, + `l_shipmode` char(10) DEFAULT NULL, + `l_comment` varchar(44) DEFAULT NULL, + PRIMARY KEY (`l_orderkey`,`l_linenumber`), + KEY `i_l_shipdate` (`l_shipDATE`), + KEY `i_l_suppkey_partkey` (`l_partkey`,`l_suppkey`), + KEY `i_l_partkey` (`l_partkey`), + KEY `i_l_suppkey` (`l_suppkey`), + KEY `i_l_receiptdate` (`l_receiptDATE`), + KEY `i_l_orderkey` (`l_orderkey`), + KEY `i_l_orderkey_quantity` (`l_orderkey`,`l_quantity`), + KEY `i_l_commitdate` (`l_commitDATE`) +) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1 +select * from lineitem where l_orderkey=1 and l_linenumber=2; +l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipDATE l_commitDATE l_receiptDATE l_shipinstruct l_shipmode l_comment +1 68 9 2 36 34850.16 0.09 0.06 N O 1996-04-12 1996-02-28 1996-04-20 TAKE BACK RETURN MAIL slyly bold pinto beans detect s +create unique index i_c_name on customer(c_name); +show create table customer; +Table Create Table +customer CREATE TABLE `customer` ( + `c_custkey` int(11) NOT NULL, + `c_name` varchar(25) DEFAULT NULL, + `c_address` varchar(40) DEFAULT NULL, + `c_nationkey` int(11) DEFAULT NULL, + `c_phone` char(15) DEFAULT NULL, + `c_acctbal` double DEFAULT NULL, + `c_mktsegment` char(10) DEFAULT NULL, + `c_comment` varchar(117) DEFAULT NULL, + PRIMARY KEY (`c_custkey`), + UNIQUE KEY `i_c_name` (`c_name`), + KEY `i_c_nationkey` (`c_nationkey`) +) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1 +select * from customer where c_name='Customer#000000003'; +c_custkey c_name c_address c_nationkey c_phone c_acctbal c_mktsegment c_comment +3 Customer#000000003 MG9kdTD2WBHm 1 11-719-748-3364 7498.12 AUTOMOBILE special packages wake. slyly reg +drop index i_c_name on customer; +insert into customer values +(303,'Customer#000000003','MG9kdTD2WBHm',1,'11-719-748-3364',7498.12,'AUTOMOBILE','special packages wake. slyly reg'); +select * from customer where c_name='Customer#000000003'; +c_custkey c_name c_address c_nationkey c_phone c_acctbal c_mktsegment c_comment +3 Customer#000000003 MG9kdTD2WBHm 1 11-719-748-3364 7498.12 AUTOMOBILE special packages wake. slyly reg +303 Customer#000000003 MG9kdTD2WBHm 1 11-719-748-3364 7498.12 AUTOMOBILE special packages wake. slyly reg +alter table customer add unique index i_c_name(c_name); +ERROR 23000: Duplicate entry 'Customer#000000003' for key 'i_c_name' +show create table customer; +Table Create Table +customer CREATE TABLE `customer` ( + `c_custkey` int(11) NOT NULL, + `c_name` varchar(25) DEFAULT NULL, + `c_address` varchar(40) DEFAULT NULL, + `c_nationkey` int(11) DEFAULT NULL, + `c_phone` char(15) DEFAULT NULL, + `c_acctbal` double DEFAULT NULL, + `c_mktsegment` char(10) DEFAULT NULL, + `c_comment` varchar(117) DEFAULT NULL, + PRIMARY KEY (`c_custkey`), + KEY `i_c_nationkey` (`c_nationkey`) +) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1 +select * from customer where c_name='Customer#000000003'; +c_custkey c_name c_address c_nationkey c_phone c_acctbal c_mktsegment c_comment +3 Customer#000000003 MG9kdTD2WBHm 1 11-719-748-3364 7498.12 AUTOMOBILE special packages wake. slyly reg +303 Customer#000000003 MG9kdTD2WBHm 1 11-719-748-3364 7498.12 AUTOMOBILE special packages wake. slyly reg +delete from customer where c_custkey=303; +select * from customer where c_name='Customer#000000003'; +c_custkey c_name c_address c_nationkey c_phone c_acctbal c_mktsegment c_comment +3 Customer#000000003 MG9kdTD2WBHm 1 11-719-748-3364 7498.12 AUTOMOBILE special packages wake. slyly reg +alter table customer add unique index i_c_name(c_name); +show create table customer; +Table Create Table +customer CREATE TABLE `customer` ( + `c_custkey` int(11) NOT NULL, + `c_name` varchar(25) DEFAULT NULL, + `c_address` varchar(40) DEFAULT NULL, + `c_nationkey` int(11) DEFAULT NULL, + `c_phone` char(15) DEFAULT NULL, + `c_acctbal` double DEFAULT NULL, + `c_mktsegment` char(10) DEFAULT NULL, + `c_comment` varchar(117) DEFAULT NULL, + PRIMARY KEY (`c_custkey`), + UNIQUE KEY `i_c_name` (`c_name`), + KEY `i_c_nationkey` (`c_nationkey`) +) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1 +select * from customer where c_name='Customer#000000003'; +c_custkey c_name c_address c_nationkey c_phone c_acctbal c_mktsegment c_comment +3 Customer#000000003 MG9kdTD2WBHm 1 11-719-748-3364 7498.12 AUTOMOBILE special packages wake. slyly reg +drop index `primary` on customer; +show create table customer; +Table Create Table +customer CREATE TABLE `customer` ( + `c_custkey` int(11) NOT NULL, + `c_name` varchar(25) DEFAULT NULL, + `c_address` varchar(40) DEFAULT NULL, + `c_nationkey` int(11) DEFAULT NULL, + `c_phone` char(15) DEFAULT NULL, + `c_acctbal` double DEFAULT NULL, + `c_mktsegment` char(10) DEFAULT NULL, + `c_comment` varchar(117) DEFAULT NULL, + UNIQUE KEY `i_c_name` (`c_name`), + KEY `i_c_nationkey` (`c_nationkey`) +) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1 +insert into customer values +(3,'Customer#000000303','MG9kdTD2WBHm',1,'11-719-748-3364',7498.12,'AUTOMOBILE','special packages wake. slyly reg'); +alter ignore table customer add primary key (c_custkey); +show create table customer; +Table Create Table +customer CREATE TABLE `customer` ( + `c_custkey` int(11) NOT NULL, + `c_name` varchar(25) DEFAULT NULL, + `c_address` varchar(40) DEFAULT NULL, + `c_nationkey` int(11) DEFAULT NULL, + `c_phone` char(15) DEFAULT NULL, + `c_acctbal` double DEFAULT NULL, + `c_mktsegment` char(10) DEFAULT NULL, + `c_comment` varchar(117) DEFAULT NULL, + PRIMARY KEY (`c_custkey`), + UNIQUE KEY `i_c_name` (`c_name`), + KEY `i_c_nationkey` (`c_nationkey`) +) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1 +select * from customer where c_custkey=3; +c_custkey c_name c_address c_nationkey c_phone c_acctbal c_mktsegment c_comment +3 Customer#000000003 MG9kdTD2WBHm 1 11-719-748-3364 7498.12 AUTOMOBILE special packages wake. slyly reg +DROP DATABASE dbt3_s001; +set @@storage_engine= default; diff --git a/mysql-test/r/alter_table_mdev539_myisam.result b/mysql-test/r/alter_table_mdev539_myisam.result new file mode 100644 index 00000000000..7140c544836 --- /dev/null +++ b/mysql-test/r/alter_table_mdev539_myisam.result @@ -0,0 +1,252 @@ +# +set @@storage_engine= MyISAM; +# +# mdev-539: fast build of unique/primary indexes for MyISAM/Aria +# +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +drop index `primary` on lineitem; +show create table lineitem; +Table Create Table +lineitem CREATE TABLE `lineitem` ( + `l_orderkey` int(11) NOT NULL DEFAULT '0', + `l_partkey` int(11) DEFAULT NULL, + `l_suppkey` int(11) DEFAULT NULL, + `l_linenumber` int(11) NOT NULL DEFAULT '0', + `l_quantity` double DEFAULT NULL, + `l_extendedprice` double DEFAULT NULL, + `l_discount` double DEFAULT NULL, + `l_tax` double DEFAULT NULL, + `l_returnflag` char(1) DEFAULT NULL, + `l_linestatus` char(1) DEFAULT NULL, + `l_shipDATE` date DEFAULT NULL, + `l_commitDATE` date DEFAULT NULL, + `l_receiptDATE` date DEFAULT NULL, + `l_shipinstruct` char(25) DEFAULT NULL, + `l_shipmode` char(10) DEFAULT NULL, + `l_comment` varchar(44) DEFAULT NULL, + KEY `i_l_shipdate` (`l_shipDATE`), + KEY `i_l_suppkey_partkey` (`l_partkey`,`l_suppkey`), + KEY `i_l_partkey` (`l_partkey`), + KEY `i_l_suppkey` (`l_suppkey`), + KEY `i_l_receiptdate` (`l_receiptDATE`), + KEY `i_l_orderkey` (`l_orderkey`), + KEY `i_l_orderkey_quantity` (`l_orderkey`,`l_quantity`), + KEY `i_l_commitdate` (`l_commitDATE`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +alter table lineitem add primary key (l_orderkey, l_linenumber); +show create table lineitem; +Table Create Table +lineitem CREATE TABLE `lineitem` ( + `l_orderkey` int(11) NOT NULL DEFAULT '0', + `l_partkey` int(11) DEFAULT NULL, + `l_suppkey` int(11) DEFAULT NULL, + `l_linenumber` int(11) NOT NULL DEFAULT '0', + `l_quantity` double DEFAULT NULL, + `l_extendedprice` double DEFAULT NULL, + `l_discount` double DEFAULT NULL, + `l_tax` double DEFAULT NULL, + `l_returnflag` char(1) DEFAULT NULL, + `l_linestatus` char(1) DEFAULT NULL, + `l_shipDATE` date DEFAULT NULL, + `l_commitDATE` date DEFAULT NULL, + `l_receiptDATE` date DEFAULT NULL, + `l_shipinstruct` char(25) DEFAULT NULL, + `l_shipmode` char(10) DEFAULT NULL, + `l_comment` varchar(44) DEFAULT NULL, + PRIMARY KEY (`l_orderkey`,`l_linenumber`), + KEY `i_l_shipdate` (`l_shipDATE`), + KEY `i_l_suppkey_partkey` (`l_partkey`,`l_suppkey`), + KEY `i_l_partkey` (`l_partkey`), + KEY `i_l_suppkey` (`l_suppkey`), + KEY `i_l_receiptdate` (`l_receiptDATE`), + KEY `i_l_orderkey` (`l_orderkey`), + KEY `i_l_orderkey_quantity` (`l_orderkey`,`l_quantity`), + KEY `i_l_commitdate` (`l_commitDATE`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop index `primary` on lineitem; +select * from lineitem where l_orderkey=1 and l_linenumber=2; +l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipDATE l_commitDATE l_receiptDATE l_shipinstruct l_shipmode l_comment +1 68 9 2 36 34850.16 0.09 0.06 N O 1996-04-12 1996-02-28 1996-04-20 TAKE BACK RETURN MAIL slyly bold pinto beans detect s +insert into lineitem values +(1,68,9,2,36,34850.16,0.07,0.06,'N','O','1996-04-12','1996-02-28','1996-04-20','TAKE BACK RETURN','MAIL','slyly bold pinto beans detect s'); +select * from lineitem where l_orderkey=1 and l_linenumber=2; +l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipDATE l_commitDATE l_receiptDATE l_shipinstruct l_shipmode l_comment +1 68 9 2 36 34850.16 0.09 0.06 N O 1996-04-12 1996-02-28 1996-04-20 TAKE BACK RETURN MAIL slyly bold pinto beans detect s +1 68 9 2 36 34850.16 0.07 0.06 N O 1996-04-12 1996-02-28 1996-04-20 TAKE BACK RETURN MAIL slyly bold pinto beans detect s +alter table lineitem add primary key (l_orderkey, l_linenumber); +ERROR 23000: Duplicate entry '1-2' for key 'PRIMARY' +show create table lineitem; +Table Create Table +lineitem CREATE TABLE `lineitem` ( + `l_orderkey` int(11) NOT NULL DEFAULT '0', + `l_partkey` int(11) DEFAULT NULL, + `l_suppkey` int(11) DEFAULT NULL, + `l_linenumber` int(11) NOT NULL DEFAULT '0', + `l_quantity` double DEFAULT NULL, + `l_extendedprice` double DEFAULT NULL, + `l_discount` double DEFAULT NULL, + `l_tax` double DEFAULT NULL, + `l_returnflag` char(1) DEFAULT NULL, + `l_linestatus` char(1) DEFAULT NULL, + `l_shipDATE` date DEFAULT NULL, + `l_commitDATE` date DEFAULT NULL, + `l_receiptDATE` date DEFAULT NULL, + `l_shipinstruct` char(25) DEFAULT NULL, + `l_shipmode` char(10) DEFAULT NULL, + `l_comment` varchar(44) DEFAULT NULL, + KEY `i_l_shipdate` (`l_shipDATE`), + KEY `i_l_suppkey_partkey` (`l_partkey`,`l_suppkey`), + KEY `i_l_partkey` (`l_partkey`), + KEY `i_l_suppkey` (`l_suppkey`), + KEY `i_l_receiptdate` (`l_receiptDATE`), + KEY `i_l_orderkey` (`l_orderkey`), + KEY `i_l_orderkey_quantity` (`l_orderkey`,`l_quantity`), + KEY `i_l_commitdate` (`l_commitDATE`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +select * from lineitem where l_orderkey=1 and l_linenumber=2; +l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipDATE l_commitDATE l_receiptDATE l_shipinstruct l_shipmode l_comment +1 68 9 2 36 34850.16 0.09 0.06 N O 1996-04-12 1996-02-28 1996-04-20 TAKE BACK RETURN MAIL slyly bold pinto beans detect s +1 68 9 2 36 34850.16 0.07 0.06 N O 1996-04-12 1996-02-28 1996-04-20 TAKE BACK RETURN MAIL slyly bold pinto beans detect s +delete from lineitem where l_orderkey=1 and l_linenumber=2 and l_discount=0.07; +alter table lineitem add primary key (l_orderkey, l_linenumber); +show create table lineitem; +Table Create Table +lineitem CREATE TABLE `lineitem` ( + `l_orderkey` int(11) NOT NULL DEFAULT '0', + `l_partkey` int(11) DEFAULT NULL, + `l_suppkey` int(11) DEFAULT NULL, + `l_linenumber` int(11) NOT NULL DEFAULT '0', + `l_quantity` double DEFAULT NULL, + `l_extendedprice` double DEFAULT NULL, + `l_discount` double DEFAULT NULL, + `l_tax` double DEFAULT NULL, + `l_returnflag` char(1) DEFAULT NULL, + `l_linestatus` char(1) DEFAULT NULL, + `l_shipDATE` date DEFAULT NULL, + `l_commitDATE` date DEFAULT NULL, + `l_receiptDATE` date DEFAULT NULL, + `l_shipinstruct` char(25) DEFAULT NULL, + `l_shipmode` char(10) DEFAULT NULL, + `l_comment` varchar(44) DEFAULT NULL, + PRIMARY KEY (`l_orderkey`,`l_linenumber`), + KEY `i_l_shipdate` (`l_shipDATE`), + KEY `i_l_suppkey_partkey` (`l_partkey`,`l_suppkey`), + KEY `i_l_partkey` (`l_partkey`), + KEY `i_l_suppkey` (`l_suppkey`), + KEY `i_l_receiptdate` (`l_receiptDATE`), + KEY `i_l_orderkey` (`l_orderkey`), + KEY `i_l_orderkey_quantity` (`l_orderkey`,`l_quantity`), + KEY `i_l_commitdate` (`l_commitDATE`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +select * from lineitem where l_orderkey=1 and l_linenumber=2; +l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipDATE l_commitDATE l_receiptDATE l_shipinstruct l_shipmode l_comment +1 68 9 2 36 34850.16 0.09 0.06 N O 1996-04-12 1996-02-28 1996-04-20 TAKE BACK RETURN MAIL slyly bold pinto beans detect s +create unique index i_c_name on customer(c_name); +show create table customer; +Table Create Table +customer CREATE TABLE `customer` ( + `c_custkey` int(11) NOT NULL, + `c_name` varchar(25) DEFAULT NULL, + `c_address` varchar(40) DEFAULT NULL, + `c_nationkey` int(11) DEFAULT NULL, + `c_phone` char(15) DEFAULT NULL, + `c_acctbal` double DEFAULT NULL, + `c_mktsegment` char(10) DEFAULT NULL, + `c_comment` varchar(117) DEFAULT NULL, + PRIMARY KEY (`c_custkey`), + UNIQUE KEY `i_c_name` (`c_name`), + KEY `i_c_nationkey` (`c_nationkey`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +select * from customer where c_name='Customer#000000003'; +c_custkey c_name c_address c_nationkey c_phone c_acctbal c_mktsegment c_comment +3 Customer#000000003 MG9kdTD2WBHm 1 11-719-748-3364 7498.12 AUTOMOBILE special packages wake. slyly reg +drop index i_c_name on customer; +insert into customer values +(303,'Customer#000000003','MG9kdTD2WBHm',1,'11-719-748-3364',7498.12,'AUTOMOBILE','special packages wake. slyly reg'); +select * from customer where c_name='Customer#000000003'; +c_custkey c_name c_address c_nationkey c_phone c_acctbal c_mktsegment c_comment +3 Customer#000000003 MG9kdTD2WBHm 1 11-719-748-3364 7498.12 AUTOMOBILE special packages wake. slyly reg +303 Customer#000000003 MG9kdTD2WBHm 1 11-719-748-3364 7498.12 AUTOMOBILE special packages wake. slyly reg +alter table customer add unique index i_c_name(c_name); +ERROR 23000: Duplicate entry 'Customer#000000003' for key 'i_c_name' +show create table customer; +Table Create Table +customer CREATE TABLE `customer` ( + `c_custkey` int(11) NOT NULL, + `c_name` varchar(25) DEFAULT NULL, + `c_address` varchar(40) DEFAULT NULL, + `c_nationkey` int(11) DEFAULT NULL, + `c_phone` char(15) DEFAULT NULL, + `c_acctbal` double DEFAULT NULL, + `c_mktsegment` char(10) DEFAULT NULL, + `c_comment` varchar(117) DEFAULT NULL, + PRIMARY KEY (`c_custkey`), + KEY `i_c_nationkey` (`c_nationkey`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +select * from customer where c_name='Customer#000000003'; +c_custkey c_name c_address c_nationkey c_phone c_acctbal c_mktsegment c_comment +3 Customer#000000003 MG9kdTD2WBHm 1 11-719-748-3364 7498.12 AUTOMOBILE special packages wake. slyly reg +303 Customer#000000003 MG9kdTD2WBHm 1 11-719-748-3364 7498.12 AUTOMOBILE special packages wake. slyly reg +delete from customer where c_custkey=303; +select * from customer where c_name='Customer#000000003'; +c_custkey c_name c_address c_nationkey c_phone c_acctbal c_mktsegment c_comment +3 Customer#000000003 MG9kdTD2WBHm 1 11-719-748-3364 7498.12 AUTOMOBILE special packages wake. slyly reg +alter table customer add unique index i_c_name(c_name); +show create table customer; +Table Create Table +customer CREATE TABLE `customer` ( + `c_custkey` int(11) NOT NULL, + `c_name` varchar(25) DEFAULT NULL, + `c_address` varchar(40) DEFAULT NULL, + `c_nationkey` int(11) DEFAULT NULL, + `c_phone` char(15) DEFAULT NULL, + `c_acctbal` double DEFAULT NULL, + `c_mktsegment` char(10) DEFAULT NULL, + `c_comment` varchar(117) DEFAULT NULL, + PRIMARY KEY (`c_custkey`), + UNIQUE KEY `i_c_name` (`c_name`), + KEY `i_c_nationkey` (`c_nationkey`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +select * from customer where c_name='Customer#000000003'; +c_custkey c_name c_address c_nationkey c_phone c_acctbal c_mktsegment c_comment +3 Customer#000000003 MG9kdTD2WBHm 1 11-719-748-3364 7498.12 AUTOMOBILE special packages wake. slyly reg +drop index `primary` on customer; +show create table customer; +Table Create Table +customer CREATE TABLE `customer` ( + `c_custkey` int(11) NOT NULL, + `c_name` varchar(25) DEFAULT NULL, + `c_address` varchar(40) DEFAULT NULL, + `c_nationkey` int(11) DEFAULT NULL, + `c_phone` char(15) DEFAULT NULL, + `c_acctbal` double DEFAULT NULL, + `c_mktsegment` char(10) DEFAULT NULL, + `c_comment` varchar(117) DEFAULT NULL, + UNIQUE KEY `i_c_name` (`c_name`), + KEY `i_c_nationkey` (`c_nationkey`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +insert into customer values +(3,'Customer#000000303','MG9kdTD2WBHm',1,'11-719-748-3364',7498.12,'AUTOMOBILE','special packages wake. slyly reg'); +alter ignore table customer add primary key (c_custkey); +show create table customer; +Table Create Table +customer CREATE TABLE `customer` ( + `c_custkey` int(11) NOT NULL, + `c_name` varchar(25) DEFAULT NULL, + `c_address` varchar(40) DEFAULT NULL, + `c_nationkey` int(11) DEFAULT NULL, + `c_phone` char(15) DEFAULT NULL, + `c_acctbal` double DEFAULT NULL, + `c_mktsegment` char(10) DEFAULT NULL, + `c_comment` varchar(117) DEFAULT NULL, + PRIMARY KEY (`c_custkey`), + UNIQUE KEY `i_c_name` (`c_name`), + KEY `i_c_nationkey` (`c_nationkey`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +select * from customer where c_custkey=3; +c_custkey c_name c_address c_nationkey c_phone c_acctbal c_mktsegment c_comment +3 Customer#000000003 MG9kdTD2WBHm 1 11-719-748-3364 7498.12 AUTOMOBILE special packages wake. slyly reg +DROP DATABASE dbt3_s001; +set @@storage_engine= default; diff --git a/mysql-test/r/alter_table_trans.result b/mysql-test/r/alter_table_trans.result index 67ae4075d57..a2547708ada 100644 --- a/mysql-test/r/alter_table_trans.result +++ b/mysql-test/r/alter_table_trans.result @@ -2,7 +2,7 @@ drop table if exists t1,t2; CREATE TABLE t1 (a INT, INDEX(a)) engine=innodb; ALTER TABLE t1 RENAME TO t2, DISABLE KEYS; Warnings: -Note 1031 Table storage engine for 't1' doesn't have this option +Note 1031 Storage engine InnoDB of the table `test`.`t1` doesn't have this option DROP TABLE t2; CREATE TABLE t1 ( col4 text NOT NULL, diff --git a/mysql-test/r/comments.result b/mysql-test/r/comments.result index 8aebe95c5ac..ce817b5012f 100644 --- a/mysql-test/r/comments.result +++ b/mysql-test/r/comments.result @@ -10,7 +10,7 @@ ERROR 42000: Query was empty select 1 /*!32301 +1 */; 1 +1 2 -select 1 /*!52301 +1 */; +select 1 /*!952301 +1 */; 1 1 select 1--1; @@ -35,19 +35,62 @@ select 1 /*M!50000 +1 */; select 1 /*M!50300 +1 */; 1 +1 2 -select 2 /*M!99999 +1 */; +select 2 /*M!999999 +1 */; 2 2 select 2 /*M!0000 +1 */; 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 '0000 +1 */' at line 1 +# +# Testing that MySQL versions >= 5.7.x and < 10.0.0 are ignored (MDEV-5009) +# +SELECT 1 /*!50699 +1*/; +1 +1 +2 +SELECT 1 /*!50700 +1*/; +1 +1 +SELECT 1 /*!50999 +1*/; +1 +1 +SELECT 1 /*!99999 +1*/; +1 +1 +SELECT 1 /*!100000 +1*/; +1 +1 +2 +SELECT 1 /*!110000 +1*/; +1 +1 +# +# Tesing that versions >= 5.7.x and < 10.0.0 are not ignored +# when used with the MariaDB executable comment syntax. +# +SELECT 1 /*M!50699 +1*/; +1 +1 +2 +SELECT 1 /*M!50700 +1*/; +1 +1 +2 +SELECT 1 /*M!50999 +1*/; +1 +1 +2 +SELECT 1 /*M!99999 +1*/; +1 +1 +2 +SELECT 1 /*M!100000 +1*/; +1 +1 +2 +SELECT 1 /*M!110000 +1*/; +1 +1 select 1/*!2*/; 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 '2*/' at line 1 -select 1/*!000002*/; +select 1/*!0000002*/; 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 '2*/' at line 1 select 1/*!999992*/; 1 1 -select 1 + /*!00000 2 */ + 3 /*!99999 noise*/ + 4; +select 1 + /*!00000 2 */ + 3 /*!999999 noise*/ + 4; 1 + 2 + 3 + 4 10 drop table if exists table_28779; @@ -60,8 +103,8 @@ prepare bar from "DELETE FROM table_28779 WHERE a = 7 OR 1=1/*! AND 2=2;"; 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 '' at line 1 prepare bar from "DELETE FROM table_28779 WHERE a = 7 OR 1=1/*! AND 2=2;*"; 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 '*' at line 1 -prepare bar from "DELETE FROM table_28779 WHERE a = 7 OR 1=1/*!98765' AND b = 'bar';"; -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 '/*!98765' AND b = 'bar'' at line 1 -prepare bar from "DELETE FROM table_28779 WHERE a = 7 OR 1=1/*!98765' AND b = 'bar';*"; -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 '/*!98765' AND b = 'bar';*' at line 1 +prepare bar from "DELETE FROM table_28779 WHERE a = 7 OR 1=1/*!998765' AND b = 'bar';"; +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 '/*!998765' AND b = 'bar'' at line 1 +prepare bar from "DELETE FROM table_28779 WHERE a = 7 OR 1=1/*!998765' AND b = 'bar';*"; +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 '/*!998765' AND b = 'bar';*' at line 1 drop table table_28779; diff --git a/mysql-test/r/connect.result b/mysql-test/r/connect.result index 09eaf9855b0..b41303137ab 100644 --- a/mysql-test/r/connect.result +++ b/mysql-test/r/connect.result @@ -1,23 +1,28 @@ drop table if exists t1,t2; show tables; Tables_in_mysql +column_stats columns_priv db event func general_log +gtid_slave_pos help_category help_keyword help_relation help_topic host +index_stats ndb_binlog_index plugin proc procs_priv proxies_priv +roles_mapping servers slow_log +table_stats tables_priv time_zone time_zone_leap_second @@ -35,23 +40,28 @@ grant ALL on *.* to test@localhost identified by "gambling"; grant ALL on *.* to test@127.0.0.1 identified by "gambling"; show tables; Tables_in_mysql +column_stats columns_priv db event func general_log +gtid_slave_pos help_category help_keyword help_relation help_topic host +index_stats ndb_binlog_index plugin proc procs_priv proxies_priv +roles_mapping servers slow_log +table_stats tables_priv time_zone time_zone_leap_second @@ -77,23 +87,28 @@ ERROR HY000: Password hash should be a 41-digit hexadecimal number set password=old_password('gambling3'); show tables; Tables_in_mysql +column_stats columns_priv db event func general_log +gtid_slave_pos help_category help_keyword help_relation help_topic host +index_stats ndb_binlog_index plugin proc procs_priv proxies_priv +roles_mapping servers slow_log +table_stats tables_priv time_zone time_zone_leap_second @@ -229,9 +244,9 @@ Connection on extra port 2 ok # -- Bug#49752: 2469.126.2 unintentionally breaks authentication # against MySQL 5.1 server # -GRANT ALL ON test.* TO 'Azundris12345678'@'localhost' IDENTIFIED BY 'test123'; +GRANT ALL ON test.* TO 'O1234567890123456789012345678901234567890123456789012345678901234567890123456789'@'localhost' IDENTIFIED BY 'test123'; FLUSH PRIVILEGES; -DROP USER 'Azundris12345678'@'localhost'; +DROP USER 'O1234567890123456789012345678901234567890123456789012345678901234567890123456789'@'localhost'; FLUSH PRIVILEGES; # # -- End of Bug#49752 diff --git a/mysql-test/r/create-big.result b/mysql-test/r/create-big.result index 4cce5d8618c..2f351fee365 100644 --- a/mysql-test/r/create-big.result +++ b/mysql-test/r/create-big.result @@ -188,11 +188,14 @@ t2 CREATE TABLE `t2` ( drop table t2; show binlog events from <binlog_start>; Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Query # # use `test`; insert into t1 values (1) master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; create table t2 like t1 +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; DROP TABLE `t1` /* generated by server */ +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; DROP TABLE `t2` /* generated by server */ create table t1 (i int); set debug_sync='create_table_like_before_binlog SIGNAL parked WAIT_FOR go'; @@ -216,13 +219,20 @@ drop table t2; set debug_sync='RESET'; show binlog events from <binlog_start>; Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; create table t2 like t1 -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Query # # use `test`; insert into t2 values (1) master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; DROP TABLE `t2` /* generated by server */ +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; create table t2 like t1 +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; DROP TABLE `t2` /* generated by server */ +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; create table t2 like t1 +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; DROP TABLE `t1` /* generated by server */ +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; DROP TABLE `t2` /* generated by server */ diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index 751dd939361..173a3887f4a 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -1,3 +1,4 @@ +call mtr.add_suppression("table or database name 't-1'"); drop table if exists t1,t2,t3,t4,t5; drop database if exists mysqltest; drop view if exists v1; @@ -31,9 +32,9 @@ Warnings: Note 1051 Unknown table 't1' Note 1051 Unknown table 't2' create table t1 (b char(0) not null, index(b)); -ERROR 42000: The used storage engine can't index column 'b' +ERROR 42000: The storage engine MyISAM can't index column `b` create table t1 (a int not null,b text) engine=heap; -ERROR 42000: The used table type doesn't support BLOB/TEXT columns +ERROR 42000: Storage engine MEMORY doesn't support BLOB/TEXT columns drop table if exists t1; Warnings: Note 1051 Unknown table 't1' @@ -55,9 +56,9 @@ ERROR 42000: Incorrect table name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa create table a (`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` int); ERROR 42000: Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long create table t1 (a datetime default now()); -ERROR 42000: Invalid default value for 'a' +drop table t1; create table t1 (a datetime on update now()); -ERROR HY000: Invalid ON UPDATE clause for 'a' column +drop table t1; create table t1 (a int default 100 auto_increment); ERROR 42000: Invalid default value for 'a' create table t1 (a tinyint default 1000); @@ -1762,7 +1763,10 @@ t1 CREATE TABLE `t1` ( `TIME_MS` decimal(22,3) NOT NULL DEFAULT '0.000', `STAGE` tinyint(2) NOT NULL DEFAULT '0', `MAX_STAGE` tinyint(2) NOT NULL DEFAULT '0', - `PROGRESS` decimal(7,3) NOT NULL DEFAULT '0.000' + `PROGRESS` decimal(7,3) NOT NULL DEFAULT '0.000', + `MEMORY_USED` int(7) NOT NULL DEFAULT '0', + `EXAMINED_ROWS` int(7) NOT NULL DEFAULT '0', + `QUERY_ID` bigint(4) NOT NULL DEFAULT '0' ) DEFAULT CHARSET=utf8 drop table t1; create temporary table t1 like information_schema.processlist; @@ -1780,7 +1784,10 @@ t1 CREATE TEMPORARY TABLE `t1` ( `TIME_MS` decimal(22,3) NOT NULL DEFAULT '0.000', `STAGE` tinyint(2) NOT NULL DEFAULT '0', `MAX_STAGE` tinyint(2) NOT NULL DEFAULT '0', - `PROGRESS` decimal(7,3) NOT NULL DEFAULT '0.000' + `PROGRESS` decimal(7,3) NOT NULL DEFAULT '0.000', + `MEMORY_USED` int(7) NOT NULL DEFAULT '0', + `EXAMINED_ROWS` int(7) NOT NULL DEFAULT '0', + `QUERY_ID` bigint(4) NOT NULL DEFAULT '0' ) DEFAULT CHARSET=utf8 drop table t1; create table t1 like information_schema.character_sets; @@ -1895,25 +1902,36 @@ create table t3 (a int) row_format=page; drop table t1,t2,t3; # -- End of Bug#45829 -# new table creation/renaming blocked if old encoded table present -create table `t-1` (a int) engine=myisam; -insert into `t-1` values (1); +create table `#mysql50#t-1` (a int) engine=myisam; +insert into `#mysql50#t-1` values (1); show tables; Tables_in_test -t-1 -flush tables; -convert table files in mysql 5.0 file name encoding +#mysql50#t-1 +create table `t-1` (a int); show tables; Tables_in_test #mysql50#t-1 -create table `t-1` (a int); -ERROR 42S01: Table '#mysql50#t-1' already exists +t-1 +select * from `t-1`; +a +select * from `#mysql50#t-1`; +a +1 +drop table `t-1`; create table t1 (a int); alter table t1 rename `t-1`; -ERROR 42S01: Table '#mysql50#t-1' already exists +show tables; +Tables_in_test +#mysql50#t-1 +t-1 +drop table `t-1`; +create table t1 (a int); rename table t1 to `t-1`; -ERROR 42S01: Table '#mysql50#t-1' already exists -drop table `#mysql50#t-1`, t1; +show tables; +Tables_in_test +#mysql50#t-1 +t-1 +drop table `#mysql50#t-1`, `t-1`; End of 5.1 tests diff --git a/mysql-test/r/ctype_cp932_binlog_row.result b/mysql-test/r/ctype_cp932_binlog_row.result index cbac6b14669..2724f2bbde8 100644 --- a/mysql-test/r/ctype_cp932_binlog_row.result +++ b/mysql-test/r/ctype_cp932_binlog_row.result @@ -8,8 +8,9 @@ SET @var1= x'8300'; EXECUTE stmt1 USING @var1; show binlog events from <binlog_start>; Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; CREATE TABLE t1(f1 blob) -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Query # # COMMIT diff --git a/mysql-test/r/ctype_cp932_binlog_stm.result b/mysql-test/r/ctype_cp932_binlog_stm.result index deca926a69c..d5abf8d482c 100644 --- a/mysql-test/r/ctype_cp932_binlog_stm.result +++ b/mysql-test/r/ctype_cp932_binlog_stm.result @@ -8,8 +8,9 @@ SET @var1= x'8300'; EXECUTE stmt1 USING @var1; show binlog events from <binlog_start>; Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; CREATE TABLE t1(f1 blob) -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES(X'8300') master-bin.000001 # Query # # COMMIT SELECT HEX(f1) FROM t1; @@ -34,19 +35,23 @@ DROP PROCEDURE bug18293| DROP TABLE t4| show binlog events from <binlog_start>| Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; CREATE TABLE t4 (s1 CHAR(50) CHARACTER SET latin1, s2 CHAR(50) CHARACTER SET cp932, d DECIMAL(10,2)) +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; CREATE DEFINER=`root`@`localhost` PROCEDURE `bug18293`(IN ins1 CHAR(50), IN ins2 CHAR(50) CHARACTER SET cp932, IN ind DECIMAL(10,2)) BEGIN INSERT INTO t4 VALUES (ins1, ins2, ind); END -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Query # # use `test`; INSERT INTO t4 VALUES ( NAME_CONST('ins1',_latin1 X'466F6F2773206120426172' COLLATE 'latin1_swedish_ci'), NAME_CONST('ins2',_cp932 X'ED40ED41ED42' COLLATE 'cp932_japanese_ci'), NAME_CONST('ind',47.93)) master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; DROP PROCEDURE bug18293 +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; DROP TABLE `t4` /* generated by server */ End of 5.0 tests call mtr.add_suppression("Error in Log_event::read_log_event\\\(\\\): 'Found invalid"); @@ -19512,16 +19517,18 @@ DROP PREPARE stmt; DROP TABLE t1; show binlog events from <binlog_start>; Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INT) -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (0x31) master-bin.000001 # Query # # COMMIT -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES (X'31') master-bin.000001 # Query # # COMMIT -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Query # # use `test`; INSERT INTO t1 (a) VALUES (X'31') master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; DROP TABLE `t1` /* generated by server */ # # End of 5.5 tests diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 802006c4c66..d1f94ac77fc 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -316,26 +316,26 @@ NULL drop table t1; set names utf8; set names utf8; -select 'ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'ваÑÑ' rlike '\\bваÑÑ\\b'; +'ваÑÑ' rlike '\\bваÑÑ\\b' 1 -select 'ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'ваÑÑ ' rlike '\\bваÑÑ\\b'; +'ваÑÑ ' rlike '\\bваÑÑ\\b' 1 -select ' ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -' ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select ' ваÑÑ' rlike '\\bваÑÑ\\b'; +' ваÑÑ' rlike '\\bваÑÑ\\b' 1 -select ' ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -' ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select ' ваÑÑ ' rlike '\\bваÑÑ\\b'; +' ваÑÑ ' rlike '\\bваÑÑ\\b' 1 -select 'ваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'ваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'ваÑÑz' rlike '\\bваÑÑ\\b'; +'ваÑÑz' rlike '\\bваÑÑ\\b' 0 -select 'zваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'zваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'zваÑÑ' rlike '\\bваÑÑ\\b'; +'zваÑÑ' rlike '\\bваÑÑ\\b' 0 -select 'zваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'zваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'zваÑÑz' rlike '\\bваÑÑ\\b'; +'zваÑÑz' rlike '\\bваÑÑ\\b' 0 CREATE TABLE t1 (a enum ('Y', 'N') DEFAULT 'N' COLLATE utf8_unicode_ci); ALTER TABLE t1 ADD COLUMN b CHAR(20); diff --git a/mysql-test/r/ctype_utf8mb4.result b/mysql-test/r/ctype_utf8mb4.result index f1da956c0cb..2935da39387 100644 --- a/mysql-test/r/ctype_utf8mb4.result +++ b/mysql-test/r/ctype_utf8mb4.result @@ -316,26 +316,26 @@ NULL drop table t1; set names utf8mb4; set names utf8mb4; -select 'ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'ваÑÑ' rlike '\\bваÑÑ\\b'; +'ваÑÑ' rlike '\\bваÑÑ\\b' 1 -select 'ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'ваÑÑ ' rlike '\\bваÑÑ\\b'; +'ваÑÑ ' rlike '\\bваÑÑ\\b' 1 -select ' ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -' ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select ' ваÑÑ' rlike '\\bваÑÑ\\b'; +' ваÑÑ' rlike '\\bваÑÑ\\b' 1 -select ' ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -' ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select ' ваÑÑ ' rlike '\\bваÑÑ\\b'; +' ваÑÑ ' rlike '\\bваÑÑ\\b' 1 -select 'ваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'ваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'ваÑÑz' rlike '\\bваÑÑ\\b'; +'ваÑÑz' rlike '\\bваÑÑ\\b' 0 -select 'zваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'zваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'zваÑÑ' rlike '\\bваÑÑ\\b'; +'zваÑÑ' rlike '\\bваÑÑ\\b' 0 -select 'zваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'zваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'zваÑÑz' rlike '\\bваÑÑ\\b'; +'zваÑÑz' rlike '\\bваÑÑ\\b' 0 CREATE TABLE t1 (a enum ('Y', 'N') DEFAULT 'N' COLLATE utf8mb4_unicode_ci); ALTER TABLE t1 ADD COLUMN b CHAR(20); diff --git a/mysql-test/r/ctype_utf8mb4_heap.result b/mysql-test/r/ctype_utf8mb4_heap.result index 5959205ad1e..0a2b92041f9 100644 --- a/mysql-test/r/ctype_utf8mb4_heap.result +++ b/mysql-test/r/ctype_utf8mb4_heap.result @@ -306,26 +306,26 @@ NULL drop table t1; set names utf8mb4; set names utf8mb4; -select 'ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'ваÑÑ' rlike '\\bваÑÑ\\b'; +'ваÑÑ' rlike '\\bваÑÑ\\b' 1 -select 'ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'ваÑÑ ' rlike '\\bваÑÑ\\b'; +'ваÑÑ ' rlike '\\bваÑÑ\\b' 1 -select ' ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -' ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select ' ваÑÑ' rlike '\\bваÑÑ\\b'; +' ваÑÑ' rlike '\\bваÑÑ\\b' 1 -select ' ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -' ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select ' ваÑÑ ' rlike '\\bваÑÑ\\b'; +' ваÑÑ ' rlike '\\bваÑÑ\\b' 1 -select 'ваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'ваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'ваÑÑz' rlike '\\bваÑÑ\\b'; +'ваÑÑz' rlike '\\bваÑÑ\\b' 0 -select 'zваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'zваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'zваÑÑ' rlike '\\bваÑÑ\\b'; +'zваÑÑ' rlike '\\bваÑÑ\\b' 0 -select 'zваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'zваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'zваÑÑz' rlike '\\bваÑÑ\\b'; +'zваÑÑz' rlike '\\bваÑÑ\\b' 0 CREATE TABLE t1 (a enum ('Y', 'N') DEFAULT 'N' COLLATE utf8mb4_unicode_ci) ENGINE heap; ALTER TABLE t1 ADD COLUMN b CHAR(20); diff --git a/mysql-test/r/ctype_utf8mb4_innodb.result b/mysql-test/r/ctype_utf8mb4_innodb.result index 4dcac1d9d7b..e9ee649f2ba 100644 --- a/mysql-test/r/ctype_utf8mb4_innodb.result +++ b/mysql-test/r/ctype_utf8mb4_innodb.result @@ -316,26 +316,26 @@ NULL drop table t1; set names utf8mb4; set names utf8mb4; -select 'ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'ваÑÑ' rlike '\\bваÑÑ\\b'; +'ваÑÑ' rlike '\\bваÑÑ\\b' 1 -select 'ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'ваÑÑ ' rlike '\\bваÑÑ\\b'; +'ваÑÑ ' rlike '\\bваÑÑ\\b' 1 -select ' ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -' ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select ' ваÑÑ' rlike '\\bваÑÑ\\b'; +' ваÑÑ' rlike '\\bваÑÑ\\b' 1 -select ' ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -' ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select ' ваÑÑ ' rlike '\\bваÑÑ\\b'; +' ваÑÑ ' rlike '\\bваÑÑ\\b' 1 -select 'ваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'ваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'ваÑÑz' rlike '\\bваÑÑ\\b'; +'ваÑÑz' rlike '\\bваÑÑ\\b' 0 -select 'zваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'zваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'zваÑÑ' rlike '\\bваÑÑ\\b'; +'zваÑÑ' rlike '\\bваÑÑ\\b' 0 -select 'zваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'zваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'zваÑÑz' rlike '\\bваÑÑ\\b'; +'zваÑÑz' rlike '\\bваÑÑ\\b' 0 CREATE TABLE t1 (a enum ('Y', 'N') DEFAULT 'N' COLLATE utf8mb4_unicode_ci) ENGINE InnoDB; ALTER TABLE t1 ADD COLUMN b CHAR(20); diff --git a/mysql-test/r/ctype_utf8mb4_myisam.result b/mysql-test/r/ctype_utf8mb4_myisam.result index e07e3472a37..1d12be15aa2 100644 --- a/mysql-test/r/ctype_utf8mb4_myisam.result +++ b/mysql-test/r/ctype_utf8mb4_myisam.result @@ -316,26 +316,26 @@ NULL drop table t1; set names utf8mb4; set names utf8mb4; -select 'ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'ваÑÑ' rlike '\\bваÑÑ\\b'; +'ваÑÑ' rlike '\\bваÑÑ\\b' 1 -select 'ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'ваÑÑ ' rlike '\\bваÑÑ\\b'; +'ваÑÑ ' rlike '\\bваÑÑ\\b' 1 -select ' ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -' ваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select ' ваÑÑ' rlike '\\bваÑÑ\\b'; +' ваÑÑ' rlike '\\bваÑÑ\\b' 1 -select ' ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -' ваÑÑ ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select ' ваÑÑ ' rlike '\\bваÑÑ\\b'; +' ваÑÑ ' rlike '\\bваÑÑ\\b' 1 -select 'ваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'ваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'ваÑÑz' rlike '\\bваÑÑ\\b'; +'ваÑÑz' rlike '\\bваÑÑ\\b' 0 -select 'zваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'zваÑÑ' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'zваÑÑ' rlike '\\bваÑÑ\\b'; +'zваÑÑ' rlike '\\bваÑÑ\\b' 0 -select 'zваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]'; -'zваÑÑz' rlike '[[:<:]]ваÑÑ[[:>:]]' +select 'zваÑÑz' rlike '\\bваÑÑ\\b'; +'zваÑÑz' rlike '\\bваÑÑ\\b' 0 CREATE TABLE t1 (a enum ('Y', 'N') DEFAULT 'N' COLLATE utf8mb4_unicode_ci) ENGINE MyISAM; ALTER TABLE t1 ADD COLUMN b CHAR(20); diff --git a/mysql-test/r/delete_returning.result b/mysql-test/r/delete_returning.result new file mode 100644 index 00000000000..4d8044c1a7a --- /dev/null +++ b/mysql-test/r/delete_returning.result @@ -0,0 +1,267 @@ +drop table if exists t1,t2; +drop view if exists v1; +drop procedure if exists p1; +CREATE TABLE t1 (a int, b varchar(32)); +INSERT INTO t1 VALUES +(7,'ggggggg'), (1,'a'), (3,'ccc'), +(4,'dddd'), (1,'A'), (2,'BB'), (4,'DDDD'), +(5,'EEEEE'), (7,'GGGGGGG'), (2,'bb'); +CREATE TABLE t1c SELECT * FROM t1; +CREATE TABLE t2 (c int); +INSERT INTO t2 VALUES +(4), (5), (7), (1); +CREATE TABLE t2c SELECT * FROM t2; +CREATE VIEW v1 AS SELECT a, UPPER(b) FROM t1; +DELETE FROM t1 WHERE a=2 RETURNING * ; +a b +2 BB +2 bb +SELECT * FROM t1; +a b +7 ggggggg +1 a +3 ccc +4 dddd +1 A +4 DDDD +5 EEEEE +7 GGGGGGG +INSERT INTO t1 VALUES (2,'BB'), (2,'bb'); +DELETE FROM t1 WHERE a=2 RETURNING b; +b +bb +BB +SELECT * FROM t1; +a b +7 ggggggg +1 a +3 ccc +4 dddd +1 A +4 DDDD +5 EEEEE +7 GGGGGGG +DELETE FROM t1 WHERE a=2 RETURNING c; +ERROR 42S22: Unknown column 'c' in 'field list' +INSERT INTO t1 VALUES (2,'BB'), (2,'bb'); +DELETE FROM t1 WHERE a=2 RETURNING a, UPPER(b); +a UPPER(b) +2 BB +2 BB +SELECT * FROM t1; +a b +7 ggggggg +1 a +3 ccc +4 dddd +1 A +4 DDDD +5 EEEEE +7 GGGGGGG +INSERT INTO t1 VALUES (2,'BB'), (2,'bb'); +DELETE FROM t1 WHERE a=6 RETURNING b; +b +SELECT * FROM t1; +a b +7 ggggggg +1 a +3 ccc +4 dddd +1 A +2 bb +4 DDDD +5 EEEEE +7 GGGGGGG +2 BB +DELETE FROM t1 WHERE a=2 RETURNING MAX(b); +ERROR HY000: Invalid use of group function +DELETE FROM t1 WHERE a < 5 RETURNING a, (SELECT MIN(c) FROM t2 WHERE c=a+1); +a (SELECT MIN(c) FROM t2 WHERE c=a+1) +1 NULL +3 4 +4 5 +1 NULL +2 NULL +4 5 +2 NULL +SELECT * FROM t1; +a b +7 ggggggg +5 EEEEE +7 GGGGGGG +DELETE FROM t1; +INSERT INTO t1 SELECT * FROM t1c; +DELETE FROM t2 WHERE c < 5 +RETURNING (SELECT GROUP_CONCAT(b) FROM t1 GROUP BY a HAVING a=c); +(SELECT GROUP_CONCAT(b) FROM t1 GROUP BY a HAVING a=c) +dddd,DDDD +a,A +SELECT * FROM t2; +c +5 +7 +DELETE FROM t2; +INSERT INTO t2 SELECT * FROM t2c; +CREATE FUNCTION f(arg INT) RETURNS TEXT +BEGIN +RETURN (SELECT GROUP_CONCAT(b) FROM t1 WHERE a=arg); +END| +DELETE FROM t2 WHERE c < 5 RETURNING f(c); +f(c) +dddd,DDDD +a,A +SELECT * FROM t2; +c +5 +7 +DELETE FROM t2; +INSERT INTO t2 SELECT * FROM t2c; +DROP FUNCTION f; +DELETE FROM v1 WHERE a < 5 RETURNING * ; +a UPPER(b) +1 A +3 CCC +4 DDDD +1 A +2 BB +4 DDDD +2 BB +SELECT * FROM t1; +a b +7 ggggggg +5 EEEEE +7 GGGGGGG +DELETE FROM t1; +INSERT INTO t1 SELECT * FROM t1c; +CREATE VIEW v11(a,c) AS SELECT a, COUNT(b) FROM t1 GROUP BY a; +DELETE FROM v11 WHERE a < 5 RETURNING * ; +ERROR HY000: The target table v11 of the DELETE is not updatable +DROP VIEW v11; +PREPARE stmt FROM +"DELETE FROM t1 WHERE a=2 ORDER BY b LIMIT 1 RETURNING a, UPPER(b)"; +EXECUTE stmt; +a UPPER(b) +2 BB +SELECT * FROM t1; +a b +7 ggggggg +1 a +3 ccc +4 dddd +1 A +4 DDDD +5 EEEEE +7 GGGGGGG +2 bb +EXECUTE stmt; +a UPPER(b) +2 BB +SELECT * FROM t1; +a b +7 ggggggg +1 a +3 ccc +4 dddd +1 A +4 DDDD +5 EEEEE +7 GGGGGGG +DEALLOCATE PREPARE stmt; +DELETE FROM t1; +INSERT INTO t1 SELECT * FROM t1c; +FLUSH PRIVILEGES; +CREATE DATABASE mysqltest; +CREATE TABLE mysqltest.t1 SELECT * FROM t1; +GRANT DELETE ON mysqltest.* TO mysqltest_1@localhost; +GRANT SELECT(b) ON mysqltest.t1 TO mysqltest_1@localhost; +DELETE FROM mysqltest.t1 WHERE a=2 RETURNING b; +ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for column 'a' in table 't1' +DELETE FROM mysqltest.t1 RETURNING b; +b +ggggggg +a +ccc +dddd +A +BB +DDDD +EEEEE +GGGGGGG +bb +SELECT * FROM mysqltest.t1; +a b +INSERT INTO mysqltest.t1 SELECT * FROM t1; +GRANT SELECT(a) ON mysqltest.t1 TO mysqltest_1@localhost; +DELETE FROM mysqltest.t1 WHERE a=2 RETURNING b; +b +bb +BB +SELECT * FROM mysqltest.t1; +a b +7 GGGGGGG +5 EEEEE +4 DDDD +1 A +4 dddd +3 ccc +1 a +7 ggggggg +INSERT INTO mysqltest.t1 SELECT * FROM t1; +CREATE VIEW mysqltest.v1(a) AS SELECT a FROM mysqltest.t1; +GRANT SELECT, INSERT ON mysqltest.t1 TO mysqltest_1@localhost; +DELETE FROM mysqltest.v1; +SELECT * FROM mysqltest.t1; +a b +INSERT INTO mysqltest.t1 SELECT * FROM t1; +DELETE FROM mysqltest.v1 RETURNING a; +ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for column 'a' in table 'v1' +GRANT SELECT ON mysqltest.* TO mysqltest_1@localhost; +DELETE FROM mysqltest.v1 RETURNING a; +a +7 +1 +3 +4 +1 +2 +4 +5 +7 +2 +SELECT * FROM mysqltest.t1; +a b +INSERT INTO mysqltest.t1 SELECT * FROM t1; +DROP DATABASE mysqltest; +DROP USER mysqltest_1@localhost; +DROP VIEW v1; +DROP TABLE t1,t2; +DROP TABLE t1c,t2c; +# +# Bug mdev-4918: DELETE ... RETURNING subquery with more than 1 row +# +CREATE TABLE t1 (i1 int); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (i2 int); +INSERT INTO t2 VALUES (1),(2); +DELETE FROM t1 ORDER BY i1 RETURNING ( SELECT i2 FROM t2 ); +ERROR 21000: Subquery returns more than 1 row +DROP TABLE t1,t2; +# +# MDEV-4919: Packets out of order on a SELECT after calling a procedure with DELETE .. RETURNING +# +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (1),(2); +CREATE PROCEDURE p1 (a INT) +BEGIN +DELETE FROM t1 WHERE i = a RETURNING *; +INSERT INTO t1 VALUES (a); +END | +CALL p1(1); +i +1 +SELECT * FROM t1; +i +1 +2 +DROP PROCEDURE p1; +DROP TABLE t1; diff --git a/mysql-test/r/derived_opt.result b/mysql-test/r/derived_opt.result index 22e2ab8d676..f5e7393591c 100644 --- a/mysql-test/r/derived_opt.result +++ b/mysql-test/r/derived_opt.result @@ -109,8 +109,8 @@ count(*) 2 explain select count(*) from t1 INNER JOIN (SELECT A.E1, A.E2, A.E3 FROM t1 AS A WHERE A.E3 = (SELECT MAX(B.E3) FROM t1 AS B WHERE A.E2 = B.E2)) AS THEMAX ON t1.E1 = THEMAX.E2 AND t1.E1 = t1.E2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE A ALL NULL NULL NULL NULL 2 Using where -1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.A.E2 1 Using where +1 PRIMARY A ALL NULL NULL NULL NULL 2 Using where +1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.A.E2 1 Using where 3 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 2 Using where drop table t1; create table t1 (a int); diff --git a/mysql-test/r/derived_view.result b/mysql-test/r/derived_view.result index 9a70bffff6f..cbf5900d57c 100644 --- a/mysql-test/r/derived_view.result +++ b/mysql-test/r/derived_view.result @@ -386,7 +386,7 @@ materialized derived in merged derived explain extended select * from (select * from (select * from t1 where f1 < 7 group by f1) tt where f1 > 2) zz; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE <derived3> ALL NULL NULL NULL NULL 11 100.00 Using where +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 11 100.00 Using where 3 DERIVED t1 ALL NULL NULL NULL NULL 11 100.00 Using where; Using temporary; Using filesort Warnings: Note 1003 select `tt`.`f1` AS `f1`,`tt`.`f11` AS `f11` from (select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f11` AS `f11` from `test`.`t1` where (`test`.`t1`.`f1` < 7) group by `test`.`t1`.`f1`) `tt` where (`tt`.`f1` > 2) @@ -429,8 +429,8 @@ join (select * from (select * from t1 where f1 < 7 group by f1) tt where f1 > 2) z on x.f1 = z.f1; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE <derived3> ALL NULL NULL NULL NULL 11 100.00 Using where -1 SIMPLE <derived5> ref key0 key0 5 tt.f1 2 100.00 +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 11 100.00 Using where +1 PRIMARY <derived5> ref key0 key0 5 tt.f1 2 100.00 5 DERIVED t1 ALL NULL NULL NULL NULL 11 100.00 Using where; Using temporary; Using filesort 3 DERIVED t1 ALL NULL NULL NULL NULL 11 100.00 Using where; Using temporary; Using filesort Warnings: @@ -522,7 +522,7 @@ materialized view in merged derived explain extended select * from ( select * from v1 where f1 < 7) tt; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE <derived3> ALL NULL NULL NULL NULL 11 100.00 Using where +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 11 100.00 Using where 3 DERIVED t1 ALL NULL NULL NULL NULL 11 100.00 Using temporary; Using filesort Warnings: Note 1003 select `v1`.`f1` AS `f1`,`v1`.`f11` AS `f11` from `test`.`v1` where (`v1`.`f1` < 7) @@ -568,8 +568,8 @@ f1 f11 join of above two explain extended select * from v6 join v7 on f2=f1; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 11 100.00 Using where -1 SIMPLE <derived5> ref key0 key0 5 test.t2.f2 2 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 11 100.00 Using where +1 PRIMARY <derived5> ref key0 key0 5 test.t2.f2 2 100.00 5 DERIVED t1 ALL NULL NULL NULL NULL 11 100.00 Using temporary; Using filesort Warnings: Note 1003 select `test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f22` AS `f22`,`v1`.`f1` AS `f1`,`v1`.`f11` AS `f11` from `test`.`t2` join `test`.`v1` where ((`v1`.`f1` = `test`.`t2`.`f2`) and (`test`.`t2`.`f2` < 7) and (`test`.`t2`.`f2` in (2,3))) @@ -1220,7 +1220,7 @@ Note 1003 select `test`.`t1`.`b` AS `b` from `test`.`t1` where 0 EXPLAIN EXTENDED SELECT * FROM (SELECT b FROM v2 WHERE b = 0) t WHERE b; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 3 DERIVED t1 ALL NULL NULL NULL NULL 5 100.00 Using temporary; Using filesort Warnings: Note 1003 select `v2`.`b` AS `b` from `test`.`v2` where 0 @@ -1468,14 +1468,14 @@ WHERE (t2.a ,t1.b) NOT IN (SELECT DISTINCT c,a FROM t3 t); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) -2 DEPENDENT SUBQUERY t eq_ref PRIMARY,c PRIMARY 4 func 1 Using where +2 DEPENDENT SUBQUERY t unique_subquery PRIMARY,c PRIMARY 4 func 1 Using where EXPLAIN SELECT * FROM t1 , t2 WHERE (t2.a ,t1.b) NOT IN (SELECT DISTINCT c,a FROM (SELECT * FROM t3) t); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) -2 DEPENDENT SUBQUERY t3 eq_ref PRIMARY,c PRIMARY 4 func 1 Using where +2 DEPENDENT SUBQUERY t3 unique_subquery PRIMARY,c PRIMARY 4 func 1 Using where SELECT * FROM t1 , t2 WHERE (t2.a ,t1.b) NOT IN (SELECT DISTINCT c,a FROM (SELECT * FROM t3) t); b a @@ -2360,8 +2360,8 @@ ON p.id = g.p_random ORDER BY gallery_name ASC ; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE <derived2> ALL NULL NULL NULL NULL 2 Using filesort -1 SIMPLE p eq_ref PRIMARY PRIMARY 4 g.p_random 1 Using where +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 Using filesort +1 PRIMARY p eq_ref PRIMARY PRIMARY 4 g.p_random 1 Using where 2 DERIVED gal ALL NULL NULL NULL NULL 10 3 DEPENDENT SUBQUERY pi ref gallery_id gallery_id 4 test.gal.id 4 Using temporary; Using filesort drop table galleries, pictures; diff --git a/mysql-test/r/distinct.result b/mysql-test/r/distinct.result index 1ba078c1c1c..019099bde14 100644 --- a/mysql-test/r/distinct.result +++ b/mysql-test/r/distinct.result @@ -756,7 +756,7 @@ INSERT INTO t1(a, b, c) VALUES (1, 1, 1), (1, 2, 3); EXPLAIN SELECT DISTINCT a, b, d, c FROM t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL PRIMARY 16 NULL 7 Using index for group-by; Using temporary +1 SIMPLE t1 range NULL a 16 NULL 7 Using index for group-by SELECT DISTINCT a, b, d, c FROM t1; a b d c 1 1 0 1 diff --git a/mysql-test/r/drop.result b/mysql-test/r/drop.result index db3aa770499..e1adfe95d8b 100644 --- a/mysql-test/r/drop.result +++ b/mysql-test/r/drop.result @@ -1,3 +1,4 @@ +call mtr.add_suppression("table or database name 'abc`def'"); drop table if exists t1; drop database if exists mysqltest; drop database if exists client_test_db; @@ -142,9 +143,9 @@ create table `#mysql50#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ERROR 42000: Incorrect table name '#mysql50#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa12345' show tables; Tables_in_mysqltestbug26703 +#mysql50#abc`def aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1234 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -#mysql50#abc`def use test; drop database mysqltestbug26703; End of 5.1 tests diff --git a/mysql-test/r/dyncol.result b/mysql-test/r/dyncol.result index 5e53c365dad..2b936af8dec 100644 --- a/mysql-test/r/dyncol.result +++ b/mysql-test/r/dyncol.result @@ -1088,7 +1088,7 @@ column_list(column_add(column_create(1, 1), 1, null)) select column_list(column_add(column_create(1, 1), 1, "")); column_list(column_add(column_create(1, 1), 1, "")) -1 +`1` select hex(column_add("", 1, 1)); hex(column_add("", 1, 1)) 00010001000002 @@ -1133,10 +1133,10 @@ column_exists(column_create(1, 1212 as integer, 2, 1212 as integer), 4) # column list select column_list(column_create(1, 1212 as integer, 2, 1212 as integer)); column_list(column_create(1, 1212 as integer, 2, 1212 as integer)) -1,2 +`1`,`2` select column_list(column_create(1, 1212 as integer)); column_list(column_create(1, 1212 as integer)) -1 +`1` select column_list(column_create(1, NULL as integer)); column_list(column_create(1, NULL as integer)) @@ -1218,35 +1218,35 @@ sum(column_get(str, 1 as int)) 11 select id, column_list(str) from t1 where id= 5; id column_list(str) -5 1,2,3,10 +5 `1`,`2`,`3`,`10` update t1 set str=column_delete(str, 3, 4, 2) where id= 5; select id, length(str), column_list(str), column_get(str, 1 as int), column_get(str, 2 as char), column_get(str, 3 as int) from t1; id length(str) column_list(str) column_get(str, 1 as int) column_get(str, 2 as char) column_get(str, 3 as int) -1 12 1,2 1 a NULL -2 12 1,2 2 a NULL -3 12 2,3 NULL c 100 -4 16 1,2,3 5 c 100 -5 15 1,10 6 NULL NULL -6 21 2,3,10 NULL c 100 +1 12 `1`,`2` 1 a NULL +2 12 `1`,`2` 2 a NULL +3 12 `2`,`3` NULL c 100 +4 16 `1`,`2`,`3` 5 c 100 +5 15 `1`,`10` 6 NULL NULL +6 21 `2`,`3`,`10` NULL c 100 update t1 set str=column_add(str, 4, 45 as char, 2, 'c') where id= 5; select id, length(str), column_list(str), column_get(str, 1 as int), column_get(str, 2 as char), column_get(str, 3 as int) from t1 where id = 5; id length(str) column_list(str) column_get(str, 1 as int) column_get(str, 2 as char) column_get(str, 3 as int) -5 26 1,2,4,10 6 c NULL +5 26 `1`,`2`,`4`,`10` 6 c NULL select id, length(str), column_list(str), column_exists(str, 4) from t1; id length(str) column_list(str) column_exists(str, 4) -1 12 1,2 0 -2 12 1,2 0 -3 12 2,3 0 -4 16 1,2,3 0 -5 26 1,2,4,10 1 -6 21 2,3,10 0 +1 12 `1`,`2` 0 +2 12 `1`,`2` 0 +3 12 `2`,`3` 0 +4 16 `1`,`2`,`3` 0 +5 26 `1`,`2`,`4`,`10` 1 +6 21 `2`,`3`,`10` 0 select sum(column_get(str, 1 as int)), column_list(str) from t1 group by 2; sum(column_get(str, 1 as int)) column_list(str) -3 1,2 -5 1,2,3 -6 1,2,4,10 -NULL 2,3 -NULL 2,3,10 +3 `1`,`2` +5 `1`,`2`,`3` +6 `1`,`2`,`4`,`10` +NULL `2`,`3` +NULL `2`,`3`,`10` select id, hex(str) from t1; id hex(str) 1 00020001000002000B020861 @@ -1282,11 +1282,11 @@ id 5 select id, column_list(str), length(str) from t1 where id=5; id column_list(str) length(str) -5 1,2,4,5,10 100048 +5 `1`,`2`,`4`,`5`,`10` 100048 update t1 set str=column_delete(str, 5) where id=5; select id, column_list(str), length(str) from t1 where id=5; id column_list(str) length(str) -5 1,2,4,10 34 +5 `1`,`2`,`4`,`10` 34 drop table t1; # # LP#778905: Assertion `value->year <= 9999' failed in @@ -1306,7 +1306,7 @@ INSERT INTO t1 SET f1 = COLUMN_CREATE( 2 , 'cde' ); SELECT HEX(COLUMN_ADD(f1, 1, 'abc')), COLUMN_LIST(f1) FROM t1; HEX(COLUMN_ADD(f1, 1, 'abc')) COLUMN_LIST(f1) NULL NULL -0002000100030200230861626308636465 2 +0002000100030200230861626308636465 `2` SELECT COLUMN_ADD(f1, 1, 'abc'), COLUMN_LIST(f1) FROM t1; DROP TABLE t1; # @@ -1413,6 +1413,13 @@ Warnings: Warning 1265 Data truncated for column 'dyn' at row 1 SELECT COLUMN_ADD( dyn, 6, REPEAT('x',80), 4, REPEAT('y',215) AS INTEGER ) FROM t1; ERROR HY000: Encountered illegal format of dynamic column string +delete from t1; +#above test with 10.0 format +INSERT INTO t1 SET dyn = COLUMN_CREATE( 'a', REPEAT('a', 250), 'b', REPEAT('b', 322) ); +Warnings: +Warning 1265 Data truncated for column 'dyn' at row 1 +SELECT COLUMN_ADD( dyn, 'c', REPEAT('x',80), 'b', REPEAT('y',215) AS INTEGER ) FROM t1; +ERROR HY000: Encountered illegal format of dynamic column string DROP table t1; # # MDEV-4812: Valgrind warnings (Invalid write) in @@ -1423,6 +1430,11 @@ INSERT INTO t1 SET dyncol = COLUMN_CREATE( 7, REPEAT('k',487), 209, REPEAT('x',4 Warnings: Warning 1265 Data truncated for column 'dyncol' at row 1 SELECT COLUMN_ADD( dyncol, 7, '22:22:22', 8, REPEAT('x',270) AS CHAR ) FROM t1; +delete from t1; +INSERT INTO t1 SET dyncol = COLUMN_CREATE( 'a', REPEAT('k',487), 'b', REPEAT('x',464) ); +Warnings: +Warning 1265 Data truncated for column 'dyncol' at row 1 +SELECT COLUMN_ADD( dyncol, 'a', '22:22:22', 'c', REPEAT('x',270) AS CHAR ) FROM t1; DROP table t1; # # end of 5.3 tests @@ -1433,3 +1445,315 @@ column_get(column_create(1, "18446744073709552001" as char), 1 as int) Warnings: Warning 1918 Encountered illegal value '18446744073709552001' when converting to INT Note 1105 Cast to signed converted positive out-of-range integer to it's negative complement +# +# test of symbolic names +# +# creation test (names) +set names utf8; +select hex(column_create("адын", 1212)); +hex(column_create("адын", 1212)) +040100080000000000D0B0D0B4D18BD0BD7809 +select hex(column_create("1212", 1212)); +hex(column_create("1212", 1212)) +040100040000000000313231327809 +select hex(column_create(1212, 2, "www", 3)); +hex(column_create(1212, 2, "www", 3)) +04020007000000000003001000777777313231320604 +select hex(column_create("1212", 2, "www", 3)); +hex(column_create("1212", 2, "www", 3)) +04020007000000000003001000777777313231320604 +select hex(column_create("1212", 2, 3, 3)); +hex(column_create("1212", 2, 3, 3)) +0402000500000000000100100033313231320604 +select hex(column_create("1212", 2, "адын", 1, 3, 3)); +hex(column_create("1212", 2, "адын", 1, 3, 3)) +0403000D000000000001001000050020003331323132D0B0D0B4D18BD0BD060402 +set names default; +# fetching column test (names) +set names utf8; +select column_get(column_create("адын", 1212), "адын" as int); +column_get(column_create("адын", 1212), "адын" as int) +1212 +select column_get(column_create("1212", 2, "адын", 1, 3, 3), "адын" as int); +column_get(column_create("1212", 2, "адын", 1, 3, 3), "адын" as int) +1 +select column_get(column_create("1212", 2, "адын", 1, 3, 3), 1212 as int); +column_get(column_create("1212", 2, "адын", 1, 3, 3), 1212 as int) +2 +select column_get(column_create("1212", 2, "адын", 1, 3, 3), "3" as int); +column_get(column_create("1212", 2, "адын", 1, 3, 3), "3" as int) +3 +select column_get(column_create("1212", 2, "адын", 1, 3, 3), 3 as int); +column_get(column_create("1212", 2, "адын", 1, 3, 3), 3 as int) +3 +select column_get(column_create("1212", 2, "адын", 1, 3, 3), 4 as int); +column_get(column_create("1212", 2, "адын", 1, 3, 3), 4 as int) +NULL +select column_get(column_create("1212", 2, "адын", 1, 3, 3), "4" as int); +column_get(column_create("1212", 2, "адын", 1, 3, 3), "4" as int) +NULL +set names default; +# column existance test (names) +set names utf8; +select column_exists(column_create("адын", 1212), "адын"); +column_exists(column_create("адын", 1212), "адын") +1 +select column_exists(column_create("адын", 1212), "aады"); +column_exists(column_create("адын", 1212), "aады") +0 +select column_exists(column_create("1212", 2, "адын", 1, 3, 3), "адын"); +column_exists(column_create("1212", 2, "адын", 1, 3, 3), "адын") +1 +select column_exists(column_create("1212", 2, "адын", 1, 3, 3), 1212); +column_exists(column_create("1212", 2, "адын", 1, 3, 3), 1212) +1 +select column_exists(column_create("1212", 2, "адын", 1, 3, 3), "3"); +column_exists(column_create("1212", 2, "адын", 1, 3, 3), "3") +1 +select column_exists(column_create("1212", 2, "адын", 1, 3, 3), 3); +column_exists(column_create("1212", 2, "адын", 1, 3, 3), 3) +1 +select column_exists(column_create("1212", 2, "адын", 1, 3, 3), 4); +column_exists(column_create("1212", 2, "адын", 1, 3, 3), 4) +0 +select column_exists(column_create("1212", 2, "адын", 1, 3, 3), "4"); +column_exists(column_create("1212", 2, "адын", 1, 3, 3), "4") +0 +set names default; +# column changing test (names) +select hex(column_add(column_create(1, "AAA"), "b", "BBB")); +hex(column_add(column_create(1, "AAA"), "b", "BBB")) +0402000200000003000100430031620841414108424242 +select hex(column_add(column_create("1", "AAA"), "b", "BBB")); +hex(column_add(column_create("1", "AAA"), "b", "BBB")) +0402000200000003000100430031620841414108424242 +select column_get(column_add(column_create(1, "AAA"), "b", "BBB"), 1 as char); +column_get(column_add(column_create(1, "AAA"), "b", "BBB"), 1 as char) +AAA +select column_get(column_add(column_create(1, "AAA"), "b", "BBB"), "b" as char); +column_get(column_add(column_create(1, "AAA"), "b", "BBB"), "b" as char) +BBB +select hex(column_add(column_create("a", "AAA"), 1, "BBB")); +hex(column_add(column_create("a", "AAA"), 1, "BBB")) +0402000200000003000100430031610842424208414141 +select hex(column_add(column_create("a", "AAA"), "1", "BBB")); +hex(column_add(column_create("a", "AAA"), "1", "BBB")) +0402000200000003000100430031610842424208414141 +select hex(column_add(column_create("a", 1212 as integer), "b", "1212" as integer)); +hex(column_add(column_create("a", 1212 as integer), "b", "1212" as integer)) +04020002000000000001002000616278097809 +select hex(column_add(column_create("a", 1212 as integer), "a", "1212" as integer)); +hex(column_add(column_create("a", 1212 as integer), "a", "1212" as integer)) +040100010000000000617809 +select hex(column_add(column_create("a", 1212 as integer), "a", NULL as integer)); +hex(column_add(column_create("a", 1212 as integer), "a", NULL as integer)) +0400000000 +select hex(column_add(column_create("a", 1212 as integer), "b", NULL as integer)); +hex(column_add(column_create("a", 1212 as integer), "b", NULL as integer)) +040100010000000000617809 +select hex(column_add(column_create("a", 1212 as integer), "b", 1212 as integer, "a", 11 as integer)); +hex(column_add(column_create("a", 1212 as integer), "b", 1212 as integer, "a", 11 as integer)) +040200020000000000010010006162167809 +select column_get(column_add(column_create("a", 1212 as integer), "b", 1212 as integer, "a", 11 as integer), "a" as integer); +column_get(column_add(column_create("a", 1212 as integer), "b", 1212 as integer, "a", 11 as integer), "a" as integer) +11 +select column_get(column_add(column_create("a", 1212 as integer), "b", 1212 as integer, "a", 11 as integer), "b" as integer); +column_get(column_add(column_create("a", 1212 as integer), "b", 1212 as integer, "a", 11 as integer), "b" as integer) +1212 +select hex(column_add(column_create("a", 1212 as integer), "a", 1212 as integer, "b", 11 as integer)); +hex(column_add(column_create("a", 1212 as integer), "a", 1212 as integer, "b", 11 as integer)) +040200020000000000010020006162780916 +select hex(column_add(column_create("a", NULL as integer), "a", 1212 as integer, "b", 11 as integer)); +hex(column_add(column_create("a", NULL as integer), "a", 1212 as integer, "b", 11 as integer)) +040200020000000000010020006162780916 +select hex(column_add(column_create("a", 1212 as integer, "b", 1212 as integer), "a", 11 as integer)); +hex(column_add(column_create("a", 1212 as integer, "b", 1212 as integer), "a", 11 as integer)) +040200020000000000010010006162167809 +select hex(column_add(column_create("a", 1), "a", null)); +hex(column_add(column_create("a", 1), "a", null)) +0400000000 +select column_list(column_add(column_create("a", 1), "a", null)); +column_list(column_add(column_create("a", 1), "a", null)) + +select column_list(column_add(column_create("a", 1), "a", "")); +column_list(column_add(column_create("a", 1), "a", "")) +`a` +select hex(column_add("", "a", 1)); +hex(column_add("", "a", 1)) +0401000100000000006102 +# column delete (names) +select hex(column_delete(column_create("a", 1212 as integer, "b", 1212 as integer), "a")); +hex(column_delete(column_create("a", 1212 as integer, "b", 1212 as integer), "a")) +040100010000000000627809 +select hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "b")); +hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "b")) +0402000200000000000100100061630206 +select hex(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer)); +hex(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer)) +0403000300000000000100100002002000616263020406 +select hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "c")); +hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "c")) +0402000200000000000100100061620204 +select hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "d")); +hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "d")) +0403000300000000000100100002002000616263020406 +select hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "b", "a")); +hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "b", "a")) +0401000100000000006306 +select hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "b", "c")); +hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "b", "c")) +0401000100000000006102 +select hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "a", "b", "c")); +hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "a", "b", "c")) +0400000000 +select hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "a", "b", "c", "e")); +hex(column_delete(column_create("a", 1 as integer, "b", 2 as integer, "c", 3 as integer), "a", "b", "c", "e")) +0400000000 +select hex(column_delete(column_create("a", 1), "a")); +hex(column_delete(column_create("a", 1), "a")) +0400000000 +select hex(column_delete("", "a")); +hex(column_delete("", "a")) + +# +# MDEV-458 DNAMES: Server crashes on using an unquoted string +# as a dynamic column name +# +select COLUMN_CREATE(color, "black"); +ERROR 42S22: Unknown column 'color' in 'field list' +# +# MDEV-489 Assertion `offset < 0x1f' failed in +# type_and_offset_store on COLUMN_ADD +# +CREATE TABLE t1 (f1 tinyblob); +INSERT INTO t1 VALUES (COLUMN_CREATE('col1', REPEAT('a',30))); +select column_check(f1) from t1; +column_check(f1) +1 +UPDATE t1 SET f1 = COLUMN_ADD( f1, REPEAT('b',211), 'val2' ); +Warnings: +Warning 1265 Data truncated for column 'f1' at row 1 +select column_check(f1) from t1; +column_check(f1) +0 +UPDATE t1 SET f1 = COLUMN_ADD( f1, REPEAT('c',211), 'val3' ); +Warnings: +Warning 1265 Data truncated for column 'f1' at row 1 +select column_check(f1) from t1; +column_check(f1) +0 +drop table t1; +# +# MDEV-490/MDEV-491 null as arguments +# +SELECT COLUMN_GET( COLUMN_CREATE( 'col', 'val' ), NULL AS CHAR ); +COLUMN_GET( COLUMN_CREATE( 'col', 'val' ), NULL AS CHAR ) +NULL +SELECT COLUMN_GET( NULL, 'col' as char ); +COLUMN_GET( NULL, 'col' as char ) +NULL +SELECT COLUMN_EXISTS( COLUMN_CREATE( 'col', 'val' ), NULL); +COLUMN_EXISTS( COLUMN_CREATE( 'col', 'val' ), NULL) +NULL +SELECT COLUMN_EXISTS( NULL, 'col'); +COLUMN_EXISTS( NULL, 'col') +NULL +SELECT COLUMN_CREATE( NULL, 'val' ); +COLUMN_CREATE( NULL, 'val' ) +NULL +SELECT COLUMN_ADD( NULL, 'val', 'col'); +COLUMN_ADD( NULL, 'val', 'col') +NULL +# +# MDEV-488: Assertion `column_name->length < 255' failed on a +# column name with length 255 (precisely) +# +SELECT hex(COLUMN_CREATE(REPEAT('a',255),1)); +hex(COLUMN_CREATE(REPEAT('a',255),1)) +040100FF000000000061616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616102 +SELECT hex(COLUMN_CREATE(REPEAT('a',65536),1)); +ERROR 22007: Illegal value used as argument of dynamic column function +# +# JSON conversion +# +select column_json(column_create("int", -1212 as int, "uint", 12334 as unsigned int, "decimal", "23.344" as decimal, "double", 1.23444e50 as double, "string", 'gdgd\\dhdjh"dhdhd' as char, "time", "0:45:49.000001" AS time, "datetime", "2011-04-05 0:45:49.000001" AS datetime, "date", "2011-04-05" AS date)); +column_json(column_create("int", -1212 as int, "uint", 12334 as unsigned int, "decimal", "23.344" as decimal, "double", 1.23444e50 as double, "string", 'gdgd\\dhdjh"dhdhd' as char, "time", "0:45:49.000001" AS time, "datetime", "2011-04-05 0:45:49.000001" +{"int":-1212,"date":"2011-04-05","time":"00:45:49.000001","uint":12334,"double":"1.2e50","string":"gdgd\\dhdjh\"dhdhd","decimal":23.344,"datetime":"2011-04-05 00:45:49.000001"} +select column_json(column_create(1, -1212 as int, 2, 12334 as unsigned int, 3, "23.344" as decimal, 4, 1.23444e50 as double, 5, 'gdgd\\dhdjh"dhdhd' as char, 6, "0:45:49.000001" AS time, 7, "2011-04-05 0:45:49.000001" AS datetime, 8, "2011-04-05" AS date)); +column_json(column_create(1, -1212 as int, 2, 12334 as unsigned int, 3, "23.344" as decimal, 4, 1.23444e50 as double, 5, 'gdgd\\dhdjh"dhdhd' as char, 6, "0:45:49.000001" AS time, 7, "2011-04-05 0:45:49.000001" AS datetime, 8, "2011-04-05" AS date)) +{"1":-1212,"2":12334,"3":23.344,"4":"1.2e50","5":"gdgd\\dhdjh\"dhdhd","6":"00:45:49.000001","7":"2011-04-05 00:45:49.000001","8":"2011-04-05"} +# +# CHECK test +# +SELECT COLUMN_CHECK(COLUMN_CREATE(1,'a')); +COLUMN_CHECK(COLUMN_CREATE(1,'a')) +1 +SELECT COLUMN_CHECK('abracadabra'); +COLUMN_CHECK('abracadabra') +0 +SELECT COLUMN_CHECK(''); +COLUMN_CHECK('') +1 +SELECT COLUMN_CHECK(NULL); +COLUMN_CHECK(NULL) +NULL +# +# escaping check +# +select column_json(column_create("string", "'\"/\\`.,whatever")),hex(column_create("string", "'\"/\\`.,whatever")); +column_json(column_create("string", "'\"/\\`.,whatever")) hex(column_create("string", "'\"/\\`.,whatever")) +{"string":"'\"/\\`.,whatever"} 040100060000000300737472696E670827222F5C602E2C7768617465766572 +# +# embedding test +# +select column_json(column_create("val", "val", "emb", column_create("val2", "val2"))); +column_json(column_create("val", "val", "emb", column_create("val2", "val2"))) +{"emb":{"val2":"val2"},"val":"val"} +select column_json(column_create(1, "val", 2, column_create(3, "val2"))); +column_json(column_create(1, "val", 2, column_create(3, "val2"))) +{"1":"val","2":{"3":"val2"}} +# +# Time encoding +# +select hex(column_create("t", "800:46:06.23434" AS time)) as hex, +column_json(column_create("t", "800:46:06.23434" AS time)) as json; +hex json +04010001000000070074649363B82003 {"t":"800:46:06.234340"} +select hex(column_create(1, "800:46:06.23434" AS time)) as hex, +column_json(column_create(1, "800:46:06.23434" AS time)) as json; +hex json +000100010007649363B82003 {"1":"800:46:06.234340"} +select hex(column_create("t", "800:46:06" AS time)) as hex, +column_json(column_create("t", "800:46:06" AS time)) as json; +hex json +04010001000000070074860B32 {"t":"800:46:06"} +select hex(column_create(1, "800:46:06" AS time)) as hex, +column_json(column_create(1, "800:46:06" AS time)) as json; +hex json +000100010007000060B82003 {"1":"800:46:06"} +select hex(column_create("t", "2012-12-21 10:46:06.23434" AS datetime)) as hex, +column_json(column_create("t", "2012-12-21 10:46:06.23434" AS datetime)) as json; +hex json +0401000100000005007495B90F649363B80A00 {"t":"2012-12-21 10:46:06.234340"} +select hex(column_create(1, "2012-12-21 10:46:06.23434" AS datetime)) as hex, +column_json(column_create(1, "2012-12-21 10:46:06.23434" AS datetime)) as json; +hex json +00010001000595B90F649363B80A00 {"1":"2012-12-21 10:46:06.234340"} +select hex(column_create("t", "2012-12-21 10:46:06" AS datetime)) as hex, +column_json(column_create("t", "2012-12-21 10:46:06" AS datetime)) as json; +hex json +0401000100000005007495B90F86AB00 {"t":"2012-12-21 10:46:06"} +select hex(column_create(1, "2012-12-21 10:46:06" AS datetime)) as hex, +column_json(column_create(1, "2012-12-21 10:46:06" AS datetime)) as json; +hex json +00010001000595B90F000060B80A00 {"1":"2012-12-21 10:46:06"} +# +# MDEV-4849: Out of memory error and valgrind warnings on COLUMN_ADD +# +CREATE TABLE t1 (dyncol tinyblob) ENGINE=MyISAM; +INSERT INTO t1 SET dyncol = COLUMN_CREATE( 3, REPEAT('a',330), 4, 'x' ); +Warnings: +Warning 1265 Data truncated for column 'dyncol' at row 1 +SELECT COLUMN_ADD( COLUMN_ADD( dyncol, 1, REPEAT('b',130) ), 3, 'y' ) FROM t1; +ERROR HY000: Encountered illegal format of dynamic column string +DROP TABLE t1; diff --git a/mysql-test/r/events_bugs.result b/mysql-test/r/events_bugs.result index 30bc4f89d8c..efa4b89a0a8 100644 --- a/mysql-test/r/events_bugs.result +++ b/mysql-test/r/events_bugs.result @@ -569,7 +569,7 @@ USE test; SHOW GRANTS FOR CURRENT_USER; Grants for root@localhost GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION -GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION +GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION SET GLOBAL event_scheduler = ON; CREATE TABLE events_test.event_log (id int KEY AUTO_INCREMENT, ev_nm char(40), ev_cnt int, ev_tm timestamp) diff --git a/mysql-test/r/explain_non_select.result b/mysql-test/r/explain_non_select.result new file mode 100644 index 00000000000..4cc36a642a5 --- /dev/null +++ b/mysql-test/r/explain_non_select.result @@ -0,0 +1,221 @@ +drop table if exists t0, t1; +create table t0 (a int) engine=myisam; +insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8); +# +# Tests for single-table DELETE +# +explain select * from t0 where a=3; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 8 Using where +explain delete from t0 where a=3; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 8 Using where +# DELETE without WHERE is a special case: +explain delete from t0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL 8 Deleting all rows +create table t1 (a int, b int, filler char(100), key(a), key(b)); +insert into t1 +select A.a+10*B.a + 10*C.a, A.a+10*B.a + 10*C.a, 'filler' +from t0 A, t0 B, t0 C; +# This should use an index, possible_keys=NULL because there is no WHERE +explain delete from t1 order by a limit 2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index NULL a 5 NULL 2 +# This should use range, possible_keys={a,b} +explain delete from t1 where a<20 and b < 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a,b a 5 NULL 1 Using where +# This should use ALL + filesort +explain delete from t1 order by a+1 limit 2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 512 Using filesort +# This should use range + using filesort +explain delete from t1 where a<20 order by b limit 2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 5 NULL 1 Using where; Using filesort +# Try some subqueries: +explain delete from t1 where a < (select max(a) from t0); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 range a a 5 NULL 1 Using where +2 SUBQUERY t0 ALL NULL NULL NULL NULL 8 +explain delete from t1 where a < (select max(a) from t0 where a < t1.b); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 512 Using where +2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 8 Using where +# +# Tests for multi-table DELETE +# +explain delete t1 from t0, t1 where t0.a = t1.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 8 Using where +1 SIMPLE t1 ref a a 5 test.t0.a 4 +drop table t0, t1; +# ################################################################### +# ## EXPLAIN UPDATE tests +# ################################################################### +create table t0 (a int) engine=myisam; +insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8); +explain update t0 set a=3 where a=4; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 8 Using where +create table t1 (a int, b int, filler char(100), key(a), key(b)); +insert into t1 +select A.a+10*B.a + 10*C.a, A.a+10*B.a + 10*C.a, 'filler' +from t0 A, t0 B, t0 C; +explain update t1 set a=a+1 where 3>4; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +explain update t1 set a=a+1 where a=3 and a=4; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +# This should use an index, possible_keys=NULL because there is no WHERE +explain update t1 set a=a+1 order by a limit 2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 512 Using filesort +# This should use range, possible_keys={a,b} +explain update t1 set filler='fooo' where a<20 and b < 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a,b a 5 NULL 1 Using where +# This should use ALL + filesort +explain update t1 set filler='fooo' order by a+1 limit 2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 512 Using filesort +# This should use range + using filesort +explain update t1 set filler='fooo' where a<20 order by b limit 2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 5 NULL 1 Using where; Using filesort +# Try some subqueries: +explain update t1 set filler='fooo' where a < (select max(a) from t0); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 range a a 5 NULL 1 Using where +2 SUBQUERY t0 ALL NULL NULL NULL NULL 8 +explain update t1 set filler='fooo' where a < (select max(a) from t0 where a < t1.b); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 512 Using where +2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 8 Using where +# +# Tests for multi-table UPDATE +# +explain update t0, t1 set t1.a=t1.a+1 where t0.a = t1.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 8 Using where +1 SIMPLE t1 ref a a 5 test.t0.a 4 +drop table t0, t1; +# +# Try DELETE ... RETURNING ... +# +create table t0 (a int); +insert into t0 values (1),(2),(3),(4); +explain delete from t0 where a=1 returning a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 4 Using where +explain delete from t0 returning a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 4 +drop table t0; +# +# MDEV-5070 - EXPLAIN INSERT ... SELECT crashes on 10.0-base-explain-slowquerylog +# +create table t0 (a int); +insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8); +create table t1 (a int); +explain insert into t1 select * from t0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 8 +explain replace into t1 select * from t0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 8 +drop table t0, t1; +# +# MDEV-5067: Valgrind warnings (Invalid read) in QPF_table_access::print_explain +# +CREATE TABLE t1 (i INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (7),(0),(9); +SELECT * FROM t1 INNER JOIN ( SELECT DISTINCT * FROM t1 ) AS sq ON (sq.i = t1.i); +i i +7 7 +0 0 +9 9 +DROP TABLE t1; +# +# MDEV-5093, MDEV-5094: EXPLAIN PARTITIONS and EXPLAIN EXTENDED do not +# work for EXPLAIN UPDATE. +# +create table t1 (i int); +explain partitions update t1 set i = 3; +id select_type table partitions type possible_keys key key_len ref rows Extra +1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 0 +create table t2 (a int, b int) partition by hash(a) partitions 5; +insert into t2 values (0,0),(1,1),(2,2),(3,3),(4,4); +explain partitions update t2 set b=3 where a in (3,4); +id select_type table partitions type possible_keys key key_len ref rows Extra +1 SIMPLE t2 p3,p4 ALL NULL NULL NULL NULL 2 Using where +explain partitions delete from t2 where a in (3,4); +id select_type table partitions type possible_keys key key_len ref rows Extra +1 SIMPLE t2 p3,p4 ALL NULL NULL NULL NULL 2 Using where +explain extended update t2 set b=3 where a in (3,4); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where +explain extended delete from t2 where a in (3,4); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 100.00 Using where +drop table t1,t2; +# +# Check the special case where partition pruning removed all partitions +# +create table t1 (a int, b int) +partition by range (a) ( +partition p0 values less than (10), +partition p1 values less than (20), +partition p2 values less than (30) +); +insert into t1 values (9,9), (19,19), (29,29); +explain partitions select * from t1 where a in (32,33); +id select_type table partitions type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +explain partitions delete from t1 where a in (32,33); +id select_type table partitions type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No matching rows after partition pruning +explain partitions update t1 set b=12345 where a in (32,33); +id select_type table partitions type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No matching rows after partition pruning +drop table t1; +# +# Tests for EXPLAIN INSERT ... VALUES +# +create table t1 (a int, key(a)); +explain insert into t1 values (1),(2),(3); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +insert into t1 values (1),(2),(3); +create table t2 (a int, b int); +explain insert into t2 values +(10, 1+(select max(a) from t1)), +(11, 1+(select max(a+1) from t1)); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t2 ALL NULL NULL NULL NULL NULL NULL +3 SUBQUERY t1 index NULL a 5 NULL 3 Using index +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +drop table t1,t2; +# +# MDEV-5122: "Commands out of sync", "Malformed packet" or client hang up on unique key violation +# +drop table if exists t1; +Warnings: +Note 1051 Unknown table 't1' +drop function if exists f1; +create table t1 (a int, unique(a)); +create function f1(x int) +returns int +begin +insert into t1 values(x),(x); +return 10; +end| +select f1(100); +ERROR 23000: Duplicate entry '100' for key 'a' +select 'OK'; +OK +OK +drop function f1; +drop table t1; diff --git a/mysql-test/r/explain_slowquerylog.result b/mysql-test/r/explain_slowquerylog.result new file mode 100644 index 00000000000..8acbdc69a4c --- /dev/null +++ b/mysql-test/r/explain_slowquerylog.result @@ -0,0 +1,53 @@ +drop table if exists t0,t1; +create table t0 (a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +explain select * from t0 where a < 3; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where +# +# MDEV-5045: Server crashes in QPF_query::print_explain with log_slow_verbosity='query_plan,explain' +# +set autocommit=1; +drop table t0; +# +# MDEV-5047 virtual THD::~THD(): Assertion `status_var.memory_used == 0' fails on disconnect +# +ALTER TABLE nonexisting ENABLE KEYS; +ERROR 42S02: Table 'test.nonexisting' doesn't exist +SHOW WARNINGS; +Level Code Message +Error 1146 Table 'test.nonexisting' doesn't exist +SELECT 1; +1 +1 +# +# MDEV-5060 Server crashes on EXPLAIN EXTENDED or EXPLAIN PARTITIONS with explain in slow_log +# +EXPLAIN PARTITIONS SELECT 1 ; +id select_type table partitions type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +# +# MDEV-5106: Server crashes in Explain_union::print_explain on ER_TOO_BIG_SELECT with explain in slow log +# +CREATE TABLE t1 (i INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES +(1),(2),(3),(4),(5),(6),(7),(8),(9),(10); +SET max_join_size = 10; +( SELECT ta.* FROM t1 ta, t1 tb ) UNION ( SELECT * FROM t1 ); +ERROR 42000: The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET MAX_JOIN_SIZE=# if the SELECT is okay +SELECT 'Server still alive?' as 'Yes'; +Yes +Server still alive? +DROP TABLE t1; +# +# MDEV-5308 Crash when running with slow_query_log=1 +# +SET @save1= @@log_slow_rate_limit; +SET @save2= @@long_query_time; +SET log_slow_rate_limit=1000; +SET long_query_time=0.000001; +SELECT 1; +1 +1 +SET log_slow_rate_limit=@save1; +SET long_query_time=@save2; diff --git a/mysql-test/r/filesort_debug.result b/mysql-test/r/filesort_debug.result index 6d6eb817259..13912ac8756 100644 --- a/mysql-test/r/filesort_debug.result +++ b/mysql-test/r/filesort_debug.result @@ -4,7 +4,7 @@ SET @old_debug= @@session.debug; # CREATE TABLE t1(f0 int auto_increment primary key, f1 int); INSERT INTO t1(f1) VALUES (0),(1),(2),(3),(4),(5); -SET session debug_dbug= '+d,make_sort_keys_alloc_fail'; +SET session debug_dbug= '+d,alloc_sort_buffer_fail'; CALL mtr.add_suppression("Out of sort memory"); SELECT * FROM t1 ORDER BY f1 ASC, f0; ERROR HY001: Out of sort memory, consider increasing server sort buffer size diff --git a/mysql-test/r/flush.result b/mysql-test/r/flush.result index d3b3cd16210..b64351045bf 100644 --- a/mysql-test/r/flush.result +++ b/mysql-test/r/flush.result @@ -489,3 +489,10 @@ UNLOCK TABLES; # Switching to connection 'default'. COMMIT; DROP TABLE t1; +# +# Test flushing slave or relay logs twice +# +flush relay logs,relay logs; +ERROR HY000: Incorrect usage of FLUSH and RELAY LOGS +flush slave,slave; +ERROR HY000: Incorrect usage of FLUSH and SLAVE diff --git a/mysql-test/r/flush_read_lock.result b/mysql-test/r/flush_read_lock.result index cd7083405bf..05fab64330d 100644 --- a/mysql-test/r/flush_read_lock.result +++ b/mysql-test/r/flush_read_lock.result @@ -431,7 +431,7 @@ Success: Was able to run 'execute stmt1' under FTWRL. Success: Was able to run 'execute stmt1' with FTWRL active in another connection. Success: Was able to run FTWRL while 'execute stmt1' was active in another connection. deallocate prepare stmt1; -call mtr.add_suppression("Slave SQL.*Can.t execute the query because you have a conflicting read lock., Error_code: 1223"); +call mtr.add_suppression("Slave SQL.*Can.t execute the query because you have a conflicting read lock., error.* 1223"); # # 9.2.b) EXECUTE for statement which is incompatible with FTWRL # should be also incompatible. diff --git a/mysql-test/r/fulltext.result b/mysql-test/r/fulltext.result index c067ff02574..e6abd44c267 100644 --- a/mysql-test/r/fulltext.result +++ b/mysql-test/r/fulltext.result @@ -699,3 +699,14 @@ EXECUTE stmt; DEALLOCATE PREPARE stmt; DROP TABLE t1; End of 5.1 tests +CREATE TABLE t1 ( +id int(11) auto_increment, +title varchar(100) default '', +PRIMARY KEY (id), +KEY ind5 (title) +) ENGINE=MyISAM; +CREATE FULLTEXT INDEX IF NOT EXISTS ft1 ON t1(title); +CREATE FULLTEXT INDEX IF NOT EXISTS ft1 ON t1(title); +Warnings: +Note 1061 Duplicate key name 'ft1' +DROP TABLE t1; diff --git a/mysql-test/r/func_like.result b/mysql-test/r/func_like.result index 39590eb1c99..8d72b818cf8 100644 --- a/mysql-test/r/func_like.result +++ b/mysql-test/r/func_like.result @@ -188,3 +188,15 @@ DROP TABLE t1, t2; SELECT '' LIKE '1' ESCAPE COUNT(1); ERROR HY000: Incorrect arguments to ESCAPE End of 5.1 tests +# +# Start of 10.0 tests +# +# +# MDEV-5445 Server crashes in Item_func_like::fix_fields on LIKE ExtractValue(..) +# +SELECT 'a' LIKE REPEAT('',0); +'a' LIKE REPEAT('',0) +0 +SELECT 'a' LIKE EXTRACTVALUE('bar','qux'); +'a' LIKE EXTRACTVALUE('bar','qux') +0 diff --git a/mysql-test/r/func_misc.result b/mysql-test/r/func_misc.result index 55b0f9d3c57..a033c91bc05 100644 --- a/mysql-test/r/func_misc.result +++ b/mysql-test/r/func_misc.result @@ -338,6 +338,227 @@ set optimizer_switch=@optimizer_switch_save; drop view v_merge, vm; drop table t1,tv; # +# 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 +# -> Switching to 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 +# -> Switching to 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 +# -> Switching to connection 'con1' +create table t1 select connection_id() as id; +select get_lock('test', 7200); +# -> Switching to connection 'default' +select (@id := id) - id from t1; +(@id := id) - id +0 +kill query @id; +# -> Switching to connection 'con1' +get_lock('test', 7200) +NULL +# -> Switching to 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 +# -> Switching to connection 'con1' +select get_lock('test2', 0); +get_lock('test2', 0) +1 +select get_lock('test1', 7200); +# -> Switching to 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 +# -> Switching to connection 'con1' +get_lock('test1', 7200) +1 +select release_lock('test2'); +release_lock('test2') +1 +select release_lock('test1'); +release_lock('test1') +1 +# -> Switching to 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 +# -> Switching to connection 'con1' +lock table t1 write; +select get_lock('test', 7200); +# -> Switching to 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 +# -> Switching to connection 'con1' +get_lock('test', 7200) +1 +select release_lock('test'); +release_lock('test') +1 +unlock tables; +# cleanup +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 +# # End of 5.5 tests # # diff --git a/mysql-test/r/func_regexp_pcre.result b/mysql-test/r/func_regexp_pcre.result new file mode 100644 index 00000000000..ebbdedc6999 --- /dev/null +++ b/mysql-test/r/func_regexp_pcre.result @@ -0,0 +1,756 @@ +SET NAMES utf8; +# +# MDEV-4425 REGEXP enhancements +# +# +# Checking RLIKE +# +SELECT 'à ' RLIKE '^.$'; +'à ' RLIKE '^.$' +1 +SELECT 'à ' RLIKE '\\x{00E0}'; +'à ' RLIKE '\\x{00E0}' +1 +SELECT 'À' RLIKE '\\x{00E0}'; +'À' RLIKE '\\x{00E0}' +1 +SELECT 'à ' RLIKE '\\x{00C0}'; +'à ' RLIKE '\\x{00C0}' +1 +SELECT 'À' RLIKE '\\x{00C0}'; +'À' RLIKE '\\x{00C0}' +1 +SELECT 'à ' RLIKE '\\x{00E0}' COLLATE utf8_bin; +'à ' RLIKE '\\x{00E0}' COLLATE utf8_bin +1 +SELECT 'À' RLIKE '\\x{00E0}' COLLATE utf8_bin; +'À' RLIKE '\\x{00E0}' COLLATE utf8_bin +0 +SELECT 'à ' RLIKE '\\x{00C0}' COLLATE utf8_bin; +'à ' RLIKE '\\x{00C0}' COLLATE utf8_bin +0 +SELECT 'À' RLIKE '\\x{00C0}' COLLATE utf8_bin; +'À' RLIKE '\\x{00C0}' COLLATE utf8_bin +1 +CREATE TABLE t1 (s VARCHAR(10) CHARACTER SET utf8); +INSERT INTO t1 VALUES ('a'),('A'); +CREATE TABLE t2 (p VARCHAR(10) CHARACTER SET utf8); +INSERT INTO t2 VALUES ('a'),('(?i)a'),('(?-i)a'),('A'),('(?i)A'),('(?-i)A'); +SELECT s,p,s RLIKE p, s COLLATE utf8_bin RLIKE p FROM t1,t2 ORDER BY BINARY s, BINARY p; +s p s RLIKE p s COLLATE utf8_bin RLIKE p +A (?-i)A 1 1 +A (?-i)a 0 0 +A (?i)A 1 1 +A (?i)a 1 1 +A A 1 1 +A a 1 0 +a (?-i)A 0 0 +a (?-i)a 1 1 +a (?i)A 1 1 +a (?i)a 1 1 +a A 1 0 +a a 1 1 +DROP TABLE t1,t2; +CREATE TABLE t1 (ch VARCHAR(22)) CHARACTER SET utf8; +CREATE TABLE t2 (class VARCHAR(32)) CHARACTER SET utf8; +INSERT INTO t1 VALUES ('Я'),('Σ'),('A'),('À'); +INSERT INTO t1 VALUES ('Ñ'),('σ'),('a'),('à '); +INSERT INTO t1 VALUES ('ã—'),('ê°·'),('ප'); +INSERT INTO t1 VALUES ('1'),('௨'); +INSERT INTO t2 VALUES ('\\p{Cyrillic}'),('\\p{Greek}'),('\\p{Latin}'); +INSERT INTO t2 VALUES ('\\p{Han}'),('\\p{Hangul}'); +INSERT INTO t2 VALUES ('\\p{Sinhala}'), ('\\p{Tamil}'); +INSERT INTO t2 VALUES ('\\p{L}'),('\\p{Ll}'),('\\p{Lu}'),('\\p{L&}'); +INSERT INTO t2 VALUES ('[[:alpha:]]'),('[[:digit:]]'); +SELECT class, ch, ch RLIKE class FROM t1, t2 ORDER BY class, BINARY ch; +class ch ch RLIKE class +[[:alpha:]] 1 0 +[[:alpha:]] A 1 +[[:alpha:]] a 1 +[[:alpha:]] À 1 +[[:alpha:]] à 1 +[[:alpha:]] Σ 1 +[[:alpha:]] σ 1 +[[:alpha:]] Я 1 +[[:alpha:]] Ñ 1 +[[:alpha:]] ௨ 0 +[[:alpha:]] ප 1 +[[:alpha:]] ã— 1 +[[:alpha:]] ê°· 1 +[[:digit:]] 1 1 +[[:digit:]] A 0 +[[:digit:]] a 0 +[[:digit:]] À 0 +[[:digit:]] à 0 +[[:digit:]] Σ 0 +[[:digit:]] σ 0 +[[:digit:]] Я 0 +[[:digit:]] Ñ 0 +[[:digit:]] ௨ 1 +[[:digit:]] ප 0 +[[:digit:]] ã— 0 +[[:digit:]] ê°· 0 +\p{Cyrillic} 1 0 +\p{Cyrillic} A 0 +\p{Cyrillic} a 0 +\p{Cyrillic} À 0 +\p{Cyrillic} à 0 +\p{Cyrillic} Σ 0 +\p{Cyrillic} σ 0 +\p{Cyrillic} Я 1 +\p{Cyrillic} Ñ 1 +\p{Cyrillic} ௨ 0 +\p{Cyrillic} ප 0 +\p{Cyrillic} ã— 0 +\p{Cyrillic} ê°· 0 +\p{Greek} 1 0 +\p{Greek} A 0 +\p{Greek} a 0 +\p{Greek} À 0 +\p{Greek} à 0 +\p{Greek} Σ 1 +\p{Greek} σ 1 +\p{Greek} Я 0 +\p{Greek} Ñ 0 +\p{Greek} ௨ 0 +\p{Greek} ප 0 +\p{Greek} ã— 0 +\p{Greek} ê°· 0 +\p{Hangul} 1 0 +\p{Hangul} A 0 +\p{Hangul} a 0 +\p{Hangul} À 0 +\p{Hangul} à 0 +\p{Hangul} Σ 0 +\p{Hangul} σ 0 +\p{Hangul} Я 0 +\p{Hangul} Ñ 0 +\p{Hangul} ௨ 0 +\p{Hangul} ප 0 +\p{Hangul} ã— 0 +\p{Hangul} ê°· 1 +\p{Han} 1 0 +\p{Han} A 0 +\p{Han} a 0 +\p{Han} À 0 +\p{Han} à 0 +\p{Han} Σ 0 +\p{Han} σ 0 +\p{Han} Я 0 +\p{Han} Ñ 0 +\p{Han} ௨ 0 +\p{Han} ප 0 +\p{Han} ã— 1 +\p{Han} ê°· 0 +\p{L&} 1 0 +\p{L&} A 1 +\p{L&} a 1 +\p{L&} À 1 +\p{L&} à 1 +\p{L&} Σ 1 +\p{L&} σ 1 +\p{L&} Я 1 +\p{L&} Ñ 1 +\p{L&} ௨ 0 +\p{L&} ප 0 +\p{L&} ã— 0 +\p{L&} ê°· 0 +\p{Latin} 1 0 +\p{Latin} A 1 +\p{Latin} a 1 +\p{Latin} À 1 +\p{Latin} à 1 +\p{Latin} Σ 0 +\p{Latin} σ 0 +\p{Latin} Я 0 +\p{Latin} Ñ 0 +\p{Latin} ௨ 0 +\p{Latin} ප 0 +\p{Latin} ã— 0 +\p{Latin} ê°· 0 +\p{Ll} 1 0 +\p{Ll} A 0 +\p{Ll} a 1 +\p{Ll} À 0 +\p{Ll} à 1 +\p{Ll} Σ 0 +\p{Ll} σ 1 +\p{Ll} Я 0 +\p{Ll} Ñ 1 +\p{Ll} ௨ 0 +\p{Ll} ප 0 +\p{Ll} ã— 0 +\p{Ll} ê°· 0 +\p{Lu} 1 0 +\p{Lu} A 1 +\p{Lu} a 0 +\p{Lu} À 1 +\p{Lu} à 0 +\p{Lu} Σ 1 +\p{Lu} σ 0 +\p{Lu} Я 1 +\p{Lu} Ñ 0 +\p{Lu} ௨ 0 +\p{Lu} ප 0 +\p{Lu} ã— 0 +\p{Lu} ê°· 0 +\p{L} 1 0 +\p{L} A 1 +\p{L} a 1 +\p{L} À 1 +\p{L} à 1 +\p{L} Σ 1 +\p{L} σ 1 +\p{L} Я 1 +\p{L} Ñ 1 +\p{L} ௨ 0 +\p{L} ප 1 +\p{L} ã— 1 +\p{L} ê°· 1 +\p{Sinhala} 1 0 +\p{Sinhala} A 0 +\p{Sinhala} a 0 +\p{Sinhala} À 0 +\p{Sinhala} à 0 +\p{Sinhala} Σ 0 +\p{Sinhala} σ 0 +\p{Sinhala} Я 0 +\p{Sinhala} Ñ 0 +\p{Sinhala} ௨ 0 +\p{Sinhala} ප 1 +\p{Sinhala} ã— 0 +\p{Sinhala} ê°· 0 +\p{Tamil} 1 0 +\p{Tamil} A 0 +\p{Tamil} a 0 +\p{Tamil} À 0 +\p{Tamil} à 0 +\p{Tamil} Σ 0 +\p{Tamil} σ 0 +\p{Tamil} Я 0 +\p{Tamil} Ñ 0 +\p{Tamil} ௨ 1 +\p{Tamil} ප 0 +\p{Tamil} ã— 0 +\p{Tamil} ê°· 0 +DROP TABLE t1, t2; +SELECT 0xFF RLIKE '\\w'; +0xFF RLIKE '\\w' +0 +SELECT 0xFF RLIKE '(*UCP)\\w'; +0xFF RLIKE '(*UCP)\\w' +1 +SELECT '\n' RLIKE '(*CR)'; +'\n' RLIKE '(*CR)' +1 +SELECT '\n' RLIKE '(*LF)'; +'\n' RLIKE '(*LF)' +1 +SELECT '\n' RLIKE '(*CRLF)'; +'\n' RLIKE '(*CRLF)' +1 +SELECT '\n' RLIKE '(*ANYCRLF)'; +'\n' RLIKE '(*ANYCRLF)' +1 +SELECT '\n' RLIKE '(*ANY)'; +'\n' RLIKE '(*ANY)' +1 +SELECT 'a\nb' RLIKE '(*LF)(?m)^a$'; +'a\nb' RLIKE '(*LF)(?m)^a$' +1 +SELECT 'a\nb' RLIKE '(*CR)(?m)^a$'; +'a\nb' RLIKE '(*CR)(?m)^a$' +0 +SELECT 'a\nb' RLIKE '(*CRLF)(?m)^a$'; +'a\nb' RLIKE '(*CRLF)(?m)^a$' +0 +SELECT 'a\nb' RLIKE '(*ANYCRLF)(?m)^a$'; +'a\nb' RLIKE '(*ANYCRLF)(?m)^a$' +1 +SELECT 'a\rb' RLIKE '(*LF)(?m)^a$'; +'a\rb' RLIKE '(*LF)(?m)^a$' +0 +SELECT 'a\rb' RLIKE '(*CR)(?m)^a$'; +'a\rb' RLIKE '(*CR)(?m)^a$' +1 +SELECT 'a\rb' RLIKE '(*CRLF)(?m)^a$'; +'a\rb' RLIKE '(*CRLF)(?m)^a$' +0 +SELECT 'a\rb' RLIKE '(*ANYCRLF)(?m)^a$'; +'a\rb' RLIKE '(*ANYCRLF)(?m)^a$' +1 +SELECT 'a\r\nb' RLIKE '(*LF)(?m)^a$'; +'a\r\nb' RLIKE '(*LF)(?m)^a$' +0 +SELECT 'a\r\nb' RLIKE '(*CR)(?m)^a$'; +'a\r\nb' RLIKE '(*CR)(?m)^a$' +1 +SELECT 'a\r\nb' RLIKE '(*CRLF)(?m)^a$'; +'a\r\nb' RLIKE '(*CRLF)(?m)^a$' +1 +SELECT 'a\r\nb' RLIKE '(*ANYCRLF)(?m)^a$'; +'a\r\nb' RLIKE '(*ANYCRLF)(?m)^a$' +1 +SELECT 'aa' RLIKE '(a)\\g1'; +'aa' RLIKE '(a)\\g1' +1 +SELECT 'aa bb' RLIKE '(a)\\g1 (b)\\g2'; +'aa bb' RLIKE '(a)\\g1 (b)\\g2' +1 +SELECT 'aaaaa' RLIKE 'a{0,5}'; +'aaaaa' RLIKE 'a{0,5}' +1 +SELECT 'aaaaa' RLIKE 'a{1,3}'; +'aaaaa' RLIKE 'a{1,3}' +1 +SELECT 'aaaaa' RLIKE 'a{0,}'; +'aaaaa' RLIKE 'a{0,}' +1 +SELECT 'aaaaa' RLIKE 'a{10,20}'; +'aaaaa' RLIKE 'a{10,20}' +0 +SELECT 'aabb' RLIKE 'a(?R)?b'; +'aabb' RLIKE 'a(?R)?b' +1 +SELECT 'aabb' RLIKE 'aa(?R)?bb'; +'aabb' RLIKE 'aa(?R)?bb' +1 +SELECT 'abcc' RLIKE 'a(?>bc|b)c'; +'abcc' RLIKE 'a(?>bc|b)c' +1 +SELECT 'abc' RLIKE 'a(?>bc|b)c'; +'abc' RLIKE 'a(?>bc|b)c' +0 +SELECT 'ab' RLIKE 'a(?!b)'; +'ab' RLIKE 'a(?!b)' +0 +SELECT 'ac' RLIKE 'a(?!b)'; +'ac' RLIKE 'a(?!b)' +1 +SELECT 'ab' RLIKE 'a(?=b)'; +'ab' RLIKE 'a(?=b)' +1 +SELECT 'ac' RLIKE 'a(?=b)'; +'ac' RLIKE 'a(?=b)' +0 +SELECT 'ab' RLIKE '(?<!a)b'; +'ab' RLIKE '(?<!a)b' +0 +SELECT 'cb' RLIKE '(?<!a)b'; +'cb' RLIKE '(?<!a)b' +1 +SELECT 'ab' RLIKE '(?<=a)b'; +'ab' RLIKE '(?<=a)b' +1 +SELECT 'cb' RLIKE '(?<=a)b'; +'cb' RLIKE '(?<=a)b' +0 +SELECT 'aa' RLIKE '(?P<pattern>a)(?P=pattern)'; +'aa' RLIKE '(?P<pattern>a)(?P=pattern)' +1 +SELECT 'aba' RLIKE '(?P<pattern>a)b(?P=pattern)'; +'aba' RLIKE '(?P<pattern>a)b(?P=pattern)' +1 +SELECT 'a' RLIKE 'a(?#comment)'; +'a' RLIKE 'a(?#comment)' +1 +SELECT 'aa' RLIKE 'a(?#comment)a'; +'aa' RLIKE 'a(?#comment)a' +1 +SELECT 'aba' RLIKE 'a(?#b)a'; +'aba' RLIKE 'a(?#b)a' +0 +SELECT 'aaa' RLIKE '\\W\\W\\W'; +'aaa' RLIKE '\\W\\W\\W' +0 +SELECT '%' RLIKE '\\W'; +'%' RLIKE '\\W' +1 +SELECT '%a$' RLIKE '\\W.\\W'; +'%a$' RLIKE '\\W.\\W' +1 +SELECT '123' RLIKE '\\d\\d\\d'; +'123' RLIKE '\\d\\d\\d' +1 +SELECT 'aaa' RLIKE '\\d\\d\\d'; +'aaa' RLIKE '\\d\\d\\d' +0 +SELECT '1a3' RLIKE '\\d.\\d'; +'1a3' RLIKE '\\d.\\d' +1 +SELECT 'a1b' RLIKE '\\d.\\d'; +'a1b' RLIKE '\\d.\\d' +0 +SELECT '8' RLIKE '\\D'; +'8' RLIKE '\\D' +0 +SELECT 'a' RLIKE '\\D'; +'a' RLIKE '\\D' +1 +SELECT '%' RLIKE '\\D'; +'%' RLIKE '\\D' +1 +SELECT 'a1' RLIKE '\\D\\d'; +'a1' RLIKE '\\D\\d' +1 +SELECT 'a1' RLIKE '\\d\\D'; +'a1' RLIKE '\\d\\D' +0 +SELECT '\t' RLIKE '\\s'; +'\t' RLIKE '\\s' +1 +SELECT '\r' RLIKE '\\s'; +'\r' RLIKE '\\s' +1 +SELECT '\n' RLIKE '\\s'; +'\n' RLIKE '\\s' +1 +SELECT '\v' RLIKE '\\s'; +'\v' RLIKE '\\s' +0 +SELECT 'a' RLIKE '\\S'; +'a' RLIKE '\\S' +1 +SELECT '1' RLIKE '\\S'; +'1' RLIKE '\\S' +1 +SELECT '!' RLIKE '\\S'; +'!' RLIKE '\\S' +1 +SELECT '.' RLIKE '\\S'; +'.' RLIKE '\\S' +1 +SELECT 'abc\0def' REGEXP 'def'; +'abc\0def' REGEXP 'def' +1 +SELECT 'abc\0def' REGEXP 'abc\\x{00}def'; +'abc\0def' REGEXP 'abc\\x{00}def' +1 +SELECT HEX(REGEXP_SUBSTR('abc\0def','abc\\x{00}def')); +HEX(REGEXP_SUBSTR('abc\0def','abc\\x{00}def')) +61626300646566 +# +# Checking REGEXP_REPLACE +# +CREATE TABLE t1 AS SELECT REGEXP_REPLACE('abc','b','x'); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `REGEXP_REPLACE('abc','b','x')` longtext CHARACTER SET utf8 NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +EXPLAIN EXTENDED SELECT REGEXP_REPLACE('abc','b','x'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select regexp_replace('abc','b','x') AS `REGEXP_REPLACE('abc','b','x')` +CREATE TABLE t1 AS SELECT REGEXP_REPLACE('abc','b','x')+0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `REGEXP_REPLACE('abc','b','x')+0` double NOT NULL DEFAULT '0' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +SELECT REGEXP_REPLACE(NULL,'b','c'); +REGEXP_REPLACE(NULL,'b','c') +NULL +SELECT REGEXP_REPLACE('a',NULL,'c'); +REGEXP_REPLACE('a',NULL,'c') +NULL +SELECT REGEXP_REPLACE('a','b',NULL); +REGEXP_REPLACE('a','b',NULL) +NULL +SELECT REGEXP_REPLACE('a','x','b'); +REGEXP_REPLACE('a','x','b') +a +SELECT REGEXP_REPLACE('a','','b'); +REGEXP_REPLACE('a','','b') +a +SELECT REGEXP_REPLACE('a5b ab a5b','(?<=a)5*(?=b)','x'); +REGEXP_REPLACE('a5b ab a5b','(?<=a)5*(?=b)','x') +axb ab a5b +SELECT REGEXP_REPLACE('a5b a5b a5b','(?<=a)5*(?=b)','x'); +REGEXP_REPLACE('a5b a5b a5b','(?<=a)5*(?=b)','x') +axb axb axb +SELECT REGEXP_REPLACE('A','a','b'); +REGEXP_REPLACE('A','a','b') +b +SELECT REGEXP_REPLACE('a','A','b'); +REGEXP_REPLACE('a','A','b') +b +SELECT REGEXP_REPLACE('A' COLLATE utf8_bin,'a','b'); +REGEXP_REPLACE('A' COLLATE utf8_bin,'a','b') +A +SELECT REGEXP_REPLACE('a' COLLATE utf8_bin,'A','b'); +REGEXP_REPLACE('a' COLLATE utf8_bin,'A','b') +a +SELECT REGEXP_REPLACE('James Bond', '(.*) (.*)', '\\2, \\1 \\2'); +REGEXP_REPLACE('James Bond', '(.*) (.*)', '\\2, \\1 \\2') +Bond, James Bond +SELECT REGEXP_REPLACE('абвгд','в','ц'); +REGEXP_REPLACE('абвгд','в','ц') +абцгд +SELECT REGEXP_REPLACE('г',0xB3,0xB4); +REGEXP_REPLACE('г',0xB3,0xB4) +д +SELECT REGEXP_REPLACE('aaaa','a','b'); +REGEXP_REPLACE('aaaa','a','b') +bbbb +SELECT REGEXP_REPLACE('aaaa','(?<=.)a','b'); +REGEXP_REPLACE('aaaa','(?<=.)a','b') +abbb +SELECT REGEXP_REPLACE('aaaa','a(?=.)','b'); +REGEXP_REPLACE('aaaa','a(?=.)','b') +bbba +SELECT REGEXP_REPLACE('aaaa','(?<=.)a(?=.)','b'); +REGEXP_REPLACE('aaaa','(?<=.)a(?=.)','b') +abba +SELECT REGEXP_REPLACE('a\nb','(*LF)(?m)^a$','c'); +REGEXP_REPLACE('a\nb','(*LF)(?m)^a$','c') +c +b +SELECT REGEXP_REPLACE('a\nb','(*CR)(?m)^a$','c'); +REGEXP_REPLACE('a\nb','(*CR)(?m)^a$','c') +a +b +SELECT REGEXP_REPLACE('a\nb','(*CRLF)(?m)^a$','c'); +REGEXP_REPLACE('a\nb','(*CRLF)(?m)^a$','c') +a +b +SELECT REGEXP_REPLACE('a\nb','(*ANYCRLF)(?m)^a$','c'); +REGEXP_REPLACE('a\nb','(*ANYCRLF)(?m)^a$','c') +c +b +SELECT REGEXP_REPLACE('a\rb','(*LF)(?m)^a$','c'); +REGEXP_REPLACE('a\rb','(*LF)(?m)^a$','c') +a
b +SELECT REGEXP_REPLACE('a\rb','(*CR)(?m)^a$','c'); +REGEXP_REPLACE('a\rb','(*CR)(?m)^a$','c') +c
b +SELECT REGEXP_REPLACE('a\rb','(*CRLF)(?m)^a$','c'); +REGEXP_REPLACE('a\rb','(*CRLF)(?m)^a$','c') +a
b +SELECT REGEXP_REPLACE('a\rb','(*ANYCRLF)(?m)^a$','c'); +REGEXP_REPLACE('a\rb','(*ANYCRLF)(?m)^a$','c') +c
b +SELECT REGEXP_REPLACE('a\r\nb','(*LF)(?m)^a$','c'); +REGEXP_REPLACE('a\r\nb','(*LF)(?m)^a$','c') +a
+b +SELECT REGEXP_REPLACE('a\r\nb','(*CR)(?m)^a$','c'); +REGEXP_REPLACE('a\r\nb','(*CR)(?m)^a$','c') +c
+b +SELECT REGEXP_REPLACE('a\r\nb','(*CRLF)(?m)^a$','c'); +REGEXP_REPLACE('a\r\nb','(*CRLF)(?m)^a$','c') +c
+b +SELECT REGEXP_REPLACE('a\r\nb','(*ANYCRLF)(?m)^a$','c'); +REGEXP_REPLACE('a\r\nb','(*ANYCRLF)(?m)^a$','c') +c
+b +SELECT REGEXP_REPLACE('aa','(a)\\g1','b'); +REGEXP_REPLACE('aa','(a)\\g1','b') +b +SELECT REGEXP_REPLACE('aa bb','(a)\\g1 (b)\\g2','c'); +REGEXP_REPLACE('aa bb','(a)\\g1 (b)\\g2','c') +c +SELECT REGEXP_REPLACE('aaaaa','a{1,3}','b'); +REGEXP_REPLACE('aaaaa','a{1,3}','b') +bb +SELECT REGEXP_REPLACE('aaaaa','a{10,20}','b'); +REGEXP_REPLACE('aaaaa','a{10,20}','b') +aaaaa +SELECT REGEXP_REPLACE('daabbd','a(?R)?b','c'); +REGEXP_REPLACE('daabbd','a(?R)?b','c') +dcd +SELECT REGEXP_REPLACE('daabbd','aa(?R)?bb','c'); +REGEXP_REPLACE('daabbd','aa(?R)?bb','c') +dcd +SELECT REGEXP_REPLACE('dabccd','a(?>bc|b)c','e'); +REGEXP_REPLACE('dabccd','a(?>bc|b)c','e') +ded +SELECT REGEXP_REPLACE('dabcd','a(?>bc|b)c','e'); +REGEXP_REPLACE('dabcd','a(?>bc|b)c','e') +dabcd +SELECT REGEXP_REPLACE('ab','a(?!b)','e'); +REGEXP_REPLACE('ab','a(?!b)','e') +ab +SELECT REGEXP_REPLACE('ac','a(?!b)','e'); +REGEXP_REPLACE('ac','a(?!b)','e') +ec +SELECT REGEXP_REPLACE('ab','a(?=b)','e'); +REGEXP_REPLACE('ab','a(?=b)','e') +eb +SELECT REGEXP_REPLACE('ac','a(?=b)','e'); +REGEXP_REPLACE('ac','a(?=b)','e') +ac +SELECT REGEXP_REPLACE('ab','(?<!a)b','e'); +REGEXP_REPLACE('ab','(?<!a)b','e') +ab +SELECT REGEXP_REPLACE('cb','(?<!a)b','e'); +REGEXP_REPLACE('cb','(?<!a)b','e') +ce +SELECT REGEXP_REPLACE('ab','(?<=a)b','e'); +REGEXP_REPLACE('ab','(?<=a)b','e') +ae +SELECT REGEXP_REPLACE('cb','(?<=a)b','e'); +REGEXP_REPLACE('cb','(?<=a)b','e') +cb +SELECT REGEXP_REPLACE('aa','(?P<pattern>a)(?P=pattern)','b'); +REGEXP_REPLACE('aa','(?P<pattern>a)(?P=pattern)','b') +b +SELECT REGEXP_REPLACE('aba','(?P<pattern>a)b(?P=pattern)','c'); +REGEXP_REPLACE('aba','(?P<pattern>a)b(?P=pattern)','c') +c +SELECT REGEXP_REPLACE('a','a(?#comment)','e'); +REGEXP_REPLACE('a','a(?#comment)','e') +e +SELECT REGEXP_REPLACE('aa','a(?#comment)a','e'); +REGEXP_REPLACE('aa','a(?#comment)a','e') +e +SELECT REGEXP_REPLACE('aba','a(?#b)a','e'); +REGEXP_REPLACE('aba','a(?#b)a','e') +aba +SELECT REGEXP_REPLACE('ddd<ab>cc</ab>eee','<.+?>','*'); +REGEXP_REPLACE('ddd<ab>cc</ab>eee','<.+?>','*') +ddd*cc*eee +SELECT REGEXP_REPLACE('aaa','\\W\\W\\W','e'); +REGEXP_REPLACE('aaa','\\W\\W\\W','e') +aaa +SELECT REGEXP_REPLACE('aaa','\\w\\w\\w','e'); +REGEXP_REPLACE('aaa','\\w\\w\\w','e') +e +SELECT REGEXP_REPLACE('%','\\W','e'); +REGEXP_REPLACE('%','\\W','e') +e +SELECT REGEXP_REPLACE('%a$','\\W.\\W','e'); +REGEXP_REPLACE('%a$','\\W.\\W','e') +e +SELECT REGEXP_REPLACE('%a$','\\W\\w\\W','e'); +REGEXP_REPLACE('%a$','\\W\\w\\W','e') +e +SELECT REGEXP_REPLACE('123','\\d\\d\\d\\d\\d\\d','e'); +REGEXP_REPLACE('123','\\d\\d\\d\\d\\d\\d','e') +123 +SELECT REGEXP_REPLACE('123','\\d\\d\\d','e'); +REGEXP_REPLACE('123','\\d\\d\\d','e') +e +SELECT REGEXP_REPLACE('aaa','\\d\\d\\d','e'); +REGEXP_REPLACE('aaa','\\d\\d\\d','e') +aaa +SELECT REGEXP_REPLACE('1a3','\\d.\\d\\d.\\d','e'); +REGEXP_REPLACE('1a3','\\d.\\d\\d.\\d','e') +1a3 +SELECT REGEXP_REPLACE('1a3','\\d.\\d','e'); +REGEXP_REPLACE('1a3','\\d.\\d','e') +e +SELECT REGEXP_REPLACE('a1b','\\d.\\d','e'); +REGEXP_REPLACE('a1b','\\d.\\d','e') +a1b +SELECT REGEXP_REPLACE('8','\\D','e'); +REGEXP_REPLACE('8','\\D','e') +8 +SELECT REGEXP_REPLACE('a','\\D','e'); +REGEXP_REPLACE('a','\\D','e') +e +SELECT REGEXP_REPLACE('%','\\D','e'); +REGEXP_REPLACE('%','\\D','e') +e +SELECT REGEXP_REPLACE('a1','\\D\\d','e'); +REGEXP_REPLACE('a1','\\D\\d','e') +e +SELECT REGEXP_REPLACE('a1','\\d\\D','e'); +REGEXP_REPLACE('a1','\\d\\D','e') +a1 +SELECT REGEXP_REPLACE('\t','\\s','e'); +REGEXP_REPLACE('\t','\\s','e') +e +SELECT REGEXP_REPLACE('\r','\\s','e'); +REGEXP_REPLACE('\r','\\s','e') +e +SELECT REGEXP_REPLACE('\n','\\s','e'); +REGEXP_REPLACE('\n','\\s','e') +e +SELECT REGEXP_REPLACE('a','\\S','e'); +REGEXP_REPLACE('a','\\S','e') +e +SELECT REGEXP_REPLACE('1','\\S','e'); +REGEXP_REPLACE('1','\\S','e') +e +SELECT REGEXP_REPLACE('!','\\S','e'); +REGEXP_REPLACE('!','\\S','e') +e +SELECT REGEXP_REPLACE('.','\\S','e'); +REGEXP_REPLACE('.','\\S','e') +e +# +# Checking REGEXP_INSTR +# +SELECT REGEXP_INSTR('abcd','X'); +REGEXP_INSTR('abcd','X') +0 +SELECT REGEXP_INSTR('abcd','a'); +REGEXP_INSTR('abcd','a') +1 +SELECT REGEXP_INSTR('abcd','b'); +REGEXP_INSTR('abcd','b') +2 +SELECT REGEXP_INSTR('abcd','c'); +REGEXP_INSTR('abcd','c') +3 +SELECT REGEXP_INSTR('abcd','d'); +REGEXP_INSTR('abcd','d') +4 +SELECT REGEXP_INSTR('aaaa','(?<=a)a'); +REGEXP_INSTR('aaaa','(?<=a)a') +2 +SELECT REGEXP_INSTR('ваÑÑ','в'); +REGEXP_INSTR('ваÑÑ','в') +1 +SELECT REGEXP_INSTR('ваÑÑ','а'); +REGEXP_INSTR('ваÑÑ','а') +2 +SELECT REGEXP_INSTR('ваÑÑ','Ñ'); +REGEXP_INSTR('ваÑÑ','Ñ') +3 +SELECT REGEXP_INSTR('ваÑÑ','Ñ'); +REGEXP_INSTR('ваÑÑ','Ñ') +4 +SELECT REGEXP_INSTR(CONVERT('ваÑÑ' USING koi8r), CONVERT('в' USING koi8r)); +REGEXP_INSTR(CONVERT('ваÑÑ' USING koi8r), CONVERT('в' USING koi8r)) +1 +SELECT REGEXP_INSTR(CONVERT('ваÑÑ' USING koi8r), CONVERT('а' USING koi8r)); +REGEXP_INSTR(CONVERT('ваÑÑ' USING koi8r), CONVERT('а' USING koi8r)) +2 +SELECT REGEXP_INSTR(CONVERT('ваÑÑ' USING koi8r), CONVERT('Ñ' USING koi8r)); +REGEXP_INSTR(CONVERT('ваÑÑ' USING koi8r), CONVERT('Ñ' USING koi8r)) +3 +SELECT REGEXP_INSTR(CONVERT('ваÑÑ' USING koi8r), CONVERT('Ñ' USING koi8r)); +REGEXP_INSTR(CONVERT('ваÑÑ' USING koi8r), CONVERT('Ñ' USING koi8r)) +4 +# +# Checking REGEXP_SUBSTR +# +CREATE TABLE t1 AS SELECT REGEXP_SUBSTR('abc','b'); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `REGEXP_SUBSTR('abc','b')` varchar(3) CHARACTER SET utf8 NOT NULL DEFAULT '' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +EXPLAIN EXTENDED SELECT REGEXP_SUBSTR('abc','b'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select regexp_substr('abc','b') AS `REGEXP_SUBSTR('abc','b')` +CREATE TABLE t1 AS SELECT REGEXP_SUBSTR('abc','b')+0; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `REGEXP_SUBSTR('abc','b')+0` double NOT NULL DEFAULT '0' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +SELECT REGEXP_SUBSTR('See https://mariadb.org/en/foundation/ for details', 'https?://[^/]*'); +REGEXP_SUBSTR('See https://mariadb.org/en/foundation/ for details', 'https?://[^/]*') +https://mariadb.org diff --git a/mysql-test/r/func_set.result b/mysql-test/r/func_set.result index 9c4976d46db..93757800505 100644 --- a/mysql-test/r/func_set.result +++ b/mysql-test/r/func_set.result @@ -220,3 +220,22 @@ NULL 1,2,3,4,5,6,7 DROP TABLE t1; +# +# Start of 5.3 tests +# +# +# MDEV-4512 Valgrind warnings in my_long10_to_str_8bit on INTERVAL and DATE_ADD with incorrect types +# +CREATE TABLE t1 (pk INT PRIMARY KEY); +INSERT INTO t1 VALUES (10),(11); +SELECT INTERVAL( 9, 1, DATE_ADD( pk, INTERVAL pk MINUTE_SECOND ), 9, 8, 3, 5, 2, 1 ) FROM t1; +INTERVAL( 9, 1, DATE_ADD( pk, INTERVAL pk MINUTE_SECOND ), 9, 8, 3, 5, 2, 1 ) +8 +8 +Warnings: +Warning 1292 Incorrect datetime value: '10' +Warning 1292 Incorrect datetime value: '11' +DROP TABLE t1; +# +# End of 5.3 tests +# diff --git a/mysql-test/r/func_system.result b/mysql-test/r/func_system.result index fa05021eb47..1452cf7e533 100644 --- a/mysql-test/r/func_system.result +++ b/mysql-test/r/func_system.result @@ -25,14 +25,14 @@ user() like _latin1"%@%" select charset(user()); charset(user()) utf8 -select version()>="3.23.29"; -version()>="3.23.29" +select version()>="03.23.29"; +version()>="03.23.29" 1 -select version()>=_utf8"3.23.29"; -version()>=_utf8"3.23.29" +select version()>=_utf8"03.23.29"; +version()>=_utf8"03.23.29" 1 -select version()>=_latin1"3.23.29"; -version()>=_latin1"3.23.29" +select version()>=_latin1"03.23.29"; +version()>=_latin1"03.23.29" 1 select charset(version()); charset(version()) @@ -47,7 +47,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `database()` varchar(34) CHARACTER SET utf8 DEFAULT NULL, - `user()` varchar(77) CHARACTER SET utf8 NOT NULL DEFAULT '', + `user()` varchar(141) CHARACTER SET utf8 NOT NULL DEFAULT '', `version` char(60) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index 52c148d9046..b03fdb7ea83 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -1023,11 +1023,11 @@ MAKETIME(CAST(-1 AS UNSIGNED), 0, 0) Warnings: Note 1105 Cast to unsigned converted negative integer to it's positive complement Warning 1292 Truncated incorrect time value: '18446744073709551615:00:00' -SELECT EXTRACT(HOUR FROM '100000:02:03'); -EXTRACT(HOUR FROM '100000:02:03') +SELECT EXTRACT(HOUR FROM '10000:02:03'); +EXTRACT(HOUR FROM '10000:02:03') 22 Warnings: -Warning 1292 Truncated incorrect time value: '100000:02:03' +Warning 1292 Truncated incorrect time value: '10000:02:03' CREATE TABLE t1(f1 TIME); INSERT INTO t1 VALUES('916:00:00 a'); Warnings: diff --git a/mysql-test/r/function_defaults.result b/mysql-test/r/function_defaults.result new file mode 100644 index 00000000000..27b9ee0a323 --- /dev/null +++ b/mysql-test/r/function_defaults.result @@ -0,0 +1,3067 @@ +# +# Test of function defaults for any server, including embedded. +# +# +# Function defaults run 1. No microsecond precision. +# +SET TIME_ZONE = "+00:00"; +# +# Test of errors for column data types that dont support function +# defaults. +# +CREATE TABLE t1( a BIT DEFAULT CURRENT_TIMESTAMP ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a TINYINT DEFAULT CURRENT_TIMESTAMP ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a SMALLINT DEFAULT CURRENT_TIMESTAMP ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a MEDIUMINT DEFAULT CURRENT_TIMESTAMP ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a INT DEFAULT CURRENT_TIMESTAMP ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a BIGINT DEFAULT CURRENT_TIMESTAMP ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a FLOAT DEFAULT CURRENT_TIMESTAMP ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a DECIMAL DEFAULT CURRENT_TIMESTAMP ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a DATE DEFAULT CURRENT_TIMESTAMP ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a TIME DEFAULT CURRENT_TIMESTAMP ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a YEAR DEFAULT CURRENT_TIMESTAMP ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a BIT ON UPDATE CURRENT_TIMESTAMP ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a TINYINT ON UPDATE CURRENT_TIMESTAMP ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a SMALLINT ON UPDATE CURRENT_TIMESTAMP ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a MEDIUMINT ON UPDATE CURRENT_TIMESTAMP ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a INT ON UPDATE CURRENT_TIMESTAMP ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a BIGINT ON UPDATE CURRENT_TIMESTAMP ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a FLOAT ON UPDATE CURRENT_TIMESTAMP ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a DECIMAL ON UPDATE CURRENT_TIMESTAMP ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a DATE ON UPDATE CURRENT_TIMESTAMP ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a TIME ON UPDATE CURRENT_TIMESTAMP ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a YEAR ON UPDATE CURRENT_TIMESTAMP ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +# +# Test that the default clause behaves like NOW() regarding time zones. +# +CREATE TABLE t1 ( +a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +c TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +d TIMESTAMP NULL, +e DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +f DATETIME DEFAULT CURRENT_TIMESTAMP, +g DATETIME ON UPDATE CURRENT_TIMESTAMP, +h DATETIME +); +# 2011-09-27 14:11:08 UTC +SET TIMESTAMP = 1317132668.654321; +SET @old_time_zone = @@TIME_ZONE; +SET TIME_ZONE = "+05:00"; +INSERT INTO t1( d, h ) VALUES ( NOW(), NOW() ); +SELECT * FROM t1; +a b c d e f g h +2011-09-27 19:11:08 2011-09-27 19:11:08 0000-00-00 00:00:00 2011-09-27 19:11:08 2011-09-27 19:11:08 2011-09-27 19:11:08 NULL 2011-09-27 19:11:08 +# 1989-05-13 01:02:03 +SET TIMESTAMP = 611017323.543212; +UPDATE t1 SET d = NOW(), h = NOW(); +SELECT * FROM t1; +a b c d e f g h +1989-05-13 04:02:03 2011-09-27 19:11:08 1989-05-13 04:02:03 1989-05-13 04:02:03 1989-05-13 04:02:03 2011-09-27 19:11:08 1989-05-13 04:02:03 1989-05-13 04:02:03 +SET TIME_ZONE = @old_time_zone; +DROP TABLE t1; +# +# Test of several TIMESTAMP columns with different function defaults. +# +CREATE TABLE t1 ( +a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +c TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +d TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +e TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +f INT +); +# 2011-04-19 07:22:02 UTC +SET TIMESTAMP = 1303197722.534231; +INSERT INTO t1 ( f ) VALUES (1); +SELECT * FROM t1; +a b c d e f +2011-04-19 07:22:02 2011-04-19 07:22:02 2011-04-19 07:22:02 0000-00-00 00:00:00 0000-00-00 00:00:00 1 +# 2011-04-19 07:23:18 UTC +SET TIMESTAMP = 1303197798.132435; +UPDATE t1 SET f = 2; +SELECT * FROM t1; +a b c d e f +2011-04-19 07:23:18 2011-04-19 07:23:18 2011-04-19 07:22:02 2011-04-19 07:23:18 2011-04-19 07:23:18 2 +DROP TABLE t1; +# +# Test of inserted values out of order. +# +CREATE TABLE t1 ( +a INT, +b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +c TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +d TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +e TIMESTAMP NULL, +f DATETIME, +g DATETIME DEFAULT CURRENT_TIMESTAMP, +h DATETIME ON UPDATE CURRENT_TIMESTAMP, +i DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +j INT +); +# 2011-04-19 07:22:02 UTC +SET TIMESTAMP = 1303197722.534231; +INSERT INTO t1 ( j, a ) VALUES ( 1, 1 ); +SELECT * FROM t1; +a b c d e f g h i j +1 2011-04-19 07:22:02 2011-04-19 07:22:02 0000-00-00 00:00:00 NULL NULL 2011-04-19 07:22:02 NULL 2011-04-19 07:22:02 1 +DROP TABLE t1; +# +# Test of ON DUPLICATE KEY UPDATE +# +CREATE TABLE t1 ( +a INT PRIMARY KEY, +b INT, +c TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +d TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +e TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +f TIMESTAMP NOT NULL DEFAULT '1986-09-27 03:00:00.098765', +g TIMESTAMP NULL, +h DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +i DATETIME DEFAULT CURRENT_TIMESTAMP, +j DATETIME ON UPDATE CURRENT_TIMESTAMP, +k DATETIME NULL, +l DATETIME DEFAULT '1986-09-27 03:00:00.098765' +); +# 1977-12-21 23:00:00 UTC +SET TIMESTAMP = 251593200.192837; +INSERT INTO t1(a) VALUES (1) ON DUPLICATE KEY UPDATE b = 2; +SELECT * FROM t1; +a b c d e f g h i j k l +1 NULL 1977-12-21 23:00:00 1977-12-21 23:00:00 0000-00-00 00:00:00 1986-09-27 03:00:00 NULL 1977-12-21 23:00:00 1977-12-21 23:00:00 NULL NULL 1986-09-27 03:00:00 +# 1975-05-21 23:00:00 UTC +SET TIMESTAMP = 169945200.918273; +INSERT INTO t1(a) VALUES (1) ON DUPLICATE KEY UPDATE b = 2; +SELECT * FROM t1; +a b c d e f g h i j k l +1 2 1975-05-21 23:00:00 1977-12-21 23:00:00 1975-05-21 23:00:00 1986-09-27 03:00:00 NULL 1975-05-21 23:00:00 1977-12-21 23:00:00 1975-05-21 23:00:00 NULL 1986-09-27 03:00:00 +# 1973-08-14 09:11:22 UTC +SET TIMESTAMP = 114167482.534231; +INSERT INTO t1(a) VALUES (2) ON DUPLICATE KEY UPDATE b = 2; +SELECT * FROM t1; +a b c d e f g h i j k l +1 2 1975-05-21 23:00:00 1977-12-21 23:00:00 1975-05-21 23:00:00 1986-09-27 03:00:00 NULL 1975-05-21 23:00:00 1977-12-21 23:00:00 1975-05-21 23:00:00 NULL 1986-09-27 03:00:00 +2 NULL 1973-08-14 09:11:22 1973-08-14 09:11:22 0000-00-00 00:00:00 1986-09-27 03:00:00 NULL 1973-08-14 09:11:22 1973-08-14 09:11:22 NULL NULL 1986-09-27 03:00:00 +DROP TABLE t1; +CREATE TABLE t1 ( a INT PRIMARY KEY, b INT, c TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ); +# 2011-04-19 07:23:18 UTC +SET TIMESTAMP = 1303197798.945156; +INSERT INTO t1 VALUES +(1, 0, '2001-01-01 01:01:01.111111'), +(2, 0, '2002-02-02 02:02:02.222222'), +(3, 0, '2003-03-03 03:03:03.333333'); +SELECT * FROM t1; +a b c +1 0 2001-01-01 01:01:01 +2 0 2002-02-02 02:02:02 +3 0 2003-03-03 03:03:03 +UPDATE t1 SET b = 2, c = c WHERE a = 2; +SELECT * FROM t1; +a b c +1 0 2001-01-01 01:01:01 +2 2 2002-02-02 02:02:02 +3 0 2003-03-03 03:03:03 +INSERT INTO t1 (a) VALUES (4); +SELECT * FROM t1; +a b c +1 0 2001-01-01 01:01:01 +2 2 2002-02-02 02:02:02 +3 0 2003-03-03 03:03:03 +4 NULL 2011-04-19 07:23:18 +UPDATE t1 SET c = '2004-04-04 04:04:04.444444' WHERE a = 4; +SELECT * FROM t1; +a b c +1 0 2001-01-01 01:01:01 +2 2 2002-02-02 02:02:02 +3 0 2003-03-03 03:03:03 +4 NULL 2004-04-04 04:04:04 +INSERT INTO t1 ( a ) VALUES ( 3 ), ( 5 ) ON DUPLICATE KEY UPDATE b = 3, c = c; +SELECT * FROM t1; +a b c +1 0 2001-01-01 01:01:01 +2 2 2002-02-02 02:02:02 +3 3 2003-03-03 03:03:03 +4 NULL 2004-04-04 04:04:04 +5 NULL 2011-04-19 07:23:18 +INSERT INTO t1 (a, c) VALUES +(4, '2004-04-04 00:00:00.444444'), +(6, '2006-06-06 06:06:06.666666') +ON DUPLICATE KEY UPDATE b = 4; +SELECT * FROM t1; +a b c +1 0 2001-01-01 01:01:01 +2 2 2002-02-02 02:02:02 +3 3 2003-03-03 03:03:03 +4 4 2011-04-19 07:23:18 +5 NULL 2011-04-19 07:23:18 +6 NULL 2006-06-06 06:06:06 +DROP TABLE t1; +# +# Test of REPLACE INTO executed as UPDATE. +# +CREATE TABLE t1 ( +a INT PRIMARY KEY, +b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +c DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +d TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +e DATETIME DEFAULT CURRENT_TIMESTAMP, +f TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +g DATETIME ON UPDATE CURRENT_TIMESTAMP, +h TIMESTAMP NULL, +i DATETIME +); +# 1970-09-21 09:11:12 UTC +SET TIMESTAMP = 22756272.163584; +REPLACE INTO t1 ( a ) VALUES ( 1 ); +SELECT * FROM t1; +a b c d e f g h i +1 1970-09-21 09:11:12 1970-09-21 09:11:12 1970-09-21 09:11:12 1970-09-21 09:11:12 0000-00-00 00:00:00 NULL NULL NULL +# 1970-11-10 14:16:17 UTC +SET TIMESTAMP = 27094577.852954; +REPLACE INTO t1 ( a ) VALUES ( 1 ); +SELECT * FROM t1; +a b c d e f g h i +1 1970-11-10 14:16:17 1970-11-10 14:16:17 1970-11-10 14:16:17 1970-11-10 14:16:17 0000-00-00 00:00:00 NULL NULL NULL +DROP TABLE t1; +# +# Test of insertion of NULL, DEFAULT and an empty row for DEFAULT +# CURRENT_TIMESTAMP. +# +CREATE TABLE t1 ( +a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +b DATETIME DEFAULT CURRENT_TIMESTAMP, +c INT +); +# 2011-04-20 09:53:41 UTC +SET TIMESTAMP = 1303293221.163578; +INSERT INTO t1 VALUES (NULL, NULL, 1), (DEFAULT, DEFAULT, 2); +INSERT INTO t1 ( a, b, c ) VALUES (NULL, NULL, 3), (DEFAULT, DEFAULT, 4); +SELECT * FROM t1; +a b c +2011-04-20 09:53:41 NULL 1 +2011-04-20 09:53:41 2011-04-20 09:53:41 2 +2011-04-20 09:53:41 NULL 3 +2011-04-20 09:53:41 2011-04-20 09:53:41 4 +SET TIME_ZONE = "+03:00"; +SELECT * FROM t1; +a b c +2011-04-20 12:53:41 NULL 1 +2011-04-20 12:53:41 2011-04-20 09:53:41 2 +2011-04-20 12:53:41 NULL 3 +2011-04-20 12:53:41 2011-04-20 09:53:41 4 +SET TIME_ZONE = "+00:00"; +DROP TABLE t1; +# 2011-04-20 07:05:39 UTC +SET TIMESTAMP = 1303283139.195624; +CREATE TABLE t1 ( +a TIMESTAMP NOT NULL DEFAULT '2010-10-11 12:34:56' ON UPDATE CURRENT_TIMESTAMP, +b DATETIME DEFAULT '2010-10-11 12:34:56' +); +INSERT INTO t1 VALUES (NULL, NULL), (DEFAULT, DEFAULT); +INSERT INTO t1 ( a, b ) VALUES (NULL, NULL), (DEFAULT, DEFAULT); +SELECT * FROM t1; +a b +2011-04-20 07:05:39 NULL +2010-10-11 12:34:56 2010-10-11 12:34:56 +2011-04-20 07:05:39 NULL +2010-10-11 12:34:56 2010-10-11 12:34:56 +DROP TABLE t1; +# 2011-04-20 09:53:41 UTC +SET TIMESTAMP = 1303293221.136952; +CREATE TABLE t1 ( +a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +c TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +d TIMESTAMP NOT NULL DEFAULT '1986-09-27 03:00:00.098765', +e TIMESTAMP NULL, +f DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +g DATETIME DEFAULT CURRENT_TIMESTAMP, +h DATETIME ON UPDATE CURRENT_TIMESTAMP, +i DATETIME NULL, +j DATETIME DEFAULT '1986-09-27 03:00:00.098765' +); +INSERT INTO t1 VALUES (); +INSERT INTO t1 SELECT NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL; +SELECT * FROM t1; +a b c d e f g h i j +2011-04-20 09:53:41 2011-04-20 09:53:41 0000-00-00 00:00:00 1986-09-27 03:00:00 NULL 2011-04-20 09:53:41 2011-04-20 09:53:41 NULL NULL 1986-09-27 03:00:00 +2011-04-20 09:53:41 2011-04-20 09:53:41 2011-04-20 09:53:41 2011-04-20 09:53:41 NULL NULL NULL NULL NULL NULL +DROP TABLE t1; +# +# Test of multiple-table UPDATE for DEFAULT CURRENT_TIMESTAMP +# +CREATE TABLE t1 ( +a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +b DATETIME DEFAULT CURRENT_TIMESTAMP, +c INT +); +INSERT INTO t1 ( c ) VALUES (1); +SELECT * FROM t1; +a b c +2011-04-20 09:53:41 2011-04-20 09:53:41 1 +# 2011-04-20 17:06:13 UTC +SET TIMESTAMP = 1303311973.163587; +UPDATE t1 t11, t1 t12 SET t11.c = 1; +SELECT * FROM t1; +a b c +2011-04-20 09:53:41 2011-04-20 09:53:41 1 +UPDATE t1 t11, t1 t12 SET t11.c = 2; +SELECT * FROM t1; +a b c +2011-04-20 15:06:13 2011-04-20 09:53:41 2 +DROP TABLE t1; +CREATE TABLE t1 ( +a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +b TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +c DATETIME DEFAULT CURRENT_TIMESTAMP, +d DATETIME ON UPDATE CURRENT_TIMESTAMP, +e INT +); +CREATE TABLE t2 ( +f INT, +g DATETIME ON UPDATE CURRENT_TIMESTAMP, +h DATETIME DEFAULT CURRENT_TIMESTAMP, +i TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +j TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); +# 1995-03-11 00:02:03 UTC +SET TIMESTAMP = 794880123.195676; +INSERT INTO t1 ( e ) VALUES ( 1 ), ( 2 ); +INSERT INTO t2 ( f ) VALUES ( 1 ), ( 2 ); +SELECT * FROM t1; +a b c d e +1995-03-11 00:02:03 0000-00-00 00:00:00 1995-03-11 00:02:03 NULL 1 +1995-03-11 00:02:03 0000-00-00 00:00:00 1995-03-11 00:02:03 NULL 2 +SELECT * FROM t2; +f g h i j +1 NULL 1995-03-11 00:02:03 0000-00-00 00:00:00 1995-03-11 00:02:03 +2 NULL 1995-03-11 00:02:03 0000-00-00 00:00:00 1995-03-11 00:02:03 +# 1980-12-13 02:02:01 UTC +SET TIMESTAMP = 345520921.196755; +UPDATE t1, t2 SET t1.e = 3, t2.f = 4; +SELECT * FROM t1; +a b c d e +1995-03-11 00:02:03 1980-12-13 02:02:01 1995-03-11 00:02:03 1980-12-13 02:02:01 3 +1995-03-11 00:02:03 1980-12-13 02:02:01 1995-03-11 00:02:03 1980-12-13 02:02:01 3 +SELECT * FROM t2; +f g h i j +4 1980-12-13 02:02:01 1995-03-11 00:02:03 1980-12-13 02:02:01 1995-03-11 00:02:03 +4 1980-12-13 02:02:01 1995-03-11 00:02:03 1980-12-13 02:02:01 1995-03-11 00:02:03 +DROP TABLE t1, t2; +# +# Test of multiple table update with temporary table and on the fly. +# +CREATE TABLE t1 ( +a TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +b DATETIME ON UPDATE CURRENT_TIMESTAMP, +c INT, +d INT +); +CREATE TABLE t2 ( +a TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +b DATETIME ON UPDATE CURRENT_TIMESTAMP, +c INT KEY, +d INT +); +INSERT INTO t1 ( c ) VALUES (1), (2); +INSERT INTO t2 ( c ) VALUES (1), (2); +# Test of multiple table update done on the fly +# 2011-04-20 15:06:13 UTC +SET TIMESTAMP = 1303311973.194685; +UPDATE t1 JOIN t2 USING ( c ) SET t2.d = 1; +SELECT * FROM t1; +a b c d +0000-00-00 00:00:00 NULL 1 NULL +0000-00-00 00:00:00 NULL 2 NULL +SELECT * FROM t2; +a b c d +2011-04-20 15:06:13 2011-04-20 15:06:13 1 1 +2011-04-20 15:06:13 2011-04-20 15:06:13 2 1 +# Test of multiple table update done with temporary table. +# 1979-01-15 03:02:01 +SET TIMESTAMP = 285213721.134679; +UPDATE t1 JOIN t2 USING ( c ) SET t1.d = 1; +SELECT * FROM t1; +a b c d +1979-01-15 02:02:01 1979-01-15 02:02:01 1 1 +1979-01-15 02:02:01 1979-01-15 02:02:01 2 1 +SELECT * FROM t2; +a b c d +2011-04-20 15:06:13 2011-04-20 15:06:13 1 1 +2011-04-20 15:06:13 2011-04-20 15:06:13 2 1 +DROP TABLE t1, t2; +# +# Test of ON UPDATE CURRENT_TIMESTAMP. +# +CREATE TABLE t1 ( +a TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +b DATETIME ON UPDATE CURRENT_TIMESTAMP, +c INT +); +# 2011-04-20 09:53:41 UTC +SET TIMESTAMP = 1303293221.794613; +INSERT INTO t1 ( c ) VALUES ( 1 ); +SELECT * FROM t1; +a b c +0000-00-00 00:00:00 NULL 1 +UPDATE t1 SET c = 1; +SELECT * FROM t1; +a b c +0000-00-00 00:00:00 NULL 1 +UPDATE t1 SET c = 2; +SELECT * FROM t1; +a b c +2011-04-20 09:53:41 2011-04-20 09:53:41 2 +# +# Test of multiple-table UPDATE for ON UPDATE CURRENT_TIMESTAMP +# +# 2011-04-20 15:06:13 UTC +SET TIMESTAMP = 1303311973.534231; +UPDATE t1 t11, t1 t12 SET t11.c = 2; +SELECT * FROM t1; +a b c +2011-04-20 09:53:41 2011-04-20 09:53:41 2 +UPDATE t1 t11, t1 t12 SET t11.c = 3; +SELECT * FROM t1; +a b c +2011-04-20 15:06:13 2011-04-20 15:06:13 3 +DROP TABLE t1; +# +# Test of a multiple-table update where only one table is updated and +# the updated table has a primary key. +# +CREATE TABLE t1 ( a INT, b INT, PRIMARY KEY (a) ); +INSERT INTO t1 VALUES (1, 1),(2, 2),(3, 3),(4, 4); +CREATE TABLE t2 ( a INT, b INT ); +INSERT INTO t2 VALUES (1, 1),(2, 2),(3, 3),(4, 4),(5, 5); +UPDATE t1, t2 SET t1.b = 100 WHERE t1.a = t2.a; +SELECT * FROM t1; +a b +1 100 +2 100 +3 100 +4 100 +SELECT * FROM t2; +a b +1 1 +2 2 +3 3 +4 4 +5 5 +DROP TABLE t1, t2; +# +# Test of ALTER TABLE, reordering columns. +# +CREATE TABLE t1 ( a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, b INT ); +ALTER TABLE t1 MODIFY a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) DEFAULT NULL, + `a` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( a INT, b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, c TIMESTAMP NULL ); +ALTER TABLE t1 MODIFY b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP FIRST; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `a` int(11) DEFAULT NULL, + `c` timestamp NULL DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( a INT, b TIMESTAMP NULL ); +ALTER TABLE t1 MODIFY b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP FIRST; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, b TIMESTAMP NULL ); +ALTER TABLE t1 MODIFY a TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` timestamp NULL DEFAULT NULL, + `a` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, b TIMESTAMP NULL ); +ALTER TABLE t1 MODIFY a TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` timestamp NULL DEFAULT NULL, + `a` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( a TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE NOW(), b INT, c TIMESTAMP NULL ); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, + `b` int(11) DEFAULT NULL, + `c` timestamp NULL DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +ALTER TABLE t1 MODIFY a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) DEFAULT NULL, + `a` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `c` timestamp NULL DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( a TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE NOW(), b INT, c TIMESTAMP NULL ); +ALTER TABLE t1 MODIFY c TIMESTAMP NULL FIRST; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` timestamp NULL DEFAULT NULL, + `a` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, + `b` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( a TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE CURRENT_TIMESTAMP, b INT, c TIMESTAMP NULL ); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `b` int(11) DEFAULT NULL, + `c` timestamp NULL DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +ALTER TABLE t1 MODIFY a TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE CURRENT_TIMESTAMP AFTER b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) DEFAULT NULL, + `a` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `c` timestamp NULL DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( a TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE CURRENT_TIMESTAMP, b INT, c TIMESTAMP NULL ); +ALTER TABLE t1 MODIFY c TIMESTAMP NULL FIRST; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` timestamp NULL DEFAULT NULL, + `a` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `b` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +# +# Test of ALTER TABLE, adding columns. +# +CREATE TABLE t1 ( a INT ); +ALTER TABLE t1 ADD COLUMN b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +# +# Test of INSERT SELECT. +# +CREATE TABLE t1 ( +a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +c DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +d DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +); +CREATE TABLE t2 ( +placeholder1 INT, +placeholder2 INT, +placeholder3 INT, +placeholder4 INT, +a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +b TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', +c DATETIME, +d DATETIME +); +# 1977-08-16 15:30:01 UTC +SET TIMESTAMP = 240589801.654312; +INSERT INTO t2 (a, b, c, d) VALUES ( +'1977-08-16 15:30:01.123456', +'1977-08-16 15:30:01.234567', +'1977-08-16 15:30:01.345678', +'1977-08-16 15:30:01.456789' +); +# 1986-09-27 01:00:00 UTC +SET TIMESTAMP = 528166800.132435; +INSERT INTO t1 ( a, c ) SELECT a, c FROM t2; +SELECT * FROM t1; +a b c d +1977-08-16 15:30:01 1986-09-27 01:00:00 1977-08-16 15:30:01 1986-09-27 01:00:00 +DROP TABLE t1, t2; +# +# Test of CREATE TABLE SELECT. +# +# We test that the columns of the source table are not used to determine +# function defaults for the receiving table. +# +# 1970-04-11 20:13:57 UTC +SET TIMESTAMP = 8712837.657898; +CREATE TABLE t1 ( +a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +c TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +d TIMESTAMP NOT NULL DEFAULT '1986-09-27 03:00:00.098765', +e TIMESTAMP NULL, +f DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +g DATETIME DEFAULT CURRENT_TIMESTAMP, +h DATETIME ON UPDATE CURRENT_TIMESTAMP, +i DATETIME NULL, +j DATETIME DEFAULT '1986-09-27 03:00:00.098765' +); +INSERT INTO t1 VALUES (); +# 1971-01-31 21:13:57 UTC +SET TIMESTAMP = 34200837.164937; +CREATE TABLE t2 SELECT a FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +a +1970-04-11 20:13:57 +CREATE TABLE t3 SELECT b FROM t1; +SHOW CREATE TABLE t3; +Table Create Table +t3 CREATE TABLE `t3` ( + `b` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t3; +b +1970-04-11 20:13:57 +CREATE TABLE t4 SELECT c FROM t1; +SHOW CREATE TABLE t4; +Table Create Table +t4 CREATE TABLE `t4` ( + `c` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t4; +c +0000-00-00 00:00:00 +CREATE TABLE t5 SELECT d FROM t1; +SHOW CREATE TABLE t5; +Table Create Table +t5 CREATE TABLE `t5` ( + `d` timestamp NOT NULL DEFAULT '1986-09-27 03:00:00' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t5; +d +1986-09-27 03:00:00 +CREATE TABLE t6 SELECT e FROM t1; +SHOW CREATE TABLE t6; +Table Create Table +t6 CREATE TABLE `t6` ( + `e` timestamp NULL DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t6; +e +NULL +CREATE TABLE t7 SELECT f FROM t1; +SHOW CREATE TABLE t7; +Table Create Table +t7 CREATE TABLE `t7` ( + `f` datetime DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t7; +f +1970-04-11 20:13:57 +CREATE TABLE t8 SELECT g FROM t1; +SHOW CREATE TABLE t8; +Table Create Table +t8 CREATE TABLE `t8` ( + `g` datetime DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t8; +g +1970-04-11 20:13:57 +CREATE TABLE t9 SELECT h FROM t1; +SHOW CREATE TABLE t9; +Table Create Table +t9 CREATE TABLE `t9` ( + `h` datetime DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t9; +h +NULL +CREATE TABLE t10 SELECT i FROM t1; +SHOW CREATE TABLE t10; +Table Create Table +t10 CREATE TABLE `t10` ( + `i` datetime DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t10; +i +NULL +CREATE TABLE t11 SELECT j FROM t1; +SHOW CREATE TABLE t11; +Table Create Table +t11 CREATE TABLE `t11` ( + `j` datetime DEFAULT '1986-09-27 03:00:00' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t11; +j +1986-09-27 03:00:00 +CREATE TABLE t12 ( +k TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +l TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +m TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +n TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +o TIMESTAMP NOT NULL DEFAULT '1986-09-27 03:00:00.098765', +p TIMESTAMP NULL, +q DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +r DATETIME DEFAULT CURRENT_TIMESTAMP, +s DATETIME ON UPDATE CURRENT_TIMESTAMP, +t DATETIME NULL, +u DATETIME DEFAULT '1986-09-27 03:00:00.098765' +) +SELECT * FROM t1; +SHOW CREATE TABLE t12; +Table Create Table +t12 CREATE TABLE `t12` ( + `k` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `l` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `m` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `n` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, + `o` timestamp NOT NULL DEFAULT '1986-09-27 03:00:00', + `p` timestamp NULL DEFAULT NULL, + `q` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `r` datetime DEFAULT CURRENT_TIMESTAMP, + `s` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + `t` datetime DEFAULT NULL, + `u` datetime DEFAULT '1986-09-27 03:00:00', + `a` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `b` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `c` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + `d` timestamp NOT NULL DEFAULT '1986-09-27 03:00:00', + `e` timestamp NULL DEFAULT NULL, + `f` datetime DEFAULT NULL, + `g` datetime DEFAULT NULL, + `h` datetime DEFAULT NULL, + `i` datetime DEFAULT NULL, + `j` datetime DEFAULT '1986-09-27 03:00:00' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12; +# 1970-04-11 20:13:57 UTC +SET TIMESTAMP = 8712837.164953; +CREATE TABLE t1 ( +a DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +b DATETIME DEFAULT CURRENT_TIMESTAMP, +c DATETIME ON UPDATE CURRENT_TIMESTAMP, +d DATETIME NULL, +e DATETIME DEFAULT '1986-09-27 03:00:00.098765' +); +INSERT INTO t1 VALUES (); +# 1971-01-31 20:13:57 UTC +SET TIMESTAMP = 34200837.915736; +CREATE TABLE t2 SELECT a FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` datetime DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +a +1970-04-11 20:13:57 +CREATE TABLE t3 SELECT b FROM t1; +SHOW CREATE TABLE t3; +Table Create Table +t3 CREATE TABLE `t3` ( + `b` datetime DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t3; +b +1970-04-11 20:13:57 +CREATE TABLE t4 SELECT c FROM t1; +SHOW CREATE TABLE t4; +Table Create Table +t4 CREATE TABLE `t4` ( + `c` datetime DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t4; +c +NULL +CREATE TABLE t5 SELECT d FROM t1; +SHOW CREATE TABLE t5; +Table Create Table +t5 CREATE TABLE `t5` ( + `d` datetime DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t5; +d +NULL +CREATE TABLE t6 SELECT e FROM t1; +SHOW CREATE TABLE t6; +Table Create Table +t6 CREATE TABLE `t6` ( + `e` datetime DEFAULT '1986-09-27 03:00:00' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t6; +e +1986-09-27 03:00:00 +DROP TABLE t1, t2, t3, t4, t5, t6; +# +# Test of a CREATE TABLE SELECT that also declared columns. In this case +# the function default should be de-activated during the execution of the +# CREATE TABLE statement. +# +# 1970-01-01 03:16:40 +SET TIMESTAMP = 1000.987654; +CREATE TABLE t1 ( a INT ); +INSERT INTO t1 VALUES ( 1 ), ( 2 ); +CREATE TABLE t2 ( b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP) SELECT a FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `b` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SET TIMESTAMP = 2000.876543; +INSERT INTO t2( a ) VALUES ( 3 ); +SELECT * FROM t2; +b a +0000-00-00 00:00:00 1 +0000-00-00 00:00:00 2 +1970-01-01 00:33:20 3 +DROP TABLE t1, t2; +# +# Test of updating a view. +# +CREATE TABLE t1 ( a INT, b DATETIME DEFAULT CURRENT_TIMESTAMP ); +CREATE TABLE t2 ( a INT, b DATETIME ON UPDATE CURRENT_TIMESTAMP ); +CREATE VIEW v1 AS SELECT * FROM t1; +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` latin1 latin1_swedish_ci +CREATE VIEW v2 AS SELECT * FROM t2; +SHOW CREATE VIEW v2; +View Create View character_set_client collation_connection +v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t2`.`a` AS `a`,`t2`.`b` AS `b` from `t2` latin1 latin1_swedish_ci +# 1971-01-31 21:13:57 UTC +SET TIMESTAMP = 34200837.348564; +INSERT INTO v1 ( a ) VALUES ( 1 ); +INSERT INTO v2 ( a ) VALUES ( 1 ); +SELECT * FROM t1; +a b +1 1971-01-31 20:13:57 +SELECT * FROM v1; +a b +1 1971-01-31 20:13:57 +SELECT * FROM t2; +a b +1 NULL +SELECT * FROM v2; +a b +1 NULL +# 1970-04-11 20:13:57 UTC +SET TIMESTAMP = 8712837.567332; +UPDATE v1 SET a = 2; +UPDATE v2 SET a = 2; +SELECT * FROM t1; +a b +2 1971-01-31 20:13:57 +SELECT * FROM v1; +a b +2 1971-01-31 20:13:57 +SELECT * FROM t2; +a b +2 1970-04-11 20:13:57 +SELECT * FROM v2; +a b +2 1970-04-11 20:13:57 +DROP VIEW v1, v2; +DROP TABLE t1, t2; +# +# Test with stored procedures. +# +CREATE TABLE t1 ( +a INT, +b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +c TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +d TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +e TIMESTAMP NULL, +f DATETIME DEFAULT CURRENT_TIMESTAMP, +g DATETIME ON UPDATE CURRENT_TIMESTAMP +); +CREATE PROCEDURE p1() INSERT INTO test.t1( a ) VALUES ( 1 ); +CREATE PROCEDURE p2() UPDATE t1 SET a = 2 WHERE a = 1; +# 1971-01-31 20:13:57 UTC +SET TIMESTAMP = 34200837.876544; +CALL p1(); +SELECT * FROM t1; +a b c d e f g +1 1971-01-31 20:13:57 1971-01-31 20:13:57 0000-00-00 00:00:00 NULL 1971-01-31 20:13:57 NULL +# 1970-04-11 21:13:57 UTC +SET TIMESTAMP = 8712837.143546; +CALL p2(); +SELECT * FROM t1; +a b c d e f g +2 1970-04-11 20:13:57 1971-01-31 20:13:57 1970-04-11 20:13:57 NULL 1971-01-31 20:13:57 1970-04-11 20:13:57 +DROP PROCEDURE p1; +DROP PROCEDURE p2; +DROP TABLE t1; +# +# Test with triggers. +# +CREATE TABLE t1 ( +a INT, +b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +c TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +d TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +e TIMESTAMP NULL, +f DATETIME, +g DATETIME DEFAULT CURRENT_TIMESTAMP, +h DATETIME ON UPDATE CURRENT_TIMESTAMP, +i DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +); +CREATE TABLE t2 ( a INT ); +CREATE TRIGGER t2_trg BEFORE INSERT ON t2 FOR EACH ROW +BEGIN +INSERT INTO t1 ( a ) VALUES ( 1 ); +END| +# 1971-01-31 21:13:57 UTC +SET TIMESTAMP = 34200837.978675; +INSERT INTO t2 ( a ) VALUES ( 1 ); +SELECT * FROM t1; +a b c d e f g h i +1 1971-01-31 20:13:57 1971-01-31 20:13:57 0000-00-00 00:00:00 NULL NULL 1971-01-31 20:13:57 NULL 1971-01-31 20:13:57 +DROP TRIGGER t2_trg; +CREATE TRIGGER t2_trg BEFORE INSERT ON t2 FOR EACH ROW +BEGIN +UPDATE t1 SET a = 2; +END| +# 1970-04-11 21:13:57 UTC +SET TIMESTAMP = 8712837.456789; +INSERT INTO t2 ( a ) VALUES ( 1 ); +SELECT * FROM t1; +a b c d e f g h i +2 1970-04-11 20:13:57 1971-01-31 20:13:57 1970-04-11 20:13:57 NULL NULL 1971-01-31 20:13:57 1970-04-11 20:13:57 1970-04-11 20:13:57 +DROP TABLE t1, t2; +# +# Test where the assignment target is not a column. +# +CREATE TABLE t1 ( a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ); +CREATE TABLE t2 ( a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ); +CREATE TABLE t3 ( a TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP ); +CREATE TABLE t4 ( a TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP ); +CREATE VIEW v1 AS SELECT a COLLATE latin1_german1_ci AS b FROM t1; +CREATE VIEW v2 ( b ) AS SELECT a COLLATE latin1_german1_ci FROM t2; +CREATE VIEW v3 AS SELECT a COLLATE latin1_german1_ci AS b FROM t3; +CREATE VIEW v4 ( b ) AS SELECT a COLLATE latin1_german1_ci FROM t4; +INSERT INTO v1 ( b ) VALUES ( '2007-10-24 00:03:34.010203' ); +SELECT a FROM t1; +a +2007-10-24 00:03:34 +INSERT INTO v2 ( b ) VALUES ( '2007-10-24 00:03:34.010203' ); +SELECT a FROM t2; +a +2007-10-24 00:03:34 +INSERT INTO t3 VALUES (); +UPDATE v3 SET b = '2007-10-24 00:03:34.010203'; +SELECT a FROM t3; +a +2007-10-24 00:03:34 +INSERT INTO t4 VALUES (); +UPDATE v4 SET b = '2007-10-24 00:03:34.010203'; +SELECT a FROM t4; +a +2007-10-24 00:03:34 +DROP VIEW v1, v2, v3, v4; +DROP TABLE t1, t2, t3, t4; +# +# Test of LOAD DATA/XML INFILE +# This tests behavior of function defaults for TIMESTAMP and DATETIME +# columns. during LOAD ... INFILE. +# As can be seen here, a TIMESTAMP column with only ON UPDATE +# CURRENT_TIMESTAMP will still have CURRENT_TIMESTAMP inserted on LOAD +# ... INFILE if the value is missing. For DATETIME columns a NULL value +# is inserted instead. +# +CREATE TABLE t1 ( +a INT, +b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +c TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +d TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +e TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +f DATETIME, +g DATETIME DEFAULT CURRENT_TIMESTAMP, +h DATETIME ON UPDATE CURRENT_TIMESTAMP, +i DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +); +CREATE TABLE t2 ( +a TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +c TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, +d TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +e DATETIME NOT NULL, +f DATETIME NOT NULL DEFAULT '1977-01-02 12:13:14', +g DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, +h DATETIME ON UPDATE CURRENT_TIMESTAMP NOT NULL, +i DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL +); +SELECT 1 INTO OUTFILE 't3.dat' FROM dual; +SELECT NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL +INTO OUTFILE 't4.dat' +FROM dual; +SELECT 1, 2 INTO OUTFILE 't5.dat' FROM dual; +# Mon Aug 1 15:11:19 2011 UTC +SET TIMESTAMP = 1312211479.918273; +LOAD DATA INFILE 't3.dat' INTO TABLE t1; +Warnings: +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +SELECT * FROM t1; +a 1 +b 2011-08-01 15:11:19 +c 2011-08-01 15:11:19 +d 2011-08-01 15:11:19 +e 2011-08-01 15:11:19 +f NULL +g NULL +h NULL +i NULL +LOAD DATA INFILE 't4.dat' INTO TABLE t2; +Warnings: +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'e' at row 1 +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'f' at row 1 +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'g' at row 1 +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'h' at row 1 +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'i' at row 1 +SELECT a FROM t2; +a +2011-08-01 15:11:19 +SELECT b FROM t2; +b +2011-08-01 15:11:19 +SELECT c FROM t2; +c +2011-08-01 15:11:19 +SELECT d FROM t2; +d +2011-08-01 15:11:19 +# As shown here, supplying a NULL value to a non-nullable +# column with no default value results in the zero date. +SELECT e FROM t2; +e +0000-00-00 00:00:00 +# As shown here, supplying a NULL value to a non-nullable column with a +# default value results in the zero date. +SELECT f FROM t2; +f +0000-00-00 00:00:00 +# As shown here, supplying a NULL value to a non-nullable column with a +# default function results in the zero date. +SELECT g FROM t2; +g +0000-00-00 00:00:00 +# As shown here, supplying a NULL value to a non-nullable DATETIME ON +# UPDATE CURRENT_TIMESTAMP column with no default value results in the +# zero date. +SELECT h FROM t2; +h +0000-00-00 00:00:00 +SELECT i FROM t2; +i +0000-00-00 00:00:00 +DELETE FROM t1; +DELETE FROM t2; +# Read t3 file into t1 +# The syntax will cause a different code path to be taken +# (read_fixed_length()) than under the LOAD ... INTO TABLE t1 command +# above. The code in this path is copy-pasted code from the path taken +# under the syntax used in the previous LOAD command. +LOAD DATA INFILE 't3.dat' INTO TABLE t1 +FIELDS TERMINATED BY '' ENCLOSED BY ''; +Warnings: +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +SELECT b FROM t1; +b +2011-08-01 15:11:19 +SELECT c FROM t1; +c +2011-08-01 15:11:19 +SELECT d FROM t1; +d +2011-08-01 15:11:19 +SELECT e FROM t1; +e +2011-08-01 15:11:19 +# Yes, a missing field cannot be NULL using this syntax, so it will +# zero date instead. Says a comment in read_fixed_length() : "No fields +# specified in fields_vars list can be NULL in this format." +# It appears to be by design. This is inconsistent with LOAD DATA INFILE +# syntax in previous test. +SELECT f FROM t1; +f +0000-00-00 00:00:00 +SELECT g FROM t1; +g +0000-00-00 00:00:00 +# See comment above "SELECT f FROM f1". +SELECT h FROM t1; +h +0000-00-00 00:00:00 +SELECT i FROM t1; +i +0000-00-00 00:00:00 +DELETE FROM t1; +LOAD DATA INFILE 't5.dat' INTO TABLE t1 ( a, @dummy ); +SELECT * FROM t1; +a b c d e f g h i +1 2011-08-01 15:11:19 2011-08-01 15:11:19 0000-00-00 00:00:00 2011-08-01 15:11:19 NULL 2011-08-01 15:11:19 NULL 2011-08-01 15:11:19 +SELECT @dummy; +@dummy +2 +DELETE FROM t1; +LOAD DATA INFILE 't3.dat' INTO TABLE t1 ( a ) SET c = '2005-06-06 08:09:10'; +SELECT * FROM t1; +a b c d e f g h i +1 2011-08-01 15:11:19 2005-06-06 08:09:10 0000-00-00 00:00:00 2011-08-01 15:11:19 NULL 2011-08-01 15:11:19 NULL 2011-08-01 15:11:19 +DELETE FROM t1; +LOAD DATA INFILE 't3.dat' INTO TABLE t1 ( a ) SET g = '2005-06-06 08:09:10'; +SELECT * FROM t1; +a b c d e f g h i +1 2011-08-01 15:11:19 2011-08-01 15:11:19 0000-00-00 00:00:00 2011-08-01 15:11:19 NULL 2005-06-06 08:09:10 NULL 2011-08-01 15:11:19 +DELETE FROM t1; +# Load a static XML file +LOAD XML INFILE '../../std_data/onerow.xml' INTO TABLE t1 +ROWS IDENTIFIED BY '<row>'; +Missing tags are treated as NULL +SELECT * FROM t1; +a 1 +b 2011-08-01 15:11:19 +c 2011-08-01 15:11:19 +d 2011-08-01 15:11:19 +e 2011-08-01 15:11:19 +f NULL +g NULL +h NULL +i NULL +DROP TABLE t1, t2; +# +# Similar LOAD DATA tests in another form +# +# All of this test portion has been run on a pre-WL5874 trunk +# (except that like_b and like_c didn't exist) and all result +# differences are a bug. +# Regarding like_b its definition is the same as b's except +# that the constant default is replaced with a function +# default. Our expectation is that like_b would behave +# like b: if b is set to NULL, or set to 0000-00-00, or set to +# its default, then the same should apply to like_b. Same for +# like_c vs c. +# Mon Aug 1 15:11:19 2011 UTC +SET TIMESTAMP = 1312211479.089786; +SELECT 1 INTO OUTFILE "file1.dat" FROM dual; +SELECT NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL +INTO OUTFILE "file2.dat" FROM dual; +# Too short row +CREATE TABLE t1 ( +dummy INT, +a DATETIME NULL DEFAULT NULL, +b DATETIME NULL DEFAULT "2011-11-18", +like_b DATETIME NULL DEFAULT CURRENT_TIMESTAMP, +c DATETIME NOT NULL DEFAULT "2011-11-18", +like_c DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, +d TIMESTAMP NULL DEFAULT "2011-05-03" ON UPDATE CURRENT_TIMESTAMP, +e TIMESTAMP NOT NULL DEFAULT "2011-05-03", +f TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +g TIMESTAMP NULL DEFAULT NULL, +h INT NULL, +i INT NOT NULL DEFAULT 42 +); +# There is no promotion +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `dummy` int(11) DEFAULT NULL, + `a` datetime DEFAULT NULL, + `b` datetime DEFAULT '2011-11-18 00:00:00', + `like_b` datetime DEFAULT CURRENT_TIMESTAMP, + `c` datetime NOT NULL DEFAULT '2011-11-18 00:00:00', + `like_c` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `d` timestamp NULL DEFAULT '2011-05-03 00:00:00' ON UPDATE CURRENT_TIMESTAMP, + `e` timestamp NOT NULL DEFAULT '2011-05-03 00:00:00', + `f` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `g` timestamp NULL DEFAULT NULL, + `h` int(11) DEFAULT NULL, + `i` int(11) NOT NULL DEFAULT '42' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +LOAD DATA INFILE "file1.dat" INTO table t1; +Warnings: +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +# It is strange that "like_b" gets NULL when "b" gets 0. But +# this is consistent with how "a" gets NULL when "b" gets 0, +# with how "g" gets NULL when "d" gets 0, and with how "h" gets +# NULL when "i" gets 0. Looks like "DEFAULT +# <non-NULL-constant>" is changed to 0, whereas DEFAULT NULL +# and DEFAULT NOW are changed to NULL. +SELECT * FROM t1; +dummy 1 +a NULL +b 0000-00-00 00:00:00 +like_b NULL +c 0000-00-00 00:00:00 +like_c 0000-00-00 00:00:00 +d 0000-00-00 00:00:00 +e 2011-08-01 15:11:19 +f 2011-08-01 15:11:19 +g NULL +h NULL +i 0 +delete from t1; +alter table t1 +modify f TIMESTAMP NULL default CURRENT_TIMESTAMP; +# There is no promotion +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `dummy` int(11) DEFAULT NULL, + `a` datetime DEFAULT NULL, + `b` datetime DEFAULT '2011-11-18 00:00:00', + `like_b` datetime DEFAULT CURRENT_TIMESTAMP, + `c` datetime NOT NULL DEFAULT '2011-11-18 00:00:00', + `like_c` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `d` timestamp NULL DEFAULT '2011-05-03 00:00:00' ON UPDATE CURRENT_TIMESTAMP, + `e` timestamp NOT NULL DEFAULT '2011-05-03 00:00:00', + `f` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `g` timestamp NULL DEFAULT NULL, + `h` int(11) DEFAULT NULL, + `i` int(11) NOT NULL DEFAULT '42' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +LOAD DATA INFILE "file1.dat" INTO table t1; +Warnings: +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +SELECT * FROM t1; +dummy 1 +a NULL +b 0000-00-00 00:00:00 +like_b NULL +c 0000-00-00 00:00:00 +like_c 0000-00-00 00:00:00 +d 0000-00-00 00:00:00 +e 2011-08-01 15:11:19 +f NULL +g NULL +h NULL +i 0 +delete from t1; +drop table t1; +# Conclusion derived from trunk's results: +# DATETIME DEFAULT <non-NULL-constant> (b,c) gets 0000-00-00, +# DATETIME DEFAULT NULL (a) gets NULL, +# TIMESTAMP NULL DEFAULT <non-NULL-constant> (d) gets 0000-00-00, +# TIMESTAMP NULL DEFAULT NULL (g) gets NULL, +# TIMESTAMP NULL DEFAULT NOW (f after ALTER) gets NULL, +# TIMESTAMP NOT NULL (f before ALTER, e) gets NOW. +### Loading NULL ### +CREATE TABLE t1 ( +dummy INT, +a DATETIME NULL DEFAULT NULL, +b DATETIME NULL DEFAULT "2011-11-18", +like_b DATETIME NULL DEFAULT CURRENT_TIMESTAMP, +c DATETIME NOT NULL DEFAULT "2011-11-18", +like_c DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, +d TIMESTAMP NULL DEFAULT "2011-05-03" ON UPDATE CURRENT_TIMESTAMP, +e TIMESTAMP NOT NULL DEFAULT "2011-05-03", +f TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, +g TIMESTAMP NULL DEFAULT NULL, +h INT NULL, +i INT NOT NULL DEFAULT 42 +); +# There is no promotion +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `dummy` int(11) DEFAULT NULL, + `a` datetime DEFAULT NULL, + `b` datetime DEFAULT '2011-11-18 00:00:00', + `like_b` datetime DEFAULT CURRENT_TIMESTAMP, + `c` datetime NOT NULL DEFAULT '2011-11-18 00:00:00', + `like_c` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `d` timestamp NULL DEFAULT '2011-05-03 00:00:00' ON UPDATE CURRENT_TIMESTAMP, + `e` timestamp NOT NULL DEFAULT '2011-05-03 00:00:00', + `f` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `g` timestamp NULL DEFAULT NULL, + `h` int(11) DEFAULT NULL, + `i` int(11) NOT NULL DEFAULT '42' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +LOAD DATA INFILE "file2.dat" INTO table t1; +Warnings: +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'c' at row 1 +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'like_c' at row 1 +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'i' at row 1 +SELECT * FROM t1; +dummy NULL +a NULL +b NULL +like_b NULL +c 0000-00-00 00:00:00 +like_c 0000-00-00 00:00:00 +d NULL +e 2011-08-01 15:11:19 +f 2011-08-01 15:11:19 +g NULL +h NULL +i 0 +delete from t1; +alter table t1 +modify f TIMESTAMP NULL default CURRENT_TIMESTAMP; +# There is no promotion +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `dummy` int(11) DEFAULT NULL, + `a` datetime DEFAULT NULL, + `b` datetime DEFAULT '2011-11-18 00:00:00', + `like_b` datetime DEFAULT CURRENT_TIMESTAMP, + `c` datetime NOT NULL DEFAULT '2011-11-18 00:00:00', + `like_c` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `d` timestamp NULL DEFAULT '2011-05-03 00:00:00' ON UPDATE CURRENT_TIMESTAMP, + `e` timestamp NOT NULL DEFAULT '2011-05-03 00:00:00', + `f` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `g` timestamp NULL DEFAULT NULL, + `h` int(11) DEFAULT NULL, + `i` int(11) NOT NULL DEFAULT '42' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +LOAD DATA INFILE "file2.dat" INTO table t1; +Warnings: +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'c' at row 1 +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'like_c' at row 1 +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'i' at row 1 +SELECT * FROM t1; +dummy NULL +a NULL +b NULL +like_b NULL +c 0000-00-00 00:00:00 +like_c 0000-00-00 00:00:00 +d NULL +e 2011-08-01 15:11:19 +f NULL +g NULL +h NULL +i 0 +delete from t1; +# Conclusion derived from trunk's results: +# DATETIME NULL (a,b) gets NULL, +# DATETIME NOT NULL (c) gets 0000-00-00, +# TIMESTAMP NULL (d,f,g) gets NULL, +# TIMESTAMP NOT NULL (e) gets NOW. +drop table t1; +# +# Test of updatable views with check options. The option can be violated +# using ON UPDATE updates which is very strange as this offers a loophole +# in this integrity check. +# +SET TIME_ZONE = "+03:00"; +# 1970-01-01 03:16:40 +SET TIMESTAMP = 1000.123456; +CREATE TABLE t1 ( a INT, b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP) ENGINE = INNODB; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +INSERT INTO t1 ( a ) VALUES ( 1 ); +SELECT * FROM t1; +a b +1 1970-01-01 03:16:40 +CREATE VIEW v1 AS SELECT * FROM t1 WHERE b <= '1970-01-01 03:16:40.123456' +WITH CHECK OPTION; +SELECT * FROM v1; +a b +1 1970-01-01 03:16:40 +# 1970-01-01 03:33:20 +SET TIMESTAMP = 2000.000234; +UPDATE v1 SET a = 2; +ERROR HY000: CHECK OPTION failed 'test.v1' +SELECT * FROM t1; +a b +1 1970-01-01 03:16:40 +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 ( +a TIMESTAMP NOT NULL DEFAULT '1973-08-14 09:11:22.089786' ON UPDATE CURRENT_TIMESTAMP, +c INT KEY +); +# 1973-08-14 09:11:22 UTC +SET TIMESTAMP = 114167482.534231; +INSERT INTO t1 ( c ) VALUES ( 1 ); +CREATE VIEW v1 AS +SELECT * +FROM t1 +WHERE a >= '1973-08-14 09:11:22' +WITH LOCAL CHECK OPTION; +SELECT * FROM v1; +a c +1973-08-14 09:11:22 1 +SET TIMESTAMP = 1.126789; +INSERT INTO v1 ( c ) VALUES ( 1 ) ON DUPLICATE KEY UPDATE c = 2; +ERROR HY000: CHECK OPTION failed 'test.v1' +SELECT * FROM v1; +a c +1973-08-14 09:11:22 1 +DROP VIEW v1; +DROP TABLE t1; +# +# Bug 13095459 - MULTI-TABLE UPDATE MODIFIES A ROW TWICE +# +CREATE TABLE t1 ( +a INT, +b INT, +ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, +PRIMARY KEY ( a, ts ) +) ENGINE = INNODB; +INSERT INTO t1( a, b, ts ) VALUES ( 1, 0, '2000-09-28 17:44:34' ); +CREATE TABLE t2 ( a INT ) ENGINE = INNODB; +INSERT INTO t2 VALUES ( 1 ); +UPDATE t1 STRAIGHT_JOIN t2 +SET t1.b = t1.b + 1 +WHERE t1.a = 1 AND t1.ts >= '2000-09-28 00:00:00'; +SELECT b FROM t1; +b +1 +DROP TABLE t1, t2; +# +# Bug#11745578: 17392: ALTER TABLE ADD COLUMN TIMESTAMP DEFAULT +# CURRENT_TIMESTAMP INSERTS ZERO +# +SET timestamp = 1000; +CREATE TABLE t1 ( b INT ); +INSERT INTO t1 VALUES (1); +ALTER TABLE t1 ADD COLUMN a6 DATETIME DEFAULT NOW() ON UPDATE NOW() FIRST; +ALTER TABLE t1 ADD COLUMN a5 DATETIME DEFAULT NOW() FIRST; +ALTER TABLE t1 ADD COLUMN a4 DATETIME ON UPDATE NOW() FIRST; +ALTER TABLE t1 ADD COLUMN a3 TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() FIRST; +ALTER TABLE t1 ADD COLUMN a2 TIMESTAMP NOT NULL DEFAULT NOW() FIRST; +ALTER TABLE t1 ADD COLUMN a1 TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE NOW() FIRST; +ALTER TABLE t1 ADD COLUMN c1 TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE NOW() AFTER b; +ALTER TABLE t1 ADD COLUMN c2 TIMESTAMP NOT NULL DEFAULT NOW() AFTER c1; +ALTER TABLE t1 ADD COLUMN c3 TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE NOW() AFTER c2; +ALTER TABLE t1 ADD COLUMN c4 DATETIME ON UPDATE NOW() AFTER c3; +ALTER TABLE t1 ADD COLUMN c5 DATETIME DEFAULT NOW() AFTER c4; +ALTER TABLE t1 ADD COLUMN c6 DATETIME DEFAULT NOW() ON UPDATE NOW() AFTER c5; +SELECT * FROM t1; +a1 a2 a3 a4 a5 a6 b c1 c2 c3 c4 c5 c6 +0000-00-00 00:00:00 1970-01-01 03:16:40 1970-01-01 03:16:40 NULL 1970-01-01 03:16:40 1970-01-01 03:16:40 1 0000-00-00 00:00:00 1970-01-01 03:16:40 1970-01-01 03:16:40 NULL 1970-01-01 03:16:40 1970-01-01 03:16:40 +DROP TABLE t1; +CREATE TABLE t1 ( a TIMESTAMP NOT NULL DEFAULT NOW() ON UPDATE CURRENT_TIMESTAMP, b DATETIME DEFAULT NOW() ); +INSERT INTO t1 VALUES (); +SET timestamp = 1000000000; +ALTER TABLE t1 MODIFY COLUMN a TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP(3); +ALTER TABLE t1 MODIFY COLUMN b DATETIME(3) DEFAULT CURRENT_TIMESTAMP(3); +SELECT * FROM t1; +a b +1970-01-01 03:16:40.000 1970-01-01 03:16:40.000 +DROP TABLE t1; +CREATE TABLE t1 ( +a TIMESTAMP NOT NULL DEFAULT '1999-12-01 11:22:33' ON UPDATE CURRENT_TIMESTAMP, +b DATETIME DEFAULT '1999-12-01 11:22:33' +); +INSERT INTO t1 VALUES (); +ALTER TABLE t1 MODIFY COLUMN a TIMESTAMP DEFAULT NOW(); +ALTER TABLE t1 MODIFY COLUMN b DATETIME DEFAULT NOW(); +INSERT INTO t1 VALUES (); +SELECT * FROM t1; +a b +1999-12-01 11:22:33 1999-12-01 11:22:33 +2001-09-09 04:46:40 2001-09-09 04:46:40 +DROP TABLE t1; +# +# Function defaults run 2. Six digits scale on seconds precision. +# +SET TIME_ZONE = "+00:00"; +# +# Test of errors for column data types that dont support function +# defaults. +# +CREATE TABLE t1( a BIT DEFAULT CURRENT_TIMESTAMP(6) ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a TINYINT DEFAULT CURRENT_TIMESTAMP(6) ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a SMALLINT DEFAULT CURRENT_TIMESTAMP(6) ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a MEDIUMINT DEFAULT CURRENT_TIMESTAMP(6) ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a INT DEFAULT CURRENT_TIMESTAMP(6) ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a BIGINT DEFAULT CURRENT_TIMESTAMP(6) ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a FLOAT DEFAULT CURRENT_TIMESTAMP(6) ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a DECIMAL DEFAULT CURRENT_TIMESTAMP(6) ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a DATE DEFAULT CURRENT_TIMESTAMP(6) ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a TIME DEFAULT CURRENT_TIMESTAMP(6) ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a YEAR DEFAULT CURRENT_TIMESTAMP(6) ); +ERROR 42000: Invalid default value for 'a' +CREATE TABLE t1( a BIT ON UPDATE CURRENT_TIMESTAMP(6) ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a TINYINT ON UPDATE CURRENT_TIMESTAMP(6) ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a SMALLINT ON UPDATE CURRENT_TIMESTAMP(6) ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a MEDIUMINT ON UPDATE CURRENT_TIMESTAMP(6) ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a INT ON UPDATE CURRENT_TIMESTAMP(6) ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a BIGINT ON UPDATE CURRENT_TIMESTAMP(6) ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a FLOAT ON UPDATE CURRENT_TIMESTAMP(6) ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a DECIMAL ON UPDATE CURRENT_TIMESTAMP(6) ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a DATE ON UPDATE CURRENT_TIMESTAMP(6) ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a TIME ON UPDATE CURRENT_TIMESTAMP(6) ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +CREATE TABLE t1( a YEAR ON UPDATE CURRENT_TIMESTAMP(6) ); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +# +# Test that the default clause behaves like NOW() regarding time zones. +# +CREATE TABLE t1 ( +a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +c TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +d TIMESTAMP(6) NULL, +e DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +f DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6), +g DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6), +h DATETIME(6) +); +# 2011-09-27 14:11:08 UTC +SET TIMESTAMP = 1317132668.654321; +SET @old_time_zone = @@TIME_ZONE; +SET TIME_ZONE = "+05:00"; +INSERT INTO t1( d, h ) VALUES ( NOW(6), NOW(6) ); +SELECT * FROM t1; +a b c d e f g h +2011-09-27 19:11:08.654321 2011-09-27 19:11:08.654321 0000-00-00 00:00:00.000000 2011-09-27 19:11:08.654321 2011-09-27 19:11:08.654321 2011-09-27 19:11:08.654321 NULL 2011-09-27 19:11:08.654321 +# 1989-05-13 01:02:03 +SET TIMESTAMP = 611017323.543212; +UPDATE t1 SET d = NOW(6), h = NOW(6); +SELECT * FROM t1; +a b c d e f g h +1989-05-13 04:02:03.543212 2011-09-27 19:11:08.654321 1989-05-13 04:02:03.543212 1989-05-13 04:02:03.543212 1989-05-13 04:02:03.543212 2011-09-27 19:11:08.654321 1989-05-13 04:02:03.543212 1989-05-13 04:02:03.543212 +SET TIME_ZONE = @old_time_zone; +DROP TABLE t1; +# +# Test of several TIMESTAMP columns with different function defaults. +# +CREATE TABLE t1 ( +a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +c TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +d TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +e TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +f INT +); +# 2011-04-19 07:22:02 UTC +SET TIMESTAMP = 1303197722.534231; +INSERT INTO t1 ( f ) VALUES (1); +SELECT * FROM t1; +a b c d e f +2011-04-19 07:22:02.534231 2011-04-19 07:22:02.534231 2011-04-19 07:22:02.534231 0000-00-00 00:00:00.000000 0000-00-00 00:00:00.000000 1 +# 2011-04-19 07:23:18 UTC +SET TIMESTAMP = 1303197798.132435; +UPDATE t1 SET f = 2; +SELECT * FROM t1; +a b c d e f +2011-04-19 07:23:18.132435 2011-04-19 07:23:18.132435 2011-04-19 07:22:02.534231 2011-04-19 07:23:18.132435 2011-04-19 07:23:18.132435 2 +DROP TABLE t1; +# +# Test of inserted values out of order. +# +CREATE TABLE t1 ( +a INT, +b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +c TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +d TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +e TIMESTAMP(6) NULL, +f DATETIME(6), +g DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6), +h DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6), +i DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +j INT +); +# 2011-04-19 07:22:02 UTC +SET TIMESTAMP = 1303197722.534231; +INSERT INTO t1 ( j, a ) VALUES ( 1, 1 ); +SELECT * FROM t1; +a b c d e f g h i j +1 2011-04-19 07:22:02.534231 2011-04-19 07:22:02.534231 0000-00-00 00:00:00.000000 NULL NULL 2011-04-19 07:22:02.534231 NULL 2011-04-19 07:22:02.534231 1 +DROP TABLE t1; +# +# Test of ON DUPLICATE KEY UPDATE +# +CREATE TABLE t1 ( +a INT PRIMARY KEY, +b INT, +c TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +d TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +e TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +f TIMESTAMP(6) NOT NULL DEFAULT '1986-09-27 03:00:00.098765', +g TIMESTAMP(6) NULL, +h DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +i DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6), +j DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6), +k DATETIME(6) NULL, +l DATETIME(6) DEFAULT '1986-09-27 03:00:00.098765' +); +# 1977-12-21 23:00:00 UTC +SET TIMESTAMP = 251593200.192837; +INSERT INTO t1(a) VALUES (1) ON DUPLICATE KEY UPDATE b = 2; +SELECT * FROM t1; +a b c d e f g h i j k l +1 NULL 1977-12-21 23:00:00.192837 1977-12-21 23:00:00.192837 0000-00-00 00:00:00.000000 1986-09-27 03:00:00.098765 NULL 1977-12-21 23:00:00.192837 1977-12-21 23:00:00.192837 NULL NULL 1986-09-27 03:00:00.098765 +# 1975-05-21 23:00:00 UTC +SET TIMESTAMP = 169945200.918273; +INSERT INTO t1(a) VALUES (1) ON DUPLICATE KEY UPDATE b = 2; +SELECT * FROM t1; +a b c d e f g h i j k l +1 2 1975-05-21 23:00:00.918273 1977-12-21 23:00:00.192837 1975-05-21 23:00:00.918273 1986-09-27 03:00:00.098765 NULL 1975-05-21 23:00:00.918273 1977-12-21 23:00:00.192837 1975-05-21 23:00:00.918273 NULL 1986-09-27 03:00:00.098765 +# 1973-08-14 09:11:22 UTC +SET TIMESTAMP = 114167482.534231; +INSERT INTO t1(a) VALUES (2) ON DUPLICATE KEY UPDATE b = 2; +SELECT * FROM t1; +a b c d e f g h i j k l +1 2 1975-05-21 23:00:00.918273 1977-12-21 23:00:00.192837 1975-05-21 23:00:00.918273 1986-09-27 03:00:00.098765 NULL 1975-05-21 23:00:00.918273 1977-12-21 23:00:00.192837 1975-05-21 23:00:00.918273 NULL 1986-09-27 03:00:00.098765 +2 NULL 1973-08-14 09:11:22.534231 1973-08-14 09:11:22.534231 0000-00-00 00:00:00.000000 1986-09-27 03:00:00.098765 NULL 1973-08-14 09:11:22.534231 1973-08-14 09:11:22.534231 NULL NULL 1986-09-27 03:00:00.098765 +DROP TABLE t1; +CREATE TABLE t1 ( a INT PRIMARY KEY, b INT, c TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) ); +# 2011-04-19 07:23:18 UTC +SET TIMESTAMP = 1303197798.945156; +INSERT INTO t1 VALUES +(1, 0, '2001-01-01 01:01:01.111111'), +(2, 0, '2002-02-02 02:02:02.222222'), +(3, 0, '2003-03-03 03:03:03.333333'); +SELECT * FROM t1; +a b c +1 0 2001-01-01 01:01:01.111111 +2 0 2002-02-02 02:02:02.222222 +3 0 2003-03-03 03:03:03.333333 +UPDATE t1 SET b = 2, c = c WHERE a = 2; +SELECT * FROM t1; +a b c +1 0 2001-01-01 01:01:01.111111 +2 2 2002-02-02 02:02:02.222222 +3 0 2003-03-03 03:03:03.333333 +INSERT INTO t1 (a) VALUES (4); +SELECT * FROM t1; +a b c +1 0 2001-01-01 01:01:01.111111 +2 2 2002-02-02 02:02:02.222222 +3 0 2003-03-03 03:03:03.333333 +4 NULL 2011-04-19 07:23:18.945156 +UPDATE t1 SET c = '2004-04-04 04:04:04.444444' WHERE a = 4; +SELECT * FROM t1; +a b c +1 0 2001-01-01 01:01:01.111111 +2 2 2002-02-02 02:02:02.222222 +3 0 2003-03-03 03:03:03.333333 +4 NULL 2004-04-04 04:04:04.444444 +INSERT INTO t1 ( a ) VALUES ( 3 ), ( 5 ) ON DUPLICATE KEY UPDATE b = 3, c = c; +SELECT * FROM t1; +a b c +1 0 2001-01-01 01:01:01.111111 +2 2 2002-02-02 02:02:02.222222 +3 3 2003-03-03 03:03:03.333333 +4 NULL 2004-04-04 04:04:04.444444 +5 NULL 2011-04-19 07:23:18.945156 +INSERT INTO t1 (a, c) VALUES +(4, '2004-04-04 00:00:00.444444'), +(6, '2006-06-06 06:06:06.666666') +ON DUPLICATE KEY UPDATE b = 4; +SELECT * FROM t1; +a b c +1 0 2001-01-01 01:01:01.111111 +2 2 2002-02-02 02:02:02.222222 +3 3 2003-03-03 03:03:03.333333 +4 4 2011-04-19 07:23:18.945156 +5 NULL 2011-04-19 07:23:18.945156 +6 NULL 2006-06-06 06:06:06.666666 +DROP TABLE t1; +# +# Test of REPLACE INTO executed as UPDATE. +# +CREATE TABLE t1 ( +a INT PRIMARY KEY, +b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +c DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +d TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +e DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6), +f TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +g DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6), +h TIMESTAMP(6) NULL, +i DATETIME(6) +); +# 1970-09-21 09:11:12 UTC +SET TIMESTAMP = 22756272.163584; +REPLACE INTO t1 ( a ) VALUES ( 1 ); +SELECT * FROM t1; +a b c d e f g h i +1 1970-09-21 09:11:12.163584 1970-09-21 09:11:12.163584 1970-09-21 09:11:12.163584 1970-09-21 09:11:12.163584 0000-00-00 00:00:00.000000 NULL NULL NULL +# 1970-11-10 14:16:17 UTC +SET TIMESTAMP = 27094577.852954; +REPLACE INTO t1 ( a ) VALUES ( 1 ); +SELECT * FROM t1; +a b c d e f g h i +1 1970-11-10 14:16:17.852954 1970-11-10 14:16:17.852954 1970-11-10 14:16:17.852954 1970-11-10 14:16:17.852954 0000-00-00 00:00:00.000000 NULL NULL NULL +DROP TABLE t1; +# +# Test of insertion of NULL, DEFAULT and an empty row for DEFAULT +# CURRENT_TIMESTAMP. +# +CREATE TABLE t1 ( +a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +b DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6), +c INT +); +# 2011-04-20 09:53:41 UTC +SET TIMESTAMP = 1303293221.163578; +INSERT INTO t1 VALUES (NULL, NULL, 1), (DEFAULT, DEFAULT, 2); +INSERT INTO t1 ( a, b, c ) VALUES (NULL, NULL, 3), (DEFAULT, DEFAULT, 4); +SELECT * FROM t1; +a b c +2011-04-20 09:53:41.163578 NULL 1 +2011-04-20 09:53:41.163578 2011-04-20 09:53:41.163578 2 +2011-04-20 09:53:41.163578 NULL 3 +2011-04-20 09:53:41.163578 2011-04-20 09:53:41.163578 4 +SET TIME_ZONE = "+03:00"; +SELECT * FROM t1; +a b c +2011-04-20 12:53:41.163578 NULL 1 +2011-04-20 12:53:41.163578 2011-04-20 09:53:41.163578 2 +2011-04-20 12:53:41.163578 NULL 3 +2011-04-20 12:53:41.163578 2011-04-20 09:53:41.163578 4 +SET TIME_ZONE = "+00:00"; +DROP TABLE t1; +# 2011-04-20 07:05:39 UTC +SET TIMESTAMP = 1303283139.195624; +CREATE TABLE t1 ( +a TIMESTAMP(6) NOT NULL DEFAULT '2010-10-11 12:34:56' ON UPDATE CURRENT_TIMESTAMP(6), +b DATETIME(6) DEFAULT '2010-10-11 12:34:56' +); +INSERT INTO t1 VALUES (NULL, NULL), (DEFAULT, DEFAULT); +INSERT INTO t1 ( a, b ) VALUES (NULL, NULL), (DEFAULT, DEFAULT); +SELECT * FROM t1; +a b +2011-04-20 07:05:39.195624 NULL +2010-10-11 12:34:56.000000 2010-10-11 12:34:56.000000 +2011-04-20 07:05:39.195624 NULL +2010-10-11 12:34:56.000000 2010-10-11 12:34:56.000000 +DROP TABLE t1; +# 2011-04-20 09:53:41 UTC +SET TIMESTAMP = 1303293221.136952; +CREATE TABLE t1 ( +a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +c TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +d TIMESTAMP(6) NOT NULL DEFAULT '1986-09-27 03:00:00.098765', +e TIMESTAMP(6) NULL, +f DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +g DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6), +h DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6), +i DATETIME(6) NULL, +j DATETIME(6) DEFAULT '1986-09-27 03:00:00.098765' +); +INSERT INTO t1 VALUES (); +INSERT INTO t1 SELECT NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL; +SELECT * FROM t1; +a b c d e f g h i j +2011-04-20 09:53:41.136952 2011-04-20 09:53:41.136952 0000-00-00 00:00:00.000000 1986-09-27 03:00:00.098765 NULL 2011-04-20 09:53:41.136952 2011-04-20 09:53:41.136952 NULL NULL 1986-09-27 03:00:00.098765 +2011-04-20 09:53:41.136952 2011-04-20 09:53:41.136952 2011-04-20 09:53:41.136952 2011-04-20 09:53:41.136952 NULL NULL NULL NULL NULL NULL +DROP TABLE t1; +# +# Test of multiple-table UPDATE for DEFAULT CURRENT_TIMESTAMP +# +CREATE TABLE t1 ( +a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +b DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6), +c INT +); +INSERT INTO t1 ( c ) VALUES (1); +SELECT * FROM t1; +a b c +2011-04-20 09:53:41.136952 2011-04-20 09:53:41.136952 1 +# 2011-04-20 17:06:13 UTC +SET TIMESTAMP = 1303311973.163587; +UPDATE t1 t11, t1 t12 SET t11.c = 1; +SELECT * FROM t1; +a b c +2011-04-20 09:53:41.136952 2011-04-20 09:53:41.136952 1 +UPDATE t1 t11, t1 t12 SET t11.c = 2; +SELECT * FROM t1; +a b c +2011-04-20 15:06:13.163587 2011-04-20 09:53:41.136952 2 +DROP TABLE t1; +CREATE TABLE t1 ( +a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +b TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +c DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6), +d DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6), +e INT +); +CREATE TABLE t2 ( +f INT, +g DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6), +h DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6), +i TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +j TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) +); +# 1995-03-11 00:02:03 UTC +SET TIMESTAMP = 794880123.195676; +INSERT INTO t1 ( e ) VALUES ( 1 ), ( 2 ); +INSERT INTO t2 ( f ) VALUES ( 1 ), ( 2 ); +SELECT * FROM t1; +a b c d e +1995-03-11 00:02:03.195676 0000-00-00 00:00:00.000000 1995-03-11 00:02:03.195676 NULL 1 +1995-03-11 00:02:03.195676 0000-00-00 00:00:00.000000 1995-03-11 00:02:03.195676 NULL 2 +SELECT * FROM t2; +f g h i j +1 NULL 1995-03-11 00:02:03.195676 0000-00-00 00:00:00.000000 1995-03-11 00:02:03.195676 +2 NULL 1995-03-11 00:02:03.195676 0000-00-00 00:00:00.000000 1995-03-11 00:02:03.195676 +# 1980-12-13 02:02:01 UTC +SET TIMESTAMP = 345520921.196755; +UPDATE t1, t2 SET t1.e = 3, t2.f = 4; +SELECT * FROM t1; +a b c d e +1995-03-11 00:02:03.195676 1980-12-13 02:02:01.196755 1995-03-11 00:02:03.195676 1980-12-13 02:02:01.196755 3 +1995-03-11 00:02:03.195676 1980-12-13 02:02:01.196755 1995-03-11 00:02:03.195676 1980-12-13 02:02:01.196755 3 +SELECT * FROM t2; +f g h i j +4 1980-12-13 02:02:01.196755 1995-03-11 00:02:03.195676 1980-12-13 02:02:01.196755 1995-03-11 00:02:03.195676 +4 1980-12-13 02:02:01.196755 1995-03-11 00:02:03.195676 1980-12-13 02:02:01.196755 1995-03-11 00:02:03.195676 +DROP TABLE t1, t2; +# +# Test of multiple table update with temporary table and on the fly. +# +CREATE TABLE t1 ( +a TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +b DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6), +c INT, +d INT +); +CREATE TABLE t2 ( +a TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +b DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6), +c INT KEY, +d INT +); +INSERT INTO t1 ( c ) VALUES (1), (2); +INSERT INTO t2 ( c ) VALUES (1), (2); +# Test of multiple table update done on the fly +# 2011-04-20 15:06:13 UTC +SET TIMESTAMP = 1303311973.194685; +UPDATE t1 JOIN t2 USING ( c ) SET t2.d = 1; +SELECT * FROM t1; +a b c d +0000-00-00 00:00:00.000000 NULL 1 NULL +0000-00-00 00:00:00.000000 NULL 2 NULL +SELECT * FROM t2; +a b c d +2011-04-20 15:06:13.194685 2011-04-20 15:06:13.194685 1 1 +2011-04-20 15:06:13.194685 2011-04-20 15:06:13.194685 2 1 +# Test of multiple table update done with temporary table. +# 1979-01-15 03:02:01 +SET TIMESTAMP = 285213721.134679; +UPDATE t1 JOIN t2 USING ( c ) SET t1.d = 1; +SELECT * FROM t1; +a b c d +1979-01-15 02:02:01.134679 1979-01-15 02:02:01.134679 1 1 +1979-01-15 02:02:01.134679 1979-01-15 02:02:01.134679 2 1 +SELECT * FROM t2; +a b c d +2011-04-20 15:06:13.194685 2011-04-20 15:06:13.194685 1 1 +2011-04-20 15:06:13.194685 2011-04-20 15:06:13.194685 2 1 +DROP TABLE t1, t2; +# +# Test of ON UPDATE CURRENT_TIMESTAMP. +# +CREATE TABLE t1 ( +a TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +b DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6), +c INT +); +# 2011-04-20 09:53:41 UTC +SET TIMESTAMP = 1303293221.794613; +INSERT INTO t1 ( c ) VALUES ( 1 ); +SELECT * FROM t1; +a b c +0000-00-00 00:00:00.000000 NULL 1 +UPDATE t1 SET c = 1; +SELECT * FROM t1; +a b c +0000-00-00 00:00:00.000000 NULL 1 +UPDATE t1 SET c = 2; +SELECT * FROM t1; +a b c +2011-04-20 09:53:41.794613 2011-04-20 09:53:41.794613 2 +# +# Test of multiple-table UPDATE for ON UPDATE CURRENT_TIMESTAMP +# +# 2011-04-20 15:06:13 UTC +SET TIMESTAMP = 1303311973.534231; +UPDATE t1 t11, t1 t12 SET t11.c = 2; +SELECT * FROM t1; +a b c +2011-04-20 09:53:41.794613 2011-04-20 09:53:41.794613 2 +UPDATE t1 t11, t1 t12 SET t11.c = 3; +SELECT * FROM t1; +a b c +2011-04-20 15:06:13.534231 2011-04-20 15:06:13.534231 3 +DROP TABLE t1; +# +# Test of a multiple-table update where only one table is updated and +# the updated table has a primary key. +# +CREATE TABLE t1 ( a INT, b INT, PRIMARY KEY (a) ); +INSERT INTO t1 VALUES (1, 1),(2, 2),(3, 3),(4, 4); +CREATE TABLE t2 ( a INT, b INT ); +INSERT INTO t2 VALUES (1, 1),(2, 2),(3, 3),(4, 4),(5, 5); +UPDATE t1, t2 SET t1.b = 100 WHERE t1.a = t2.a; +SELECT * FROM t1; +a b +1 100 +2 100 +3 100 +4 100 +SELECT * FROM t2; +a b +1 1 +2 2 +3 3 +4 4 +5 5 +DROP TABLE t1, t2; +# +# Test of ALTER TABLE, reordering columns. +# +CREATE TABLE t1 ( a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), b INT ); +ALTER TABLE t1 MODIFY a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) AFTER b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) DEFAULT NULL, + `a` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( a INT, b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), c TIMESTAMP(6) NULL ); +ALTER TABLE t1 MODIFY b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) FIRST; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + `a` int(11) DEFAULT NULL, + `c` timestamp(6) NULL DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( a INT, b TIMESTAMP(6) NULL ); +ALTER TABLE t1 MODIFY b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) FIRST; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), b TIMESTAMP(6) NULL ); +ALTER TABLE t1 MODIFY a TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` timestamp(6) NULL DEFAULT NULL, + `a` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), b TIMESTAMP(6) NULL ); +ALTER TABLE t1 MODIFY a TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` timestamp(6) NULL DEFAULT NULL, + `a` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( a TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE NOW(6), b INT, c TIMESTAMP(6) NULL ); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000' ON UPDATE CURRENT_TIMESTAMP(6), + `b` int(11) DEFAULT NULL, + `c` timestamp(6) NULL DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +ALTER TABLE t1 MODIFY a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) AFTER b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) DEFAULT NULL, + `a` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + `c` timestamp(6) NULL DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( a TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE NOW(6), b INT, c TIMESTAMP(6) NULL ); +ALTER TABLE t1 MODIFY c TIMESTAMP(6) NULL FIRST; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` timestamp(6) NULL DEFAULT NULL, + `a` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000' ON UPDATE CURRENT_TIMESTAMP(6), + `b` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( a TIMESTAMP(6) NOT NULL DEFAULT NOW(6) ON UPDATE CURRENT_TIMESTAMP(6), b INT, c TIMESTAMP(6) NULL ); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + `b` int(11) DEFAULT NULL, + `c` timestamp(6) NULL DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +ALTER TABLE t1 MODIFY a TIMESTAMP(6) NOT NULL DEFAULT NOW(6) ON UPDATE CURRENT_TIMESTAMP(6) AFTER b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) DEFAULT NULL, + `a` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + `c` timestamp(6) NULL DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +CREATE TABLE t1 ( a TIMESTAMP(6) NOT NULL DEFAULT NOW(6) ON UPDATE CURRENT_TIMESTAMP(6), b INT, c TIMESTAMP(6) NULL ); +ALTER TABLE t1 MODIFY c TIMESTAMP(6) NULL FIRST; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` timestamp(6) NULL DEFAULT NULL, + `a` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + `b` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +# +# Test of ALTER TABLE, adding columns. +# +CREATE TABLE t1 ( a INT ); +ALTER TABLE t1 ADD COLUMN b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1; +# +# Test of INSERT SELECT. +# +CREATE TABLE t1 ( +a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +c DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +d DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) +); +CREATE TABLE t2 ( +placeholder1 INT, +placeholder2 INT, +placeholder3 INT, +placeholder4 INT, +a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +b TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00', +c DATETIME(6), +d DATETIME(6) +); +# 1977-08-16 15:30:01 UTC +SET TIMESTAMP = 240589801.654312; +INSERT INTO t2 (a, b, c, d) VALUES ( +'1977-08-16 15:30:01.123456', +'1977-08-16 15:30:01.234567', +'1977-08-16 15:30:01.345678', +'1977-08-16 15:30:01.456789' +); +# 1986-09-27 01:00:00 UTC +SET TIMESTAMP = 528166800.132435; +INSERT INTO t1 ( a, c ) SELECT a, c FROM t2; +SELECT * FROM t1; +a b c d +1977-08-16 15:30:01.123456 1986-09-27 01:00:00.132435 1977-08-16 15:30:01.345678 1986-09-27 01:00:00.132435 +DROP TABLE t1, t2; +# +# Test of CREATE TABLE SELECT. +# +# We test that the columns of the source table are not used to determine +# function defaults for the receiving table. +# +# 1970-04-11 20:13:57 UTC +SET TIMESTAMP = 8712837.657898; +CREATE TABLE t1 ( +a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +c TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +d TIMESTAMP(6) NOT NULL DEFAULT '1986-09-27 03:00:00.098765', +e TIMESTAMP(6) NULL, +f DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +g DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6), +h DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6), +i DATETIME(6) NULL, +j DATETIME(6) DEFAULT '1986-09-27 03:00:00.098765' +); +INSERT INTO t1 VALUES (); +# 1971-01-31 21:13:57 UTC +SET TIMESTAMP = 34200837.164937; +CREATE TABLE t2 SELECT a FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +a +1970-04-11 20:13:57.657897 +CREATE TABLE t3 SELECT b FROM t1; +SHOW CREATE TABLE t3; +Table Create Table +t3 CREATE TABLE `t3` ( + `b` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t3; +b +1970-04-11 20:13:57.657897 +CREATE TABLE t4 SELECT c FROM t1; +SHOW CREATE TABLE t4; +Table Create Table +t4 CREATE TABLE `t4` ( + `c` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t4; +c +0000-00-00 00:00:00.000000 +CREATE TABLE t5 SELECT d FROM t1; +SHOW CREATE TABLE t5; +Table Create Table +t5 CREATE TABLE `t5` ( + `d` timestamp(6) NOT NULL DEFAULT '1986-09-27 03:00:00.098765' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t5; +d +1986-09-27 03:00:00.098765 +CREATE TABLE t6 SELECT e FROM t1; +SHOW CREATE TABLE t6; +Table Create Table +t6 CREATE TABLE `t6` ( + `e` timestamp(6) NULL DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t6; +e +NULL +CREATE TABLE t7 SELECT f FROM t1; +SHOW CREATE TABLE t7; +Table Create Table +t7 CREATE TABLE `t7` ( + `f` datetime(6) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t7; +f +1970-04-11 20:13:57.657897 +CREATE TABLE t8 SELECT g FROM t1; +SHOW CREATE TABLE t8; +Table Create Table +t8 CREATE TABLE `t8` ( + `g` datetime(6) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t8; +g +1970-04-11 20:13:57.657897 +CREATE TABLE t9 SELECT h FROM t1; +SHOW CREATE TABLE t9; +Table Create Table +t9 CREATE TABLE `t9` ( + `h` datetime(6) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t9; +h +NULL +CREATE TABLE t10 SELECT i FROM t1; +SHOW CREATE TABLE t10; +Table Create Table +t10 CREATE TABLE `t10` ( + `i` datetime(6) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t10; +i +NULL +CREATE TABLE t11 SELECT j FROM t1; +SHOW CREATE TABLE t11; +Table Create Table +t11 CREATE TABLE `t11` ( + `j` datetime(6) DEFAULT '1986-09-27 03:00:00.098765' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t11; +j +1986-09-27 03:00:00.098765 +CREATE TABLE t12 ( +k TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +l TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +m TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +n TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +o TIMESTAMP(6) NOT NULL DEFAULT '1986-09-27 03:00:00.098765', +p TIMESTAMP(6) NULL, +q DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +r DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6), +s DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6), +t DATETIME(6) NULL, +u DATETIME(6) DEFAULT '1986-09-27 03:00:00.098765' +) +SELECT * FROM t1; +SHOW CREATE TABLE t12; +Table Create Table +t12 CREATE TABLE `t12` ( + `k` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + `l` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + `m` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), + `n` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000' ON UPDATE CURRENT_TIMESTAMP(6), + `o` timestamp(6) NOT NULL DEFAULT '1986-09-27 03:00:00.098765', + `p` timestamp(6) NULL DEFAULT NULL, + `q` datetime(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + `r` datetime(6) DEFAULT CURRENT_TIMESTAMP(6), + `s` datetime(6) DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(6), + `t` datetime(6) DEFAULT NULL, + `u` datetime(6) DEFAULT '1986-09-27 03:00:00.098765', + `a` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000', + `b` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000', + `c` timestamp(6) NOT NULL DEFAULT '0000-00-00 00:00:00.000000', + `d` timestamp(6) NOT NULL DEFAULT '1986-09-27 03:00:00.098765', + `e` timestamp(6) NULL DEFAULT NULL, + `f` datetime(6) DEFAULT NULL, + `g` datetime(6) DEFAULT NULL, + `h` datetime(6) DEFAULT NULL, + `i` datetime(6) DEFAULT NULL, + `j` datetime(6) DEFAULT '1986-09-27 03:00:00.098765' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12; +# 1970-04-11 20:13:57 UTC +SET TIMESTAMP = 8712837.164953; +CREATE TABLE t1 ( +a DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +b DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6), +c DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6), +d DATETIME(6) NULL, +e DATETIME(6) DEFAULT '1986-09-27 03:00:00.098765' +); +INSERT INTO t1 VALUES (); +# 1971-01-31 20:13:57 UTC +SET TIMESTAMP = 34200837.915736; +CREATE TABLE t2 SELECT a FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` datetime(6) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +a +1970-04-11 20:13:57.164953 +CREATE TABLE t3 SELECT b FROM t1; +SHOW CREATE TABLE t3; +Table Create Table +t3 CREATE TABLE `t3` ( + `b` datetime(6) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t3; +b +1970-04-11 20:13:57.164953 +CREATE TABLE t4 SELECT c FROM t1; +SHOW CREATE TABLE t4; +Table Create Table +t4 CREATE TABLE `t4` ( + `c` datetime(6) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t4; +c +NULL +CREATE TABLE t5 SELECT d FROM t1; +SHOW CREATE TABLE t5; +Table Create Table +t5 CREATE TABLE `t5` ( + `d` datetime(6) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t5; +d +NULL +CREATE TABLE t6 SELECT e FROM t1; +SHOW CREATE TABLE t6; +Table Create Table +t6 CREATE TABLE `t6` ( + `e` datetime(6) DEFAULT '1986-09-27 03:00:00.098765' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t6; +e +1986-09-27 03:00:00.098765 +DROP TABLE t1, t2, t3, t4, t5, t6; +# +# Test of a CREATE TABLE SELECT that also declared columns. In this case +# the function default should be de-activated during the execution of the +# CREATE TABLE statement. +# +# 1970-01-01 03:16:40 +SET TIMESTAMP = 1000.987654; +CREATE TABLE t1 ( a INT ); +INSERT INTO t1 VALUES ( 1 ), ( 2 ); +CREATE TABLE t2 ( b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)) SELECT a FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `b` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SET TIMESTAMP = 2000.876543; +INSERT INTO t2( a ) VALUES ( 3 ); +SELECT * FROM t2; +b a +0000-00-00 00:00:00.000000 1 +0000-00-00 00:00:00.000000 2 +1970-01-01 00:33:20.876543 3 +DROP TABLE t1, t2; +# +# Test of updating a view. +# +CREATE TABLE t1 ( a INT, b DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ); +CREATE TABLE t2 ( a INT, b DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6) ); +CREATE VIEW v1 AS SELECT * FROM t1; +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a`,`t1`.`b` AS `b` from `t1` latin1 latin1_swedish_ci +CREATE VIEW v2 AS SELECT * FROM t2; +SHOW CREATE VIEW v2; +View Create View character_set_client collation_connection +v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t2`.`a` AS `a`,`t2`.`b` AS `b` from `t2` latin1 latin1_swedish_ci +# 1971-01-31 21:13:57 UTC +SET TIMESTAMP = 34200837.348564; +INSERT INTO v1 ( a ) VALUES ( 1 ); +INSERT INTO v2 ( a ) VALUES ( 1 ); +SELECT * FROM t1; +a b +1 1971-01-31 20:13:57.348564 +SELECT * FROM v1; +a b +1 1971-01-31 20:13:57.348564 +SELECT * FROM t2; +a b +1 NULL +SELECT * FROM v2; +a b +1 NULL +# 1970-04-11 20:13:57 UTC +SET TIMESTAMP = 8712837.567332; +UPDATE v1 SET a = 2; +UPDATE v2 SET a = 2; +SELECT * FROM t1; +a b +2 1971-01-31 20:13:57.348564 +SELECT * FROM v1; +a b +2 1971-01-31 20:13:57.348564 +SELECT * FROM t2; +a b +2 1970-04-11 20:13:57.567332 +SELECT * FROM v2; +a b +2 1970-04-11 20:13:57.567332 +DROP VIEW v1, v2; +DROP TABLE t1, t2; +# +# Test with stored procedures. +# +CREATE TABLE t1 ( +a INT, +b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +c TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +d TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +e TIMESTAMP(6) NULL, +f DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6), +g DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6) +); +CREATE PROCEDURE p1() INSERT INTO test.t1( a ) VALUES ( 1 ); +CREATE PROCEDURE p2() UPDATE t1 SET a = 2 WHERE a = 1; +# 1971-01-31 20:13:57 UTC +SET TIMESTAMP = 34200837.876544; +CALL p1(); +SELECT * FROM t1; +a b c d e f g +1 1971-01-31 20:13:57.876544 1971-01-31 20:13:57.876544 0000-00-00 00:00:00.000000 NULL 1971-01-31 20:13:57.876544 NULL +# 1970-04-11 21:13:57 UTC +SET TIMESTAMP = 8712837.143546; +CALL p2(); +SELECT * FROM t1; +a b c d e f g +2 1970-04-11 20:13:57.143546 1971-01-31 20:13:57.876544 1970-04-11 20:13:57.143546 NULL 1971-01-31 20:13:57.876544 1970-04-11 20:13:57.143546 +DROP PROCEDURE p1; +DROP PROCEDURE p2; +DROP TABLE t1; +# +# Test with triggers. +# +CREATE TABLE t1 ( +a INT, +b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +c TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +d TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +e TIMESTAMP(6) NULL, +f DATETIME(6), +g DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6), +h DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6), +i DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) +); +CREATE TABLE t2 ( a INT ); +CREATE TRIGGER t2_trg BEFORE INSERT ON t2 FOR EACH ROW +BEGIN +INSERT INTO t1 ( a ) VALUES ( 1 ); +END| +# 1971-01-31 21:13:57 UTC +SET TIMESTAMP = 34200837.978675; +INSERT INTO t2 ( a ) VALUES ( 1 ); +SELECT * FROM t1; +a b c d e f g h i +1 1971-01-31 20:13:57.978675 1971-01-31 20:13:57.978675 0000-00-00 00:00:00.000000 NULL NULL 1971-01-31 20:13:57.978675 NULL 1971-01-31 20:13:57.978675 +DROP TRIGGER t2_trg; +CREATE TRIGGER t2_trg BEFORE INSERT ON t2 FOR EACH ROW +BEGIN +UPDATE t1 SET a = 2; +END| +# 1970-04-11 21:13:57 UTC +SET TIMESTAMP = 8712837.456789; +INSERT INTO t2 ( a ) VALUES ( 1 ); +SELECT * FROM t1; +a b c d e f g h i +2 1970-04-11 20:13:57.456789 1971-01-31 20:13:57.978675 1970-04-11 20:13:57.456789 NULL NULL 1971-01-31 20:13:57.978675 1970-04-11 20:13:57.456789 1970-04-11 20:13:57.456789 +DROP TABLE t1, t2; +# +# Test where the assignment target is not a column. +# +CREATE TABLE t1 ( a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) ); +CREATE TABLE t2 ( a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) ); +CREATE TABLE t3 ( a TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6) ); +CREATE TABLE t4 ( a TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6) ); +CREATE VIEW v1 AS SELECT a COLLATE latin1_german1_ci AS b FROM t1; +CREATE VIEW v2 ( b ) AS SELECT a COLLATE latin1_german1_ci FROM t2; +CREATE VIEW v3 AS SELECT a COLLATE latin1_german1_ci AS b FROM t3; +CREATE VIEW v4 ( b ) AS SELECT a COLLATE latin1_german1_ci FROM t4; +INSERT INTO v1 ( b ) VALUES ( '2007-10-24 00:03:34.010203' ); +SELECT a FROM t1; +a +2007-10-24 00:03:34.010203 +INSERT INTO v2 ( b ) VALUES ( '2007-10-24 00:03:34.010203' ); +SELECT a FROM t2; +a +2007-10-24 00:03:34.010203 +INSERT INTO t3 VALUES (); +UPDATE v3 SET b = '2007-10-24 00:03:34.010203'; +SELECT a FROM t3; +a +2007-10-24 00:03:34.010203 +INSERT INTO t4 VALUES (); +UPDATE v4 SET b = '2007-10-24 00:03:34.010203'; +SELECT a FROM t4; +a +2007-10-24 00:03:34.010203 +DROP VIEW v1, v2, v3, v4; +DROP TABLE t1, t2, t3, t4; +# +# Test of LOAD DATA/XML INFILE +# This tests behavior of function defaults for TIMESTAMP and DATETIME +# columns. during LOAD ... INFILE. +# As can be seen here, a TIMESTAMP column with only ON UPDATE +# CURRENT_TIMESTAMP will still have CURRENT_TIMESTAMP inserted on LOAD +# ... INFILE if the value is missing. For DATETIME columns a NULL value +# is inserted instead. +# +CREATE TABLE t1 ( +a INT, +b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +c TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +d TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +e TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +f DATETIME(6), +g DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6), +h DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6), +i DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) +); +CREATE TABLE t2 ( +a TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +c TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP(6), +d TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +e DATETIME(6) NOT NULL, +f DATETIME(6) NOT NULL DEFAULT '1977-01-02 12:13:14', +g DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) NOT NULL, +h DATETIME(6) ON UPDATE CURRENT_TIMESTAMP(6) NOT NULL, +i DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) NOT NULL +); +SELECT 1 INTO OUTFILE 't3.dat' FROM dual; +SELECT NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL +INTO OUTFILE 't4.dat' +FROM dual; +SELECT 1, 2 INTO OUTFILE 't5.dat' FROM dual; +# Mon Aug 1 15:11:19 2011 UTC +SET TIMESTAMP = 1312211479.918273; +LOAD DATA INFILE 't3.dat' INTO TABLE t1; +Warnings: +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +SELECT * FROM t1; +a 1 +b 2011-08-01 15:11:19.918273 +c 2011-08-01 15:11:19.918273 +d 2011-08-01 15:11:19.918273 +e 2011-08-01 15:11:19.918273 +f NULL +g NULL +h NULL +i NULL +LOAD DATA INFILE 't4.dat' INTO TABLE t2; +Warnings: +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'e' at row 1 +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'f' at row 1 +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'g' at row 1 +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'h' at row 1 +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'i' at row 1 +SELECT a FROM t2; +a +2011-08-01 15:11:19.918273 +SELECT b FROM t2; +b +2011-08-01 15:11:19.918273 +SELECT c FROM t2; +c +2011-08-01 15:11:19.918273 +SELECT d FROM t2; +d +2011-08-01 15:11:19.918273 +# As shown here, supplying a NULL value to a non-nullable +# column with no default value results in the zero date. +SELECT e FROM t2; +e +0000-00-00 00:00:00.000000 +# As shown here, supplying a NULL value to a non-nullable column with a +# default value results in the zero date. +SELECT f FROM t2; +f +0000-00-00 00:00:00.000000 +# As shown here, supplying a NULL value to a non-nullable column with a +# default function results in the zero date. +SELECT g FROM t2; +g +0000-00-00 00:00:00.000000 +# As shown here, supplying a NULL value to a non-nullable DATETIME ON +# UPDATE CURRENT_TIMESTAMP column with no default value results in the +# zero date. +SELECT h FROM t2; +h +0000-00-00 00:00:00.000000 +SELECT i FROM t2; +i +0000-00-00 00:00:00.000000 +DELETE FROM t1; +DELETE FROM t2; +# Read t3 file into t1 +# The syntax will cause a different code path to be taken +# (read_fixed_length()) than under the LOAD ... INTO TABLE t1 command +# above. The code in this path is copy-pasted code from the path taken +# under the syntax used in the previous LOAD command. +LOAD DATA INFILE 't3.dat' INTO TABLE t1 +FIELDS TERMINATED BY '' ENCLOSED BY ''; +Warnings: +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +SELECT b FROM t1; +b +2011-08-01 15:11:19.918273 +SELECT c FROM t1; +c +2011-08-01 15:11:19.918273 +SELECT d FROM t1; +d +2011-08-01 15:11:19.918273 +SELECT e FROM t1; +e +2011-08-01 15:11:19.918273 +# Yes, a missing field cannot be NULL using this syntax, so it will +# zero date instead. Says a comment in read_fixed_length() : "No fields +# specified in fields_vars list can be NULL in this format." +# It appears to be by design. This is inconsistent with LOAD DATA INFILE +# syntax in previous test. +SELECT f FROM t1; +f +0000-00-00 00:00:00.000000 +SELECT g FROM t1; +g +0000-00-00 00:00:00.000000 +# See comment above "SELECT f FROM f1". +SELECT h FROM t1; +h +0000-00-00 00:00:00.000000 +SELECT i FROM t1; +i +0000-00-00 00:00:00.000000 +DELETE FROM t1; +LOAD DATA INFILE 't5.dat' INTO TABLE t1 ( a, @dummy ); +SELECT * FROM t1; +a b c d e f g h i +1 2011-08-01 15:11:19.918273 2011-08-01 15:11:19.918273 0000-00-00 00:00:00.000000 2011-08-01 15:11:19.918273 NULL 2011-08-01 15:11:19.918273 NULL 2011-08-01 15:11:19.918273 +SELECT @dummy; +@dummy +2 +DELETE FROM t1; +LOAD DATA INFILE 't3.dat' INTO TABLE t1 ( a ) SET c = '2005-06-06 08:09:10'; +SELECT * FROM t1; +a b c d e f g h i +1 2011-08-01 15:11:19.918273 2005-06-06 08:09:10.000000 0000-00-00 00:00:00.000000 2011-08-01 15:11:19.918273 NULL 2011-08-01 15:11:19.918273 NULL 2011-08-01 15:11:19.918273 +DELETE FROM t1; +LOAD DATA INFILE 't3.dat' INTO TABLE t1 ( a ) SET g = '2005-06-06 08:09:10'; +SELECT * FROM t1; +a b c d e f g h i +1 2011-08-01 15:11:19.918273 2011-08-01 15:11:19.918273 0000-00-00 00:00:00.000000 2011-08-01 15:11:19.918273 NULL 2005-06-06 08:09:10.000000 NULL 2011-08-01 15:11:19.918273 +DELETE FROM t1; +# Load a static XML file +LOAD XML INFILE '../../std_data/onerow.xml' INTO TABLE t1 +ROWS IDENTIFIED BY '<row>'; +Missing tags are treated as NULL +SELECT * FROM t1; +a 1 +b 2011-08-01 15:11:19.918273 +c 2011-08-01 15:11:19.918273 +d 2011-08-01 15:11:19.918273 +e 2011-08-01 15:11:19.918273 +f NULL +g NULL +h NULL +i NULL +DROP TABLE t1, t2; +# +# Similar LOAD DATA tests in another form +# +# All of this test portion has been run on a pre-WL5874 trunk +# (except that like_b and like_c didn't exist) and all result +# differences are a bug. +# Regarding like_b its definition is the same as b's except +# that the constant default is replaced with a function +# default. Our expectation is that like_b would behave +# like b: if b is set to NULL, or set to 0000-00-00, or set to +# its default, then the same should apply to like_b. Same for +# like_c vs c. +# Mon Aug 1 15:11:19 2011 UTC +SET TIMESTAMP = 1312211479.089786; +SELECT 1 INTO OUTFILE "file1.dat" FROM dual; +SELECT NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL +INTO OUTFILE "file2.dat" FROM dual; +# Too short row +CREATE TABLE t1 ( +dummy INT, +a DATETIME(6) NULL DEFAULT NULL, +b DATETIME(6) NULL DEFAULT "2011-11-18", +like_b DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6), +c DATETIME(6) NOT NULL DEFAULT "2011-11-18", +like_c DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +d TIMESTAMP(6) NULL DEFAULT "2011-05-03" ON UPDATE CURRENT_TIMESTAMP(6), +e TIMESTAMP(6) NOT NULL DEFAULT "2011-05-03", +f TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +g TIMESTAMP(6) NULL DEFAULT NULL, +h INT NULL, +i INT NOT NULL DEFAULT 42 +); +# There is no promotion +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `dummy` int(11) DEFAULT NULL, + `a` datetime(6) DEFAULT NULL, + `b` datetime(6) DEFAULT '2011-11-18 00:00:00.000000', + `like_b` datetime(6) DEFAULT CURRENT_TIMESTAMP(6), + `c` datetime(6) NOT NULL DEFAULT '2011-11-18 00:00:00.000000', + `like_c` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), + `d` timestamp(6) NULL DEFAULT '2011-05-03 00:00:00.000000' ON UPDATE CURRENT_TIMESTAMP(6), + `e` timestamp(6) NOT NULL DEFAULT '2011-05-03 00:00:00.000000', + `f` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), + `g` timestamp(6) NULL DEFAULT NULL, + `h` int(11) DEFAULT NULL, + `i` int(11) NOT NULL DEFAULT '42' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +LOAD DATA INFILE "file1.dat" INTO table t1; +Warnings: +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +# It is strange that "like_b" gets NULL when "b" gets 0. But +# this is consistent with how "a" gets NULL when "b" gets 0, +# with how "g" gets NULL when "d" gets 0, and with how "h" gets +# NULL when "i" gets 0. Looks like "DEFAULT +# <non-NULL-constant>" is changed to 0, whereas DEFAULT NULL +# and DEFAULT NOW are changed to NULL. +SELECT * FROM t1; +dummy 1 +a NULL +b 0000-00-00 00:00:00.000000 +like_b NULL +c 0000-00-00 00:00:00.000000 +like_c 0000-00-00 00:00:00.000000 +d 0000-00-00 00:00:00.000000 +e 2011-08-01 15:11:19.089786 +f 2011-08-01 15:11:19.089786 +g NULL +h NULL +i 0 +delete from t1; +alter table t1 +modify f TIMESTAMP NULL default CURRENT_TIMESTAMP; +# There is no promotion +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `dummy` int(11) DEFAULT NULL, + `a` datetime(6) DEFAULT NULL, + `b` datetime(6) DEFAULT '2011-11-18 00:00:00.000000', + `like_b` datetime(6) DEFAULT CURRENT_TIMESTAMP(6), + `c` datetime(6) NOT NULL DEFAULT '2011-11-18 00:00:00.000000', + `like_c` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), + `d` timestamp(6) NULL DEFAULT '2011-05-03 00:00:00.000000' ON UPDATE CURRENT_TIMESTAMP(6), + `e` timestamp(6) NOT NULL DEFAULT '2011-05-03 00:00:00.000000', + `f` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `g` timestamp(6) NULL DEFAULT NULL, + `h` int(11) DEFAULT NULL, + `i` int(11) NOT NULL DEFAULT '42' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +LOAD DATA INFILE "file1.dat" INTO table t1; +Warnings: +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +Warning 1261 Row 1 doesn't contain data for all columns +SELECT * FROM t1; +dummy 1 +a NULL +b 0000-00-00 00:00:00.000000 +like_b NULL +c 0000-00-00 00:00:00.000000 +like_c 0000-00-00 00:00:00.000000 +d 0000-00-00 00:00:00.000000 +e 2011-08-01 15:11:19.089786 +f NULL +g NULL +h NULL +i 0 +delete from t1; +drop table t1; +# Conclusion derived from trunk's results: +# DATETIME DEFAULT <non-NULL-constant> (b,c) gets 0000-00-00, +# DATETIME DEFAULT NULL (a) gets NULL, +# TIMESTAMP NULL DEFAULT <non-NULL-constant> (d) gets 0000-00-00, +# TIMESTAMP NULL DEFAULT NULL (g) gets NULL, +# TIMESTAMP NULL DEFAULT NOW (f after ALTER) gets NULL, +# TIMESTAMP NOT NULL (f before ALTER, e) gets NOW. +### Loading NULL ### +CREATE TABLE t1 ( +dummy INT, +a DATETIME(6) NULL DEFAULT NULL, +b DATETIME(6) NULL DEFAULT "2011-11-18", +like_b DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6), +c DATETIME(6) NOT NULL DEFAULT "2011-11-18", +like_c DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +d TIMESTAMP(6) NULL DEFAULT "2011-05-03" ON UPDATE CURRENT_TIMESTAMP(6), +e TIMESTAMP(6) NOT NULL DEFAULT "2011-05-03", +f TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), +g TIMESTAMP(6) NULL DEFAULT NULL, +h INT NULL, +i INT NOT NULL DEFAULT 42 +); +# There is no promotion +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `dummy` int(11) DEFAULT NULL, + `a` datetime(6) DEFAULT NULL, + `b` datetime(6) DEFAULT '2011-11-18 00:00:00.000000', + `like_b` datetime(6) DEFAULT CURRENT_TIMESTAMP(6), + `c` datetime(6) NOT NULL DEFAULT '2011-11-18 00:00:00.000000', + `like_c` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), + `d` timestamp(6) NULL DEFAULT '2011-05-03 00:00:00.000000' ON UPDATE CURRENT_TIMESTAMP(6), + `e` timestamp(6) NOT NULL DEFAULT '2011-05-03 00:00:00.000000', + `f` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), + `g` timestamp(6) NULL DEFAULT NULL, + `h` int(11) DEFAULT NULL, + `i` int(11) NOT NULL DEFAULT '42' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +LOAD DATA INFILE "file2.dat" INTO table t1; +Warnings: +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'c' at row 1 +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'like_c' at row 1 +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'i' at row 1 +SELECT * FROM t1; +dummy NULL +a NULL +b NULL +like_b NULL +c 0000-00-00 00:00:00.000000 +like_c 0000-00-00 00:00:00.000000 +d NULL +e 2011-08-01 15:11:19.089786 +f 2011-08-01 15:11:19.089786 +g NULL +h NULL +i 0 +delete from t1; +alter table t1 +modify f TIMESTAMP NULL default CURRENT_TIMESTAMP; +# There is no promotion +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `dummy` int(11) DEFAULT NULL, + `a` datetime(6) DEFAULT NULL, + `b` datetime(6) DEFAULT '2011-11-18 00:00:00.000000', + `like_b` datetime(6) DEFAULT CURRENT_TIMESTAMP(6), + `c` datetime(6) NOT NULL DEFAULT '2011-11-18 00:00:00.000000', + `like_c` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), + `d` timestamp(6) NULL DEFAULT '2011-05-03 00:00:00.000000' ON UPDATE CURRENT_TIMESTAMP(6), + `e` timestamp(6) NOT NULL DEFAULT '2011-05-03 00:00:00.000000', + `f` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `g` timestamp(6) NULL DEFAULT NULL, + `h` int(11) DEFAULT NULL, + `i` int(11) NOT NULL DEFAULT '42' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +LOAD DATA INFILE "file2.dat" INTO table t1; +Warnings: +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'c' at row 1 +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'like_c' at row 1 +Warning 1263 Column set to default value; NULL supplied to NOT NULL column 'i' at row 1 +SELECT * FROM t1; +dummy NULL +a NULL +b NULL +like_b NULL +c 0000-00-00 00:00:00.000000 +like_c 0000-00-00 00:00:00.000000 +d NULL +e 2011-08-01 15:11:19.089786 +f NULL +g NULL +h NULL +i 0 +delete from t1; +# Conclusion derived from trunk's results: +# DATETIME NULL (a,b) gets NULL, +# DATETIME NOT NULL (c) gets 0000-00-00, +# TIMESTAMP NULL (d,f,g) gets NULL, +# TIMESTAMP NOT NULL (e) gets NOW. +drop table t1; +# +# Test of updatable views with check options. The option can be violated +# using ON UPDATE updates which is very strange as this offers a loophole +# in this integrity check. +# +SET TIME_ZONE = "+03:00"; +# 1970-01-01 03:16:40 +SET TIMESTAMP = 1000.123456; +CREATE TABLE t1 ( a INT, b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)) ENGINE = INNODB; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +INSERT INTO t1 ( a ) VALUES ( 1 ); +SELECT * FROM t1; +a b +1 1970-01-01 03:16:40.123456 +CREATE VIEW v1 AS SELECT * FROM t1 WHERE b <= '1970-01-01 03:16:40.123456' +WITH CHECK OPTION; +SELECT * FROM v1; +a b +1 1970-01-01 03:16:40.123456 +# 1970-01-01 03:33:20 +SET TIMESTAMP = 2000.000234; +UPDATE v1 SET a = 2; +ERROR HY000: CHECK OPTION failed 'test.v1' +SELECT * FROM t1; +a b +1 1970-01-01 03:16:40.123456 +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 ( +a TIMESTAMP(6) NOT NULL DEFAULT '1973-08-14 09:11:22.089786' ON UPDATE CURRENT_TIMESTAMP(6), +c INT KEY +); +# 1973-08-14 09:11:22 UTC +SET TIMESTAMP = 114167482.534231; +INSERT INTO t1 ( c ) VALUES ( 1 ); +CREATE VIEW v1 AS +SELECT * +FROM t1 +WHERE a >= '1973-08-14 09:11:22' +WITH LOCAL CHECK OPTION; +SELECT * FROM v1; +a c +1973-08-14 09:11:22.089786 1 +SET TIMESTAMP = 1.126789; +INSERT INTO v1 ( c ) VALUES ( 1 ) ON DUPLICATE KEY UPDATE c = 2; +ERROR HY000: CHECK OPTION failed 'test.v1' +SELECT * FROM v1; +a c +1973-08-14 09:11:22.089786 1 +DROP VIEW v1; +DROP TABLE t1; +# +# Bug 13095459 - MULTI-TABLE UPDATE MODIFIES A ROW TWICE +# +CREATE TABLE t1 ( +a INT, +b INT, +ts TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), +PRIMARY KEY ( a, ts ) +) ENGINE = INNODB; +INSERT INTO t1( a, b, ts ) VALUES ( 1, 0, '2000-09-28 17:44:34' ); +CREATE TABLE t2 ( a INT ) ENGINE = INNODB; +INSERT INTO t2 VALUES ( 1 ); +UPDATE t1 STRAIGHT_JOIN t2 +SET t1.b = t1.b + 1 +WHERE t1.a = 1 AND t1.ts >= '2000-09-28 00:00:00'; +SELECT b FROM t1; +b +1 +DROP TABLE t1, t2; +# +# Bug#11745578: 17392: ALTER TABLE ADD COLUMN TIMESTAMP DEFAULT +# CURRENT_TIMESTAMP INSERTS ZERO +# +SET timestamp = 1000; +CREATE TABLE t1 ( b INT ); +INSERT INTO t1 VALUES (1); +ALTER TABLE t1 ADD COLUMN a6 DATETIME(6) DEFAULT NOW(6) ON UPDATE NOW(6) FIRST; +ALTER TABLE t1 ADD COLUMN a5 DATETIME(6) DEFAULT NOW(6) FIRST; +ALTER TABLE t1 ADD COLUMN a4 DATETIME(6) ON UPDATE NOW(6) FIRST; +ALTER TABLE t1 ADD COLUMN a3 TIMESTAMP(6) NOT NULL DEFAULT NOW(6) ON UPDATE NOW(6) FIRST; +ALTER TABLE t1 ADD COLUMN a2 TIMESTAMP(6) NOT NULL DEFAULT NOW(6) FIRST; +ALTER TABLE t1 ADD COLUMN a1 TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE NOW(6) FIRST; +ALTER TABLE t1 ADD COLUMN c1 TIMESTAMP(6) NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE NOW(6) AFTER b; +ALTER TABLE t1 ADD COLUMN c2 TIMESTAMP(6) NOT NULL DEFAULT NOW(6) AFTER c1; +ALTER TABLE t1 ADD COLUMN c3 TIMESTAMP(6) NOT NULL DEFAULT NOW(6) ON UPDATE NOW(6) AFTER c2; +ALTER TABLE t1 ADD COLUMN c4 DATETIME(6) ON UPDATE NOW(6) AFTER c3; +ALTER TABLE t1 ADD COLUMN c5 DATETIME(6) DEFAULT NOW(6) AFTER c4; +ALTER TABLE t1 ADD COLUMN c6 DATETIME(6) DEFAULT NOW(6) ON UPDATE NOW(6) AFTER c5; +SELECT * FROM t1; +a1 a2 a3 a4 a5 a6 b c1 c2 c3 c4 c5 c6 +0000-00-00 00:00:00.000000 1970-01-01 03:16:40.000000 1970-01-01 03:16:40.000000 NULL 1970-01-01 03:16:40.000000 1970-01-01 03:16:40.000000 1 0000-00-00 00:00:00.000000 1970-01-01 03:16:40.000000 1970-01-01 03:16:40.000000 NULL 1970-01-01 03:16:40.000000 1970-01-01 03:16:40.000000 +DROP TABLE t1; +CREATE TABLE t1 ( a TIMESTAMP(6) NOT NULL DEFAULT NOW(6) ON UPDATE CURRENT_TIMESTAMP(6), b DATETIME(6) DEFAULT NOW(6) ); +INSERT INTO t1 VALUES (); +SET timestamp = 1000000000; +ALTER TABLE t1 MODIFY COLUMN a TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP(3); +ALTER TABLE t1 MODIFY COLUMN b DATETIME(3) DEFAULT CURRENT_TIMESTAMP(3); +SELECT * FROM t1; +a b +1970-01-01 03:16:40.000 1970-01-01 03:16:40.000 +DROP TABLE t1; +CREATE TABLE t1 ( +a TIMESTAMP(6) NOT NULL DEFAULT '1999-12-01 11:22:33' ON UPDATE CURRENT_TIMESTAMP(6), +b DATETIME(6) DEFAULT '1999-12-01 11:22:33' +); +INSERT INTO t1 VALUES (); +ALTER TABLE t1 MODIFY COLUMN a TIMESTAMP(6) DEFAULT NOW(6); +ALTER TABLE t1 MODIFY COLUMN b DATETIME(6) DEFAULT NOW(6); +INSERT INTO t1 VALUES (); +SELECT * FROM t1; +a b +1999-12-01 11:22:33.000000 1999-12-01 11:22:33.000000 +2001-09-09 04:46:40.000000 2001-09-09 04:46:40.000000 +DROP TABLE t1; diff --git a/mysql-test/r/function_defaults_notembedded.result b/mysql-test/r/function_defaults_notembedded.result new file mode 100644 index 00000000000..9bd03ab9f05 --- /dev/null +++ b/mysql-test/r/function_defaults_notembedded.result @@ -0,0 +1,173 @@ +# +# Test of function defaults for non-embedded server. +# +# +# Function defaults run 1. No microsecond precision. +# +SET TIME_ZONE = "+00:00"; +# +# Test of INSERT DELAYED ... SET ... +# +# 2011-04-19 08:02:40 UTC +SET TIMESTAMP = 1303200160.123456; +CREATE TABLE t1 ( a INT, b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP); +INSERT DELAYED INTO t1 SET a = 1; +FLUSH TABLE t1; +SELECT * FROM t1; +a b +1 2011-04-19 08:02:40 +SELECT * FROM t1 WHERE b = 0; +a b +INSERT DELAYED INTO t1 SET a = 2, b = '1980-01-02 10:20:30.405060'; +FLUSH TABLE t1; +SELECT * FROM t1; +a b +1 2011-04-19 08:02:40 +2 1980-01-02 10:20:30 +DROP TABLE t1; +# +# Test of INSERT DELAYED ... VALUES ... +# +# 2011-04-19 08:04:01 UTC +SET TIMESTAMP = 1303200241.234567; +CREATE TABLE t1 ( a INT, b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP); +INSERT DELAYED INTO t1 ( a ) VALUES (1); +FLUSH TABLE t1; +SELECT * FROM t1; +a b +1 2011-04-19 08:04:01 +INSERT DELAYED INTO t1 VALUES (2, '1977-12-19 12:34:56.789123'); +FLUSH TABLE t1; +SELECT * FROM t1; +a b +1 2011-04-19 08:04:01 +2 1977-12-19 12:34:56 +DROP TABLE t1; +# +# Test of a delayed insert handler servicing two insert operations +# with different sets of active defaults. +# +CREATE TABLE t1 ( a INT, b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP); +# 2011-04-19 08:04:01 UTC +SET TIMESTAMP = 1303200241.345678; +SET debug_sync = 'before_write_delayed SIGNAL parked WAIT_FOR go'; +INSERT DELAYED INTO t1 ( a ) VALUES (1), (2), (3); +SET debug_sync = 'now WAIT_FOR parked'; +# 2011-04-19 08:04:01 UTC +SET TIME_ZONE="+03:00"; +SET TIMESTAMP = 1303200241.456789; +INSERT DELAYED INTO t1 ( a, b ) VALUES (4, '1977-12-19 12:34:56.789123'), (5, '1977-12-19 12:34:57.891234'), (6, '1977-12-19 12:34:58.912345'); +SET debug_sync = 'now SIGNAL go'; +SELECT * FROM t1; +a b +1 2011-04-19 08:04:01 +2 2011-04-19 08:04:01 +3 2011-04-19 08:04:01 +4 1977-12-19 09:34:56 +5 1977-12-19 09:34:57 +6 1977-12-19 09:34:58 +DROP TABLE t1; +# +# Test of early activation of function defaults. +# +CREATE TABLE t1 ( a INT, b TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP); +SET TIMESTAMP = 1317235172.987654; +INSERT DELAYED INTO t1 ( a ) VALUES (1), (2), (3); +SET TIMESTAMP = 385503754.876543; +INSERT DELAYED INTO t1 ( a ) VALUES (4), (5), (6); +FLUSH TABLE t1; +SELECT * FROM t1; +a b +1 2011-09-28 18:39:32 +2 2011-09-28 18:39:32 +3 2011-09-28 18:39:32 +4 1982-03-20 20:22:34 +5 1982-03-20 20:22:34 +6 1982-03-20 20:22:34 +DROP TABLE t1; +SET debug_sync = 'RESET'; +# +# Function defaults run 2. Six digits scale on seconds precision. +# +SET TIME_ZONE = "+00:00"; +# +# Test of INSERT DELAYED ... SET ... +# +# 2011-04-19 08:02:40 UTC +SET TIMESTAMP = 1303200160.123456; +CREATE TABLE t1 ( a INT, b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)); +INSERT DELAYED INTO t1 SET a = 1; +FLUSH TABLE t1; +SELECT * FROM t1; +a b +1 2011-04-19 08:02:40.123456 +SELECT * FROM t1 WHERE b = 0; +a b +INSERT DELAYED INTO t1 SET a = 2, b = '1980-01-02 10:20:30.405060'; +FLUSH TABLE t1; +SELECT * FROM t1; +a b +1 2011-04-19 08:02:40.123456 +2 1980-01-02 10:20:30.405060 +DROP TABLE t1; +# +# Test of INSERT DELAYED ... VALUES ... +# +# 2011-04-19 08:04:01 UTC +SET TIMESTAMP = 1303200241.234567; +CREATE TABLE t1 ( a INT, b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)); +INSERT DELAYED INTO t1 ( a ) VALUES (1); +FLUSH TABLE t1; +SELECT * FROM t1; +a b +1 2011-04-19 08:04:01.234567 +INSERT DELAYED INTO t1 VALUES (2, '1977-12-19 12:34:56.789123'); +FLUSH TABLE t1; +SELECT * FROM t1; +a b +1 2011-04-19 08:04:01.234567 +2 1977-12-19 12:34:56.789123 +DROP TABLE t1; +# +# Test of a delayed insert handler servicing two insert operations +# with different sets of active defaults. +# +CREATE TABLE t1 ( a INT, b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)); +# 2011-04-19 08:04:01 UTC +SET TIMESTAMP = 1303200241.345678; +SET debug_sync = 'before_write_delayed SIGNAL parked WAIT_FOR go'; +INSERT DELAYED INTO t1 ( a ) VALUES (1), (2), (3); +SET debug_sync = 'now WAIT_FOR parked'; +# 2011-04-19 08:04:01 UTC +SET TIME_ZONE="+03:00"; +SET TIMESTAMP = 1303200241.456789; +INSERT DELAYED INTO t1 ( a, b ) VALUES (4, '1977-12-19 12:34:56.789123'), (5, '1977-12-19 12:34:57.891234'), (6, '1977-12-19 12:34:58.912345'); +SET debug_sync = 'now SIGNAL go'; +SELECT * FROM t1; +a b +1 2011-04-19 08:04:01.345678 +2 2011-04-19 08:04:01.345678 +3 2011-04-19 08:04:01.345678 +4 1977-12-19 09:34:56.789123 +5 1977-12-19 09:34:57.891234 +6 1977-12-19 09:34:58.912345 +DROP TABLE t1; +# +# Test of early activation of function defaults. +# +CREATE TABLE t1 ( a INT, b TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)); +SET TIMESTAMP = 1317235172.987654; +INSERT DELAYED INTO t1 ( a ) VALUES (1), (2), (3); +SET TIMESTAMP = 385503754.876543; +INSERT DELAYED INTO t1 ( a ) VALUES (4), (5), (6); +FLUSH TABLE t1; +SELECT * FROM t1; +a b +1 2011-09-28 18:39:32.987654 +2 2011-09-28 18:39:32.987654 +3 2011-09-28 18:39:32.987654 +4 1982-03-20 20:22:34.876543 +5 1982-03-20 20:22:34.876543 +6 1982-03-20 20:22:34.876543 +DROP TABLE t1; +SET debug_sync = 'RESET'; diff --git a/mysql-test/r/grant.result b/mysql-test/r/grant.result index f3910b67dd3..7f1358d2e62 100644 --- a/mysql-test/r/grant.result +++ b/mysql-test/r/grant.result @@ -55,6 +55,7 @@ max_connections 0 max_user_connections 0 plugin authentication_string +is_role N show grants for mysqltest_1@localhost; Grants for mysqltest_1@localhost GRANT USAGE ON *.* TO 'mysqltest_1'@'localhost' REQUIRE CIPHER 'EDH-RSA-DES-CBC3-SHA' @@ -126,6 +127,7 @@ max_connections 0 max_user_connections 0 plugin authentication_string +is_role N show grants for mysqltest_1@localhost; Grants for mysqltest_1@localhost GRANT USAGE ON *.* TO 'mysqltest_1'@'localhost' WITH MAX_QUERIES_PER_HOUR 10 @@ -173,6 +175,7 @@ max_connections 30 max_user_connections 0 plugin authentication_string +is_role N show grants for mysqltest_1@localhost; Grants for mysqltest_1@localhost GRANT USAGE ON *.* TO 'mysqltest_1'@'localhost' WITH MAX_QUERIES_PER_HOUR 10 MAX_UPDATES_PER_HOUR 20 MAX_CONNECTIONS_PER_HOUR 30 @@ -650,9 +653,9 @@ SHOW FIELDS FROM mysql.tables_priv; Field Type Null Key Default Extra Host char(60) NO PRI Db char(64) NO PRI -User char(16) NO PRI +User char(80) NO PRI Table_name char(64) NO PRI -Grantor char(77) NO MUL +Grantor char(141) NO MUL Timestamp timestamp NO CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger') NO Column_priv set('Select','Insert','Update','References') NO @@ -747,28 +750,28 @@ show grants for root@localhost; Grants for root@localhost GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION GRANT SELECT ON `ÂÄ`.* TO 'root'@'localhost' -GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION +GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION flush privileges; show grants for root@localhost; Grants for root@localhost GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION GRANT SELECT ON `ÂÄ`.* TO 'root'@'localhost' -GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION +GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION drop database ÂÄ; revoke all privileges on ÂÄ.* from root@localhost; show grants for root@localhost; Grants for root@localhost GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION -GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION +GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION set names latin1; create user mysqltest_7@; set password for mysqltest_7@ = password('systpass'); show grants for mysqltest_7@; -Grants for mysqltest_7@ -GRANT USAGE ON *.* TO 'mysqltest_7'@'' IDENTIFIED BY PASSWORD '*2FB071A056F9BB745219D9C876814231DAF46517' +Grants for mysqltest_7@% +GRANT USAGE ON *.* TO 'mysqltest_7'@'%' IDENTIFIED BY PASSWORD '*2FB071A056F9BB745219D9C876814231DAF46517' drop user mysqltest_7@; show grants for mysqltest_7@; -ERROR 42000: There is no such grant defined for user 'mysqltest_7' on host '' +ERROR 42000: There is no such grant defined for user 'mysqltest_7' on host '%' create database mysqltest; use mysqltest; create table t1(f1 int); @@ -804,30 +807,28 @@ create table t2 as select * from mysql.user where user=''; delete from mysql.user where user=''; flush privileges; create user mysqltest_8@''; -create user mysqltest_8; create user mysqltest_8@host8; create user mysqltest_8@''; -ERROR HY000: Operation CREATE USER failed for 'mysqltest_8'@'' +ERROR HY000: Operation CREATE USER failed for 'mysqltest_8'@'%' create user mysqltest_8; ERROR HY000: Operation CREATE USER failed for 'mysqltest_8'@'%' create user mysqltest_8@host8; ERROR HY000: Operation CREATE USER failed for 'mysqltest_8'@'host8' select user, QUOTE(host) from mysql.user where user="mysqltest_8"; user QUOTE(host) -mysqltest_8 '' mysqltest_8 '%' mysqltest_8 'host8' Schema privileges grant select on mysqltest.* to mysqltest_8@''; show grants for mysqltest_8@''; -Grants for mysqltest_8@ -GRANT USAGE ON *.* TO 'mysqltest_8'@'' -GRANT SELECT ON `mysqltest`.* TO 'mysqltest_8'@'' +Grants for mysqltest_8@% +GRANT USAGE ON *.* TO 'mysqltest_8'@'%' +GRANT SELECT ON `mysqltest`.* TO 'mysqltest_8'@'%' grant select on mysqltest.* to mysqltest_8@; show grants for mysqltest_8@; -Grants for mysqltest_8@ -GRANT USAGE ON *.* TO 'mysqltest_8'@'' -GRANT SELECT ON `mysqltest`.* TO 'mysqltest_8'@'' +Grants for mysqltest_8@% +GRANT USAGE ON *.* TO 'mysqltest_8'@'%' +GRANT SELECT ON `mysqltest`.* TO 'mysqltest_8'@'%' grant select on mysqltest.* to mysqltest_8; show grants for mysqltest_8; Grants for mysqltest_8@% @@ -837,14 +838,12 @@ select * from information_schema.schema_privileges where grantee like "'mysqltest_8'%"; GRANTEE TABLE_CATALOG TABLE_SCHEMA PRIVILEGE_TYPE IS_GRANTABLE 'mysqltest_8'@'%' def mysqltest SELECT NO -'mysqltest_8'@'' def mysqltest SELECT NO select * from t1; a revoke select on mysqltest.* from mysqltest_8@''; -revoke select on mysqltest.* from mysqltest_8; show grants for mysqltest_8@''; -Grants for mysqltest_8@ -GRANT USAGE ON *.* TO 'mysqltest_8'@'' +Grants for mysqltest_8@% +GRANT USAGE ON *.* TO 'mysqltest_8'@'%' show grants for mysqltest_8; Grants for mysqltest_8@% GRANT USAGE ON *.* TO 'mysqltest_8'@'%' @@ -853,35 +852,35 @@ where grantee like "'mysqltest_8'%"; GRANTEE TABLE_CATALOG TABLE_SCHEMA PRIVILEGE_TYPE IS_GRANTABLE flush privileges; show grants for mysqltest_8@''; -Grants for mysqltest_8@ -GRANT USAGE ON *.* TO 'mysqltest_8'@'' +Grants for mysqltest_8@% +GRANT USAGE ON *.* TO 'mysqltest_8'@'%' show grants for mysqltest_8@; -Grants for mysqltest_8@ -GRANT USAGE ON *.* TO 'mysqltest_8'@'' +Grants for mysqltest_8@% +GRANT USAGE ON *.* TO 'mysqltest_8'@'%' grant select on mysqltest.* to mysqltest_8@''; flush privileges; show grants for mysqltest_8@; -Grants for mysqltest_8@ -GRANT USAGE ON *.* TO 'mysqltest_8'@'' -GRANT SELECT ON `mysqltest`.* TO 'mysqltest_8'@'' +Grants for mysqltest_8@% +GRANT USAGE ON *.* TO 'mysqltest_8'@'%' +GRANT SELECT ON `mysqltest`.* TO 'mysqltest_8'@'%' revoke select on mysqltest.* from mysqltest_8@''; flush privileges; Column privileges grant update (a) on t1 to mysqltest_8@''; grant update (a) on t1 to mysqltest_8; show grants for mysqltest_8@''; -Grants for mysqltest_8@ -GRANT USAGE ON *.* TO 'mysqltest_8'@'' -GRANT UPDATE (a) ON `test`.`t1` TO 'mysqltest_8'@'' +Grants for mysqltest_8@% +GRANT USAGE ON *.* TO 'mysqltest_8'@'%' +GRANT UPDATE (a) ON `test`.`t1` TO 'mysqltest_8'@'%' show grants for mysqltest_8; Grants for mysqltest_8@% GRANT USAGE ON *.* TO 'mysqltest_8'@'%' GRANT UPDATE (a) ON `test`.`t1` TO 'mysqltest_8'@'%' flush privileges; show grants for mysqltest_8@''; -Grants for mysqltest_8@ -GRANT USAGE ON *.* TO 'mysqltest_8'@'' -GRANT UPDATE (a) ON `test`.`t1` TO 'mysqltest_8'@'' +Grants for mysqltest_8@% +GRANT USAGE ON *.* TO 'mysqltest_8'@'%' +GRANT UPDATE (a) ON `test`.`t1` TO 'mysqltest_8'@'%' show grants for mysqltest_8; Grants for mysqltest_8@% GRANT USAGE ON *.* TO 'mysqltest_8'@'%' @@ -889,14 +888,12 @@ GRANT UPDATE (a) ON `test`.`t1` TO 'mysqltest_8'@'%' select * from information_schema.column_privileges; GRANTEE TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME PRIVILEGE_TYPE IS_GRANTABLE 'mysqltest_8'@'%' def test t1 a UPDATE NO -'mysqltest_8'@'' def test t1 a UPDATE NO select * from t1; a revoke update (a) on t1 from mysqltest_8@''; -revoke update (a) on t1 from mysqltest_8; show grants for mysqltest_8@''; -Grants for mysqltest_8@ -GRANT USAGE ON *.* TO 'mysqltest_8'@'' +Grants for mysqltest_8@% +GRANT USAGE ON *.* TO 'mysqltest_8'@'%' show grants for mysqltest_8; Grants for mysqltest_8@% GRANT USAGE ON *.* TO 'mysqltest_8'@'%' @@ -904,8 +901,8 @@ select * from information_schema.column_privileges; GRANTEE TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME PRIVILEGE_TYPE IS_GRANTABLE flush privileges; show grants for mysqltest_8@''; -Grants for mysqltest_8@ -GRANT USAGE ON *.* TO 'mysqltest_8'@'' +Grants for mysqltest_8@% +GRANT USAGE ON *.* TO 'mysqltest_8'@'%' show grants for mysqltest_8; Grants for mysqltest_8@% GRANT USAGE ON *.* TO 'mysqltest_8'@'%' @@ -913,18 +910,18 @@ Table privileges grant update on t1 to mysqltest_8@''; grant update on t1 to mysqltest_8; show grants for mysqltest_8@''; -Grants for mysqltest_8@ -GRANT USAGE ON *.* TO 'mysqltest_8'@'' -GRANT UPDATE ON `test`.`t1` TO 'mysqltest_8'@'' +Grants for mysqltest_8@% +GRANT USAGE ON *.* TO 'mysqltest_8'@'%' +GRANT UPDATE ON `test`.`t1` TO 'mysqltest_8'@'%' show grants for mysqltest_8; Grants for mysqltest_8@% GRANT USAGE ON *.* TO 'mysqltest_8'@'%' GRANT UPDATE ON `test`.`t1` TO 'mysqltest_8'@'%' flush privileges; show grants for mysqltest_8@''; -Grants for mysqltest_8@ -GRANT USAGE ON *.* TO 'mysqltest_8'@'' -GRANT UPDATE ON `test`.`t1` TO 'mysqltest_8'@'' +Grants for mysqltest_8@% +GRANT USAGE ON *.* TO 'mysqltest_8'@'%' +GRANT UPDATE ON `test`.`t1` TO 'mysqltest_8'@'%' show grants for mysqltest_8; Grants for mysqltest_8@% GRANT USAGE ON *.* TO 'mysqltest_8'@'%' @@ -932,14 +929,12 @@ GRANT UPDATE ON `test`.`t1` TO 'mysqltest_8'@'%' select * from information_schema.table_privileges; GRANTEE TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PRIVILEGE_TYPE IS_GRANTABLE 'mysqltest_8'@'%' def test t1 UPDATE NO -'mysqltest_8'@'' def test t1 UPDATE NO select * from t1; a revoke update on t1 from mysqltest_8@''; -revoke update on t1 from mysqltest_8; show grants for mysqltest_8@''; -Grants for mysqltest_8@ -GRANT USAGE ON *.* TO 'mysqltest_8'@'' +Grants for mysqltest_8@% +GRANT USAGE ON *.* TO 'mysqltest_8'@'%' show grants for mysqltest_8; Grants for mysqltest_8@% GRANT USAGE ON *.* TO 'mysqltest_8'@'%' @@ -947,8 +942,8 @@ select * from information_schema.table_privileges; GRANTEE TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PRIVILEGE_TYPE IS_GRANTABLE flush privileges; show grants for mysqltest_8@''; -Grants for mysqltest_8@ -GRANT USAGE ON *.* TO 'mysqltest_8'@'' +Grants for mysqltest_8@% +GRANT USAGE ON *.* TO 'mysqltest_8'@'%' show grants for mysqltest_8; Grants for mysqltest_8@% GRANT USAGE ON *.* TO 'mysqltest_8'@'%' @@ -959,45 +954,36 @@ grant update on t1 to mysqltest_8@''; grant update (a) on t1 to mysqltest_8@''; grant all privileges on mysqltest.* to mysqltest_8; show grants for mysqltest_8@''; -Grants for mysqltest_8@ -GRANT USAGE ON *.* TO 'mysqltest_8'@'' -GRANT ALL PRIVILEGES ON `mysqltest`.* TO 'mysqltest_8'@'' -GRANT UPDATE, UPDATE (a) ON `test`.`t1` TO 'mysqltest_8'@'' +Grants for mysqltest_8@% +GRANT USAGE ON *.* TO 'mysqltest_8'@'%' +GRANT ALL PRIVILEGES ON `mysqltest`.* TO 'mysqltest_8'@'%' +GRANT UPDATE, UPDATE (a) ON `test`.`t1` TO 'mysqltest_8'@'%' show grants for mysqltest_8; Grants for mysqltest_8@% GRANT USAGE ON *.* TO 'mysqltest_8'@'%' GRANT ALL PRIVILEGES ON `mysqltest`.* TO 'mysqltest_8'@'%' +GRANT UPDATE, UPDATE (a) ON `test`.`t1` TO 'mysqltest_8'@'%' select * from information_schema.user_privileges where grantee like "'mysqltest_8'%"; GRANTEE TABLE_CATALOG PRIVILEGE_TYPE IS_GRANTABLE 'mysqltest_8'@'host8' def USAGE NO 'mysqltest_8'@'%' def USAGE NO -'mysqltest_8'@'' def USAGE NO select * from t1; a flush privileges; show grants for mysqltest_8@''; -Grants for mysqltest_8@ -GRANT USAGE ON *.* TO 'mysqltest_8'@'' -GRANT ALL PRIVILEGES ON `mysqltest`.* TO 'mysqltest_8'@'' -GRANT UPDATE, UPDATE (a) ON `test`.`t1` TO 'mysqltest_8'@'' -show grants for mysqltest_8; Grants for mysqltest_8@% GRANT USAGE ON *.* TO 'mysqltest_8'@'%' GRANT ALL PRIVILEGES ON `mysqltest`.* TO 'mysqltest_8'@'%' -drop user mysqltest_8@''; -show grants for mysqltest_8@''; -ERROR 42000: There is no such grant defined for user 'mysqltest_8' on host '' +GRANT UPDATE, UPDATE (a) ON `test`.`t1` TO 'mysqltest_8'@'%' show grants for mysqltest_8; Grants for mysqltest_8@% GRANT USAGE ON *.* TO 'mysqltest_8'@'%' GRANT ALL PRIVILEGES ON `mysqltest`.* TO 'mysqltest_8'@'%' -select * from information_schema.user_privileges -where grantee like "'mysqltest_8'%"; -GRANTEE TABLE_CATALOG PRIVILEGE_TYPE IS_GRANTABLE -'mysqltest_8'@'host8' def USAGE NO -'mysqltest_8'@'%' def USAGE NO -drop user mysqltest_8; +GRANT UPDATE, UPDATE (a) ON `test`.`t1` TO 'mysqltest_8'@'%' +drop user mysqltest_8@''; +show grants for mysqltest_8@''; +ERROR 42000: There is no such grant defined for user 'mysqltest_8' on host '%' connect(localhost,mysqltest_8,,test,MASTER_PORT,MASTER_SOCKET); ERROR 28000: Access denied for user 'mysqltest_8'@'localhost' (using password: NO) show grants for mysqltest_8; @@ -1085,8 +1071,8 @@ DROP DATABASE mysqltest3; REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'mysqltest_1'@'localhost'; DROP USER 'mysqltest_1'@'localhost'; USE test; -create user mysqltest1_thisisreallytoolong; -ERROR HY000: String 'mysqltest1_thisisreallytoolong' is too long for user name (should be no longer than 16) +create user longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789; +ERROR HY000: String 'longer_than_80_4567890123456789012345678901234567890123456789012345678' is too long for user name (should be no longer than 80) CREATE DATABASE mysqltest1; CREATE TABLE mysqltest1.t1 ( int_field INTEGER UNSIGNED NOT NULL, @@ -1153,28 +1139,28 @@ ERROR 42000: DROP command denied to user 'mysqltest_1'@'localhost' for table 't1 DROP USER mysqltest_1@localhost; DROP DATABASE mysqltest1; USE test; -GRANT CREATE ON mysqltest.* TO 1234567890abcdefGHIKL@localhost; -ERROR HY000: String '1234567890abcdefGHIKL' is too long for user name (should be no longer than 16) +GRANT CREATE ON mysqltest.* TO longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost; +ERROR HY000: String 'longer_than_80_4567890123456789012345678901234567890123456789012345678' is too long for user name (should be no longer than 80) GRANT CREATE ON mysqltest.* TO some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY; ERROR HY000: String '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY' is too long for host name (should be no longer than 60) -REVOKE CREATE ON mysqltest.* FROM 1234567890abcdefGHIKL@localhost; -ERROR HY000: String '1234567890abcdefGHIKL' is too long for user name (should be no longer than 16) +REVOKE CREATE ON mysqltest.* FROM longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost; +ERROR HY000: String 'longer_than_80_4567890123456789012345678901234567890123456789012345678' is too long for user name (should be no longer than 80) REVOKE CREATE ON mysqltest.* FROM some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY; ERROR HY000: String '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY' is too long for host name (should be no longer than 60) -GRANT CREATE ON t1 TO 1234567890abcdefGHIKL@localhost; -ERROR HY000: String '1234567890abcdefGHIKL' is too long for user name (should be no longer than 16) +GRANT CREATE ON t1 TO longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost; +ERROR HY000: String 'longer_than_80_4567890123456789012345678901234567890123456789012345678' is too long for user name (should be no longer than 80) GRANT CREATE ON t1 TO some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY; ERROR HY000: String '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY' is too long for host name (should be no longer than 60) -REVOKE CREATE ON t1 FROM 1234567890abcdefGHIKL@localhost; -ERROR HY000: String '1234567890abcdefGHIKL' is too long for user name (should be no longer than 16) +REVOKE CREATE ON t1 FROM longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost; +ERROR HY000: String 'longer_than_80_4567890123456789012345678901234567890123456789012345678' is too long for user name (should be no longer than 80) REVOKE CREATE ON t1 FROM some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY; ERROR HY000: String '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY' is too long for host name (should be no longer than 60) -GRANT EXECUTE ON PROCEDURE p1 TO 1234567890abcdefGHIKL@localhost; -ERROR HY000: String '1234567890abcdefGHIKL' is too long for user name (should be no longer than 16) +GRANT EXECUTE ON PROCEDURE p1 TO longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost; +ERROR HY000: String 'longer_than_80_4567890123456789012345678901234567890123456789012345678' is too long for user name (should be no longer than 80) GRANT EXECUTE ON PROCEDURE p1 TO some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY; ERROR HY000: String '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY' is too long for host name (should be no longer than 60) -REVOKE EXECUTE ON PROCEDURE p1 FROM 1234567890abcdefGHIKL@localhost; -ERROR HY000: String '1234567890abcdefGHIKL' is too long for user name (should be no longer than 16) +REVOKE EXECUTE ON PROCEDURE p1 FROM longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost; +ERROR HY000: String 'longer_than_80_4567890123456789012345678901234567890123456789012345678' is too long for user name (should be no longer than 80) REVOKE EXECUTE ON PROCEDURE t1 FROM some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY; ERROR HY000: String '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY' is too long for host name (should be no longer than 60) CREATE USER bug23556@localhost; @@ -1652,8 +1638,8 @@ user() юзер_юзер@localhost revoke all on test.* from юзер_юзер@localhost; drop user юзер_юзер@localhost; -grant select on test.* to очень_длинный_юзер@localhost; -ERROR HY000: String 'очень_длинный_юзер' is too long for user name (should be no longer than 16) +grant select on test.* to очень_длинный_юзер890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890@localhost; +ERROR HY000: String 'очень_длинный_юзер890123456789012345678901234567890123' is too long for user name (should be no longer than 80) set names default; create database mysqltest; use mysqltest; @@ -1696,7 +1682,6 @@ use test; FLUSH PRIVILEGES without procs_priv table. RENAME TABLE mysql.procs_priv TO mysql.procs_gone; FLUSH PRIVILEGES; -ERROR 42S02: Table 'mysql.procs_priv' doesn't exist Assigning privileges without procs_priv table. CREATE DATABASE mysqltest1; CREATE PROCEDURE mysqltest1.test() SQL SECURITY DEFINER diff --git a/mysql-test/r/grant2.result b/mysql-test/r/grant2.result index 196f6601d48..42bde270440 100644 --- a/mysql-test/r/grant2.result +++ b/mysql-test/r/grant2.result @@ -36,7 +36,7 @@ select @@sql_mode; @@sql_mode NO_AUTO_CREATE_USER grant select on `my\_1`.* to mysqltest_4@localhost with grant option; -ERROR 42000: Can't find any matching row in the user table +ERROR 28000: Can't find any matching row in the user table grant select on `my\_1`.* to mysqltest_4@localhost identified by 'mypass' with grant option; show grants for mysqltest_1@localhost; @@ -335,7 +335,7 @@ delete from mysql.user where user like 'mysqltest\_1'; flush privileges; drop database mysqltest_1; set password = password("changed"); -ERROR 42000: Can't find any matching row in the user table +ERROR 42000: You are using MariaDB as an anonymous user and anonymous users are not allowed to change passwords lock table mysql.user write; flush privileges; grant all on *.* to 'mysqltest_1'@'localhost'; diff --git a/mysql-test/r/grant4.result b/mysql-test/r/grant4.result index d0b6627cd0b..65ab92c1afd 100644 --- a/mysql-test/r/grant4.result +++ b/mysql-test/r/grant4.result @@ -86,9 +86,9 @@ GRANT SHOW VIEW, SELECT ON v3 to mysqltest_u1@localhost; use mysqltest_db1; ** Connect as restricted user mysqltest_u1. ** SELECT FROM INFORMATION_SCHEMA.STATISTICS will succeed because any privileges will do (authentication is enough). +** but will return no rows SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE table_name='t5'; TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT INDEX_COMMENT -def mysqltest_db1 t5 1 mysqltest_db1 i 1 s1 A NULL NULL NULL YES BTREE ** SHOW INDEX FROM t5 will fail because we don't have any privileges on any column combination. SHOW INDEX FROM t5; ERROR 42000: SELECT command denied to user 'mysqltest_u1'@'localhost' for table 't5' diff --git a/mysql-test/r/grant_4332.result b/mysql-test/r/grant_4332.result index cca7825a07e..5a475bed6d8 100644 --- a/mysql-test/r/grant_4332.result +++ b/mysql-test/r/grant_4332.result @@ -1,3 +1,11 @@ +alter table mysql.user modify User char(16) binary not null default ''; +alter table mysql.db modify User char(16) binary not null default ''; +alter table mysql.tables_priv modify User char(16) binary not null default ''; +alter table mysql.columns_priv modify User char(16) binary not null default ''; +alter table mysql.procs_priv modify User char(16) binary not null default ''; +alter table mysql.proc modify definer char(77) collate utf8_bin not null default ''; +alter table mysql.event modify definer char(77) collate utf8_bin not null default ''; +flush privileges; select user(); Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr def user() 253 77 14 N 1 31 8 @@ -5,6 +13,10 @@ user() root@localhost create user a17aaaaaaaaaaaaa0@localhost; ERROR HY000: String 'a17aaaaaaaaaaaaa0' is too long for user name (should be no longer than 16) +grant usage on *.* to a17aaaaaaaaaaaaa0@lodalhost; +ERROR HY000: String 'a17aaaaaaaaaaaaa0' is too long for user name (should be no longer than 16) +drop user a17aaaaaaaaaaaaa0@lodalhost; +ERROR HY000: String 'a17aaaaaaaaaaaaa0' is too long for user name (should be no longer than 16) alter table mysql.user modify User char(80) binary not null default ''; alter table mysql.db modify User char(80) binary not null default ''; alter table mysql.tables_priv modify User char(80) binary not null default ''; @@ -12,107 +24,9 @@ alter table mysql.columns_priv modify User char(80) binary not null default ''; alter table mysql.procs_priv modify User char(80) binary not null default ''; alter table mysql.proc modify definer char(141) collate utf8_bin not null default ''; alter table mysql.event modify definer char(141) collate utf8_bin not null default ''; -set global event_scheduler = on; -select user(); -Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def user() 253 141 14 N 1 31 8 -user() -root@localhost -create user a17aaaaaaaaaaaaa0@localhost; -grant usage on *.* to a17aaaaaaaaaaaaa0@localhost; -grant select on mysql.user to b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0@localhost; -grant select(User) on mysql.tables_priv to c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost; -select user(), current_user(); -user() current_user() -a17aaaaaaaaaaaaa0@localhost a17aaaaaaaaaaaaa0@localhost -show grants; -Grants for a17aaaaaaaaaaaaa0@localhost -GRANT USAGE ON *.* TO 'a17aaaaaaaaaaaaa0'@'localhost' -select user(), current_user(); -user() current_user() -b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0@localhost b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0@localhost -show grants; -Grants for b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0@localhost -GRANT USAGE ON *.* TO 'b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0'@'localhost' -GRANT SELECT ON `mysql`.`user` TO 'b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0'@'localhost' -select user,host from mysql.user where user like '%0'; -user host -a17aaaaaaaaaaaaa0 localhost -b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0 localhost -c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0 localhost -select user,host from mysql.db; -ERROR 42000: SELECT command denied to user 'b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0'@'localhost' for table 'db' -select user(), current_user(); -user() current_user() -c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost -show grants; -Grants for c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost -GRANT USAGE ON *.* TO 'c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0'@'localhost' -GRANT SELECT (User) ON `mysql`.`tables_priv` TO 'c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0'@'localhost' -select user from mysql.tables_priv; -user -b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0 -c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0 -select user,host from mysql.tables_priv; -ERROR 42000: SELECT command denied to user 'c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0'@'localhost' for column 'host' in table 'tables_priv' -use mtr; -ERROR 42000: Access denied for user 'c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0'@'localhost' to database 'mtr' -drop procedure mtr.add_suppression; -ERROR 42000: alter routine command denied to user 'c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0'@'localhost' for routine 'mtr.add_suppression' -create procedure test.p1() select user(), current_user(), user from mysql.tables_priv; -show create procedure test.p1; -Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation -p1 CREATE DEFINER=`c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0`@`localhost` PROCEDURE `p1`() -select user(), current_user(), user from mysql.tables_priv latin1 latin1_swedish_ci latin1_swedish_ci -select definer from information_schema.routines; -definer -c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost -create table test.t1 (a text); -create event e1 on schedule every 1 second -do insert test.t1 values (concat(user(), ' ', current_user())); -select definer from information_schema.events; -definer -c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost -create view v1 as select * from t1; -select definer from information_schema.views; -definer -c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost -drop view v1; -create trigger tr1 before delete on t1 for each row set @a:=1; -select definer from information_schema.triggers; -definer -c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost -drop trigger tr1; -connect(localhost,c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0,foobar,test,MASTER_PORT,MASTER_SOCKET); -ERROR 28000: Access denied for user 'c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0'@'localhost' (using password: YES) -call test.p1(); -user() current_user() user -root@localhost c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0 -root@localhost c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0 -select * from t1 limit 1; -a -event_scheduler@localhost c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost -grant usage on *.* to d81ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd0@lodalhost; -ERROR HY000: String 'd81ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' is too long for user name (should be no longer than 80) -drop user d81ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd0@lodalhost; -ERROR HY000: String 'd81ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' is too long for user name (should be no longer than 80) -drop user c80cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc0@localhost; -drop user b64bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0@localhost; -drop user a17aaaaaaaaaaaaa0@localhost; -set global event_scheduler = off; -drop event e1; -drop procedure test.p1; -drop table t1; -alter table mysql.user modify User char(16) binary not null default ''; -alter table mysql.db modify User char(16) binary not null default ''; -alter table mysql.tables_priv modify User char(16) binary not null default ''; -alter table mysql.columns_priv modify User char(16) binary not null default ''; -alter table mysql.procs_priv modify User char(16) binary not null default ''; -alter table mysql.proc modify definer char(77) collate utf8_bin not null default ''; -alter table mysql.event modify definer char(77) collate utf8_bin not null default ''; flush privileges; select user(); Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def user() 253 77 14 N 1 31 8 +def user() 253 141 14 N 1 31 8 user() root@localhost diff --git a/mysql-test/r/grant_cache_no_prot.result b/mysql-test/r/grant_cache_no_prot.result index e95a858fd9a..777eb10cda6 100644 --- a/mysql-test/r/grant_cache_no_prot.result +++ b/mysql-test/r/grant_cache_no_prot.result @@ -7,11 +7,11 @@ flush status; show grants for current_user; Grants for root@localhost GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION -GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION +GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION show grants; Grants for root@localhost GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION -GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION +GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION create database if not exists mysqltest; create table mysqltest.t1 (a int,b int,c int); create table mysqltest.t2 (a int,b int,c int); diff --git a/mysql-test/r/grant_cache_ps_prot.result b/mysql-test/r/grant_cache_ps_prot.result index f9786298a81..b504dc4be35 100644 --- a/mysql-test/r/grant_cache_ps_prot.result +++ b/mysql-test/r/grant_cache_ps_prot.result @@ -7,11 +7,11 @@ flush status; show grants for current_user; Grants for root@localhost GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION -GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION +GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION show grants; Grants for root@localhost GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION -GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION +GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION create database if not exists mysqltest; create table mysqltest.t1 (a int,b int,c int); create table mysqltest.t2 (a int,b int,c int); diff --git a/mysql-test/r/grant_explain_non_select.result b/mysql-test/r/grant_explain_non_select.result new file mode 100644 index 00000000000..c18f5334e35 --- /dev/null +++ b/mysql-test/r/grant_explain_non_select.result @@ -0,0 +1,178 @@ +CREATE DATABASE privtest_db; +CREATE TABLE privtest_db.t1 (a INT); +CREATE TABLE privtest_db.t2 (a INT); +INSERT INTO privtest_db.t2 VALUES (1), (2), (3); +GRANT USAGE ON *.* TO 'privtest'@'localhost'; +GRANT SELECT ON privtest_db.t2 TO 'privtest'@'localhost'; +USE privtest_db; +EXPLAIN INSERT INTO t1 VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +INSERT INTO t1 VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +INSERT INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +GRANT INSERT ON privtest_db.t1 TO 'privtest'@'localhost'; +EXPLAIN INSERT INTO t1 VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +INSERT INTO t1 VALUES (10); +EXPLAIN INSERT INTO t1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +INSERT INTO t1 SELECT * FROM t2; +REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost'; +EXPLAIN REPLACE INTO t1 VALUES (10); +ERROR 42000: INSERT,DELETE command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 VALUES (10); +ERROR 42000: INSERT,DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT,DELETE command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT,DELETE command denied to user 'privtest'@'localhost' for table 't1' +GRANT INSERT ON privtest_db.t1 TO 'privtest'@'localhost'; +EXPLAIN REPLACE INTO t1 VALUES (10); +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 VALUES (10); +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +REVOKE INSERT ON privtest_db.t1 FROM 'privtest'@'localhost'; +GRANT DELETE ON privtest_db.t1 TO 'privtest'@'localhost'; +EXPLAIN REPLACE INTO t1 VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 VALUES (10); +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +REPLACE INTO t1 SELECT * FROM t2; +ERROR 42000: INSERT command denied to user 'privtest'@'localhost' for table 't1' +GRANT INSERT, DELETE ON privtest_db.t1 TO 'privtest'@'localhost'; +EXPLAIN REPLACE INTO t1 VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +REPLACE INTO t1 VALUES (10); +EXPLAIN REPLACE INTO t1 SELECT * FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +REPLACE INTO t1 SELECT * FROM t2; +REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost'; +EXPLAIN UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +GRANT UPDATE ON privtest_db.t1 TO 'privtest'@'localhost'; +EXPLAIN UPDATE t1 SET a = a + 1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1' +UPDATE t1 SET a = a + 1; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1' +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1' +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1' +REVOKE UPDATE ON privtest_db.t1 FROM 'privtest'@'localhost'; +GRANT SELECT ON privtest_db.t1 TO 'privtest'@'localhost'; +EXPLAIN UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1 SET a = a + 1; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +ERROR 42000: UPDATE command denied to user 'privtest'@'localhost' for table 't1' +GRANT UPDATE, SELECT ON privtest_db.t1 TO 'privtest'@'localhost'; +EXPLAIN UPDATE t1 SET a = a + 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 +UPDATE t1 SET a = a + 1; +EXPLAIN UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +UPDATE t1, t2 SET t1.a = t1.a + 1 WHERE t1.a = t2.a; +REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost'; +EXPLAIN DELETE FROM t1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +GRANT DELETE ON privtest_db.t1 TO 'privtest'@'localhost'; +EXPLAIN DELETE FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1' +DELETE FROM t1 WHERE a = 10; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for column 'a' in table 't1' +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: SELECT command denied to user 'privtest'@'localhost' for table 't1' +REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost'; +GRANT SELECT ON privtest_db.t1 TO 'privtest'@'localhost'; +EXPLAIN DELETE FROM t1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 WHERE a = 10; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +ERROR 42000: DELETE command denied to user 'privtest'@'localhost' for table 't1' +REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost'; +GRANT DELETE, SELECT ON privtest_db.t1 TO 'privtest'@'localhost'; +EXPLAIN DELETE FROM t1 WHERE a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +DELETE FROM t1 WHERE a = 10; +EXPLAIN DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where +DELETE FROM t1 USING t1, t2 WHERE t1.a = t2.a; +REVOKE ALL PRIVILEGES ON privtest_db.t1 FROM 'privtest'@'localhost'; +CREATE VIEW privtest_db.v1 (a) AS SELECT a FROM privtest_db.t1; +GRANT SELECT, INSERT, UPDATE, DELETE ON privtest_db.v1 TO 'privtest'@'localhost'; +EXPLAIN SELECT * FROM v1; +ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +SELECT * FROM v1; +a +11 +4 +4 +11 +4 +4 +EXPLAIN INSERT INTO v1 VALUES (10); +ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v1 VALUES (10); +EXPLAIN INSERT INTO v1 SELECT * FROM t2; +ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +INSERT INTO v1 SELECT * FROM t2; +EXPLAIN REPLACE INTO v1 VALUES (10); +ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v1 VALUES (10); +EXPLAIN REPLACE INTO v1 SELECT * FROM t2; +ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +REPLACE INTO v1 SELECT * FROM t2; +EXPLAIN UPDATE v1 SET a = a + 1; +ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1 SET a = a + 1; +EXPLAIN UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +UPDATE v1, t2 SET v1.a = v1.a + 1 WHERE v1.a = t2.a; +EXPLAIN DELETE FROM v1 WHERE a = 10; +ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1 WHERE a = 10; +EXPLAIN DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +ERROR HY000: EXPLAIN/SHOW can not be issued; lacking privileges for underlying table +DELETE FROM v1 USING v1, t2 WHERE v1.a = t2.a; +DROP USER 'privtest'@localhost; +USE test; +DROP DATABASE privtest_db; diff --git a/mysql-test/r/grant_lowercase.result b/mysql-test/r/grant_lowercase.result index 489f990daf1..f13b077c214 100644 --- a/mysql-test/r/grant_lowercase.result +++ b/mysql-test/r/grant_lowercase.result @@ -5,7 +5,7 @@ ERROR 42000: Incorrect database name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa drop user user1@localhost; call mtr.add_suppression("Incorrect database name"); alter table mysql.host modify Db varchar(200); -alter table mysql.db modify Db varchar(200); +alter table mysql.db modify User char(16), modify Db varchar(200); insert mysql.host set db=concat('=>', repeat(_utf8 'й', 200)); Warnings: Warning 1265 Data truncated for column 'Db' at row 1 @@ -16,5 +16,5 @@ flush privileges; delete from mysql.host where db like '=>%'; delete from mysql.db where db like '=>%'; alter table mysql.host modify Db char(64); -alter table mysql.db modify Db char(64); +alter table mysql.db modify Db char(64), modify User char(80); flush privileges; diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index a9e91199949..4d37f126563 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -2084,7 +2084,7 @@ f1 f2 explain select col1 f1, col1 f2 from t1 group by f2 order by f2, f1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL idx 5 NULL 7 Using index for group-by +1 SIMPLE t1 index NULL idx 5 NULL 20 Using index select col1 f1, col1 f2 from t1 group by f2 order by f2, f1; f1 f2 1 1 @@ -2473,3 +2473,48 @@ c 1c v 2v,2v NULL 1c,2v,2v DROP TABLE t1,t2; +# +# Bug #58782 +# Missing rows with SELECT .. WHERE .. IN subquery +# with full GROUP BY and no aggr +# +CREATE TABLE t1 ( +pk INT NOT NULL, +col_int_nokey INT, +PRIMARY KEY (pk) +); +INSERT INTO t1 VALUES (10,7); +INSERT INTO t1 VALUES (11,1); +INSERT INTO t1 VALUES (12,5); +INSERT INTO t1 VALUES (13,3); +SELECT pk AS field1, col_int_nokey AS field2 +FROM t1 +WHERE col_int_nokey > 0 +GROUP BY field1, field2; +field1 field2 +10 7 +11 1 +12 5 +13 3 +CREATE TABLE where_subselect +SELECT pk AS field1, col_int_nokey AS field2 +FROM t1 +WHERE col_int_nokey > 0 +GROUP BY field1, field2 +; +SELECT * +FROM where_subselect +WHERE (field1, field2) IN ( +SELECT pk AS field1, col_int_nokey AS field2 +FROM t1 +WHERE col_int_nokey > 0 +GROUP BY field1, field2 +); +field1 field2 +10 7 +11 1 +12 5 +13 3 +DROP TABLE t1; +DROP TABLE where_subselect; +# End of Bug #58782 diff --git a/mysql-test/r/group_min_max.result b/mysql-test/r/group_min_max.result index d590039f322..43b0f4d56f3 100644 --- a/mysql-test/r/group_min_max.result +++ b/mysql-test/r/group_min_max.result @@ -2126,6 +2126,31 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 index idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_2 147 NULL 128 75.00 Using where; Using index Warnings: Note 1003 select sum(ord(`test`.`t1`.`a1`)) AS `sum(ord(a1))` from `test`.`t1` where (`test`.`t1`.`a1` > 'a') group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b` +create table t4 as select distinct a1, a2, b, c from t1; +alter table t4 add unique index idxt4 (a1, a2, b, c); +explain +select a1, a2, b, min(c) from t4 group by a1, a2, b; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 index NULL idxt4 163 NULL 64 Using index +select a1, a2, b, min(c) from t4 group by a1, a2, b; +a1 a2 b min(c) +a a a a111 +a a b e112 +a b a i121 +a b b m122 +b a a a211 +b a b e212 +b b a i221 +b b b m222 +c a a a311 +c a b e312 +c b a i321 +c b b m322 +d a a a411 +d a b e412 +d b a i421 +d b b m422 +drop table t4; explain select distinct(a1) from t1 where ord(a2) = 98; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL idx_t1_2 147 NULL 128 Using where; Using index @@ -2249,14 +2274,14 @@ COUNT(DISTINCT a) 1 DROP TABLE t1; DROP PROCEDURE a; -CREATE TABLE t1 (a varchar(64) NOT NULL default '', PRIMARY KEY(a)); +CREATE TABLE t1 (a varchar(64) NOT NULL default '', KEY(a)); INSERT INTO t1 (a) VALUES (''), ('CENTRAL'), ('EASTERN'), ('GREATER LONDON'), ('NORTH CENTRAL'), ('NORTH EAST'), ('NORTH WEST'), ('SCOTLAND'), ('SOUTH EAST'), ('SOUTH WEST'), ('WESTERN'); EXPLAIN SELECT DISTINCT a,a FROM t1 ORDER BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL PRIMARY 66 NULL 12 Using index for group-by +1 SIMPLE t1 range NULL a 66 NULL 6 Using index for group-by SELECT DISTINCT a,a FROM t1 ORDER BY a; a a @@ -2314,11 +2339,11 @@ t1; id2 id3 id5 id4 id3 id6 id5 id1 1 1 1 1 1 1 1 1 DROP TABLE t1,t2,t3,t4,t5,t6; -CREATE TABLE t1 (a int, b int, PRIMARY KEY (a,b), KEY b (b)); +CREATE TABLE t1 (a int, b int, KEY (a,b), KEY b (b)); INSERT INTO t1 VALUES (1,1),(1,2),(1,0),(1,3); explain SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY,b PRIMARY 8 NULL 1 Using where; Using index for group-by +1 SIMPLE t1 range a,b a 10 NULL 1 Using where; Using index for group-by SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a; MAX(b) a 1 1 @@ -2329,7 +2354,7 @@ CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a,b,c)); INSERT INTO t2 SELECT a,b,b FROM t1; explain SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range PRIMARY PRIMARY 12 NULL 1 Using where; Using index for group-by +1 SIMPLE t2 ref PRIMARY PRIMARY 8 const,const 1 Using where; Using index SELECT MIN(c) FROM t2 WHERE b = 2 and a = 1 and c > 1 GROUP BY a; MIN(c) 2 @@ -2525,7 +2550,7 @@ a MIN(b) MAX(b) AVG(b) 2 1 3 2.0000 1 1 3 2.0000 DROP TABLE t1; -create table t1 (a int, b int, primary key (a,b), key `index` (a,b)) engine=MyISAM; +create table t1 (a int, b int, key (a,b), key `index` (a,b)) engine=MyISAM; insert into t1 (a,b) values (0,0),(0,1),(0,2),(0,3),(0,4),(0,5),(0,6), (0,7),(0,8),(0,9),(0,10),(0,11),(0,12),(0,13), @@ -2597,7 +2622,7 @@ a b 3 13 explain extended select sql_buffer_result a, max(b)+1 from t1 where a = 0 group by a; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 ref PRIMARY,index PRIMARY 4 const 15 100.00 Using index; Using temporary +1 SIMPLE t1 ref a,index a 5 const 15 100.00 Using index; Using temporary Warnings: Note 1003 select sql_buffer_result `test`.`t1`.`a` AS `a`,(max(`test`.`t1`.`b`) + 1) AS `max(b)+1` from `test`.`t1` where (`test`.`t1`.`a` = 0) group by `test`.`t1`.`a` drop table t1; @@ -3548,7 +3573,7 @@ DROP TABLE t1,t2; CREATE TABLE t1 ( f1 int(11) NOT NULL DEFAULT '0', f2 char(1) NOT NULL DEFAULT '', -PRIMARY KEY (f1,f2) +KEY (f1,f2) ) ; insert into t1 values(1,'A'),(1 , 'B'), (1, 'C'), (2, 'A'), (3, 'A'), (3, 'B'), (3, 'C'), (3, 'D'); @@ -3559,7 +3584,7 @@ f1 COUNT(DISTINCT f2) 3 4 explain SELECT f1, COUNT(DISTINCT f2) FROM t1 GROUP BY f1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range NULL PRIMARY 5 NULL 9 Using index for group-by (scanning) +1 SIMPLE t1 range NULL f1 5 NULL 9 Using index for group-by (scanning) drop table t1; # End of test#50539. # @@ -3583,7 +3608,7 @@ INSERT INTO faulty (b, c) VALUES EXPLAIN SELECT DISTINCT b, c FROM faulty WHERE b='1802' ORDER BY c; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE faulty range b_and_c b_and_c 12 NULL 2 Using where; Using index for group-by; Using filesort +1 SIMPLE faulty ref b_and_c b_and_c 4 const 2 Using where; Using index SELECT DISTINCT b, c FROM faulty WHERE b='1802' ORDER BY c; b c 1802 2013-02-28 09:00:00 diff --git a/mysql-test/r/having.result b/mysql-test/r/having.result index a0a4fc42e2d..1f09ba6cef5 100644 --- a/mysql-test/r/having.result +++ b/mysql-test/r/having.result @@ -637,3 +637,15 @@ Note 1003 select min(`test`.`t1`.`f10`) AS `field1` from `test`.`t1` where <expr set optimizer_switch=@save_optimizer_switch; drop table t1,t2,t3; End of 5.2 tests +# +# Bug mdev-5160: two-way join with HAVING over the second table +# +CREATE TABLE t1 (c1 varchar(6)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('s'), ('t'), ('a'), ('x'); +CREATE TABLE t2 (c2 varchar(6)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('a'), ('x'); +SELECT * FROM t1 JOIN t2 ON c1 = c2 HAVING c2 > 'a' ORDER BY c2 LIMIT 1; +c1 c2 +x x +DROP TABLE t1,t2; +End of 10.0 tests diff --git a/mysql-test/r/information_schema-big.result b/mysql-test/r/information_schema-big.result index 3d4fa27859d..55ed95f6452 100644 --- a/mysql-test/r/information_schema-big.result +++ b/mysql-test/r/information_schema-big.result @@ -19,12 +19,15 @@ c2.column_name LIKE '%SCHEMA%' ) AND t.table_name NOT LIKE 'innodb%'; table_name column_name +ALL_PLUGINS PLUGIN_NAME +APPLICABLE_ROLES GRANTEE CHARACTER_SETS CHARACTER_SET_NAME CLIENT_STATISTICS CLIENT COLLATIONS COLLATION_NAME COLLATION_CHARACTER_SET_APPLICABILITY COLLATION_NAME COLUMNS TABLE_SCHEMA COLUMN_PRIVILEGES TABLE_SCHEMA +ENABLED_ROLES ROLE_NAME ENGINES ENGINE EVENTS EVENT_SCHEMA FILES TABLE_SCHEMA @@ -71,12 +74,15 @@ c2.column_name LIKE '%SCHEMA%' ) AND t.table_name NOT LIKE 'innodb%'; table_name column_name +ALL_PLUGINS PLUGIN_NAME +APPLICABLE_ROLES GRANTEE CHARACTER_SETS CHARACTER_SET_NAME CLIENT_STATISTICS CLIENT COLLATIONS COLLATION_NAME COLLATION_CHARACTER_SET_APPLICABILITY COLLATION_NAME COLUMNS TABLE_SCHEMA COLUMN_PRIVILEGES TABLE_SCHEMA +ENABLED_ROLES ROLE_NAME ENGINES ENGINE EVENTS EVENT_SCHEMA FILES TABLE_SCHEMA diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index 93fc70caa2c..4ccf3ba1ca4 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -46,12 +46,15 @@ table_name not like 'ndb_%' AND table_name not like 'innodb_%' AND table_name not like 'xtradb_%'; select * from v1; c +ALL_PLUGINS +APPLICABLE_ROLES CHARACTER_SETS CLIENT_STATISTICS COLLATIONS COLLATION_CHARACTER_SET_APPLICABILITY COLUMNS COLUMN_PRIVILEGES +ENABLED_ROLES ENGINES EVENTS FILES @@ -81,20 +84,24 @@ TRIGGERS USER_PRIVILEGES USER_STATISTICS VIEWS +column_stats columns_priv db event func general_log +gtid_slave_pos help_category help_keyword help_relation help_topic host +index_stats plugin proc procs_priv proxies_priv +roles_mapping servers slow_log t1 @@ -102,6 +109,7 @@ t2 t3 t4 t5 +table_stats tables_priv time_zone time_zone_leap_second @@ -120,6 +128,7 @@ TABLE_CONSTRAINTS TABLE_CONSTRAINTS TABLE_PRIVILEGES TABLE_PRIVILEGES TABLE_STATISTICS TABLE_STATISTICS TRIGGERS TRIGGERS +table_stats table_stats tables_priv tables_priv time_zone time_zone time_zone_leap_second time_zone_leap_second @@ -141,6 +150,7 @@ TABLE_CONSTRAINTS TABLE_CONSTRAINTS TABLE_PRIVILEGES TABLE_PRIVILEGES TABLE_STATISTICS TABLE_STATISTICS TRIGGERS TRIGGERS +table_stats table_stats tables_priv tables_priv time_zone time_zone time_zone_leap_second time_zone_leap_second @@ -162,6 +172,7 @@ TABLE_CONSTRAINTS TABLE_CONSTRAINTS TABLE_PRIVILEGES TABLE_PRIVILEGES TABLE_STATISTICS TABLE_STATISTICS TRIGGERS TRIGGERS +table_stats table_stats tables_priv tables_priv time_zone time_zone time_zone_leap_second time_zone_leap_second @@ -607,7 +618,7 @@ proc security_type enum('INVOKER','DEFINER') proc param_list blob proc returns longblob proc body longblob -proc definer char(77) +proc definer char(141) proc created timestamp proc modified timestamp proc sql_mode set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','IGNORE_BAD_TABLE_OPTIONS','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH') @@ -642,8 +653,8 @@ select TABLE_NAME,TABLE_TYPE,ENGINE from information_schema.tables where table_schema='information_schema' limit 2; TABLE_NAME TABLE_TYPE ENGINE -CHARACTER_SETS SYSTEM VIEW MEMORY -CLIENT_STATISTICS SYSTEM VIEW MEMORY +ALL_PLUGINS SYSTEM VIEW Aria +APPLICABLE_ROLES SYSTEM VIEW MEMORY show tables from information_schema like "T%"; Tables_in_information_schema (T%) TABLES @@ -698,6 +709,7 @@ max_questions select,insert,update,references max_connections select,insert,update,references max_user_connections select,insert,update,references authentication_string select,insert,update,references +is_role select,insert,update,references use test; create function sub1(i int) returns int return i+1; @@ -788,6 +800,7 @@ select table_schema,table_name, column_name from information_schema.columns where data_type = 'longtext'; table_schema table_name column_name +information_schema ALL_PLUGINS PLUGIN_DESCRIPTION information_schema COLUMNS COLUMN_DEFAULT information_schema COLUMNS COLUMN_TYPE information_schema EVENTS EVENT_DEFINITION @@ -1174,7 +1187,7 @@ group by column_type order by num; column_type group_concat(table_schema, '.', table_name) num varchar(27) information_schema.COLUMNS 1 varchar(7) information_schema.ROUTINES,information_schema.VIEWS 2 -varchar(20) information_schema.FILES,information_schema.FILES,information_schema.PLUGINS,information_schema.PLUGINS,information_schema.PLUGINS,information_schema.PROFILING 6 +varchar(20) information_schema.ALL_PLUGINS,information_schema.ALL_PLUGINS,information_schema.ALL_PLUGINS,information_schema.FILES,information_schema.FILES,information_schema.PLUGINS,information_schema.PLUGINS,information_schema.PLUGINS,information_schema.PROFILING 9 create table t1(f1 char(1) not null, f2 char(9) not null) default character set utf8; select CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH from diff --git a/mysql-test/r/information_schema_all_engines.result b/mysql-test/r/information_schema_all_engines.result index 4dac9a3e53c..ec9027fa32f 100644 --- a/mysql-test/r/information_schema_all_engines.result +++ b/mysql-test/r/information_schema_all_engines.result @@ -1,12 +1,15 @@ use INFORMATION_SCHEMA; show tables; Tables_in_information_schema +ALL_PLUGINS +APPLICABLE_ROLES CHARACTER_SETS CLIENT_STATISTICS COLLATIONS COLLATION_CHARACTER_SET_APPLICABILITY COLUMNS COLUMN_PRIVILEGES +ENABLED_ROLES ENGINES EVENTS FILES @@ -74,12 +77,15 @@ c2.table_name = t.table_name AND c2.column_name LIKE '%SCHEMA%' ) order by t.table_name; table_name column_name +ALL_PLUGINS PLUGIN_NAME +APPLICABLE_ROLES GRANTEE CHARACTER_SETS CHARACTER_SET_NAME CLIENT_STATISTICS CLIENT COLLATIONS COLLATION_NAME COLLATION_CHARACTER_SET_APPLICABILITY COLLATION_NAME COLUMNS TABLE_SCHEMA COLUMN_PRIVILEGES TABLE_SCHEMA +ENABLED_ROLES ROLE_NAME ENGINES ENGINE EVENTS EVENT_SCHEMA FILES TABLE_SCHEMA @@ -147,12 +153,15 @@ c2.table_name = t.table_name AND c2.column_name LIKE '%SCHEMA%' ) order by t.table_name; table_name column_name +ALL_PLUGINS PLUGIN_NAME +APPLICABLE_ROLES GRANTEE CHARACTER_SETS CHARACTER_SET_NAME CLIENT_STATISTICS CLIENT COLLATIONS COLLATION_NAME COLLATION_CHARACTER_SET_APPLICABILITY COLLATION_NAME COLUMNS TABLE_SCHEMA COLUMN_PRIVILEGES TABLE_SCHEMA +ENABLED_ROLES ROLE_NAME ENGINES ENGINE EVENTS EVENT_SCHEMA FILES TABLE_SCHEMA @@ -205,7 +214,7 @@ USER_PRIVILEGES GRANTEE USER_STATISTICS USER VIEWS TABLE_SCHEMA XTRADB_ADMIN_COMMAND result_message -select 1 as f1 from information_schema.tables where "CHARACTER_SETS"= +select 1 as f1 from information_schema.tables where "ALL_PLUGINS"= (select cast(table_name as char) from information_schema.tables order by table_name limit 1) limit 1; f1 @@ -226,6 +235,8 @@ c2.table_schema='information_schema' and group by c2.column_type order by num limit 1) group by t.table_name order by num1, t.table_name; table_name group_concat(t.table_schema, '.', t.table_name) num1 +ALL_PLUGINS information_schema.ALL_PLUGINS 1 +APPLICABLE_ROLES information_schema.APPLICABLE_ROLES 1 CHARACTER_SETS information_schema.CHARACTER_SETS 1 CLIENT_STATISTICS information_schema.CLIENT_STATISTICS 1 COLLATIONS information_schema.COLLATIONS 1 @@ -288,12 +299,15 @@ VIEWS information_schema.VIEWS 1 +---------------------------------------+ Database: information_schema | Tables | +| ALL_PLUGINS | +| APPLICABLE_ROLES | | CHARACTER_SETS | | CLIENT_STATISTICS | | COLLATIONS | | COLLATION_CHARACTER_SET_APPLICABILITY | | COLUMNS | | COLUMN_PRIVILEGES | +| ENABLED_ROLES | | ENGINES | | EVENTS | | FILES | @@ -351,12 +365,15 @@ Database: information_schema +---------------------------------------+ Database: INFORMATION_SCHEMA | Tables | +| ALL_PLUGINS | +| APPLICABLE_ROLES | | CHARACTER_SETS | | CLIENT_STATISTICS | | COLLATIONS | | COLLATION_CHARACTER_SET_APPLICABILITY | | COLUMNS | | COLUMN_PRIVILEGES | +| ENABLED_ROLES | | ENGINES | | EVENTS | | FILES | @@ -417,5 +434,5 @@ Wildcard: inf_rmation_schema | information_schema | SELECT table_schema, count(*) FROM information_schema.TABLES WHERE table_schema IN ('mysql', 'INFORMATION_SCHEMA', 'test', 'mysqltest') AND table_name<>'ndb_binlog_index' AND table_name<>'ndb_apply_status' GROUP BY TABLE_SCHEMA; table_schema count(*) -information_schema 58 -mysql 23 +information_schema 61 +mysql 28 diff --git a/mysql-test/r/innodb_mysql_sync.result b/mysql-test/r/innodb_mysql_sync.result index 58254412c5b..7c41ffec344 100644 --- a/mysql-test/r/innodb_mysql_sync.result +++ b/mysql-test/r/innodb_mysql_sync.result @@ -18,10 +18,10 @@ SET DEBUG_SYNC='now SIGNAL table_altered'; # Complete optimization Table Op Msg_type Msg_text test.t1 optimize note Table does not support optimize, doing recreate + analyze instead -test.t1 optimize error Got error -1 from storage engine +test.t1 optimize error Got error -1 "Internal error < 0 (Not system error)" from storage engine MEMORY test.t1 optimize status Operation failed Warnings: -Error 1030 Got error -1 from storage engine +Error 1030 Got error -1 "Internal error < 0 (Not system error)" from storage engine MEMORY DROP TABLE t1; SET DEBUG_SYNC='RESET'; # diff --git a/mysql-test/r/is_debug_build.require b/mysql-test/r/is_debug_build.require deleted file mode 100644 index 4d77bcdc1ed..00000000000 --- a/mysql-test/r/is_debug_build.require +++ /dev/null @@ -1,2 +0,0 @@ -instr(version(), "debug") > 0 -1 diff --git a/mysql-test/r/join.result b/mysql-test/r/join.result index 1e51d55f012..0f798f7ba1a 100644 --- a/mysql-test/r/join.result +++ b/mysql-test/r/join.result @@ -756,7 +756,7 @@ columns.TABLE_CATALOG, columns.TABLE_SCHEMA, columns.COLUMN_DEFAULT, columns.IS_ from information_schema.statistics join information_schema.columns using(table_name,column_name) where table_name='user'; TABLE_NAME COLUMN_NAME TABLE_CATALOG TABLE_SCHEMA NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLLATION SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT TABLE_CATALOG TABLE_SCHEMA COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA COLUMN_COMMENT user Host def mysql 0 mysql PRIMARY 1 A NULL NULL BTREE def mysql NO char 60 180 NULL NULL utf8 utf8_bin char(60) PRI -user User def mysql 0 mysql PRIMARY 2 A NULL NULL BTREE def mysql NO char 16 48 NULL NULL utf8 utf8_bin char(16) PRI +user User def mysql 0 mysql PRIMARY 2 A NULL NULL BTREE def mysql NO char 80 240 NULL NULL utf8 utf8_bin char(80) PRI drop table t1; drop table t2; drop table t3; @@ -1497,3 +1497,44 @@ Note 1003 select NULL AS `i1`,`v2`.`i2` AS `i2`,`v2`.`a` AS `a`,`v2`.`b` AS `b` DROP VIEW v2; DROP TABLE t1,t2; SET optimizer_switch=@save_optimizer_switch; +# +# Bug #35268: Parser can't handle STRAIGHT_JOIN with USING +# +CREATE TABLE t1 (a int); +INSERT INTO t1 (a) VALUES (1),(2),(3),(4),(5),(6),(7),(8); +CREATE TABLE t2 (a int); +INSERT INTO t2 (a) VALUES (1),(2),(3),(4); +EXPLAIN +SELECT t1.a FROM t1 NATURAL INNER JOIN t2 ORDER BY t1.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 Using temporary; Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) +SELECT t1.a FROM t1 NATURAL INNER JOIN t2 ORDER BY t1.a; +a +1 +2 +3 +4 +EXPLAIN +SELECT t1.a FROM t1 STRAIGHT_JOIN t2 USING(a) ORDER BY t1.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using temporary; Using filesort +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join) +SELECT t1.a FROM t1 STRAIGHT_JOIN t2 USING(a) ORDER BY t1.a; +a +1 +2 +3 +4 +EXPLAIN +SELECT t1.a FROM t1 NATURAL STRAIGHT_JOIN t2 ORDER BY t1.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using temporary; Using filesort +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join) +SELECT t1.a FROM t1 NATURAL STRAIGHT_JOIN t2 ORDER BY t1.a; +a +1 +2 +3 +4 +DROP TABLE t1,t2; diff --git a/mysql-test/r/join_cache.result b/mysql-test/r/join_cache.result index b3ca6dc0df2..7ca28c28b1e 100644 --- a/mysql-test/r/join_cache.result +++ b/mysql-test/r/join_cache.result @@ -5058,7 +5058,7 @@ EXPLAIN SELECT * FROM t1,t2 WHERE t1.a < 3 and t2.a IS NULL; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 Using where; Using index -1 SIMPLE t2 hash_range idx #hash#idx:idx 5:5 const 4 Using index condition; Rowid-ordered scan; Using join buffer (flat, BNLH join) +1 SIMPLE t2 hash_range idx #hash#idx:idx 5:5 const 4 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join) SELECT * FROM t1,t2 WHERE t1.a < 3 and t2.a IS NULL; a a b 1 NULL 10 @@ -5656,4 +5656,51 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 1 SIMPLE t2 ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join) drop table t0,t1,t2; +# +# MDEV-5123 Remove duplicated conditions pushed both to join_tab->select_cond and join_tab->cache_select->cond for blocked joins. +# +set join_cache_level=default; +set expensive_subquery_limit=0; +create table t1 (c1 int); +create table t2 (c2 int); +create table t3 (c3 int); +insert into t1 values (1), (2); +insert into t2 values (1), (2); +insert into t3 values (2); +explain +select count(*) from t1 straight_join t2 +where c1 = c2-0 and c2 <= (select max(c3) from t3 where c3 = 2 and @counter:=@counter+1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +2 UNCACHEABLE SUBQUERY t3 system NULL NULL NULL NULL 1 +set @counter=0; +select count(*) from t1 straight_join t2 +where c1 = c2-0 and c2 <= (select max(c3) from t3 where c3 = 2 and @counter:=@counter+1); +count(*) +2 +select @counter; +@counter +2 +explain +select count(*) from t1 straight_join t2 +where c1 = c2-0 and +c2 <= (select max(c3) from t3 where c3 = 2 and @counter:=@counter+1) and +c2 / 2 = 1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +2 UNCACHEABLE SUBQUERY t3 system NULL NULL NULL NULL 1 +set @counter=0; +select count(*) from t1 straight_join t2 +where c1 = c2-0 and +c2 <= (select max(c3) from t3 where c3 = 2 and @counter:=@counter+1) and +c2 / 2 = 1; +count(*) +1 +select @counter; +@counter +2 +drop table t1,t2,t3; +set expensive_subquery_limit=default; set @@optimizer_switch=@save_optimizer_switch; diff --git a/mysql-test/r/kill.result b/mysql-test/r/kill.result index e91db0c9036..6afce67cc1a 100644 --- a/mysql-test/r/kill.result +++ b/mysql-test/r/kill.result @@ -298,5 +298,15 @@ select 1; Got one of the listed errors select 1; Got one of the listed errors +# +# MDEV-4911 - add KILL query id, and add query id information to +# processlist +# +SELECT SLEEP(1000); +KILL QUERY ID @id; +SLEEP(1000) +1 +KILL QUERY ID 0; +ERROR HY000: Unknown query id: 0 SET DEBUG_SYNC = 'RESET'; DROP FUNCTION MY_KILL; diff --git a/mysql-test/r/limit_rows_examined.result b/mysql-test/r/limit_rows_examined.result index a51798a5883..130d17ae270 100644 --- a/mysql-test/r/limit_rows_examined.result +++ b/mysql-test/r/limit_rows_examined.result @@ -439,7 +439,7 @@ from (select * from t1 where c1 IN (select * from t2 where c2 > ' ' LIMIT ROWS EXAMINED 0)) as tmp LIMIT ROWS EXAMINED 11; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where 3 MATERIALIZED t2 ALL NULL NULL NULL NULL 4 Using where select * from (select * from t1 @@ -747,27 +747,27 @@ ERROR HY000: Sort aborted: SHOW STATUS LIKE 'Handler_read%'; Variable_name Value Handler_read_first 0 -Handler_read_key 4 +Handler_read_key 5 Handler_read_last 0 Handler_read_next 0 Handler_read_prev 0 Handler_read_rnd 0 Handler_read_rnd_deleted 0 -Handler_read_rnd_next 52 +Handler_read_rnd_next 46 SHOW STATUS LIKE 'Handler_tmp%'; Variable_name Value Handler_tmp_update 0 -Handler_tmp_write 66 +Handler_tmp_write 70 FLUSH STATUS; SELECT a AS field1, alias2.d AS field2, alias2.f AS field3, alias2.e AS field4, b AS field5 FROM t1, t2 AS alias2, t2 AS alias3 WHERE alias3.c IN ( SELECT 1 UNION SELECT 6 ) GROUP BY field1, field2, field3, field4, field5 -LIMIT ROWS EXAMINED 250; +LIMIT ROWS EXAMINED 124; field1 field2 field3 field4 field5 00:21:38 06:07:10 a 2007-06-08 04:35:26 2007-05-28 00:00:00 Warnings: -Warning 1931 Query execution was interrupted. The query examined at least 251 rows, which exceeds LIMIT ROWS EXAMINED (250). The query result may be incomplete. +Warning 1931 Query execution was interrupted. The query examined at least 125 rows, which exceeds LIMIT ROWS EXAMINED (124). The query result may be incomplete. SHOW STATUS LIKE 'Handler_read%'; Variable_name Value Handler_read_first 0 @@ -777,11 +777,11 @@ Handler_read_next 0 Handler_read_prev 0 Handler_read_rnd 2 Handler_read_rnd_deleted 1 -Handler_read_rnd_next 110 +Handler_read_rnd_next 47 SHOW STATUS LIKE 'Handler_tmp%'; Variable_name Value Handler_tmp_update 0 -Handler_tmp_write 133 +Handler_tmp_write 70 drop table t1, t2; MDEV-161 LIMIT_ROWS EXAMINED: query with the limit and NOT EXISTS, without GROUP BY or aggregate, diff --git a/mysql-test/r/loaddata.result b/mysql-test/r/loaddata.result index 328d26eec72..932c1c76027 100644 --- a/mysql-test/r/loaddata.result +++ b/mysql-test/r/loaddata.result @@ -5,8 +5,8 @@ Warnings: Warning 1265 Data truncated for column 'a' at row 1 Warning 1265 Data truncated for column 'c' at row 1 Warning 1265 Data truncated for column 'd' at row 1 -Warning 1264 Out of range value for column 'a' at row 2 -Warning 1264 Out of range value for column 'b' at row 2 +Warning 1265 Data truncated for column 'a' at row 2 +Warning 1265 Data truncated for column 'b' at row 2 Warning 1265 Data truncated for column 'd' at row 2 load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES; SELECT * from t1; @@ -20,7 +20,7 @@ load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated Warnings: Warning 1265 Data truncated for column 'c' at row 1 Warning 1265 Data truncated for column 'd' at row 1 -Warning 1264 Out of range value for column 'b' at row 2 +Warning 1265 Data truncated for column 'b' at row 2 Warning 1265 Data truncated for column 'd' at row 2 SELECT * from t1; a b c d diff --git a/mysql-test/r/lock_multi.result b/mysql-test/r/lock_multi.result index 67712ccabe6..f9e4a88fe95 100644 --- a/mysql-test/r/lock_multi.result +++ b/mysql-test/r/lock_multi.result @@ -18,7 +18,7 @@ n 4 drop table t1; create table t1(n int); -insert into t1 values (1); +insert into t1 values (1),(2); select get_lock("mysqltest_lock", 100); get_lock("mysqltest_lock", 100) 1 @@ -27,11 +27,13 @@ update low_priority t1 set n = 4; select n from t1; n 1 +2 select release_lock("mysqltest_lock"); release_lock("mysqltest_lock") 1 n 1 +2 select release_lock("mysqltest_lock"); release_lock("mysqltest_lock") 1 diff --git a/mysql-test/r/log_slow.result b/mysql-test/r/log_slow.result index 89846dc698c..6500ba3ca53 100644 --- a/mysql-test/r/log_slow.result +++ b/mysql-test/r/log_slow.result @@ -45,7 +45,7 @@ select @@log_slow_verbosity; innodb show fields from mysql.slow_log; Field Type Null Key Default Extra -start_time timestamp(6) NO CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP +start_time timestamp(6) NO CURRENT_TIMESTAMP(6) on update CURRENT_TIMESTAMP user_host mediumtext NO NULL query_time time(6) NO NULL lock_time time(6) NO NULL diff --git a/mysql-test/r/log_tables.result b/mysql-test/r/log_tables.result index 62775f3db4d..d03540c9c27 100644 --- a/mysql-test/r/log_tables.result +++ b/mysql-test/r/log_tables.result @@ -53,7 +53,7 @@ ERROR HY000: You can't use locks with log tables. show create table mysql.general_log; Table Create Table general_log CREATE TABLE `general_log` ( - `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `user_host` mediumtext NOT NULL, `thread_id` int(11) NOT NULL, `server_id` int(10) unsigned NOT NULL, @@ -62,7 +62,7 @@ general_log CREATE TABLE `general_log` ( ) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='General log' show fields from mysql.general_log; Field Type Null Key Default Extra -event_time timestamp(6) NO CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP +event_time timestamp(6) NO CURRENT_TIMESTAMP(6) on update CURRENT_TIMESTAMP user_host mediumtext NO NULL thread_id int(11) NO NULL server_id int(10) unsigned NO NULL @@ -71,7 +71,7 @@ argument mediumtext NO NULL show create table mysql.slow_log; Table Create Table slow_log CREATE TABLE `slow_log` ( - `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `user_host` mediumtext NOT NULL, `query_time` time(6) NOT NULL, `lock_time` time(6) NOT NULL, @@ -85,7 +85,7 @@ slow_log CREATE TABLE `slow_log` ( ) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log' show fields from mysql.slow_log; Field Type Null Key Default Extra -start_time timestamp(6) NO CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP +start_time timestamp(6) NO CURRENT_TIMESTAMP(6) on update CURRENT_TIMESTAMP user_host mediumtext NO NULL query_time time(6) NO NULL lock_time time(6) NO NULL @@ -164,7 +164,7 @@ set global slow_query_log='OFF'; show create table mysql.general_log; Table Create Table general_log CREATE TABLE `general_log` ( - `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `user_host` mediumtext NOT NULL, `thread_id` int(11) NOT NULL, `server_id` int(10) unsigned NOT NULL, @@ -174,7 +174,7 @@ general_log CREATE TABLE `general_log` ( show create table mysql.slow_log; Table Create Table slow_log CREATE TABLE `slow_log` ( - `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `user_host` mediumtext NOT NULL, `query_time` time(6) NOT NULL, `lock_time` time(6) NOT NULL, @@ -191,7 +191,7 @@ alter table mysql.slow_log engine=myisam; show create table mysql.general_log; Table Create Table general_log CREATE TABLE `general_log` ( - `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `user_host` mediumtext NOT NULL, `thread_id` int(11) NOT NULL, `server_id` int(10) unsigned NOT NULL, @@ -201,7 +201,7 @@ general_log CREATE TABLE `general_log` ( show create table mysql.slow_log; Table Create Table slow_log CREATE TABLE `slow_log` ( - `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `user_host` mediumtext NOT NULL, `query_time` time(6) NOT NULL, `lock_time` time(6) NOT NULL, @@ -251,7 +251,7 @@ alter table mysql.slow_log engine=NonExistentEngine; Warnings: Warning 1286 Unknown storage engine 'NonExistentEngine' alter table mysql.slow_log engine=memory; -ERROR HY000: This storage engine cannot be used for log tables +ERROR HY000: Storage engine MEMORY cannot be used for log tables set storage_engine= @save_storage_engine; drop table mysql.slow_log; drop table mysql.general_log; diff --git a/mysql-test/r/log_tables_upgrade.result b/mysql-test/r/log_tables_upgrade.result index 5ed59eecc31..bae329073a7 100644 --- a/mysql-test/r/log_tables_upgrade.result +++ b/mysql-test/r/log_tables_upgrade.result @@ -19,22 +19,27 @@ mtr mtr.global_suppressions OK mtr.test_suppressions OK mysql +mysql.column_stats OK mysql.columns_priv OK mysql.db OK mysql.event OK mysql.func OK +mysql.gtid_slave_pos OK mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stats OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.proxies_priv OK mysql.renamed_general_log OK +mysql.roles_mapping OK mysql.servers OK +mysql.table_stats OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK diff --git a/mysql-test/r/lowercase_table2.result b/mysql-test/r/lowercase_table2.result index abd16641b56..ac368a06bc9 100644 --- a/mysql-test/r/lowercase_table2.result +++ b/mysql-test/r/lowercase_table2.result @@ -272,7 +272,7 @@ Database Table In_use Name_locked test t_bug44738_uppercase 0 0 # So attempt to create table with the same name should fail. create table t_bug44738_UPPERCASE (i int); -ERROR HY000: Can't find file: 't_bug44738_uppercase' (errno: 2) +ERROR HY000: Can't find file: './test/t_bug44738_uppercase.MYI' (errno: 2 "No such file or directory") # And should succeed after FLUSH TABLES. flush tables; create table t_bug44738_UPPERCASE (i int); diff --git a/mysql-test/r/mdev-504.result b/mysql-test/r/mdev-504.result new file mode 100644 index 00000000000..e178127cf2a --- /dev/null +++ b/mysql-test/r/mdev-504.result @@ -0,0 +1,21 @@ +CREATE TABLE A ( +pk INTEGER AUTO_INCREMENT PRIMARY KEY, +fdate DATE +) ENGINE=MyISAM; +CREATE PROCEDURE p_analyze() +BEGIN +DECLARE attempts INTEGER DEFAULT 100; +wl_loop: WHILE attempts > 0 DO +ANALYZE TABLE A; +SET attempts = attempts - 1; +END WHILE wl_loop; +END | +CREATE FUNCTION rnd3() RETURNS INT +BEGIN +RETURN ROUND(3 * RAND() + 0.5); +END | +SET GLOBAL use_stat_tables = PREFERABLY; +DROP TABLE A; +DROP PROCEDURE p_analyze; +DROP FUNCTION rnd3; +SET GLOBAL use_stat_tables = DEFAULT; diff --git a/mysql-test/r/mdl_sync.result b/mysql-test/r/mdl_sync.result index 4f929a5760f..de905454a63 100644 --- a/mysql-test/r/mdl_sync.result +++ b/mysql-test/r/mdl_sync.result @@ -2830,7 +2830,7 @@ SET DEBUG_SYNC= 'now SIGNAL blocked'; # Reaping: DROP DATABASE db1 # Connection con2 # Reaping: RENAME TABLE db1.t1 TO test.t1 -Got one of the listed errors +ERROR 42S02: Table 'db1.t1' doesn't exist # Connection default CREATE DATABASE db1; CREATE TABLE test.t2 (a INT); diff --git a/mysql-test/r/merge.result b/mysql-test/r/merge.result index 41ee148cee3..c0b23651e70 100644 --- a/mysql-test/r/merge.result +++ b/mysql-test/r/merge.result @@ -2257,7 +2257,7 @@ CREATE TABLE m1(a int)engine=merge union=(t1,t2,t3,t4,t5,t6,t7); SELECT 1 FROM m1; 1 HANDLER m1 OPEN; -ERROR HY000: Table storage engine for 'm1' doesn't have this option +ERROR HY000: Storage engine MRG_MyISAM of the table `test`.`m1` doesn't have this option DROP TABLE m1,t1,t2,t3,t4,t5,t6,t7; SELECT 1 FROM m1; ERROR 42S02: Table 'test.m1' doesn't exist @@ -2890,7 +2890,7 @@ Table Create Table m2 CREATE TEMPORARY TABLE `m2` ( `c1` int(11) DEFAULT NULL, `c2` int(11) DEFAULT NULL -) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) +) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) SELECT * FROM m2; c1 c2 111 121 @@ -2907,7 +2907,7 @@ Table Create Table m1 CREATE TEMPORARY TABLE `m1` ( `c1` int(11) DEFAULT NULL, `c2` int(11) DEFAULT NULL -) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) +) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) SELECT * FROM m1; c1 c2 111 121 @@ -2996,7 +2996,7 @@ Table Create Table m1 CREATE TEMPORARY TABLE `m1` ( `c1` int(11) DEFAULT NULL, `c2` int(11) DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 +) ENGINE=MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1 INSERT INTO m1 VALUES (511, 521); SELECT * FROM m1; c1 c2 @@ -3047,7 +3047,7 @@ Table Create Table m1 CREATE TEMPORARY TABLE `m1` ( `c1` int(11) DEFAULT NULL, `c2` int(11) DEFAULT NULL -) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) +) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) # CREATE TABLE m2 SELECT * FROM m1; SHOW CREATE TABLE m2; @@ -3099,7 +3099,7 @@ Table Create Table m2 CREATE TABLE `m2` ( `c1` int(11) DEFAULT NULL, `c2` int(11) DEFAULT NULL -) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) +) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) SELECT * FROM m2; c1 c2 111 121 @@ -3125,7 +3125,7 @@ Table Create Table m2 CREATE TEMPORARY TABLE `m2` ( `c1` int(11) DEFAULT NULL, `c2` int(11) DEFAULT NULL -) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) +) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) SELECT * FROM m2; c1 c2 111 121 @@ -3295,7 +3295,7 @@ Table Create Table m2 CREATE TEMPORARY TABLE `m2` ( `c1` int(11) DEFAULT NULL, `c2` int(11) DEFAULT NULL -) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) +) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) SELECT * FROM m2; c1 c2 111 121 @@ -3312,7 +3312,7 @@ Table Create Table m1 CREATE TEMPORARY TABLE `m1` ( `c1` int(11) DEFAULT NULL, `c2` int(11) DEFAULT NULL -) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) +) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) SELECT * FROM m1; c1 c2 111 121 @@ -3403,7 +3403,7 @@ Table Create Table m1 CREATE TEMPORARY TABLE `m1` ( `c1` int(11) DEFAULT NULL, `c2` int(11) DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 +) ENGINE=MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1 INSERT INTO m1 VALUES (511, 521); SELECT * FROM m1; c1 c2 @@ -3454,7 +3454,7 @@ Table Create Table m1 CREATE TEMPORARY TABLE `m1` ( `c1` int(11) DEFAULT NULL, `c2` int(11) DEFAULT NULL -) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) +) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) CREATE TABLE m2 SELECT * FROM m1; ERROR HY000: Table 'm2' was not locked with LOCK TABLES # @@ -3499,14 +3499,14 @@ Table Create Table m2 CREATE TEMPORARY TABLE `m2` ( `c1` int(11) DEFAULT NULL, `c2` int(11) DEFAULT NULL -) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) +) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) LOCK TABLE m1 WRITE, m2 WRITE; SHOW CREATE TABLE m2; Table Create Table m2 CREATE TEMPORARY TABLE `m2` ( `c1` int(11) DEFAULT NULL, `c2` int(11) DEFAULT NULL -) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) +) ENGINE=MRG_MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1 INSERT_METHOD=LAST UNION=(`t1`,`t2`) SELECT * FROM m2; c1 c2 111 121 @@ -3559,7 +3559,7 @@ CREATE TABLE t2 (c1 int); CREATE TABLE t3 (c1 int) ENGINE = MERGE UNION (t1,t2); START TRANSACTION; HANDLER t3 OPEN; -ERROR HY000: Table storage engine for 't3' doesn't have this option +ERROR HY000: Storage engine MRG_MyISAM of the table `test`.`t3` doesn't have this option DROP TABLE t1, t2, t3; # Connection default. # Disconnecting con1, all mdl_tickets must have been released. diff --git a/mysql-test/r/multi_update.result b/mysql-test/r/multi_update.result index 7386af13e2c..b490c8610f2 100644 --- a/mysql-test/r/multi_update.result +++ b/mysql-test/r/multi_update.result @@ -605,7 +605,7 @@ a b 4 4 show binlog events from <binlog_start>; Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Table_map # # table_id: # (test.t2) master-bin.000001 # Update_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Query # # COMMIT @@ -618,7 +618,7 @@ UPDATE t2,t1 SET t2.a=t2.b where t2.a=t1.a; ERROR 23000: Duplicate entry '4' for key 'PRIMARY' show binlog events from <binlog_start>; Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Table_map # # table_id: # (test.t2) master-bin.000001 # Update_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Query # # COMMIT diff --git a/mysql-test/r/myisam-metadata.result b/mysql-test/r/myisam-metadata.result index 4d49bac9436..f13e4ac8b60 100644 --- a/mysql-test/r/myisam-metadata.result +++ b/mysql-test/r/myisam-metadata.result @@ -5,7 +5,7 @@ a VARCHAR(100), INDEX(a) ) ENGINE=MyISAM; ALTER TABLE t1 DISABLE KEYS; -SET debug_sync= 'myisam_after_repair_by_sort SIGNAL waiting WAIT_FOR go'; +SET debug_sync= 'myisam_before_repair_by_sort SIGNAL waiting WAIT_FOR go'; ALTER TABLE t1 ENABLE KEYS; SET debug_sync= 'now WAIT_FOR waiting'; SET debug_sync= 'now SIGNAL go'; diff --git a/mysql-test/r/myisam-system.result b/mysql-test/r/myisam-system.result index b3ba8066f5c..9d5a59459ec 100644 --- a/mysql-test/r/myisam-system.result +++ b/mysql-test/r/myisam-system.result @@ -2,12 +2,18 @@ drop table if exists t1,t2; create table t1 (a int) engine=myisam; drop table if exists t1; Warnings: -Warning 2 Can't find file: 't1' (errno: 2) +Warning 2 Can't find file: './test/t1.MYI' (errno: 2 "No such file or directory") create table t1 (a int) engine=myisam; +select * from t1; +ERROR HY000: Can't find file: './test/t1.MYI' (errno: 2 "No such file or directory") drop table t1; -Got one of the listed errors +Warnings: +Warning 2 Can't find file: './test/t1.MYI' (errno: 2 "No such file or directory") create table t1 (a int) engine=myisam; +select * from t1; +ERROR HY000: File './test/t1.MYD' not found (Errcode: 2 "No such file or directory") drop table t1; -Got one of the listed errors +Warnings: +Warning 2 Can't find file: './test/t1.MYI' (errno: 2 "No such file or directory") drop table t1; ERROR 42S02: Unknown table 't1' diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result index c969b237293..267110be487 100644 --- a/mysql-test/r/myisam.result +++ b/mysql-test/r/myisam.result @@ -618,7 +618,7 @@ t1 1 a 1 a A 1000 NULL NULL YES BTREE alter table t1 engine=heap; alter table t1 disable keys; Warnings: -Note 1031 Table storage engine for 't1' doesn't have this option +Note 1031 Storage engine MEMORY of the table `test`.`t1` doesn't have this option 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 1 a 1 a NULL 500 NULL NULL YES HASH @@ -1697,7 +1697,7 @@ t1 CREATE TABLE `t1` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; create table t1 (v varchar(65535)); -ERROR 42000: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs +ERROR 42000: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs set storage_engine=MyISAM; set @save_concurrent_insert=@@concurrent_insert; set global concurrent_insert=1; @@ -2355,7 +2355,7 @@ Warnings: Warning 1292 Truncated incorrect myisam_sort_buffer_size value: '4' REPAIR TABLE t1; Table Op Msg_type Msg_text -test.t1 repair error myisam_sort_buffer_size is too small +test.t1 repair error myisam_sort_buffer_size is too small. X test.t1 repair warning Number of rows changed from 0 to 7168 test.t1 repair status OK SET myisam_repair_threads=2; @@ -2424,7 +2424,7 @@ INSERT INTO t1 VALUES ('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'), ('0'),('0'),('0'),('0'),('0'),('0'),('0'); Warnings: -Error 1034 myisam_sort_buffer_size is too small +Error 1034 myisam_sort_buffer_size is too small. X Error 1034 Number of rows changed from 0 to 157 SET myisam_sort_buffer_size=@@global.myisam_sort_buffer_size; INSERT INTO t1 VALUES('1'); diff --git a/mysql-test/r/myisam_explain_non_select_all.result b/mysql-test/r/myisam_explain_non_select_all.result new file mode 100644 index 00000000000..86e3ffbff6c --- /dev/null +++ b/mysql-test/r/myisam_explain_non_select_all.result @@ -0,0 +1,2907 @@ +set @save_storage_engine= @@session.default_storage_engine; +set session default_storage_engine = MyISAM; +#1 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +# +# query: UPDATE t1 SET a = 10 WHERE a < 10 +# select: SELECT * FROM t1 WHERE a < 10 +# +EXPLAIN UPDATE t1 SET a = 10 WHERE a < 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a < 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a < 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` < 10) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 4 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd_next 4 +Handler_update 3 + +DROP TABLE t1; +#2 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +# +# query: DELETE FROM t1 WHERE a < 10 +# select: SELECT * FROM t1 WHERE a < 10 +# +EXPLAIN DELETE FROM t1 WHERE a < 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1 WHERE a < 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a < 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` < 10) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 4 +# Status of testing query execution: +Variable_name Value +Handler_delete 3 +Handler_read_rnd_next 4 + +DROP TABLE t1; +#3 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +# +# query: DELETE FROM t1 USING t1 WHERE a = 1 +# select: SELECT * FROM t1 WHERE a = 1 +# +EXPLAIN DELETE FROM t1 USING t1 WHERE a = 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1 USING t1 WHERE a = 1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a = 1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 1) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 4 +# Status of testing query execution: +Variable_name Value +Handler_delete 1 +Handler_read_rnd_next 4 + +DROP TABLE t1; +#4 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (1), (2), (3); +# +# query: UPDATE t1, t2 SET t1.a = 10 WHERE t1.a = 1 +# select: SELECT * FROM t1, t2 WHERE t1.a = 1 +# +EXPLAIN UPDATE t1, t2 SET t1.a = 10 WHERE t1.a = 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1, t2 SET t1.a = 10 WHERE t1.a = 1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1, t2 WHERE t1.a = 1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t1`.`a` = 1) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 8 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd_next 8 +Handler_update 1 + +DROP TABLE t1, t2; +#5 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (1), (2), (3); +# +# query: UPDATE t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a = 1 +# select: SELECT * FROM t1 t11, (SELECT * FROM t2) t12 WHERE t11.a = 1 +# +EXPLAIN UPDATE t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a = 1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t11 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 +2 DERIVED t2 ALL NULL NULL NULL NULL 3 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a = 1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 100.00 +2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT * FROM t2) t12 WHERE t11.a = 1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t11 ALL NULL NULL NULL NULL 3 100.00 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t11`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` `t11` join `test`.`t2` where (`test`.`t11`.`a` = 1) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 8 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd_next 12 +Handler_update 1 + +DROP TABLE t1, t2; +#6 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (1), (2), (3); +# +# query: UPDATE t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3) +# select: SELECT * FROM t1 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3) +# +EXPLAIN UPDATE t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3); +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 t2 ALL NULL NULL NULL NULL 3 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +Handler_read_rnd_next 1 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where (`test`.`t2`.`b` < 3) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 1 +Handler_read_rnd_next 8 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd_next 5 +Handler_update 3 + +DROP TABLE t1, t2; +#7 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (1), (2), (3); +# +# query: UPDATE t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3) +# select: SELECT * FROM t1 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3) +# +EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3); +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 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3); +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 t2 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a IN (SELECT b FROM t2 WHERE t1.a < 3); +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 t2 ALL NULL NULL NULL NULL 3 100.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`b` = `test`.`t1`.`a`) and (`test`.`t1`.`a` < 3)) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 8 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd_next 7 +Handler_update 2 + +DROP TABLE t1, t2; +#7 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (1), (2), (3); +# +# query: UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3) +# select: SELECT * FROM t1, t2 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3) +# +EXPLAIN UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3); +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 <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1, t2 WHERE a IN (SELECT b FROM t2 WHERE t2.b < 3); +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 <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` semi join (`test`.`t2`) join `test`.`t2` where ((`test`.`t2`.`b` < 3)) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 3 +Handler_read_rnd_next 12 +# Status of testing query execution: +Variable_name Value +Handler_read_key 3 +Handler_read_rnd_next 16 +Handler_update 2 + +DROP TABLE t1, t2; +#8 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (1), (2), (3); +# +# query: UPDATE t1 t11, (SELECT * FROM t2) t12 SET t11.a = t11.a + 10 +# select: SELECT * FROM t1 t11, (SELECT * FROM t2) t12 +# +EXPLAIN UPDATE t1 t11, (SELECT * FROM t2) t12 SET t11.a = t11.a + 10; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t11 ALL NULL NULL NULL NULL 3 +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 +2 DERIVED t2 ALL NULL NULL NULL NULL 3 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 t11, (SELECT * FROM t2) t12 SET t11.a = t11.a + 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 100.00 +2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT * FROM t2) t12; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t11 ALL NULL NULL NULL NULL 3 100.00 +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t11`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` `t11` join `test`.`t2` +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 8 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd 3 +Handler_read_rnd_deleted 1 +Handler_read_rnd_next 24 +Handler_update 3 + +DROP TABLE t1, t2; +#9 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (1), (2), (3); +# +# query: UPDATE t1 t11, (SELECT 1 FROM DUAL) t12 SET t11.a = t11.a + 10 +# select: SELECT * FROM t1 t11, (SELECT 1 FROM DUAL) t12 +# +EXPLAIN UPDATE t1 t11, (SELECT 1 FROM DUAL) t12 SET t11.a = t11.a + 10; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> system NULL NULL NULL NULL 1 +1 PRIMARY t11 ALL NULL NULL NULL NULL 3 +2 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 t11, (SELECT 1 FROM DUAL) t12 SET t11.a = t11.a + 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00 +1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00 +2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used +# Status of EXPLAIN EXTENDED query +Variable_name Value +Handler_read_rnd_next 1 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT 1 FROM DUAL) t12; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00 +1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00 +2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select `test`.`t11`.`a` AS `a`,1 AS `1` from `test`.`t1` `t11` +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +Handler_read_rnd_next 1 +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 5 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd 3 +Handler_read_rnd_next 9 +Handler_update 3 + +DROP TABLE t1, t2; +#10 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (1), (2), (3); +# +# query: UPDATE t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a > 1 +# select: SELECT * FROM t1 t11, (SELECT * FROM t2) t12 WHERE t11.a > 1 +# +EXPLAIN UPDATE t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a > 1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t11 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 +2 DERIVED t2 ALL NULL NULL NULL NULL 3 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 t11, (SELECT * FROM t2) t12 SET t11.a = 10 WHERE t11.a > 1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t11 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 100.00 +2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 t11, (SELECT * FROM t2) t12 WHERE t11.a > 1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t11 ALL NULL NULL NULL NULL 3 100.00 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t11`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` `t11` join `test`.`t2` where (`test`.`t11`.`a` > 1) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 8 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd_next 16 +Handler_update 2 + +DROP TABLE t1, t2; +#11 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +# +# query: DELETE FROM t1 WHERE a > 1 LIMIT 1 +# select: SELECT * FROM t1 WHERE a > 1 LIMIT 1 +# +EXPLAIN DELETE FROM t1 WHERE a > 1 LIMIT 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1 WHERE a > 1 LIMIT 1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a > 1 LIMIT 1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 1) limit 1 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 2 +# Status of testing query execution: +Variable_name Value +Handler_delete 1 +Handler_read_rnd_next 2 + +DROP TABLE t1; +#12 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +# +# query: DELETE FROM t1 WHERE 0 +# select: SELECT * FROM t1 WHERE 0 +# +EXPLAIN DELETE FROM t1 WHERE 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1 WHERE 0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE 0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +# Status of testing query execution: +Variable_name Value + +DROP TABLE t1; +#13 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +# +# query: DELETE FROM t1 USING t1 WHERE 0 +# select: SELECT * FROM t1 WHERE 0 +# +EXPLAIN DELETE FROM t1 USING t1 WHERE 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1 USING t1 WHERE 0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE 0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +# Status of testing query execution: +Variable_name Value + +DROP TABLE t1; +#14 +CREATE TABLE t1 (a INT, b INT, UNIQUE KEY (a), KEY (b)); +INSERT INTO t1 VALUES (3, 3), (7, 7); +# +# query: DELETE FROM t1 WHERE a = 3 +# select: SELECT * FROM t1 WHERE a = 3 +# +EXPLAIN DELETE FROM t1 WHERE a = 3; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 5 NULL 1 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1 WHERE a = 3; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range a a 5 NULL 1 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a = 3; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 const a a 5 const 1 100.00 +Warnings: +Note 1003 select 3 AS `a`,3 AS `b` from `test`.`t1` where 1 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +Handler_read_key 1 +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 1 +# Status of testing query execution: +Variable_name Value +Handler_delete 1 +Handler_read_key 1 + +DROP TABLE t1; +#15 +CREATE TABLE t1 (a INT, b INT, UNIQUE KEY (a), KEY (b)); +INSERT INTO t1 VALUES (3, 3), (7, 7); +# +# query: DELETE FROM t1 WHERE a < 3 +# select: SELECT * FROM t1 WHERE a < 3 +# +EXPLAIN DELETE FROM t1 WHERE a < 3; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 5 NULL 1 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1 WHERE a < 3; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range a a 5 NULL 1 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a < 3; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range a a 5 NULL 1 100.00 Using index condition +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a` < 3) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 1 +# Status of testing query execution: +Variable_name Value +Handler_read_key 1 + +DROP TABLE t1; +#16 +CREATE TABLE t1 ( a int PRIMARY KEY ); +# +# query: DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a +# select: SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a +# +EXPLAIN DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select NULL AS `a` from `test`.`t1` where 0 order by NULL +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +Handler_read_rnd_next 1 +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 1 +# Status of testing query execution: +Variable_name Value +Handler_read_key 1 + +INSERT INTO t1 VALUES (1), (2), (3); +# +# query: DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a +# select: SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a +# +EXPLAIN DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE t1.a > 0 ORDER BY t1.a; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 3 100.00 Using where; Using index +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 0) order by `test`.`t1`.`a` +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_first 1 +Handler_read_next 3 +# Status of testing query execution: +Variable_name Value +Handler_delete 3 +Handler_read_key 1 +Handler_read_next 3 + +DROP TABLE t1; +#17 +CREATE TABLE t1(a INT PRIMARY KEY); +INSERT INTO t1 VALUES (4),(3),(1),(2); +# +# query: DELETE FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1 +# select: SELECT * FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1 +# +EXPLAIN DELETE FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index NULL PRIMARY 4 NULL 1 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 index NULL PRIMARY 4 NULL 1 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE (@a:= a) ORDER BY a LIMIT 1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 index NULL PRIMARY 4 NULL 1 100.00 Using where; Using index +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (@a:=`test`.`t1`.`a`) order by `test`.`t1`.`a` limit 1 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_first 1 +# Status of testing query execution: +Variable_name Value +Handler_delete 1 +Handler_read_first 1 + +DROP TABLE t1; +#18 +CREATE TABLE t1 (a DATE, b TIME, c INT, KEY c(c), KEY b(b), KEY a(a)); +INSERT INTO t1 VALUES (), (), (), (), (), (), (), (), (), (); +UPDATE t1 SET a = c, b = c; +# +# query: DELETE FROM t1 ORDER BY a ASC, b ASC LIMIT 1 +# select: SELECT * FROM t1 ORDER BY a ASC, b ASC LIMIT 1 +# +EXPLAIN DELETE FROM t1 ORDER BY a ASC, b ASC LIMIT 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1 ORDER BY a ASC, b ASC LIMIT 1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 100.00 Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 ORDER BY a ASC, b ASC LIMIT 1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 100.00 Using filesort +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` order by `test`.`t1`.`a`,`test`.`t1`.`b` limit 1 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 11 +Sort_rows 1 +Sort_scan 1 +# Status of testing query execution: +Variable_name Value +Handler_delete 1 +Handler_read_rnd 1 +Handler_read_rnd_next 11 +Sort_rows 10 +Sort_scan 1 + +DROP TABLE t1; +#19 +CREATE TABLE t1 (a1 INT NOT NULL, b1 INT NOT NULL); +CREATE TABLE t2 (a2 INT NOT NULL, b2 INT NOT NULL, PRIMARY KEY (a2,b2)); +CREATE TABLE t3 (a3 INT NOT NULL, b3 INT NOT NULL, PRIMARY KEY (a3,b3)); +INSERT INTO t1 VALUES (1,1), (2,1), (1,3); +INSERT INTO t2 VALUES (1,1), (2,2), (3,3); +INSERT INTO t3 VALUES (1,1), (2,1), (1,3); +# +# query: DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3 +# select: SELECT * FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3 +# +EXPLAIN DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 +1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 8 test.t2.b2,test.t1.b1 1 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE t1,t2,t3 FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 100.00 +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 8 test.t2.b2,test.t1.b1 1 100.00 +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1,t2,t3 WHERE a1=a2 AND b2=a3 AND b1=b3; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a1 1 100.00 Using index +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 8 test.t2.b2,test.t1.b1 1 100.00 Using index +Warnings: +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2`,`test`.`t3`.`a3` AS `a3`,`test`.`t3`.`b3` AS `b3` from `test`.`t1` join `test`.`t2` join `test`.`t3` where ((`test`.`t2`.`a2` = `test`.`t1`.`a1`) and (`test`.`t3`.`a3` = `test`.`t2`.`b2`) and (`test`.`t3`.`b3` = `test`.`t1`.`b1`)) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 6 +Handler_read_next 3 +Handler_read_rnd_next 4 +# Status of testing query execution: +Variable_name Value +Handler_delete 8 +Handler_read_key 6 +Handler_read_next 3 +Handler_read_rnd 5 +Handler_read_rnd_next 4 + +DROP TABLE t1, t2, t3; +#20 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +CREATE TABLE t2 (a INT); +INSERT INTO t2 VALUES (1), (2), (3); +# +# query: UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2) +# select: SELECT * FROM t1 WHERE a IN (SELECT a FROM t2) +# +EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2); +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 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 3 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2); +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 t2 ALL NULL NULL NULL NULL 3 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a IN (SELECT a FROM t2); +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 <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where 1 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 3 +Handler_read_rnd_next 8 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd_next 10 +Handler_update 3 + +DROP TABLE t1, t2; +#21 +CREATE TABLE t1 (a1 INT); +INSERT INTO t1 VALUES (1), (2), (3), (4), (5); +CREATE TABLE t2 (a2 VARCHAR(10)); +INSERT INTO t2 VALUES (1), (2), (3), (4), (5); +SET @save_optimizer_switch= @@optimizer_switch; +# +# query: DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2) +# select: SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2) +# +EXPLAIN DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2); +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 Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2); +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 Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a1` AS `a1` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t1`.`a1`,<exists>(select `test`.`t2`.`a2` from `test`.`t2` where ((`test`.`t2`.`a2` > 2) and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`a2`))))) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 5 +Handler_read_rnd_next 30 +# Status of testing query execution: +Variable_name Value +Handler_delete 3 +Handler_read_rnd_next 30 + +SET @@optimizer_switch= @save_optimizer_switch; +TRUNCATE t1; +INSERT INTO t1 VALUES (1), (2), (3), (4), (5); +# +# query: DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2) +# select: SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2) +# +EXPLAIN DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2); +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 Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a1 IN (SELECT a2 FROM t2 WHERE a2 > 2); +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 +1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`a1` AS `a1` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`a2` > 2) and (`test`.`t1`.`a1` = `test`.`t2`.`a2`)) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 12 +# Status of testing query execution: +Variable_name Value +Handler_delete 3 +Handler_read_rnd_next 30 + +DROP TABLE t1, t2; +#22 +CREATE TABLE t1 (i INT, j INT); +INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5); +# +# query: UPDATE t1 SET i = 10 +# select: SELECT * FROM t1 +# +EXPLAIN UPDATE t1 SET i = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 5 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 SET i = 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 +Warnings: +Note 1003 select `test`.`t1`.`i` AS `i`,`test`.`t1`.`j` AS `j` from `test`.`t1` +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 6 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd_next 6 +Handler_update 5 + +DROP TABLE t1; +#23 +CREATE TABLE t1 (i INT, j INT); +INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5); +# +# query: DELETE FROM t1 +# select: SELECT * FROM t1 +# +EXPLAIN DELETE FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL 5 Deleting all rows +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL 5 NULL Deleting all rows +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 5 100.00 +Warnings: +Note 1003 select `test`.`t1`.`i` AS `i`,`test`.`t1`.`j` AS `j` from `test`.`t1` +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 6 +# Status of testing query execution: +Variable_name Value + +DROP TABLE t1; +#24 +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c)); +INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1; +INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2; +# +# query: DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5 +# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5 +# +EXPLAIN DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index NULL a 15 NULL 5 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_first 1 +Handler_read_next 4 +# Status of testing query execution: +Variable_name Value +Handler_delete 5 +Handler_read_first 1 +Handler_read_next 4 + +DROP TABLE t1, t2; +#25 +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (1), (2), (3); +CREATE TABLE t2 (i INT); +# +# query: INSERT INTO t2 SELECT * FROM t1 +# select: SELECT * FROM t1 +# +EXPLAIN INSERT INTO t2 SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED INSERT INTO t2 SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1003 select `test`.`t1`.`i` AS `i` from `test`.`t1` +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 4 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd_next 4 +Handler_write 3 + +DROP TABLE t1, t2; +#26 +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (1), (2), (3); +CREATE TABLE t2 (i INT); +# +# query: REPLACE INTO t2 SELECT * FROM t1 +# select: SELECT * FROM t1 +# +EXPLAIN REPLACE INTO t2 SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED REPLACE INTO t2 SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1003 select `test`.`t1`.`i` AS `i` from `test`.`t1` +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 4 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd_next 4 +Handler_write 3 + +DROP TABLE t1, t2; +#27 +CREATE TABLE t1 (i INT); +# +# query: INSERT INTO t1 SET i = 10 +# select: +# +EXPLAIN INSERT INTO t1 SET i = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED INSERT INTO t1 SET i = 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL +# Status of EXPLAIN EXTENDED query +Variable_name Value +# Status of testing query execution: +Variable_name Value +Handler_write 1 + +DROP TABLE t1; +#28 +CREATE TABLE t1 (i INT); +# +# query: REPLACE INTO t1 SET i = 10 +# select: +# +EXPLAIN REPLACE INTO t1 SET i = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED REPLACE INTO t1 SET i = 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL +# Status of EXPLAIN EXTENDED query +Variable_name Value +# Status of testing query execution: +Variable_name Value +Handler_write 1 + +DROP TABLE t1; +#29 +CREATE TABLE t1 (a INT, i INT PRIMARY KEY); +INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +# +# query: DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5 +# select: SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5 +# +EXPLAIN DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 8 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 8 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 8 100.00 Using index condition +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`i` AS `i` from `test`.`t1` where ((`test`.`t1`.`i` > 10) and (`test`.`t1`.`i` <= 18)) order by `test`.`t1`.`i` limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 1 +Handler_read_next 4 +# Status of testing query execution: +Variable_name Value +Handler_delete 5 +Handler_read_key 1 +Handler_read_next 4 + +DROP TABLE t1; +#30 +CREATE TABLE t1(a INT, i CHAR(2), INDEX(i(1))); +INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +# +# query: DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5 +# select: SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5 +# +EXPLAIN DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 26 Using where; Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL i NULL NULL NULL 26 100.00 Using where; Using filesort +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`i` AS `i` from `test`.`t1` where ((`test`.`t1`.`i` > 10) and (`test`.`t1`.`i` <= 18)) order by `test`.`t1`.`i` limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 27 +Sort_rows 5 +Sort_scan 1 +# Status of testing query execution: +Variable_name Value +Handler_delete 5 +Handler_read_rnd 5 +Handler_read_rnd_next 27 +Sort_rows 8 +Sort_scan 1 + +DROP TABLE t1; +#31 +CREATE TABLE t1 (i INT); +INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c)); +INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1; +# +# query: DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5 +# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5 +# +EXPLAIN DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using where; Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 27 +Sort_rows 1 +Sort_scan 1 +# Status of testing query execution: +Variable_name Value +Handler_delete 1 +Handler_read_rnd 1 +Handler_read_rnd_next 27 +Sort_rows 1 +Sort_scan 1 + +DROP TABLE t1, t2; +#32 +CREATE TABLE t1 (i INT); +INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c)); +INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1; +INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2; +# +# query: DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5 +# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5 +# +EXPLAIN DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index NULL a 15 NULL 5 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_first 1 +Handler_read_next 4 +# Status of testing query execution: +Variable_name Value +Handler_delete 5 +Handler_read_first 1 +Handler_read_next 4 + +DROP TABLE t1, t2; +#33 +CREATE TABLE t1 (i INT); +INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b(1),c)); +INSERT INTO t2 SELECT i, i, i, i FROM t1; +# +# query: DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5 +# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5 +# +EXPLAIN DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using where; Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 27 +Sort_rows 1 +Sort_scan 1 +# Status of testing query execution: +Variable_name Value +Handler_delete 1 +Handler_read_rnd 1 +Handler_read_rnd_next 27 +Sort_rows 1 +Sort_scan 1 + +DROP TABLE t1, t2; +#34 +CREATE TABLE t1 (i INT); +INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b,c)) +ENGINE=HEAP; +INSERT INTO t2 SELECT i, i, i, i FROM t1; +# +# query: DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5 +# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5 +# +EXPLAIN DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using where; Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd 1 +Handler_read_rnd_next 27 +Sort_rows 1 +Sort_scan 1 +# Status of testing query execution: +Variable_name Value +Handler_delete 1 +Handler_read_rnd 1 +Handler_read_rnd_next 27 +Sort_rows 1 +Sort_scan 1 + +DROP TABLE t1, t2; +#35 +CREATE TABLE t1 (i INT); +INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35),(36),(37),(38),(39), +(40),(41),(42); +CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2)); +INSERT INTO t2 (key1, key2) SELECT i, i FROM t1; +# +# query: DELETE FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1 +# select: SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1 +# +EXPLAIN DELETE FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index_merge key1,key2 key1,key2 5,5 NULL 7 Using sort_union(key1,key2); Using where; Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 index_merge key1,key2 key1,key2 5,5 NULL 7 100.00 Using sort_union(key1,key2); Using where; Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 index_merge key1,key2 key1,key2 5,5 NULL 7 100.00 Using sort_union(key1,key2); Using where; Using filesort +Warnings: +Note 1003 select `test`.`t2`.`i` AS `i`,`test`.`t2`.`key1` AS `key1`,`test`.`t2`.`key2` AS `key2` from `test`.`t2` where ((`test`.`t2`.`key1` < 13) or (`test`.`t2`.`key2` < 14)) order by `test`.`t2`.`key1` +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 2 +Handler_read_next 7 +Handler_read_rnd 4 +Sort_range 1 +Sort_rows 4 +# Status of testing query execution: +Variable_name Value +Handler_delete 4 +Handler_read_key 2 +Handler_read_next 7 +Handler_read_rnd 8 +Sort_range 1 +Sort_rows 4 + +DROP TABLE t1, t2; +#36 +CREATE TABLE t1 (i INT); +INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2(a INT, i INT PRIMARY KEY); +INSERT INTO t2 (i) SELECT i FROM t1; +# +# query: DELETE FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5 +# select: SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5 +# +EXPLAIN DELETE FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 8 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 8 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 8 100.00 Using where +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` desc limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 1 +Handler_read_prev 4 +# Status of testing query execution: +Variable_name Value +Handler_delete 5 +Handler_read_key 1 +Handler_read_prev 4 + +DROP TABLE t1, t2; +#37 +CREATE TABLE t1 (i INT); +INSERT INTO t1 (i) VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), INDEX (a, b)); +INSERT INTO t2 SELECT i, i, i FROM t1; +# +# query: DELETE FROM t2 ORDER BY a, b DESC LIMIT 5 +# select: SELECT * FROM t2 ORDER BY a, b DESC LIMIT 5 +# +EXPLAIN DELETE FROM t2 ORDER BY a, b DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t2 ORDER BY a, b DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 ORDER BY a, b DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using filesort +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 27 +Sort_rows 5 +Sort_scan 1 +# Status of testing query execution: +Variable_name Value +Handler_delete 5 +Handler_read_rnd 5 +Handler_read_rnd_next 27 +Sort_rows 26 +Sort_scan 1 + +DROP TABLE t1, t2; +#38 +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2 (a CHAR(2), b CHAR(2), c INT, INDEX (a, b)); +INSERT INTO t2 (a, b) SELECT i, i FROM t1; +INSERT INTO t2 (a, b) SELECT t1.i, t1.i FROM t1, t1 x1, t1 x2; +# +# query: DELETE FROM t2 ORDER BY a DESC, b DESC LIMIT 5 +# select: SELECT * FROM t2 ORDER BY a DESC, b DESC LIMIT 5 +# +EXPLAIN DELETE FROM t2 ORDER BY a DESC, b DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index NULL a 6 NULL 5 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t2 ORDER BY a DESC, b DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 index NULL a 6 NULL 5 100.00 +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 ORDER BY a DESC, b DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 index NULL a 6 NULL 5 100.00 +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_last 1 +Handler_read_prev 4 +# Status of testing query execution: +Variable_name Value +Handler_delete 5 +Handler_read_last 1 +Handler_read_prev 4 + +DROP TABLE t1, t2; +#39 +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2(a INT, i INT PRIMARY KEY); +INSERT INTO t2 (i) SELECT i FROM t1; +# +# query: UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5 +# select: SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5 +# +EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 8 Using where; Using buffer +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 8 100.00 Using where; Using buffer +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 8 100.00 Using index condition +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 1 +Handler_read_next 4 +# Status of testing query execution: +Variable_name Value +Handler_read_key 1 +Handler_read_next 4 +Handler_read_rnd 5 +Handler_update 5 + +DROP TABLE t1, t2; +#40 +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2(a INT, i CHAR(2), INDEX(i(1))); +INSERT INTO t2 (i) SELECT i FROM t1; +# +# query: UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5 +# select: SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5 +# +EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using where; Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL i NULL NULL NULL 26 100.00 Using where; Using filesort +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 27 +Sort_rows 5 +Sort_scan 1 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd 5 +Handler_read_rnd_next 27 +Handler_update 5 +Sort_rows 5 +Sort_scan 1 + +DROP TABLE t1, t2; +#41 +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c)); +INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1; +# +# query: UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5 +# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5 +# +EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using where; Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 27 +Sort_rows 1 +Sort_scan 1 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd 1 +Handler_read_rnd_next 27 +Handler_update 1 +Sort_rows 1 +Sort_scan 1 + +DROP TABLE t1, t2; +#42 +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2(a INT, b INT, c INT, d INT, INDEX(a, b, c)); +INSERT INTO t2 (a, b, c) SELECT i, i, i FROM t1; +INSERT INTO t2 (a, b, c) SELECT t1.i, t1.i, t1.i FROM t1, t1 x1, t1 x2; +# +# query: UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5 +# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5 +# +EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index NULL a 15 NULL 5 Using where; Using buffer +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where; Using buffer +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_first 1 +Handler_read_next 4 +# Status of testing query execution: +Variable_name Value +Handler_read_first 1 +Handler_read_next 4 +Handler_read_rnd 5 +Handler_update 5 + +DROP TABLE t1, t2; +#43 +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b(1),c)); +INSERT INTO t2 SELECT i, i, i, i FROM t1; +# +# query: UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5 +# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5 +# +EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using where; Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 27 +Sort_rows 1 +Sort_scan 1 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd 1 +Handler_read_rnd_next 27 +Sort_rows 1 +Sort_scan 1 + +DROP TABLE t1, t2; +#44 +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), d CHAR(2), INDEX (a,b,c)) +ENGINE=HEAP; +INSERT INTO t2 SELECT i, i, i, i FROM t1; +# +# query: UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5 +# select: SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5 +# +EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using where; Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` where (`test`.`t2`.`b` = 10) order by `test`.`t2`.`a`,`test`.`t2`.`c` limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd 1 +Handler_read_rnd_next 27 +Sort_rows 1 +Sort_scan 1 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd 1 +Handler_read_rnd_next 27 +Sort_rows 1 +Sort_scan 1 + +DROP TABLE t1, t2; +#45 +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35),(36),(37),(38),(39), +(40),(41),(42); +CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2)); +INSERT INTO t2 (key1, key2) SELECT i, i FROM t1; +# +# query: UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1 +# select: SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1 +# +EXPLAIN UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index_merge key1,key2 key1,key2 5,5 NULL 7 Using sort_union(key1,key2); Using where; Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t2 SET i = 123 WHERE key1 < 13 or key2 < 14 ORDER BY key1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 index_merge key1,key2 key1,key2 5,5 NULL 7 100.00 Using sort_union(key1,key2); Using where; Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 index_merge key1,key2 key1,key2 5,5 NULL 7 100.00 Using sort_union(key1,key2); Using where; Using filesort +Warnings: +Note 1003 select `test`.`t2`.`i` AS `i`,`test`.`t2`.`key1` AS `key1`,`test`.`t2`.`key2` AS `key2` from `test`.`t2` where ((`test`.`t2`.`key1` < 13) or (`test`.`t2`.`key2` < 14)) order by `test`.`t2`.`key1` +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 2 +Handler_read_next 7 +Handler_read_rnd 4 +Sort_range 1 +Sort_rows 4 +# Status of testing query execution: +Variable_name Value +Handler_read_key 2 +Handler_read_next 7 +Handler_read_rnd 8 +Handler_update 4 +Sort_range 1 +Sort_rows 4 + +DROP TABLE t1, t2; +#46 +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2(a INT, i INT PRIMARY KEY); +INSERT INTO t2 (i) SELECT i FROM t1; +# +# query: UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5 +# select: SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5 +# +EXPLAIN UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 8 Using where; Using buffer +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t2 SET a = 10 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 8 100.00 Using where; Using buffer +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 WHERE i > 10 AND i <= 18 ORDER BY i DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 8 100.00 Using where +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`i` AS `i` from `test`.`t2` where ((`test`.`t2`.`i` > 10) and (`test`.`t2`.`i` <= 18)) order by `test`.`t2`.`i` desc limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 1 +Handler_read_prev 4 +# Status of testing query execution: +Variable_name Value +Handler_read_key 1 +Handler_read_prev 4 +Handler_read_rnd 5 +Handler_update 5 + +DROP TABLE t1, t2; +#47 +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2 (a CHAR(2), b CHAR(2), c CHAR(2), INDEX (a, b)); +INSERT INTO t2 SELECT i, i, i FROM t1; +# +# query: UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5 +# select: SELECT * FROM t2 ORDER BY a, b DESC LIMIT 5 +# +EXPLAIN UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a, b DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 ORDER BY a, b DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using filesort +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a`,`test`.`t2`.`b` desc limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 27 +Sort_rows 5 +Sort_scan 1 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd 5 +Handler_read_rnd_next 27 +Handler_update 4 +Sort_rows 5 +Sort_scan 1 + +DROP TABLE t1, t2; +#48 +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19), +(20),(21),(22),(23),(24),(25),(26),(27),(28),(29), +(30),(31),(32),(33),(34),(35); +CREATE TABLE t2 (a CHAR(2), b CHAR(2), c INT, INDEX (a, b)); +INSERT INTO t2 (a, b) SELECT i, i FROM t1; +INSERT INTO t2 (a, b) SELECT t1.i, t1.i FROM t1, t1 x1, t1 x2; +# +# query: UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5 +# select: SELECT * FROM t2 ORDER BY a DESC, b DESC LIMIT 5 +# +EXPLAIN UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index NULL a 6 NULL 5 Using buffer +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t2 SET c = 10 ORDER BY a DESC, b DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 index NULL a 6 NULL 5 100.00 Using buffer +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2 ORDER BY a DESC, b DESC LIMIT 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 index NULL a 6 NULL 5 100.00 +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` order by `test`.`t2`.`a` desc,`test`.`t2`.`b` desc limit 5 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_last 1 +Handler_read_prev 4 +# Status of testing query execution: +Variable_name Value +Handler_read_last 1 +Handler_read_prev 4 +Handler_read_rnd 5 +Handler_update 5 + +DROP TABLE t1, t2; +#49 +CREATE TABLE t1 ( +pk INT NOT NULL AUTO_INCREMENT, +c1_idx CHAR(1) DEFAULT 'y', +c2 INT, +PRIMARY KEY (pk), +INDEX c1_idx (c1_idx) +); +INSERT INTO t1 VALUES (1,'y',1), (2,'n',2), (3,'y',3), (4,'n',4); +# +# query: UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2 +# select: SELECT * FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2 +# +EXPLAIN UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range c1_idx c1_idx 2 NULL 2 Using where; Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 SET c2 = 0 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range c1_idx c1_idx 2 NULL 2 100.00 Using where; Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ref c1_idx c1_idx 2 const 2 100.00 Using index condition; Using where; Using filesort +Warnings: +Note 1003 select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1_idx` AS `c1_idx`,`test`.`t1`.`c2` AS `c2` from `test`.`t1` where (`test`.`t1`.`c1_idx` = 'y') order by `test`.`t1`.`pk` desc limit 2 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 1 +Handler_read_next 2 +Sort_range 1 +Sort_rows 2 +# Status of testing query execution: +Variable_name Value +Handler_read_key 1 +Handler_read_next 2 +Handler_read_rnd 2 +Handler_update 2 +Sort_range 1 +Sort_rows 2 + +# +# query: DELETE FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2 +# select: SELECT * FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2 +# +EXPLAIN DELETE FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range c1_idx c1_idx 2 NULL 2 Using where; Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range c1_idx c1_idx 2 NULL 2 100.00 Using where; Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE c1_idx = 'y' ORDER BY pk DESC LIMIT 2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ref c1_idx c1_idx 2 const 2 100.00 Using index condition; Using where; Using filesort +Warnings: +Note 1003 select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`c1_idx` AS `c1_idx`,`test`.`t1`.`c2` AS `c2` from `test`.`t1` where (`test`.`t1`.`c1_idx` = 'y') order by `test`.`t1`.`pk` desc limit 2 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 1 +Handler_read_next 2 +Sort_range 1 +Sort_rows 2 +# Status of testing query execution: +Variable_name Value +Handler_delete 2 +Handler_read_key 1 +Handler_read_next 2 +Handler_read_rnd 2 +Sort_range 1 +Sort_rows 2 + +DROP TABLE t1; +#50 +CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY); +INSERT INTO t1 VALUES (),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(); +# +# query: UPDATE t1 SET a=a+10 WHERE a > 34 +# select: SELECT * FROM t1 WHERE a > 34 +# +EXPLAIN UPDATE t1 SET a=a+10 WHERE a > 34; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 Using where; Using buffer +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 SET a=a+10 WHERE a > 34; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where; Using buffer +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a > 34; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where; Using index +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 34) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 1 +Handler_read_next 2 +# Status of testing query execution: +Variable_name Value +Handler_read_key 1 +Handler_read_next 2 +Handler_read_rnd 2 +Handler_update 2 + +DROP TABLE t1; +#51 +CREATE TABLE t1 (c1 INT, c2 INT, c3 INT); +CREATE TABLE t2 (c1 INT, c2 INT); +INSERT INTO t1 VALUES (1, 1, 10), (2, 2, 20); +# +# query: UPDATE t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 +# select: SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1 +# +EXPLAIN UPDATE t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 system NULL NULL NULL NULL 0 const row not found +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +# Status of EXPLAIN EXTENDED query +Variable_name Value +Handler_read_rnd_next 1 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +Warnings: +Note 1003 select `test`.`t1`.`c1` AS `c1`,`test`.`t1`.`c2` AS `c2`,`test`.`t1`.`c3` AS `c3`,NULL AS `c1`,NULL AS `c2` from `test`.`t1` +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +Handler_read_rnd_next 1 +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 4 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd_next 4 + +# +# query: UPDATE t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 WHERE t1.c3 = 10 +# select: SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1 WHERE t1.c3 = 10 +# +EXPLAIN UPDATE t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 WHERE t1.c3 = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 system NULL NULL NULL NULL 0 const row not found +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 LEFT JOIN t2 ON t1.c1 = t2.c1 SET t2.c2 = 10 WHERE t1.c3 = 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +Handler_read_rnd_next 1 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 LEFT JOIN t2 ON t1.c1 = t2.c1 WHERE t1.c3 = 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 system NULL NULL NULL NULL 0 0.00 const row not found +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`c1` AS `c1`,`test`.`t1`.`c2` AS `c2`,`test`.`t1`.`c3` AS `c3`,NULL AS `c1`,NULL AS `c2` from `test`.`t1` where (`test`.`t1`.`c3` = 10) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +Handler_read_rnd_next 1 +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 4 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd_next 4 + +DROP TABLE t1, t2; +#52 +CREATE TABLE t1(f1 INT, f2 INT); +CREATE TABLE t2(f3 INT, f4 INT); +CREATE INDEX IDX ON t2(f3); +INSERT INTO t1 VALUES(1,0),(2,0); +INSERT INTO t2 VALUES(1,1),(2,2); +# +# query: UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1) +# select: SELECT (SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1) FROM t1 +# +EXPLAIN UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +2 DEPENDENT SUBQUERY t2 ALL IDX NULL NULL NULL 2 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1); +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 +2 DEPENDENT SUBQUERY t2 ALL IDX NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1 +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT (SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1) FROM t1; +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 +2 DEPENDENT SUBQUERY t2 ALL IDX NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1 +Note 1003 select <expr_cache><`test`.`t1`.`f1`>((select max(`test`.`t2`.`f4`) from `test`.`t2` where (`test`.`t2`.`f3` = `test`.`t1`.`f1`))) AS `(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1)` from `test`.`t1` +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 2 +Handler_read_rnd_next 9 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd_next 9 +Handler_update 2 + +DROP TABLE t1, t2; +#55 +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUES (1); +SET @a = NULL; +EXPLAIN DELETE FROM t1 WHERE (@a:= a); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 1 Using where +DROP TABLE t1; +#56 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +DELETE FROM t1 USING t1 WHERE uknown_column = 12345; +ERROR 42S22: Unknown column 'uknown_column' in 'where clause' +EXPLAIN EXTENDED DELETE FROM t1 USING t1 WHERE uknown_column = 12345; +ERROR 42S22: Unknown column 'uknown_column' in 'where clause' +DROP TABLE t1; +#57 +CREATE TABLE t1(f1 INT); +EXPLAIN EXTENDED UPDATE t1 SET f2=1 ORDER BY f2; +ERROR 42S22: Unknown column 'f2' in 'order clause' +UPDATE t1 SET f2=1 ORDER BY f2; +ERROR 42S22: Unknown column 'f2' in 'order clause' +DROP TABLE t1; +#62 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0), (1); +CREATE VIEW v1 AS SELECT t11.a, t12.a AS b FROM t1 t11, t1 t12; +# +# query: UPDATE v1 SET a = 1 WHERE a > 0 +# select: SELECT * FROM v1 WHERE a > 0 +# +EXPLAIN UPDATE v1 SET a = 1 WHERE a > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t11 ALL NULL NULL NULL NULL 2 Using where +1 SIMPLE t12 ALL NULL NULL NULL NULL 2 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE v1 SET a = 1 WHERE a > 0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t11 ALL NULL NULL NULL NULL 2 100.00 Using where +1 SIMPLE t12 ALL NULL NULL NULL NULL 2 100.00 +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM v1 WHERE a > 0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t11 ALL NULL NULL NULL NULL 2 100.00 Using where +1 SIMPLE t12 ALL NULL NULL NULL NULL 2 100.00 Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t11`.`a` AS `a`,`test`.`t12`.`a` AS `b` from `test`.`t1` `t11` join `test`.`t1` `t12` where (`test`.`t11`.`a` > 0) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 6 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd 1 +Handler_read_rnd_deleted 1 +Handler_read_rnd_next 8 + +# +# query: UPDATE t1, v1 SET v1.a = 1 WHERE t1.a = v1.a +# select: SELECT * FROM t1, v1 WHERE t1.a = v1.a +# +EXPLAIN UPDATE t1, v1 SET v1.a = 1 WHERE t1.a = v1.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 +1 SIMPLE t11 ALL NULL NULL NULL NULL 2 Using where +1 SIMPLE t12 ALL NULL NULL NULL NULL 2 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1, v1 SET v1.a = 1 WHERE t1.a = v1.a; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +1 SIMPLE t11 ALL NULL NULL NULL NULL 2 100.00 Using where +1 SIMPLE t12 ALL NULL NULL NULL NULL 2 100.00 +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1, v1 WHERE t1.a = v1.a; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 +1 SIMPLE t11 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t12 ALL NULL NULL NULL NULL 2 100.00 Using join buffer (incremental, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t11`.`a` AS `a`,`test`.`t12`.`a` AS `b` from `test`.`t1` join `test`.`t1` `t11` join `test`.`t1` `t12` where (`test`.`t11`.`a` = `test`.`t1`.`a`) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 9 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd 2 +Handler_read_rnd_deleted 1 +Handler_read_rnd_next 18 +Handler_update 1 + +DROP TABLE t1; +DROP VIEW v1; +#63 +CREATE TABLE t1 (a INT, PRIMARY KEY(a)); +INSERT INTO t1 VALUES (1), (2), (3), (4), (5); +CREATE VIEW v1 (a) AS SELECT a FROM t1; +# +# query: DELETE FROM v1 WHERE a < 4 +# select: SELECT * FROM v1 WHERE a < 4 +# +EXPLAIN DELETE FROM v1 WHERE a < 4; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 Using where +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE FROM v1 WHERE a < 4; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM v1 WHERE a < 4; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where; Using index +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` < 4) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_first 1 +Handler_read_next 3 +# Status of testing query execution: +Variable_name Value +Handler_delete 3 +Handler_read_first 1 +Handler_read_next 3 + +DROP TABLE t1; +DROP VIEW v1; +#64 +CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a)); +INSERT INTO t1 VALUES (1,2), (2,3), (3,4), (4,5), (5,10); +CREATE TABLE t2 (x INT); +INSERT INTO t2 VALUES (1), (2), (3), (4); +CREATE VIEW v1 (a,c) AS SELECT a, b+1 FROM t1; +# +# query: DELETE v1 FROM t2, v1 WHERE t2.x = v1.a +# select: SELECT * FROM t2, v1 WHERE t2.x = v1.a +# +EXPLAIN DELETE v1 FROM t2, v1 WHERE t2.x = v1.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00 +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2, v1 WHERE t2.x = v1.a; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00 +Warnings: +Note 1003 select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 4 +Handler_read_rnd_next 5 +# Status of testing query execution: +Variable_name Value +Handler_delete 4 +Handler_read_key 4 +Handler_read_rnd 4 +Handler_read_rnd_next 5 + +DROP TABLE t1,t2; +DROP VIEW v1; +#65 +CREATE TABLE t1 (a INT, b INT, PRIMARY KEY(a)); +INSERT INTO t1 VALUES (1,2), (2,3), (3,4), (4,5), (5,10); +CREATE TABLE t2 (x INT); +INSERT INTO t2 VALUES (1), (2), (3), (4); +CREATE VIEW v1 (a,c) AS SELECT a, b+1 FROM t1; +# +# query: DELETE v1 FROM t2, v1 WHERE t2.x = v1.a +# select: SELECT * FROM t2, v1 WHERE t2.x = v1.a +# +EXPLAIN DELETE v1 FROM t2, v1 WHERE t2.x = v1.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED DELETE v1 FROM t2, v1 WHERE t2.x = v1.a; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00 +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t2, v1 WHERE t2.x = v1.a; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00 +Warnings: +Note 1003 select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 4 +Handler_read_rnd_next 5 +# Status of testing query execution: +Variable_name Value +Handler_delete 4 +Handler_read_key 4 +Handler_read_rnd 4 +Handler_read_rnd_next 5 + +DROP TABLE t1,t2; +DROP VIEW v1; +#66 +CREATE TABLE t1 (a INT); +CREATE VIEW v1 (x) AS SELECT a FROM t1; +# +# query: INSERT INTO v1 VALUES (10) +# select: SELECT NULL +# +EXPLAIN INSERT INTO v1 VALUES (10); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED INSERT INTO v1 VALUES (10); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL 100.00 NULL +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select NULL AS `NULL` +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +# Status of testing query execution: +Variable_name Value +Handler_write 1 + +DROP TABLE t1; +DROP VIEW v1; +#67 +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (1), (2), (3); +CREATE VIEW v1 (x) AS SELECT b FROM t2; +# +# query: INSERT INTO v1 SELECT * FROM t1 +# select: SELECT * FROM t1 +# +EXPLAIN INSERT INTO v1 SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 system NULL NULL NULL NULL 0 const row not found +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED INSERT INTO v1 SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 system NULL NULL NULL NULL 0 0.00 const row not found +# Status of EXPLAIN EXTENDED query +Variable_name Value +Handler_read_rnd_next 1 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 system NULL NULL NULL NULL 0 0.00 const row not found +Warnings: +Note 1003 select NULL AS `a` from `test`.`t1` +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +Handler_read_rnd_next 1 +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 1 +# Status of testing query execution: +Variable_name Value +Handler_read_rnd_next 1 + +DROP TABLE t1, t2; +DROP VIEW v1; +#68 +CREATE TABLE t1 (i INT); +EXPLAIN INSERT DELAYED INTO t1 VALUES (1); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +DROP TABLE t1; +#69 +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1), (2), (3); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (1), (2), (3); +# +# query: UPDATE t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x) +# select: SELECT * FROM t1 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x) +# +EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x); +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 DEPENDENT SUBQUERY <derived3> index_subquery key0 key0 5 func 2 +3 DERIVED t2 ALL NULL NULL NULL NULL 3 Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x); +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 <derived3> index_subquery key0 key0 5 func 2 100.00 +3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x); +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 <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 100.00 +3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join ((select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) where 1 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 3 +Handler_read_rnd_next 10 +Sort_rows 3 +Sort_scan 1 +# Status of testing query execution: +Variable_name Value +Handler_read_key 3 +Handler_read_rnd_next 8 +Handler_update 1 +Sort_rows 3 +Sort_scan 1 + +# +# query: UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x) +# select: SELECT * FROM t1, t2 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x) +# +EXPLAIN UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 +2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 +3 DERIVED t2 ALL NULL NULL NULL NULL 3 Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1, t2 SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x); +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 <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 +2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 100.00 +3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1, t2 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x); +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 <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join) +2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 100.00 +3 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` semi join ((select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) join `test`.`t2` where 1 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 3 +Handler_read_rnd_next 10 +Sort_rows 3 +Sort_scan 1 +# Status of testing query execution: +Variable_name Value +Handler_read_key 3 +Handler_read_rnd_next 10 +Sort_rows 3 +Sort_scan 1 + +# +# query: UPDATE t1, (SELECT * FROM t2) y SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x) +# select: SELECT * FROM t1, (SELECT * FROM t2) y WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x) +# +EXPLAIN UPDATE t1, (SELECT * FROM t2) y SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1 +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 +3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 3 +4 DERIVED t2 ALL NULL NULL NULL NULL 3 Using filesort +2 DERIVED t2 ALL NULL NULL NULL NULL 3 +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1, (SELECT * FROM t2) y SET a = 10 WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x); +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 <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00 +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 100.00 +3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 3 100.00 +4 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort +2 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT * FROM t1, (SELECT * FROM t2) y WHERE a IN (SELECT * FROM (SELECT b FROM t2 ORDER BY b LIMIT 2,2) x); +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 <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join) +3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 3 100.00 +4 DERIVED t2 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` semi join ((select `test`.`t2`.`b` AS `b` from `test`.`t2` order by `test`.`t2`.`b` limit 2,2) `x`) join `test`.`t2` where 1 +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_key 3 +Handler_read_rnd_next 10 +Sort_rows 3 +Sort_scan 1 +# Status of testing query execution: +Variable_name Value +Handler_read_key 3 +Handler_read_rnd_next 10 +Sort_rows 3 +Sort_scan 1 + +DROP TABLE t1,t2; +#70 +CREATE TABLE t1 (c1 INT KEY); +CREATE TABLE t2 (c2 INT); +CREATE TABLE t3 (c3 INT); +EXPLAIN EXTENDED UPDATE t3 SET c3 = ( +SELECT COUNT(d1.c1) +FROM ( +SELECT a11.c1 FROM t1 AS a11 +STRAIGHT_JOIN t2 AS a21 ON a21.c2 = a11.c1 +JOIN t1 AS a12 ON a12.c1 = a11.c1 +) d1 +); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t3 ALL NULL NULL NULL NULL 0 100.00 +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +DROP TABLE t1, t2, t3; +#73 +CREATE TABLE t1 (id INT); +CREATE TABLE t2 (id INT); +INSERT INTO t1 VALUES (1), (2); +EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USING(id) GROUP BY t1.id; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 system NULL NULL NULL NULL 0 const row not found; Using temporary; Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 +DROP TABLE t1,t2; +#74 +CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB; +Warnings: +Warning 1286 Unknown storage engine 'InnoDB' +Warning 1266 Using storage engine MyISAM for table 't1' +INSERT INTO t1 VALUES (1), (2), (3), (4), (5); +# used key is modified & Using temporary +# +# query: UPDATE t1 SET a=a+1 WHERE a>10 +# select: SELECT a t1 FROM t1 WHERE a>10 +# +EXPLAIN UPDATE t1 SET a=a+1 WHERE a>10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 Using where; Using buffer +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 SET a=a+1 WHERE a>10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 100.00 Using where; Using buffer +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT a t1 FROM t1 WHERE a>10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 5 20.00 Using where; Using index +Warnings: +Note 1003 select `test`.`t1`.`a` AS `t1` from `test`.`t1` where (`test`.`t1`.`a` > 10) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_first 1 +Handler_read_next 5 +# Status of testing query execution: +Variable_name Value +Handler_read_key 1 + +# used key is modified & Using filesort +# +# query: UPDATE t1 SET a=a+1 WHERE a>10 ORDER BY a+20 +# select: SELECT a t1 FROM t1 WHERE a>10 ORDER BY a+20 +# +EXPLAIN UPDATE t1 SET a=a+1 WHERE a>10 ORDER BY a+20; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 Using where; Using filesort +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED UPDATE t1 SET a=a+1 WHERE a>10 ORDER BY a+20; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 100.00 Using where; Using filesort +# Status of EXPLAIN EXTENDED query +Variable_name Value +FLUSH STATUS; +FLUSH TABLES; +EXPLAIN EXTENDED SELECT a t1 FROM t1 WHERE a>10 ORDER BY a+20; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 5 20.00 Using where; Using index; Using filesort +Warnings: +Note 1003 select `test`.`t1`.`a` AS `t1` from `test`.`t1` where (`test`.`t1`.`a` > 10) order by (`test`.`t1`.`a` + 20) +# Status of EXPLAIN EXTENDED "equivalent" SELECT query execution +Variable_name Value +# Status of "equivalent" SELECT query execution: +Variable_name Value +Handler_read_rnd_next 6 +Sort_scan 1 +# Status of testing query execution: +Variable_name Value +Handler_read_key 1 +Sort_range 1 + +DROP TABLE t1; +# +# Bug #12949629: CLIENT LOSES CONNECTION AFTER EXECUTING A PROCEDURE WITH +# EXPLAIN UPDATE/DEL/INS +# +CREATE TABLE t1 (i INT); +CREATE TABLE t2 (i INT); +CREATE PROCEDURE p1() BEGIN EXPLAIN INSERT INTO t1 VALUES (1);END| +CREATE PROCEDURE p2() BEGIN INSERT INTO t1 VALUES (1);END| +CREATE PROCEDURE p3() BEGIN EXPLAIN INSERT INTO t1 SELECT 1;END| +CREATE PROCEDURE p4() BEGIN INSERT INTO t1 SELECT 1;END| +CREATE PROCEDURE p5() BEGIN EXPLAIN REPLACE INTO t1 VALUES (1);END| +CREATE PROCEDURE p6() BEGIN REPLACE INTO t1 VALUES (1);END| +CREATE PROCEDURE p7() BEGIN EXPLAIN REPLACE INTO t1 SELECT 1;END| +CREATE PROCEDURE p8() BEGIN REPLACE INTO t1 SELECT 1;END| +CREATE PROCEDURE p9() BEGIN EXPLAIN UPDATE t1 SET i = 10;END| +CREATE PROCEDURE p10() BEGIN UPDATE t1 SET i = 10;END| +CREATE PROCEDURE p11() BEGIN EXPLAIN UPDATE t1,t2 SET t1.i = 10 WHERE t1.i = t2.i ;END| +CREATE PROCEDURE p12() BEGIN UPDATE t1,t2 SET t1.i = 10 WHERE t1.i = t2.i ;END| +CREATE PROCEDURE p13() BEGIN EXPLAIN DELETE FROM t1;END| +CREATE PROCEDURE p14() BEGIN DELETE FROM t1;END| +CREATE PROCEDURE p15() BEGIN EXPLAIN DELETE FROM t1 USING t1;END| +CREATE PROCEDURE p16() BEGIN DELETE FROM t1 USING t1;END| +CALL p16(); +DROP PROCEDURE p16; +CALL p15(); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 system NULL NULL NULL NULL 0 const row not found +DROP PROCEDURE p15; +CALL p14(); +DROP PROCEDURE p14; +CALL p13(); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL 0 Deleting all rows +DROP PROCEDURE p13; +CALL p12(); +DROP PROCEDURE p12; +CALL p11(); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +DROP PROCEDURE p11; +CALL p10(); +DROP PROCEDURE p10; +CALL p9(); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 0 +DROP PROCEDURE p9; +CALL p8(); +DROP PROCEDURE p8; +CALL p7(); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used +DROP PROCEDURE p7; +CALL p6(); +DROP PROCEDURE p6; +CALL p5(); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +DROP PROCEDURE p5; +CALL p4(); +DROP PROCEDURE p4; +CALL p3(); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used +DROP PROCEDURE p3; +CALL p2(); +DROP PROCEDURE p2; +CALL p1(); +id select_type table type possible_keys key key_len ref rows Extra +1 INSERT t1 ALL NULL NULL NULL NULL NULL NULL +DROP PROCEDURE p1; +DROP TABLE t1, t2; +# +set default_storage_engine= @save_storage_engine; +set optimizer_switch=default; diff --git a/mysql-test/r/myisam_optimize.result b/mysql-test/r/myisam_optimize.result index 341c3e180b8..ae0c5b59d06 100644 --- a/mysql-test/r/myisam_optimize.result +++ b/mysql-test/r/myisam_optimize.result @@ -11,7 +11,7 @@ select left(b,10), a from t1 order by a; left(b,10) a CCCCCCCCCC 3 CCCCCCCCCC 4 -set debug_sync='myisam_after_repair_by_sort wait_for go'; +set debug_sync='myisam_before_repair_by_sort wait_for go'; optimize table t1; select a, left(b,10) from t1 order by a; set debug_sync='now signal go'; diff --git a/mysql-test/r/myisampack.result b/mysql-test/r/myisampack.result index 56f61ccdf47..2cefa385048 100644 --- a/mysql-test/r/myisampack.result +++ b/mysql-test/r/myisampack.result @@ -113,7 +113,7 @@ ERROR 42S02: Table 'test.t3' doesn't exist # ===== myisampack.4 ===== #Tests the myisampack join operation with an existing destination .frm,.MYI,.MDI #the command should fail with exit status 2 -myisampack: Can't create/write to file (Errcode: 17) +myisampack: Can't create/write to file (Errcode: 17 "File exists") Aborted: file is not compressed DROP TABLE t1,t2,t3; DROP TABLE mysql_db1.t1; diff --git a/mysql-test/r/mysql_client_test.result b/mysql-test/r/mysql_client_test.result index 7875464ebe2..4ad07b20ab5 100644 --- a/mysql-test/r/mysql_client_test.result +++ b/mysql-test/r/mysql_client_test.result @@ -1,5 +1,6 @@ SET @old_general_log= @@global.general_log; SET @old_slow_query_log= @@global.slow_query_log; +call mtr.add_suppression(" Error reading file './client_test_db/test_frm_bug.frm'"); ok # cat MYSQL_TMP_DIR/test_wl4435.out.log diff --git a/mysql-test/r/mysql_client_test_nonblock.result b/mysql-test/r/mysql_client_test_nonblock.result index edda7980e97..e37e2132b0c 100644 --- a/mysql-test/r/mysql_client_test_nonblock.result +++ b/mysql-test/r/mysql_client_test_nonblock.result @@ -1,5 +1,6 @@ SET @old_general_log= @@global.general_log; SET @old_slow_query_log= @@global.slow_query_log; +call mtr.add_suppression(" Error reading file './client_test_db/test_frm_bug.frm'"); ok SET @@global.general_log= @old_general_log; SET @@global.slow_query_log= @old_slow_query_log; diff --git a/mysql-test/r/mysql_upgrade.result b/mysql-test/r/mysql_upgrade.result index 285b00ae27f..17e7a0d933f 100644 --- a/mysql-test/r/mysql_upgrade.result +++ b/mysql-test/r/mysql_upgrade.result @@ -7,21 +7,26 @@ mtr mtr.global_suppressions OK mtr.test_suppressions OK mysql +mysql.column_stats OK mysql.columns_priv OK mysql.db OK mysql.event OK mysql.func OK +mysql.gtid_slave_pos OK mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stats OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.proxies_priv OK +mysql.roles_mapping OK mysql.servers OK +mysql.table_stats OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK @@ -44,21 +49,26 @@ mtr mtr.global_suppressions OK mtr.test_suppressions OK mysql +mysql.column_stats OK mysql.columns_priv OK mysql.db OK mysql.event OK mysql.func OK +mysql.gtid_slave_pos OK mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stats OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.proxies_priv OK +mysql.roles_mapping OK mysql.servers OK +mysql.table_stats OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK @@ -81,21 +91,26 @@ mtr mtr.global_suppressions OK mtr.test_suppressions OK mysql +mysql.column_stats OK mysql.columns_priv OK mysql.db OK mysql.event OK mysql.func OK +mysql.gtid_slave_pos OK mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stats OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.proxies_priv OK +mysql.roles_mapping OK mysql.servers OK +mysql.table_stats OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK @@ -123,21 +138,26 @@ mtr mtr.global_suppressions OK mtr.test_suppressions OK mysql +mysql.column_stats OK mysql.columns_priv OK mysql.db OK mysql.event OK mysql.func OK +mysql.gtid_slave_pos OK mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stats OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.proxies_priv OK +mysql.roles_mapping OK mysql.servers OK +mysql.table_stats OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK @@ -166,21 +186,26 @@ mtr mtr.global_suppressions OK mtr.test_suppressions OK mysql +mysql.column_stats OK mysql.columns_priv OK mysql.db OK mysql.event OK mysql.func OK +mysql.gtid_slave_pos OK mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stats OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.proxies_priv OK +mysql.roles_mapping OK mysql.servers OK +mysql.table_stats OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK @@ -212,21 +237,26 @@ mtr mtr.global_suppressions OK mtr.test_suppressions OK mysql +mysql.column_stats OK mysql.columns_priv OK mysql.db OK mysql.event OK mysql.func OK +mysql.gtid_slave_pos OK mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stats OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.proxies_priv OK +mysql.roles_mapping OK mysql.servers OK +mysql.table_stats OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK @@ -261,21 +291,26 @@ mtr mtr.global_suppressions OK mtr.test_suppressions OK mysql +mysql.column_stats OK mysql.columns_priv OK mysql.db OK mysql.event OK mysql.func OK +mysql.gtid_slave_pos OK mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stats OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.proxies_priv OK +mysql.roles_mapping OK mysql.servers OK +mysql.table_stats OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK diff --git a/mysql-test/r/mysql_upgrade_ssl.result b/mysql-test/r/mysql_upgrade_ssl.result index a08e7c115cc..c8c4252c5c2 100644 --- a/mysql-test/r/mysql_upgrade_ssl.result +++ b/mysql-test/r/mysql_upgrade_ssl.result @@ -9,21 +9,26 @@ mtr mtr.global_suppressions OK mtr.test_suppressions OK mysql +mysql.column_stats OK mysql.columns_priv OK mysql.db OK mysql.event OK mysql.func OK +mysql.gtid_slave_pos OK mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stats OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.proxies_priv OK +mysql.roles_mapping OK mysql.servers OK +mysql.table_stats OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK diff --git a/mysql-test/r/mysqlbinlog-innodb.result b/mysql-test/r/mysqlbinlog-innodb.result index a5865fe4fac..f0358928c0e 100644 --- a/mysql-test/r/mysqlbinlog-innodb.result +++ b/mysql-test/r/mysqlbinlog-innodb.result @@ -24,6 +24,9 @@ FLUSH LOGS; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; ROLLBACK/*!*/; +BEGIN +/*!*/; +use `test`/*!*/; SET TIMESTAMP=1000000000/*!*/; SET @@session.pseudo_thread_id=999999999/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; @@ -33,14 +36,9 @@ SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/ 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/*!*/; -BEGIN -/*!*/; -use `test`/*!*/; -SET TIMESTAMP=1000000000/*!*/; INSERT INTO t1 VALUES (1) /*!*/; COMMIT/*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -57,6 +55,9 @@ ROLLBACK /* added by mysqlbinlog */; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; ROLLBACK/*!*/; +BEGIN +/*!*/; +use `foo`/*!*/; SET TIMESTAMP=1000000000/*!*/; SET @@session.pseudo_thread_id=999999999/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; @@ -66,14 +67,9 @@ SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/ 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/*!*/; -BEGIN -/*!*/; -use `foo`/*!*/; -SET TIMESTAMP=1000000000/*!*/; INSERT INTO t1 VALUES (1) /*!*/; COMMIT/*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; diff --git a/mysql-test/r/mysqlbinlog.result b/mysql-test/r/mysqlbinlog.result index 823c7dc8629..007ef38b413 100644 --- a/mysql-test/r/mysqlbinlog.result +++ b/mysql-test/r/mysqlbinlog.result @@ -37,7 +37,6 @@ create table t1 (word varchar(20)) SET TIMESTAMP=1000000000/*!*/; create table t2 (id int auto_increment not null primary key) /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -46,7 +45,6 @@ insert into t1 values ("abirvalg") SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET INSERT_ID=1/*!*/; @@ -56,7 +54,6 @@ insert into t2 values () SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -65,7 +62,6 @@ LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `t1` FI SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -74,7 +70,6 @@ LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `t1` FI SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -83,7 +78,6 @@ LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `t1` FI SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -103,6 +97,9 @@ ROLLBACK /* added by mysqlbinlog */; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; +BEGIN +/*!*/; +use `test`/*!*/; SET TIMESTAMP=1000000000/*!*/; SET @@session.pseudo_thread_id=999999999/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; @@ -112,16 +109,11 @@ SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/ 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/*!*/; -BEGIN -/*!*/; -use `test`/*!*/; -SET TIMESTAMP=1000000000/*!*/; LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `t1` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`word`) /*!*/; SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -142,6 +134,8 @@ ROLLBACK /* added by mysqlbinlog */; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; ROLLBACK/*!*/; +BEGIN +/*!*/; SET TIMESTAMP=1000000000/*!*/; SET @@session.pseudo_thread_id=999999999/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; @@ -151,37 +145,29 @@ SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/ 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/*!*/; -BEGIN -/*!*/; -SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET INSERT_ID=1/*!*/; SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -198,6 +184,9 @@ ROLLBACK /* added by mysqlbinlog */; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; +BEGIN +/*!*/; +use `test`/*!*/; SET TIMESTAMP=1000000000/*!*/; SET @@session.pseudo_thread_id=999999999/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; @@ -207,10 +196,6 @@ SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/ 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/*!*/; -BEGIN -/*!*/; -use `test`/*!*/; -SET TIMESTAMP=1000000000/*!*/; insert into t1 values ("Alas") /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -246,7 +231,6 @@ create table t1 (word varchar(20)) SET TIMESTAMP=1000000000/*!*/; create table t2 (id int auto_increment not null primary key) /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -255,7 +239,6 @@ insert into t1 values ("abirvalg") SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET INSERT_ID=1/*!*/; @@ -265,7 +248,6 @@ insert into t2 values () SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -274,7 +256,6 @@ LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `t1` FI SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -283,7 +264,6 @@ LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `t1` FI SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -292,7 +272,6 @@ LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `t1` FI SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -312,6 +291,9 @@ ROLLBACK /* added by mysqlbinlog */; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; +BEGIN +/*!*/; +use `test`/*!*/; SET TIMESTAMP=1000000000/*!*/; SET @@session.pseudo_thread_id=999999999/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; @@ -321,16 +303,11 @@ SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/ 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/*!*/; -BEGIN -/*!*/; -use `test`/*!*/; -SET TIMESTAMP=1000000000/*!*/; LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `t1` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`word`) /*!*/; SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -351,6 +328,8 @@ ROLLBACK /* added by mysqlbinlog */; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; ROLLBACK/*!*/; +BEGIN +/*!*/; SET TIMESTAMP=1000000000/*!*/; SET @@session.pseudo_thread_id=999999999/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; @@ -360,37 +339,29 @@ SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/ 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/*!*/; -BEGIN -/*!*/; -SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET INSERT_ID=1/*!*/; SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -407,6 +378,9 @@ ROLLBACK /* added by mysqlbinlog */; /*!40019 SET @@session.max_insert_delayed_threads=0*/; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; +BEGIN +/*!*/; +use `test`/*!*/; SET TIMESTAMP=1000000000/*!*/; SET @@session.pseudo_thread_id=999999999/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; @@ -416,10 +390,6 @@ SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/ 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/*!*/; -BEGIN -/*!*/; -use `test`/*!*/; -SET TIMESTAMP=1000000000/*!*/; insert into t1 values ("Alas") /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -583,7 +553,6 @@ SET @@session.lc_time_names=0/*!*/; SET @@session.collation_database=DEFAULT/*!*/; create table t1 (a varchar(64) character set utf8) /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -592,27 +561,24 @@ LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `t1` FI SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; -SET @@session.collation_database=7/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; +SET @@session.collation_database=7/*!*/; LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `t1` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`a`) /*!*/; SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; -SET @@session.collation_database=DEFAULT/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; +SET @@session.collation_database=DEFAULT/*!*/; LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `t1` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`a`) /*!*/; SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -621,27 +587,24 @@ LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `t1` FI SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; -SET @@session.collation_database=7/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; +SET @@session.collation_database=7/*!*/; LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `t1` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`a`) /*!*/; SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; -SET @@session.collation_database=DEFAULT/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; +SET @@session.collation_database=DEFAULT/*!*/; LOAD DATA LOCAL INFILE 'MYSQLTEST_VARDIR/tmp/SQL_LOAD_MB-#-#' INTO TABLE `t1` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' (`a`) /*!*/; SET TIMESTAMP=1000000000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=1000000000/*!*/; BEGIN /*!*/; SET TIMESTAMP=1000000000/*!*/; @@ -663,13 +626,13 @@ FLUSH LOGS; INSERT INTO t1 VALUES ('0123456789'); FLUSH LOGS; DROP TABLE t1; -We expect this value to be 1 +We expect this value to be 2 (one for the INSERT, one for COMMIT). The bug being tested was that 'Query' lines were not preceded by '#' If the line is in the table, it had to have been preceded by a '#' -SELECT COUNT(*) AS `BUG#28293_expect_3` FROM patch WHERE a LIKE '%Query%'; -BUG#28293_expect_3 -3 +SELECT COUNT(*) AS `BUG#28293_expect_2` FROM patch WHERE a LIKE '#%Query%'; +BUG#28293_expect_2 +2 DROP TABLE patch; FLUSH LOGS; CREATE TABLE t1(a INT); @@ -924,12 +887,20 @@ DROP DATABASE test1; FLUSH LOGS; show binlog events in 'master-bin.000002' from <binlog_start>; Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000002 # Binlog_checkpoint # # master-bin.000002 +master-bin.000002 # Gtid # # GTID #-#-# master-bin.000002 # Query # # CREATE DATABASE test1 +master-bin.000002 # Gtid # # GTID #-#-# master-bin.000002 # Query # # use `test1`; CREATE TABLE t1(id int) +master-bin.000002 # Gtid # # GTID #-#-# master-bin.000002 # Query # # DROP DATABASE test1 +master-bin.000002 # Gtid # # GTID #-#-# master-bin.000002 # Query # # CREATE DATABASE test1 +master-bin.000002 # Gtid # # GTID #-#-# master-bin.000002 # Query # # use `test1`; CREATE TABLE t1(id int) +master-bin.000002 # Gtid # # GTID #-#-# master-bin.000002 # Query # # use `test1`; DROP TABLE `t1` /* generated by server */ +master-bin.000002 # Gtid # # GTID #-#-# master-bin.000002 # Query # # DROP DATABASE test1 RESET MASTER; USE test; @@ -943,3 +914,339 @@ t1 SHOW TABLES IN test; Tables_in_test SET GLOBAL SERVER_ID = 1; +# +# MDEV-4645: Incorrect reads of frozen binlog events; +# FDE corrupted in relay log +# +/*!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 +#130807 23:29:20 server id 1 end_log_pos 106 +# Position +# |Timestamp |Type |Master ID |Size |Master Pos |Flags +# 4 |20 ae 02 52 |0f |01 00 00 00 |66 00 00 00 |6a 00 00 00 |00 01 +# +# 17 04 00 35 2e 31 2e 36 33 2d 67 6f 6f 67 6c 65 2d |..5.1.63-google-| +# 27 64 65 62 75 67 2d 6c 6f 67 00 00 00 00 00 00 00 |debug-log.......| +# 37 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +# 47 00 00 00 00 20 ae 02 52 17 38 0d 00 08 00 12 00 |.... ..R.8......| +# 57 04 04 04 04 12 00 00 53 00 04 1a 08 00 00 00 08 |.......S........| +# 67 08 08 02 |...| +# +# Event: Start: binlog v 4, server v 5.1.63-google-debug-log created 130807 23:29:20 at startup +ROLLBACK/*!*/; +BINLOG ' +IK4CUg8BAAAAZgAAAGoAAAAAAQQANS4xLjYzLWdvb2dsZS1kZWJ1Zy1sb2cAAAAAAAAAAAAAAAAA +AAAAAAAAAAAAAAAAAAAgrgJSFzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC +'/*!*/; +# at 106 +#130807 23:29:24 server id 1 end_log_pos 207 +# Position +# |Timestamp |Type |Master ID |Size |Master Pos |Flags +# 6a |24 ae 02 52 |02 |01 00 00 00 |65 00 00 00 |cf 00 00 00 |00 00 +# +# 81 01 00 00 00 00 00 00 00 00 00 00 1a 00 00 00 40 |...............@| +# 91 00 00 01 00 00 00 00 00 00 00 00 06 03 73 74 64 |.............std| +# a1 04 08 00 08 00 08 00 00 63 72 65 61 74 65 20 74 |........create t| +# b1 61 62 6c 65 20 74 65 73 74 2e 74 31 20 28 69 64 |able test.t1 (id| +# c1 20 69 6e 74 20 6e 6f 74 20 6e 75 6c 6c 29 | int not null)| +# +# Event: Query thread_id=1 exec_time=0 error_code=0 +SET TIMESTAMP=1375907364/*!*/; +SET @@session.pseudo_thread_id=1/*!*/; +SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1, @@session.autocommit=1/*!*/; +SET @@session.sql_mode=0/*!*/; +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 test.t1 (id int not null) +/*!*/; +# at 207 +#130807 23:29:26 server id 1 end_log_pos 305 +# Position +# |Timestamp |Type |Master ID |Size |Master Pos |Flags +# cf |26 ae 02 52 |02 |01 00 00 00 |62 00 00 00 |31 01 00 00 |00 00 +# +# e6 01 00 00 00 00 00 00 00 00 00 00 1a 00 00 00 40 |...............@| +# f6 00 00 01 00 00 00 00 00 00 00 00 06 03 73 74 64 |.............std| +# 106 04 08 00 08 00 08 00 00 69 6e 73 65 72 74 20 69 |........insert i| +# 116 6e 74 6f 20 74 65 73 74 2e 74 31 20 28 69 64 29 |nto test.t1 (id)| +# 126 20 76 61 6c 75 65 73 20 28 31 29 | values (1)| +# +# Event: Query thread_id=1 exec_time=0 error_code=0 +SET TIMESTAMP=1375907366/*!*/; +insert into test.t1 (id) values (1) +/*!*/; +# at 305 +#130807 23:29:28 server id 1 end_log_pos 386 +# Position +# |Timestamp |Type |Master ID |Size |Master Pos |Flags +# 131 |28 ae 02 52 |02 |01 00 00 00 |51 00 00 00 |82 01 00 00 |00 00 +# +# 148 01 00 00 00 00 00 00 00 00 00 00 1a 00 00 00 40 |...............@| +# 158 00 00 01 00 00 00 00 00 00 00 00 06 03 73 74 64 |.............std| +# 168 04 08 00 08 00 08 00 00 64 72 6f 70 20 74 61 62 |........drop tab| +# 178 6c 65 20 74 65 73 74 2e 74 31 |le test.t1| +# +# Event: Query thread_id=1 exec_time=0 error_code=0 +SET TIMESTAMP=1375907368/*!*/; +drop table test.t1 +/*!*/; +DELIMITER ; +# End of log file +ROLLBACK /* added by mysqlbinlog */; +/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; +/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; +/*!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 +#130807 23:25:35 server id 1 end_log_pos 106 +# Position +# |Timestamp |Type |Master ID |Size |Master Pos |Flags +# 4 |3f ad 02 52 |0f |01 00 00 00 |66 00 00 00 |6a 00 00 00 |00 00 +# +# 17 04 00 35 2e 31 2e 36 33 2d 67 6f 6f 67 6c 65 2d |..5.1.63-google-| +# 27 64 65 62 75 67 2d 6c 6f 67 00 00 00 00 00 00 00 |debug-log.......| +# 37 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +# 47 00 00 00 00 3f ad 02 52 1b 38 0d 00 08 00 12 00 |....?..R.8......| +# 57 04 04 04 04 12 00 00 53 00 04 1a 08 00 00 00 08 |.......S........| +# 67 08 08 02 |...| +# +# Event: Start: binlog v 4, server v 5.1.63-google-debug-log created 130807 23:25:35 at startup +ROLLBACK/*!*/; +BINLOG ' +P60CUg8BAAAAZgAAAGoAAAAAAAQANS4xLjYzLWdvb2dsZS1kZWJ1Zy1sb2cAAAAAAAAAAAAAAAAA +AAAAAAAAAAAAAAAAAAA/rQJSGzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC +'/*!*/; +# at 106 +#130807 23:25:41 server id 1 end_log_pos 211 +# Position +# |Timestamp |Type |Master ID |Size |Master Pos |Flags +# 6a |45 ad 02 52 |02 |01 00 00 00 |69 00 00 00 |d3 00 00 00 |00 00 +# +# 85 01 00 00 00 01 00 00 00 00 00 00 1a 00 00 00 40 |...............@| +# 95 00 00 01 00 00 00 00 00 00 00 00 06 03 73 74 64 |.............std| +# a5 04 08 00 08 00 08 00 00 63 72 65 61 74 65 20 74 |........create t| +# b5 61 62 6c 65 20 74 65 73 74 2e 74 31 20 28 69 64 |able test.t1 (id| +# c5 20 69 6e 74 20 6e 6f 74 20 6e 75 6c 6c 29 | int not null)| +# +# Event: Query thread_id=1 exec_time=1 error_code=0 +SET TIMESTAMP=1375907141/*!*/; +SET @@session.pseudo_thread_id=1/*!*/; +SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1, @@session.autocommit=1/*!*/; +SET @@session.sql_mode=0/*!*/; +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 test.t1 (id int not null) +/*!*/; +# at 211 +#130807 23:25:44 server id 1 end_log_pos 313 +# Position +# |Timestamp |Type |Master ID |Size |Master Pos |Flags +# d3 |48 ad 02 52 |02 |01 00 00 00 |66 00 00 00 |39 01 00 00 |00 00 +# +# ee 01 00 00 00 00 00 00 00 00 00 00 1a 00 00 00 40 |...............@| +# fe 00 00 01 00 00 00 00 00 00 00 00 06 03 73 74 64 |.............std| +# 10e 04 08 00 08 00 08 00 00 69 6e 73 65 72 74 20 69 |........insert i| +# 11e 6e 74 6f 20 74 65 73 74 2e 74 31 20 28 69 64 29 |nto test.t1 (id)| +# 12e 20 76 61 6c 75 65 73 20 28 31 29 | values (1)| +# +# Event: Query thread_id=1 exec_time=0 error_code=0 +SET TIMESTAMP=1375907144/*!*/; +insert into test.t1 (id) values (1) +/*!*/; +# at 313 +#130807 23:25:48 server id 1 end_log_pos 398 +# Position +# |Timestamp |Type |Master ID |Size |Master Pos |Flags +# 139 |4c ad 02 52 |02 |01 00 00 00 |55 00 00 00 |8e 01 00 00 |00 00 +# +# 154 01 00 00 00 00 00 00 00 00 00 00 1a 00 00 00 40 |...............@| +# 164 00 00 01 00 00 00 00 00 00 00 00 06 03 73 74 64 |.............std| +# 174 04 08 00 08 00 08 00 00 64 72 6f 70 20 74 61 62 |........drop tab| +# 184 6c 65 20 74 65 73 74 2e 74 31 |le test.t1| +# +# Event: Query thread_id=1 exec_time=0 error_code=0 +SET TIMESTAMP=1375907148/*!*/; +drop table test.t1 +/*!*/; +DELIMITER ; +# End of log file +ROLLBACK /* added by mysqlbinlog */; +/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; +/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; +/*!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 +#130807 23:20:55 server id 1 end_log_pos 106 +# Position +# |Timestamp |Type |Master ID |Size |Master Pos |Flags +# 4 |27 ac 02 52 |0f |01 00 00 00 |66 00 00 00 |6a 00 00 00 |00 01 +# +# 17 04 00 35 2e 31 2e 36 33 2d 67 6f 6f 67 6c 65 2d |..5.1.63-google-| +# 27 64 65 62 75 67 2d 6c 6f 67 00 00 00 00 00 00 00 |debug-log.......| +# 37 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +# 47 00 00 00 00 27 ac 02 52 1f 38 0d 00 08 00 12 00 |....'..R.8......| +# 57 04 04 04 04 12 00 00 53 00 04 1a 08 00 00 00 08 |.......S........| +# 67 08 08 02 |...| +# +# Event: Start: binlog v 4, server v 5.1.63-google-debug-log created 130807 23:20:55 at startup +ROLLBACK/*!*/; +BINLOG ' +J6wCUg8BAAAAZgAAAGoAAAAAAQQANS4xLjYzLWdvb2dsZS1kZWJ1Zy1sb2cAAAAAAAAAAAAAAAAA +AAAAAAAAAAAAAAAAAAAnrAJSHzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC +'/*!*/; +# at 106 +#130807 23:21:19 server id 1 end_log_pos 215 +# Position +# |Timestamp |Type |Master ID |Size |Master Pos |Flags +# 6a |3f ac 02 52 |02 |01 00 00 00 |6d 00 00 00 |d7 00 00 00 |00 00 +# +# 89 01 00 00 00 00 00 00 00 00 00 00 1a 00 00 00 40 |...............@| +# 99 00 00 01 00 00 00 00 00 00 00 00 06 03 73 74 64 |.............std| +# a9 04 08 00 08 00 08 00 00 63 72 65 61 74 65 20 74 |........create t| +# b9 61 62 6c 65 20 74 65 73 74 2e 74 31 20 28 69 64 |able test.t1 (id| +# c9 20 69 6e 74 20 6e 6f 74 20 6e 75 6c 6c 29 | int not null)| +# +# Event: Query thread_id=1 exec_time=0 error_code=0 +SET TIMESTAMP=1375906879/*!*/; +SET @@session.pseudo_thread_id=1/*!*/; +SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1, @@session.autocommit=1/*!*/; +SET @@session.sql_mode=0/*!*/; +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 test.t1 (id int not null) +/*!*/; +# at 215 +#130807 23:21:31 server id 1 end_log_pos 321 +# Position +# |Timestamp |Type |Master ID |Size |Master Pos |Flags +# d7 |4b ac 02 52 |02 |01 00 00 00 |6a 00 00 00 |41 01 00 00 |00 00 +# +# f6 01 00 00 00 00 00 00 00 00 00 00 1a 00 00 00 40 |...............@| +# 106 00 00 01 00 00 00 00 00 00 00 00 06 03 73 74 64 |.............std| +# 116 04 08 00 08 00 08 00 00 69 6e 73 65 72 74 20 69 |........insert i| +# 126 6e 74 6f 20 74 65 73 74 2e 74 31 20 28 69 64 29 |nto test.t1 (id)| +# 136 20 76 61 6c 75 65 73 20 28 31 29 | values (1)| +# +# Event: Query thread_id=1 exec_time=0 error_code=0 +SET TIMESTAMP=1375906891/*!*/; +insert into test.t1 (id) values (1) +/*!*/; +# at 321 +#130807 23:21:41 server id 1 end_log_pos 410 +# Position +# |Timestamp |Type |Master ID |Size |Master Pos |Flags +# 141 |55 ac 02 52 |02 |01 00 00 00 |59 00 00 00 |9a 01 00 00 |00 00 +# +# 160 01 00 00 00 00 00 00 00 00 00 00 1a 00 00 00 40 |...............@| +# 170 00 00 01 00 00 00 00 00 00 00 00 06 03 73 74 64 |.............std| +# 180 04 08 00 08 00 08 00 00 64 72 6f 70 20 74 61 62 |........drop tab| +# 190 6c 65 20 74 65 73 74 2e 74 31 |le test.t1| +# +# Event: Query thread_id=1 exec_time=0 error_code=0 +SET TIMESTAMP=1375906901/*!*/; +drop table test.t1 +/*!*/; +DELIMITER ; +# End of log file +ROLLBACK /* added by mysqlbinlog */; +/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; +/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; +/*!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 +#130807 23:38:51 server id 1 end_log_pos 106 +# Position +# |Timestamp |Type |Master ID |Size |Master Pos |Flags +# 4 |5b b0 02 52 |0f |01 00 00 00 |66 00 00 00 |6a 00 00 00 |00 00 +# +# 17 04 00 35 2e 31 2e 36 33 2d 67 6f 6f 67 6c 65 2d |..5.1.63-google-| +# 27 64 65 62 75 67 2d 6c 6f 67 00 00 00 00 00 00 00 |debug-log.......| +# 37 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +# 47 00 00 00 00 5b b0 02 52 13 38 0d 00 08 00 12 00 |....[..R.8......| +# 57 04 04 04 04 12 00 00 53 00 04 1a 08 00 00 00 08 |.......S........| +# 67 08 08 02 |...| +# +# Event: Start: binlog v 4, server v 5.1.63-google-debug-log created 130807 23:38:51 at startup +ROLLBACK/*!*/; +BINLOG ' +W7ACUg8BAAAAZgAAAGoAAAAAAAQANS4xLjYzLWdvb2dsZS1kZWJ1Zy1sb2cAAAAAAAAAAAAAAAAA +AAAAAAAAAAAAAAAAAABbsAJSEzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC +'/*!*/; +# at 106 +#130807 23:38:53 server id 1 end_log_pos 203 +# Position +# |Timestamp |Type |Master ID |Size |Master Pos |Flags +# 6a |5d b0 02 52 |02 |01 00 00 00 |61 00 00 00 |cb 00 00 00 |00 00 +# +# 7d 01 00 00 00 00 00 00 00 00 00 00 1a 00 00 00 40 |...............@| +# 8d 00 00 01 00 00 00 00 00 00 00 00 06 03 73 74 64 |.............std| +# 9d 04 08 00 08 00 08 00 00 63 72 65 61 74 65 20 74 |........create t| +# ad 61 62 6c 65 20 74 65 73 74 2e 74 31 20 28 69 64 |able test.t1 (id| +# bd 20 69 6e 74 20 6e 6f 74 20 6e 75 6c 6c 29 | int not null)| +# +# Event: Query thread_id=1 exec_time=0 error_code=0 +SET TIMESTAMP=1375907933/*!*/; +SET @@session.pseudo_thread_id=1/*!*/; +SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1, @@session.autocommit=1/*!*/; +SET @@session.sql_mode=0/*!*/; +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 test.t1 (id int not null) +/*!*/; +# at 203 +#130807 23:38:55 server id 1 end_log_pos 297 +# Position +# |Timestamp |Type |Master ID |Size |Master Pos |Flags +# cb |5f b0 02 52 |02 |01 00 00 00 |5e 00 00 00 |29 01 00 00 |00 00 +# +# de 01 00 00 00 00 00 00 00 00 00 00 1a 00 00 00 40 |...............@| +# ee 00 00 01 00 00 00 00 00 00 00 00 06 03 73 74 64 |.............std| +# fe 04 08 00 08 00 08 00 00 69 6e 73 65 72 74 20 69 |........insert i| +# 10e 6e 74 6f 20 74 65 73 74 2e 74 31 20 28 69 64 29 |nto test.t1 (id)| +# 11e 20 76 61 6c 75 65 73 20 28 31 29 | values (1)| +# +# Event: Query thread_id=1 exec_time=0 error_code=0 +SET TIMESTAMP=1375907935/*!*/; +insert into test.t1 (id) values (1) +/*!*/; +# at 297 +#130807 23:38:57 server id 1 end_log_pos 374 +# Position +# |Timestamp |Type |Master ID |Size |Master Pos |Flags +# 129 |61 b0 02 52 |02 |01 00 00 00 |4d 00 00 00 |76 01 00 00 |00 00 +# +# 13c 01 00 00 00 00 00 00 00 00 00 00 1a 00 00 00 40 |...............@| +# 14c 00 00 01 00 00 00 00 00 00 00 00 06 03 73 74 64 |.............std| +# 15c 04 08 00 08 00 08 00 00 64 72 6f 70 20 74 61 62 |........drop tab| +# 16c 6c 65 20 74 65 73 74 2e 74 31 |le test.t1| +# +# Event: Query thread_id=1 exec_time=0 error_code=0 +SET TIMESTAMP=1375907937/*!*/; +drop table test.t1 +/*!*/; +DELIMITER ; +# End of log file +ROLLBACK /* added by mysqlbinlog */; +/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; +/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/; diff --git a/mysql-test/r/mysqlcheck.result b/mysql-test/r/mysqlcheck.result index ab707ceef80..46469556215 100644 --- a/mysql-test/r/mysqlcheck.result +++ b/mysql-test/r/mysqlcheck.result @@ -1,23 +1,29 @@ +call mtr.add_suppression("Invalid .old.. table or database name"); DROP TABLE IF EXISTS t1, `t``1`, `t 1`; drop view if exists v1; drop database if exists client_test_db; mtr.global_suppressions OK mtr.test_suppressions OK +mysql.column_stats OK mysql.columns_priv OK mysql.db OK mysql.event OK mysql.func OK +mysql.gtid_slave_pos OK mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stats OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.proxies_priv OK +mysql.roles_mapping OK mysql.servers OK +mysql.table_stats OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK @@ -27,21 +33,26 @@ mysql.time_zone_transition_type OK mysql.user OK mtr.global_suppressions Table is already up to date mtr.test_suppressions Table is already up to date +mysql.column_stats OK mysql.columns_priv OK mysql.db OK mysql.event OK mysql.func OK +mysql.gtid_slave_pos OK mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stats OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.proxies_priv OK +mysql.roles_mapping OK mysql.servers OK +mysql.table_stats OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK @@ -49,21 +60,26 @@ mysql.time_zone_name OK mysql.time_zone_transition OK mysql.time_zone_transition_type OK mysql.user OK +mysql.column_stats OK mysql.columns_priv OK mysql.db OK mysql.event OK mysql.func OK +mysql.gtid_slave_pos OK mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.host OK +mysql.index_stats OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.proxies_priv OK +mysql.roles_mapping OK mysql.servers OK +mysql.table_stats OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK @@ -71,21 +87,26 @@ mysql.time_zone_name OK mysql.time_zone_transition OK mysql.time_zone_transition_type OK mysql.user OK +mysql.column_stats Table is already up to date mysql.columns_priv Table is already up to date mysql.db Table is already up to date mysql.event Table is already up to date mysql.func Table is already up to date +mysql.gtid_slave_pos Table is already up to date mysql.help_category Table is already up to date mysql.help_keyword Table is already up to date mysql.help_relation Table is already up to date mysql.help_topic Table is already up to date mysql.host Table is already up to date +mysql.index_stats Table is already up to date mysql.ndb_binlog_index Table is already up to date mysql.plugin Table is already up to date mysql.proc Table is already up to date mysql.procs_priv Table is already up to date mysql.proxies_priv Table is already up to date +mysql.roles_mapping Table is already up to date mysql.servers Table is already up to date +mysql.table_stats Table is already up to date mysql.tables_priv Table is already up to date mysql.time_zone Table is already up to date mysql.time_zone_leap_second Table is already up to date @@ -148,6 +169,7 @@ Table Op Msg_type Msg_text test.v1 check status OK information_schema.routines check note The storage engine for the table doesn't support check drop view v1; +call mtr.add_suppression("Error reading file './test/t1.frm'"); CREATE TABLE t1(a INT) engine=myisam; CREATE TABLE t2(a INT) engine=myisam; test.t1 @@ -164,15 +186,15 @@ t1 v1 show tables; Tables_in_test -t1 #mysql50#v-1 +t1 v1 test.t1 OK show tables; Tables_in_test t1 -v1 v-1 +v1 drop view v1, `v-1`; drop table t1; SET NAMES utf8; diff --git a/mysql-test/r/mysqld--help,win.rdiff b/mysql-test/r/mysqld--help,win.rdiff index cd39445f3e6..24719fce917 100644 --- a/mysql-test/r/mysqld--help,win.rdiff +++ b/mysql-test/r/mysqld--help,win.rdiff @@ -1,6 +1,6 @@ --- mysql-test/r/mysqld--help.result 2012-09-08 22:22:06 +0000 +++ mysql-test/r/mysqld--help.result 2012-10-01 14:03:59 +0000 -@@ -244,7 +244,6 @@ +@@ -248,7 +248,6 @@ The number of segments in a key cache -L, --language=name Client error messages in given language. May be given as a full path. Deprecated. Use --lc-messages-dir instead. @@ -8,7 +8,7 @@ --lc-messages=name Set the language used for the error messages. -L, --lc-messages-dir=name Directory where error messages are -@@ -440,6 +439,7 @@ +@@ -443,6 +442,7 @@ NULLS_UNEQUAL (default behavior for 4.1 and later), NULLS_EQUAL (emulate 4.0 behavior), and NULLS_IGNORED --myisam-use-mmap Use memory mapping for reading and writing MyISAM tables @@ -16,7 +16,7 @@ --net-buffer-length=# Buffer length for TCP/IP and socket communication --net-read-timeout=# -@@ -707,6 +707,9 @@ +@@ -710,6 +710,9 @@ files within specified directory --server-id=# Uniquely identifies the server instance in the community of replication partners @@ -26,7 +26,7 @@ --show-slave-auth-info Show user and password in SHOW SLAVE HOSTS on this master. -@@ -774,6 +777,10 @@ +@@ -777,6 +780,10 @@ Log slow queries to given log file. Defaults logging to 'hostname'-slow.log. Must be enabled to activate other slow log options @@ -37,7 +37,7 @@ --socket=name Socket file to use for connection --sort-buffer-size=# Each thread that needs to do a sort allocates a buffer of -@@ -782,6 +789,7 @@ +@@ -785,6 +792,7 @@ for the complete list of valid sql modes --stack-trace Print a symbolic stack trace on failure (Defaults to on; use --skip-stack-trace to disable.) @@ -45,7 +45,35 @@ --stored-program-cache=# The soft upper limit for number of cached stored routines for one connection. -@@ -822,8 +830,8 @@ +@@ -817,25 +825,11 @@ + values are COMMIT or ROLLBACK. + --thread-cache-size=# + How many threads we should keep in a cache for reuse +- --thread-pool-idle-timeout=# +- Timeout in seconds for an idle thread in the thread +- pool.Worker thread will be shut down after timeout + --thread-pool-max-threads=# + Maximum allowed number of worker threads in the thread + pool +- --thread-pool-oversubscribe=# +- How many additional active worker threads in a group are +- allowed. +- --thread-pool-size=# +- Number of thread groups in the pool. This parameter is +- roughly equivalent to maximum number of concurrently +- executing threads (threads in a waiting state do not +- count as executing). +- --thread-pool-stall-limit=# +- Maximum query execution time in milliseconds,before an +- executing non-yielding thread is considered stalled.If a +- worker thread is stalled, additional worker thread may be +- created to handle remaining clients. ++ --thread-pool-min-threads=# ++ Minimum number of threads in the thread pool. + --thread-stack=# The stack size for each thread + --time-format=name The TIME format (ignored) + --timed-mutexes Specify whether to time mutexes (only InnoDB mutexes are +@@ -844,8 +838,8 @@ size, MySQL will automatically convert it to an on-disk MyISAM or Aria table -t, --tmpdir=name Path for temporary files. Several paths may be specified, @@ -56,7 +84,7 @@ --transaction-alloc-block-size=# Allocation block size for transactions to be stored in binary log -@@ -923,7 +931,6 @@ key-cache-age-threshold 300 +@@ -949,7 +943,6 @@ key-cache-block-size 1024 key-cache-division-limit 100 key-cache-segments 0 @@ -64,7 +92,7 @@ lc-messages en_US lc-messages-dir MYSQL_SHAREDIR/ lc-time-names en_US -@@ -986,6 +993,7 @@ myisam-repair-threads 1 +@@ -1012,6 +1005,7 @@ myisam-sort-buffer-size 8388608 myisam-stats-method nulls_unequal myisam-use-mmap FALSE @@ -72,7 +100,7 @@ net-buffer-length 16384 net-read-timeout 30 net-retry-count 10 -@@ -1051,6 +1059,8 @@ safe-user-create FALSE +@@ -1077,6 +1071,8 @@ secure-auth FALSE secure-file-priv (No default value) server-id 0 @@ -81,7 +109,7 @@ show-slave-auth-info FALSE skip-grant-tables TRUE skip-name-resolve FALSE -@@ -1067,6 +1077,7 @@ slave-transaction-retries 10 +@@ -1093,6 +1089,7 @@ slave-type-conversions slow-launch-time 2 slow-query-log FALSE @@ -89,4 +117,15 @@ sort-buffer-size 2097152 sql-mode stack-trace TRUE - +@@ -1109,10 +1106,8 @@ + table-open-cache 400 + tc-heuristic-recover COMMIT + thread-cache-size 0 +-thread-pool-idle-timeout 60 + thread-pool-max-threads 500 +-thread-pool-oversubscribe 3 +-thread-pool-stall-limit 500 ++thread-pool-min-threads 1 + thread-stack 294912 + time-format %H:%i:%s + timed-mutexes FALSE diff --git a/mysql-test/r/mysqld--help.result b/mysql-test/r/mysqld--help.result index 16da8eae7f9..953e9d926dd 100644 --- a/mysql-test/r/mysqld--help.result +++ b/mysql-test/r/mysqld--help.result @@ -41,6 +41,17 @@ The following options may be given as the first argument: Type of BINLOG_CHECKSUM_ALG. Include checksum for log events in the binary log. Possible values are NONE and CRC32; default is NONE. + --binlog-commit-wait-count=# + If non-zero, binlog write will wait at most + binlog_commit_wait_usec microseconds for at least this + many commits to queue up for group commit to the binlog. + This can reduce I/O on the binlog and provide increased + opportunity for parallel apply on the slave, but too high + a value will decrease commit throughput. + --binlog-commit-wait-usec=# + Maximum time, in microseconds, to wait for more commits + to queue up for binlog group commit. Only takes effect if + the value of binlog_commit_wait_count is non-zero. --binlog-direct-non-transactional-updates Causes updates to non-transactional engines using statement format to be written directly to binary log. @@ -201,7 +212,24 @@ The following options may be given as the first argument: --group-concat-max-len=# The maximum length of the result of function GROUP_CONCAT() + --gtid-domain-id=# Used with global transaction ID to identify logically + independent replication streams. When events can + propagate through multiple parallel paths (for example + multiple masters), each independent source server must + use a distinct domain_id. For simple tree-shaped + replication topologies, it can be left at its default, 0. + --gtid-strict-mode Enforce strict seq_no ordering of events in the binary + log. Slave stops with an error if it encounters an event + that would cause it to generate an out-of-order binlog if + executed. -?, --help Display this help and exit. + --histogram-size=# Number of bytes used for a histogram. If set to 0, no + histograms are created by ANALYZE. + --histogram-type=name + Specifies type of the histograms created by ANALYZE. + Possible values are: SINGLE_PREC_HB - single precision + height-balanced, DOUBLE_PREC_HB - double precision + height-balanced. --ignore-builtin-innodb Disable initialization of builtin InnoDB plugin --ignore-db-dirs=name @@ -327,7 +355,7 @@ The following options may be given as the first argument: log if it is open. --log-slow-verbosity=name log-slow-verbosity=[value[,value ...]] where value is one - of 'innodb', 'query_plan' + of 'innodb', 'query_plan', 'explain' --log-tc=name Path to transaction coordinator log (used for transactions that affect more than one storage engine, when binary log is disabled). @@ -361,8 +389,7 @@ The following options may be given as the first argument: --max-binlog-cache-size=# Sets the total size of the transactional cache --max-binlog-size=# Binary log will be rotated automatically when the size - exceeds this value. Will also apply to relay logs if - max_relay_log_size is 0 + exceeds this value. --max-binlog-stmt-cache-size=# Sets the total size of the statement cache --max-connect-errors=# @@ -388,9 +415,9 @@ The following options may be given as the first argument: --max-prepared-stmt-count=# Maximum number of prepared statements in the server --max-relay-log-size=# - If non-zero: relay log will be rotated automatically when - the size exceeds this value; if zero: when the size - exceeds max_binlog_size + relay log will be rotated automatically when the size + exceeds this value. If 0 are startup, it's set to + max_binlog_size --max-seeks-for-key=# Limit assumed max number of seeks when looking up rows based on a key @@ -491,6 +518,9 @@ The following options may be given as the first argument: optimizer will switch to the original find_best search. NOTE: The value 63 and its associated behaviour is deprecated + --optimizer-selectivity-sampling-limit=# + Controls number of record samples to check condition + selectivity --optimizer-switch=name optimizer_switch=option=val[,option=val...], where option is one of {derived_merge, derived_with_keys, firstmatch, @@ -503,8 +533,25 @@ The following options may be given as the first argument: mrr_cost_based, mrr_sort_keys, optimize_join_buffer_size, outer_join_with_cache, partial_match_rowid_merge, partial_match_table_scan, semijoin, semijoin_with_cache, - subquery_cache, table_elimination, extended_keys } and - val is one of {on, off, default} + subquery_cache, table_elimination, extended_keys, + exists_to_in } and val is one of {on, off, default} + --optimizer-use-condition-selectivity=# + Controls selectivity of which conditions the optimizer + takes into account to calculate cardinality of a partial + join when it searches for the best execution plan + Meaning: 1 - use selectivity of index backed range + conditions to calculate the cardinality of a partial join + if the last joined table is accessed by full table scan + or an index scan, 2 - use selectivity of index backed + range conditions to calculate the cardinality of a + partial join in any case, 3 - additionally always use + selectivity of range conditions that are not backed by + any index to calculate the cardinality of a partial join, + 4 - use histograms to calculate selectivity of range + conditions that are not backed by any index to calculate + the cardinality of a partial join.5 - additionally use + selectivity of certain non-range predicates calculated on + record samples --performance-schema Enable the performance schema. --performance-schema-events-waits-history-long-size=# @@ -749,8 +796,18 @@ The following options may be given as the first argument: The maximum packet length to sent successfully from the master to slave. --slave-net-timeout=# - Number of seconds to wait for more data from a + Number of seconds to wait for more data from any master/slave connection before aborting the read + --slave-parallel-max-queued=# + Limit on how much memory SQL threads should use per + parallel replication thread when reading ahead in the + relay log looking for opportunities for parallel + replication. Only used when --slave-parallel-threads > 0. + --slave-parallel-threads=# + If non-zero, number of threads to spawn to apply in + parallel events on the slave that were group-committed on + the master or were logged with GTID in different + replication domains. --slave-skip-errors=name Tells the slave thread to continue replication when a query event returns an error from the provided list @@ -822,6 +879,25 @@ The following options may be given as the first argument: values are COMMIT or ROLLBACK. --thread-cache-size=# How many threads we should keep in a cache for reuse + --thread-pool-idle-timeout=# + Timeout in seconds for an idle thread in the thread + pool.Worker thread will be shut down after timeout + --thread-pool-max-threads=# + Maximum allowed number of worker threads in the thread + pool + --thread-pool-oversubscribe=# + How many additional active worker threads in a group are + allowed. + --thread-pool-size=# + Number of thread groups in the pool. This parameter is + roughly equivalent to maximum number of concurrently + executing threads (threads in a waiting state do not + count as executing). + --thread-pool-stall-limit=# + Maximum query execution time in milliseconds,before an + executing non-yielding thread is considered stalled.If a + worker thread is stalled, additional worker thread may be + created to handle remaining clients. --thread-stack=# The stack size for each thread --time-format=name The TIME format (ignored) --timed-mutexes Specify whether to time mutexes (only InnoDB mutexes are @@ -847,6 +923,9 @@ The following options may be given as the first argument: Prohibit update of a VIEW, which does not contain a key of the underlying table and the query uses a LIMIT clause (usually get from GUI tools) + --use-stat-tables=name + Specifies how to use system statistics tables. Possible + values are NEVER, COMPLEMENTARY, PREVERABLY -u, --user=name Run mysqld daemon as user. --userstat Enables statistics gathering for USER_STATISTICS, CLIENT_STATISTICS, INDEX_STATISTICS and TABLE_STATISTICS @@ -868,6 +947,8 @@ bind-address (No default value) binlog-annotate-row-events FALSE binlog-cache-size 32768 binlog-checksum NONE +binlog-commit-wait-count 0 +binlog-commit-wait-usec 100000 binlog-direct-non-transactional-updates FALSE binlog-format STATEMENT binlog-optimize-thread-scheduling TRUE @@ -915,7 +996,11 @@ ft-stopword-file (No default value) gdb FALSE general-log FALSE group-concat-max-len 1024 +gtid-domain-id 0 +gtid-strict-mode FALSE help TRUE +histogram-size 0 +histogram-type SINGLE_PREC_HB ignore-builtin-innodb FALSE ignore-db-dirs init-connect @@ -974,7 +1059,7 @@ max-join-size 18446744073709551615 max-length-for-sort-data 1024 max-long-data-size 1048576 max-prepared-stmt-count 16382 -max-relay-log-size 0 +max-relay-log-size 1073741824 max-seeks-for-key 18446744073709551615 max-sort-length 1024 max-sp-recursion-depth 0 @@ -992,7 +1077,7 @@ myisam-max-sort-file-size 9223372036853727232 myisam-mmap-size 18446744073709551615 myisam-recover-options DEFAULT myisam-repair-threads 1 -myisam-sort-buffer-size 8388608 +myisam-sort-buffer-size 134216704 myisam-stats-method nulls_unequal myisam-use-mmap FALSE net-buffer-length 16384 @@ -1006,7 +1091,9 @@ old-passwords FALSE old-style-user-limits FALSE optimizer-prune-level 1 optimizer-search-depth 62 +optimizer-selectivity-sampling-limit 100 optimizer-switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on +optimizer-use-condition-selectivity 1 performance-schema FALSE performance-schema-events-waits-history-long-size 10000 performance-schema-events-waits-history-size 10 @@ -1071,6 +1158,8 @@ slave-compressed-protocol FALSE slave-exec-mode STRICT slave-max-allowed-packet 1073741824 slave-net-timeout 3600 +slave-parallel-max-queued 131072 +slave-parallel-threads 0 slave-skip-errors (No default value) slave-sql-verify-checksum TRUE slave-transaction-retries 10 @@ -1093,6 +1182,10 @@ table-definition-cache 400 table-open-cache 400 tc-heuristic-recover COMMIT thread-cache-size 0 +thread-pool-idle-timeout 60 +thread-pool-max-threads 500 +thread-pool-oversubscribe 3 +thread-pool-stall-limit 500 thread-stack 294912 time-format %H:%i:%s timed-mutexes FALSE @@ -1101,6 +1194,7 @@ transaction-alloc-block-size 8192 transaction-isolation REPEATABLE-READ transaction-prealloc-size 4096 updatable-views-with-limit YES +use-stat-tables NEVER userstat FALSE verbose TRUE wait-timeout 28800 diff --git a/mysql-test/r/mysqldump-max.result b/mysql-test/r/mysqldump-max.result index 6722f308358..8d5ab551bee 100644 --- a/mysql-test/r/mysqldump-max.result +++ b/mysql-test/r/mysqldump-max.result @@ -332,12 +332,12 @@ a b 2 1 DROP TABLE t1; DROP TABLE t2; -SHOW BINLOG EVENTS LIMIT 6,3; +SHOW BINLOG EVENTS LIMIT 7,3; Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 663 Query 1 731 BEGIN -master-bin.000001 731 Query 1 828 use `test`; INSERT INTO t2 VALUES (1,0), (2,0) -master-bin.000001 828 Xid 1 855 COMMIT /* XID */ --- CHANGE MASTER TO MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=855; +master-bin.000001 593 Xid 1 620 COMMIT /* XID */ +master-bin.000001 620 Gtid 1 658 GTID 0-1-3 +master-bin.000001 658 Query 1 777 use `test`; CREATE TABLE t2 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB +-- CHANGE MASTER TO MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=939; SELECT * FROM t1 ORDER BY a; a 1 diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index 3a9cff4eef0..131bd6fd593 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -5239,7 +5239,7 @@ Error 1146 Table 'mysql.event' doesn't exist SHOW CREATE TABLE mysql.general_log; Table Create Table general_log CREATE TABLE `general_log` ( - `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `user_host` mediumtext NOT NULL, `thread_id` int(11) NOT NULL, `server_id` int(10) unsigned NOT NULL, @@ -5249,7 +5249,7 @@ general_log CREATE TABLE `general_log` ( SHOW CREATE TABLE mysql.slow_log; Table Create Table slow_log CREATE TABLE `slow_log` ( - `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `user_host` mediumtext NOT NULL, `query_time` time(6) NOT NULL, `lock_time` time(6) NOT NULL, diff --git a/mysql-test/r/mysqlslap.result b/mysql-test/r/mysqlslap.result index af78677647f..d3c5107dee3 100644 --- a/mysql-test/r/mysqlslap.result +++ b/mysql-test/r/mysqlslap.result @@ -234,8 +234,8 @@ test # 'bug58090' database should be present. SHOW DATABASES; Database -information_schema bug58090 +information_schema mtr mysql performance_schema diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 865c8d7077b..7228daa2712 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -232,7 +232,7 @@ mysqltest: At line 2: Spurious text after `query` expression mysqltest: At line 1: Missing argument(s) to 'error' mysqltest: At line 1: Missing argument(s) to 'error' mysqltest: At line 1: The sqlstate definition must start with an uppercase S -mysqltest: At line 1: The error name definition must start with an uppercase E or H +mysqltest: At line 1: The error name definition must start with an uppercase E or W or H mysqltest: At line 1: Invalid argument to error: '9eeeee' - the errno may only consist of digits[0-9] mysqltest: At line 1: Invalid argument to error: '1sssss' - the errno may only consist of digits[0-9] mysqltest: At line 1: The sqlstate must be exactly 5 chars long diff --git a/mysql-test/r/not_openssl.require b/mysql-test/r/not_openssl.require deleted file mode 100644 index 2b5e423999c..00000000000 --- a/mysql-test/r/not_openssl.require +++ /dev/null @@ -1,2 +0,0 @@ -Variable_name Value -have_openssl NO diff --git a/mysql-test/r/not_partition.result b/mysql-test/r/not_partition.result index 3c0523279a9..adda476da95 100644 --- a/mysql-test/r/not_partition.result +++ b/mysql-test/r/not_partition.result @@ -3,7 +3,7 @@ FLUSH TABLES; SELECT * FROM t1; ERROR 42000: Unknown storage engine 'partition' TRUNCATE TABLE t1; -ERROR 42S02: Table 'test.t1' doesn't exist +ERROR 42000: Unknown storage engine 'partition' ANALYZE TABLE t1; Table Op Msg_type Msg_text test.t1 analyze Error Unknown storage engine 'partition' @@ -21,17 +21,17 @@ Table Op Msg_type Msg_text test.t1 repair Error Unknown storage engine 'partition' test.t1 repair error Corrupt ALTER TABLE t1 REPAIR PARTITION ALL; -ERROR HY000: The 'partitioning' feature is disabled; you need MySQL built with '--with-plugin-partition' to have it working +ERROR HY000: The 'partitioning' feature is disabled; you need MariaDB built with '--with-plugin-partition' to have it working ALTER TABLE t1 CHECK PARTITION ALL; -ERROR HY000: The 'partitioning' feature is disabled; you need MySQL built with '--with-plugin-partition' to have it working +ERROR HY000: The 'partitioning' feature is disabled; you need MariaDB built with '--with-plugin-partition' to have it working ALTER TABLE t1 OPTIMIZE PARTITION ALL; -ERROR HY000: The 'partitioning' feature is disabled; you need MySQL built with '--with-plugin-partition' to have it working +ERROR HY000: The 'partitioning' feature is disabled; you need MariaDB built with '--with-plugin-partition' to have it working ALTER TABLE t1 ANALYZE PARTITION ALL; -ERROR HY000: The 'partitioning' feature is disabled; you need MySQL built with '--with-plugin-partition' to have it working +ERROR HY000: The 'partitioning' feature is disabled; you need MariaDB built with '--with-plugin-partition' to have it working ALTER TABLE t1 REBUILD PARTITION ALL; ERROR 42000: Unknown storage engine 'partition' ALTER TABLE t1 TRUNCATE PARTITION ALL; -ERROR HY000: The 'partitioning' feature is disabled; you need MySQL built with '--with-plugin-partition' to have it working +ERROR HY000: The 'partitioning' feature is disabled; you need MariaDB built with '--with-plugin-partition' to have it working ALTER TABLE t1 ENGINE Memory; ERROR 42000: Unknown storage engine 'partition' ALTER TABLE t1 ADD (new INT); @@ -46,9 +46,9 @@ joined DATE NOT NULL ) PARTITION BY KEY(joined) PARTITIONS 6; -ERROR HY000: The 'partitioning' feature is disabled; you need MySQL built with '--with-plugin-partition' to have it working +ERROR HY000: The 'partitioning' feature is disabled; you need MariaDB built with '--with-plugin-partition' to have it working ALTER TABLE t1 PARTITION BY KEY(joined) PARTITIONS 2; -ERROR HY000: The 'partitioning' feature is disabled; you need MySQL built with '--with-plugin-partition' to have it working +ERROR HY000: The 'partitioning' feature is disabled; you need MariaDB built with '--with-plugin-partition' to have it working drop table t1; ERROR 42S02: Unknown table 't1' CREATE TABLE t1 ( @@ -65,7 +65,7 @@ PARTITION p2 VALUES LESS THAN (1980), PARTITION p3 VALUES LESS THAN (1990), PARTITION p4 VALUES LESS THAN MAXVALUE ); -ERROR HY000: The 'partitioning' feature is disabled; you need MySQL built with '--with-plugin-partition' to have it working +ERROR HY000: The 'partitioning' feature is disabled; you need MariaDB built with '--with-plugin-partition' to have it working drop table t1; ERROR 42S02: Unknown table 't1' CREATE TABLE t1 (id INT, purchased DATE) @@ -76,7 +76,7 @@ PARTITION p0 VALUES LESS THAN (1990), PARTITION p1 VALUES LESS THAN (2000), PARTITION p2 VALUES LESS THAN MAXVALUE ); -ERROR HY000: The 'partitioning' feature is disabled; you need MySQL built with '--with-plugin-partition' to have it working +ERROR HY000: The 'partitioning' feature is disabled; you need MariaDB built with '--with-plugin-partition' to have it working drop table t1; ERROR 42S02: Unknown table 't1' create table t1 (a varchar(10) charset latin1 collate latin1_bin); diff --git a/mysql-test/r/order_by.result b/mysql-test/r/order_by.result index 6ce12651dba..a8e5cbb295c 100644 --- a/mysql-test/r/order_by.result +++ b/mysql-test/r/order_by.result @@ -1445,6 +1445,7 @@ CALL mtr.add_suppression("Out of sort memory"); select * from t1 order by b; ERROR HY001: Out of sort memory, consider increasing server sort buffer size drop table t1; +set session sort_buffer_size= 30000; # # Bug #39844: Query Crash Mysql Server 5.0.67 # @@ -1539,6 +1540,890 @@ ppfcz1 DE ppfcz1 14 8 57.5 ppfcz1 DE ppfcz1 14 9 59.5 ppfcz1 DE ppfcz1 14 10 61.5 DROP TABLE t1,t2,t3; +# +# WL#1393 - Optimizing filesort with small limit +# +CREATE TABLE t1(f0 int auto_increment primary key, f1 int, f2 varchar(200)); +INSERT INTO t1(f1, f2) VALUES +(0,"0"),(1,"1"),(2,"2"),(3,"3"),(4,"4"),(5,"5"), +(6,"6"),(7,"7"),(8,"8"),(9,"9"),(10,"10"), +(11,"11"),(12,"12"),(13,"13"),(14,"14"),(15,"15"), +(16,"16"),(17,"17"),(18,"18"),(19,"19"),(20,"20"), +(21,"21"),(22,"22"),(23,"23"),(24,"24"),(25,"25"), +(26,"26"),(27,"27"),(28,"28"),(29,"29"),(30,"30"), +(31,"31"),(32,"32"),(33,"33"),(34,"34"),(35,"35"), +(36,"36"),(37,"37"),(38,"38"),(39,"39"),(40,"40"), +(41,"41"),(42,"42"),(43,"43"),(44,"44"),(45,"45"), +(46,"46"),(47,"47"),(48,"48"),(49,"49"),(50,"50"), +(51,"51"),(52,"52"),(53,"53"),(54,"54"),(55,"55"), +(56,"56"),(57,"57"),(58,"58"),(59,"59"),(60,"60"), +(61,"61"),(62,"62"),(63,"63"),(64,"64"),(65,"65"), +(66,"66"),(67,"67"),(68,"68"),(69,"69"),(70,"70"), +(71,"71"),(72,"72"),(73,"73"),(74,"74"),(75,"75"), +(76,"76"),(77,"77"),(78,"78"),(79,"79"),(80,"80"), +(81,"81"),(82,"82"),(83,"83"),(84,"84"),(85,"85"), +(86,"86"),(87,"87"),(88,"88"),(89,"89"),(90,"90"), +(91,"91"),(92,"92"),(93,"93"),(94,"94"),(95,"95"), +(96,"96"),(97,"97"),(98,"98"),(99,"99"); +SELECT * FROM t1 ORDER BY f1 ASC, f0 LIMIT 100; +f0 f1 f2 +1 0 0 +2 1 1 +3 2 2 +4 3 3 +5 4 4 +6 5 5 +7 6 6 +8 7 7 +9 8 8 +10 9 9 +11 10 10 +12 11 11 +13 12 12 +14 13 13 +15 14 14 +16 15 15 +17 16 16 +18 17 17 +19 18 18 +20 19 19 +21 20 20 +22 21 21 +23 22 22 +24 23 23 +25 24 24 +26 25 25 +27 26 26 +28 27 27 +29 28 28 +30 29 29 +31 30 30 +32 31 31 +33 32 32 +34 33 33 +35 34 34 +36 35 35 +37 36 36 +38 37 37 +39 38 38 +40 39 39 +41 40 40 +42 41 41 +43 42 42 +44 43 43 +45 44 44 +46 45 45 +47 46 46 +48 47 47 +49 48 48 +50 49 49 +51 50 50 +52 51 51 +53 52 52 +54 53 53 +55 54 54 +56 55 55 +57 56 56 +58 57 57 +59 58 58 +60 59 59 +61 60 60 +62 61 61 +63 62 62 +64 63 63 +65 64 64 +66 65 65 +67 66 66 +68 67 67 +69 68 68 +70 69 69 +71 70 70 +72 71 71 +73 72 72 +74 73 73 +75 74 74 +76 75 75 +77 76 76 +78 77 77 +79 78 78 +80 79 79 +81 80 80 +82 81 81 +83 82 82 +84 83 83 +85 84 84 +86 85 85 +87 86 86 +88 87 87 +89 88 88 +90 89 89 +91 90 90 +92 91 91 +93 92 92 +94 93 93 +95 94 94 +96 95 95 +97 96 96 +98 97 97 +99 98 98 +100 99 99 +SELECT * FROM t1 ORDER BY f1 ASC, f0 LIMIT 30; +f0 f1 f2 +1 0 0 +2 1 1 +3 2 2 +4 3 3 +5 4 4 +6 5 5 +7 6 6 +8 7 7 +9 8 8 +10 9 9 +11 10 10 +12 11 11 +13 12 12 +14 13 13 +15 14 14 +16 15 15 +17 16 16 +18 17 17 +19 18 18 +20 19 19 +21 20 20 +22 21 21 +23 22 22 +24 23 23 +25 24 24 +26 25 25 +27 26 26 +28 27 27 +29 28 28 +30 29 29 +SELECT * FROM t1 ORDER BY f1 ASC, f0 LIMIT 0; +f0 f1 f2 +SELECT * FROM t1 ORDER BY f2 DESC, f0 LIMIT 30; +f0 f1 f2 +100 99 99 +99 98 98 +98 97 97 +97 96 96 +96 95 95 +95 94 94 +94 93 93 +93 92 92 +92 91 91 +91 90 90 +10 9 9 +90 89 89 +89 88 88 +88 87 87 +87 86 86 +86 85 85 +85 84 84 +84 83 83 +83 82 82 +82 81 81 +81 80 80 +9 8 8 +80 79 79 +79 78 78 +78 77 77 +77 76 76 +76 75 75 +75 74 74 +74 73 73 +73 72 72 +SELECT * FROM t1 ORDER BY f2 DESC, f0 LIMIT 0; +f0 f1 f2 +SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 20; +f0 f1 f2 +12 11 11 +13 12 12 +14 13 13 +15 14 14 +16 15 15 +17 16 16 +18 17 17 +19 18 18 +20 19 19 +21 20 20 +22 21 21 +23 22 22 +24 23 23 +25 24 24 +26 25 25 +27 26 26 +28 27 27 +29 28 28 +30 29 29 +31 30 30 +SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 0; +f0 f1 f2 +SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 10 OFFSET 10; +f0 f1 f2 +22 21 21 +23 22 22 +24 23 23 +25 24 24 +26 25 25 +27 26 26 +28 27 27 +29 28 28 +30 29 29 +31 30 30 +SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 0 OFFSET 10; +f0 f1 f2 +set sort_buffer_size= 32768; +CREATE TEMPORARY TABLE tmp (f1 int, f2 varchar(20)); +INSERT INTO tmp SELECT f1, f2 FROM t1; +INSERT INTO t1(f1, f2) SELECT * FROM tmp; +INSERT INTO tmp SELECT f1, f2 FROM t1; +INSERT INTO t1(f1, f2) SELECT * FROM tmp; +SELECT * FROM t1 ORDER BY f1 ASC, f0 LIMIT 30; +f0 f1 f2 +1 0 0 +101 0 0 +201 0 0 +301 0 0 +401 0 0 +2 1 1 +102 1 1 +202 1 1 +302 1 1 +402 1 1 +3 2 2 +103 2 2 +203 2 2 +303 2 2 +403 2 2 +4 3 3 +104 3 3 +204 3 3 +304 3 3 +404 3 3 +5 4 4 +105 4 4 +205 4 4 +305 4 4 +405 4 4 +6 5 5 +106 5 5 +206 5 5 +306 5 5 +406 5 5 +SELECT * FROM t1 ORDER BY f1 ASC, f0 LIMIT 0; +f0 f1 f2 +SELECT * FROM t1 ORDER BY f2 DESC, f0 LIMIT 30; +f0 f1 f2 +100 99 99 +200 99 99 +300 99 99 +400 99 99 +500 99 99 +99 98 98 +199 98 98 +299 98 98 +399 98 98 +499 98 98 +98 97 97 +198 97 97 +298 97 97 +398 97 97 +498 97 97 +97 96 96 +197 96 96 +297 96 96 +397 96 96 +497 96 96 +96 95 95 +196 95 95 +296 95 95 +396 95 95 +496 95 95 +95 94 94 +195 94 94 +295 94 94 +395 94 94 +495 94 94 +SELECT * FROM t1 ORDER BY f2 DESC, f0 LIMIT 0; +f0 f1 f2 +SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 20; +f0 f1 f2 +12 11 11 +112 11 11 +212 11 11 +312 11 11 +412 11 11 +13 12 12 +113 12 12 +213 12 12 +313 12 12 +413 12 12 +14 13 13 +114 13 13 +214 13 13 +314 13 13 +414 13 13 +15 14 14 +115 14 14 +215 14 14 +315 14 14 +415 14 14 +SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 0; +f0 f1 f2 +SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 10 OFFSET 10; +f0 f1 f2 +14 13 13 +114 13 13 +214 13 13 +314 13 13 +414 13 13 +15 14 14 +115 14 14 +215 14 14 +315 14 14 +415 14 14 +SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 0 OFFSET 10; +f0 f1 f2 +set sort_buffer_size= 32768; +SELECT SQL_CALC_FOUND_ROWS * FROM t1 +ORDER BY f1, f0 LIMIT 30; +f0 f1 f2 +1 0 0 +101 0 0 +201 0 0 +301 0 0 +401 0 0 +2 1 1 +102 1 1 +202 1 1 +302 1 1 +402 1 1 +3 2 2 +103 2 2 +203 2 2 +303 2 2 +403 2 2 +4 3 3 +104 3 3 +204 3 3 +304 3 3 +404 3 3 +5 4 4 +105 4 4 +205 4 4 +305 4 4 +405 4 4 +6 5 5 +106 5 5 +206 5 5 +306 5 5 +406 5 5 +SELECT FOUND_ROWS(); +FOUND_ROWS() +500 +SELECT SQL_CALC_FOUND_ROWS * FROM t1 +ORDER BY f1, f0 LIMIT 0; +f0 f1 f2 +SELECT FOUND_ROWS(); +FOUND_ROWS() +500 +SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE f1>10 +ORDER BY f2, f0 LIMIT 20; +f0 f1 f2 +12 11 11 +112 11 11 +212 11 11 +312 11 11 +412 11 11 +13 12 12 +113 12 12 +213 12 12 +313 12 12 +413 12 12 +14 13 13 +114 13 13 +214 13 13 +314 13 13 +414 13 13 +15 14 14 +115 14 14 +215 14 14 +315 14 14 +415 14 14 +SELECT FOUND_ROWS(); +FOUND_ROWS() +445 +SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE f1>10 +ORDER BY f2, f0 LIMIT 0; +f0 f1 f2 +SELECT FOUND_ROWS(); +FOUND_ROWS() +445 +SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE f1>10 +ORDER BY f2, f0 LIMIT 10 OFFSET 10; +f0 f1 f2 +14 13 13 +114 13 13 +214 13 13 +314 13 13 +414 13 13 +15 14 14 +115 14 14 +215 14 14 +315 14 14 +415 14 14 +SELECT FOUND_ROWS(); +FOUND_ROWS() +445 +SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE f1>10 +ORDER BY f2, f0 LIMIT 0 OFFSET 10; +f0 f1 f2 +SELECT FOUND_ROWS(); +FOUND_ROWS() +445 +set sort_buffer_size= 327680; +SELECT * FROM t1 JOIN tmp on t1.f2=tmp.f2 +ORDER BY tmp.f1, f0 LIMIT 30; +f0 f1 f2 f1 f2 +1 0 0 0 0 +1 0 0 0 0 +1 0 0 0 0 +101 0 0 0 0 +101 0 0 0 0 +101 0 0 0 0 +201 0 0 0 0 +201 0 0 0 0 +201 0 0 0 0 +301 0 0 0 0 +301 0 0 0 0 +301 0 0 0 0 +401 0 0 0 0 +401 0 0 0 0 +401 0 0 0 0 +2 1 1 1 1 +2 1 1 1 1 +2 1 1 1 1 +102 1 1 1 1 +102 1 1 1 1 +102 1 1 1 1 +202 1 1 1 1 +202 1 1 1 1 +202 1 1 1 1 +302 1 1 1 1 +302 1 1 1 1 +302 1 1 1 1 +402 1 1 1 1 +402 1 1 1 1 +402 1 1 1 1 +SELECT * FROM t1 JOIN tmp on t1.f2=tmp.f2 +ORDER BY tmp.f1, f0 LIMIT 30 OFFSET 30; +f0 f1 f2 f1 f2 +3 2 2 2 2 +3 2 2 2 2 +3 2 2 2 2 +103 2 2 2 2 +103 2 2 2 2 +103 2 2 2 2 +203 2 2 2 2 +203 2 2 2 2 +203 2 2 2 2 +303 2 2 2 2 +303 2 2 2 2 +303 2 2 2 2 +403 2 2 2 2 +403 2 2 2 2 +403 2 2 2 2 +4 3 3 3 3 +4 3 3 3 3 +4 3 3 3 3 +104 3 3 3 3 +104 3 3 3 3 +104 3 3 3 3 +204 3 3 3 3 +204 3 3 3 3 +204 3 3 3 3 +304 3 3 3 3 +304 3 3 3 3 +304 3 3 3 3 +404 3 3 3 3 +404 3 3 3 3 +404 3 3 3 3 +SELECT SQL_CALC_FOUND_ROWS * FROM t1 JOIN tmp on t1.f2=tmp.f2 +ORDER BY tmp.f1, f0 LIMIT 30 OFFSET 30; +f0 f1 f2 f1 f2 +3 2 2 2 2 +3 2 2 2 2 +3 2 2 2 2 +103 2 2 2 2 +103 2 2 2 2 +103 2 2 2 2 +203 2 2 2 2 +203 2 2 2 2 +203 2 2 2 2 +303 2 2 2 2 +303 2 2 2 2 +303 2 2 2 2 +403 2 2 2 2 +403 2 2 2 2 +403 2 2 2 2 +4 3 3 3 3 +4 3 3 3 3 +4 3 3 3 3 +104 3 3 3 3 +104 3 3 3 3 +104 3 3 3 3 +204 3 3 3 3 +204 3 3 3 3 +204 3 3 3 3 +304 3 3 3 3 +304 3 3 3 3 +304 3 3 3 3 +404 3 3 3 3 +404 3 3 3 3 +404 3 3 3 3 +SELECT FOUND_ROWS(); +FOUND_ROWS() +1500 +SELECT SQL_CALC_FOUND_ROWS * FROM t1 JOIN tmp on t1.f2=tmp.f2 +WHERE t1.f2>20 +ORDER BY tmp.f1, f0 LIMIT 30 OFFSET 30; +f0 f1 f2 f1 f2 +24 23 23 23 23 +24 23 23 23 23 +24 23 23 23 23 +124 23 23 23 23 +124 23 23 23 23 +124 23 23 23 23 +224 23 23 23 23 +224 23 23 23 23 +224 23 23 23 23 +324 23 23 23 23 +324 23 23 23 23 +324 23 23 23 23 +424 23 23 23 23 +424 23 23 23 23 +424 23 23 23 23 +25 24 24 24 24 +25 24 24 24 24 +25 24 24 24 24 +125 24 24 24 24 +125 24 24 24 24 +125 24 24 24 24 +225 24 24 24 24 +225 24 24 24 24 +225 24 24 24 24 +325 24 24 24 24 +325 24 24 24 24 +325 24 24 24 24 +425 24 24 24 24 +425 24 24 24 24 +425 24 24 24 24 +SELECT FOUND_ROWS(); +FOUND_ROWS() +1185 +CREATE VIEW v1 as SELECT * FROM t1 ORDER BY f1, f0 LIMIT 30; +SELECT * FROM v1; +f0 f1 f2 +1 0 0 +101 0 0 +201 0 0 +301 0 0 +401 0 0 +2 1 1 +102 1 1 +202 1 1 +302 1 1 +402 1 1 +3 2 2 +103 2 2 +203 2 2 +303 2 2 +403 2 2 +4 3 3 +104 3 3 +204 3 3 +304 3 3 +404 3 3 +5 4 4 +105 4 4 +205 4 4 +305 4 4 +405 4 4 +6 5 5 +106 5 5 +206 5 5 +306 5 5 +406 5 5 +drop view v1; +CREATE VIEW v1 as SELECT * FROM t1 ORDER BY f1, f0 LIMIT 100; +SELECT * FROM v1 ORDER BY f2, f0 LIMIT 30; +f0 f1 f2 +1 0 0 +101 0 0 +201 0 0 +301 0 0 +401 0 0 +2 1 1 +102 1 1 +202 1 1 +302 1 1 +402 1 1 +11 10 10 +111 10 10 +211 10 10 +311 10 10 +411 10 10 +12 11 11 +112 11 11 +212 11 11 +312 11 11 +412 11 11 +13 12 12 +113 12 12 +213 12 12 +313 12 12 +413 12 12 +14 13 13 +114 13 13 +214 13 13 +314 13 13 +414 13 13 +CREATE VIEW v2 as SELECT * FROM t1 ORDER BY f2, f0 LIMIT 100; +SELECT * FROM v1 JOIN v2 on v1.f1=v2.f1 ORDER BY v1.f2,v1.f0,v2.f0 +LIMIT 30; +f0 f1 f2 f0 f1 f2 +1 0 0 1 0 0 +1 0 0 101 0 0 +1 0 0 201 0 0 +1 0 0 301 0 0 +1 0 0 401 0 0 +101 0 0 1 0 0 +101 0 0 101 0 0 +101 0 0 201 0 0 +101 0 0 301 0 0 +101 0 0 401 0 0 +201 0 0 1 0 0 +201 0 0 101 0 0 +201 0 0 201 0 0 +201 0 0 301 0 0 +201 0 0 401 0 0 +301 0 0 1 0 0 +301 0 0 101 0 0 +301 0 0 201 0 0 +301 0 0 301 0 0 +301 0 0 401 0 0 +401 0 0 1 0 0 +401 0 0 101 0 0 +401 0 0 201 0 0 +401 0 0 301 0 0 +401 0 0 401 0 0 +2 1 1 2 1 1 +2 1 1 102 1 1 +2 1 1 202 1 1 +2 1 1 302 1 1 +2 1 1 402 1 1 +SELECT floor(f1/10) f3, count(f2) FROM t1 +GROUP BY 1 ORDER BY 2,1 LIMIT 5; +f3 count(f2) +0 50 +1 50 +2 50 +3 50 +4 50 +SELECT floor(f1/10) f3, count(f2) FROM t1 +GROUP BY 1 ORDER BY 2,1 LIMIT 0; +f3 count(f2) +CREATE PROCEDURE wl1393_sp_test() +BEGIN +SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 30; +SELECT * FROM t1 WHERE f1>10 ORDER BY f2, f0 LIMIT 15 OFFSET 15; +SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE f1>10 +ORDER BY f2, f0 LIMIT 15 OFFSET 15; +SELECT FOUND_ROWS(); +SELECT * FROM v1 ORDER BY f2, f0 LIMIT 30; +END| +CALL wl1393_sp_test()| +f0 f1 f2 +12 11 11 +112 11 11 +212 11 11 +312 11 11 +412 11 11 +13 12 12 +113 12 12 +213 12 12 +313 12 12 +413 12 12 +14 13 13 +114 13 13 +214 13 13 +314 13 13 +414 13 13 +15 14 14 +115 14 14 +215 14 14 +315 14 14 +415 14 14 +16 15 15 +116 15 15 +216 15 15 +316 15 15 +416 15 15 +17 16 16 +117 16 16 +217 16 16 +317 16 16 +417 16 16 +f0 f1 f2 +15 14 14 +115 14 14 +215 14 14 +315 14 14 +415 14 14 +16 15 15 +116 15 15 +216 15 15 +316 15 15 +416 15 15 +17 16 16 +117 16 16 +217 16 16 +317 16 16 +417 16 16 +f0 f1 f2 +15 14 14 +115 14 14 +215 14 14 +315 14 14 +415 14 14 +16 15 15 +116 15 15 +216 15 15 +316 15 15 +416 15 15 +17 16 16 +117 16 16 +217 16 16 +317 16 16 +417 16 16 +FOUND_ROWS() +445 +f0 f1 f2 +1 0 0 +101 0 0 +201 0 0 +301 0 0 +401 0 0 +2 1 1 +102 1 1 +202 1 1 +302 1 1 +402 1 1 +11 10 10 +111 10 10 +211 10 10 +311 10 10 +411 10 10 +12 11 11 +112 11 11 +212 11 11 +312 11 11 +412 11 11 +13 12 12 +113 12 12 +213 12 12 +313 12 12 +413 12 12 +14 13 13 +114 13 13 +214 13 13 +314 13 13 +414 13 13 +DROP PROCEDURE wl1393_sp_test| +SELECT d1.f1, d1.f2 FROM t1 +LEFT JOIN (SELECT * FROM t1 ORDER BY f1 LIMIT 30) d1 on t1.f1=d1.f1 +ORDER BY d1.f2 DESC LIMIT 30; +f1 f2 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +5 5 +4 4 +4 4 +4 4 +4 4 +4 4 +SELECT * FROM t1 WHERE f1 = (SELECT f1 FROM t1 ORDER BY 1 LIMIT 1); +f0 f1 f2 +1 0 0 +101 0 0 +201 0 0 +301 0 0 +401 0 0 +SELECT * FROM t1 WHERE f1 = (SELECT f1 FROM t1 ORDER BY 1 LIMIT 2); +ERROR 21000: Subquery returns more than 1 row +DROP TABLE t1, tmp; +DROP VIEW v1, v2; +# end of WL#1393 - Optimizing filesort with small limit +# +# Bug #58761 +# Crash in Field::is_null in field.h on subquery in WHERE clause +# +CREATE TABLE t1 ( +pk INT NOT NULL AUTO_INCREMENT, +col_int_key INT DEFAULT NULL, +col_varchar_key VARCHAR(1) DEFAULT NULL, +PRIMARY KEY (pk), +KEY col_varchar_key (col_varchar_key,col_int_key) +); +INSERT INTO t1 VALUES (27,7,'x'); +INSERT INTO t1 VALUES (28,6,'m'); +INSERT INTO t1 VALUES (29,4,'c'); +CREATE TABLE where_subselect +SELECT DISTINCT `pk` AS field1 , `pk` AS field2 +FROM t1 AS alias1 +WHERE alias1 . `col_int_key` > 229 +OR alias1 . `col_varchar_key` IS NOT NULL +GROUP BY field1, field2 +; +SELECT * +FROM where_subselect +WHERE (field1, field2) IN ( +SELECT DISTINCT `pk` AS field1 , `pk` AS field2 +FROM t1 AS alias1 +WHERE alias1 . `col_int_key` > 229 +OR alias1 . `col_varchar_key` IS NOT NULL +GROUP BY field1, field2 +); +field1 field2 +27 27 +28 28 +29 29 +DROP TABLE t1; +DROP TABLE where_subselect; +# End of Bug #58761 CREATE TABLE t1 ( id1 INT NULL, id2 INT NOT NULL, diff --git a/mysql-test/r/order_by_sortkey.result b/mysql-test/r/order_by_sortkey.result new file mode 100644 index 00000000000..717780f0af2 --- /dev/null +++ b/mysql-test/r/order_by_sortkey.result @@ -0,0 +1,159 @@ +CREATE TABLE t1( +f0 int auto_increment PRIMARY KEY, +f1 int, +f2 varchar(200) +); +INSERT INTO t1(f1, f2) VALUES +(0,"0"),(1,"1"),(2,"2"),(3,"3"),(4,"4"),(5,"5"), +(6,"6"),(7,"7"),(8,"8"),(9,"9"),(10,"10"), +(11,"11"),(12,"12"),(13,"13"),(14,"14"),(15,"15"), +(16,"16"),(17,"17"),(18,"18"),(19,"19"),(20,"20"), +(21,"21"),(22,"22"),(23,"23"),(24,"24"),(25,"25"), +(26,"26"),(27,"27"),(28,"28"),(29,"29"),(30,"30"), +(31,"31"),(32,"32"),(33,"33"),(34,"34"),(35,"35"), +(36,"36"),(37,"37"),(38,"38"),(39,"39"),(40,"40"), +(41,"41"),(42,"42"),(43,"43"),(44,"44"),(45,"45"), +(46,"46"),(47,"47"),(48,"48"),(49,"49"),(50,"50"), +(51,"51"),(52,"52"),(53,"53"),(54,"54"),(55,"55"), +(56,"56"),(57,"57"),(58,"58"),(59,"59"),(60,"60"), +(61,"61"),(62,"62"),(63,"63"),(64,"64"),(65,"65"), +(66,"66"),(67,"67"),(68,"68"),(69,"69"),(70,"70"), +(71,"71"),(72,"72"),(73,"73"),(74,"74"),(75,"75"), +(76,"76"),(77,"77"),(78,"78"),(79,"79"),(80,"80"), +(81,"81"),(82,"82"),(83,"83"),(84,"84"),(85,"85"), +(86,"86"),(87,"87"),(88,"88"),(89,"89"),(90,"90"), +(91,"91"),(92,"92"),(93,"93"),(94,"94"),(95,"95"), +(96,"96"),(97,"97"),(98,"98"),(99,"99"); +CREATE TEMPORARY TABLE tmp (f1 int, f2 varchar(20)); +INSERT INTO tmp SELECT f1,f2 FROM t1; +INSERT INTO t1(f1,f2) SELECT * FROM tmp; +INSERT INTO tmp SELECT f1,f2 FROM t1; +INSERT INTO t1(f1,f2) SELECT * FROM tmp; +INSERT INTO t1(f1,f2) SELECT * FROM tmp; +INSERT INTO tmp SELECT f1,f2 FROM t1; +INSERT INTO t1(f1,f2) SELECT * FROM tmp; +INSERT INTO tmp SELECT f1,f2 FROM t1; +INSERT INTO t1(f1,f2) SELECT * FROM tmp; +INSERT INTO tmp SELECT f1,f2 FROM t1; +INSERT INTO t1(f1,f2) SELECT * FROM tmp; +INSERT INTO tmp SELECT f1,f2 FROM t1; +INSERT INTO t1(f1,f2) SELECT * FROM tmp; +INSERT INTO tmp SELECT f1,f2 FROM t1; +INSERT INTO t1(f1,f2) SELECT * FROM tmp; +set sort_buffer_size= 32768; +FLUSH STATUS; +SHOW SESSION STATUS LIKE 'Sort%'; +Variable_name Value +Sort_merge_passes 0 +Sort_range 0 +Sort_rows 0 +Sort_scan 0 +SELECT * FROM t1 ORDER BY f2 LIMIT 100; +f0 f1 f2 +1 0 0 +101 0 0 +201 0 0 +301 0 0 +401 0 0 +501 0 0 +601 0 0 +701 0 0 +801 0 0 +901 0 0 +1001 0 0 +1101 0 0 +1201 0 0 +1301 0 0 +1401 0 0 +1501 0 0 +1601 0 0 +1701 0 0 +1801 0 0 +1901 0 0 +2001 0 0 +2101 0 0 +2201 0 0 +2301 0 0 +2401 0 0 +2501 0 0 +2601 0 0 +2701 0 0 +2801 0 0 +2901 0 0 +3001 0 0 +3101 0 0 +3201 0 0 +3301 0 0 +3401 0 0 +3501 0 0 +3601 0 0 +3701 0 0 +3801 0 0 +3901 0 0 +4001 0 0 +4101 0 0 +4201 0 0 +4301 0 0 +4401 0 0 +4501 0 0 +4601 0 0 +4701 0 0 +4801 0 0 +4901 0 0 +5001 0 0 +5101 0 0 +5201 0 0 +5301 0 0 +5401 0 0 +5501 0 0 +5601 0 0 +5701 0 0 +5801 0 0 +5901 0 0 +6001 0 0 +6101 0 0 +6201 0 0 +6301 0 0 +6401 0 0 +6501 0 0 +6601 0 0 +6701 0 0 +6801 0 0 +6901 0 0 +7001 0 0 +7101 0 0 +7201 0 0 +7301 0 0 +7401 0 0 +7501 0 0 +7601 0 0 +7701 0 0 +7801 0 0 +7901 0 0 +8001 0 0 +8101 0 0 +8201 0 0 +8301 0 0 +8401 0 0 +8501 0 0 +8601 0 0 +8701 0 0 +8801 0 0 +8901 0 0 +9001 0 0 +9101 0 0 +9201 0 0 +9301 0 0 +9401 0 0 +9501 0 0 +9601 0 0 +9701 0 0 +9801 0 0 +9901 0 0 +SHOW SESSION STATUS LIKE 'Sort%'; +Variable_name Value +Sort_merge_passes 0 +Sort_range 0 +Sort_rows 100 +Sort_scan 1 +DROP TABLE t1, tmp; diff --git a/mysql-test/r/parser.result b/mysql-test/r/parser.result index a4dfab4bf81..e81eea6e887 100644 --- a/mysql-test/r/parser.result +++ b/mysql-test/r/parser.result @@ -441,7 +441,7 @@ select master_pos_wait(); ERROR 42000: Incorrect parameter count in the call to native function 'master_pos_wait' select master_pos_wait(1); ERROR 42000: Incorrect parameter count in the call to native function 'master_pos_wait' -select master_pos_wait(1, 2, 3, 4); +select master_pos_wait(1, 2, 3, 4, 5); ERROR 42000: Incorrect parameter count in the call to native function 'master_pos_wait' select rand(1, 2, 3); ERROR 42000: Incorrect parameter count in the call to native function 'rand' diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index c1cbbffdbfa..c621bd8bf43 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -175,7 +175,7 @@ t1 CREATE TABLE `t1` ( PRIMARY KEY (`ID`,`aaaa,aaaaa`,`ddddddddd`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 /*!50100 PARTITION BY RANGE (ID) -SUBPARTITION BY LINEAR KEY (ID,`aaaa,aaaaa`) +SUBPARTITION BY LINEAR KEY (`ID`,`aaaa,aaaaa`) SUBPARTITIONS 2 (PARTITION p01 VALUES LESS THAN (100) ENGINE = MyISAM, PARTITION p11 VALUES LESS THAN (200) ENGINE = MyISAM, @@ -2493,3 +2493,25 @@ i 3 4 DROP TABLE t1; +CREATE TABLE t1 ( d DATE NOT NULL) +PARTITION BY RANGE( YEAR(d) ) ( +PARTITION p0 VALUES LESS THAN (1960), +PARTITION p1 VALUES LESS THAN (1970), +PARTITION p2 VALUES LESS THAN (1980), +PARTITION p3 VALUES LESS THAN (1990) +); +ALTER TABLE t1 ADD PARTITION IF NOT EXISTS( +PARTITION `p5` VALUES LESS THAN (2010) +COMMENT 'APSTART \' APEND' +); +ALTER TABLE t1 ADD PARTITION IF NOT EXISTS( +PARTITION `p5` VALUES LESS THAN (2010) +COMMENT 'APSTART \' APEND' +); +Warnings: +Note 1517 Duplicate partition name p5 +alter table t1 drop partition if exists p5; +alter table t1 drop partition if exists p5; +Warnings: +Note 1507 Error in list of partitions to DROP +DROP TABLE t1; diff --git a/mysql-test/r/partition_binlog.result b/mysql-test/r/partition_binlog.result index c8fa02c4b99..8adc0d852e3 100644 --- a/mysql-test/r/partition_binlog.result +++ b/mysql-test/r/partition_binlog.result @@ -41,9 +41,14 @@ ALTER TABLE t1 TRUNCATE PARTITION p0; ALTER TABLE t1 DROP PARTITION p0; show binlog events in 'master-bin.000001' from <binlog_start>; Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; ALTER TABLE t1 ANALYZE PARTITION p0 +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; ALTER TABLE t1 OPTIMIZE PARTITION p0 +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; ALTER TABLE t1 REPAIR PARTITION p0 +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; ALTER TABLE t1 TRUNCATE PARTITION p0 +master-bin.000001 # Gtid # # GTID #-#-# master-bin.000001 # Query # # use `test`; ALTER TABLE t1 DROP PARTITION p0 DROP TABLE t1; diff --git a/mysql-test/r/partition_datatype.result b/mysql-test/r/partition_datatype.result index 1151a1cb1fe..804d9dd1c34 100644 --- a/mysql-test/r/partition_datatype.result +++ b/mysql-test/r/partition_datatype.result @@ -315,11 +315,11 @@ drop table t1; create table t1 (a varchar(3070)) partition by key (a); ERROR HY000: The total length of the partitioning fields is too large create table t1 (a varchar(65533)) partition by key (a); -ERROR 42000: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs +ERROR 42000: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs create table t1 (a varchar(65534) not null) partition by key (a); -ERROR 42000: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs +ERROR 42000: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs create table t1 (a varchar(65535)) partition by key (a); -ERROR 42000: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs +ERROR 42000: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs create table t1 (a bit(27), primary key (a)) engine=myisam partition by hash (a) (partition p0, partition p1, partition p2); diff --git a/mysql-test/r/partition_debug_sync.result b/mysql-test/r/partition_debug_sync.result index ad0f6df5ff2..826bca019d5 100644 --- a/mysql-test/r/partition_debug_sync.result +++ b/mysql-test/r/partition_debug_sync.result @@ -42,21 +42,18 @@ CREATE TABLE t2 b INTEGER NOT NULL, KEY (b)) ENGINE = MYISAM -/*!50100 PARTITION BY RANGE (a) -(PARTITION p0 VALUES LESS THAN (2), +PARTITION BY RANGE (a) (PARTITION p0 VALUES LESS THAN (2), PARTITION p1 VALUES LESS THAN (20), PARTITION p2 VALUES LESS THAN (100), -PARTITION p3 VALUES LESS THAN MAXVALUE ) */; +PARTITION p3 VALUES LESS THAN MAXVALUE); SET DEBUG_SYNC= 'alter_table_before_open_tables SIGNAL removing_partitions WAIT_FOR waiting_for_alter'; SET DEBUG_SYNC= 'alter_table_before_rename_result_table WAIT_FOR delete_done'; ALTER TABLE t2 REMOVE PARTITIONING; # Con default -SET SESSION debug_dbug= "+d,sleep_before_no_locks_delete_table"; SET DEBUG_SYNC= 'now WAIT_FOR removing_partitions'; SET DEBUG_SYNC= 'rm_table_no_locks_before_delete_table SIGNAL waiting_for_alter'; SET DEBUG_SYNC= 'rm_table_no_locks_before_binlog SIGNAL delete_done'; DROP TABLE IF EXISTS t2; -SET SESSION debug_dbug= "-d,sleep_before_no_locks_delete_table"; # Con 1 ERROR 42S02: Table 'test.t2' doesn't exist SET DEBUG_SYNC= 'RESET'; diff --git a/mysql-test/r/partition_disabled.result b/mysql-test/r/partition_disabled.result index 2978a3b6d2e..505bec79610 100644 --- a/mysql-test/r/partition_disabled.result +++ b/mysql-test/r/partition_disabled.result @@ -3,7 +3,7 @@ FLUSH TABLES; SELECT * FROM t1; ERROR HY000: The MariaDB server is running with the --skip-partition option so it cannot execute this statement TRUNCATE TABLE t1; -ERROR 42S02: Table 'test.t1' doesn't exist +ERROR HY000: The MariaDB server is running with the --skip-partition option so it cannot execute this statement ANALYZE TABLE t1; Table Op Msg_type Msg_text test.t1 analyze Error The MariaDB server is running with the --skip-partition option so it cannot execute this statement diff --git a/mysql-test/r/partition_example.result b/mysql-test/r/partition_example.result index 2129eea0818..7b6e9aa5213 100644 --- a/mysql-test/r/partition_example.result +++ b/mysql-test/r/partition_example.result @@ -7,7 +7,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `a` int(11) NOT NULL -) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 +) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `VAROPT`='5' /*!50100 PARTITION BY LIST (a) (PARTITION p0 VALUES IN (1) ENGINE = EXAMPLE, PARTITION p1 VALUES IN (2) ENGINE = EXAMPLE) */ @@ -20,7 +20,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `a` int(11) NOT NULL -) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `ull`=12340 +) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `ull`=12340 `VAROPT`='5' /*!50100 PARTITION BY LIST (a) (PARTITION p0 VALUES IN (1) ENGINE = EXAMPLE, PARTITION p1 VALUES IN (2) ENGINE = EXAMPLE) */ diff --git a/mysql-test/r/partition_innodb_plugin.result b/mysql-test/r/partition_innodb_plugin.result index 21f18f715d0..ceade2a793c 100644 --- a/mysql-test/r/partition_innodb_plugin.result +++ b/mysql-test/r/partition_innodb_plugin.result @@ -67,7 +67,7 @@ LOCK TABLE t1 WRITE; # ALTER fails because COMPRESSED/KEY_BLOCK_SIZE # are incompatible with innodb_file_per_table = OFF; ALTER TABLE t1 ADD PARTITION PARTITIONS 1; -ERROR HY000: Got error 1478 from storage engine +ERROR HY000: Got error 140 "Wrong create options" from storage engine InnoDB t1#P#p0.ibd t1.frm t1.par @@ -76,18 +76,18 @@ t1.par SET innodb_strict_mode = OFF; ALTER TABLE t1 ADD PARTITION PARTITIONS 2; Warnings: -Warning 1478 InnoDB: KEY_BLOCK_SIZE requires innodb_file_per_table. -Warning 1478 InnoDB: ignoring KEY_BLOCK_SIZE=4. -Warning 1478 InnoDB: KEY_BLOCK_SIZE requires innodb_file_per_table. -Warning 1478 InnoDB: ignoring KEY_BLOCK_SIZE=4. -Warning 1478 InnoDB: KEY_BLOCK_SIZE requires innodb_file_per_table. -Warning 1478 InnoDB: ignoring KEY_BLOCK_SIZE=4. +Warning 140 InnoDB: KEY_BLOCK_SIZE requires innodb_file_per_table. +Warning 140 InnoDB: ignoring KEY_BLOCK_SIZE=4. +Warning 140 InnoDB: KEY_BLOCK_SIZE requires innodb_file_per_table. +Warning 140 InnoDB: ignoring KEY_BLOCK_SIZE=4. +Warning 140 InnoDB: KEY_BLOCK_SIZE requires innodb_file_per_table. +Warning 140 InnoDB: ignoring KEY_BLOCK_SIZE=4. t1.frm t1.par ALTER TABLE t1 REBUILD PARTITION p0; Warnings: -Warning 1478 InnoDB: KEY_BLOCK_SIZE requires innodb_file_per_table. -Warning 1478 InnoDB: ignoring KEY_BLOCK_SIZE=4. +Warning 140 InnoDB: KEY_BLOCK_SIZE requires innodb_file_per_table. +Warning 140 InnoDB: ignoring KEY_BLOCK_SIZE=4. UNLOCK TABLES; SHOW CREATE TABLE t1; Table Create Table diff --git a/mysql-test/r/partition_myisam.result b/mysql-test/r/partition_myisam.result index f9bf3a9fb07..ad21859a6a6 100644 --- a/mysql-test/r/partition_myisam.result +++ b/mysql-test/r/partition_myisam.result @@ -102,14 +102,14 @@ FLUSH TABLES; CHECK TABLE t1; Table Op Msg_type Msg_text test.t1 check Error Failed to read from the .par file -test.t1 check Error Incorrect information in file: './test/t1.frm' test.t1 check error Corrupt SELECT * FROM t1; ERROR HY000: Failed to read from the .par file # Note that we will remove the frm file when we detect that # .par file has been deleted. DROP TABLE t1; -ERROR 42S02: Unknown table 't1' +Warnings: +Warning 155 Table 'test.t1' doesn't exist in engine # # Bug#50392: insert_id is not reset for partitioned tables # auto_increment on duplicate entry diff --git a/mysql-test/r/partition_not_windows.result b/mysql-test/r/partition_not_windows.result index 42dca557b3e..a1da9af675b 100644 --- a/mysql-test/r/partition_not_windows.result +++ b/mysql-test/r/partition_not_windows.result @@ -94,4 +94,4 @@ PARTITION p1 DATA DIRECTORY = '/not/existent/p1Data', PARTITION p2 DATA DIRECTORY = '/not/existent/p2Data', PARTITION p3 DATA DIRECTORY = '/not/existent/p3Data' ); -Got one of the listed errors +ERROR HY000: Can't create/write to file '/not/existent/p0Data/example#P#p0.MYD' (Errcode: 2 "No such file or directory") diff --git a/mysql-test/r/partition_open_files_limit.result b/mysql-test/r/partition_open_files_limit.result index 1441ba4e78e..fed32a69c44 100644 --- a/mysql-test/r/partition_open_files_limit.result +++ b/mysql-test/r/partition_open_files_limit.result @@ -5,7 +5,7 @@ ENGINE=MyISAM PARTITION BY KEY () PARTITIONS 1; INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11); # if the bug exists, then crash will happen here ALTER TABLE t1 ADD PARTITION PARTITIONS 511; -ERROR HY000: Out of resources when opening file '<partition file>' (Errcode: 24) +ERROR HY000: Out of resources when opening file '<partition file>' (Errcode: 24 "Too many open files") SELECT * FROM t1; a 1 diff --git a/mysql-test/r/plugin.result b/mysql-test/r/plugin.result index 53b6a6f1651..6a3d93d1b3f 100644 --- a/mysql-test/r/plugin.result +++ b/mysql-test/r/plugin.result @@ -35,20 +35,23 @@ PLUGIN_LICENSE GPL LOAD_OPTION ON PLUGIN_MATURITY Experimental PLUGIN_AUTH_VERSION 3.14.15.926 -CREATE TABLE t1(a int) ENGINE=EXAMPLE; +CREATE TABLE t1 (a int) ENGINE=EXAMPLE; +CREATE TABLE t2 (a int) ENGINE=EXAMPLE; +FLUSH TABLES; SELECT * FROM t1; a set global example_ulong_var=500; set global example_enum_var= e1; show status like 'example%'; Variable_name Value -example_func_example enum_var is 0, ulong_var is 500, double_var is 8.500000, really +Example_func_example enum_var is 0, ulong_var is 500, double_var is 8.500000, really show variables like 'example%'; Variable_name Value example_double_thdvar 8.500000 example_double_var 8.500000 example_enum_var e1 example_ulong_var 500 +example_varopt_default 5 UNINSTALL SONAME 'ha_example'; Warnings: Warning 1620 Plugin is busy and will be uninstalled on shutdown @@ -67,6 +70,10 @@ LOAD_OPTION ON PLUGIN_MATURITY Experimental PLUGIN_AUTH_VERSION 0.1 DROP TABLE t1; +select * from information_schema.plugins where plugin_library like 'ha_example%'; +SELECT * FROM t2; +ERROR 42000: Unknown storage engine 'EXAMPLE' +DROP TABLE t2; UNINSTALL PLUGIN EXAMPLE; ERROR 42000: PLUGIN EXAMPLE does not exist UNINSTALL PLUGIN non_exist; @@ -115,7 +122,7 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `a` int(11) DEFAULT NULL `complex`='c,f,f,f' -) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `ULL`=10000 `STR`='dskj' `one_or_two`='one' `YESNO`=0 +) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `ULL`=10000 `STR`='dskj' `one_or_two`='one' `YESNO`=0 `VAROPT`='5' drop table t1; SET @OLD_SQL_MODE=@@SQL_MODE; SET SQL_MODE='IGNORE_BAD_TABLE_OPTIONS'; @@ -129,20 +136,20 @@ show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `a` int(11) DEFAULT NULL -) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `ULL`=10000000000000000000 `one_or_two`='ttt' `YESNO`=SSS +) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `ULL`=10000000000000000000 `one_or_two`='ttt' `YESNO`=SSS `VAROPT`='5' #alter table alter table t1 ULL=10000000; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `a` int(11) DEFAULT NULL -) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `one_or_two`='ttt' `YESNO`=SSS `ULL`=10000000 +) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `one_or_two`='ttt' `YESNO`=SSS `VAROPT`='5' `ULL`=10000000 alter table t1 change a a int complex='c,c,c'; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `a` int(11) DEFAULT NULL `complex`='c,c,c' -) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `one_or_two`='ttt' `YESNO`=SSS `ULL`=10000000 +) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `one_or_two`='ttt' `YESNO`=SSS `VAROPT`='5' `ULL`=10000000 drop table t1; #illegal value error SET SQL_MODE=''; @@ -157,17 +164,38 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `a` int(11) DEFAULT NULL -) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `ULL`=4660 +) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `ULL`=4660 `VAROPT`='5' +SET example_varopt_default=33; select create_options from information_schema.tables where table_schema='test' and table_name='t1'; create_options -`ULL`=4660 +`ULL`=4660 `VAROPT`='5' ALTER TABLE t1 ULL=DEFAULT; SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `a` int(11) DEFAULT NULL -) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 +) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `VAROPT`='5' DROP TABLE t1; +create table t1 (a int) engine=example; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `VAROPT`='33' +drop table t1; +create table t1 (a int) engine=example varopt=15; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `varopt`=15 +alter table t1 varopt=default; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=EXAMPLE DEFAULT CHARSET=latin1 `VAROPT`='33' +drop table t1; SET @@SQL_MODE=@OLD_SQL_MODE; select 1; 1 diff --git a/mysql-test/r/plugin_auth.result b/mysql-test/r/plugin_auth.result index 8c9657f4d39..0d3948dd313 100644 --- a/mysql-test/r/plugin_auth.result +++ b/mysql-test/r/plugin_auth.result @@ -20,11 +20,11 @@ SHOW CREATE TABLE mysql.proxies_priv; Table Create Table proxies_priv CREATE TABLE `proxies_priv` ( `Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '', - `User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '', + `User` char(80) COLLATE utf8_bin NOT NULL DEFAULT '', `Proxied_host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '', - `Proxied_user` char(16) COLLATE utf8_bin NOT NULL DEFAULT '', + `Proxied_user` char(80) COLLATE utf8_bin NOT NULL DEFAULT '', `With_grant` tinyint(1) NOT NULL DEFAULT '0', - `Grantor` char(77) COLLATE utf8_bin NOT NULL DEFAULT '', + `Grantor` char(141) COLLATE utf8_bin NOT NULL DEFAULT '', `Timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`Host`,`User`,`Proxied_host`,`Proxied_user`), KEY `Grantor` (`Grantor`) @@ -34,8 +34,6 @@ USER() CURRENT_USER() plug@localhost plug_dest@% ## test SET PASSWORD SET PASSWORD = PASSWORD('plug_dest'); -Warnings: -Note 1699 SET PASSWORD has no significance for users authenticating via plugins ## test bad credentials ERROR 28000: Access denied for user 'plug'@'localhost' (using password: YES) ## test bad default plugin : should get CR_AUTH_PLUGIN_CANNOT_LOAD @@ -114,7 +112,7 @@ ERROR 42000: There is no such grant defined for user 'grant_plug' on host '%' in grant_plug_dest_con ## testing what an ordinary user can grant this should fail : no rights to grant all -GRANT PROXY ON ''@'' TO grant_plug; +GRANT PROXY ON ''@'%%' TO grant_plug; ERROR 28000: Access denied for user 'grant_plug_dest'@'localhost' this should fail : not the same user GRANT PROXY ON grant_plug TO grant_plug_dest; @@ -137,15 +135,15 @@ ERROR 42000: You are not allowed to create a user with GRANT in default connection # test what root can grant should work : root has PROXY to all users -GRANT PROXY ON ''@'' TO grant_plug; -REVOKE PROXY ON ''@'' FROM grant_plug; +GRANT PROXY ON ''@'%%' TO grant_plug; +REVOKE PROXY ON ''@'%%' FROM grant_plug; should work : root has PROXY to all users -GRANT PROXY ON ''@'' TO proxy_admin IDENTIFIED BY 'test' +GRANT PROXY ON ''@'%%' TO proxy_admin IDENTIFIED BY 'test' WITH GRANT OPTION; need USAGE : PROXY doesn't contain it. GRANT USAGE on *.* TO proxy_admin; in proxy_admin_con; -should work : proxy_admin has proxy to ''@'' +should work : proxy_admin has proxy to ''@'%%' GRANT PROXY ON future_user TO grant_plug; in default connection SHOW GRANTS FOR grant_plug; @@ -232,25 +230,25 @@ DROP USER plug_dest; # Bug #56798 : Wrong credentials assigned when using a proxy user. # GRANT ALL PRIVILEGES ON *.* TO power_user; -GRANT USAGE ON anonymous_db.* TO ''@'' +GRANT USAGE ON anonymous_db.* TO ''@'%%' IDENTIFIED WITH 'test_plugin_server' AS 'power_user'; -GRANT PROXY ON power_user TO ''@''; +GRANT PROXY ON power_user TO ''@'%%'; CREATE DATABASE confidential_db; SELECT user(),current_user(),@@proxy_user; user() current_user() @@proxy_user -test_login_user@localhost power_user@% ''@'' +test_login_user@localhost power_user@% ''@'%%' DROP USER power_user; -DROP USER ''@''; +DROP USER ''@'%%'; DROP DATABASE confidential_db; # Test case #2 (crash with double grant proxy) -CREATE USER ''@'' IDENTIFIED WITH 'test_plugin_server' AS 'standard_user'; +CREATE USER ''@'%%' IDENTIFIED WITH 'test_plugin_server' AS 'standard_user'; CREATE USER standard_user; CREATE DATABASE shared; GRANT ALL PRIVILEGES ON shared.* TO standard_user; -GRANT PROXY ON standard_user TO ''@''; +GRANT PROXY ON standard_user TO ''@'%%'; #should not crash -GRANT PROXY ON standard_user TO ''@''; -DROP USER ''@''; +GRANT PROXY ON standard_user TO ''@'%%'; +DROP USER ''@'%%'; DROP USER standard_user; DROP DATABASE shared; # @@ -423,8 +421,6 @@ SELECT USER(),CURRENT_USER(); USER() CURRENT_USER() bug12818542@localhost bug12818542_dest@localhost SET PASSWORD = PASSWORD('bruhaha'); -Warnings: -Note 1699 SET PASSWORD has no significance for users authenticating via plugins SELECT USER(),CURRENT_USER(); USER() CURRENT_USER() bug12818542@localhost bug12818542_dest@localhost diff --git a/mysql-test/r/plugin_auth_qa.result b/mysql-test/r/plugin_auth_qa.result index 72d21994792..b86a01f6b52 100644 --- a/mysql-test/r/plugin_auth_qa.result +++ b/mysql-test/r/plugin_auth_qa.result @@ -303,7 +303,7 @@ grant_user test_plugin_server plug_dest CREATE USER plug_dest; DROP USER plug_dest; GRANT ALL PRIVILEGES ON test_user_db.* TO plug_dest; -ERROR 42000: Can't find any matching row in the user table +ERROR 28000: Can't find any matching row in the user table DROP USER grant_user; GRANT INSERT ON test_user_db.* TO grant_user IDENTIFIED WITH test_plugin_server AS 'plug_dest'; SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root'; diff --git a/mysql-test/r/plugin_auth_qa_1.result b/mysql-test/r/plugin_auth_qa_1.result index d700be36ac0..44b5a88de1e 100644 --- a/mysql-test/r/plugin_auth_qa_1.result +++ b/mysql-test/r/plugin_auth_qa_1.result @@ -186,7 +186,7 @@ connection default; disconnect plug_user; DROP USER new_user,new_dest,plug_dest; ========== test 2, 2.1, 2.2 ================================ -CREATE USER ''@'' IDENTIFIED WITH test_plugin_server AS 'proxied_user'; +CREATE USER ''@'%%' IDENTIFIED WITH test_plugin_server AS 'proxied_user'; CREATE USER proxied_user IDENTIFIED BY 'proxied_user_passwd'; SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root'; user plugin authentication_string @@ -204,7 +204,7 @@ connection default; disconnect proxy_con; connect(proxy_con,localhost,proxy_user,proxied_user); ERROR 28000: Access denied for user 'proxy_user'@'localhost' (using password: YES) -GRANT PROXY ON proxied_user TO ''@''; +GRANT PROXY ON proxied_user TO ''@'%%'; connect(proxy_con,localhost,proxied_user,proxied_user_passwd); SELECT USER(),CURRENT_USER(); USER() CURRENT_USER() @@ -218,11 +218,11 @@ proxy_user@localhost proxied_user@% ========== test 2.2.1 ====================================== SELECT @@proxy_user; @@proxy_user -''@'' +''@'%%' connection default; disconnect proxy_con; -DROP USER ''@'',proxied_user; -GRANT ALL PRIVILEGES ON test_user_db.* TO ''@'' +DROP USER ''@'%%',proxied_user; +GRANT ALL PRIVILEGES ON test_user_db.* TO ''@'%%' IDENTIFIED WITH test_plugin_server AS 'proxied_user'; CREATE USER proxied_user IDENTIFIED BY 'proxied_user_passwd'; SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root'; @@ -240,7 +240,7 @@ connection default; disconnect proxy_con; connect(proxy_con,localhost,proxy_user,proxied_user); ERROR 28000: Access denied for user 'proxy_user'@'localhost' (using password: YES) -GRANT PROXY ON proxied_user TO ''@''; +GRANT PROXY ON proxied_user TO ''@'%%'; connect(proxy_con,localhost,proxied_user,proxied_user_passwd); SELECT USER(),CURRENT_USER(); USER() CURRENT_USER() @@ -253,21 +253,21 @@ USER() CURRENT_USER() proxy_user@localhost proxied_user@% SELECT @@proxy_user; @@proxy_user -''@'' +''@'%%' connection default; disconnect proxy_con; -DROP USER ''@'',proxied_user; -CREATE USER ''@'' IDENTIFIED WITH test_plugin_server AS 'proxied_user'; +DROP USER ''@'%%',proxied_user; +CREATE USER ''@'%%' IDENTIFIED WITH test_plugin_server AS 'proxied_user'; CREATE USER proxied_user_1 IDENTIFIED BY 'proxied_user_1_pwd'; CREATE USER proxied_user_2 IDENTIFIED BY 'proxied_user_2_pwd'; CREATE USER proxied_user_3 IDENTIFIED BY 'proxied_user_3_pwd'; CREATE USER proxied_user_4 IDENTIFIED BY 'proxied_user_4_pwd'; CREATE USER proxied_user_5 IDENTIFIED BY 'proxied_user_5_pwd'; -GRANT PROXY ON proxied_user_1 TO ''@''; -GRANT PROXY ON proxied_user_2 TO ''@''; -GRANT PROXY ON proxied_user_3 TO ''@''; -GRANT PROXY ON proxied_user_4 TO ''@''; -GRANT PROXY ON proxied_user_5 TO ''@''; +GRANT PROXY ON proxied_user_1 TO ''@'%%'; +GRANT PROXY ON proxied_user_2 TO ''@'%%'; +GRANT PROXY ON proxied_user_3 TO ''@'%%'; +GRANT PROXY ON proxied_user_4 TO ''@'%%'; +GRANT PROXY ON proxied_user_5 TO ''@'%%'; SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root'; user plugin authentication_string test_plugin_server proxied_user @@ -322,7 +322,7 @@ disconnect proxy_con_2; disconnect proxy_con_3; disconnect proxy_con_4; disconnect proxy_con_5; -DROP USER ''@'',proxied_user_1,proxied_user_2,proxied_user_3,proxied_user_4,proxied_user_5; +DROP USER ''@'%%',proxied_user_1,proxied_user_2,proxied_user_3,proxied_user_4,proxied_user_5; ========== test 3 ========================================== GRANT ALL PRIVILEGES ON *.* TO plug_user IDENTIFIED WITH test_plugin_server AS 'plug_dest'; diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index cc348e849e3..fa15bcf5576 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -1201,13 +1201,13 @@ SET @aux= "SELECT COUNT(*) prepare my_stmt from @aux; execute my_stmt; COUNT(*) -42 +43 execute my_stmt; COUNT(*) -42 +43 execute my_stmt; COUNT(*) -42 +43 deallocate prepare my_stmt; drop procedure if exists p1| drop table if exists t1| diff --git a/mysql-test/r/ps_1general.result b/mysql-test/r/ps_1general.result index 0a3d16cf48e..0a8aea94e8a 100644 --- a/mysql-test/r/ps_1general.result +++ b/mysql-test/r/ps_1general.result @@ -533,7 +533,7 @@ drop table t2; prepare stmt1 from ' rename table t5 to t6, t7 to t8 ' ; create table t5 (a int) ; execute stmt1 ; -ERROR HY000: Can't find file: './test/t7' (errno: 2) +ERROR 42S02: Table 'test.t7' doesn't exist create table t7 (a int) ; execute stmt1 ; execute stmt1 ; diff --git a/mysql-test/r/range.result b/mysql-test/r/range.result index d41bfaa2c67..e169dcb40b0 100644 --- a/mysql-test/r/range.result +++ b/mysql-test/r/range.result @@ -221,27 +221,27 @@ update t1 set y=x; explain select * from t1, t1 t2 where t1.y = 8 and t2.x between 7 and t1.y+0; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref y y 5 const 1 -1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using join buffer (flat, BNL join) +1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using where; Using join buffer (flat, BNL join) explain select * from t1, t1 t2 where t1.y = 8 and t2.x >= 7 and t2.x <= t1.y+0; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref y y 5 const 1 -1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using join buffer (flat, BNL join) +1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using where; Using join buffer (flat, BNL join) explain select * from t1, t1 t2 where t1.y = 2 and t2.x between t1.y-1 and t1.y+1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref y y 5 const 1 -1 SIMPLE t2 range x x 5 NULL 3 Using index condition; Using join buffer (flat, BNL join) +1 SIMPLE t2 range x x 5 NULL 3 Using index condition; Using where; Using join buffer (flat, BNL join) explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= t1.y-1 and t2.x <= t1.y+1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref y y 5 const 1 -1 SIMPLE t2 range x x 5 NULL 3 Using index condition; Using join buffer (flat, BNL join) +1 SIMPLE t2 range x x 5 NULL 3 Using index condition; Using where; Using join buffer (flat, BNL join) explain select * from t1, t1 t2 where t1.y = 2 and t2.x between 0 and t1.y; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref y y 5 const 1 -1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using join buffer (flat, BNL join) +1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using where; Using join buffer (flat, BNL join) explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= 0 and t2.x <= t1.y; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref y y 5 const 1 -1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using join buffer (flat, BNL join) +1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using where; Using join buffer (flat, BNL join) explain select count(*) from t1 where x in (1); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref x x 5 const 1 Using index diff --git a/mysql-test/r/range_mrr_icp.result b/mysql-test/r/range_mrr_icp.result index a5c14d99975..0d6bfc2467b 100644 --- a/mysql-test/r/range_mrr_icp.result +++ b/mysql-test/r/range_mrr_icp.result @@ -223,27 +223,27 @@ update t1 set y=x; explain select * from t1, t1 t2 where t1.y = 8 and t2.x between 7 and t1.y+0; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref y y 5 const 1 -1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Rowid-ordered scan; Using join buffer (flat, BNL join) +1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) explain select * from t1, t1 t2 where t1.y = 8 and t2.x >= 7 and t2.x <= t1.y+0; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref y y 5 const 1 -1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Rowid-ordered scan; Using join buffer (flat, BNL join) +1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) explain select * from t1, t1 t2 where t1.y = 2 and t2.x between t1.y-1 and t1.y+1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref y y 5 const 1 -1 SIMPLE t2 range x x 5 NULL 3 Using index condition; Rowid-ordered scan; Using join buffer (flat, BNL join) +1 SIMPLE t2 range x x 5 NULL 3 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= t1.y-1 and t2.x <= t1.y+1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref y y 5 const 1 -1 SIMPLE t2 range x x 5 NULL 3 Using index condition; Rowid-ordered scan; Using join buffer (flat, BNL join) +1 SIMPLE t2 range x x 5 NULL 3 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) explain select * from t1, t1 t2 where t1.y = 2 and t2.x between 0 and t1.y; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref y y 5 const 1 -1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Rowid-ordered scan; Using join buffer (flat, BNL join) +1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= 0 and t2.x <= t1.y; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref y y 5 const 1 -1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Rowid-ordered scan; Using join buffer (flat, BNL join) +1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) explain select count(*) from t1 where x in (1); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref x x 5 const 1 Using index diff --git a/mysql-test/r/range_vs_index_merge.result b/mysql-test/r/range_vs_index_merge.result index cc8a345a2ff..424b1009a97 100644 --- a/mysql-test/r/range_vs_index_merge.result +++ b/mysql-test/r/range_vs_index_merge.result @@ -1576,7 +1576,7 @@ update t1 set c1=lpad(id+1000, 12, ' '), c2=lpad(id+10000, 15, ' '); alter table t1 add unique index (c1), add unique index (c2), add index (c3); analyze table t1; Table Op Msg_type Msg_text -test.t1 analyze status OK +test.t1 analyze status Table is already up to date explain select * from t1 where (c1=' 100000' or c2=' 2000000'); id select_type table type possible_keys key key_len ref rows Extra diff --git a/mysql-test/r/rename.result b/mysql-test/r/rename.result index edf05d0c5d3..7433ab8a0c9 100644 --- a/mysql-test/r/rename.result +++ b/mysql-test/r/rename.result @@ -14,20 +14,20 @@ select * from t1; 1 table 1 1 table 1 rename table t1 to t2; -Got one of the listed errors +ERROR 42S01: Table 't2' already exists rename table t1 to t1; -Got one of the listed errors +ERROR 42S01: Table 't1' already exists rename table t3 to t4, t2 to t3, t1 to t2, t4 to t2; -Got one of the listed errors +ERROR 42S01: Table 't2' already exists show tables like "t_"; Tables_in_test (t_) t1 t2 t3 rename table t3 to t1, t2 to t3, t1 to t2, t4 to t1; -Got one of the listed errors +ERROR 42S01: Table 't1' already exists rename table t3 to t4, t5 to t3, t1 to t2, t4 to t1; -Got one of the listed errors +ERROR 42S02: Table 'test.t5' doesn't exist select * from t1; 1 table 1 1 table 1 diff --git a/mysql-test/r/repair.result b/mysql-test/r/repair.result index 52ae9c38792..cdf6a50db72 100644 --- a/mysql-test/r/repair.result +++ b/mysql-test/r/repair.result @@ -77,12 +77,12 @@ INSERT INTO t1 VALUES ('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'),('0'), ('0'),('0'),('0'),('0'),('0'),('0'),('0'); Warnings: -Error 1034 myisam_sort_buffer_size is too small +Error 1034 myisam_sort_buffer_size is too small. X Error 1034 Number of rows changed from 0 to 157 SET myisam_repair_threads=2; REPAIR TABLE t1; Table Op Msg_type Msg_text -test.t1 repair error myisam_sort_buffer_size is too small +test.t1 repair error myisam_sort_buffer_size is too small. X test.t1 repair warning Number of rows changed from 0 to 157 test.t1 repair status OK SET myisam_repair_threads=@@global.myisam_repair_threads; @@ -188,14 +188,14 @@ drop tables t1, t2; # # Test with a saved table from 3.23 select count(*) from t1; -ERROR HY000: Got error 185 'Incompatible key or row definition between the MariaDB .frm file and the information in the storage engine. You have to dump and restore the table to fix this' from MyISAM +ERROR HY000: Got error 187 "Incompatible key or row definition between the MariaDB .frm file and the information in the storage engine. You have to dump an" from storage engine MyISAM check table t1; Table Op Msg_type Msg_text -test.t1 check Error Got error 185 'Incompatible key or row definition between the MariaDB .frm file and the information in the storage engine. You have to dump and restore the table to fix this' from MyISAM +test.t1 check Error Got error 187 "Incompatible key or row definition between the MariaDB .frm file and the information in the storage engine. You have to dump an" from storage engine MyISAM test.t1 check error Corrupt repair table t1; Table Op Msg_type Msg_text -test.t1 repair Error Got error 185 'Incompatible key or row definition between the MariaDB .frm file and the information in the storage engine. You have to dump and restore the table to fix this' from MyISAM +test.t1 repair Error Got error 187 "Incompatible key or row definition between the MariaDB .frm file and the information in the storage engine. You have to dump an" from storage engine MyISAM test.t1 repair error Corrupt repair table t1 use_frm; Table Op Msg_type Msg_text diff --git a/mysql-test/r/row-checksum-old.result b/mysql-test/r/row-checksum-old.result index ef523463860..87f0bb8af2d 100644 --- a/mysql-test/r/row-checksum-old.result +++ b/mysql-test/r/row-checksum-old.result @@ -73,7 +73,7 @@ test.t1 4108368782 drop table if exists t1; create table t1 (a int null, v varchar(100)) engine=innodb checksum=0 row_format=fixed; Warnings: -Warning 1478 InnoDB: assuming ROW_FORMAT=COMPACT. +Warning 140 InnoDB: assuming ROW_FORMAT=COMPACT. insert into t1 values(null, null), (1, "hello"); checksum table t1; Table Checksum diff --git a/mysql-test/r/row-checksum.result b/mysql-test/r/row-checksum.result index fb8a1260a1d..9e58d6fa96e 100644 --- a/mysql-test/r/row-checksum.result +++ b/mysql-test/r/row-checksum.result @@ -73,7 +73,7 @@ test.t1 3885665021 drop table if exists t1; create table t1 (a int null, v varchar(100)) engine=innodb checksum=0 row_format=fixed; Warnings: -Warning 1478 InnoDB: assuming ROW_FORMAT=COMPACT. +Warning 140 InnoDB: assuming ROW_FORMAT=COMPACT. insert into t1 values(null, null), (1, "hello"); checksum table t1; Table Checksum diff --git a/mysql-test/r/schema.result b/mysql-test/r/schema.result index 809d652053e..bb6dbd65f84 100644 --- a/mysql-test/r/schema.result +++ b/mysql-test/r/schema.result @@ -5,8 +5,8 @@ Database Create Database foo CREATE DATABASE `foo` /*!40100 DEFAULT CHARACTER SET latin1 */ show schemas; Database -information_schema foo +information_schema mtr mysql performance_schema diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index f465f5f23da..670c1460ba7 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -5470,3 +5470,38 @@ pk1 a1 b1 pk2 a2 3 1 6 1 1 DROP TABLE t1,t2; End of 5.3 tests +# +# mysql BUG#1271 Undefined variable in PASSWORD() +# function is not handled correctly +# +create table t1 ( +name VARCHAR(50) NOT NULL PRIMARY KEY, +pw VARCHAR(41) NOT NULL); +INSERT INTO t1 (name, pw) +VALUES ('tom', PASSWORD('my_pw')); +SET @pass='my_pw'; +SET @wrong='incorrect'; +select * from t1; +name pw +tom *F305E8EC27734F687F2EB6EC03CF0F7AF27C18E1 +select length(PASSWORD(@pass)); +length(PASSWORD(@pass)) +41 +SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@pass); +name +tom +SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@wrong); +name +SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined); +name +select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@pass)); +(SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@pass)) +tom +select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@wrong)); +(SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@wrong)) +NULL +select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined)); +(SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined)) +NULL +drop table t1; +End of 10.0 tests diff --git a/mysql-test/r/select_jcl6.result b/mysql-test/r/select_jcl6.result index a51f2030595..81eda02fda9 100644 --- a/mysql-test/r/select_jcl6.result +++ b/mysql-test/r/select_jcl6.result @@ -5481,6 +5481,41 @@ pk1 a1 b1 pk2 a2 3 1 6 1 1 DROP TABLE t1,t2; End of 5.3 tests +# +# mysql BUG#1271 Undefined variable in PASSWORD() +# function is not handled correctly +# +create table t1 ( +name VARCHAR(50) NOT NULL PRIMARY KEY, +pw VARCHAR(41) NOT NULL); +INSERT INTO t1 (name, pw) +VALUES ('tom', PASSWORD('my_pw')); +SET @pass='my_pw'; +SET @wrong='incorrect'; +select * from t1; +name pw +tom *F305E8EC27734F687F2EB6EC03CF0F7AF27C18E1 +select length(PASSWORD(@pass)); +length(PASSWORD(@pass)) +41 +SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@pass); +name +tom +SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@wrong); +name +SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined); +name +select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@pass)); +(SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@pass)) +tom +select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@wrong)); +(SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@wrong)) +NULL +select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined)); +(SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined)) +NULL +drop table t1; +End of 10.0 tests set join_cache_level=default; show variables like 'join_cache_level'; Variable_name Value diff --git a/mysql-test/r/select_pkeycache.result b/mysql-test/r/select_pkeycache.result index f465f5f23da..670c1460ba7 100644 --- a/mysql-test/r/select_pkeycache.result +++ b/mysql-test/r/select_pkeycache.result @@ -5470,3 +5470,38 @@ pk1 a1 b1 pk2 a2 3 1 6 1 1 DROP TABLE t1,t2; End of 5.3 tests +# +# mysql BUG#1271 Undefined variable in PASSWORD() +# function is not handled correctly +# +create table t1 ( +name VARCHAR(50) NOT NULL PRIMARY KEY, +pw VARCHAR(41) NOT NULL); +INSERT INTO t1 (name, pw) +VALUES ('tom', PASSWORD('my_pw')); +SET @pass='my_pw'; +SET @wrong='incorrect'; +select * from t1; +name pw +tom *F305E8EC27734F687F2EB6EC03CF0F7AF27C18E1 +select length(PASSWORD(@pass)); +length(PASSWORD(@pass)) +41 +SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@pass); +name +tom +SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@wrong); +name +SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined); +name +select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@pass)); +(SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@pass)) +tom +select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@wrong)); +(SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@wrong)) +NULL +select (SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined)); +(SELECT name FROM t1 WHERE name='tom' AND pw=PASSWORD(@undefined)) +NULL +drop table t1; +End of 10.0 tests diff --git a/mysql-test/r/selectivity.result b/mysql-test/r/selectivity.result new file mode 100644 index 00000000000..3059431c2e5 --- /dev/null +++ b/mysql-test/r/selectivity.result @@ -0,0 +1,1168 @@ +select @@global.use_stat_tables; +@@global.use_stat_tables +COMPLEMENTARY +select @@session.use_stat_tables; +@@session.use_stat_tables +COMPLEMENTARY +set @save_use_stat_tables=@@use_stat_tables; +set use_stat_tables='preferably'; +set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity; +set @save_histogram_size=@@histogram_size; +set @save_histogram_type=@@histogram_type; +set optimizer_use_condition_selectivity=3; +create table t1 (a int); +insert into t1 values +(9), (3), (2), (NULL), (NULL), (2), (NULL), (1), (5), (NULL); +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +select * from mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 1 9 0.4000 4.0000 1.2000 0 NULL NULL +flush table t1; +explain extended +select * from t1 where a is null; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 40.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where isnull(`test`.`t1`.`a`) +explain extended +select * from t1 where a is not null; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 60.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` is not null) +drop table t1; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +=== Q2 === +set optimizer_use_condition_selectivity=5; +explain extended +select +s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment +from +part, supplier, partsupp, nation, region +where +p_partkey = ps_partkey +and s_suppkey = ps_suppkey +and p_size = 9 +and p_type like '%TIN' + and s_nationkey = n_nationkey +and n_regionkey = r_regionkey +and r_name = 'ASIA' + and ps_supplycost = ( +select +min(ps_supplycost) +from +partsupp, supplier, nation, region +where +p_partkey = ps_partkey +and s_suppkey = ps_suppkey +and s_nationkey = n_nationkey +and n_regionkey = r_regionkey +and r_name = 'ASIA' + ) +order by +s_acctbal desc, n_name, s_name, p_partkey; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 0.31 Using where; Using temporary; Using filesort +1 PRIMARY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 80.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where +2 DEPENDENT SUBQUERY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where +2 DEPENDENT SUBQUERY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 +2 DEPENDENT SUBQUERY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where +2 DEPENDENT SUBQUERY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.part.p_partkey' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`part`.`p_size` = 9) and (`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey`) and (`dbt3_s001`.`region`.`r_name` = 'ASIA') and (`dbt3_s001`.`part`.`p_type` like '%TIN') and (`dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where ((`dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey`) and (`dbt3_s001`.`region`.`r_name` = 'ASIA') and (`dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)))))) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey` +set optimizer_use_condition_selectivity=4; +explain extended +select +s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment +from +part, supplier, partsupp, nation, region +where +p_partkey = ps_partkey +and s_suppkey = ps_suppkey +and p_size = 9 +and p_type like '%TIN' + and s_nationkey = n_nationkey +and n_regionkey = r_regionkey +and r_name = 'ASIA' + and ps_supplycost = ( +select +min(ps_supplycost) +from +partsupp, supplier, nation, region +where +p_partkey = ps_partkey +and s_suppkey = ps_suppkey +and s_nationkey = n_nationkey +and n_regionkey = r_regionkey +and r_name = 'ASIA' + ) +order by +s_acctbal desc, n_name, s_name, p_partkey; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where; Using temporary; Using filesort +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 2.08 Using where; Using join buffer (flat, BNL join) +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 80.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where +2 DEPENDENT SUBQUERY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where +2 DEPENDENT SUBQUERY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 +2 DEPENDENT SUBQUERY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where +2 DEPENDENT SUBQUERY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.part.p_partkey' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`part`.`p_size` = 9) and (`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey`) and (`dbt3_s001`.`region`.`r_name` = 'ASIA') and (`dbt3_s001`.`part`.`p_type` like '%TIN') and (`dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where ((`dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey`) and (`dbt3_s001`.`region`.`r_name` = 'ASIA') and (`dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)))))) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey` +=== Q15 === +create view revenue0 (supplier_no, total_revenue) as +select l_suppkey, sum(l_extendedprice * (1 - l_discount)) +from lineitem +where +l_shipdate >= '1995-08-01' + and l_shipdate < date_add('1995-08-01', interval 90 day) +group by l_suppkey; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no +and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using filesort +1 PRIMARY <derived3> ref key0 key0 5 dbt3_s001.supplier.s_suppkey 10 100.00 Using where +3 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 268 100.00 Using where; Using temporary; Using filesort +2 SUBQUERY <derived4> ALL NULL NULL NULL NULL 268 100.00 +4 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 268 100.00 Using where; Using temporary; Using filesort +Warnings: +Note 1003 select `dbt3_s001`.`supplier`.`s_suppkey` AS `s_suppkey`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`revenue0`.`total_revenue` AS `total_revenue` from `dbt3_s001`.`supplier` join `dbt3_s001`.`revenue0` where ((`revenue0`.`supplier_no` = `dbt3_s001`.`supplier`.`s_suppkey`) and (`revenue0`.`total_revenue` = (select max(`revenue0`.`total_revenue`) from `dbt3_s001`.`revenue0`))) order by `dbt3_s001`.`supplier`.`s_suppkey` +select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no +and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; +s_suppkey s_name s_address s_phone total_revenue +1 Supplier#000000001 N kD4on9OM Ipw3,gf0JBoQDd7tgrzrddZ 27-918-335-1736 729084.7773 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no +and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using filesort +1 PRIMARY <derived3> ref key0 key0 5 dbt3_s001.supplier.s_suppkey 10 100.00 Using where +3 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 268 100.00 Using where; Using temporary; Using filesort +2 SUBQUERY <derived4> ALL NULL NULL NULL NULL 268 100.00 +4 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 268 100.00 Using where; Using temporary; Using filesort +Warnings: +Note 1003 select `dbt3_s001`.`supplier`.`s_suppkey` AS `s_suppkey`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`revenue0`.`total_revenue` AS `total_revenue` from `dbt3_s001`.`supplier` join `dbt3_s001`.`revenue0` where ((`revenue0`.`supplier_no` = `dbt3_s001`.`supplier`.`s_suppkey`) and (`revenue0`.`total_revenue` = (select max(`revenue0`.`total_revenue`) from `dbt3_s001`.`revenue0`))) order by `dbt3_s001`.`supplier`.`s_suppkey` +select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no +and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; +s_suppkey s_name s_address s_phone total_revenue +1 Supplier#000000001 N kD4on9OM Ipw3,gf0JBoQDd7tgrzrddZ 27-918-335-1736 729084.7773 +set optimizer_switch=@save_optimizer_switch; +drop view revenue0; +=== Q16 === +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 100.00 Using where; Using temporary; Using filesort +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where; Using index +2 MATERIALIZED supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using where +Warnings: +Note 1003 select `dbt3_s001`.`part`.`p_brand` AS `p_brand`,`dbt3_s001`.`part`.`p_type` AS `p_type`,`dbt3_s001`.`part`.`p_size` AS `p_size`,count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) AS `supplier_cnt` from `dbt3_s001`.`partsupp` join `dbt3_s001`.`part` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`part`.`p_brand` <> 'Brand#11') and (not((`dbt3_s001`.`part`.`p_type` like 'SMALL POLISHED%'))) and (`dbt3_s001`.`part`.`p_size` in (49,37,27,5,40,6,22,8)) and (not(<expr_cache><`dbt3_s001`.`partsupp`.`ps_suppkey`>(<in_optimizer>(`dbt3_s001`.`partsupp`.`ps_suppkey`,`dbt3_s001`.`partsupp`.`ps_suppkey` in ( <materialize> (select `dbt3_s001`.`supplier`.`s_suppkey` from `dbt3_s001`.`supplier` where (`dbt3_s001`.`supplier`.`s_comment` like '%Customer%Complaints%') ), <primary_index_lookup>(`dbt3_s001`.`partsupp`.`ps_suppkey` in <temporary table> on distinct_key where ((`dbt3_s001`.`partsupp`.`ps_suppkey` = `<subquery2>`.`s_suppkey`))))))))) group by `dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` order by count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) desc,`dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` +select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +p_brand p_type p_size supplier_cnt +Brand#21 MEDIUM ANODIZED TIN 8 4 +Brand#22 PROMO PLATED TIN 5 4 +Brand#24 MEDIUM BURNISHED NICKEL 6 4 +Brand#24 SMALL ANODIZED STEEL 40 4 +Brand#32 MEDIUM BURNISHED BRASS 49 4 +Brand#33 MEDIUM POLISHED BRASS 49 4 +Brand#41 STANDARD BRUSHED NICKEL 40 4 +Brand#44 PROMO POLISHED STEEL 5 4 +Brand#45 PROMO ANODIZED BRASS 22 4 +Brand#53 STANDARD BRUSHED STEEL 27 4 +Brand#54 MEDIUM POLISHED BRASS 22 4 +Brand#54 STANDARD ANODIZED BRASS 22 4 +Brand#13 LARGE BRUSHED STEEL 8 2 +Brand#25 ECONOMY BURNISHED COPPER 27 2 +Brand#44 STANDARD PLATED TIN 37 1 +Brand#51 ECONOMY POLISHED STEEL 49 1 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 16.67 Using where; Using temporary; Using filesort +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where; Using index +2 MATERIALIZED supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using where +Warnings: +Note 1003 select `dbt3_s001`.`part`.`p_brand` AS `p_brand`,`dbt3_s001`.`part`.`p_type` AS `p_type`,`dbt3_s001`.`part`.`p_size` AS `p_size`,count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) AS `supplier_cnt` from `dbt3_s001`.`partsupp` join `dbt3_s001`.`part` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`part`.`p_brand` <> 'Brand#11') and (not((`dbt3_s001`.`part`.`p_type` like 'SMALL POLISHED%'))) and (`dbt3_s001`.`part`.`p_size` in (49,37,27,5,40,6,22,8)) and (not(<expr_cache><`dbt3_s001`.`partsupp`.`ps_suppkey`>(<in_optimizer>(`dbt3_s001`.`partsupp`.`ps_suppkey`,`dbt3_s001`.`partsupp`.`ps_suppkey` in ( <materialize> (select `dbt3_s001`.`supplier`.`s_suppkey` from `dbt3_s001`.`supplier` where (`dbt3_s001`.`supplier`.`s_comment` like '%Customer%Complaints%') ), <primary_index_lookup>(`dbt3_s001`.`partsupp`.`ps_suppkey` in <temporary table> on distinct_key where ((`dbt3_s001`.`partsupp`.`ps_suppkey` = `<subquery2>`.`s_suppkey`))))))))) group by `dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` order by count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) desc,`dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` +select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +p_brand p_type p_size supplier_cnt +Brand#21 MEDIUM ANODIZED TIN 8 4 +Brand#22 PROMO PLATED TIN 5 4 +Brand#24 MEDIUM BURNISHED NICKEL 6 4 +Brand#24 SMALL ANODIZED STEEL 40 4 +Brand#32 MEDIUM BURNISHED BRASS 49 4 +Brand#33 MEDIUM POLISHED BRASS 49 4 +Brand#41 STANDARD BRUSHED NICKEL 40 4 +Brand#44 PROMO POLISHED STEEL 5 4 +Brand#45 PROMO ANODIZED BRASS 22 4 +Brand#53 STANDARD BRUSHED STEEL 27 4 +Brand#54 MEDIUM POLISHED BRASS 22 4 +Brand#54 STANDARD ANODIZED BRASS 22 4 +Brand#13 LARGE BRUSHED STEEL 8 2 +Brand#25 ECONOMY BURNISHED COPPER 27 2 +Brand#44 STANDARD PLATED TIN 37 1 +Brand#51 ECONOMY POLISHED STEEL 49 1 +set optimizer_use_condition_selectivity=4; +EXPLAIN EXTENDED select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 16.67 Using where; Using temporary; Using filesort +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where; Using index +2 MATERIALIZED supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using where +Warnings: +Note 1003 select `dbt3_s001`.`part`.`p_brand` AS `p_brand`,`dbt3_s001`.`part`.`p_type` AS `p_type`,`dbt3_s001`.`part`.`p_size` AS `p_size`,count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) AS `supplier_cnt` from `dbt3_s001`.`partsupp` join `dbt3_s001`.`part` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`part`.`p_brand` <> 'Brand#11') and (not((`dbt3_s001`.`part`.`p_type` like 'SMALL POLISHED%'))) and (`dbt3_s001`.`part`.`p_size` in (49,37,27,5,40,6,22,8)) and (not(<expr_cache><`dbt3_s001`.`partsupp`.`ps_suppkey`>(<in_optimizer>(`dbt3_s001`.`partsupp`.`ps_suppkey`,`dbt3_s001`.`partsupp`.`ps_suppkey` in ( <materialize> (select `dbt3_s001`.`supplier`.`s_suppkey` from `dbt3_s001`.`supplier` where (`dbt3_s001`.`supplier`.`s_comment` like '%Customer%Complaints%') ), <primary_index_lookup>(`dbt3_s001`.`partsupp`.`ps_suppkey` in <temporary table> on distinct_key where ((`dbt3_s001`.`partsupp`.`ps_suppkey` = `<subquery2>`.`s_suppkey`))))))))) group by `dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` order by count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) desc,`dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` +select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +p_brand p_type p_size supplier_cnt +Brand#21 MEDIUM ANODIZED TIN 8 4 +Brand#22 PROMO PLATED TIN 5 4 +Brand#24 MEDIUM BURNISHED NICKEL 6 4 +Brand#24 SMALL ANODIZED STEEL 40 4 +Brand#32 MEDIUM BURNISHED BRASS 49 4 +Brand#33 MEDIUM POLISHED BRASS 49 4 +Brand#41 STANDARD BRUSHED NICKEL 40 4 +Brand#44 PROMO POLISHED STEEL 5 4 +Brand#45 PROMO ANODIZED BRASS 22 4 +Brand#53 STANDARD BRUSHED STEEL 27 4 +Brand#54 MEDIUM POLISHED BRASS 22 4 +Brand#54 STANDARD ANODIZED BRASS 22 4 +Brand#13 LARGE BRUSHED STEEL 8 2 +Brand#25 ECONOMY BURNISHED COPPER 27 2 +Brand#44 STANDARD PLATED TIN 37 1 +Brand#51 ECONOMY POLISHED STEEL 49 1 +=== Q18 === +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select +c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where +o_orderkey in (select l_orderkey from lineitem +group by l_orderkey having sum(l_quantity) > 250) +and c_custkey = o_custkey +and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY orders ALL PRIMARY,i_o_custkey NULL NULL NULL 1500 100.00 Using where; Using temporary; Using filesort +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.orders.o_orderkey 1 100.00 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 100.00 +1 PRIMARY lineitem ref PRIMARY,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey_quantity 4 dbt3_s001.orders.o_orderkey 4 100.00 Using index +2 MATERIALIZED lineitem index NULL i_l_orderkey_quantity 13 NULL 6005 100.00 Using index +Warnings: +Note 1003 select `dbt3_s001`.`customer`.`c_name` AS `c_name`,`dbt3_s001`.`customer`.`c_custkey` AS `c_custkey`,`dbt3_s001`.`orders`.`o_orderkey` AS `o_orderkey`,`dbt3_s001`.`orders`.`o_orderDATE` AS `o_orderdate`,`dbt3_s001`.`orders`.`o_totalprice` AS `o_totalprice`,sum(`dbt3_s001`.`lineitem`.`l_quantity`) AS `sum(l_quantity)` from <materialize> (select `dbt3_s001`.`lineitem`.`l_orderkey` from `dbt3_s001`.`lineitem` group by `dbt3_s001`.`lineitem`.`l_orderkey` having (sum(`dbt3_s001`.`lineitem`.`l_quantity`) > 250)) join `dbt3_s001`.`customer` join `dbt3_s001`.`orders` join `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`customer`.`c_custkey` = `dbt3_s001`.`orders`.`o_custkey`) and (`<subquery2>`.`l_orderkey` = `dbt3_s001`.`orders`.`o_orderkey`) and (`dbt3_s001`.`lineitem`.`l_orderkey` = `dbt3_s001`.`orders`.`o_orderkey`)) group by `dbt3_s001`.`customer`.`c_name`,`dbt3_s001`.`customer`.`c_custkey`,`dbt3_s001`.`orders`.`o_orderkey`,`dbt3_s001`.`orders`.`o_orderDATE`,`dbt3_s001`.`orders`.`o_totalprice` order by `dbt3_s001`.`orders`.`o_totalprice` desc,`dbt3_s001`.`orders`.`o_orderDATE` +select +c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where +o_orderkey in (select l_orderkey from lineitem +group by l_orderkey having sum(l_quantity) > 250) +and c_custkey = o_custkey +and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; +c_name c_custkey o_orderkey o_orderdate o_totalprice sum(l_quantity) +Customer#000000070 70 2567 1998-02-27 263411.29 266 +Customer#000000010 10 4421 1997-04-04 258779.02 255 +Customer#000000082 82 3460 1995-10-03 245976.74 254 +Customer#000000068 68 2208 1995-05-01 245388.06 256 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select +c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where +o_orderkey in (select l_orderkey from lineitem +group by l_orderkey having sum(l_quantity) > 250) +and c_custkey = o_custkey +and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY orders ALL PRIMARY,i_o_custkey NULL NULL NULL 1500 100.00 Using where; Using temporary; Using filesort +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.orders.o_orderkey 1 100.00 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 100.00 +1 PRIMARY lineitem ref PRIMARY,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey_quantity 4 dbt3_s001.orders.o_orderkey 4 100.00 Using index +2 MATERIALIZED lineitem index NULL i_l_orderkey_quantity 13 NULL 6005 100.00 Using index +Warnings: +Note 1003 select `dbt3_s001`.`customer`.`c_name` AS `c_name`,`dbt3_s001`.`customer`.`c_custkey` AS `c_custkey`,`dbt3_s001`.`orders`.`o_orderkey` AS `o_orderkey`,`dbt3_s001`.`orders`.`o_orderDATE` AS `o_orderdate`,`dbt3_s001`.`orders`.`o_totalprice` AS `o_totalprice`,sum(`dbt3_s001`.`lineitem`.`l_quantity`) AS `sum(l_quantity)` from <materialize> (select `dbt3_s001`.`lineitem`.`l_orderkey` from `dbt3_s001`.`lineitem` group by `dbt3_s001`.`lineitem`.`l_orderkey` having (sum(`dbt3_s001`.`lineitem`.`l_quantity`) > 250)) join `dbt3_s001`.`customer` join `dbt3_s001`.`orders` join `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`customer`.`c_custkey` = `dbt3_s001`.`orders`.`o_custkey`) and (`<subquery2>`.`l_orderkey` = `dbt3_s001`.`orders`.`o_orderkey`) and (`dbt3_s001`.`lineitem`.`l_orderkey` = `dbt3_s001`.`orders`.`o_orderkey`)) group by `dbt3_s001`.`customer`.`c_name`,`dbt3_s001`.`customer`.`c_custkey`,`dbt3_s001`.`orders`.`o_orderkey`,`dbt3_s001`.`orders`.`o_orderDATE`,`dbt3_s001`.`orders`.`o_totalprice` order by `dbt3_s001`.`orders`.`o_totalprice` desc,`dbt3_s001`.`orders`.`o_orderDATE` +select +c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where +o_orderkey in (select l_orderkey from lineitem +group by l_orderkey having sum(l_quantity) > 250) +and c_custkey = o_custkey +and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; +c_name c_custkey o_orderkey o_orderdate o_totalprice sum(l_quantity) +Customer#000000070 70 2567 1998-02-27 263411.29 266 +Customer#000000010 10 4421 1997-04-04 258779.02 255 +Customer#000000082 82 3460 1995-10-03 245976.74 254 +Customer#000000068 68 2208 1995-05-01 245388.06 256 +=== Q22 === +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( +select substr(c_phone, 1, 2) as cntrycode, c_acctbal +from customer +where +substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') +and c_acctbal > (select avg(c_acctbal) from customer +where c_acctbal > 0.00 +and substr(c_phone, 1, 2) in +('10', '20', '14', '19', '11', '28', '25')) +and not exists (select * from orders where o_custkey = c_custkey) +) as vip +group by cntrycode +order by cntrycode; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY customer ALL NULL NULL NULL NULL 150 100.00 Using where; Using temporary; Using filesort +4 DEPENDENT SUBQUERY orders ref i_o_custkey i_o_custkey 5 dbt3_s001.customer.c_custkey 15 100.00 Using index +3 SUBQUERY customer ALL NULL NULL NULL NULL 150 100.00 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.customer.c_custkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select substr(`dbt3_s001`.`customer`.`c_phone`,1,2) AS `cntrycode`,count(0) AS `numcust`,sum(`dbt3_s001`.`customer`.`c_acctbal`) AS `totacctbal` from `dbt3_s001`.`customer` where ((substr(`dbt3_s001`.`customer`.`c_phone`,1,2) in ('10','20','14','19','11','28','25')) and (`dbt3_s001`.`customer`.`c_acctbal` > (select avg(`dbt3_s001`.`customer`.`c_acctbal`) from `dbt3_s001`.`customer` where ((`dbt3_s001`.`customer`.`c_acctbal` > 0.00) and (substr(`dbt3_s001`.`customer`.`c_phone`,1,2) in ('10','20','14','19','11','28','25'))))) and (not(exists(select 1 from `dbt3_s001`.`orders` where (`dbt3_s001`.`orders`.`o_custkey` = `dbt3_s001`.`customer`.`c_custkey`))))) group by substr(`dbt3_s001`.`customer`.`c_phone`,1,2) order by substr(`dbt3_s001`.`customer`.`c_phone`,1,2) +select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( +select substr(c_phone, 1, 2) as cntrycode, c_acctbal +from customer +where +substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') +and c_acctbal > (select avg(c_acctbal) from customer +where c_acctbal > 0.00 +and substr(c_phone, 1, 2) in +('10', '20', '14', '19', '11', '28', '25')) +and not exists (select * from orders where o_custkey = c_custkey) +) as vip +group by cntrycode +order by cntrycode; +cntrycode numcust totacctbal +11 4 29942.58 +19 2 17120.35 +20 1 9091.82 +28 2 14755.5 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( +select substr(c_phone, 1, 2) as cntrycode, c_acctbal +from customer +where +substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') +and c_acctbal > (select avg(c_acctbal) from customer +where c_acctbal > 0.00 +and substr(c_phone, 1, 2) in +('10', '20', '14', '19', '11', '28', '25')) +and not exists (select * from orders where o_custkey = c_custkey) +) as vip +group by cntrycode +order by cntrycode; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY customer ALL NULL NULL NULL NULL 150 100.00 Using where; Using temporary; Using filesort +4 DEPENDENT SUBQUERY orders ref i_o_custkey i_o_custkey 5 dbt3_s001.customer.c_custkey 15 100.00 Using index +3 SUBQUERY customer ALL NULL NULL NULL NULL 150 91.00 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.customer.c_custkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select substr(`dbt3_s001`.`customer`.`c_phone`,1,2) AS `cntrycode`,count(0) AS `numcust`,sum(`dbt3_s001`.`customer`.`c_acctbal`) AS `totacctbal` from `dbt3_s001`.`customer` where ((substr(`dbt3_s001`.`customer`.`c_phone`,1,2) in ('10','20','14','19','11','28','25')) and (`dbt3_s001`.`customer`.`c_acctbal` > (select avg(`dbt3_s001`.`customer`.`c_acctbal`) from `dbt3_s001`.`customer` where ((`dbt3_s001`.`customer`.`c_acctbal` > 0.00) and (substr(`dbt3_s001`.`customer`.`c_phone`,1,2) in ('10','20','14','19','11','28','25'))))) and (not(exists(select 1 from `dbt3_s001`.`orders` where (`dbt3_s001`.`orders`.`o_custkey` = `dbt3_s001`.`customer`.`c_custkey`))))) group by substr(`dbt3_s001`.`customer`.`c_phone`,1,2) order by substr(`dbt3_s001`.`customer`.`c_phone`,1,2) +select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( +select substr(c_phone, 1, 2) as cntrycode, c_acctbal +from customer +where +substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') +and c_acctbal > (select avg(c_acctbal) from customer +where c_acctbal > 0.00 +and substr(c_phone, 1, 2) in +('10', '20', '14', '19', '11', '28', '25')) +and not exists (select * from orders where o_custkey = c_custkey) +) as vip +group by cntrycode +order by cntrycode; +cntrycode numcust totacctbal +11 4 29942.58 +19 2 17120.35 +20 1 9091.82 +28 2 14755.5 +=== Q20 === +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 100.00 Using where; Using filesort +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +1 PRIMARY nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where +2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 100.00 Using where +2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 100.00 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +SELECT ((SELECT COUNT(*) FROM part WHERE p_name LIKE 'g%') / +(SELECT COUNT(*) FROM part)) AS sel; +sel +0.0600 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 4.17 Using where +2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 15.14 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +set histogram_size=127; +ANALYZE TABLE part PERSISTENT FOR COLUMNS(p_name) INDEXES(); +Table Op Msg_type Msg_text +dbt3_s001.part analyze status Table is already up to date +flush table part; +set optimizer_use_condition_selectivity=4; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 7.03 Using where +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00 Using where; FirstMatch(supplier) +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 15.14 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +set histogram_type='DOUBLE_PREC_HB'; +set histogram_size=126; +ANALYZE TABLE part PERSISTENT FOR COLUMNS(p_name) INDEXES(); +Table Op Msg_type Msg_text +dbt3_s001.part analyze status Table is already up to date +flush table part; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 7.81 Using where +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00 Using where; FirstMatch(supplier) +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 15.14 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +set histogram_type='SINGLE_PREC_HB'; +set histogram_size=24; +ANALYZE TABLE nation PERSISTENT FOR COLUMNS(n_name) INDEXES(); +Table Op Msg_type Msg_text +dbt3_s001.nation analyze status Table is already up to date +flush table nation; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 7.81 Using where +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00 Using where; FirstMatch(supplier) +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 15.14 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +DROP DATABASE dbt3_s001; +set histogram_type=@save_histogram_type; +set histogram_size=@save_histogram_size; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +use test; +# +# Bug mdev-4348: using view with use_condition_selectivity > 1 +# +set @tmp_use_stat_tables=@@use_stat_tables; +set use_stat_tables='never'; +set optimizer_use_condition_selectivity=3; +CREATE TABLE t1 (a int, b int); +INSERT t1 VALUES (7,1), (0,7); +CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1; +CREATE TABLE t2 (c int, d int, index idx(d)); +INSERT INTO t2 VALUES +(0,4), (8,6), (1,3), (8,5), (9,3), (2,2), (6,2), +(1,9), (6,3), (2,8), (4,1), (0,7), (4,8), (4,5); +EXPLAIN EXTENDED +SELECT * FROM v1 INNER JOIN t2 ON ( a = c AND b = d ); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +1 SIMPLE t2 ref idx idx 5 test.t1.b 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`c` = `test`.`t1`.`a`) and (`test`.`t2`.`d` = `test`.`t1`.`b`)) +SELECT * FROM v1 INNER JOIN t2 ON ( a = c AND b = d ); +a b c d +0 7 0 7 +DROP VIEW v1; +DROP TABLE t1,t2; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +set use_stat_tables=@tmp_use_stat_tables; +# +# Bug mdev-4349: impossible range for non-indexed column +# +set optimizer_use_condition_selectivity=3; +create table t1 (a int); +insert into t1 values +(3), (7), (2), (5), (7), (1), (2), (2); +set optimizer_use_condition_selectivity=1; +explain extended +select * from t1 where a < 1 and a > 7; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` < 1) and (`test`.`t1`.`a` > 7)) +select * from t1 where a < 1 and a > 7; +a +set optimizer_use_condition_selectivity=3; +explain extended +select * from t1 where a < 1 and a > 7; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0 +select * from t1 where a < 1 and a > 7; +a +drop table t1; +create table t1 (a int); +insert into t1 values (1); +create table t2 (b int); +insert into t2 values (2),(3); +explain extended +select * from t1 where a in ( select b from t2 ) AND ( a > 3 ); +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 noticed after reading const tables +Warnings: +Note 1003 select 1 AS `a` from (`test`.`t2`) where 0 +select * from t1 where a in ( select b from t2 ) AND ( a > 3 ); +a +drop table t1,t2; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +# +# Bug mdev-4350: erroneous negative selectivity +# +create table t1 (a int); +insert into t1 values (1), (1); +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 values (0); +select count(*) from t1; +count(*) +1025 +set use_stat_tables='preferably'; +set histogram_size=127; +set histogram_type='SINGLE_PREC_HB'; +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +flush table t1; +set optimizer_use_condition_selectivity=4; +explain extended select * from t1 where a=0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 1025 49.61 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 0) +drop table t1; +set histogram_size=@save_histogram_size; +set histogram_type=@save_histogram_type; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +# +# Bug mdev-4367: 2-way join with an empty table +# when optimizer_use_condition_selectivity=3 +# +set optimizer_use_condition_selectivity=3; +CREATE TABLE t1 (a varchar(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('j'),('k'); +CREATE TABLE t2 (b varchar(1)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('x'),('y'); +CREATE TABLE t3 (c varchar(1), KEY(c)) ENGINE=MyISAM; +SELECT * FROM t1 STRAIGHT_JOIN (t2 JOIN t3 ON c = b AND b > 'z'); +a b c +DROP TABLE t1,t2,t3; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +# +# Bug mdev-4366: impossible condition on an indexed column discovered after +# substitution of constant tables +# with optimizer_use_condition_selectivity=3 +# +CREATE TABLE t1 (pk int PRIMARY KEY, a int); +INSERT INTO t1 VALUES +(1,4), (2,6), (3,3), (4,5); +CREATE TABLE t2 (b int); +INSERT INTO t2 VALUES (1), (7); +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select 1 AS `1` from `test`.`t1` join `test`.`t2` where 0 +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; +1 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select 1 AS `1` from `test`.`t1` join `test`.`t2` where 0 +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; +1 +DROP TABLE t1,t2; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +# +# Bug mdev-4370: Histograms have bean created, but the query is run after +# FLUSH TABLES with optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +set histogram_size=10; +set histogram_type='SINGLE_PREC_HB'; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (9), (1); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a > 3; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 75.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 3) +SELECT * FROM t1 WHERE a > 3; +a +9 +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1; +set histogram_size=@save_histogram_size; +set histogram_type=@save_histogram_type; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4371: Join with condition supported by index on an empty table +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (a int, b int, INDEX(a)); +CREATE TABLE t2 (c int); +INSERT INTO t2 VALUES (1),(2),(3),(4),(5),(6),(7),(8); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +test.t2 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +EXPLAIN EXTENDED +SELECT * FROM t1, t2 WHERE a > 9; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select NULL AS `a`,NULL AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where 0 +SELECT * FROM t1, t2 WHERE a > 9; +a b c +set optimizer_switch=@save_optimizer_switch; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4373: condition on a short varchar column +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (a varchar(1)); +INSERT INTO t1 VALUES ('x'), ('y'); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +SELECT * FROM t1 WHERE a <= 'w'; +a +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4372: exists subquery in WHERE +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables = PREFERABLY; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES +(1),(7),(4),(7),(0),(2),(9),(4),(0),(9),(1),(3),(8),(8); +CREATE TABLE t2 (b int); +INSERT INTO t2 VALUES (4),(5),(2),(5),(1),(1),(2); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT * FROM t1, t2 WHERE EXISTS ( SELECT 1 FROM t1, t2 ) AND a != b OR a <= 4; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 7 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 14 100.00 Using where; Using join buffer (flat, BNL join) +2 SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 14 100.00 Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where ((exists(select 1 from `test`.`t1` join `test`.`t2`) and (`test`.`t1`.`a` <> `test`.`t2`.`b`)) or (`test`.`t1`.`a` <= 4)) +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4363: selectivity of the condition a IS NULL OR IS NOT NULL +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables = PREFERABLY; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES +(1),(7),(4),(7),(NULL),(2),(NULL),(4),(NULL),(NULL),(1),(3),(8),(8); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +FLUSH TABLE t1; +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 28.57 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where isnull(`test`.`t1`.`a`) +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NOT NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 71.43 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` is not null) +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NULL OR a IS NOT NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (isnull(`test`.`t1`.`a`) or (`test`.`t1`.`a` is not null)) +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NULL OR a < 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 69.39 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (isnull(`test`.`t1`.`a`) or (`test`.`t1`.`a` < 5)) +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4378: 2-way join with a materialized IN subquery in WHERE +# when optimizer_use_condition_selectivity=4 +# +set use_stat_tables=PREFERABLY; +set histogram_size=50; +set histogram_type=SINGLE_PREC_HB; +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (8),(9),(6); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (8),(1),(8),(9),(24),(6),(1),(6),(2),(4); +CREATE TABLE t3 (ln VARCHAR(16)) ENGINE=MyISAM; +INSERT INTO t3 VALUES +('smith'),('black'),('white'),('jones'), +('brown'),('taylor'),('anderson'),('taylor'); +ANALYZE TABLE t1, t2, t3; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +test.t3 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=4; +SELECT * FROM t1, t2 WHERE 'garcia' IN ( SELECT MIN( ln ) FROM t3 WHERE ln = 'sun' ); +a b +set histogram_size=@save_histogram_size; +set histogram_type=@save_histogram_type; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2,t3; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4380: 2-way join with a materialized IN subquery in WHERE +# when optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (5),(9); +CREATE TABLE t2 (b VARCHAR(8)); +INSERT INTO t2 VALUES ('red'),('blue'); +CREATE TABLE t3 (c VARCHAR(8), d VARCHAR(8)); +INSERT INTO t3 VALUES ('white','black'),('cyan','yellow'); +ANALYZE TABLE t1, t2, t3; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +test.t3 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +SELECT * FROM t1, t2 WHERE ( 'orange', 'green' ) IN ( +SELECT MAX(c), MAX(d) FROM t3, t2 WHERE c >= d AND b = c +); +a b +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2,t3; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4389: join with degenerated range condition in WHERE +# when optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (f1 VARCHAR(1)); +INSERT t1 VALUES ('p'),('q'); +CREATE TABLE t2 (f2 VARCHAR(1)); +INSERT INTO t2 VALUES +('o'),('v'),('f'),('f'),('e'),('l'),('j'),('p'),('r'),('j'), +('j'),('u'),('i'),('r'),('x'),('a'),('x'),('s'); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +FLUSH TABLES; +SET optimizer_use_condition_selectivity=3; +SELECT * FROM t1, t2 AS t2a, t2 AS t2b WHERE f1 <= 'a' AND t2a.f2 = f1; +f1 f2 f2 +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4406: range condition for non-nullable column +# when optimizer_use_condition_selectivity=3 +# +create table t1 (a int not null); +insert into t1 values +(7), (6), (4), (9), (1), (5), (2), (1), (3), (8); +set use_stat_tables='preferably'; +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +flush table t1; +set optimizer_use_condition_selectivity=3; +select count(*) from t1 where a between 5 and 7; +count(*) +3 +explain extended select * from t1 where a between 5 and 7; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 25.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` between 5 and 7) +alter table t1 change column a a int; +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +flush table t1; +explain extended select * from t1 where a between 5 and 7; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 25.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` between 5 and 7) +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +drop table t1; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-5200: impossible where with a semijoin subquery +# when optimizer_use_condition_selectivity=2 +# +set use_stat_tables = 'preferably'; +set optimizer_use_condition_selectivity = 2; +CREATE TABLE t1 (i1 int) ENGINE=MyISAM; +INSERT INTO t1 VALUES (0), (1); +CREATE TABLE t2 (pk2 int, i2 int, c2 char(1), PRIMARY KEY(pk2)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,8,'m'), (2,9,'b'); +CREATE TABLE t3 (c3 char(1), INDEX(c3)) ENGINE=MyISAM; +INSERT INTO t3 VALUES ('v'), ('c'); +ANALYZE TABLE t1,t2,t3; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +test.t3 analyze status OK +SELECT * FROM t1 +WHERE 2 IN ( SELECT pk2 FROM t2 LEFT JOIN t3 ON (c3 = c2 ) WHERE i2 = 3 ); +i1 +EXPLAIN EXTENDED +SELECT * FROM t1 +WHERE 2 IN ( SELECT pk2 FROM t2 LEFT JOIN t3 ON (c3 = c2 ) WHERE i2 = 3 ); +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 noticed after reading const tables +Warnings: +Note 1003 select `test`.`t1`.`i1` AS `i1` from `test`.`t1` semi join (`test`.`t2` left join `test`.`t3` on((`test`.`t3`.`c3` = 'b'))) where 0 +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2,t3; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-5415: query over an information schema table +# when optimizer_use_condition_selectivity=3 +# +set optimizer_use_condition_selectivity = 3; +SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE SQL_MODE != ''; +TRIGGER_CATALOG TRIGGER_SCHEMA TRIGGER_NAME EVENT_MANIPULATION EVENT_OBJECT_CATALOG EVENT_OBJECT_SCHEMA EVENT_OBJECT_TABLE ACTION_ORDER ACTION_CONDITION ACTION_STATEMENT ACTION_ORIENTATION ACTION_TIMING ACTION_REFERENCE_OLD_TABLE ACTION_REFERENCE_NEW_TABLE ACTION_REFERENCE_OLD_ROW ACTION_REFERENCE_NEW_ROW CREATED SQL_MODE DEFINER CHARACTER_SET_CLIENT COLLATION_CONNECTION DATABASE_COLLATION +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; diff --git a/mysql-test/r/selectivity_innodb.result b/mysql-test/r/selectivity_innodb.result new file mode 100644 index 00000000000..f4485cb0f73 --- /dev/null +++ b/mysql-test/r/selectivity_innodb.result @@ -0,0 +1,1178 @@ +SET SESSION STORAGE_ENGINE='InnoDB'; +set @save_optimizer_switch_for_selectivity_test=@@optimizer_switch; +set optimizer_switch='extended_keys=on'; +select @@global.use_stat_tables; +@@global.use_stat_tables +COMPLEMENTARY +select @@session.use_stat_tables; +@@session.use_stat_tables +COMPLEMENTARY +set @save_use_stat_tables=@@use_stat_tables; +set use_stat_tables='preferably'; +set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity; +set @save_histogram_size=@@histogram_size; +set @save_histogram_type=@@histogram_type; +set optimizer_use_condition_selectivity=3; +create table t1 (a int); +insert into t1 values +(9), (3), (2), (NULL), (NULL), (2), (NULL), (1), (5), (NULL); +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +select * from mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 1 9 0.4000 4.0000 1.2000 0 NULL NULL +flush table t1; +explain extended +select * from t1 where a is null; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 40.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where isnull(`test`.`t1`.`a`) +explain extended +select * from t1 where a is not null; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 60.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` is not null) +drop table t1; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +=== Q2 === +set optimizer_use_condition_selectivity=5; +explain extended +select +s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment +from +part, supplier, partsupp, nation, region +where +p_partkey = ps_partkey +and s_suppkey = ps_suppkey +and p_size = 9 +and p_type like '%TIN' + and s_nationkey = n_nationkey +and n_regionkey = r_regionkey +and r_name = 'ASIA' + and ps_supplycost = ( +select +min(ps_supplycost) +from +partsupp, supplier, nation, region +where +p_partkey = ps_partkey +and s_suppkey = ps_suppkey +and s_nationkey = n_nationkey +and n_regionkey = r_regionkey +and r_name = 'ASIA' + ) +order by +s_acctbal desc, n_name, s_name, p_partkey; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 0.31 Using where; Using temporary; Using filesort +1 PRIMARY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 80.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where +2 DEPENDENT SUBQUERY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where +2 DEPENDENT SUBQUERY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 +2 DEPENDENT SUBQUERY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where +2 DEPENDENT SUBQUERY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.part.p_partkey' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`part`.`p_size` = 9) and (`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey`) and (`dbt3_s001`.`region`.`r_name` = 'ASIA') and (`dbt3_s001`.`part`.`p_type` like '%TIN') and (`dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where ((`dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey`) and (`dbt3_s001`.`region`.`r_name` = 'ASIA') and (`dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)))))) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey` +set optimizer_use_condition_selectivity=4; +explain extended +select +s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment +from +part, supplier, partsupp, nation, region +where +p_partkey = ps_partkey +and s_suppkey = ps_suppkey +and p_size = 9 +and p_type like '%TIN' + and s_nationkey = n_nationkey +and n_regionkey = r_regionkey +and r_name = 'ASIA' + and ps_supplycost = ( +select +min(ps_supplycost) +from +partsupp, supplier, nation, region +where +p_partkey = ps_partkey +and s_suppkey = ps_suppkey +and s_nationkey = n_nationkey +and n_regionkey = r_regionkey +and r_name = 'ASIA' + ) +order by +s_acctbal desc, n_name, s_name, p_partkey; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where; Using temporary; Using filesort +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 2.08 Using where; Using join buffer (flat, BNL join) +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 80.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where +2 DEPENDENT SUBQUERY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where +2 DEPENDENT SUBQUERY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 +2 DEPENDENT SUBQUERY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where +2 DEPENDENT SUBQUERY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.part.p_partkey' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`part`.`p_size` = 9) and (`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey`) and (`dbt3_s001`.`region`.`r_name` = 'ASIA') and (`dbt3_s001`.`part`.`p_type` like '%TIN') and (`dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where ((`dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey`) and (`dbt3_s001`.`region`.`r_name` = 'ASIA') and (`dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)))))) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey` +=== Q15 === +create view revenue0 (supplier_no, total_revenue) as +select l_suppkey, sum(l_extendedprice * (1 - l_discount)) +from lineitem +where +l_shipdate >= '1995-08-01' + and l_shipdate < date_add('1995-08-01', interval 90 day) +group by l_suppkey; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no +and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY supplier index PRIMARY PRIMARY 4 NULL 10 100.00 +1 PRIMARY <derived3> ref key0 key0 5 dbt3_s001.supplier.s_suppkey 10 100.00 Using where +3 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 228 100.00 Using where; Using temporary; Using filesort +2 SUBQUERY <derived4> ALL NULL NULL NULL NULL 228 100.00 +4 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 228 100.00 Using where; Using temporary; Using filesort +Warnings: +Note 1003 select `dbt3_s001`.`supplier`.`s_suppkey` AS `s_suppkey`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`revenue0`.`total_revenue` AS `total_revenue` from `dbt3_s001`.`supplier` join `dbt3_s001`.`revenue0` where ((`revenue0`.`supplier_no` = `dbt3_s001`.`supplier`.`s_suppkey`) and (`revenue0`.`total_revenue` = (select max(`revenue0`.`total_revenue`) from `dbt3_s001`.`revenue0`))) order by `dbt3_s001`.`supplier`.`s_suppkey` +select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no +and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; +s_suppkey s_name s_address s_phone total_revenue +1 Supplier#000000001 N kD4on9OM Ipw3,gf0JBoQDd7tgrzrddZ 27-918-335-1736 729084.7773 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no +and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY supplier index PRIMARY PRIMARY 4 NULL 10 100.00 +1 PRIMARY <derived3> ref key0 key0 5 dbt3_s001.supplier.s_suppkey 10 100.00 Using where +3 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 228 100.00 Using where; Using temporary; Using filesort +2 SUBQUERY <derived4> ALL NULL NULL NULL NULL 228 100.00 +4 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 228 100.00 Using where; Using temporary; Using filesort +Warnings: +Note 1003 select `dbt3_s001`.`supplier`.`s_suppkey` AS `s_suppkey`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`revenue0`.`total_revenue` AS `total_revenue` from `dbt3_s001`.`supplier` join `dbt3_s001`.`revenue0` where ((`revenue0`.`supplier_no` = `dbt3_s001`.`supplier`.`s_suppkey`) and (`revenue0`.`total_revenue` = (select max(`revenue0`.`total_revenue`) from `dbt3_s001`.`revenue0`))) order by `dbt3_s001`.`supplier`.`s_suppkey` +select s_suppkey, s_name, s_address, s_phone, total_revenue +from supplier, revenue0 +where s_suppkey = supplier_no +and total_revenue = (select max(total_revenue) from revenue0) +order by s_suppkey; +s_suppkey s_name s_address s_phone total_revenue +1 Supplier#000000001 N kD4on9OM Ipw3,gf0JBoQDd7tgrzrddZ 27-918-335-1736 729084.7773 +set optimizer_switch=@save_optimizer_switch; +drop view revenue0; +=== Q16 === +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 100.00 Using where; Using temporary; Using filesort +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00 Using where; Using index +2 MATERIALIZED supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using where +Warnings: +Note 1003 select `dbt3_s001`.`part`.`p_brand` AS `p_brand`,`dbt3_s001`.`part`.`p_type` AS `p_type`,`dbt3_s001`.`part`.`p_size` AS `p_size`,count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) AS `supplier_cnt` from `dbt3_s001`.`partsupp` join `dbt3_s001`.`part` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`part`.`p_brand` <> 'Brand#11') and (not((`dbt3_s001`.`part`.`p_type` like 'SMALL POLISHED%'))) and (`dbt3_s001`.`part`.`p_size` in (49,37,27,5,40,6,22,8)) and (not(<expr_cache><`dbt3_s001`.`partsupp`.`ps_suppkey`>(<in_optimizer>(`dbt3_s001`.`partsupp`.`ps_suppkey`,`dbt3_s001`.`partsupp`.`ps_suppkey` in ( <materialize> (select `dbt3_s001`.`supplier`.`s_suppkey` from `dbt3_s001`.`supplier` where (`dbt3_s001`.`supplier`.`s_comment` like '%Customer%Complaints%') ), <primary_index_lookup>(`dbt3_s001`.`partsupp`.`ps_suppkey` in <temporary table> on distinct_key where ((`dbt3_s001`.`partsupp`.`ps_suppkey` = `<subquery2>`.`s_suppkey`))))))))) group by `dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` order by count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) desc,`dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` +select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +p_brand p_type p_size supplier_cnt +Brand#21 MEDIUM ANODIZED TIN 8 4 +Brand#22 PROMO PLATED TIN 5 4 +Brand#24 MEDIUM BURNISHED NICKEL 6 4 +Brand#24 SMALL ANODIZED STEEL 40 4 +Brand#32 MEDIUM BURNISHED BRASS 49 4 +Brand#33 MEDIUM POLISHED BRASS 49 4 +Brand#41 STANDARD BRUSHED NICKEL 40 4 +Brand#44 PROMO POLISHED STEEL 5 4 +Brand#45 PROMO ANODIZED BRASS 22 4 +Brand#53 STANDARD BRUSHED STEEL 27 4 +Brand#54 MEDIUM POLISHED BRASS 22 4 +Brand#54 STANDARD ANODIZED BRASS 22 4 +Brand#13 LARGE BRUSHED STEEL 8 2 +Brand#25 ECONOMY BURNISHED COPPER 27 2 +Brand#44 STANDARD PLATED TIN 37 1 +Brand#51 ECONOMY POLISHED STEEL 49 1 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 16.67 Using where; Using temporary; Using filesort +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00 Using where; Using index +2 MATERIALIZED supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using where +Warnings: +Note 1003 select `dbt3_s001`.`part`.`p_brand` AS `p_brand`,`dbt3_s001`.`part`.`p_type` AS `p_type`,`dbt3_s001`.`part`.`p_size` AS `p_size`,count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) AS `supplier_cnt` from `dbt3_s001`.`partsupp` join `dbt3_s001`.`part` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`part`.`p_brand` <> 'Brand#11') and (not((`dbt3_s001`.`part`.`p_type` like 'SMALL POLISHED%'))) and (`dbt3_s001`.`part`.`p_size` in (49,37,27,5,40,6,22,8)) and (not(<expr_cache><`dbt3_s001`.`partsupp`.`ps_suppkey`>(<in_optimizer>(`dbt3_s001`.`partsupp`.`ps_suppkey`,`dbt3_s001`.`partsupp`.`ps_suppkey` in ( <materialize> (select `dbt3_s001`.`supplier`.`s_suppkey` from `dbt3_s001`.`supplier` where (`dbt3_s001`.`supplier`.`s_comment` like '%Customer%Complaints%') ), <primary_index_lookup>(`dbt3_s001`.`partsupp`.`ps_suppkey` in <temporary table> on distinct_key where ((`dbt3_s001`.`partsupp`.`ps_suppkey` = `<subquery2>`.`s_suppkey`))))))))) group by `dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` order by count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) desc,`dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` +select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +p_brand p_type p_size supplier_cnt +Brand#21 MEDIUM ANODIZED TIN 8 4 +Brand#22 PROMO PLATED TIN 5 4 +Brand#24 MEDIUM BURNISHED NICKEL 6 4 +Brand#24 SMALL ANODIZED STEEL 40 4 +Brand#32 MEDIUM BURNISHED BRASS 49 4 +Brand#33 MEDIUM POLISHED BRASS 49 4 +Brand#41 STANDARD BRUSHED NICKEL 40 4 +Brand#44 PROMO POLISHED STEEL 5 4 +Brand#45 PROMO ANODIZED BRASS 22 4 +Brand#53 STANDARD BRUSHED STEEL 27 4 +Brand#54 MEDIUM POLISHED BRASS 22 4 +Brand#54 STANDARD ANODIZED BRASS 22 4 +Brand#13 LARGE BRUSHED STEEL 8 2 +Brand#25 ECONOMY BURNISHED COPPER 27 2 +Brand#44 STANDARD PLATED TIN 37 1 +Brand#51 ECONOMY POLISHED STEEL 49 1 +set optimizer_use_condition_selectivity=4; +EXPLAIN EXTENDED select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 16.67 Using where; Using temporary; Using filesort +1 PRIMARY partsupp ref PRIMARY,i_ps_partkey i_ps_partkey 4 dbt3_s001.part.p_partkey 3 100.00 Using where; Using index +2 MATERIALIZED supplier ALL PRIMARY NULL NULL NULL 10 100.00 Using where +Warnings: +Note 1003 select `dbt3_s001`.`part`.`p_brand` AS `p_brand`,`dbt3_s001`.`part`.`p_type` AS `p_type`,`dbt3_s001`.`part`.`p_size` AS `p_size`,count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) AS `supplier_cnt` from `dbt3_s001`.`partsupp` join `dbt3_s001`.`part` where ((`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`part`.`p_brand` <> 'Brand#11') and (not((`dbt3_s001`.`part`.`p_type` like 'SMALL POLISHED%'))) and (`dbt3_s001`.`part`.`p_size` in (49,37,27,5,40,6,22,8)) and (not(<expr_cache><`dbt3_s001`.`partsupp`.`ps_suppkey`>(<in_optimizer>(`dbt3_s001`.`partsupp`.`ps_suppkey`,`dbt3_s001`.`partsupp`.`ps_suppkey` in ( <materialize> (select `dbt3_s001`.`supplier`.`s_suppkey` from `dbt3_s001`.`supplier` where (`dbt3_s001`.`supplier`.`s_comment` like '%Customer%Complaints%') ), <primary_index_lookup>(`dbt3_s001`.`partsupp`.`ps_suppkey` in <temporary table> on distinct_key where ((`dbt3_s001`.`partsupp`.`ps_suppkey` = `<subquery2>`.`s_suppkey`))))))))) group by `dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` order by count(distinct `dbt3_s001`.`partsupp`.`ps_suppkey`) desc,`dbt3_s001`.`part`.`p_brand`,`dbt3_s001`.`part`.`p_type`,`dbt3_s001`.`part`.`p_size` +select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt +from partsupp, part +where p_partkey = ps_partkey +and p_brand <> 'Brand#11' + and p_type not like 'SMALL POLISHED%' + and p_size in (49, 37, 27, 5, 40, 6, 22, 8) +and ps_suppkey not in (select s_suppkey from supplier +where s_comment like '%Customer%Complaints%') +group by p_brand, p_type, p_size +order by supplier_cnt desc, p_brand, p_type, p_size; +p_brand p_type p_size supplier_cnt +Brand#21 MEDIUM ANODIZED TIN 8 4 +Brand#22 PROMO PLATED TIN 5 4 +Brand#24 MEDIUM BURNISHED NICKEL 6 4 +Brand#24 SMALL ANODIZED STEEL 40 4 +Brand#32 MEDIUM BURNISHED BRASS 49 4 +Brand#33 MEDIUM POLISHED BRASS 49 4 +Brand#41 STANDARD BRUSHED NICKEL 40 4 +Brand#44 PROMO POLISHED STEEL 5 4 +Brand#45 PROMO ANODIZED BRASS 22 4 +Brand#53 STANDARD BRUSHED STEEL 27 4 +Brand#54 MEDIUM POLISHED BRASS 22 4 +Brand#54 STANDARD ANODIZED BRASS 22 4 +Brand#13 LARGE BRUSHED STEEL 8 2 +Brand#25 ECONOMY BURNISHED COPPER 27 2 +Brand#44 STANDARD PLATED TIN 37 1 +Brand#51 ECONOMY POLISHED STEEL 49 1 +=== Q18 === +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select +c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where +o_orderkey in (select l_orderkey from lineitem +group by l_orderkey having sum(l_quantity) > 250) +and c_custkey = o_custkey +and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY orders ALL PRIMARY,i_o_custkey NULL NULL NULL 1500 100.00 Using where; Using temporary; Using filesort +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.orders.o_orderkey 1 100.00 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 100.00 +1 PRIMARY lineitem ref PRIMARY,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey_quantity 4 dbt3_s001.orders.o_orderkey 4 100.00 Using index +2 MATERIALIZED lineitem index NULL PRIMARY 8 NULL 6005 100.00 +Warnings: +Note 1003 select `dbt3_s001`.`customer`.`c_name` AS `c_name`,`dbt3_s001`.`customer`.`c_custkey` AS `c_custkey`,`dbt3_s001`.`orders`.`o_orderkey` AS `o_orderkey`,`dbt3_s001`.`orders`.`o_orderDATE` AS `o_orderdate`,`dbt3_s001`.`orders`.`o_totalprice` AS `o_totalprice`,sum(`dbt3_s001`.`lineitem`.`l_quantity`) AS `sum(l_quantity)` from <materialize> (select `dbt3_s001`.`lineitem`.`l_orderkey` from `dbt3_s001`.`lineitem` group by `dbt3_s001`.`lineitem`.`l_orderkey` having (sum(`dbt3_s001`.`lineitem`.`l_quantity`) > 250)) join `dbt3_s001`.`customer` join `dbt3_s001`.`orders` join `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`customer`.`c_custkey` = `dbt3_s001`.`orders`.`o_custkey`) and (`<subquery2>`.`l_orderkey` = `dbt3_s001`.`orders`.`o_orderkey`) and (`dbt3_s001`.`lineitem`.`l_orderkey` = `dbt3_s001`.`orders`.`o_orderkey`)) group by `dbt3_s001`.`customer`.`c_name`,`dbt3_s001`.`customer`.`c_custkey`,`dbt3_s001`.`orders`.`o_orderkey`,`dbt3_s001`.`orders`.`o_orderDATE`,`dbt3_s001`.`orders`.`o_totalprice` order by `dbt3_s001`.`orders`.`o_totalprice` desc,`dbt3_s001`.`orders`.`o_orderDATE` +select +c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where +o_orderkey in (select l_orderkey from lineitem +group by l_orderkey having sum(l_quantity) > 250) +and c_custkey = o_custkey +and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; +c_name c_custkey o_orderkey o_orderdate o_totalprice sum(l_quantity) +Customer#000000070 70 2567 1998-02-27 263411.29 266 +Customer#000000010 10 4421 1997-04-04 258779.02 255 +Customer#000000082 82 3460 1995-10-03 245976.74 254 +Customer#000000068 68 2208 1995-05-01 245388.06 256 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select +c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where +o_orderkey in (select l_orderkey from lineitem +group by l_orderkey having sum(l_quantity) > 250) +and c_custkey = o_custkey +and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY orders ALL PRIMARY,i_o_custkey NULL NULL NULL 1500 100.00 Using where; Using temporary; Using filesort +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 dbt3_s001.orders.o_orderkey 1 100.00 +1 PRIMARY customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 100.00 +1 PRIMARY lineitem ref PRIMARY,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey_quantity 4 dbt3_s001.orders.o_orderkey 4 100.00 Using index +2 MATERIALIZED lineitem index NULL PRIMARY 8 NULL 6005 100.00 +Warnings: +Note 1003 select `dbt3_s001`.`customer`.`c_name` AS `c_name`,`dbt3_s001`.`customer`.`c_custkey` AS `c_custkey`,`dbt3_s001`.`orders`.`o_orderkey` AS `o_orderkey`,`dbt3_s001`.`orders`.`o_orderDATE` AS `o_orderdate`,`dbt3_s001`.`orders`.`o_totalprice` AS `o_totalprice`,sum(`dbt3_s001`.`lineitem`.`l_quantity`) AS `sum(l_quantity)` from <materialize> (select `dbt3_s001`.`lineitem`.`l_orderkey` from `dbt3_s001`.`lineitem` group by `dbt3_s001`.`lineitem`.`l_orderkey` having (sum(`dbt3_s001`.`lineitem`.`l_quantity`) > 250)) join `dbt3_s001`.`customer` join `dbt3_s001`.`orders` join `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`customer`.`c_custkey` = `dbt3_s001`.`orders`.`o_custkey`) and (`<subquery2>`.`l_orderkey` = `dbt3_s001`.`orders`.`o_orderkey`) and (`dbt3_s001`.`lineitem`.`l_orderkey` = `dbt3_s001`.`orders`.`o_orderkey`)) group by `dbt3_s001`.`customer`.`c_name`,`dbt3_s001`.`customer`.`c_custkey`,`dbt3_s001`.`orders`.`o_orderkey`,`dbt3_s001`.`orders`.`o_orderDATE`,`dbt3_s001`.`orders`.`o_totalprice` order by `dbt3_s001`.`orders`.`o_totalprice` desc,`dbt3_s001`.`orders`.`o_orderDATE` +select +c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, sum(l_quantity) +from customer, orders, lineitem +where +o_orderkey in (select l_orderkey from lineitem +group by l_orderkey having sum(l_quantity) > 250) +and c_custkey = o_custkey +and o_orderkey = l_orderkey +group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice +order by o_totalprice desc, o_orderdate; +c_name c_custkey o_orderkey o_orderdate o_totalprice sum(l_quantity) +Customer#000000070 70 2567 1998-02-27 263411.29 266 +Customer#000000010 10 4421 1997-04-04 258779.02 255 +Customer#000000082 82 3460 1995-10-03 245976.74 254 +Customer#000000068 68 2208 1995-05-01 245388.06 256 +=== Q22 === +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( +select substr(c_phone, 1, 2) as cntrycode, c_acctbal +from customer +where +substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') +and c_acctbal > (select avg(c_acctbal) from customer +where c_acctbal > 0.00 +and substr(c_phone, 1, 2) in +('10', '20', '14', '19', '11', '28', '25')) +and not exists (select * from orders where o_custkey = c_custkey) +) as vip +group by cntrycode +order by cntrycode; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY customer ALL NULL NULL NULL NULL 150 100.00 Using where; Using temporary; Using filesort +4 DEPENDENT SUBQUERY orders ref i_o_custkey i_o_custkey 5 dbt3_s001.customer.c_custkey 15 100.00 Using index +3 SUBQUERY customer ALL NULL NULL NULL NULL 150 100.00 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.customer.c_custkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select substr(`dbt3_s001`.`customer`.`c_phone`,1,2) AS `cntrycode`,count(0) AS `numcust`,sum(`dbt3_s001`.`customer`.`c_acctbal`) AS `totacctbal` from `dbt3_s001`.`customer` where ((substr(`dbt3_s001`.`customer`.`c_phone`,1,2) in ('10','20','14','19','11','28','25')) and (`dbt3_s001`.`customer`.`c_acctbal` > (select avg(`dbt3_s001`.`customer`.`c_acctbal`) from `dbt3_s001`.`customer` where ((`dbt3_s001`.`customer`.`c_acctbal` > 0.00) and (substr(`dbt3_s001`.`customer`.`c_phone`,1,2) in ('10','20','14','19','11','28','25'))))) and (not(exists(select 1 from `dbt3_s001`.`orders` where (`dbt3_s001`.`orders`.`o_custkey` = `dbt3_s001`.`customer`.`c_custkey`))))) group by substr(`dbt3_s001`.`customer`.`c_phone`,1,2) order by substr(`dbt3_s001`.`customer`.`c_phone`,1,2) +select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( +select substr(c_phone, 1, 2) as cntrycode, c_acctbal +from customer +where +substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') +and c_acctbal > (select avg(c_acctbal) from customer +where c_acctbal > 0.00 +and substr(c_phone, 1, 2) in +('10', '20', '14', '19', '11', '28', '25')) +and not exists (select * from orders where o_custkey = c_custkey) +) as vip +group by cntrycode +order by cntrycode; +cntrycode numcust totacctbal +11 4 29942.58 +19 2 17120.35 +20 1 9091.82 +28 2 14755.5 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( +select substr(c_phone, 1, 2) as cntrycode, c_acctbal +from customer +where +substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') +and c_acctbal > (select avg(c_acctbal) from customer +where c_acctbal > 0.00 +and substr(c_phone, 1, 2) in +('10', '20', '14', '19', '11', '28', '25')) +and not exists (select * from orders where o_custkey = c_custkey) +) as vip +group by cntrycode +order by cntrycode; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY customer ALL NULL NULL NULL NULL 150 100.00 Using where; Using temporary; Using filesort +4 DEPENDENT SUBQUERY orders ref i_o_custkey i_o_custkey 5 dbt3_s001.customer.c_custkey 15 100.00 Using index +3 SUBQUERY customer ALL NULL NULL NULL NULL 150 91.00 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.customer.c_custkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select substr(`dbt3_s001`.`customer`.`c_phone`,1,2) AS `cntrycode`,count(0) AS `numcust`,sum(`dbt3_s001`.`customer`.`c_acctbal`) AS `totacctbal` from `dbt3_s001`.`customer` where ((substr(`dbt3_s001`.`customer`.`c_phone`,1,2) in ('10','20','14','19','11','28','25')) and (`dbt3_s001`.`customer`.`c_acctbal` > (select avg(`dbt3_s001`.`customer`.`c_acctbal`) from `dbt3_s001`.`customer` where ((`dbt3_s001`.`customer`.`c_acctbal` > 0.00) and (substr(`dbt3_s001`.`customer`.`c_phone`,1,2) in ('10','20','14','19','11','28','25'))))) and (not(exists(select 1 from `dbt3_s001`.`orders` where (`dbt3_s001`.`orders`.`o_custkey` = `dbt3_s001`.`customer`.`c_custkey`))))) group by substr(`dbt3_s001`.`customer`.`c_phone`,1,2) order by substr(`dbt3_s001`.`customer`.`c_phone`,1,2) +select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal +from ( +select substr(c_phone, 1, 2) as cntrycode, c_acctbal +from customer +where +substr(c_phone, 1, 2) in ('10', '20', '14', '19', '11', '28', '25') +and c_acctbal > (select avg(c_acctbal) from customer +where c_acctbal > 0.00 +and substr(c_phone, 1, 2) in +('10', '20', '14', '19', '11', '28', '25')) +and not exists (select * from orders where o_custkey = c_custkey) +) as vip +group by cntrycode +order by cntrycode; +cntrycode numcust totacctbal +11 4 29942.58 +19 2 17120.35 +20 1 9091.82 +28 2 14755.5 +=== Q20 === +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 100.00 Using where; Using filesort +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +1 PRIMARY nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where +2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 100.00 Using where +2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 100.00 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +SELECT ((SELECT COUNT(*) FROM part WHERE p_name LIKE 'g%') / +(SELECT COUNT(*) FROM part)) AS sel; +sel +0.0600 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 4.17 Using where +2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.37 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +set histogram_size=127; +ANALYZE TABLE part PERSISTENT FOR COLUMNS(p_name) INDEXES(); +Table Op Msg_type Msg_text +dbt3_s001.part analyze status OK +flush table part; +set optimizer_use_condition_selectivity=4; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 7.03 Using where +2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.37 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +set histogram_type='DOUBLE_PREC_HB'; +set histogram_size=126; +ANALYZE TABLE part PERSISTENT FOR COLUMNS(p_name) INDEXES(); +Table Op Msg_type Msg_text +dbt3_s001.part analyze status OK +flush table part; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 7.81 Using where +2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.37 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +set histogram_type='SINGLE_PREC_HB'; +set histogram_size=24; +ANALYZE TABLE nation PERSISTENT FOR COLUMNS(n_name) INDEXES(); +Table Op Msg_type Msg_text +dbt3_s001.nation analyze status OK +flush table nation; +EXPLAIN EXTENDED select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort +1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 7.81 Using where +2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.37 Using where +Warnings: +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 +Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 +Note 1003 select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where ((`dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey`) and (`dbt3_s001`.`nation`.`n_name` = 'UNITED STATES') and (`dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey`) and (`dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((select (0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`)) from `dbt3_s001`.`lineitem` where ((`dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`) and (`dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey`) and (`dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date))) and (`dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>((cast('1993-01-01' as date) + interval '1' year))))))) and (`dbt3_s001`.`part`.`p_name` like 'g%')) order by `dbt3_s001`.`supplier`.`s_name` limit 10 +select sql_calc_found_rows +s_name, s_address +from supplier, nation +where s_suppkey in (select ps_suppkey from partsupp +where ps_partkey in (select p_partkey from part +where p_name like 'g%') +and ps_availqty > +(select 0.5 * sum(l_quantity) +from lineitem +where l_partkey = ps_partkey +and l_suppkey = ps_suppkey +and l_shipdate >= date('1993-01-01') +and l_shipdate < date('1993-01-01') + +interval '1' year )) +and s_nationkey = n_nationkey +and n_name = 'UNITED STATES' +order by s_name +limit 10; +s_name s_address +Supplier#000000010 Saygah3gYWMp72i PY +DROP DATABASE dbt3_s001; +set histogram_type=@save_histogram_type; +set histogram_size=@save_histogram_size; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +use test; +# +# Bug mdev-4348: using view with use_condition_selectivity > 1 +# +set @tmp_use_stat_tables=@@use_stat_tables; +set use_stat_tables='never'; +set optimizer_use_condition_selectivity=3; +CREATE TABLE t1 (a int, b int); +INSERT t1 VALUES (7,1), (0,7); +CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1; +CREATE TABLE t2 (c int, d int, index idx(d)); +INSERT INTO t2 VALUES +(0,4), (8,6), (1,3), (8,5), (9,3), (2,2), (6,2), +(1,9), (6,3), (2,8), (4,1), (0,7), (4,8), (4,5); +EXPLAIN EXTENDED +SELECT * FROM v1 INNER JOIN t2 ON ( a = c AND b = d ); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +1 SIMPLE t2 ref idx idx 5 test.t1.b 1 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`c` = `test`.`t1`.`a`) and (`test`.`t2`.`d` = `test`.`t1`.`b`)) +SELECT * FROM v1 INNER JOIN t2 ON ( a = c AND b = d ); +a b c d +0 7 0 7 +DROP VIEW v1; +DROP TABLE t1,t2; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +set use_stat_tables=@tmp_use_stat_tables; +# +# Bug mdev-4349: impossible range for non-indexed column +# +set optimizer_use_condition_selectivity=3; +create table t1 (a int); +insert into t1 values +(3), (7), (2), (5), (7), (1), (2), (2); +set optimizer_use_condition_selectivity=1; +explain extended +select * from t1 where a < 1 and a > 7; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 8 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` < 1) and (`test`.`t1`.`a` > 7)) +select * from t1 where a < 1 and a > 7; +a +set optimizer_use_condition_selectivity=3; +explain extended +select * from t1 where a < 1 and a > 7; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where 0 +select * from t1 where a < 1 and a > 7; +a +drop table t1; +create table t1 (a int); +insert into t1 values (1); +create table t2 (b int); +insert into t2 values (2),(3); +explain extended +select * from t1 where a in ( select b from t2 ) AND ( a > 3 ); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 1 0.00 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 0 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`b` = `test`.`t1`.`a`) and (`test`.`t1`.`a` > 3)) +select * from t1 where a in ( select b from t2 ) AND ( a > 3 ); +a +drop table t1,t2; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +# +# Bug mdev-4350: erroneous negative selectivity +# +create table t1 (a int); +insert into t1 values (1), (1); +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 values (0); +select count(*) from t1; +count(*) +1025 +set use_stat_tables='preferably'; +set histogram_size=127; +set histogram_type='SINGLE_PREC_HB'; +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +flush table t1; +set optimizer_use_condition_selectivity=4; +explain extended select * from t1 where a=0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 1025 49.61 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 0) +drop table t1; +set histogram_size=@save_histogram_size; +set histogram_type=@save_histogram_type; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +# +# Bug mdev-4367: 2-way join with an empty table +# when optimizer_use_condition_selectivity=3 +# +set optimizer_use_condition_selectivity=3; +CREATE TABLE t1 (a varchar(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('j'),('k'); +CREATE TABLE t2 (b varchar(1)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('x'),('y'); +CREATE TABLE t3 (c varchar(1), KEY(c)) ENGINE=MyISAM; +SELECT * FROM t1 STRAIGHT_JOIN (t2 JOIN t3 ON c = b AND b > 'z'); +a b c +DROP TABLE t1,t2,t3; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +# +# Bug mdev-4366: impossible condition on an indexed column discovered after +# substitution of constant tables +# with optimizer_use_condition_selectivity=3 +# +CREATE TABLE t1 (pk int PRIMARY KEY, a int); +INSERT INTO t1 VALUES +(1,4), (2,6), (3,3), (4,5); +CREATE TABLE t2 (b int); +INSERT INTO t2 VALUES (1), (7); +set optimizer_use_condition_selectivity=1; +EXPLAIN EXTENDED +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select 1 AS `1` from `test`.`t1` join `test`.`t2` where 0 +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; +1 +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select 1 AS `1` from `test`.`t1` join `test`.`t2` where 0 +SELECT 1 FROM t1, t2 WHERE pk = 6 AND a = 2 AND b = 10; +1 +DROP TABLE t1,t2; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +# +# Bug mdev-4370: Histograms have bean created, but the query is run after +# FLUSH TABLES with optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +set histogram_size=10; +set histogram_type='SINGLE_PREC_HB'; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (9), (1); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a > 3; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 75.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` > 3) +SELECT * FROM t1 WHERE a > 3; +a +9 +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1; +set histogram_size=@save_histogram_size; +set histogram_type=@save_histogram_type; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4371: Join with condition supported by index on an empty table +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (a int, b int, INDEX(a)); +CREATE TABLE t2 (c int); +INSERT INTO t2 VALUES (1),(2),(3),(4),(5),(6),(7),(8); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +EXPLAIN EXTENDED +SELECT * FROM t1, t2 WHERE a > 9; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 range a a 5 NULL 1 0.00 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t1` join `test`.`t2` where (`test`.`t1`.`a` > 9) +SELECT * FROM t1, t2 WHERE a > 9; +a b c +set optimizer_switch=@save_optimizer_switch; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4373: condition on a short varchar column +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (a varchar(1)); +INSERT INTO t1 VALUES ('x'), ('y'); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +SELECT * FROM t1 WHERE a <= 'w'; +a +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4372: exists subquery in WHERE +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables = PREFERABLY; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES +(1),(7),(4),(7),(0),(2),(9),(4),(0),(9),(1),(3),(8),(8); +CREATE TABLE t2 (b int); +INSERT INTO t2 VALUES (4),(5),(2),(5),(1),(1),(2); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT * FROM t1, t2 WHERE EXISTS ( SELECT 1 FROM t1, t2 ) AND a != b OR a <= 4; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 7 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 14 100.00 Using where; Using join buffer (flat, BNL join) +2 SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 14 100.00 Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where ((exists(select 1 from `test`.`t1` join `test`.`t2`) and (`test`.`t1`.`a` <> `test`.`t2`.`b`)) or (`test`.`t1`.`a` <= 4)) +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4363: selectivity of the condition a IS NULL OR IS NOT NULL +# with optimizer_use_condition_selectivity=3 +# +set use_stat_tables = PREFERABLY; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES +(1),(7),(4),(7),(NULL),(2),(NULL),(4),(NULL),(NULL),(1),(3),(8),(8); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +FLUSH TABLE t1; +set optimizer_use_condition_selectivity=3; +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 28.57 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where isnull(`test`.`t1`.`a`) +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NOT NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 71.43 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` is not null) +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NULL OR a IS NOT NULL; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (isnull(`test`.`t1`.`a`) or (`test`.`t1`.`a` is not null)) +EXPLAIN EXTENDED +SELECT * FROM t1 WHERE a IS NULL OR a < 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 14 69.39 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (isnull(`test`.`t1`.`a`) or (`test`.`t1`.`a` < 5)) +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4378: 2-way join with a materialized IN subquery in WHERE +# when optimizer_use_condition_selectivity=4 +# +set use_stat_tables=PREFERABLY; +set histogram_size=50; +set histogram_type=SINGLE_PREC_HB; +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (8),(9),(6); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (8),(1),(8),(9),(24),(6),(1),(6),(2),(4); +CREATE TABLE t3 (ln VARCHAR(16)) ENGINE=MyISAM; +INSERT INTO t3 VALUES +('smith'),('black'),('white'),('jones'), +('brown'),('taylor'),('anderson'),('taylor'); +ANALYZE TABLE t1, t2, t3; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +test.t3 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=4; +SELECT * FROM t1, t2 WHERE 'garcia' IN ( SELECT MIN( ln ) FROM t3 WHERE ln = 'sun' ); +a b +set histogram_size=@save_histogram_size; +set histogram_type=@save_histogram_type; +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2,t3; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4380: 2-way join with a materialized IN subquery in WHERE +# when optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (5),(9); +CREATE TABLE t2 (b VARCHAR(8)); +INSERT INTO t2 VALUES ('red'),('blue'); +CREATE TABLE t3 (c VARCHAR(8), d VARCHAR(8)); +INSERT INTO t3 VALUES ('white','black'),('cyan','yellow'); +ANALYZE TABLE t1, t2, t3; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +test.t3 analyze status OK +FLUSH TABLES; +set optimizer_use_condition_selectivity=3; +SELECT * FROM t1, t2 WHERE ( 'orange', 'green' ) IN ( +SELECT MAX(c), MAX(d) FROM t3, t2 WHERE c >= d AND b = c +); +a b +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2,t3; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4389: join with degenerated range condition in WHERE +# when optimizer_use_condition_selectivity=3 +# +set use_stat_tables=PREFERABLY; +CREATE TABLE t1 (f1 VARCHAR(1)); +INSERT t1 VALUES ('p'),('q'); +CREATE TABLE t2 (f2 VARCHAR(1)); +INSERT INTO t2 VALUES +('o'),('v'),('f'),('f'),('e'),('l'),('j'),('p'),('r'),('j'), +('j'),('u'),('i'),('r'),('x'),('a'),('x'),('s'); +ANALYZE TABLE t1, t2; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +FLUSH TABLES; +SET optimizer_use_condition_selectivity=3; +SELECT * FROM t1, t2 AS t2a, t2 AS t2b WHERE f1 <= 'a' AND t2a.f2 = f1; +f1 f2 f2 +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-4406: range condition for non-nullable column +# when optimizer_use_condition_selectivity=3 +# +create table t1 (a int not null); +insert into t1 values +(7), (6), (4), (9), (1), (5), (2), (1), (3), (8); +set use_stat_tables='preferably'; +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +flush table t1; +set optimizer_use_condition_selectivity=3; +select count(*) from t1 where a between 5 and 7; +count(*) +3 +explain extended select * from t1 where a between 5 and 7; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 25.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` between 5 and 7) +alter table t1 change column a a int; +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +flush table t1; +explain extended select * from t1 where a between 5 and 7; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 10 25.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` between 5 and 7) +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +drop table t1; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-5200: impossible where with a semijoin subquery +# when optimizer_use_condition_selectivity=2 +# +set use_stat_tables = 'preferably'; +set optimizer_use_condition_selectivity = 2; +CREATE TABLE t1 (i1 int) ENGINE=MyISAM; +INSERT INTO t1 VALUES (0), (1); +CREATE TABLE t2 (pk2 int, i2 int, c2 char(1), PRIMARY KEY(pk2)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,8,'m'), (2,9,'b'); +CREATE TABLE t3 (c3 char(1), INDEX(c3)) ENGINE=MyISAM; +INSERT INTO t3 VALUES ('v'), ('c'); +ANALYZE TABLE t1,t2,t3; +Table Op Msg_type Msg_text +test.t1 analyze status OK +test.t2 analyze status OK +test.t3 analyze status OK +SELECT * FROM t1 +WHERE 2 IN ( SELECT pk2 FROM t2 LEFT JOIN t3 ON (c3 = c2 ) WHERE i2 = 3 ); +i1 +EXPLAIN EXTENDED +SELECT * FROM t1 +WHERE 2 IN ( SELECT pk2 FROM t2 LEFT JOIN t3 ON (c3 = c2 ) WHERE i2 = 3 ); +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 noticed after reading const tables +Warnings: +Note 1003 select `test`.`t1`.`i1` AS `i1` from `test`.`t1` semi join (`test`.`t2` left join `test`.`t3` on((`test`.`t3`.`c3` = 'b'))) where 0 +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +DROP TABLE t1,t2,t3; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-5415: query over an information schema table +# when optimizer_use_condition_selectivity=3 +# +set optimizer_use_condition_selectivity = 3; +SELECT * FROM INFORMATION_SCHEMA.TRIGGERS WHERE SQL_MODE != ''; +TRIGGER_CATALOG TRIGGER_SCHEMA TRIGGER_NAME EVENT_MANIPULATION EVENT_OBJECT_CATALOG EVENT_OBJECT_SCHEMA EVENT_OBJECT_TABLE ACTION_ORDER ACTION_CONDITION ACTION_STATEMENT ACTION_ORIENTATION ACTION_TIMING ACTION_REFERENCE_OLD_TABLE ACTION_REFERENCE_NEW_TABLE ACTION_REFERENCE_OLD_ROW ACTION_REFERENCE_NEW_ROW CREATED SQL_MODE DEFINER CHARACTER_SET_CLIENT COLLATION_CONNECTION DATABASE_COLLATION +set optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity; +set optimizer_switch=@save_optimizer_switch_for_selectivity_test; +SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/r/server_id.require b/mysql-test/r/server_id.require deleted file mode 100644 index adffcc483b1..00000000000 --- a/mysql-test/r/server_id.require +++ /dev/null @@ -1,2 +0,0 @@ -Variable_name Value -server_id 1 diff --git a/mysql-test/r/server_id1.require b/mysql-test/r/server_id1.require deleted file mode 100644 index 666c94ef633..00000000000 --- a/mysql-test/r/server_id1.require +++ /dev/null @@ -1,2 +0,0 @@ -Variable_name Value -server_id 102 diff --git a/mysql-test/r/servers.result b/mysql-test/r/servers.result new file mode 100644 index 00000000000..c9d82c9cfcc --- /dev/null +++ b/mysql-test/r/servers.result @@ -0,0 +1,8 @@ +# +# MDEV-4594 - CREATE SERVER crashes embedded +# +CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(HOST 'localhost'); +SELECT * FROM mysql.servers; +Server_name Host Db Username Password Port Socket Wrapper Owner +s1 localhost 0 mysql +DROP SERVER s1; diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result index 0e4cf6c6775..44a37b9a9e5 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -198,7 +198,7 @@ show create table t2; Table Create Table t2 CREATE TEMPORARY TABLE `t2` ( `a` int(11) NOT NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 +) ENGINE=MyISAM DEFAULT CHARSET=latin1 DELAY_KEY_WRITE=1 drop table t2; create table t1 ( test_set set( 'val1', 'val2', 'val3' ) not null default '', diff --git a/mysql-test/r/show_explain.result b/mysql-test/r/show_explain.result new file mode 100644 index 00000000000..ac0f003bf44 --- /dev/null +++ b/mysql-test/r/show_explain.result @@ -0,0 +1,1171 @@ +drop table if exists t0, t1, t2, t3, t4; +drop view if exists v1; +SET @old_debug= @@session.debug; +set debug_sync='RESET'; +create table t0 (a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1 (a int); +insert into t1 select A.a + 10*B.a + 100*C.a from t0 A, t0 B, t0 C; +alter table t1 add b int, add c int, add filler char(32); +update t1 set b=a, c=a, filler='fooo'; +alter table t1 add key(a), add key(b); +show explain for 2000000000; +ERROR HY000: Unknown thread id: 2000000000 +show explain for (select max(a) from t0); +ERROR HY000: You may only use constant expressions in this statement +SET @old_debug= @@session.debug; +show explain for $thr2; +ERROR HY000: Target is not running an EXPLAINable command +show explain for $thr1; +ERROR HY000: Target is not running an EXPLAINable command +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +select count(*) from t1 where a < 100000; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index a a 5 NULL 1000 Using where; Using index +Warnings: +Note 1003 select count(*) from t1 where a < 100000 +count(*) +1000 +select max(c) from t1 where a < 10; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 5 NULL 10 Using index condition +Warnings: +Note 1003 select max(c) from t1 where a < 10 +max(c) +9 +# We can catch EXPLAIN, too. +set @show_expl_tmp= @@optimizer_switch; +set optimizer_switch='index_condition_pushdown=on,mrr=on,mrr_sort_keys=on'; +explain select max(c) from t1 where a < 10; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 5 NULL 10 Using index condition; Rowid-ordered scan +Warnings: +Note 1003 explain select max(c) from t1 where a < 10 +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 5 NULL 10 Using index condition; Rowid-ordered scan +set optimizer_switch= @show_expl_tmp; +set debug_dbug=@old_debug; +# UNION, first branch +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +explain select a from t0 A union select a+1 from t0 B; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY A ALL NULL NULL NULL NULL 10 +2 UNION B ALL NULL NULL NULL NULL 10 +NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL +Warnings: +Note 1003 explain select a from t0 A union select a+1 from t0 B +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY A ALL NULL NULL NULL NULL 10 +2 UNION B ALL NULL NULL NULL NULL 10 +NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL +set debug_dbug=@old_debug; +# UNION, second branch +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +explain select a from t0 A union select a+1 from t0 B; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY A ALL NULL NULL NULL NULL 10 +2 UNION B ALL NULL NULL NULL NULL 10 +NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL +Warnings: +Note 1003 explain select a from t0 A union select a+1 from t0 B +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY A ALL NULL NULL NULL NULL 10 +2 UNION B ALL NULL NULL NULL NULL 10 +NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL +set debug_dbug=@old_debug; +# Uncorrelated subquery, select +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +select a, (select max(a) from t0 B) from t0 A where a<1; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY A ALL NULL NULL NULL NULL 10 Using where +2 SUBQUERY B ALL NULL NULL NULL NULL 10 +Warnings: +Note 1003 select a, (select max(a) from t0 B) from t0 A where a<1 +a (select max(a) from t0 B) +0 9 +set debug_dbug=@old_debug; +# Uncorrelated subquery, explain +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +explain select a, (select max(a) from t0 B) from t0 A where a<1; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY A ALL NULL NULL NULL NULL 10 Using where +2 SUBQUERY B ALL NULL NULL NULL NULL 10 +Warnings: +Note 1003 explain select a, (select max(a) from t0 B) from t0 A where a<1 +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY A ALL NULL NULL NULL NULL 10 Using where +2 SUBQUERY B ALL NULL NULL NULL NULL 10 +set debug_dbug=@old_debug; +# correlated subquery, select +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY a ALL NULL NULL NULL NULL 10 Using where +2 DEPENDENT SUBQUERY b ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1 +a (select max(a) from t0 b where b.a+a.a<10) +0 9 +set debug_dbug=@old_debug; +# correlated subquery, explain +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY a ALL NULL NULL NULL NULL 10 Using where +2 DEPENDENT SUBQUERY b ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1 +a (select max(a) from t0 b where b.a+a.a<10) +0 9 +set debug_dbug=@old_debug; +# correlated subquery, select, while inside the subquery +set @show_explain_probe_select_id=2; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY a ALL NULL NULL NULL NULL 10 Using where +2 DEPENDENT SUBQUERY b ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1 +a (select max(a) from t0 b where b.a+a.a<10) +0 9 +set debug_dbug=@old_debug; +# correlated subquery, explain, while inside the subquery +set @show_explain_probe_select_id=2; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY a ALL NULL NULL NULL NULL 10 Using where +2 DEPENDENT SUBQUERY b ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1 +a (select max(a) from t0 b where b.a+a.a<10) +0 9 +set debug_dbug=@old_debug; +# correlated subquery, explain, while inside the subquery +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_end'; +select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY a ALL NULL NULL NULL NULL 10 Using where +2 DEPENDENT SUBQUERY b ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 select a, (select max(a) from t0 b where b.a+a.a<10) from t0 a where a<1 +a (select max(a) from t0 b where b.a+a.a<10) +0 9 +set debug_dbug=@old_debug; +# Try to do SHOW EXPLAIN for a query that runs a SET command: +# I've found experimentally that select_id==2 here... +# +set @show_explain_probe_select_id=2; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +set @foo= (select max(a) from t0 where sin(a) >0); +show explain for $thr2; +ERROR HY000: Target is not running an EXPLAINable command +kill query $thr2; +ERROR 70100: Query execution was interrupted +set debug_dbug=@old_debug; +# +# Attempt SHOW EXPLAIN for an UPDATE +# +create table t2 as select a as a, a as dummy from t0 limit 2; +set @show_explain_probe_select_id=2; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +update t2 set dummy=0 where (select max(a) from t0 where t2.a + t0.a <3) >3 ; +show explain for $thr2; +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 t0 ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 update t2 set dummy=0 where (select max(a) from t0 where t2.a + t0.a <3) >3 +show explain for $thr2; +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 t0 ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 update t2 set dummy=0 where (select max(a) from t0 where t2.a + t0.a <3) >3 +drop table t2; +set debug_dbug=@old_debug; +# +# Attempt SHOW EXPLAIN for a DELETE (UPD: now works) +# +create table t2 as select a as a, a as dummy from t0 limit 2; +set @show_explain_probe_select_id=2; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +delete from t2 where (select max(a) from t0 where t2.a + t0.a <3) >3 ; +show explain for $thr2; +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 t0 ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 delete from t2 where (select max(a) from t0 where t2.a + t0.a <3) >3 +show explain for $thr2; +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 t0 ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 delete from t2 where (select max(a) from t0 where t2.a + t0.a <3) >3 +drop table t2; +set debug_dbug=@old_debug; +# +# Multiple SHOW EXPLAIN calls for one select +# +create table t2 as select a as a, a as dummy from t0 limit 3; +set @show_explain_probe_select_id=2; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 +2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2 +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 +2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2 +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 +2 DEPENDENT SUBQUERY t0 ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 select t2.a, ((select max(a) from t0 where t2.a + t0.a <3) >3) as SUBQ from t2 +a SUBQ +0 0 +1 0 +2 0 +drop table t2; +set debug_dbug=@old_debug; +# +# SHOW EXPLAIN for SELECT ... ORDER BY with "Using filesort" +# +explain select * from t0 order by a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using filesort +set debug_dbug='+d,show_explain_probe_join_exec_start'; +set @show_explain_probe_select_id=1; +select * from t0 order by a; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using filesort +Warnings: +Note 1003 select * from t0 order by a +a +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +set debug_dbug=@old_debug; +# +# SHOW EXPLAIN for SELECT ... with "Using temporary" +# +explain select distinct a from t0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using temporary +set debug_dbug='+d,show_explain_probe_join_exec_start'; +set @show_explain_probe_select_id=1; +select distinct a from t0; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using temporary +Warnings: +Note 1003 select distinct a from t0 +a +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +set debug_dbug=@old_debug; +# +# SHOW EXPLAIN for SELECT ... with "Using temporary; Using filesort" +# +explain select distinct a from t0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using temporary +set debug_dbug='+d,show_explain_probe_join_exec_start'; +set @show_explain_probe_select_id=1; +select distinct a from t0; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using temporary +Warnings: +Note 1003 select distinct a from t0 +a +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +set debug_dbug=@old_debug; +# +# MDEV-238: SHOW EXPLAIN: Server crashes in JOIN::print_explain with FROM subquery and GROUP BY +# +CREATE TABLE t2 ( a INT ); +INSERT INTO t2 VALUES (1),(2),(1),(4),(2); +explain SELECT alias.a FROM t2, ( SELECT * FROM t2 ) AS alias GROUP BY alias.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort +1 SIMPLE t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join) +set debug_dbug='+d,show_explain_in_find_all_keys'; +SELECT alias.a FROM t2, ( SELECT * FROM t2 ) AS alias GROUP BY alias.a; +# FIXED by "conservative assumptions about when QEP is available" fix: +# NOTE: current code will not show "Using join buffer": +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort +1 SIMPLE t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join) +Warnings: +Note 1003 SELECT alias.a FROM t2, ( SELECT * FROM t2 ) AS alias GROUP BY alias.a +a +1 +2 +4 +set debug_dbug=@old_debug; +DROP TABLE t2; +# +# MDEV-239: Assertion `field_types == 0 ... ' failed in Protocol_text::store(double, uint32, String*) with +# SHOW EXPLAIN over EXPLAIN EXTENDED +# +CREATE TABLE t2 (a INT); +INSERT INTO t2 VALUES (1),(2),(1),(4),(2); +EXPLAIN EXTENDED SELECT alias.a FROM t2, ( SELECT * FROM t2 ) AS alias GROUP BY alias.a ; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 5 100.00 Using temporary; Using filesort +1 SIMPLE t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` join `test`.`t2` group by `test`.`t2`.`a` +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_end'; +EXPLAIN EXTENDED SELECT alias.a FROM t2, ( SELECT * FROM t2 ) AS alias GROUP BY alias.a ; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort +1 SIMPLE t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join) +Warnings: +Note 1003 EXPLAIN EXTENDED SELECT alias.a FROM t2, ( SELECT * FROM t2 ) AS alias GROUP BY alias.a +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 5 100.00 Using temporary; Using filesort +1 SIMPLE t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` join `test`.`t2` group by `test`.`t2`.`a` +set debug_dbug=@old_debug; +DROP TABLE t2; +# +# MDEV-240: SHOW EXPLAIN: Assertion `this->optimized == 2' failed in +# JOIN::print_explain on query with a JOIN, TEMPTABLE view, +# +CREATE TABLE t3 (a INT); +CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t3; +INSERT INTO t3 VALUES (8); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (4),(5),(6),(7),(8),(9); +explain SELECT * FROM v1, t2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> system NULL NULL NULL NULL 1 +1 PRIMARY t2 ALL NULL NULL NULL NULL 6 +2 DERIVED t3 system NULL NULL NULL NULL 1 +set @show_explain_probe_select_id=2; +set debug_dbug='+d,show_explain_probe_join_exec_end'; +SELECT * FROM v1, t2; +show explain for $thr2; +ERROR HY000: Target is not running an EXPLAINable command +kill query $thr2; +ERROR 70100: Query execution was interrupted +set debug_dbug=@old_debug; +DROP VIEW v1; +DROP TABLE t2, t3; +# +# MDEV-267: SHOW EXPLAIN: Server crashes in JOIN::print_explain on most of queries +# +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_end'; +select sleep(1); +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select sleep(1) +sleep(1) +0 +set debug_dbug=@old_debug; +# +# Same as above, but try another reason for JOIN to be degenerate +# +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_end'; +select * from t0 where 1>10; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +Warnings: +Note 1003 select * from t0 where 1>10 +a +set debug_dbug=@old_debug; +# +# Same as above, but try another reason for JOIN to be degenerate (2) +# +create table t3(a int primary key); +insert into t3 select a from t0; +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_end'; +select * from t0,t3 where t3.a=112233; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL no matching row in const table +Warnings: +Note 1003 select * from t0,t3 where t3.a=112233 +a a +set debug_dbug=@old_debug; +drop table t3; +# +# MDEV-270: SHOW EXPLAIN: server crashes in JOIN::print_explain on a query with +# select tables optimized away +# +CREATE TABLE t2 (pk INT PRIMARY KEY, a INT ) ENGINE=MyISAM; +INSERT INTO t2 VALUES +(1,4),(2,62),(3,7),(4,1),(5,0),(6,7),(7,7),(8,1),(9,7),(10,1), +(11,5),(12,2),(13,0),(14,1),(15,8),(16,1),(17,1),(18,9),(19,1),(20,5) ; +explain SELECT * FROM t2 WHERE a = +(SELECT MAX(a) FROM t2 +WHERE pk= (SELECT MAX(pk) FROM t2 WHERE pk = 3) +); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 20 Using where +2 SUBQUERY t2 const PRIMARY PRIMARY 4 const 1 +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_do_select'; +SELECT * FROM t2 WHERE a = +(SELECT MAX(a) FROM t2 +WHERE pk= (SELECT MAX(pk) FROM t2 WHERE pk = 3) +); +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 20 Using where +2 SUBQUERY t2 const PRIMARY PRIMARY 4 const 1 +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +Warnings: +Note 1003 SELECT * FROM t2 WHERE a = +(SELECT MAX(a) FROM t2 +WHERE pk= (SELECT MAX(pk) FROM t2 WHERE pk = 3) +) +pk a +3 7 +6 7 +7 7 +9 7 +set debug_dbug=@old_debug; +drop table t2; +# +# MDEV-273: SHOW EXPLAIN: server crashes in JOIN::print_explain on a query with impossible WHERE +# +CREATE TABLE t2 (a1 INT, KEY(a1)) ENGINE=MyISAM; +INSERT INTO t2 VALUES +(4),(6),(7),(1),(0),(7),(7),(1),(7),(1), +(5),(2),(0),(1),(8),(1),(1),(9),(1),(5); +CREATE TABLE t3 (b1 INT) ENGINE=MyISAM; +INSERT INTO t3 VALUES +(4),(5),(8),(4),(8),(2),(9),(6),(4),(8), +(3),(5),(9),(6),(8),(3),(2),(6),(3),(1), +(4),(3),(1),(7),(0),(0),(9),(5),(9),(0), +(2),(2),(5),(9),(1),(4),(8),(6),(5),(5), +(1),(7),(2),(8),(9),(3),(2),(6),(6),(5), +(4),(3),(2),(7),(4),(6),(0),(8),(5),(8), +(2),(9),(7),(5),(7),(0),(4),(3),(1),(0), +(6),(2),(8),(3),(7),(3),(5),(5),(1),(2), +(1),(7),(1),(9),(9),(8),(3); +CREATE TABLE t4 (c1 INT) ENGINE=MyISAM; +EXPLAIN +SELECT count(*) FROM t2, t3 +WHERE a1 < ALL ( +SELECT a1 FROM t2 +WHERE a1 IN ( SELECT a1 FROM t2, t4 ) +); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 index NULL a1 5 NULL 20 Using where; Using index +1 PRIMARY t3 ALL NULL NULL NULL NULL 87 Using join buffer (flat, BNL join) +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_do_select'; +SELECT count(*) FROM t2, t3 +WHERE a1 < ALL ( +SELECT a1 FROM t2 +WHERE a1 IN ( SELECT a1 FROM t2, t4 ) +); +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 index NULL a1 5 NULL 20 Using where; Using index +1 PRIMARY t3 ALL NULL NULL NULL NULL 87 Using join buffer (flat, BNL join) +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +Warnings: +Note 1003 SELECT count(*) FROM t2, t3 +WHERE a1 < ALL ( +SELECT a1 FROM t2 +WHERE a1 IN ( SELECT a1 FROM t2, t4 ) +) +count(*) +1740 +set debug_dbug=@old_debug; +drop table t2, t3, t4; +# +# MDEV-275: SHOW EXPLAIN: server crashes in JOIN::print_explain with IN subquery and aggregate function +# +CREATE TABLE t2 ( `pk` INT NOT NULL PRIMARY KEY, `a1` INT NOT NULL, KEY(`a1`)) ENGINE=MyISAM; +INSERT INTO t2 VALUES +(1,5),(2,4),(3,6),(4,9),(5,2),(6,8),(7,4),(8,8),(9,0),(10,43), +(11,23),(12,3),(13,45),(14,16),(15,2),(16,33),(17,2),(18,5),(19,9),(20,2); +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_end'; +SELECT * FROM t2 WHERE (5, 78) IN (SELECT `a1`, MAX(`a1`) FROM t2 GROUP BY `a1`); +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <subquery2> const distinct_key distinct_key 8 const,const 1 +1 PRIMARY t2 ALL NULL NULL NULL NULL 20 Using join buffer (flat, BNL join) +2 MATERIALIZED t2 index NULL a1 4 NULL 20 Using index +Warnings: +Note 1003 SELECT * FROM t2 WHERE (5, 78) IN (SELECT `a1`, MAX(`a1`) FROM t2 GROUP BY `a1`) +pk a1 +set debug_dbug=@old_debug; +DROP TABLE t2; +DROP TABLE t1; +# +# MDEV-305: SHOW EXPLAIN: ref returned by SHOW EXPLAIN is different from the normal EXPLAIN ('const' vs empty string) +# +CREATE TABLE t1(a INT, KEY(a)); +INSERT INTO t1 VALUES (3),(1),(5),(1); +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +SELECT 'test' FROM t1 WHERE a=1; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 5 const 1 Using index +Warnings: +Note 1003 SELECT 'test' FROM t1 WHERE a=1 +test +test +test +set debug_dbug=@old_debug; +DROP TABLE t1; +# +# MDEV-299: SHOW EXPLAIN: Plan produced by SHOW EXPLAIN changes back and forth during query execution +# +create table t1 (key1 int, col1 int, col2 int, filler char(100), key(key1)); +insert into t1 select A.a+ 10 * B.a, 10, 10, 'filler-data' from t0 A, t0 B; +update t1 set col1=3, col2=10 where key1=1; +update t1 set col1=3, col2=1000 where key1=2; +update t1 set col1=3, col2=10 where key1=3; +update t1 set col1=3, col2=1000 where key1=4; +set @tmp_mdev299_jcl= @@join_cache_level; +set join_cache_level=0; +explain select count(*) from t1 A, t1 B where B.key1 < A.col2 and A.col1=3 AND B.col2 + 1 < 100; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE A ALL NULL NULL NULL NULL 100 Using where +1 SIMPLE B ALL key1 NULL NULL NULL 100 Range checked for each record (index map: 0x1) +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_test_if_quick_select'; +select count(*) from t1 A, t1 B where B.key1 < A.col2 and A.col1=3 AND B.col2 + 1 < 100; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE A ALL NULL NULL NULL NULL 100 Using where +1 SIMPLE B ALL key1 NULL NULL NULL 100 Range checked for each record (index map: 0x1) +Warnings: +Note 1003 select count(*) from t1 A, t1 B where B.key1 < A.col2 and A.col1=3 AND B.col2 + 1 < 100 +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE A ALL NULL NULL NULL NULL 100 Using where +1 SIMPLE B ALL key1 NULL NULL NULL 100 Range checked for each record (index map: 0x1) +Warnings: +Note 1003 select count(*) from t1 A, t1 B where B.key1 < A.col2 and A.col1=3 AND B.col2 + 1 < 100 +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE A ALL NULL NULL NULL NULL 100 Using where +1 SIMPLE B ALL key1 NULL NULL NULL 100 Range checked for each record (index map: 0x1) +Warnings: +Note 1003 select count(*) from t1 A, t1 B where B.key1 < A.col2 and A.col1=3 AND B.col2 + 1 < 100 +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE A ALL NULL NULL NULL NULL 100 Using where +1 SIMPLE B ALL key1 NULL NULL NULL 100 Range checked for each record (index map: 0x1) +Warnings: +Note 1003 select count(*) from t1 A, t1 B where B.key1 < A.col2 and A.col1=3 AND B.col2 + 1 < 100 +count(*) +212 +set debug_dbug=@old_debug; +drop table t1; +# +# MDEV-297: SHOW EXPLAIN: Server gets stuck until timeout occurs while +# executing SHOW INDEX and SHOW EXPLAIN in parallel +# +CREATE TABLE t1(a INT, b INT, c INT, KEY(a), KEY(b), KEY(c)); +INSERT INTO t1 (a) VALUES (3),(1),(5),(1); +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +SHOW INDEX FROM t1; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE STATISTICS ALL NULL NULL NULL NULL NULL Skip_open_table; Scanned all databases +Warnings: +Note 1003 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 1 a 1 a A NULL NULL NULL YES BTREE +t1 1 b 1 b A NULL NULL NULL YES BTREE +t1 1 c 1 c A NULL NULL NULL YES BTREE +set debug_dbug=@old_debug; +DROP TABLE t1; +# +# MDEV-324: SHOW EXPLAIN: Plan produced by SHOW EXPLAIN for a query with TEMPTABLE view +# loses 'DERIVED' line on the way without saying that the plan was already deleted +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1; +EXPLAIN SELECT a + 1 FROM v1; +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 ALL NULL NULL NULL NULL 2 +set debug_dbug='+d,show_explain_probe_join_tab_preread'; +set @show_explain_probe_select_id=1; +SELECT a + 1 FROM v1; +show explain for $thr2; +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 ALL NULL NULL NULL NULL 2 +Warnings: +Note 1003 SELECT a + 1 FROM v1 +a + 1 +2 +3 +set debug_dbug=@old_debug; +DROP VIEW v1; +DROP TABLE t1; +# +# MDEV-323: SHOW EXPLAIN: Plan produced by SHOW EXPLAIN loses +# 'UNION RESULT' line on the way without saying that the plan was already deleted +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (4),(6); +EXPLAIN +SELECT a FROM t1 WHERE a IN ( SELECT 1+SLEEP(0.01) UNION SELECT 2 ); +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 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used +3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL +set debug_dbug='+d,show_explain_probe_union_read'; +SELECT a FROM t1 WHERE a IN ( SELECT 1+SLEEP(0.01) UNION SELECT 2 ); +show explain for $thr2; +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 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used +3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL +Warnings: +Note 1003 SELECT a FROM t1 WHERE a IN ( SELECT 1+SLEEP(0.01) UNION SELECT 2 ) +show explain for $thr2; +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 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used +3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL +Warnings: +Note 1003 SELECT a FROM t1 WHERE a IN ( SELECT 1+SLEEP(0.01) UNION SELECT 2 ) +a +set debug_dbug=@old_debug; +DROP TABLE t1; +# +# MDEV-327: SHOW EXPLAIN: Different select_type in plans produced by SHOW EXPLAIN +# and standard EXPLAIN: 'SUBQUERY' vs 'DEPENDENT SUBQUERY' +# +CREATE TABLE t1 (a INT) ENGINE=Aria; +INSERT INTO t1 VALUES +(4),(6),(3),(5),(3),(246),(2),(9),(3),(8), +(1),(8),(8),(5),(7),(5),(1),(6),(2),(9); +CREATE TABLE t2 (b INT) ENGINE=Aria; +INSERT INTO t2 VALUES +(1),(7),(4),(7),(0),(2),(9),(4),(0),(9), +(1),(3),(8),(8),(18),(84),(6),(3),(6),(6); +EXPLAIN +SELECT * FROM t1, ( SELECT * FROM t2 ) AS alias +WHERE a < ALL ( SELECT b FROM t1, t2 WHERE a = b ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 20 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 20 +3 SUBQUERY t1 ALL NULL NULL NULL NULL 20 +3 SUBQUERY t2 ALL NULL NULL NULL NULL 20 Using where +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +SELECT * FROM t1, ( SELECT * FROM t2 ) AS alias +WHERE a < ALL ( SELECT b FROM t1, t2 WHERE a = b ); +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 20 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 20 +3 SUBQUERY t1 ALL NULL NULL NULL NULL 20 +3 SUBQUERY t2 ALL NULL NULL NULL NULL 20 Using where +Warnings: +Note 1003 SELECT * FROM t1, ( SELECT * FROM t2 ) AS alias +WHERE a < ALL ( SELECT b FROM t1, t2 WHERE a = b ) +a b +set debug_dbug=@old_debug; +DROP TABLE t1, t2; +# +# Test that SHOW EXPLAIN will print 'Distinct'. +# +CREATE TABLE t1 (a int(10) unsigned not null primary key,b int(10) unsigned); +INSERT INTO t1 VALUES (1,1),(2,1),(3,1),(4,1); +CREATE TABLE t3 (a int(10) unsigned, key(A), b text); +INSERT INTO t3 VALUES (1,'1'),(2,'2'); +create temporary table t4 select * from t3; +insert into t3 select * from t4; +insert into t4 select * from t3; +insert into t3 select * from t4; +insert into t4 select * from t3; +insert into t3 select * from t4; +insert into t4 select * from t3; +insert into t3 select * from t4; +explain select distinct t1.a from t1,t3 where t1.a=t3.a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 4 Using index; Using temporary +1 SIMPLE t3 ref a a 5 test.t1.a 7 Using index; Distinct +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +select distinct t1.a from t1,t3 where t1.a=t3.a; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 4 Using index; Using temporary +1 SIMPLE t3 ref a a 5 test.t1.a 7 Using index; Distinct +Warnings: +Note 1003 select distinct t1.a from t1,t3 where t1.a=t3.a +a +1 +2 +set debug_dbug=@old_debug; +drop table t1,t3,t4; +# +# ---------- SHOW EXPLAIN and permissions ----------------- +# +grant ALL on test.* to test2@localhost; +grant super on *.* to test2@localhost; +# +# First, make sure that user 'test2' cannot do SHOW EXPLAIN on us +# +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +select * from t0 where a < 3; +show explain for $thr2; +ERROR 42000: Access denied; you need (at least one of) the PROCESS privilege(s) for this operation +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 select * from t0 where a < 3 +a +0 +1 +2 +set debug_dbug=@old_debug; +# +# Check that user test2 can do SHOW EXPLAIN on its own queries +# +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +select * from t0 where a < 3; +show explain for $thr_con2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 select * from t0 where a < 3 +a +0 +1 +2 +# +# Now, grant test2 a PROCESSLIST permission, and see that he's able to observe us +# +grant process on *.* to test2@localhost; +set debug_dbug=@old_debug; +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +select * from t0 where a < 3; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 select * from t0 where a < 3 +a +0 +1 +2 +set debug_dbug=@old_debug; +revoke all privileges on test.* from test2@localhost; +drop user test2@localhost; +# +# Test that it is possible to KILL a SHOW EXPLAIN command that's waiting +# on its target thread +# +create table t1 (pk int primary key, data char(64)) engine=innodb; +insert into t1 select A.a + 10 * B.a + 100 * C.a, 'data1' from t0 A, t0 B, t0 C; +# Lock two threads +set autocommit=0; +select * from t1 where pk between 10 and 20 for update; +pk data +10 data1 +11 data1 +12 data1 +13 data1 +14 data1 +15 data1 +16 data1 +17 data1 +18 data1 +19 data1 +20 data1 +set autocommit=0; +select * from t1 where pk between 10 and 20 for update; +# do: send_eval show explain for thr2; +kill query $thr_default; +ERROR 70100: Query execution was interrupted +rollback; +pk data +10 data1 +11 data1 +12 data1 +13 data1 +14 data1 +15 data1 +16 data1 +17 data1 +18 data1 +19 data1 +20 data1 +drop table t1; +# +# Check that the I_S table is invisible +# +select table_name from information_schema.tables where table_schema='information_schema' and table_name like '%explain%'; +table_name +# +# MDEV-325: SHOW EXPLAIN: Plan produced by SHOW EXPLAIN is different from standard EXPLAIN: type ALL vs 'index_merge'.. +# +CREATE TABLE t1 (a INT, b INT, KEY(a), KEY(b)) ENGINE=MyISAM; +INSERT INTO t1 VALUES +(8,0),(128,5050),(5372,8),(234,7596),(2,0),(2907,8930),(1,0), +(0,5224),(8,7638),(960,5),(9872,1534),(0,2295),(3408,9809), +(7,0),(1168,0),(2089,5570),(0,205),(88,1018),(0,26528), +(0,0),(4,5567),(1444,145),(6,0),(1,7535),(7793,534),(70,9), +(178,1),(44,5),(189,0),(3,0); +EXPLAIN +SELECT a+SLEEP(0.01) FROM t1 +WHERE a IN ( 255, 0 ) OR b BETWEEN 6 AND 129 +ORDER BY b; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index_merge a,b a,b 5,5 NULL 8 Using sort_union(a,b); Using where; Using filesort +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +SELECT a+SLEEP(0.01) FROM t1 +WHERE a IN ( 255, 0 ) OR b BETWEEN 6 AND 129 +ORDER BY b; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index_merge a,b a,b 5,5 NULL 8 Using sort_union(a,b); Using where; Using filesort +Warnings: +Note 1003 SELECT a+SLEEP(0.01) FROM t1 +WHERE a IN ( 255, 0 ) OR b BETWEEN 6 AND 129 +ORDER BY b +a+SLEEP(0.01) +0 +5372 +70 +0 +0 +0 +0 +set debug_dbug=@old_debug; +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_do_select'; +SELECT a+SLEEP(0.01) FROM t1 +WHERE a IN ( 255, 0 ) OR b BETWEEN 6 AND 129 +ORDER BY b; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index_merge a,b a,b 5,5 NULL 8 Using sort_union(a,b); Using where; Using filesort +Warnings: +Note 1003 SELECT a+SLEEP(0.01) FROM t1 +WHERE a IN ( 255, 0 ) OR b BETWEEN 6 AND 129 +ORDER BY b +a+SLEEP(0.01) +0 +5372 +70 +0 +0 +0 +0 +set debug_dbug=@old_debug; +drop table t1; +# +# MDEV-298: SHOW EXPLAIN: Plan returned by SHOW EXPLAIN only contains +# 'Using temporary' while the standard EXPLAIN says 'Using temporary; Using filesort' +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9), +(10),(11),(12),(13),(14),(15),(16); +INSERT INTO t1 SELECT t11.a FROM t1 t11, t1 t12, t1 t13; +EXPLAIN SELECT a FROM t1 GROUP BY a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4112 Using temporary; Using filesort +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +SELECT a FROM t1 GROUP BY a; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4112 Using temporary; Using filesort +Warnings: +Note 1003 SELECT a FROM t1 GROUP BY a +a +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +set debug_dbug=@old_debug; +drop table t1; +# +# MDEV-408: SHOW EXPLAIN: Some values are chopped off in SHOW EXPLAIN output +# +CREATE TABLE t1 (a INT, b VARCHAR(35)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (3989,'Abilene'),(3873,'Akron'); +CREATE TABLE t2 (c INT, d VARCHAR(52) PRIMARY KEY, KEY(c)) ENGINE=InnoDB; +INSERT INTO t2 VALUES (86,'English'),(87,'Russian'); +explain SELECT SUM(a + SLEEP(0.1)) FROM t1 WHERE a IN ( SELECT c FROM t2 WHERE d < b ) OR b < 's'; +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 DEPENDENT SUBQUERY t2 index_subquery PRIMARY,c c 5 func 1 Using index; Using where +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +SELECT SUM(a + SLEEP(0.1)) FROM t1 WHERE a IN ( SELECT c FROM t2 WHERE d < b ) OR b < 's'; +show explain for $thr2; +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 DEPENDENT SUBQUERY t2 index_subquery PRIMARY,c c 5 func 1 Using index; Using where +Warnings: +Note 1003 SELECT SUM(a + SLEEP(0.1)) FROM t1 WHERE a IN ( SELECT c FROM t2 WHERE d < b ) OR b < 's' +SUM(a + SLEEP(0.1)) +7862 +set debug_dbug=@old_debug; +drop table t1, t2; +# +# MDEV-412: SHOW EXPLAIN: Server crashes in JOIN::print_explain on a query with inner join and ORDER BY the same column twice +# +CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(3), KEY(b)) ENGINE=MyISAM; +INSERT INTO t1 VALUES +(3795,'USA'),(3913,'USA'),(3846,'ITA'),(4021,'USA'),(4005,'RUS'),(4038,'USA'), +(3825,'USA'),(3840,'USA'),(3987,'USA'),(3807,'USA'),(3896,'USA'),(4052,'USA'), +(3973,'USA'),(3982,'ITA'),(3965,'USA'),(3852,'RUS'),(4006,'USA'),(3800,'USA'), +(4020,'USA'),(4040,'USA'),(3916,'USA'),(3817,'USA'),(3885,'USA'),(3802,'USA'), +(4009,'ITA'),(3895,'USA'),(3963,'RUS'),(4045,'USA'),(3988,'USA'),(3815,'USA'), +(4063,'USA'),(3978,'USA'),(4019,'USA'),(3954,'USA'),(3950,'USA'),(3974,'ITA'), +(4054,'USA'),(4061,'RUS'),(3976,'USA'),(3966,'USA'),(3957,'USA'),(3981,'USA'), +(3923,'USA'),(3876,'USA'),(3819,'USA'),(3877,'USA'),(3829,'ITA'),(3964,'USA'), +(4053,'RUS'),(3917,'USA'),(3874,'USA'),(4023,'USA'),(4001,'USA'),(3872,'USA'), +(3890,'USA'),(3962,'USA'),(3886,'USA'),(4026,'ITA'),(3869,'USA'),(3937,'RUS'), +(3975,'USA'),(3944,'USA'),(3908,'USA'),(3867,'USA'),(3947,'USA'),(3838,'USA'), +(3796,'USA'),(3893,'USA'),(3920,'ITA'),(3994,'USA'),(3875,'RUS'),(4011,'USA'), +(4013,'USA'),(3810,'USA'),(3834,'USA'),(3968,'USA'),(3931,'USA'),(3839,'USA'), +(4042,'USA'),(4039,'ITA'),(3811,'USA'),(3837,'RUS'),(4041,'USA'),(3884,'USA'), +(3894,'USA'),(3879,'USA'),(3942,'USA'),(3959,'USA'),(3814,'USA'),(4044,'USA'), +(3971,'ITA'),(3823,'USA'),(3793,'RUS'),(3855,'USA'),(3905,'USA'),(3865,'USA'), +(4046,'USA'),(3990,'USA'),(4022,'USA'),(3833,'USA'),(3918,'USA'),(4064,'ITA'), +(3821,'USA'),(3836,'RUS'),(3921,'USA'),(3914,'USA'),(3888,'USA'); +CREATE TABLE t2 (c VARCHAR(3) PRIMARY KEY) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('USA'); +CREATE TABLE t3 (d VARCHAR(3), e VARCHAR(52), PRIMARY KEY (d,e)) ENGINE=MyISAM; +INSERT INTO t3 VALUES +('JPN','Japanese'),('KOR','Korean'),('POL','Polish'),('PRT','Portuguese'), +('ESP','Spanish'),('FRA','French'),('VNM','Vietnamese'); +explain +SELECT b AS field1, b AS field2 FROM t1, t2, t3 WHERE d = b ORDER BY field1, field2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 system NULL NULL NULL NULL 1 +1 SIMPLE t1 index b b 6 NULL 107 Using where; Using index +1 SIMPLE t3 ref PRIMARY PRIMARY 5 test.t1.b 1 Using index +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_do_select'; +SELECT b AS field1, b AS field2 FROM t1, t2, t3 WHERE d = b ORDER BY field1, field2; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 system NULL NULL NULL NULL 1 Using filesort +1 SIMPLE t1 index b b 6 NULL 107 Using where; Using index +1 SIMPLE t3 ref PRIMARY PRIMARY 5 test.t1.b 1 Using index +Warnings: +Note 1003 SELECT b AS field1, b AS field2 FROM t1, t2, t3 WHERE d = b ORDER BY field1, field2 +field1 field2 +set debug_dbug=@old_debug; +DROP TABLE t1,t2,t3; +# +# MDEV-423: SHOW EXPLAIN: 'Using where' for a subquery is shown in EXPLAIN, but not in SHOW EXPLAIN output +# +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (7),(0),(9),(3),(4),(2),(5),(7),(0),(9),(3),(4),(2),(5); +CREATE TABLE t2 (b INT, c INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES +(0,4),(8,6),(1,3),(8,5),(9,3),(24,246),(6,2),(1,9),(6,3),(2,8), +(4,1),(8,8),(4,8),(4,5),(7,7),(4,5),(1,1),(9,6),(4,2),(8,9); +create table t3 like t2; +insert into t3 select * from t2; +explain +SELECT max(a+b+c) FROM t1 AS alias1, ( SELECT * FROM t2 ) AS alias +WHERE EXISTS ( SELECT * FROM t3 WHERE b = c ) OR a <= 10; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 ALL NULL NULL NULL NULL 14 +1 PRIMARY t2 ALL NULL NULL NULL NULL 20 +3 SUBQUERY t3 ALL NULL NULL NULL NULL 20 Using where +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +SELECT max(a+b+c) FROM t1 AS alias1, ( SELECT * FROM t2 ) AS alias +WHERE EXISTS ( SELECT * FROM t3 WHERE b = c ) OR a <= 10; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 ALL NULL NULL NULL NULL 14 +1 PRIMARY t2 ALL NULL NULL NULL NULL 20 +3 SUBQUERY t3 ALL NULL NULL NULL NULL 20 Using where +Warnings: +Note 1003 SELECT max(a+b+c) FROM t1 AS alias1, ( SELECT * FROM t2 ) AS alias +WHERE EXISTS ( SELECT * FROM t3 WHERE b = c ) OR a <= 10 +max(a+b+c) +279 +set debug_dbug=@old_debug; +DROP TABLE t1,t2,t3; +# +# MDEV-416: Server crashes in SQL_SELECT::cleanup on EXPLAIN with SUM ( DISTINCT ) in a non-correlated subquery (5.5-show-explain tree) +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (8),(9); +EXPLAIN SELECT * FROM t1 +WHERE ( 8, 89 ) IN ( SELECT b, SUM( DISTINCT b ) FROM t2 GROUP BY 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 +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using filesort +DROP TABLE t1,t2; +# +# Check if queries in non-default charsets work. +# +set names cp1251; +select charset('ãû'); +charset('ãû') +cp1251 +select hex('ãû'); +hex('ãû') +E3FB +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +select * from t0 where length('ãû') = a; +set names utf8; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 select * from t0 where length('гы') = a +set names default; +a +2 +set debug_dbug=@old_debug; +set names default; +# +# MDEV-462: SHOW EXPLAIN: Assertion `table_list->table' fails in find_field_in_table_ref if FOR contains a non-numeric value +# +show explain for foo; +ERROR HY000: You may only use constant expressions in this statement +# +# MDEV-411: SHOW EXPLAIN: For dependent subquery EXPLAIN produces type=index, key, 'Using where; Using index', +# while SHOW EXPLAIN says type=ALL, no key, 'Range checked for each record' +# +CREATE TABLE t1 (a INT NOT NULL, KEY(a)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (7),(0); +CREATE TABLE t2 (b INT NOT NULL) ENGINE=MyISAM; +INSERT INTO t2 VALUES (0),(8); +explain +SELECT SUM(b) FROM ( SELECT * FROM t1 ) AS alias1, t2 +WHERE b <= ANY ( +SELECT a FROM t1 +WHERE a = b + SLEEP(0.2) OR a >= ( SELECT SUM(b) FROM t2 )); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 index NULL a 4 NULL 2 Using index +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where +3 DEPENDENT SUBQUERY t1 ALL a NULL NULL NULL 2 Range checked for each record (index map: 0x1) +4 SUBQUERY t2 ALL NULL NULL NULL NULL 2 +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_join_exec_start'; +SELECT SUM(b) FROM ( SELECT * FROM t1 ) AS alias1, t2 +WHERE b <= ANY ( +SELECT a FROM t1 +WHERE a = b + SLEEP(0.2) OR a >= ( SELECT SUM(b) FROM t2 )); +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 index NULL a 4 NULL 2 Using index +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where +3 DEPENDENT SUBQUERY t1 ALL a NULL NULL NULL 2 Range checked for each record (index map: 0x1) +4 SUBQUERY t2 ALL NULL NULL NULL NULL 2 +Warnings: +Note 1003 SELECT SUM(b) FROM ( SELECT * FROM t1 ) AS alias1, t2 +WHERE b <= ANY ( +SELECT a FROM t1 +WHERE a = b + SLEEP(0.2) OR a >= ( SELECT SUM(b) FROM t2 )) +SUM(b) +0 +set debug_dbug=@old_debug; +DROP TABLE t1,t2; +# End +drop table t0; +set debug_sync='RESET'; diff --git a/mysql-test/r/show_explain_non_select.result b/mysql-test/r/show_explain_non_select.result new file mode 100644 index 00000000000..0bd1e959405 --- /dev/null +++ b/mysql-test/r/show_explain_non_select.result @@ -0,0 +1,44 @@ +drop table if exists t0, t1; +SET @old_debug= @@session.debug; +set debug_sync='RESET'; +create table t0 (a int) engine=myisam; +insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8); +create table t1 (a int, b int, filler char(100), key(a), key(b)); +insert into t1 +select A.a+10*B.a + 10*C.a, A.a+10*B.a + 10*C.a, 'filler' +from t0 A, t0 B, t0 C; +# +# Test SHOW EXPLAIN for single-table DELETE +# +set debug_dbug='+d,show_explain_probe_delete_exec_start'; +delete from t1 where a<10 and b+1>1000; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 5 NULL 1 Using where +Warnings: +Note 1003 delete from t1 where a<10 and b+1>1000 +# +# Test SHOW EXPLAIN for multi-table DELETE +# +set @show_explain_probe_select_id=1; +set debug_dbug='+d,show_explain_probe_do_select'; +delete t1 from t1, t0 where t0.a=t1.a and t1.b +1 > 1000; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 8 Using where +1 SIMPLE t1 ref a a 5 test.t0.a 4 Using where +Warnings: +Note 1003 delete t1 from t1, t0 where t0.a=t1.a and t1.b +1 > 1000 +# +# Test SHOW EXPLAIN for single-table UPDATE +# +set debug_dbug='+d,show_explain_probe_update_exec_start'; +update t1 set filler='filler-data-2' where a<10 and b+1>1000; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 5 NULL 1 Using where +Warnings: +Note 1003 update t1 set filler='filler-data-2' where a<10 and b+1>1000 +drop table t0,t1; +set debug_dbug=@old_debug; +set debug_sync='RESET'; diff --git a/mysql-test/r/show_explain_ps.result b/mysql-test/r/show_explain_ps.result new file mode 100644 index 00000000000..625b9cfddae --- /dev/null +++ b/mysql-test/r/show_explain_ps.result @@ -0,0 +1,27 @@ +drop table if exists t0, t1; +select * from performance_schema.setup_instruments where name like '%show_explain%'; +NAME ENABLED TIMED +wait/synch/cond/sql/show_explain YES YES +# We've got no instances +select * from performance_schema.cond_instances where name like '%show_explain%'; +NAME OBJECT_INSTANCE_BEGIN +# Check out if our cond is hit. +create table t0 (a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +set @show_explain_probe_select_id=1; +set debug_dbug='d,show_explain_probe_join_exec_start'; +select count(*) from t0 where a < 100000; +show explain for $thr2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where +Warnings: +Note 1003 select count(*) from t0 where a < 100000 +count(*) +10 +set debug_dbug=''; +select event_name +from performance_schema.events_waits_history_long +where event_name='wait/synch/cond/sql/show_explain'; +event_name +wait/synch/cond/sql/show_explain +drop table t0; diff --git a/mysql-test/r/shutdown.result b/mysql-test/r/shutdown.result new file mode 100644 index 00000000000..fae3af1cd08 --- /dev/null +++ b/mysql-test/r/shutdown.result @@ -0,0 +1,5 @@ +create user user1@localhost; +shutdown; +ERROR 42000: Access denied; you need (at least one of) the SHUTDOWN privilege(s) for this operation +shutdown; +drop user user1@localhost; diff --git a/mysql-test/r/signal_code.result b/mysql-test/r/signal_code.result index ca46f1d2079..4cd1de97729 100644 --- a/mysql-test/r/signal_code.result +++ b/mysql-test/r/signal_code.result @@ -20,16 +20,16 @@ return 0; end $$ show procedure code signal_proc; Pos Instruction -0 stmt 130 "SIGNAL foo" -1 stmt 130 "SIGNAL foo SET MESSAGE_TEXT = "This i..." -2 stmt 131 "RESIGNAL foo" -3 stmt 131 "RESIGNAL foo SET MESSAGE_TEXT = "This..." +0 stmt 132 "SIGNAL foo" +1 stmt 132 "SIGNAL foo SET MESSAGE_TEXT = "This i..." +2 stmt 133 "RESIGNAL foo" +3 stmt 133 "RESIGNAL foo SET MESSAGE_TEXT = "This..." drop procedure signal_proc; show function code signal_func; Pos Instruction -0 stmt 130 "SIGNAL foo" -1 stmt 130 "SIGNAL foo SET MESSAGE_TEXT = "This i..." -2 stmt 131 "RESIGNAL foo" -3 stmt 131 "RESIGNAL foo SET MESSAGE_TEXT = "This..." +0 stmt 132 "SIGNAL foo" +1 stmt 132 "SIGNAL foo SET MESSAGE_TEXT = "This i..." +2 stmt 133 "RESIGNAL foo" +3 stmt 133 "RESIGNAL foo SET MESSAGE_TEXT = "This..." 4 freturn 3 0 drop function signal_func; diff --git a/mysql-test/r/skip_grants.result b/mysql-test/r/skip_grants.result index cd691d882fa..b178e0ecfa7 100644 --- a/mysql-test/r/skip_grants.result +++ b/mysql-test/r/skip_grants.result @@ -36,14 +36,14 @@ CREATE DEFINER=a@'' FUNCTION f3() RETURNS INT RETURN 3; SHOW CREATE VIEW v3; View Create View character_set_client collation_connection -v3 CREATE ALGORITHM=UNDEFINED DEFINER=`a`@`` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`c` AS `c` from `t1` latin1 latin1_swedish_ci +v3 CREATE ALGORITHM=UNDEFINED DEFINER=`a`@`%` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`c` AS `c` from `t1` latin1 latin1_swedish_ci SHOW CREATE PROCEDURE p3; Procedure sql_mode Create Procedure character_set_client collation_connection Database Collation -p3 CREATE DEFINER=`a`@`` PROCEDURE `p3`() +p3 CREATE DEFINER=`a`@`%` PROCEDURE `p3`() SELECT 3 latin1 latin1_swedish_ci latin1_swedish_ci SHOW CREATE FUNCTION f3; Function sql_mode Create Function character_set_client collation_connection Database Collation -f3 CREATE DEFINER=`a`@`` FUNCTION `f3`() RETURNS int(11) +f3 CREATE DEFINER=`a`@`%` FUNCTION `f3`() RETURNS int(11) RETURN 3 latin1 latin1_swedish_ci latin1_swedish_ci DROP TRIGGER t1_bi; DROP TRIGGER ti_ai; diff --git a/mysql-test/r/sp-code.result b/mysql-test/r/sp-code.result index 67651294498..3061c58747a 100644 --- a/mysql-test/r/sp-code.result +++ b/mysql-test/r/sp-code.result @@ -155,11 +155,11 @@ Pos Instruction 0 stmt 9 "drop temporary table if exists sudoku..." 1 stmt 1 "create temporary table sudoku_work ( ..." 2 stmt 1 "create temporary table sudoku_schedul..." -3 stmt 88 "call sudoku_init()" +3 stmt 90 "call sudoku_init()" 4 jump_if_not 7(8) p_naive@0 5 stmt 4 "update sudoku_work set cnt = 0 where ..." 6 jump 8 -7 stmt 88 "call sudoku_count()" +7 stmt 90 "call sudoku_count()" 8 stmt 6 "insert into sudoku_schedule (row,col)..." 9 set v_scounter@2 0 10 set v_i@3 1 diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 962b834e4ac..17e5632157b 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -5408,11 +5408,11 @@ use test| drop table t3| DROP PROCEDURE IF EXISTS bug16899_p1| DROP FUNCTION IF EXISTS bug16899_f1| -CREATE DEFINER=1234567890abcdefGHIKL@localhost PROCEDURE bug16899_p1() +CREATE DEFINER=longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost PROCEDURE bug16899_p1() BEGIN SET @a = 1; END| -ERROR HY000: String '1234567890abcdefGHIKL' is too long for user name (should be no longer than 16) +ERROR HY000: String 'longer_than_80_4567890123456789012345678901234567890123456789012345678' is too long for user name (should be no longer than 80) CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY FUNCTION bug16899_f1() RETURNS INT BEGIN @@ -6403,14 +6403,14 @@ select 1; /*! select 2; */ select 3; /*!00000 select 4; */ -/*!99999 select 5; */ +/*!999999 select 5; */ end $$ create procedure proc_25411_b( /* real comment */ /*! p1 int, */ /*!00000 p2 int */ -/*!99999 ,p3 int */ +/*!999999 ,p3 int */ ) begin select p1, p2; @@ -6418,11 +6418,11 @@ end $$ create procedure proc_25411_c() begin -select 1/*!,2*//*!00000,3*//*!99999,4*/; -select 1/*! ,2*//*!00000 ,3*//*!99999 ,4*/; -select 1/*!,2 *//*!00000,3 *//*!99999,4 */; -select 1/*! ,2 *//*!00000 ,3 *//*!99999 ,4 */; -select 1 /*!,2*/ /*!00000,3*/ /*!99999,4*/ ; +select 1/*!,2*//*!00000,3*//*!999999,4*/; +select 1/*! ,2*//*!00000 ,3*//*!999999 ,4*/; +select 1/*!,2 *//*!00000,3 *//*!999999,4 */; +select 1/*! ,2 *//*!00000 ,3 *//*!999999 ,4 */; +select 1 /*!,2*/ /*!00000,3*/ /*!999999,4*/ ; end $$ show create procedure proc_25411_a; diff --git a/mysql-test/r/sp_notembedded.result b/mysql-test/r/sp_notembedded.result index 540a66e7508..410441b63e3 100644 --- a/mysql-test/r/sp_notembedded.result +++ b/mysql-test/r/sp_notembedded.result @@ -9,11 +9,11 @@ end| call bug4902()| Grants for root@localhost GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION -GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION +GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION call bug4902()| Grants for root@localhost GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION -GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION +GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION drop procedure bug4902| drop procedure if exists bug4902_2| create procedure bug4902_2() @@ -32,9 +32,9 @@ drop procedure bug4902_2| drop procedure if exists bug6807| create procedure bug6807() begin -declare id int; -set id = connection_id(); -kill query id; +declare a int; +set a = connection_id(); +kill query a; select 'Not reached'; end| call bug6807()| @@ -156,11 +156,11 @@ create procedure 15298_2 () sql security definer show grants; call 15298_1(); Grants for root@localhost GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION -GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION +GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION call 15298_2(); Grants for root@localhost GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION -GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION +GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION drop user mysqltest_1@localhost; drop procedure 15298_1; drop procedure 15298_2; @@ -169,7 +169,7 @@ drop procedure if exists p1; create table t1 (value varchar(15)); create procedure p1() update t1 set value='updated' where value='old'; call p1(); -insert into t1 (value) values ("old"); +insert into t1 (value) values ("old"),("irrelevant"); select get_lock('b26162',120); get_lock('b26162',120) 1 @@ -179,11 +179,13 @@ call p1();; select 'rl_contender', value from t1; rl_contender value rl_contender old +rl_contender irrelevant select release_lock('b26162'); release_lock('b26162') 1 rl_acquirer value rl_acquirer old +rl_acquirer irrelevant drop procedure p1; drop table t1; set session low_priority_updates=default; diff --git a/mysql-test/r/sp_trans_log.result b/mysql-test/r/sp_trans_log.result index e3463dec571..241f0b15342 100644 --- a/mysql-test/r/sp_trans_log.result +++ b/mysql-test/r/sp_trans_log.result @@ -16,7 +16,7 @@ insert into t2 values (bug23333(),1)| ERROR 23000: Duplicate entry '1' for key 'PRIMARY' show binlog events from <binlog_start> limit 0, 4| Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Query # # COMMIT diff --git a/mysql-test/r/sql_mode.result b/mysql-test/r/sql_mode.result index 6736ca7f541..4fdac6b9cea 100644 --- a/mysql-test/r/sql_mode.result +++ b/mysql-test/r/sql_mode.result @@ -71,7 +71,7 @@ t1 CREATE TABLE `t1` ( `email` varchar(60) NOT NULL DEFAULT '', PRIMARY KEY (`a`), UNIQUE KEY `email` (`email`) -) TYPE=HEAP ROW_FORMAT=DYNAMIC +) TYPE=MEMORY ROW_FORMAT=DYNAMIC set sql_mode="postgresql,oracle,mssql,db2,maxdb"; select @@sql_mode; @@sql_mode diff --git a/mysql-test/r/stat_tables.result b/mysql-test/r/stat_tables.result new file mode 100644 index 00000000000..63c65e23c19 --- /dev/null +++ b/mysql-test/r/stat_tables.result @@ -0,0 +1,419 @@ +select @@global.use_stat_tables; +@@global.use_stat_tables +COMPLEMENTARY +select @@session.use_stat_tables; +@@session.use_stat_tables +COMPLEMENTARY +set @save_use_stat_tables=@@use_stat_tables; +set use_stat_tables='preferably'; +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=off'; +select * from mysql.table_stats; +db_name table_name cardinality +dbt3_s001 customer 150 +dbt3_s001 lineitem 6005 +dbt3_s001 nation 25 +dbt3_s001 orders 1500 +dbt3_s001 part 200 +dbt3_s001 partsupp 700 +dbt3_s001 region 5 +dbt3_s001 supplier 10 +select * from mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 customer PRIMARY 1 1.0000 +dbt3_s001 customer i_c_nationkey 1 6.0000 +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 nation PRIMARY 1 1.0000 +dbt3_s001 nation i_n_regionkey 1 5.0000 +dbt3_s001 orders PRIMARY 1 1.0000 +dbt3_s001 orders i_o_orderdate 1 1.3321 +dbt3_s001 orders i_o_custkey 1 15.0000 +dbt3_s001 part PRIMARY 1 1.0000 +dbt3_s001 part i_p_retailprice 1 1.0000 +dbt3_s001 partsupp PRIMARY 1 3.5000 +dbt3_s001 partsupp PRIMARY 2 1.0000 +dbt3_s001 partsupp i_ps_partkey 1 3.5000 +dbt3_s001 partsupp i_ps_suppkey 1 70.0000 +dbt3_s001 region PRIMARY 1 1.0000 +dbt3_s001 supplier PRIMARY 1 1.0000 +dbt3_s001 supplier i_s_nationkey 1 1.1111 +set optimizer_switch=@save_optimizer_switch; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +EXPLAIN select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey +and l_suppkey = s_suppkey and c_nationkey = s_nationkey +and s_nationkey = n_nationkey and n_regionkey = r_regionkey +and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 179 Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +1 SIMPLE nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1 +1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +1 SIMPLE supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.lineitem.l_suppkey 1 Using where +select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey +and l_suppkey = s_suppkey and c_nationkey = s_nationkey +and s_nationkey = n_nationkey and n_regionkey = r_regionkey +and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; +n_name revenue +PERU 321915.8715 +ARGENTINA 69817.1451 +set optimizer_switch=@save_optimizer_switch; +delete from mysql.index_stats; +select * from mysql.table_stats; +db_name table_name cardinality +dbt3_s001 customer 150 +dbt3_s001 lineitem 6005 +dbt3_s001 nation 25 +dbt3_s001 orders 1500 +dbt3_s001 part 200 +dbt3_s001 partsupp 700 +dbt3_s001 region 5 +dbt3_s001 supplier 10 +select * from mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 customer PRIMARY 1 1.0000 +dbt3_s001 customer i_c_nationkey 1 6.0000 +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 nation PRIMARY 1 1.0000 +dbt3_s001 nation i_n_regionkey 1 5.0000 +dbt3_s001 orders PRIMARY 1 1.0000 +dbt3_s001 orders i_o_orderdate 1 1.3321 +dbt3_s001 orders i_o_custkey 1 15.0000 +dbt3_s001 part PRIMARY 1 1.0000 +dbt3_s001 part i_p_retailprice 1 1.0000 +dbt3_s001 partsupp PRIMARY 1 3.5000 +dbt3_s001 partsupp PRIMARY 2 1.0000 +dbt3_s001 partsupp i_ps_partkey 1 3.5000 +dbt3_s001 partsupp i_ps_suppkey 1 70.0000 +dbt3_s001 region PRIMARY 1 1.0000 +dbt3_s001 supplier PRIMARY 1 1.0000 +dbt3_s001 supplier i_s_nationkey 1 1.1111 +select * from mysql.table_stats where table_name='orders'; +db_name table_name cardinality +dbt3_s001 orders 1500 +select * from mysql.index_stats where table_name='orders'; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 orders PRIMARY 1 1.0000 +dbt3_s001 orders i_o_orderdate 1 1.3321 +dbt3_s001 orders i_o_custkey 1 15.0000 +select (select cardinality from mysql.table_stats where table_name='orders') / +(select avg_frequency from mysql.index_stats +where index_name='i_o_orderdate' and prefix_arity=1) as n_distinct; +n_distinct +1126.0416 +select count(distinct o_orderdate) from orders; +count(distinct o_orderdate) +1126 +select (select cardinality from mysql.table_stats where table_name='orders') / +(select avg_frequency from mysql.index_stats +where index_name='i_o_custkey' and prefix_arity=1) as n_distinct; +n_distinct +100.0000 +select count(distinct o_custkey) from orders; +count(distinct o_custkey) +100 +show index from orders; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +orders 0 PRIMARY 1 o_orderkey A 1500 NULL NULL BTREE +orders 1 i_o_orderdate 1 o_orderDATE A 1126 NULL NULL YES BTREE +orders 1 i_o_custkey 1 o_custkey A 100 NULL NULL YES BTREE +select index_name, column_name, cardinality from information_schema.statistics +where table_name='orders'; +index_name column_name cardinality +PRIMARY o_orderkey 1500 +i_o_orderdate o_orderDATE 1126 +i_o_custkey o_custkey 100 +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +EXPLAIN select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey +and l_suppkey = s_suppkey and c_nationkey = s_nationkey +and s_nationkey = n_nationkey and n_regionkey = r_regionkey +and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 179 Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +1 SIMPLE nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1 +1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +1 SIMPLE supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.lineitem.l_suppkey 1 Using where +select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey +and l_suppkey = s_suppkey and c_nationkey = s_nationkey +and s_nationkey = n_nationkey and n_regionkey = r_regionkey +and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; +n_name revenue +PERU 321915.8715 +ARGENTINA 69817.1451 +set optimizer_switch=@save_optimizer_switch; +EXPLAIN select o_year, +sum(case when nation = 'UNITED STATES' then volume else 0 end) / +sum(volume) as mkt_share +from (select extract(year from o_orderdate) as o_year, +l_extendedprice * (1-l_discount) as volume, +n2.n_name as nation +from part, supplier, lineitem, orders, customer, +nation n1, nation n2, region +where p_partkey = l_partkey and s_suppkey = l_suppkey +and l_orderkey = o_orderkey and o_custkey = c_custkey +and c_nationkey = n1.n_nationkey and n1.n_regionkey = r_regionkey +and r_name = 'AMERICA' and s_nationkey = n2.n_nationkey +and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'STANDARD BRUSHED STEEL' ) as all_nations +group by o_year +order by o_year; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders ALL PRIMARY,i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +1 SIMPLE n1 eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1 +1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +1 SIMPLE part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where +1 SIMPLE supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.lineitem.l_suppkey 1 Using where +1 SIMPLE n2 eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 +select o_year, +sum(case when nation = 'UNITED STATES' then volume else 0 end) / +sum(volume) as mkt_share +from (select extract(year from o_orderdate) as o_year, +l_extendedprice * (1-l_discount) as volume, +n2.n_name as nation +from part, supplier, lineitem, orders, customer, +nation n1, nation n2, region +where p_partkey = l_partkey and s_suppkey = l_suppkey +and l_orderkey = o_orderkey and o_custkey = c_custkey +and c_nationkey = n1.n_nationkey and n1.n_regionkey = r_regionkey +and r_name = 'AMERICA' and s_nationkey = n2.n_nationkey +and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'STANDARD BRUSHED STEEL' ) as all_nations +group by o_year +order by o_year; +o_year mkt_share +1995 0.4495521838895718 +1996 0.024585468215352495 +EXPLAIN select nation, o_year, sum(amount) as sum_profit +from (select n_name as nation, +extract(year from o_orderdate) as o_year, +l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount +from part, supplier, lineitem, partsupp, orders, nation +where s_suppkey = l_suppkey and ps_suppkey = l_suppkey +and ps_partkey = l_partkey and p_partkey = l_partkey +and o_orderkey = l_orderkey and s_nationkey = n_nationkey +and p_name like '%green%') as profit +group by nation, o_year +order by nation, o_year desc; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE supplier ALL PRIMARY,i_s_nationkey NULL NULL NULL 10 Using where; Using temporary; Using filesort +1 SIMPLE nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 +1 SIMPLE partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 70 +1 SIMPLE part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.supplier.s_suppkey 8 +1 SIMPLE orders eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 +select nation, o_year, sum(amount) as sum_profit +from (select n_name as nation, +extract(year from o_orderdate) as o_year, +l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount +from part, supplier, lineitem, partsupp, orders, nation +where s_suppkey = l_suppkey and ps_suppkey = l_suppkey +and ps_partkey = l_partkey and p_partkey = l_partkey +and o_orderkey = l_orderkey and s_nationkey = n_nationkey +and p_name like '%green%') as profit +group by nation, o_year +order by nation, o_year desc; +nation o_year sum_profit +ARGENTINA 1997 18247.873399999993 +ARGENTINA 1996 7731.089399999995 +ARGENTINA 1995 134490.5697 +ARGENTINA 1994 36767.101500000004 +ARGENTINA 1993 35857.08 +ARGENTINA 1992 35740 +ETHIOPIA 1998 2758.7801999999992 +ETHIOPIA 1997 19419.294599999997 +ETHIOPIA 1995 51231.87439999999 +ETHIOPIA 1994 3578.9478999999974 +ETHIOPIA 1992 1525.8234999999986 +IRAN 1998 37817.229600000006 +IRAN 1997 52643.77359999999 +IRAN 1996 70143.7761 +IRAN 1995 84094.58260000001 +IRAN 1994 18140.925599999995 +IRAN 1993 78655.1676 +IRAN 1992 87142.23960000002 +IRAQ 1998 22860.8082 +IRAQ 1997 93676.24359999999 +IRAQ 1996 45103.3242 +IRAQ 1994 36010.728599999995 +IRAQ 1993 33221.9399 +IRAQ 1992 47755.05900000001 +KENYA 1998 44194.831999999995 +KENYA 1997 57578.36259999999 +KENYA 1996 59195.90210000001 +KENYA 1995 79262.6278 +KENYA 1994 102360.66609999999 +KENYA 1993 128422.0196 +KENYA 1992 181517.2089 +MOROCCO 1998 41797.823199999984 +MOROCCO 1997 23685.801799999994 +MOROCCO 1996 62115.19579999998 +MOROCCO 1995 42442.64300000001 +MOROCCO 1994 48655.878000000004 +MOROCCO 1993 22926.744400000003 +MOROCCO 1992 32239.8088 +PERU 1998 86999.36459999997 +PERU 1997 121110.41070000001 +PERU 1996 177040.40759999995 +PERU 1995 122247.94520000002 +PERU 1994 88046.25329999998 +PERU 1993 49379.813799999996 +PERU 1992 80646.86050000001 +UNITED KINGDOM 1998 50577.25560000001 +UNITED KINGDOM 1997 114288.8605 +UNITED KINGDOM 1996 147684.46480000002 +UNITED KINGDOM 1995 225267.65759999998 +UNITED KINGDOM 1994 140595.5864 +UNITED KINGDOM 1993 322548.49210000003 +UNITED KINGDOM 1992 67747.88279999999 +UNITED STATES 1998 3957.0431999999996 +UNITED STATES 1997 94729.5704 +UNITED STATES 1996 79297.85670000002 +UNITED STATES 1995 62201.23360000001 +UNITED STATES 1994 43075.629899999985 +UNITED STATES 1993 27168.486199999996 +UNITED STATES 1992 34092.366 +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=on'; +EXPLAIN select o_orderkey, p_partkey +from part, lineitem, orders +where p_retailprice > 1100 and o_orderdate='1997-01-01' +and o_orderkey=l_orderkey and p_partkey=l_partkey; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders ref PRIMARY,i_o_orderdate i_o_orderdate 4 const 1 +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +1 SIMPLE part eq_ref PRIMARY,i_p_retailprice PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where +select o_orderkey, p_partkey +from part, lineitem, orders +where p_retailprice > 1100 and o_orderdate='1997-01-01' +and o_orderkey=l_orderkey and p_partkey=l_partkey; +o_orderkey p_partkey +5895 200 +set optimizer_switch=@save_optimizer_switch; +DROP DATABASE dbt3_s001; +use test; +# +# Bug mdev-473: ANALYZE table locked for write +# +set use_stat_tables='complementary'; +create table t1 (i int); +lock table t1 write; +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +alter table t1 add column a varchar(8); +drop table t1; +# +# Bug mdev-487: memory leak in ANALYZE with stat tables +# +SET use_stat_tables = 'preferably'; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +DELETE FROM t1 WHERE a=1; +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +DROP TABLE t1; +# +# Bug mdev-518: corrupted/missing statistical tables +# +CREATE TABLE t1 (i int) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +FLUSH TABLE t1; +SET use_stat_tables='never'; +EXPLAIN SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 +FLUSH TABLES; +SET use_stat_tables='preferably'; +EXPLAIN SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 +DROP TABLE t1; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-5204: invalid impossible where after reading const tables +# when use_stat_tables = 'preferably' +# +set use_stat_tables = 'preferably'; +CREATE TABLE t1 (id int PRIMARY KEY) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +CREATE TABLE t2 (name char(3)) ENGINE=MyISAM; +ANALYZE TABLE t2; +Table Op Msg_type Msg_text +test.t2 analyze status Table is already up to date +INSERT INTO t2 VALUES ('USA'),('AUS'); +SELECT * FROM t1 STRAIGHT_JOIN t2 WHERE name IN ( 'AUS','YEM' ) AND id = 1; +id name +1 AUS +EXPLAIN +SELECT * FROM t1 STRAIGHT_JOIN t2 WHERE name IN ( 'AUS','YEM' ) AND id = 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 Using index +1 SIMPLE t2 ALL NULL NULL NULL NULL 0 Using where +ANALYZE TABLE t2; +Table Op Msg_type Msg_text +test.t2 analyze status OK +SELECT * FROM t1 STRAIGHT_JOIN t2 WHERE name IN ( 'AUS','YEM' ) AND id = 1; +id name +1 AUS +EXPLAIN +SELECT * FROM t1 STRAIGHT_JOIN t2 WHERE name IN ( 'AUS','YEM' ) AND id = 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 Using index +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where +DROP TABLE t1,t2; +set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/r/stat_tables_disabled.result b/mysql-test/r/stat_tables_disabled.result new file mode 100644 index 00000000000..f57abc34e0c --- /dev/null +++ b/mysql-test/r/stat_tables_disabled.result @@ -0,0 +1,70 @@ +SET SESSION STORAGE_ENGINE='InnoDB'; +select @@global.use_stat_tables; +@@global.use_stat_tables +NEVER +select @@session.use_stat_tables; +@@session.use_stat_tables +NEVER +set @save_use_stat_tables=@@use_stat_tables; +set use_stat_tables='preferably'; +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=off'; +# +# Bug mdev-503: optimizer ignores setting use_stat_tables='preferably' +# +flush tables +customer, lineitem, nation, orders, part, partsupp, region, supplier; +set use_stat_tables='never'; +EXPLAIN select sql_calc_found_rows straight_join +l_orderkey, sum(l_extendedprice*(1-l_discount)) as revenue, +o_orderdate, o_shippriority +from orders, customer, lineitem +where c_mktsegment = 'BUILDING' and c_custkey = o_custkey +and l_orderkey = o_orderkey and o_orderdate < date '1995-03-15' + and l_shipdate > date '1995-03-15' +group by l_orderkey, o_orderdate, o_shippriority +order by revenue desc, o_orderdate +limit 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders ALL PRIMARY,i_o_orderdate,i_o_custkey NULL NULL NULL # Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey # Using where +1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey # Using where +set use_stat_tables='preferably'; +EXPLAIN select sql_calc_found_rows straight_join +l_orderkey, sum(l_extendedprice*(1-l_discount)) as revenue, +o_orderdate, o_shippriority +from orders, customer, lineitem +where c_mktsegment = 'BUILDING' and c_custkey = o_custkey +and l_orderkey = o_orderkey and o_orderdate < date '1995-03-15' + and l_shipdate > date '1995-03-15' +group by l_orderkey, o_orderdate, o_shippriority +order by revenue desc, o_orderdate +limit 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders ALL PRIMARY,i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +flush tables customer, orders, lineitem; +EXPLAIN select sql_calc_found_rows straight_join +l_orderkey, sum(l_extendedprice*(1-l_discount)) as revenue, +o_orderdate, o_shippriority +from orders, customer, lineitem +where c_mktsegment = 'BUILDING' and c_custkey = o_custkey +and l_orderkey = o_orderkey and o_orderdate < date '1995-03-15' + and l_shipdate > date '1995-03-15' +group by l_orderkey, o_orderdate, o_shippriority +order by revenue desc, o_orderdate +limit 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders ALL PRIMARY,i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +# End of the test case for mdev-503 +set optimizer_switch=@save_optimizer_switch; +DROP DATABASE dbt3_s001; +use test; +set use_stat_tables=@save_use_stat_tables; +SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/r/stat_tables_innodb.result b/mysql-test/r/stat_tables_innodb.result new file mode 100644 index 00000000000..c601271c4d0 --- /dev/null +++ b/mysql-test/r/stat_tables_innodb.result @@ -0,0 +1,448 @@ +SET SESSION STORAGE_ENGINE='InnoDB'; +set @save_optimizer_switch_for_stat_tables_test=@@optimizer_switch; +set optimizer_switch='extended_keys=on'; +select @@global.use_stat_tables; +@@global.use_stat_tables +COMPLEMENTARY +select @@session.use_stat_tables; +@@session.use_stat_tables +COMPLEMENTARY +set @save_use_stat_tables=@@use_stat_tables; +set use_stat_tables='preferably'; +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=off'; +select * from mysql.table_stats; +db_name table_name cardinality +dbt3_s001 customer 150 +dbt3_s001 lineitem 6005 +dbt3_s001 nation 25 +dbt3_s001 orders 1500 +dbt3_s001 part 200 +dbt3_s001 partsupp 700 +dbt3_s001 region 5 +dbt3_s001 supplier 10 +select * from mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 customer PRIMARY 1 1.0000 +dbt3_s001 customer i_c_nationkey 1 6.0000 +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 nation PRIMARY 1 1.0000 +dbt3_s001 nation i_n_regionkey 1 5.0000 +dbt3_s001 orders PRIMARY 1 1.0000 +dbt3_s001 orders i_o_orderdate 1 1.3321 +dbt3_s001 orders i_o_custkey 1 15.0000 +dbt3_s001 part PRIMARY 1 1.0000 +dbt3_s001 part i_p_retailprice 1 1.0000 +dbt3_s001 partsupp PRIMARY 1 3.5000 +dbt3_s001 partsupp PRIMARY 2 1.0000 +dbt3_s001 partsupp i_ps_partkey 1 3.5000 +dbt3_s001 partsupp i_ps_suppkey 1 70.0000 +dbt3_s001 region PRIMARY 1 1.0000 +dbt3_s001 supplier PRIMARY 1 1.0000 +dbt3_s001 supplier i_s_nationkey 1 1.1111 +set optimizer_switch=@save_optimizer_switch; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +EXPLAIN select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey +and l_suppkey = s_suppkey and c_nationkey = s_nationkey +and s_nationkey = n_nationkey and n_regionkey = r_regionkey +and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 211 Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +1 SIMPLE nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1 +1 SIMPLE supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.customer.c_nationkey 1 Using index +1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey +and l_suppkey = s_suppkey and c_nationkey = s_nationkey +and s_nationkey = n_nationkey and n_regionkey = r_regionkey +and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; +n_name revenue +PERU 321915.8715 +ARGENTINA 69817.1451 +set optimizer_switch=@save_optimizer_switch; +delete from mysql.index_stats; +select * from mysql.table_stats; +db_name table_name cardinality +dbt3_s001 customer 150 +dbt3_s001 lineitem 6005 +dbt3_s001 nation 25 +dbt3_s001 orders 1500 +dbt3_s001 part 200 +dbt3_s001 partsupp 700 +dbt3_s001 region 5 +dbt3_s001 supplier 10 +select * from mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 customer PRIMARY 1 1.0000 +dbt3_s001 customer i_c_nationkey 1 6.0000 +dbt3_s001 customer i_c_nationkey 2 1.0000 +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_shipdate 2 1.0149 +dbt3_s001 lineitem i_l_shipdate 3 1.0000 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 3 1.0030 +dbt3_s001 lineitem i_l_suppkey_partkey 4 1.0000 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_partkey 2 1.0089 +dbt3_s001 lineitem i_l_partkey 3 1.0000 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey 2 1.2073 +dbt3_s001 lineitem i_l_suppkey 3 1.0000 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_receiptdate 2 1.0152 +dbt3_s001 lineitem i_l_receiptdate 3 1.0000 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey 2 1.0000 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_orderkey_quantity 3 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_commitdate 2 1.0364 +dbt3_s001 lineitem i_l_commitdate 3 1.0000 +dbt3_s001 nation PRIMARY 1 1.0000 +dbt3_s001 nation i_n_regionkey 1 5.0000 +dbt3_s001 nation i_n_regionkey 2 1.0000 +dbt3_s001 orders PRIMARY 1 1.0000 +dbt3_s001 orders i_o_orderdate 1 1.3321 +dbt3_s001 orders i_o_orderdate 2 1.0000 +dbt3_s001 orders i_o_custkey 1 15.0000 +dbt3_s001 orders i_o_custkey 2 1.0000 +dbt3_s001 part PRIMARY 1 1.0000 +dbt3_s001 part i_p_retailprice 1 1.0000 +dbt3_s001 part i_p_retailprice 2 1.0000 +dbt3_s001 partsupp PRIMARY 1 3.5000 +dbt3_s001 partsupp PRIMARY 2 1.0000 +dbt3_s001 partsupp i_ps_partkey 1 3.5000 +dbt3_s001 partsupp i_ps_partkey 2 1.0000 +dbt3_s001 partsupp i_ps_suppkey 1 70.0000 +dbt3_s001 partsupp i_ps_suppkey 2 1.0000 +dbt3_s001 region PRIMARY 1 1.0000 +dbt3_s001 supplier PRIMARY 1 1.0000 +dbt3_s001 supplier i_s_nationkey 1 1.1111 +dbt3_s001 supplier i_s_nationkey 2 1.0000 +select * from mysql.table_stats where table_name='orders'; +db_name table_name cardinality +dbt3_s001 orders 1500 +select * from mysql.index_stats where table_name='orders'; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 orders PRIMARY 1 1.0000 +dbt3_s001 orders i_o_orderdate 1 1.3321 +dbt3_s001 orders i_o_orderdate 2 1.0000 +dbt3_s001 orders i_o_custkey 1 15.0000 +dbt3_s001 orders i_o_custkey 2 1.0000 +select (select cardinality from mysql.table_stats where table_name='orders') / +(select avg_frequency from mysql.index_stats +where index_name='i_o_orderdate' and prefix_arity=1) as n_distinct; +n_distinct +1126.0416 +select count(distinct o_orderdate) from orders; +count(distinct o_orderdate) +1126 +select (select cardinality from mysql.table_stats where table_name='orders') / +(select avg_frequency from mysql.index_stats +where index_name='i_o_custkey' and prefix_arity=1) as n_distinct; +n_distinct +100.0000 +select count(distinct o_custkey) from orders; +count(distinct o_custkey) +100 +show index from orders; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +orders 0 PRIMARY 1 o_orderkey A 1500 NULL NULL BTREE +orders 1 i_o_orderdate 1 o_orderDATE A 1126 NULL NULL YES BTREE +orders 1 i_o_custkey 1 o_custkey A 100 NULL NULL YES BTREE +select index_name, column_name, cardinality from information_schema.statistics +where table_name='orders'; +index_name column_name cardinality +PRIMARY o_orderkey 1500 +i_o_orderdate o_orderDATE 1126 +i_o_custkey o_custkey 100 +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='index_condition_pushdown=off'; +EXPLAIN select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey +and l_suppkey = s_suppkey and c_nationkey = s_nationkey +and s_nationkey = n_nationkey and n_regionkey = r_regionkey +and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_custkey i_o_orderdate 4 NULL 211 Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +1 SIMPLE nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1 +1 SIMPLE supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.customer.c_nationkey 1 Using index +1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +select n_name, sum(l_extendedprice * (1 - l_discount)) as revenue +from customer, orders, lineitem, supplier, nation, region +where c_custkey = o_custkey and l_orderkey = o_orderkey +and l_suppkey = s_suppkey and c_nationkey = s_nationkey +and s_nationkey = n_nationkey and n_regionkey = r_regionkey +and r_name = 'AMERICA' and o_orderdate >= date '1995-01-01' + and o_orderdate < date '1995-01-01' + interval '1' year +group by n_name +order by revenue desc; +n_name revenue +PERU 321915.8715 +ARGENTINA 69817.1451 +set optimizer_switch=@save_optimizer_switch; +EXPLAIN select o_year, +sum(case when nation = 'UNITED STATES' then volume else 0 end) / +sum(volume) as mkt_share +from (select extract(year from o_orderdate) as o_year, +l_extendedprice * (1-l_discount) as volume, +n2.n_name as nation +from part, supplier, lineitem, orders, customer, +nation n1, nation n2, region +where p_partkey = l_partkey and s_suppkey = l_suppkey +and l_orderkey = o_orderkey and o_custkey = c_custkey +and c_nationkey = n1.n_nationkey and n1.n_regionkey = r_regionkey +and r_name = 'AMERICA' and s_nationkey = n2.n_nationkey +and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'STANDARD BRUSHED STEEL' ) as all_nations +group by o_year +order by o_year; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE orders ALL PRIMARY,i_o_orderdate,i_o_custkey NULL NULL NULL 1500 Using where; Using temporary; Using filesort +1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where +1 SIMPLE n1 eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1 +1 SIMPLE region ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +1 SIMPLE part eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_partkey 1 Using where +1 SIMPLE supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.lineitem.l_suppkey 1 Using where +1 SIMPLE n2 eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 +select o_year, +sum(case when nation = 'UNITED STATES' then volume else 0 end) / +sum(volume) as mkt_share +from (select extract(year from o_orderdate) as o_year, +l_extendedprice * (1-l_discount) as volume, +n2.n_name as nation +from part, supplier, lineitem, orders, customer, +nation n1, nation n2, region +where p_partkey = l_partkey and s_suppkey = l_suppkey +and l_orderkey = o_orderkey and o_custkey = c_custkey +and c_nationkey = n1.n_nationkey and n1.n_regionkey = r_regionkey +and r_name = 'AMERICA' and s_nationkey = n2.n_nationkey +and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = 'STANDARD BRUSHED STEEL' ) as all_nations +group by o_year +order by o_year; +o_year mkt_share +1995 0.4495521838895718 +1996 0.024585468215352495 +EXPLAIN select nation, o_year, sum(amount) as sum_profit +from (select n_name as nation, +extract(year from o_orderdate) as o_year, +l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount +from part, supplier, lineitem, partsupp, orders, nation +where s_suppkey = l_suppkey and ps_suppkey = l_suppkey +and ps_partkey = l_partkey and p_partkey = l_partkey +and o_orderkey = l_orderkey and s_nationkey = n_nationkey +and p_name like '%green%') as profit +group by nation, o_year +order by nation, o_year desc; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE supplier index PRIMARY,i_s_nationkey i_s_nationkey 5 NULL 10 Using where; Using index; Using temporary; Using filesort +1 SIMPLE nation eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 +1 SIMPLE partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey i_ps_suppkey 4 dbt3_s001.supplier.s_suppkey 70 +1 SIMPLE part eq_ref PRIMARY PRIMARY 4 dbt3_s001.partsupp.ps_partkey 1 Using where +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey,i_l_orderkey,i_l_orderkey_quantity i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.supplier.s_suppkey 8 +1 SIMPLE orders eq_ref PRIMARY PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 +select nation, o_year, sum(amount) as sum_profit +from (select n_name as nation, +extract(year from o_orderdate) as o_year, +l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount +from part, supplier, lineitem, partsupp, orders, nation +where s_suppkey = l_suppkey and ps_suppkey = l_suppkey +and ps_partkey = l_partkey and p_partkey = l_partkey +and o_orderkey = l_orderkey and s_nationkey = n_nationkey +and p_name like '%green%') as profit +group by nation, o_year +order by nation, o_year desc; +nation o_year sum_profit +ARGENTINA 1997 18247.873399999993 +ARGENTINA 1996 7731.089399999995 +ARGENTINA 1995 134490.5697 +ARGENTINA 1994 36767.101500000004 +ARGENTINA 1993 35857.08 +ARGENTINA 1992 35740 +ETHIOPIA 1998 2758.7801999999992 +ETHIOPIA 1997 19419.294599999997 +ETHIOPIA 1995 51231.87439999999 +ETHIOPIA 1994 3578.9478999999974 +ETHIOPIA 1992 1525.8234999999986 +IRAN 1998 37817.229600000006 +IRAN 1997 52643.77359999999 +IRAN 1996 70143.7761 +IRAN 1995 84094.58260000001 +IRAN 1994 18140.925599999995 +IRAN 1993 78655.1676 +IRAN 1992 87142.23960000002 +IRAQ 1998 22860.8082 +IRAQ 1997 93676.24359999999 +IRAQ 1996 45103.3242 +IRAQ 1994 36010.728599999995 +IRAQ 1993 33221.9399 +IRAQ 1992 47755.05900000001 +KENYA 1998 44194.831999999995 +KENYA 1997 57578.36259999999 +KENYA 1996 59195.90210000001 +KENYA 1995 79262.6278 +KENYA 1994 102360.66609999999 +KENYA 1993 128422.0196 +KENYA 1992 181517.2089 +MOROCCO 1998 41797.823199999984 +MOROCCO 1997 23685.801799999994 +MOROCCO 1996 62115.19579999998 +MOROCCO 1995 42442.64300000001 +MOROCCO 1994 48655.878000000004 +MOROCCO 1993 22926.744400000003 +MOROCCO 1992 32239.8088 +PERU 1998 86999.36459999997 +PERU 1997 121110.41070000001 +PERU 1996 177040.40759999995 +PERU 1995 122247.94520000002 +PERU 1994 88046.25329999998 +PERU 1993 49379.813799999996 +PERU 1992 80646.86050000001 +UNITED KINGDOM 1998 50577.25560000001 +UNITED KINGDOM 1997 114288.8605 +UNITED KINGDOM 1996 147684.46480000002 +UNITED KINGDOM 1995 225267.65759999998 +UNITED KINGDOM 1994 140595.5864 +UNITED KINGDOM 1993 322548.49210000003 +UNITED KINGDOM 1992 67747.88279999999 +UNITED STATES 1998 3957.0431999999996 +UNITED STATES 1997 94729.5704 +UNITED STATES 1996 79297.85670000002 +UNITED STATES 1995 62201.23360000001 +UNITED STATES 1994 43075.629899999985 +UNITED STATES 1993 27168.486199999996 +UNITED STATES 1992 34092.366 +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=on'; +EXPLAIN select o_orderkey, p_partkey +from part, lineitem, orders +where p_retailprice > 1100 and o_orderdate='1997-01-01' +and o_orderkey=l_orderkey and p_partkey=l_partkey; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE part range PRIMARY,i_p_retailprice i_p_retailprice 9 NULL 1 Using where; Using index +1 SIMPLE orders ref PRIMARY,i_o_orderdate i_o_orderdate 4 const 1 Using index +1 SIMPLE lineitem ref PRIMARY,i_l_suppkey_partkey,i_l_partkey,i_l_orderkey,i_l_orderkey_quantity i_l_partkey 9 dbt3_s001.part.p_partkey,dbt3_s001.orders.o_orderkey 1 Using index +select o_orderkey, p_partkey +from part, lineitem, orders +where p_retailprice > 1100 and o_orderdate='1997-01-01' +and o_orderkey=l_orderkey and p_partkey=l_partkey; +o_orderkey p_partkey +5895 200 +set optimizer_switch=@save_optimizer_switch; +DROP DATABASE dbt3_s001; +use test; +# +# Bug mdev-473: ANALYZE table locked for write +# +set use_stat_tables='complementary'; +create table t1 (i int); +lock table t1 write; +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +alter table t1 add column a varchar(8); +drop table t1; +# +# Bug mdev-487: memory leak in ANALYZE with stat tables +# +SET use_stat_tables = 'preferably'; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +DELETE FROM t1 WHERE a=1; +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +DROP TABLE t1; +# +# Bug mdev-518: corrupted/missing statistical tables +# +CREATE TABLE t1 (i int) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +FLUSH TABLE t1; +SET use_stat_tables='never'; +EXPLAIN SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 +FLUSH TABLES; +SET use_stat_tables='preferably'; +EXPLAIN SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 +DROP TABLE t1; +set use_stat_tables=@save_use_stat_tables; +# +# Bug mdev-5204: invalid impossible where after reading const tables +# when use_stat_tables = 'preferably' +# +set use_stat_tables = 'preferably'; +CREATE TABLE t1 (id int PRIMARY KEY) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +CREATE TABLE t2 (name char(3)) ENGINE=MyISAM; +ANALYZE TABLE t2; +Table Op Msg_type Msg_text +test.t2 analyze status Table is already up to date +INSERT INTO t2 VALUES ('USA'),('AUS'); +SELECT * FROM t1 STRAIGHT_JOIN t2 WHERE name IN ( 'AUS','YEM' ) AND id = 1; +id name +1 AUS +EXPLAIN +SELECT * FROM t1 STRAIGHT_JOIN t2 WHERE name IN ( 'AUS','YEM' ) AND id = 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 Using index +1 SIMPLE t2 ALL NULL NULL NULL NULL 0 Using where +ANALYZE TABLE t2; +Table Op Msg_type Msg_text +test.t2 analyze status OK +SELECT * FROM t1 STRAIGHT_JOIN t2 WHERE name IN ( 'AUS','YEM' ) AND id = 1; +id name +1 AUS +EXPLAIN +SELECT * FROM t1 STRAIGHT_JOIN t2 WHERE name IN ( 'AUS','YEM' ) AND id = 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 Using index +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where +DROP TABLE t1,t2; +set use_stat_tables=@save_use_stat_tables; +set optimizer_switch=@save_optimizer_switch_for_stat_tables_test; +SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/r/stat_tables_par.result b/mysql-test/r/stat_tables_par.result new file mode 100644 index 00000000000..a98f934fa96 --- /dev/null +++ b/mysql-test/r/stat_tables_par.result @@ -0,0 +1,242 @@ +set @save_use_stat_tables=@@use_stat_tables; +set use_stat_tables='preferably'; +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=off'; +select * from mysql.table_stats; +db_name table_name cardinality +dbt3_s001 customer 150 +dbt3_s001 lineitem 6005 +dbt3_s001 nation 25 +dbt3_s001 orders 1500 +dbt3_s001 part 200 +dbt3_s001 partsupp 700 +dbt3_s001 region 5 +dbt3_s001 supplier 10 +select * from mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 customer PRIMARY 1 1.0000 +dbt3_s001 customer i_c_nationkey 1 6.0000 +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 nation PRIMARY 1 1.0000 +dbt3_s001 nation i_n_regionkey 1 5.0000 +dbt3_s001 orders PRIMARY 1 1.0000 +dbt3_s001 orders i_o_orderdate 1 1.3321 +dbt3_s001 orders i_o_custkey 1 15.0000 +dbt3_s001 part PRIMARY 1 1.0000 +dbt3_s001 partsupp PRIMARY 1 3.5000 +dbt3_s001 partsupp PRIMARY 2 1.0000 +dbt3_s001 partsupp i_ps_partkey 1 3.5000 +dbt3_s001 partsupp i_ps_suppkey 1 70.0000 +dbt3_s001 region PRIMARY 1 1.0000 +dbt3_s001 supplier PRIMARY 1 1.0000 +dbt3_s001 supplier i_s_nationkey 1 1.1111 +flush table lineitem; +set use_stat_tables='never'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24; +revenue +77949.91860000002 +set debug_sync='statistics_mem_alloc_start1 WAIT_FOR second_thread_started_too'; +set debug_sync='statistics_mem_alloc_start2 SIGNAL first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24 ; +set debug_sync='statistics_mem_alloc_start1 SIGNAL second_thread_started_too'; +set debug_sync='statistics_mem_alloc_start2 WAIT_FOR first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24; +revenue +77949.91860000002 +revenue +77949.91860000002 +set use_stat_tables='preferably'; +set debug_sync='RESET'; +select * from mysql.index_stats where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +delete from mysql.index_stats +where table_name='lineitem' and +index_name in ('i_l_shipdate', 'i_l_receiptdate'); +select * from mysql.index_stats where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +analyze table lineitem persistent for columns() indexes (i_l_shipdate); +select * from mysql.index_stats where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +delete from mysql.index_stats +where table_name='lineitem' and index_name= 'i_l_shipdate'; +select * from mysql.index_stats where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +set debug_sync='statistics_collection_start1 WAIT_FOR second_thread_started_too'; +set debug_sync='statistics_collection_start2 SIGNAL first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +analyze table lineitem persistent for columns() indexes (i_l_shipdate); +set debug_sync='statistics_collection_start1 SIGNAL second_thread_started_too'; +set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +analyze table lineitem persistent for columns() indexes (i_l_receiptdate); +set debug_sync='RESET'; +select * from mysql.index_stats where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +select * from mysql.index_stats where table_name='lineitem' + order by index_name, prefix_arity; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +set debug_sync='RESET'; +set debug_sync='statistics_collection_start SIGNAL parked WAIT_FOR finish'; +use dbt3_s001; +set use_stat_tables='preferably'; +analyze table lineitem persistent for all; +set debug_sync='now WAIT_FOR parked'; +use dbt3_s001; +set use_stat_tables='never'; +set debug_sync='now SIGNAL finish'; +set debug_sync='RESET'; +select * from mysql.index_stats where table_name='lineitem' + order by index_name, prefix_arity; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +set @save_global_use_stat_tables=@@global.use_stat_tables; +set global use_stat_tables='preferably'; +set debug_sync='RESET'; +set debug_sync='statistics_update_start SIGNAL parker WAIT_FOR go1 EXECUTE 1'; +set debug_sync='thr_multi_lock_after_thr_lock SIGNAL go2 EXECUTE 2'; +use dbt3_s001; +analyze table lineitem persistent for all; +set debug_sync='open_and_process_table WAIT_FOR parker'; +set debug_sync='statistics_read_start SIGNAL go1 WAIT_FOR go2'; +use dbt3_s001; +select * from mysql.index_stats, lineitem where index_name= 'i_l_shipdate' and l_orderkey=1 and l_partkey=68; +db_name table_name index_name prefix_arity avg_frequency l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipDATE l_commitDATE l_receiptDATE l_shipinstruct l_shipmode l_comment +dbt3_s001 lineitem i_l_shipdate 1 2.6500 1 68 9 2 36 34850.16 0.09 0.06 N O 1996-04-12 1996-02-28 1996-04-20 TAKE BACK RETURN MAIL slyly bold pinto beans detect s +set debug_sync='RESET'; +set global use_stat_tables=@save_global_use_stat_tables; +DROP DATABASE dbt3_s001; +use test; +set @save_global_use_stat_tables=@@global.use_stat_tables; +set global use_stat_tables='preferably'; +set debug_sync='RESET'; +create table t1 (a int, b int, key(a)); +insert t1 values (1,1),(2,2); +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +SET debug_sync='after_open_table_ignore_flush WAIT_FOR go'; +select * from information_schema.statistics where table_schema='test'; +select * from t1; +a b +1 1 +2 2 +SET DEBUG_SYNC= "now SIGNAL go"; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT INDEX_COMMENT +def test t1 1 test a 1 a A 2 NULL NULL YES BTREE +set debug_sync='RESET'; +drop table t1; +set global use_stat_tables=@save_global_use_stat_tables; +set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/r/stat_tables_par_innodb.result b/mysql-test/r/stat_tables_par_innodb.result new file mode 100644 index 00000000000..e0c00c482a0 --- /dev/null +++ b/mysql-test/r/stat_tables_par_innodb.result @@ -0,0 +1,253 @@ +SET SESSION STORAGE_ENGINE='InnoDB'; +set @save_optimizer_switch_for_stat_tables_test=@@optimizer_switch; +set optimizer_switch='extended_keys=on'; +set @save_use_stat_tables=@@use_stat_tables; +set use_stat_tables='preferably'; +DROP DATABASE IF EXISTS dbt3_s001; +CREATE DATABASE dbt3_s001; +use dbt3_s001; +set @save_optimizer_switch=@@optimizer_switch; +set optimizer_switch='extended_keys=off'; +select * from mysql.table_stats; +db_name table_name cardinality +dbt3_s001 customer 150 +dbt3_s001 lineitem 6005 +dbt3_s001 nation 25 +dbt3_s001 orders 1500 +dbt3_s001 part 200 +dbt3_s001 partsupp 700 +dbt3_s001 region 5 +dbt3_s001 supplier 10 +select * from mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 customer PRIMARY 1 1.0000 +dbt3_s001 customer i_c_nationkey 1 6.0000 +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 nation PRIMARY 1 1.0000 +dbt3_s001 nation i_n_regionkey 1 5.0000 +dbt3_s001 orders PRIMARY 1 1.0000 +dbt3_s001 orders i_o_orderdate 1 1.3321 +dbt3_s001 orders i_o_custkey 1 15.0000 +dbt3_s001 part PRIMARY 1 1.0000 +dbt3_s001 partsupp PRIMARY 1 3.5000 +dbt3_s001 partsupp PRIMARY 2 1.0000 +dbt3_s001 partsupp i_ps_partkey 1 3.5000 +dbt3_s001 partsupp i_ps_suppkey 1 70.0000 +dbt3_s001 region PRIMARY 1 1.0000 +dbt3_s001 supplier PRIMARY 1 1.0000 +dbt3_s001 supplier i_s_nationkey 1 1.1111 +flush table lineitem; +set use_stat_tables='never'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24; +revenue +77949.91860000002 +set debug_sync='statistics_mem_alloc_start1 WAIT_FOR second_thread_started_too'; +set debug_sync='statistics_mem_alloc_start2 SIGNAL first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24 ; +set debug_sync='statistics_mem_alloc_start1 SIGNAL second_thread_started_too'; +set debug_sync='statistics_mem_alloc_start2 WAIT_FOR first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +select sum(l_extendedprice*l_discount) as revenue +from lineitem +where l_shipdate >= date '1994-01-01' +and l_shipdate < date '1994-01-01' + interval '1' year +and l_discount between 0.06 - 0.01 and 0.06 + 0.01 +and l_quantity < 24; +revenue +77949.91860000002 +revenue +77949.91860000002 +set use_stat_tables='preferably'; +set debug_sync='RESET'; +select * from mysql.index_stats where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +delete from mysql.index_stats +where table_name='lineitem' and +index_name in ('i_l_shipdate', 'i_l_receiptdate'); +select * from mysql.index_stats where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +analyze table lineitem persistent for columns() indexes (i_l_shipdate); +select * from mysql.index_stats where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +delete from mysql.index_stats +where table_name='lineitem' and index_name= 'i_l_shipdate'; +select * from mysql.index_stats where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +set debug_sync='statistics_collection_start1 WAIT_FOR second_thread_started_too'; +set debug_sync='statistics_collection_start2 SIGNAL first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +analyze table lineitem persistent for columns() indexes (i_l_shipdate); +set debug_sync='statistics_collection_start1 SIGNAL second_thread_started_too'; +set debug_sync='statistics_collection_start2 WAIT_FOR first_thread_working'; +use dbt3_s001; +set use_stat_tables='preferably'; +analyze table lineitem persistent for columns() indexes (i_l_receiptdate); +set debug_sync='RESET'; +select * from mysql.index_stats where table_name='lineitem' order by index_name; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +select * from mysql.index_stats where table_name='lineitem' + order by index_name, prefix_arity; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0033 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7160 +dbt3_s001 lineitem i_l_orderkey 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0033 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0250 +dbt3_s001 lineitem i_l_receiptdate 1 2.6477 +dbt3_s001 lineitem i_l_shipdate 1 2.6500 +dbt3_s001 lineitem i_l_suppkey 1 600.5000 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0250 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5786 +set debug_sync='RESET'; +set debug_sync='statistics_collection_start SIGNAL parked WAIT_FOR finish'; +use dbt3_s001; +set use_stat_tables='preferably'; +analyze table lineitem persistent for all; +set debug_sync='now WAIT_FOR parked'; +use dbt3_s001; +set use_stat_tables='never'; +select * from lineitem where l_orderkey=1 and l_partkey=156; +l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipDATE l_commitDATE l_receiptDATE l_shipinstruct l_shipmode l_comment +1 156 4 1 17 17954.55 0.04 0.02 N O 1996-03-13 1996-02-12 1996-03-22 DELIVER IN PERSON TRUCK blithely regular ideas caj +delete from lineitem where l_orderkey=1 and l_partkey=156; +select * from lineitem where l_orderkey=1 and l_partkey=156; +l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipDATE l_commitDATE l_receiptDATE l_shipinstruct l_shipmode l_comment +set debug_sync='now SIGNAL finish'; +set debug_sync='RESET'; +select * from mysql.index_stats where table_name='lineitem' + order by index_name, prefix_arity; +db_name table_name index_name prefix_arity avg_frequency +dbt3_s001 lineitem PRIMARY 1 4.0027 +dbt3_s001 lineitem PRIMARY 2 1.0000 +dbt3_s001 lineitem i_l_commitdate 1 2.7155 +dbt3_s001 lineitem i_l_orderkey 1 4.0027 +dbt3_s001 lineitem i_l_orderkey_quantity 1 4.0027 +dbt3_s001 lineitem i_l_orderkey_quantity 2 1.0404 +dbt3_s001 lineitem i_l_partkey 1 30.0200 +dbt3_s001 lineitem i_l_receiptdate 1 2.6473 +dbt3_s001 lineitem i_l_shipdate 1 2.6496 +dbt3_s001 lineitem i_l_suppkey 1 600.4000 +dbt3_s001 lineitem i_l_suppkey_partkey 1 30.0200 +dbt3_s001 lineitem i_l_suppkey_partkey 2 8.5771 +set @save_global_use_stat_tables=@@global.use_stat_tables; +set global use_stat_tables='preferably'; +set debug_sync='RESET'; +set debug_sync='statistics_update_start SIGNAL parker WAIT_FOR go1 EXECUTE 1'; +set debug_sync='thr_multi_lock_after_thr_lock SIGNAL go2 EXECUTE 2'; +use dbt3_s001; +analyze table lineitem persistent for all; +set debug_sync='open_and_process_table WAIT_FOR parker'; +set debug_sync='statistics_read_start SIGNAL go1 WAIT_FOR go2'; +use dbt3_s001; +select * from mysql.index_stats, lineitem where index_name= 'i_l_shipdate' and l_orderkey=1 and l_partkey=68; +db_name table_name index_name prefix_arity avg_frequency l_orderkey l_partkey l_suppkey l_linenumber l_quantity l_extendedprice l_discount l_tax l_returnflag l_linestatus l_shipDATE l_commitDATE l_receiptDATE l_shipinstruct l_shipmode l_comment +dbt3_s001 lineitem i_l_shipdate 1 2.6496 1 68 9 2 36 34850.16 0.09 0.06 N O 1996-04-12 1996-02-28 1996-04-20 TAKE BACK RETURN MAIL slyly bold pinto beans detect s +set debug_sync='RESET'; +set global use_stat_tables=@save_global_use_stat_tables; +DROP DATABASE dbt3_s001; +use test; +set @save_global_use_stat_tables=@@global.use_stat_tables; +set global use_stat_tables='preferably'; +set debug_sync='RESET'; +create table t1 (a int, b int, key(a)); +insert t1 values (1,1),(2,2); +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +SET debug_sync='after_open_table_ignore_flush WAIT_FOR go'; +select * from information_schema.statistics where table_schema='test'; +select * from t1; +a b +1 1 +2 2 +SET DEBUG_SYNC= "now SIGNAL go"; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT INDEX_COMMENT +def test t1 1 test a 1 a A 2 NULL NULL YES BTREE +set debug_sync='RESET'; +drop table t1; +set global use_stat_tables=@save_global_use_stat_tables; +set use_stat_tables=@save_use_stat_tables; +set optimizer_switch=@save_optimizer_switch_for_stat_tables_test; +SET SESSION STORAGE_ENGINE=DEFAULT; diff --git a/mysql-test/r/stat_tables_partition.result b/mysql-test/r/stat_tables_partition.result new file mode 100644 index 00000000000..75454b61fe0 --- /dev/null +++ b/mysql-test/r/stat_tables_partition.result @@ -0,0 +1,12 @@ +# +# Bug mdev-3866: valgrind complain from ANALYZE on a table with BIT field +# +SET use_stat_tables = 'preferably'; +CREATE TABLE t1 (pk int PRIMARY KEY, a bit(1), INDEX idx(a) +) ENGINE=MyISAM PARTITION BY KEY(pk) PARTITIONS 2; +INSERT INTO t1 VALUES (1,1),(2,0),(3,0),(4,1); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +SET use_stat_tables = DEFAULT; +DROP TABLE t1; diff --git a/mysql-test/r/stat_tables_rbr.result b/mysql-test/r/stat_tables_rbr.result new file mode 100644 index 00000000000..0c941bcb248 --- /dev/null +++ b/mysql-test/r/stat_tables_rbr.result @@ -0,0 +1,32 @@ +# +# Bug mdev-463: assertion failure when running ANALYZE with RBR on +# +SET GLOBAL use_stat_tables = PREFERABLY; +CREATE TABLE t1 (i INT) ENGINE=InnoDB; +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +DROP TABLE t1; +SET GLOBAL use_stat_tables = DEFAULT; +SET use_stat_tables = PREFERABLY; +CREATE TABLE t1 ( a INT ) ENGINE=MyISAM PARTITION BY HASH(a) PARTITIONS 2; +ALTER TABLE t1 ANALYZE PARTITION p1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +SHOW BINLOG EVENTS; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 4 Format_desc 1 248 Server ver: #, Binlog ver: # +master-bin.000001 248 Gtid_list 1 273 [] +master-bin.000001 273 Binlog_checkpoint 1 313 master-bin.000001 +master-bin.000001 313 Gtid 1 351 GTID 0-1-1 +master-bin.000001 351 Query 1 451 use `test`; CREATE TABLE t1 (i INT) ENGINE=InnoDB +master-bin.000001 451 Gtid 1 489 GTID 0-1-2 +master-bin.000001 489 Query 1 568 use `test`; ANALYZE TABLE t1 +master-bin.000001 568 Gtid 1 606 GTID 0-1-3 +master-bin.000001 606 Query 1 710 use `test`; DROP TABLE `t1` /* generated by server */ +master-bin.000001 710 Gtid 1 748 GTID 0-1-4 +master-bin.000001 748 Query 1 884 use `test`; CREATE TABLE t1 ( a INT ) ENGINE=MyISAM PARTITION BY HASH(a) PARTITIONS 2 +master-bin.000001 884 Gtid 1 922 GTID 0-1-5 +master-bin.000001 922 Query 1 1020 use `test`; ALTER TABLE t1 ANALYZE PARTITION p1 +SET use_stat_tables = DEFAULT; +DROP TABLE t1; diff --git a/mysql-test/r/stat_tables_repl.result b/mysql-test/r/stat_tables_repl.result new file mode 100644 index 00000000000..370b8c59db1 --- /dev/null +++ b/mysql-test/r/stat_tables_repl.result @@ -0,0 +1,41 @@ +include/master-slave.inc +[connection master] +# +# Bug mdev-485: unexpected failure with replication of DROP/ALTER table +# when RBR is on +# +CREATE TABLE t1 ( a int, b int ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,20), (1,20), (3,30); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +DROP TABLE t1; +CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,20), (1,20), (3,30); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +DROP INDEX idx1 ON t1; +DROP TABLE t1; +CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,20), (1,20), (3,30); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +ALTER TABLE t1 DROP COLUMN b; +DROP TABLE t1; +CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,20), (1,20), (3,30); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +ALTER TABLE t1 RENAME to s; +DROP TABLE s; +CREATE TABLE t1 ( a int, b int, INDEX idx1(b) ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (2,20), (1,20), (3,30); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +ALTER TABLE t1 CHANGE COLUMN b c int ; +DROP TABLE t1; +include/rpl_end.inc diff --git a/mysql-test/r/statistics.result b/mysql-test/r/statistics.result new file mode 100644 index 00000000000..640a2f649d6 --- /dev/null +++ b/mysql-test/r/statistics.result @@ -0,0 +1,1590 @@ +drop table if exists t1,t2; +set @save_use_stat_tables=@@use_stat_tables; +DELETE FROM mysql.table_stats; +DELETE FROM mysql.column_stats; +DELETE FROM mysql.index_stats; +set use_stat_tables='preferably'; +CREATE TABLE t1 ( +a int NOT NULL PRIMARY KEY, +b varchar(32), +c char(16), +d date, +e double, +f bit(3), +INDEX idx1 (b, e), +INDEX idx2 (c, d), +INDEX idx3 (d), +INDEX idx4 (e, b, d) +) ENGINE= MYISAM; +INSERT INTO t1 VALUES +(0, NULL, NULL, NULL, NULL, NULL), +(7, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'dddddddd', '1990-05-15', 0.1, b'100'), +(17, 'vvvvvvvvvvvvv', 'aaaa', '1989-03-12', 0.01, b'101'), +(1, 'vvvvvvvvvvvvv', NULL, '1989-03-12', 0.01, b'100'), +(12, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1999-07-23', 0.112, b'001'), +(23, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.1, b'100'), +(8, 'vvvvvvvvvvvvv', 'aaaa', '1999-07-23', 0.1, b'100'), +(22, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'aaaa', '1989-03-12', 0.112, b'001'), +(31, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'aaaa', '1999-07-23', 0.01, b'001'), +(10, NULL, 'aaaa', NULL, 0.01, b'010'), +(5, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1999-07-23', 0.1, b'100'), +(15, 'vvvvvvvvvvvvv', 'ccccccccc', '1990-05-15', 0.1, b'010'), +(30, NULL, 'bbbbbb', NULL, NULL, b'100'), +(38, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', NULL, NULL, NULL), +(18, 'zzzzzzzzzzzzzzzzzz', 'ccccccccc', '1990-05-15', 0.01, b'010'), +(9, 'yyy', 'bbbbbb', '1998-08-28', 0.01, NULL), +(29, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.012, b'010'), +(3, 'yyy', 'dddddddd', '1990-05-15', 0.112, b'010'), +(39, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', NULL, 0.01, b'100'), +(14, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'ccccccccc', '1990-05-15', 0.1, b'100'), +(40, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb', '1989-03-12', NULL, NULL), +(44, NULL, 'aaaa', '1989-03-12', NULL, b'010'), +(19, 'vvvvvvvvvvvvv', 'ccccccccc', '1990-05-15', 0.012, b'011'), +(21, 'zzzzzzzzzzzzzzzzzz', 'dddddddd', '1989-03-12', 0.112, b'100'), +(45, NULL, NULL, '1989-03-12', NULL, b'011'), +(2, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'ccccccccc', '1990-05-15', 0.1, b'001'), +(35, 'yyy', 'aaaa', '1990-05-15', 0.05, b'011'), +(4, 'vvvvvvvvvvvvv', 'dddddddd', '1999-07-23', 0.01, b'101'), +(47, NULL, 'aaaa', '1990-05-15', 0.05, b'010'), +(42, NULL, 'ccccccccc', '1989-03-12', 0.01, b'010'), +(32, NULL, 'bbbbbb', '1990-05-15', 0.01, b'011'), +(49, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww' , 'aaaa', '1990-05-15', NULL, NULL), +(43, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww' , 'bbbbbb', '1990-05-15', NULL, b'100'), +(37, 'yyy', NULL, '1989-03-12', 0.05, b'011'), +(41, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'ccccccccc', '1990-05-15', 0.05, NULL), +(34, 'yyy', NULL, NULL, NULL, NULL), +(33, 'zzzzzzzzzzzzzzzzzz', 'dddddddd', '1989-03-12', 0.05, b'011'), +(24, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd', '1990-05-15', 0.01, b'101'), +(11, 'yyy', 'ccccccccc', '1999-07-23', 0.1, NULL), +(25, 'zzzzzzzzzzzzzzzzzz', 'bbb', '1989-03-12', 0.01, b'101'); +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +SELECT * FROM mysql.table_stats; +db_name table_name cardinality +test t1 40 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx1 1 6.4000 +test t1 idx1 2 1.6875 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +SELECT COUNT(*) FROM t1; +COUNT(*) +40 +SELECT * FROM mysql.column_stats +WHERE db_name='test' AND table_name='t1' AND column_name='a'; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +SELECT MIN(t1.a), MAX(t1.a), +(SELECT COUNT(*) FROM t1 WHERE t1.b IS NULL) / +(SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.a)", +(SELECT COUNT(t1.a) FROM t1) / +(SELECT COUNT(DISTINCT t1.a) FROM t1) AS "AVG_FREQUENCY(t1.a)" +FROM t1; +MIN(t1.a) MAX(t1.a) NULLS_RATIO(t1.a) AVG_FREQUENCY(t1.a) +0 49 0.2000 1.0000 +SELECT * FROM mysql.column_stats +WHERE db_name='test' AND table_name='t1' AND column_name='b'; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +SELECT MIN(t1.b), MAX(t1.b), +(SELECT COUNT(*) FROM t1 WHERE t1.b IS NULL) / +(SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.b)", +(SELECT COUNT(t1.b) FROM t1) / +(SELECT COUNT(DISTINCT t1.b) FROM t1) AS "AVG_FREQUENCY(t1.b)" +FROM t1; +MIN(t1.b) MAX(t1.b) NULLS_RATIO(t1.b) AVG_FREQUENCY(t1.b) +vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 6.4000 +SELECT * FROM mysql.column_stats +WHERE db_name='test' AND table_name='t1' AND column_name='c'; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +SELECT MIN(t1.c), MAX(t1.c), +(SELECT COUNT(*) FROM t1 WHERE t1.c IS NULL) / +(SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.c)", +(SELECT COUNT(t1.c) FROM t1) / +(SELECT COUNT(DISTINCT t1.c) FROM t1) AS "AVG_FREQUENCY(t1.c)" +FROM t1; +MIN(t1.c) MAX(t1.c) NULLS_RATIO(t1.c) AVG_FREQUENCY(t1.c) +aaaa dddddddd 0.1250 7.0000 +SELECT * FROM mysql.column_stats +WHERE db_name='test' AND table_name='t1' AND column_name='d'; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +SELECT MIN(t1.d), MAX(t1.d), +(SELECT COUNT(*) FROM t1 WHERE t1.d IS NULL) / +(SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.d)", +(SELECT COUNT(t1.d) FROM t1) / +(SELECT COUNT(DISTINCT t1.d) FROM t1) AS "AVG_FREQUENCY(t1.d)" +FROM t1; +MIN(t1.d) MAX(t1.d) NULLS_RATIO(t1.d) AVG_FREQUENCY(t1.d) +1989-03-12 1999-07-23 0.1500 8.5000 +SELECT * FROM mysql.column_stats +WHERE db_name='test' AND table_name='t1' AND column_name='e'; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +SELECT MIN(t1.e), MAX(t1.e), +(SELECT COUNT(*) FROM t1 WHERE t1.e IS NULL) / +(SELECT COUNT(*) FROM t1) AS "NULLS_RATIO(t1.e)", +(SELECT COUNT(t1.e) FROM t1) / +(SELECT COUNT(DISTINCT t1.e) FROM t1) AS "AVG_FREQUENCY(t1.e)" +FROM t1; +MIN(t1.e) MAX(t1.e) NULLS_RATIO(t1.e) AVG_FREQUENCY(t1.e) +0.01 0.112 0.2250 6.2000 +SELECT * FROM mysql.index_stats +WHERE db_name='test' AND table_name='t1' AND index_name='idx1'; +db_name table_name index_name prefix_arity avg_frequency +test t1 idx1 1 6.4000 +test t1 idx1 2 1.6875 +SELECT +(SELECT COUNT(*) FROM t1 WHERE t1.b IS NOT NULL) / +(SELECT COUNT(DISTINCT t1.b) FROM t1 WHERE t1.b IS NOT NULL) +AS 'ARITY 1', +(SELECT COUNT(*) FROM t1 WHERE t1.b IS NOT NULL AND t1.e IS NOT NULL) / +(SELECT COUNT(DISTINCT t1.b, t1.e) FROM t1 +WHERE t1.b IS NOT NULL AND t1.e IS NOT NULL) +AS 'ARITY 2'; +ARITY 1 ARITY 2 +6.4000 1.6875 +SELECT * FROM mysql.index_stats +WHERE db_name='test' AND table_name='t1' AND index_name='idx2'; +db_name table_name index_name prefix_arity avg_frequency +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +SELECT +(SELECT COUNT(*) FROM t1 WHERE t1.c IS NOT NULL) / +(SELECT COUNT(DISTINCT t1.c) FROM t1 WHERE t1.c IS NOT NULL) +AS 'ARITY 1', +(SELECT COUNT(*) FROM t1 WHERE t1.c IS NOT NULL AND t1.d IS NOT NULL) / +(SELECT COUNT(DISTINCT t1.c, t1.d) FROM t1 +WHERE t1.c IS NOT NULL AND t1.d IS NOT NULL) +AS 'ARITY 2'; +ARITY 1 ARITY 2 +7.0000 2.3846 +SELECT * FROM mysql.index_stats +WHERE db_name='test' AND table_name='t1' AND index_name='idx3'; +db_name table_name index_name prefix_arity avg_frequency +test t1 idx3 1 8.5000 +SELECT +(SELECT COUNT(*) FROM t1 WHERE t1.d IS NOT NULL) / +(SELECT COUNT(DISTINCT t1.d) FROM t1 WHERE t1.d IS NOT NULL) +AS 'ARITY 1'; +ARITY 1 +8.5000 +SELECT * FROM mysql.index_stats +WHERE db_name='test' AND table_name='t1' AND index_name='idx4'; +db_name table_name index_name prefix_arity avg_frequency +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +SELECT +(SELECT COUNT(*) FROM t1 WHERE t1.e IS NOT NULL) / +(SELECT COUNT(DISTINCT t1.e) FROM t1 WHERE t1.e IS NOT NULL) +AS 'ARITY 1', +(SELECT COUNT(*) FROM t1 WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL) / +(SELECT COUNT(DISTINCT t1.e, t1.b) FROM t1 +WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL) +AS 'ARITY 2', +(SELECT COUNT(*) FROM t1 +WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL) / +(SELECT COUNT(DISTINCT t1.e, t1.b, t1.d) FROM t1 +WHERE t1.e IS NOT NULL AND t1.b IS NOT NULL AND t1.d IS NOT NULL) +AS 'ARITY 3'; +ARITY 1 ARITY 2 ARITY 3 +6.2000 1.6875 1.1304 +DELETE FROM mysql.column_stats; +set histogram_size=4; +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +SELECT db_name, table_name, column_name, +min_value, max_value, +nulls_ratio, avg_frequency, +hist_size, hist_type, HEX(histogram) +FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_frequency hist_size hist_type HEX(histogram) +test t1 a 0 49 0.0000 1.0000 4 SINGLE_PREC_HB 2E62A1D0 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 6.4000 4 SINGLE_PREC_HB 003FBFFF +test t1 c aaaa dddddddd 0.1250 7.0000 4 SINGLE_PREC_HB 0055AAFF +test t1 d 1989-03-12 1999-07-23 0.1500 8.5000 4 SINGLE_PREC_HB 009393FF +test t1 e 0.01 0.112 0.2250 6.2000 4 SINGLE_PREC_HB 000564E1 +test t1 f 1 5 0.2000 6.4000 4 SINGLE_PREC_HB 3F7FBFBF +DELETE FROM mysql.column_stats; +set histogram_size=8; +set histogram_type='DOUBLE_PREC_HB'; +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +SELECT db_name, table_name, column_name, +min_value, max_value, +nulls_ratio, avg_frequency, +hist_size, hist_type, HEX(histogram) +FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_frequency hist_size hist_type HEX(histogram) +test t1 a 0 49 0.0000 1.0000 8 DOUBLE_PREC_HB 052F4363F4A1F9D0 +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 6.4000 8 DOUBLE_PREC_HB 0000FF3FFFBFFFFF +test t1 c aaaa dddddddd 0.1250 7.0000 8 DOUBLE_PREC_HB 00005555AAAAFFFF +test t1 d 1989-03-12 1999-07-23 0.1500 8.5000 8 DOUBLE_PREC_HB 000026942694FFFF +test t1 e 0.01 0.112 0.2250 6.2000 8 DOUBLE_PREC_HB 000005056464E1E1 +test t1 f 1 5 0.2000 6.4000 8 DOUBLE_PREC_HB FF3FFF7FFFBFFFBF +DELETE FROM mysql.column_stats; +set histogram_size= 0; +set histogram_type=default; +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +CREATE TABLE t3 ( +a int NOT NULL PRIMARY KEY, +b varchar(32), +c char(16), +INDEX idx (c) +) ENGINE=MYISAM; +INSERT INTO t3 VALUES +(0, NULL, NULL), +(7, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'dddddddd'), +(17, 'vvvvvvvvvvvvv', 'aaaa'), +(1, 'vvvvvvvvvvvvv', NULL), +(12, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd'), +(23, 'vvvvvvvvvvvvv', 'dddddddd'), +(8, 'vvvvvvvvvvvvv', 'aaaa'), +(22, 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'aaaa'), +(31, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'aaaa'), +(10, NULL, 'aaaa'), +(5, 'wwwwwwwwwwwwwwwwwwwwwwwwwwww', 'dddddddd'), +(15, 'vvvvvvvvvvvvv', 'ccccccccc'), +(30, NULL, 'bbbbbb'), +(38, 'zzzzzzzzzzzzzzzzzz', 'bbbbbb'), +(18, 'zzzzzzzzzzzzzzzzzz', 'ccccccccc'), +(9, 'yyy', 'bbbbbb'), +(29, 'vvvvvvvvvvvvv', 'dddddddd'); +ANALYZE TABLE t3; +Table Op Msg_type Msg_text +test.t3 analyze status OK +SELECT * FROM mysql.table_stats; +db_name table_name cardinality +test t1 40 +test t3 17 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +test t3 a 0 38 0.0000 4.0000 1.0000 0 NULL NULL +test t3 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.1765 18.0714 2.8000 0 NULL NULL +test t3 c aaaa dddddddd 0.1176 6.4000 3.7500 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx1 1 6.4000 +test t1 idx1 2 1.6875 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +test t3 PRIMARY 1 1.0000 +test t3 idx 1 3.7500 +ALTER TABLE t1 RENAME TO s1; +SELECT * FROM mysql.table_stats; +db_name table_name cardinality +test s1 40 +test t3 17 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test s1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test s1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test s1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test s1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test s1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test s1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +test t3 a 0 38 0.0000 4.0000 1.0000 0 NULL NULL +test t3 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.1765 18.0714 2.8000 0 NULL NULL +test t3 c aaaa dddddddd 0.1176 6.4000 3.7500 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test s1 PRIMARY 1 1.0000 +test s1 idx1 1 6.4000 +test s1 idx1 2 1.6875 +test s1 idx2 1 7.0000 +test s1 idx2 2 2.3846 +test s1 idx3 1 8.5000 +test s1 idx4 1 6.2000 +test s1 idx4 2 1.6875 +test s1 idx4 3 1.1304 +test t3 PRIMARY 1 1.0000 +test t3 idx 1 3.7500 +RENAME TABLE s1 TO t1; +SELECT * FROM mysql.table_stats; +db_name table_name cardinality +test t1 40 +test t3 17 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +test t3 a 0 38 0.0000 4.0000 1.0000 0 NULL NULL +test t3 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.1765 18.0714 2.8000 0 NULL NULL +test t3 c aaaa dddddddd 0.1176 6.4000 3.7500 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx1 1 6.4000 +test t1 idx1 2 1.6875 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +test t3 PRIMARY 1 1.0000 +test t3 idx 1 3.7500 +DROP TABLE t3; +SELECT * FROM mysql.table_stats; +db_name table_name cardinality +test t1 40 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx1 1 6.4000 +test t1 idx1 2 1.6875 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +CREATE TEMPORARY TABLE t0 ( +a int NOT NULL PRIMARY KEY, +b varchar(32) +); +INSERT INTO t0 SELECT a,b FROM t1; +ALTER TABLE t1 CHANGE COLUMN b x varchar(32), +CHANGE COLUMN e y double; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `x` varchar(32) DEFAULT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `y` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`x`,`y`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`y`,`x`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 x vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 y 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +ALTER TABLE t1 CHANGE COLUMN x b varchar(32), +CHANGE COLUMN y e double; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(32) DEFAULT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`b`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`b`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +ALTER TABLE t1 RENAME TO s1, CHANGE COLUMN b x varchar(32); +SHOW CREATE TABLE s1; +Table Create Table +s1 CREATE TABLE `s1` ( + `a` int(11) NOT NULL, + `x` varchar(32) DEFAULT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`x`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`x`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.table_stats; +db_name table_name cardinality +test s1 40 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test s1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test s1 x vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test s1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test s1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test s1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test s1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test s1 PRIMARY 1 1.0000 +test s1 idx1 1 6.4000 +test s1 idx1 2 1.6875 +test s1 idx2 1 7.0000 +test s1 idx2 2 2.3846 +test s1 idx3 1 8.5000 +test s1 idx4 1 6.2000 +test s1 idx4 2 1.6875 +test s1 idx4 3 1.1304 +ALTER TABLE s1 RENAME TO t1, CHANGE COLUMN x b varchar(32); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(32) DEFAULT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`b`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`b`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.table_stats; +db_name table_name cardinality +test t1 40 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx1 1 6.4000 +test t1 idx1 2 1.6875 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +ALTER TABLE t1 CHANGE COLUMN b x varchar(30); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `x` varchar(30) DEFAULT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`x`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`x`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +ALTER TABLE t1 CHANGE COLUMN x b varchar(32); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(32) DEFAULT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`b`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`b`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx4); +Table Op Msg_type Msg_text +test.t1 analyze status OK +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx4 3 1.1304 +test t1 idx4 2 1.6875 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t1 idx1 2 1.6875 +test t1 idx1 1 6.4000 +SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/save_column_stats' + FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' + FROM mysql.column_stats WHERE column_name='b'; +SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/save_index_stats' + FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' + FROM mysql.index_stats WHERE index_name IN ('idx1', 'idx4'); +ALTER TABLE t1 CHANGE COLUMN b x varchar(30); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `x` varchar(30) DEFAULT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`x`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`x`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +ALTER TABLE t1 CHANGE COLUMN x b varchar(32); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` varchar(32) DEFAULT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`b`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`b`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/save_column_stats' + INTO TABLE mysql.column_stats +FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'; +LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/save_index_stats' + INTO TABLE mysql.index_stats +FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'; +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx4 3 1.1304 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t1 idx4 2 1.6875 +test t1 idx4 1 6.2000 +test t1 idx1 2 1.6875 +test t1 idx1 1 6.4000 +ALTER TABLE t1 DROP COLUMN b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`e`), + KEY `idx2` (`c`,`d`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx3 1 8.5000 +DROP INDEX idx2 ON t1; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx1` (`e`), + KEY `idx3` (`d`), + KEY `idx4` (`e`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx3 1 8.5000 +DROP INDEX idx1 ON t1; +DROP INDEX idx4 ON t1; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx3` (`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +ALTER TABLE t1 ADD COLUMN b varchar(32); +CREATE INDEX idx1 ON t1(b, e); +CREATE INDEX idx2 ON t1(c, d); +CREATE INDEX idx4 ON t1(e, b, d); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + `b` varchar(32) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx3` (`d`), + KEY `idx1` (`b`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx4` (`e`,`b`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx3 1 8.5000 +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4); +Table Op Msg_type Msg_text +test.t1 analyze status OK +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b NULL NULL 1.0000 NULL NULL 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx2 1 7.0000 +test t1 idx1 2 NULL +test t1 idx1 1 NULL +test t1 idx3 1 8.5000 +test t1 idx2 2 2.3846 +test t1 idx4 1 6.2000 +test t1 idx4 2 NULL +test t1 idx4 3 NULL +UPDATE t1 SET b=(SELECT b FROM t0 WHERE t0.a= t1.a); +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4); +Table Op Msg_type Msg_text +test.t1 analyze status OK +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx2 1 7.0000 +test t1 idx1 2 1.6875 +test t1 idx1 1 6.4000 +test t1 idx3 1 8.5000 +test t1 idx2 2 2.3846 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +ALTER TABLE t1 DROP COLUMN b, +DROP INDEX idx1, DROP INDEX idx2, DROP INDEX idx4; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx3` (`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx3 1 8.5000 +ALTER TABLE t1 ADD COLUMN b varchar(32); +ALTER TABLE t1 +ADD INDEX idx1 (b, e), ADD INDEX idx2 (c, d), ADD INDEX idx4 (e, b, d); +UPDATE t1 SET b=(SELECT b FROM t0 WHERE t0.a= t1.a); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `c` char(16) DEFAULT NULL, + `d` date DEFAULT NULL, + `e` double DEFAULT NULL, + `f` bit(3) DEFAULT NULL, + `b` varchar(32) DEFAULT NULL, + PRIMARY KEY (`a`), + KEY `idx3` (`d`), + KEY `idx1` (`b`,`e`), + KEY `idx2` (`c`,`d`), + KEY `idx4` (`e`,`b`,`d`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx3 1 8.5000 +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(b) INDEXES(idx1, idx2, idx4); +Table Op Msg_type Msg_text +test.t1 analyze status OK +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx3 1 8.5000 +test t1 idx2 2 2.3846 +test t1 idx2 1 7.0000 +test t1 idx1 2 1.6875 +test t1 idx1 1 6.4000 +test t1 idx4 3 1.1304 +DELETE FROM mysql.table_stats; +DELETE FROM mysql.column_stats; +DELETE FROM mysql.index_stats; +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS() INDEXES(); +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +SELECT * FROM mysql.table_stats; +db_name table_name cardinality +test t1 40 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS(c,e,b) INDEXES(idx2,idx4); +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +SELECT * FROM mysql.table_stats; +db_name table_name cardinality +test t1 40 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +DELETE FROM mysql.index_stats WHERE table_name='t1' AND index_name='primary'; +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS() INDEXES(primary); +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +test t1 PRIMARY 1 1.0000 +DELETE FROM mysql.table_stats; +DELETE FROM mysql.column_stats; +DELETE FROM mysql.index_stats; +ANALYZE TABLE t1 PERSISTENT FOR COLUMNS ALL INDEXES ALL; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +SELECT * FROM mysql.table_stats; +db_name table_name cardinality +test t1 40 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx3 1 8.5000 +test t1 idx1 1 6.4000 +test t1 idx1 2 1.6875 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t1 idx4 3 1.1304 +CREATE TABLE t2 LIKE t1; +ALTER TABLE t2 ENGINE=InnoDB; +INSERT INTO t2 SELECT * FROM t1; +set optimizer_switch='extended_keys=off'; +ANALYZE TABLE t2; +Table Op Msg_type Msg_text +test.t2 analyze status OK +SELECT * FROM mysql.table_stats; +db_name table_name cardinality +test t1 40 +test t2 40 +SELECT * FROM mysql.column_stats ORDER BY column_name; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t2 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t2 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t2 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t2 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t2 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +test t2 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t2 PRIMARY 1 1.0000 +test t1 idx1 1 6.4000 +test t2 idx1 1 6.4000 +test t1 idx1 2 1.6875 +test t2 idx1 2 1.6875 +test t1 idx2 1 7.0000 +test t2 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t2 idx2 2 2.3846 +test t1 idx3 1 8.5000 +test t2 idx3 1 8.5000 +test t1 idx4 1 6.2000 +test t2 idx4 1 6.2000 +test t1 idx4 2 1.6875 +test t2 idx4 2 1.6875 +test t1 idx4 3 1.1304 +test t2 idx4 3 1.1304 +DELETE FROM mysql.table_stats; +DELETE FROM mysql.column_stats; +DELETE FROM mysql.index_stats; +set optimizer_switch='extended_keys=on'; +ANALYZE TABLE t2; +Table Op Msg_type Msg_text +test.t2 analyze status OK +SELECT * FROM mysql.table_stats; +db_name table_name cardinality +test t2 40 +SELECT * FROM mysql.column_stats ORDER BY column_name; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t2 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t2 b vvvvvvvvvvvvv zzzzzzzzzzzzzzzzzz 0.2000 17.1250 6.4000 0 NULL NULL +test t2 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t2 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t2 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t2 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name; +db_name table_name index_name prefix_arity avg_frequency +test t2 PRIMARY 1 1.0000 +test t2 idx1 1 6.4000 +test t2 idx1 2 1.6875 +test t2 idx1 3 1.0000 +test t2 idx2 1 7.0000 +test t2 idx2 2 2.3846 +test t2 idx2 3 1.0000 +test t2 idx3 1 8.5000 +test t2 idx3 2 1.0000 +test t2 idx4 1 6.2000 +test t2 idx4 2 1.6875 +test t2 idx4 3 1.1304 +test t2 idx4 4 1.0000 +ALTER TABLE t2 DROP PRIMARY KEY, DROP INDEX idx1; +SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name; +db_name table_name index_name prefix_arity avg_frequency +test t2 idx2 1 7.0000 +test t2 idx2 2 2.3846 +test t2 idx3 1 8.5000 +test t2 idx4 1 6.2000 +test t2 idx4 2 1.6875 +test t2 idx4 3 1.1304 +UPDATE t2 SET b=0 WHERE b IS NULL; +ALTER TABLE t2 ADD PRIMARY KEY (a,b); +SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name; +db_name table_name index_name prefix_arity avg_frequency +test t2 idx2 1 7.0000 +test t2 idx2 2 2.3846 +test t2 idx3 1 8.5000 +test t2 idx4 1 6.2000 +test t2 idx4 2 1.6875 +test t2 idx4 3 1.1304 +ANALYZE TABLE t2 PERSISTENT FOR COLUMNS() INDEXES ALL; +Table Op Msg_type Msg_text +test.t2 analyze status OK +SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name; +db_name table_name index_name prefix_arity avg_frequency +test t2 PRIMARY 1 1.0000 +test t2 PRIMARY 2 1.0000 +test t2 idx2 1 7.0000 +test t2 idx2 2 2.3846 +test t2 idx2 3 1.0000 +test t2 idx2 4 1.0000 +test t2 idx3 1 8.5000 +test t2 idx3 2 1.0000 +test t2 idx3 3 1.0000 +test t2 idx4 1 6.2000 +test t2 idx4 2 1.7222 +test t2 idx4 3 1.1154 +test t2 idx4 4 1.0000 +ALTER TABLE t2 CHANGE COLUMN b b varchar(30); +SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name; +db_name table_name index_name prefix_arity avg_frequency +test t2 idx2 1 7.0000 +test t2 idx2 2 2.3846 +test t2 idx3 1 8.5000 +ANALYZE TABLE t2 PERSISTENT FOR COLUMNS ALL INDEXES ALL; +Table Op Msg_type Msg_text +test.t2 analyze status OK +SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name; +db_name table_name index_name prefix_arity avg_frequency +test t2 PRIMARY 1 1.0000 +test t2 PRIMARY 2 1.0000 +test t2 idx2 1 7.0000 +test t2 idx2 2 2.3846 +test t2 idx2 3 1.0000 +test t2 idx2 4 1.0000 +test t2 idx3 1 8.5000 +test t2 idx3 2 1.0000 +test t2 idx3 3 1.0000 +test t2 idx4 1 6.2000 +test t2 idx4 2 1.7222 +test t2 idx4 3 1.1154 +test t2 idx4 4 1.0000 +ALTER TABLE t2 CHANGE COLUMN b b varchar(32); +SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name; +db_name table_name index_name prefix_arity avg_frequency +test t2 idx2 1 7.0000 +test t2 idx2 2 2.3846 +test t2 idx3 1 8.5000 +ANALYZE TABLE t2 PERSISTENT FOR COLUMNS ALL INDEXES ALL; +Table Op Msg_type Msg_text +test.t2 analyze status OK +SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name; +db_name table_name index_name prefix_arity avg_frequency +test t2 PRIMARY 1 1.0000 +test t2 PRIMARY 2 1.0000 +test t2 idx2 1 7.0000 +test t2 idx2 2 2.3846 +test t2 idx2 3 1.0000 +test t2 idx2 4 1.0000 +test t2 idx3 1 8.5000 +test t2 idx3 2 1.0000 +test t2 idx3 3 1.0000 +test t2 idx4 1 6.2000 +test t2 idx4 2 1.7222 +test t2 idx4 3 1.1154 +test t2 idx4 4 1.0000 +ALTER TABLE t2 DROP COLUMN b; +SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name; +db_name table_name index_name prefix_arity avg_frequency +test t2 idx2 1 7.0000 +test t2 idx2 2 2.3846 +test t2 idx3 1 8.5000 +ANALYZE TABLE t2 PERSISTENT FOR COLUMNS() INDEXES ALL; +Table Op Msg_type Msg_text +test.t2 analyze status OK +SELECT * FROM mysql.index_stats ORDER BY index_name, prefix_arity, table_name; +db_name table_name index_name prefix_arity avg_frequency +test t2 PRIMARY 1 1.0000 +test t2 idx2 1 7.0000 +test t2 idx2 2 2.3846 +test t2 idx2 3 1.0000 +test t2 idx3 1 8.5000 +test t2 idx3 2 1.0000 +test t2 idx4 1 6.2000 +test t2 idx4 2 2.2308 +test t2 idx4 3 1.0000 +set optimizer_switch='extended_keys=off'; +ALTER TABLE t1 +DROP INDEX idx1, +DROP INDEX idx4; +ALTER TABLE t1 +MODIFY COLUMN b text, +ADD INDEX idx1 (b(4), e), +ADD INDEX idx4 (e, b(4), d); +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t2 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t2 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t2 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t2 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t2 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t2 idx3 1 8.5000 +test t2 idx3 2 1.0000 +test t2 idx2 3 1.0000 +test t2 idx2 1 7.0000 +test t2 idx2 2 2.3846 +test t2 idx4 3 1.0000 +test t2 idx4 1 6.2000 +test t2 idx4 2 2.2308 +test t2 PRIMARY 1 1.0000 +ANALYZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 analyze status OK +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t2 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t2 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t2 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t2 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t2 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +test t1 b NULL NULL 0.2000 17.1250 NULL NULL NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t2 idx3 1 8.5000 +test t2 idx3 2 1.0000 +test t2 idx2 3 1.0000 +test t2 idx2 1 7.0000 +test t2 idx2 2 2.3846 +test t1 idx2 1 7.0000 +test t1 idx3 1 8.5000 +test t1 PRIMARY 1 1.0000 +test t2 idx4 3 1.0000 +test t2 idx4 1 6.2000 +test t2 idx4 2 2.2308 +test t2 PRIMARY 1 1.0000 +test t1 idx2 2 2.3846 +test t1 idx1 1 NULL +test t1 idx1 2 NULL +test t1 idx4 1 6.2000 +test t1 idx4 2 NULL +test t1 idx4 3 NULL +DELETE FROM mysql.table_stats; +DELETE FROM mysql.column_stats; +DELETE FROM mysql.index_stats; +ANALYZE TABLE mysql.column_stats PERSISTENT FOR ALL; +Table Op Msg_type Msg_text +mysql.column_stats analyze error Invalid argument +ANALYZE TABLE mysql.column_stats; +Table Op Msg_type Msg_text +mysql.column_stats analyze status OK +SELECT * FROM mysql.table_stats; +db_name table_name cardinality +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +set use_stat_tables='never'; +ANALYZE TABLE t1 PERSISTENT FOR ALL; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +SELECT * FROM mysql.table_stats; +db_name table_name cardinality +test t1 40 +SELECT * FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram +test t1 a 0 49 0.0000 4.0000 1.0000 0 NULL NULL +test t1 c aaaa dddddddd 0.1250 6.6571 7.0000 0 NULL NULL +test t1 d 1989-03-12 1999-07-23 0.1500 3.0000 8.5000 0 NULL NULL +test t1 e 0.01 0.112 0.2250 8.0000 6.2000 0 NULL NULL +test t1 f 1 5 0.2000 1.0000 6.4000 0 NULL NULL +test t1 b NULL NULL 0.2000 17.1250 NULL NULL NULL NULL +SELECT * FROM mysql.index_stats; +db_name table_name index_name prefix_arity avg_frequency +test t1 PRIMARY 1 1.0000 +test t1 idx3 1 8.5000 +test t1 idx2 1 7.0000 +test t1 idx2 2 2.3846 +test t1 idx1 1 NULL +test t1 idx1 2 NULL +test t1 idx4 1 6.2000 +test t1 idx4 2 NULL +test t1 idx4 3 NULL +DELETE FROM mysql.table_stats; +DELETE FROM mysql.column_stats; +DELETE FROM mysql.index_stats; +DROP TABLE t1,t2; +set names utf8; +CREATE DATABASE world; +use world; +CREATE TABLE Country ( +Code char(3) NOT NULL default '', +Name char(52) NOT NULL default '', +SurfaceArea float(10,2) NOT NULL default '0.00', +Population int(11) NOT NULL default '0', +Capital int(11) default NULL, +PRIMARY KEY (Code), +UNIQUE INDEX (Name) +) CHARACTER SET utf8 COLLATE utf8_bin; +CREATE TABLE City ( +ID int(11) NOT NULL auto_increment, +Name char(35) NOT NULL default '', +Country char(3) NOT NULL default '', +Population int(11) NOT NULL default '0', +PRIMARY KEY (ID), +INDEX (Population), +INDEX (Country) +) CHARACTER SET utf8 COLLATE utf8_bin; +CREATE TABLE CountryLanguage ( +Country char(3) NOT NULL default '', +Language char(30) NOT NULL default '', +Percentage float(3,1) NOT NULL default '0.0', +PRIMARY KEY (Country, Language), +INDEX (Percentage) +) CHARACTER SET utf8 COLLATE utf8_bin; +set use_stat_tables='preferably'; +ANALYZE TABLE Country, City, CountryLanguage; +SELECT UPPER(db_name), UPPER(table_name), cardinality +FROM mysql.table_stats; +UPPER(db_name) UPPER(table_name) cardinality +WORLD COUNTRY 239 +WORLD CITY 4079 +WORLD COUNTRYLANGUAGE 984 +SELECT UPPER(db_name), UPPER(table_name), +column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency +FROM mysql.column_stats; +UPPER(db_name) UPPER(table_name) column_name min_value max_value nulls_ratio avg_length avg_frequency +WORLD COUNTRY Code ABW ZWE 0.0000 3.0000 1.0000 +WORLD COUNTRY Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 +WORLD COUNTRY SurfaceArea 0.40 17075400.00 0.0000 4.0000 1.0042 +WORLD COUNTRY Population 0 1277558000 0.0000 4.0000 1.0575 +WORLD COUNTRY Capital 1 4074 0.0293 4.0000 1.0000 +WORLD CITY ID 1 4079 0.0000 4.0000 1.0000 +WORLD CITY Name A Coruña (La Coruña) Ãœrgenc 0.0000 8.6416 1.0195 +WORLD CITY Country ABW ZWE 0.0000 3.0000 17.5819 +WORLD CITY Population 42 10500000 0.0000 4.0000 1.0467 +WORLD COUNTRYLANGUAGE Country ABW ZWE 0.0000 3.0000 4.2232 +WORLD COUNTRYLANGUAGE Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 +WORLD COUNTRYLANGUAGE Percentage 0.0 99.9 0.0000 4.0000 2.7640 +SELECT UPPER(db_name), UPPER(table_name), +index_name, prefix_arity, avg_frequency +FROM mysql.index_stats; +UPPER(db_name) UPPER(table_name) index_name prefix_arity avg_frequency +WORLD COUNTRY PRIMARY 1 1.0000 +WORLD COUNTRY Name 1 1.0000 +WORLD CITY PRIMARY 1 1.0000 +WORLD CITY Population 1 1.0467 +WORLD CITY Country 1 17.5819 +WORLD COUNTRYLANGUAGE PRIMARY 1 4.2232 +WORLD COUNTRYLANGUAGE PRIMARY 2 1.0000 +WORLD COUNTRYLANGUAGE Percentage 1 2.7640 +use test; +set use_stat_tables='never'; +CREATE DATABASE world_innodb; +use world_innodb; +CREATE TABLE Country ( +Code char(3) NOT NULL default '', +Name char(52) NOT NULL default '', +SurfaceArea float(10,2) NOT NULL default '0.00', +Population int(11) NOT NULL default '0', +Capital int(11) default NULL, +PRIMARY KEY (Code), +UNIQUE INDEX (Name) +) CHARACTER SET utf8 COLLATE utf8_bin; +CREATE TABLE City ( +ID int(11) NOT NULL auto_increment, +Name char(35) NOT NULL default '', +Country char(3) NOT NULL default '', +Population int(11) NOT NULL default '0', +PRIMARY KEY (ID), +INDEX (Population), +INDEX (Country) +) CHARACTER SET utf8 COLLATE utf8_bin; +CREATE TABLE CountryLanguage ( +Country char(3) NOT NULL default '', +Language char(30) NOT NULL default '', +Percentage float(3,1) NOT NULL default '0.0', +PRIMARY KEY (Country, Language), +INDEX (Percentage) +) CHARACTER SET utf8 COLLATE utf8_bin; +ALTER TABLE Country ENGINE=InnoDB; +ALTER TABLE City ENGINE=InnoDB; +ALTER TABLE CountryLanguage ENGINE=InnoDB; +set use_stat_tables='preferably'; +ANALYZE TABLE Country, City, CountryLanguage; +SELECT UPPER(db_name), UPPER(table_name), cardinality +FROM mysql.table_stats; +UPPER(db_name) UPPER(table_name) cardinality +WORLD COUNTRY 239 +WORLD CITY 4079 +WORLD COUNTRYLANGUAGE 984 +WORLD_INNODB COUNTRY 239 +WORLD_INNODB CITY 4079 +WORLD_INNODB COUNTRYLANGUAGE 984 +SELECT UPPER(db_name), UPPER(table_name), +column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency +FROM mysql.column_stats; +UPPER(db_name) UPPER(table_name) column_name min_value max_value nulls_ratio avg_length avg_frequency +WORLD COUNTRY Code ABW ZWE 0.0000 3.0000 1.0000 +WORLD COUNTRY Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 +WORLD COUNTRY SurfaceArea 0.40 17075400.00 0.0000 4.0000 1.0042 +WORLD COUNTRY Population 0 1277558000 0.0000 4.0000 1.0575 +WORLD COUNTRY Capital 1 4074 0.0293 4.0000 1.0000 +WORLD CITY ID 1 4079 0.0000 4.0000 1.0000 +WORLD CITY Name A Coruña (La Coruña) Ãœrgenc 0.0000 8.6416 1.0195 +WORLD CITY Country ABW ZWE 0.0000 3.0000 17.5819 +WORLD CITY Population 42 10500000 0.0000 4.0000 1.0467 +WORLD COUNTRYLANGUAGE Country ABW ZWE 0.0000 3.0000 4.2232 +WORLD COUNTRYLANGUAGE Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 +WORLD COUNTRYLANGUAGE Percentage 0.0 99.9 0.0000 4.0000 2.7640 +WORLD_INNODB COUNTRY Code ABW ZWE 0.0000 3.0000 1.0000 +WORLD_INNODB COUNTRY Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 +WORLD_INNODB COUNTRY SurfaceArea 0.40 17075400.00 0.0000 4.0000 1.0042 +WORLD_INNODB COUNTRY Population 0 1277558000 0.0000 4.0000 1.0575 +WORLD_INNODB COUNTRY Capital 1 4074 0.0293 4.0000 1.0000 +WORLD_INNODB CITY ID 1 4079 0.0000 4.0000 1.0000 +WORLD_INNODB CITY Name A Coruña (La Coruña) Ãœrgenc 0.0000 8.6416 1.0195 +WORLD_INNODB CITY Country ABW ZWE 0.0000 3.0000 17.5819 +WORLD_INNODB CITY Population 42 10500000 0.0000 4.0000 1.0467 +WORLD_INNODB COUNTRYLANGUAGE Country ABW ZWE 0.0000 3.0000 4.2232 +WORLD_INNODB COUNTRYLANGUAGE Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 +WORLD_INNODB COUNTRYLANGUAGE Percentage 0.0 99.9 0.0000 4.0000 2.7640 +SELECT UPPER(db_name), UPPER(table_name), +index_name, prefix_arity, avg_frequency +FROM mysql.index_stats; +UPPER(db_name) UPPER(table_name) index_name prefix_arity avg_frequency +WORLD COUNTRY PRIMARY 1 1.0000 +WORLD COUNTRY Name 1 1.0000 +WORLD CITY PRIMARY 1 1.0000 +WORLD CITY Population 1 1.0467 +WORLD CITY Country 1 17.5819 +WORLD COUNTRYLANGUAGE PRIMARY 1 4.2232 +WORLD COUNTRYLANGUAGE PRIMARY 2 1.0000 +WORLD COUNTRYLANGUAGE Percentage 1 2.7640 +WORLD_INNODB COUNTRY PRIMARY 1 1.0000 +WORLD_INNODB COUNTRY Name 1 1.0000 +WORLD_INNODB CITY PRIMARY 1 1.0000 +WORLD_INNODB CITY Population 1 1.0467 +WORLD_INNODB CITY Country 1 17.5819 +WORLD_INNODB COUNTRYLANGUAGE PRIMARY 1 4.2232 +WORLD_INNODB COUNTRYLANGUAGE PRIMARY 2 1.0000 +WORLD_INNODB COUNTRYLANGUAGE Percentage 1 2.7640 +use world; +set use_stat_tables='preferably'; +set histogram_size=100; +set histogram_type='SINGLE_PREC_HB'; +ANALYZE TABLE CountryLanguage; +set histogram_size=254; +set histogram_type='DOUBLE_PREC_HB'; +ANALYZE TABLE City; +FLUSH TABLES; +select UPPER(db_name),UPPER(table_name),UPPER(column_name),min_value,max_value,nulls_ratio,avg_length,avg_frequency,hist_size,hist_type,hex(histogram),decode_histogram(histogram,hist_type) from mysql.column_stats where UPPER(db_name)='WORLD' and UPPER(table_name)='COUNTRYLANGUAGE' and UPPER(column_name) = 'PERCENTAGE';; +UPPER(db_name) WORLD +UPPER(table_name) COUNTRYLANGUAGE +UPPER(column_name) PERCENTAGE +min_value 0.0 +max_value 99.9 +nulls_ratio 0.0000 +avg_length 4.0000 +avg_frequency 2.7640 +hist_size 100 +hist_type SINGLE_PREC_HB +hex(histogram) 0000000000000000000000000101010101010101010202020303030304040404050505050606070707080809090A0A0B0C0D0D0E0E0F10111213131415161718191B1C1E202224292A2E33373B4850575F6A76818C9AA7B9C4CFDADFE5EBF0F4F8FAFCFF +decode_histogram(histogram,hist_type) 0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.004,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.004,0.000,0.000,0.004,0.000,0.000,0.000,0.004,0.000,0.000,0.000,0.004,0.000,0.000,0.000,0.004,0.000,0.004,0.000,0.000,0.004,0.000,0.004,0.000,0.004,0.000,0.004,0.004,0.004,0.000,0.004,0.000,0.004,0.004,0.004,0.004,0.004,0.000,0.004,0.004,0.004,0.004,0.004,0.004,0.008,0.004,0.008,0.008,0.008,0.008,0.020,0.004,0.016,0.020,0.016,0.016,0.051,0.031,0.027,0.031,0.043,0.047,0.043,0.043,0.055,0.051,0.071,0.043,0.043,0.043,0.020,0.024,0.024,0.020,0.016,0.016,0.008,0.008,0.012,0.000 +select UPPER(db_name),UPPER(table_name),UPPER(column_name),min_value,max_value,nulls_ratio,avg_length,avg_frequency,hist_size,hist_type,hex(histogram),decode_histogram(histogram,hist_type) from mysql.column_stats where UPPER(db_name)='WORLD' and UPPER(table_name)='CITY' and UPPER(column_name) = 'POPULATION';; +UPPER(db_name) WORLD +UPPER(table_name) CITY +UPPER(column_name) POPULATION +min_value 42 +max_value 10500000 +nulls_ratio 0.0000 +avg_length 4.0000 +avg_frequency 1.0467 +hist_size 254 +hist_type DOUBLE_PREC_HB +hex(histogram) 1F00A1002B023002350238023F02430249024E02520258025D02630268026E02720276027B02800285028C02920297029D02A102A802AC02B402BC02C402CC02D302DA02E302EA02F102F802010305030C03120319031F03290333033D0343034F03590363036D037803840390039A03A603B303C303D103E003F203020412042404330440045304600472047F049104A204B804C804DE04F2040A0526053F0558056F058E05B305D905F4051306380667068406AB06DA06020731075C079407C507F8072E085E08A508DF0824096909CC092E0A760AD50A400BA90B150CAD0C310D240E130F0E103B11B9126B14F0166B192F1CB71FFF240630483FC567 +decode_histogram(histogram,hist_type) 0.00047,0.00198,0.00601,0.00008,0.00008,0.00005,0.00011,0.00006,0.00009,0.00008,0.00006,0.00009,0.00008,0.00009,0.00008,0.00009,0.00006,0.00006,0.00008,0.00008,0.00008,0.00011,0.00009,0.00008,0.00009,0.00006,0.00011,0.00006,0.00012,0.00012,0.00012,0.00012,0.00011,0.00011,0.00014,0.00011,0.00011,0.00011,0.00014,0.00006,0.00011,0.00009,0.00011,0.00009,0.00015,0.00015,0.00015,0.00009,0.00018,0.00015,0.00015,0.00015,0.00017,0.00018,0.00018,0.00015,0.00018,0.00020,0.00024,0.00021,0.00023,0.00027,0.00024,0.00024,0.00027,0.00023,0.00020,0.00029,0.00020,0.00027,0.00020,0.00027,0.00026,0.00034,0.00024,0.00034,0.00031,0.00037,0.00043,0.00038,0.00038,0.00035,0.00047,0.00056,0.00058,0.00041,0.00047,0.00056,0.00072,0.00044,0.00060,0.00072,0.00061,0.00072,0.00066,0.00085,0.00075,0.00078,0.00082,0.00073,0.00108,0.00089,0.00105,0.00105,0.00151,0.00150,0.00110,0.00145,0.00163,0.00160,0.00165,0.00232,0.00201,0.00371,0.00365,0.00383,0.00459,0.00583,0.00662,0.00984,0.00969,0.01080,0.01379,0.02063,0.04308,0.05960,0.15816,0.59464 +set histogram_type=default; +set histogram_size=default; +use test; +DROP DATABASE world; +SELECT UPPER(db_name), UPPER(table_name), cardinality +FROM mysql.table_stats; +UPPER(db_name) UPPER(table_name) cardinality +WORLD_INNODB COUNTRY 239 +WORLD_INNODB CITY 4079 +WORLD_INNODB COUNTRYLANGUAGE 984 +SELECT UPPER(db_name), UPPER(table_name), +column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency +FROM mysql.column_stats; +UPPER(db_name) UPPER(table_name) column_name min_value max_value nulls_ratio avg_length avg_frequency +WORLD_INNODB COUNTRY Code ABW ZWE 0.0000 3.0000 1.0000 +WORLD_INNODB COUNTRY Name Afghanistan Zimbabwe 0.0000 10.1088 1.0000 +WORLD_INNODB COUNTRY SurfaceArea 0.40 17075400.00 0.0000 4.0000 1.0042 +WORLD_INNODB COUNTRY Population 0 1277558000 0.0000 4.0000 1.0575 +WORLD_INNODB COUNTRY Capital 1 4074 0.0293 4.0000 1.0000 +WORLD_INNODB CITY ID 1 4079 0.0000 4.0000 1.0000 +WORLD_INNODB CITY Name A Coruña (La Coruña) Ãœrgenc 0.0000 8.6416 1.0195 +WORLD_INNODB CITY Country ABW ZWE 0.0000 3.0000 17.5819 +WORLD_INNODB CITY Population 42 10500000 0.0000 4.0000 1.0467 +WORLD_INNODB COUNTRYLANGUAGE Country ABW ZWE 0.0000 3.0000 4.2232 +WORLD_INNODB COUNTRYLANGUAGE Language Abhyasi [South]Mande 0.0000 7.1778 2.1532 +WORLD_INNODB COUNTRYLANGUAGE Percentage 0.0 99.9 0.0000 4.0000 2.7640 +SELECT UPPER(db_name), UPPER(table_name), +index_name, prefix_arity, avg_frequency +FROM mysql.index_stats; +UPPER(db_name) UPPER(table_name) index_name prefix_arity avg_frequency +WORLD_INNODB COUNTRY PRIMARY 1 1.0000 +WORLD_INNODB COUNTRY Name 1 1.0000 +WORLD_INNODB CITY PRIMARY 1 1.0000 +WORLD_INNODB CITY Population 1 1.0467 +WORLD_INNODB CITY Country 1 17.5819 +WORLD_INNODB COUNTRYLANGUAGE PRIMARY 1 4.2232 +WORLD_INNODB COUNTRYLANGUAGE PRIMARY 2 1.0000 +WORLD_INNODB COUNTRYLANGUAGE Percentage 1 2.7640 +DROP DATABASE world_innodb; +SELECT UPPER(db_name), UPPER(table_name), cardinality +FROM mysql.table_stats; +UPPER(db_name) UPPER(table_name) cardinality +SELECT UPPER(db_name), UPPER(table_name), +column_name, min_value, max_value, nulls_ratio, avg_length, avg_frequency +FROM mysql.column_stats; +UPPER(db_name) UPPER(table_name) column_name min_value max_value nulls_ratio avg_length avg_frequency +SELECT UPPER(db_name), UPPER(table_name), +index_name, prefix_arity, avg_frequency +FROM mysql.index_stats; +UPPER(db_name) UPPER(table_name) index_name prefix_arity avg_frequency +DELETE FROM mysql.table_stats; +DELETE FROM mysql.column_stats; +DELETE FROM mysql.index_stats; +# +# Bug mdev-4357: empty string as a value of the HIST_SIZE column +# from mysql.column_stats +# +create table t1 (a int); +insert into t1 values (1),(2),(3); +set histogram_size=10; +analyze table t1 persistent for all; +Table Op Msg_type Msg_text +test.t1 analyze status OK +select db_name, table_name, column_name, +min_value, max_value, +nulls_ratio, avg_frequency, +hist_size, hist_type, HEX(histogram) +FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_frequency hist_size hist_type HEX(histogram) +test t1 a 1 3 0.0000 1.0000 10 SINGLE_PREC_HB 0000007F7F7F7FFFFFFF +set histogram_size=default; +drop table t1; +# +# Bug mdev-4359: wrong setting of the HIST_SIZE column +# (see also mdev-4357) from mysql.column_stats +# +create table t1 ( a int); +insert into t1 values (1),(2),(3),(4),(5); +set histogram_size=10; +set histogram_type='double_prec_hb'; +show variables like 'histogram%'; +Variable_name Value +histogram_size 10 +histogram_type DOUBLE_PREC_HB +analyze table t1 persistent for all; +Table Op Msg_type Msg_text +test.t1 analyze status OK +select db_name, table_name, column_name, +min_value, max_value, +nulls_ratio, avg_frequency, +hist_size, hist_type, HEX(histogram) +FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_frequency hist_size hist_type HEX(histogram) +test t1 a 1 5 0.0000 1.0000 10 DOUBLE_PREC_HB 0000FF3FFF7FFFBFFFFF +set histogram_size=default; +set histogram_type=default; +drop table t1; +# +# Bug mdev-4369: histogram for a column with many distinct values +# +CREATE TABLE t1 (id int); +CREATE TABLE t2 (id int); +INSERT INTO t1 (id) VALUES (1), (1), (1),(1); +INSERT INTO t1 (id) SELECT id FROM t1; +INSERT INTO t1 SELECT id+1 FROM t1; +INSERT INTO t1 SELECT id+2 FROM t1; +INSERT INTO t1 SELECT id+4 FROM t1; +INSERT INTO t1 SELECT id+8 FROM t1; +INSERT INTO t1 SELECT id+16 FROM t1; +INSERT INTO t1 SELECT id+32 FROM t1; +INSERT INTO t1 SELECT id+64 FROM t1; +INSERT INTO t1 SELECT id+128 FROM t1; +INSERT INTO t1 SELECT id+256 FROM t1; +INSERT INTO t1 SELECT id+512 FROM t1; +INSERT INTO t2 SELECT id FROM t1 ORDER BY id*rand(); +SELECT COUNT(*) FROM t2; +COUNT(*) +8192 +SELECT COUNT(DISTINCT id) FROM t2; +COUNT(DISTINCT id) +1024 +set @@tmp_table_size=1024*16; +set @@max_heap_table_size=1024*16; +set histogram_size=63; +analyze table t2 persistent for all; +Table Op Msg_type Msg_text +test.t2 analyze status OK +select db_name, table_name, column_name, +min_value, max_value, +nulls_ratio, avg_frequency, +hist_size, hist_type, HEX(histogram) +FROM mysql.column_stats; +db_name table_name column_name min_value max_value nulls_ratio avg_frequency hist_size hist_type HEX(histogram) +test t2 id 1 1024 0.0000 8.0000 63 SINGLE_PREC_HB 03070B0F13171B1F23272B2F33373B3F43474B4F53575B5F63676B6F73777B7F83878B8F93979B9FA3A7ABAFB3B7BBBFC3C7CBCFD3D7DBDFE3E7EBEFF3F7FB +set histogram_size=default; +drop table t1, t2; +set use_stat_tables=@save_use_stat_tables; diff --git a/mysql-test/r/status_user.result b/mysql-test/r/status_user.result index 39579799431..fb6dac3f5ac 100644 --- a/mysql-test/r/status_user.result +++ b/mysql-test/r/status_user.result @@ -107,7 +107,7 @@ Handler_mrr_key_refills 0 Handler_mrr_rowid_refills 0 Handler_prepare 18 Handler_read_first 0 -Handler_read_key 3 +Handler_read_key 9 Handler_read_last 0 Handler_read_next 0 Handler_read_prev 0 @@ -123,7 +123,7 @@ Handler_update 5 Handler_write 7 select variable_value - @global_read_key as "handler_read_key" from information_schema.global_status where variable_name="handler_read_key"; handler_read_key -3 +9 set @@global.userstat=0; select * from information_schema.index_statistics; TABLE_SCHEMA TABLE_NAME INDEX_NAME ROWS_READ diff --git a/mysql-test/r/str_to_datetime_457.result b/mysql-test/r/str_to_datetime_457.result new file mode 100644 index 00000000000..4fd0d00691c --- /dev/null +++ b/mysql-test/r/str_to_datetime_457.result @@ -0,0 +1,51 @@ +select cast('01:02:03 ' as time), cast('01:02:03 ' as time); +cast('01:02:03 ' as time) cast('01:02:03 ' as time) +01:02:03 00:00:00 +select cast('2002-011-012' as date), cast('2002.11.12' as date), cast('2002.011.012' as date); +cast('2002-011-012' as date) cast('2002.11.12' as date) cast('2002.011.012' as date) +2002-11-12 2002-11-12 2002-11-12 +select cast('2012103123595912' as datetime(6)), cast('20121031235959123' as datetime(6)); +cast('2012103123595912' as datetime(6)) cast('20121031235959123' as datetime(6)) +2012-10-31 23:59:59.000000 2012-10-31 23:59:59.000000 +Warnings: +Warning 1292 Truncated incorrect datetime value: '2012103123595912' +Warning 1292 Truncated incorrect datetime value: '20121031235959123' +select cast(0 as date), cast('0000-00-00' as date), cast('0' as date); +cast(0 as date) cast('0000-00-00' as date) cast('0' as date) +0000-00-00 0000-00-00 NULL +Warnings: +Warning 1292 Incorrect datetime value: '0' +select extract(hour from '100000:02:03'), extract(hour from '100000:02:03 '); +extract(hour from '100000:02:03') extract(hour from '100000:02:03 ') +NULL NULL +Warnings: +Warning 1292 Truncated incorrect time value: '100000:02:03' +Warning 1292 Truncated incorrect time value: '100000:02:03 ' +# +# backward compatibility craziness +# +select cast('12:00:00.12.34.56' as time); +cast('12:00:00.12.34.56' as time) +12:00:00 +Warnings: +Warning 1292 Truncated incorrect time value: '12:00:00.12.34.56' +select cast('12:00:00 12.34.56' as time); +cast('12:00:00 12.34.56' as time) +12:34:56 +select cast('12:00:00-12.34.56' as time); +cast('12:00:00-12.34.56' as time) +12:00:00 +Warnings: +Warning 1292 Truncated incorrect time value: '12:00:00-12.34.56' +select cast('12:00:00.12.34.56' as datetime); +cast('12:00:00.12.34.56' as datetime) +2012-00-00 12:34:56 +select cast('12:00:00-12.34.56' as datetime); +cast('12:00:00-12.34.56' as datetime) +2012-00-00 12:34:56 +select cast('12:00:00 12.34.56' as datetime); +cast('12:00:00 12.34.56' as datetime) +2012-00-00 12:34:56 +select cast('12:00:00.123456' as time); +cast('12:00:00.123456' as time) +12:00:00 diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 9d13c29f886..4d9bbf93168 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -10,7 +10,7 @@ select (select 2); 2 explain extended select (select 2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1249 Select 2 was reduced during optimization Note 1003 select 2 AS `(select 2)` @@ -734,7 +734,7 @@ id 1 EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 ref id id 5 const 1 100.00 Using index +1 SIMPLE t2 ref id id 5 const 1 100.00 Using index Warnings: Note 1249 Select 2 was reduced during optimization Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = 1) @@ -746,7 +746,7 @@ id 2 EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 ref id id 5 const 1 100.00 Using where; Using index +1 SIMPLE t2 ref id id 5 const 1 100.00 Using where; Using index Warnings: Note 1249 Select 3 was reduced during optimization Note 1249 Select 2 was reduced during optimization @@ -880,7 +880,7 @@ select 10.5 > ANY (SELECT * from t1); 1 explain extended select (select a+1) from t1; 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 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 Note 1249 Select 2 was reduced during optimization @@ -2966,7 +2966,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`one`,`test`.`t1`.`two`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1` +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`one`,`test`.`t1`.`two`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)))) and trigcond(trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1` explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N'); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 @@ -2979,7 +2979,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`one`,`test`.`t1`.`two`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1` +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`one`,`test`.`t1`.`two`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)))) and trigcond(trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1` DROP TABLE t1,t2; set optimizer_switch=@tmp11867_optimizer_switch; CREATE TABLE t1 (a char(5), b char(5)); @@ -4554,7 +4554,7 @@ int_nokey int_key 0 0 EXPLAIN EXTENDED SELECT * FROM C WHERE `int_key` IN (SELECT `int_nokey`); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY C ALL NULL NULL NULL NULL 20 100.00 Using where +1 SIMPLE C ALL NULL NULL NULL NULL 20 100.00 Using where DROP TABLE C; # End of test for bug#45061. # @@ -6112,7 +6112,7 @@ FROM t1 AS sq4_alias1 WHERE (sq4_alias1.col_varchar_key + NULL) IS NULL OR sq4_alias1.col_varchar_key = @var3 ) AS alias3; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE <derived2> system NULL NULL NULL NULL 0 const row not found +1 PRIMARY <derived2> system NULL NULL NULL NULL 0 const row not found 2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table SELECT * FROM ( SELECT @var3:=12, sq4_alias1.* FROM t1 AS sq4_alias1 @@ -6157,7 +6157,7 @@ FROM t2 AS c_sq1_alias1 WHERE (c_sq1_alias1.col_int_nokey != @var2 OR c_sq1_alias1.pk != @var3)) ) AS alias3; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 DEPENDENT SUBQUERY c_sq1_alias1 system PRIMARY NULL NULL NULL 1 SELECT * FROM ( SELECT sq4_alias1.* FROM t1 AS sq4_alias1 diff --git a/mysql-test/r/subselect2.result b/mysql-test/r/subselect2.result index 72ca9d33354..c5a996552e4 100644 --- a/mysql-test/r/subselect2.result +++ b/mysql-test/r/subselect2.result @@ -286,7 +286,7 @@ WHERE date < '2012-12-12 12:12:12' ORDER BY mirror_date ASC ) AS calculated_result; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE <derived2> ALL NULL NULL NULL NULL 2 +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 2 DERIVED t1 range date date 9 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using filesort SELECT * FROM ( SELECT node_uid, date, mirror_date, @result := 0 AS result @@ -309,7 +309,7 @@ WHERE date < '2012-12-12 12:12:12' ORDER BY mirror_date ASC ) AS calculated_result; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE <derived2> ALL NULL NULL NULL NULL 2 +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 2 DERIVED t1 range date date 9 NULL 2 Using index condition; Using where; Using filesort SELECT * FROM ( SELECT node_uid, date, mirror_date, @result := 0 AS result diff --git a/mysql-test/r/subselect3.result b/mysql-test/r/subselect3.result index 487ffe655c1..24d9f0de35a 100644 --- a/mysql-test/r/subselect3.result +++ b/mysql-test/r/subselect3.result @@ -252,7 +252,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 100.00 Using where; Full scan on NULL key Warnings: Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1 -Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`))))))) AS `Z` from `test`.`t2` +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`)))) and trigcond(trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`))))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`))))))) AS `Z` from `test`.`t2` select a,b, oref, (a,b) in (select a,b from t1 where c=t2.oref) Z from t2; a b oref Z NULL 1 100 0 @@ -269,7 +269,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY t4 ALL NULL NULL NULL NULL 100 100.00 Using where; Using join buffer (flat, BNL join) Warnings: Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1 -Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(select `test`.`t1`.`a`,`test`.`t1`.`b` from `test`.`t1` join `test`.`t4` where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`)))))) AS `Z` from `test`.`t2` +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(select `test`.`t1`.`a`,`test`.`t1`.`b` from `test`.`t1` join `test`.`t4` where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`)))) and trigcond(trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`))))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`)))))) AS `Z` from `test`.`t2` select a,b, oref, (a,b) in (select a,b from t1,t4 where c=t2.oref) Z from t2; @@ -314,7 +314,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY t1 index_subquery idx idx 5 func 4 100.00 Using where; Full scan on NULL key Warnings: Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1 -Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`))))))) AS `Z` from `test`.`t2` where ((`test`.`t2`.`a` = 10) and (`test`.`t2`.`b` = 10)) +Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`)))) and trigcond(trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`))))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`))))))) AS `Z` from `test`.`t2` where ((`test`.`t2`.`a` = 10) and (`test`.`t2`.`b` = 10)) drop table t1, t2; create table t1 (oref char(4), grp int, ie int); insert into t1 (oref, grp, ie) values @@ -584,7 +584,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY t1 index_subquery idx idx 5 func 4 100.00 Using where; Full scan on NULL key Warnings: Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1 -Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`))))))) AS `Z` from `test`.`t2` +Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`)))) and trigcond(trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`))))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`))))))) AS `Z` from `test`.`t2` drop table t1,t2; create table t1 (oref char(4), grp int, ie int primary key); insert into t1 (oref, grp, ie) values @@ -1031,7 +1031,7 @@ update t22 set c = '2005-12-08 15:58:27' where a = 255; explain select t21.* from t21,t22 where t21.a = t22.a and t22.a in (select t12.a from t11, t12 where t11.a in(255,256) and t11.a = t12.a and t11.c is null) and t22.c is null order by t21.a; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t11 ALL NULL NULL NULL NULL 8 Using where; Using temporary; Using filesort; Start temporary +1 PRIMARY t11 ALL NULL NULL NULL NULL 8 Using where; Start temporary; Using temporary; Using filesort 1 PRIMARY t12 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) 1 PRIMARY t22 ALL NULL NULL NULL NULL 26 Using where; End temporary; Using join buffer (flat, BNL join) 1 PRIMARY t21 ALL NULL NULL NULL NULL 26 Using where; Using join buffer (flat, BNL join) diff --git a/mysql-test/r/subselect3_jcl6.result b/mysql-test/r/subselect3_jcl6.result index 9cd3018718c..19d3d25148f 100644 --- a/mysql-test/r/subselect3_jcl6.result +++ b/mysql-test/r/subselect3_jcl6.result @@ -262,7 +262,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 100.00 Using where; Full scan on NULL key Warnings: Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1 -Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`))))))) AS `Z` from `test`.`t2` +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`)))) and trigcond(trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`))))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`))))))) AS `Z` from `test`.`t2` select a,b, oref, (a,b) in (select a,b from t1 where c=t2.oref) Z from t2; a b oref Z NULL 1 100 0 @@ -279,7 +279,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY t4 ALL NULL NULL NULL NULL 100 100.00 Using where; Using join buffer (flat, BNL join) Warnings: Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1 -Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(select `test`.`t1`.`a`,`test`.`t1`.`b` from `test`.`t1` join `test`.`t4` where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`)))))) AS `Z` from `test`.`t2` +Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`oref` AS `oref`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(select `test`.`t1`.`a`,`test`.`t1`.`b` from `test`.`t1` join `test`.`t4` where ((`test`.`t1`.`c` = `test`.`t2`.`oref`) and trigcond(trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`)))) and trigcond(trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`b`) or isnull(`test`.`t1`.`b`))))) having (trigcond(<is_not_null_test>(`test`.`t1`.`a`)) and trigcond(<is_not_null_test>(`test`.`t1`.`b`)))))) AS `Z` from `test`.`t2` select a,b, oref, (a,b) in (select a,b from t1,t4 where c=t2.oref) Z from t2; @@ -324,7 +324,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY t1 index_subquery idx idx 5 func 4 100.00 Using where; Full scan on NULL key Warnings: Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1 -Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`))))))) AS `Z` from `test`.`t2` where ((`test`.`t2`.`a` = 10) and (`test`.`t2`.`b` = 10)) +Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`)))) and trigcond(trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`))))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`))))))) AS `Z` from `test`.`t2` where ((`test`.`t2`.`a` = 10) and (`test`.`t2`.`b` = 10)) drop table t1, t2; create table t1 (oref char(4), grp int, ie int); insert into t1 (oref, grp, ie) values @@ -594,7 +594,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 DEPENDENT SUBQUERY t1 index_subquery idx idx 5 func 4 100.00 Using where; Full scan on NULL key Warnings: Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1 -Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`))) and trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`)))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`))))))) AS `Z` from `test`.`t2` +Note 1003 select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`b`,`test`.`t2`.`oref`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on idx checking NULL where ((`test`.`t1`.`oref` = `test`.`t2`.`oref`) and trigcond(trigcond(((<cache>(`test`.`t2`.`a`) = `test`.`t1`.`ie1`) or isnull(`test`.`t1`.`ie1`)))) and trigcond(trigcond(((<cache>(`test`.`t2`.`b`) = `test`.`t1`.`ie2`) or isnull(`test`.`t1`.`ie2`))))) having (trigcond(<is_not_null_test>(`test`.`t1`.`ie1`)) and trigcond(<is_not_null_test>(`test`.`t1`.`ie2`))))))) AS `Z` from `test`.`t2` drop table t1,t2; create table t1 (oref char(4), grp int, ie int primary key); insert into t1 (oref, grp, ie) values @@ -1041,7 +1041,7 @@ update t22 set c = '2005-12-08 15:58:27' where a = 255; explain select t21.* from t21,t22 where t21.a = t22.a and t22.a in (select t12.a from t11, t12 where t11.a in(255,256) and t11.a = t12.a and t11.c is null) and t22.c is null order by t21.a; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t11 ALL NULL NULL NULL NULL 8 Using where; Using temporary; Using filesort; Start temporary +1 PRIMARY t11 ALL NULL NULL NULL NULL 8 Using where; Start temporary; Using temporary; Using filesort 1 PRIMARY t12 hash_ALL NULL #hash#$hj 4 test.t11.a 8 Using where; Using join buffer (flat, BNLH join) 1 PRIMARY t22 hash_ALL NULL #hash#$hj 4 test.t11.a 26 Using where; End temporary; Using join buffer (incremental, BNLH join) 1 PRIMARY t21 hash_ALL NULL #hash#$hj 4 test.t11.a 26 Using where; Using join buffer (incremental, BNLH join) diff --git a/mysql-test/r/subselect4.result b/mysql-test/r/subselect4.result index 00ee59ecbec..e6f30472777 100644 --- a/mysql-test/r/subselect4.result +++ b/mysql-test/r/subselect4.result @@ -93,12 +93,12 @@ DROP TABLE t1,t2; # EXPLAIN SELECT 1 LIKE ( 1 IN ( SELECT 1 ) ); 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 +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1249 Select 2 was reduced during optimization DESCRIBE SELECT 1 LIKE ( 1 IN ( SELECT 1 ) ); 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 +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1249 Select 2 was reduced during optimization # None of the below should crash @@ -303,7 +303,7 @@ EXPLAIN SELECT * FROM t1 WHERE (NULL, 1) NOT IN (SELECT t2a.i, t2a.pk FROM t2a WHERE t2a.pk = t1.pk); 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 DEPENDENT SUBQUERY t2a eq_ref PRIMARY PRIMARY 8 const,test.t1.pk 1 Using where; Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2a unique_subquery PRIMARY PRIMARY 8 const,test.t1.pk 1 Using index; Using where; Full scan on NULL key SELECT * FROM t1 WHERE (NULL, 1) NOT IN (SELECT t2a.i, t2a.pk FROM t2a WHERE t2a.pk = t1.pk); pk i 0 10 @@ -335,7 +335,7 @@ EXPLAIN SELECT * FROM t1 WHERE (NULL, 1) NOT IN (SELECT t2c.i, t2c.pk FROM t2c WHERE t2c.pk = t1.pk); 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 DEPENDENT SUBQUERY t2c ref it2c it2c 8 const,test.t1.pk 2 Using where; Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2c index_subquery it2c it2c 8 const,test.t1.pk 2 Using index; Using where; Full scan on NULL key SELECT * FROM t1 WHERE (NULL, 1) NOT IN (SELECT t2c.i, t2c.pk FROM t2c WHERE t2c.pk = t1.pk); pk i 0 10 @@ -520,8 +520,8 @@ id select_type table type possible_keys key key_len ref rows Extra 2 MATERIALIZED t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL t1_IDX NULL NULL NULL 5 -1 SIMPLE <subquery2> eq_ref distinct_key distinct_key 3 func 1 +1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 3 func 1 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 Using where 2 MATERIALIZED t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) DEALLOCATE PREPARE stmt; @@ -558,8 +558,8 @@ id select_type table type possible_keys key key_len ref rows Extra 2 MATERIALIZED t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL t1_IDX NULL NULL NULL 5 -1 SIMPLE <subquery2> eq_ref distinct_key distinct_key 3 func 1 +1 PRIMARY t1 ALL t1_IDX NULL NULL NULL 5 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 3 func 1 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 Using where 2 MATERIALIZED t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) DEALLOCATE PREPARE stmt; @@ -595,8 +595,8 @@ id select_type table type possible_keys key key_len ref rows Extra 2 MATERIALIZED t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 5 -1 SIMPLE <subquery2> eq_ref distinct_key distinct_key 3 func 1 +1 PRIMARY t1 ALL NULL NULL NULL NULL 5 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 3 func 1 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 Using where 2 MATERIALIZED t3 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) DEALLOCATE PREPARE stmt; diff --git a/mysql-test/r/subselect_exists2in.result b/mysql-test/r/subselect_exists2in.result new file mode 100644 index 00000000000..efbbe08cede --- /dev/null +++ b/mysql-test/r/subselect_exists2in.result @@ -0,0 +1,865 @@ +drop table if exists t1,t2,t3; +set optimizer_switch='exists_to_in=on'; +# +# LP BUG#884644 exists2in broke name resolution +# +CREATE TABLE t1 (f1 integer); +SELECT * FROM t1 WHERE EXISTS (SELECT NO_SUCH_TABLE.NO_SUCH_FIELD FROM t1); +ERROR 42S22: Unknown column 'NO_SUCH_TABLE.NO_SUCH_FIELD' in 'field list' +drop table t1; +# +# LP BUG#884657 Wrong result with exists2in , correlated subquery +# +CREATE TABLE t1 ( a varchar(1)) ; +INSERT INTO t1 VALUES ('c'),('b'); +CREATE TABLE t2 ( b varchar(1)) ; +INSERT INTO t2 VALUES ('v'),('v'),('c'),(NULL),('x'),('i'),('e'),('p'),('s'),('j'),('z'),('c'),('a'),('q'),('y'),(NULL),('r'),('v'),(NULL),('r'); +CREATE TABLE t3 ( a int NOT NULL , b varchar(1)) ; +INSERT INTO t3 VALUES (29,'c'); +SELECT * +FROM t1, t2 +WHERE EXISTS ( +SELECT a +FROM t3 +WHERE t3.b = t1.a +AND t3.b <> t2.b +); +a b +c v +c v +c x +c i +c e +c p +c s +c j +c z +c a +c q +c y +c r +c v +c r +INSERT INTO t3 VALUES (2,'c'); +alter table t1 add index aa (a); +alter table t3 add index bb (b); +-- EXIST to IN then semijoin (has priority over IN to EXISTS) +set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=on,materialization=off,subquery_cache=off'; +SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a); +a +c +explain extended +SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index aa aa 4 NULL 2 100.00 Using index +1 PRIMARY t3 ALL bb NULL NULL NULL 2 100.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t3`) where (`test`.`t3`.`b` = `test`.`t1`.`a`) +-- EXIST to IN then IN to EXISTS +set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=off,materialization=off,subquery_cache=off'; +SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a); +a +c +explain extended +SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL aa 4 NULL 2 100.00 Using where; Using index +2 DEPENDENT SUBQUERY t3 ALL bb NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t3`.`b` from `test`.`t3` where (<cache>(`test`.`t1`.`a`) = `test`.`t3`.`b`))) +-- EXIST2IN then MATERIALIZATION +set optimizer_switch='exists_to_in=on,in_to_exists=off,semijoin=off,materialization=on,subquery_cache=off'; +SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a); +a +c +explain extended +SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL aa 4 NULL 2 100.00 Using where; Using index +2 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t3`.`b` from `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`b`))))) +-- NO EXIST2IN +set optimizer_switch='exists_to_in=off,subquery_cache=off'; +SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a); +a +c +explain extended +SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t3 WHERE t3.b = t1.a); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL aa 4 NULL 2 100.00 Using where; Using index +2 DEPENDENT SUBQUERY t3 ALL bb NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where exists(select `test`.`t3`.`a` from `test`.`t3` where (`test`.`t3`.`b` = `test`.`t1`.`a`)) +set optimizer_switch=default; +set optimizer_switch='exists_to_in=on'; +drop table t1,t2,t3; +# +# From group_min_max.test +# +create table t1 ( +a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' ' +); +insert into t1 (a1, a2, b, c, d) values +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'), +('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'), +('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'), +('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'), +('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'), +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'), +('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'), +('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'), +('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'), +('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'); +create index idx_t1_0 on t1 (a1); +create index idx_t1_1 on t1 (a1,a2,b,c); +create index idx_t1_2 on t1 (a1,a2,b); +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +create table t2 ( +a1 char(64), a2 char(64) not null, b char(16), c char(16), d char(16), dummy char(64) default ' ' +); +insert into t2 select * from t1; +insert into t2 (a1, a2, b, c, d) values +('a','a',NULL,'a777','xyz'),('a','a',NULL,'a888','xyz'),('a','a',NULL,'a999','xyz'), +('a','a','a',NULL,'xyz'), +('a','a','b',NULL,'xyz'), +('a','b','a',NULL,'xyz'), +('c','a',NULL,'c777','xyz'),('c','a',NULL,'c888','xyz'),('c','a',NULL,'c999','xyz'), +('d','b','b',NULL,'xyz'), +('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'), +('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'), +('a','a',NULL,'a777','xyz'),('a','a',NULL,'a888','xyz'),('a','a',NULL,'a999','xyz'), +('a','a','a',NULL,'xyz'), +('a','a','b',NULL,'xyz'), +('a','b','a',NULL,'xyz'), +('c','a',NULL,'c777','xyz'),('c','a',NULL,'c888','xyz'),('c','a',NULL,'c999','xyz'), +('d','b','b',NULL,'xyz'), +('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'),('e','a','a',NULL,'xyz'), +('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'),('e','a','b',NULL,'xyz'); +create index idx_t2_0 on t2 (a1); +create index idx_t2_1 on t2 (a1,a2,b,c); +create index idx_t2_2 on t2 (a1,a2,b); +analyze table t2; +Table Op Msg_type Msg_text +test.t2 analyze status Table is already up to date +create table t3 ( +a1 char(1), a2 char(1), b char(1), c char(4) not null, d char(3), dummy char(1) default ' ' +); +insert into t3 (a1, a2, b, c, d) values +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'); +insert into t3 (a1, a2, b, c, d) values +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'); +insert into t3 (a1, a2, b, c, d) values +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'); +insert into t3 (a1, a2, b, c, d) values +('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'), +('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'), +('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'), +('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'), +('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'), +('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'), +('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'), +('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'), +('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'), +('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'), +('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'), +('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'); +create index idx_t3_0 on t3 (a1); +create index idx_t3_1 on t3 (a1,a2,b,c); +create index idx_t3_2 on t3 (a1,a2,b); +analyze table t3; +Table Op Msg_type Msg_text +test.t3 analyze status Table is already up to date +explain select a1,a2,b,c,min(c), max(c) from t1 +where exists ( select * from t2 +where t2.c in (select c from t3 where t3.c > t1.b) and +t2.c > 'b1' ) +group by a1,a2,b; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index +2 DEPENDENT SUBQUERY t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index +2 DEPENDENT SUBQUERY t3 index NULL idx_t3_1 10 NULL 192 Using where; Using index; FirstMatch(t2); Using join buffer (flat, BNL join) +select a1,a2,b,c,min(c), max(c) from t1 +where exists ( select * from t2 +where t2.c in (select c from t3 where t3.c > t1.b) and +t2.c > 'b1' ) +group by a1,a2,b; +a1 a2 b c min(c) max(c) +a a a a111 a111 d111 +a a b e112 e112 h112 +a b a i121 i121 l121 +a b b m122 m122 p122 +b a a a211 a211 d211 +b a b e212 e212 h212 +b b a i221 i221 l221 +b b b m222 m222 p222 +c a a a311 a311 d311 +c a b e312 e312 h312 +c b a i321 i321 l321 +c b b m322 m322 p322 +d a a a411 a411 d411 +d a b e412 e412 h412 +d b a i421 i421 l421 +d b b m422 m422 p422 +explain select a1,a2,b,c,min(c), max(c) from t1 +where exists ( select * from t2 +where t2.c in (select c from t3 where t3.c > t1.c) and +t2.c > 'b1' ) +group by a1,a2,b; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index +2 DEPENDENT SUBQUERY t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index +2 DEPENDENT SUBQUERY t3 index NULL idx_t3_1 10 NULL 192 Using where; Using index; FirstMatch(t2); Using join buffer (flat, BNL join) +select a1,a2,b,c,min(c), max(c) from t1 +where exists ( select * from t2 +where t2.c in (select c from t3 where t3.c > t1.c) and +t2.c > 'b1' ) +group by a1,a2,b; +a1 a2 b c min(c) max(c) +a a a a111 a111 d111 +a a b e112 e112 h112 +a b a i121 i121 l121 +a b b m122 m122 p122 +b a a a211 a211 d211 +b a b e212 e212 h212 +b b a i221 i221 l221 +b b b m222 m222 p222 +c a a a311 a311 d311 +c a b e312 e312 h312 +c b a i321 i321 l321 +c b b m322 m322 o322 +d a a a411 a411 d411 +d a b e412 e412 h412 +d b a i421 i421 l421 +d b b m422 m422 o422 +drop table t1, t2, t3; +CREATE TABLE t1 ( a INT ); +INSERT INTO t1 VALUES (7),(0); +CREATE TABLE t2 ( b INT ); +INSERT INTO t2 VALUES (0),(8); +SELECT * FROM t1 WHERE +EXISTS ( SELECT * FROM t2 WHERE b = a ) +OR a > 0; +a +7 +0 +explain extended +SELECT * FROM t1 WHERE +EXISTS ( SELECT * FROM t2 WHERE b = a ) +OR a > 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 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1003 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 `test`.`t2`.`b` from `test`.`t2` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`b`)))))) or (`test`.`t1`.`a` > 0)) +drop tables t1,t2; +CREATE TABLE t1 ( a INT ); +INSERT INTO t1 VALUES (1),(5); +CREATE TABLE t2 ( b INT ) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1); +CREATE TABLE t3 ( c INT ); +INSERT INTO t3 VALUES (4),(5); +SET optimizer_switch='exists_to_in=on,subquery_cache=off,materialization=on,in_to_exists=off,semijoin=off'; +explain extended +SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1; +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 +2 SUBQUERY t2 system NULL NULL NULL NULL 1 100.00 +3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1276 Field or reference 'test.t2.b' of SELECT #3 was resolved in SELECT #2 +Note 1003 select (select 1 from dual where (not(((1 is not null) and <in_optimizer>(1,1 in ( <materialize> (select `test`.`t3`.`c` from `test`.`t3` where (`test`.`t3`.`c` is not null) ), <primary_index_lookup>(1 in <temporary table> on distinct_key where ((1 = `<subquery3>`.`c`))))))))) AS `( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) )` from `test`.`t1` +SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1; +( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) +1 +1 +SET optimizer_switch='exists_to_in=on,subquery_cache=off'; +explain extended +SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1; +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 +2 SUBQUERY t2 system NULL NULL NULL NULL 1 100.00 +3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1276 Field or reference 'test.t2.b' of SELECT #3 was resolved in SELECT #2 +Note 1003 select (select 1 from dual where (not(((1 is not null) and <in_optimizer>(1,1 in ( <materialize> (select `test`.`t3`.`c` from `test`.`t3` where (`test`.`t3`.`c` is not null) ), <primary_index_lookup>(1 in <temporary table> on distinct_key where ((1 = `<subquery3>`.`c`))))))))) AS `( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) )` from `test`.`t1` +SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1; +( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) +1 +1 +SET optimizer_switch='exists_to_in=off,subquery_cache=off'; +explain extended +SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1; +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 +2 SUBQUERY t2 system NULL NULL NULL NULL 1 100.00 +3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1276 Field or reference 'test.t2.b' of SELECT #3 was resolved in SELECT #2 +Note 1003 select (select 1 from dual where (not(exists(select `test`.`t3`.`c` from `test`.`t3` where (`test`.`t3`.`c` = 1))))) AS `( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) )` from `test`.`t1` +SELECT ( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1; +( SELECT b FROM t2 WHERE NOT EXISTS ( SELECT c FROM t3 WHERE c = b ) ) +1 +1 +set optimizer_switch=default; +set optimizer_switch='exists_to_in=on'; +drop table t1,t2,t3; +# multi condition test +CREATE TABLE t1 ( a varchar(1), a1 varchar(1)) ; +INSERT INTO t1 VALUES ('c', 'c'), ('b', 'b'); +CREATE TABLE t3 ( a int NOT NULL , b varchar(1), b1 varchar(1)) ; +INSERT INTO t3 VALUES (29,'c','c'); +INSERT INTO t3 VALUES (2,'c','c'); +alter table t1 add index aa (a,a1); +alter table t3 add index bb (b,b1); +-- EXIST to IN then semijoin (has priority over IN to EXISTS) +set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=on,materialization=off,subquery_cache=off'; +SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1); +a a1 +c c +explain extended +SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t3 index bb bb 8 NULL 2 100.00 Using where; Using index; LooseScan +1 PRIMARY t1 ref aa aa 8 test.t3.b,test.t3.b1 2 100.00 Using index +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1276 Field or reference 'test.t1.a1' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`a1` AS `a1` from `test`.`t1` semi join (`test`.`t3`) where ((`test`.`t1`.`a` = `test`.`t3`.`b`) and (`test`.`t1`.`a1` = `test`.`t3`.`b1`)) +-- EXIST to IN then IN to EXISTS +set optimizer_switch='exists_to_in=on,in_to_exists=on,semijoin=off,materialization=off,subquery_cache=off'; +SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1); +a a1 +c c +explain extended +SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL aa 8 NULL 2 100.00 Using where; Using index +2 DEPENDENT SUBQUERY t3 index_subquery bb bb 8 func,func 2 100.00 Using index; Using where +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1276 Field or reference 'test.t1.a1' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`a1` AS `a1` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`a1`),<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in t3 on bb where ((<cache>(`test`.`t1`.`a`) = `test`.`t3`.`b`) and (<cache>(`test`.`t1`.`a1`) = `test`.`t3`.`b1`))))) +-- EXIST2IN then MATERIALIZATION +set optimizer_switch='exists_to_in=on,in_to_exists=off,semijoin=off,materialization=on,subquery_cache=off'; +SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1); +a a1 +c c +explain extended +SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL aa 8 NULL 2 100.00 Using where; Using index +2 MATERIALIZED t3 index NULL bb 8 NULL 2 100.00 Using index +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1276 Field or reference 'test.t1.a1' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`a1` AS `a1` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`a1`),(`test`.`t1`.`a`,`test`.`t1`.`a1`) in ( <materialize> (select `test`.`t3`.`b`,`test`.`t3`.`b1` from `test`.`t3` where 1 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where ((`test`.`t1`.`a` = `<subquery2>`.`b`) and (`test`.`t1`.`a1` = `<subquery2>`.`b1`))))) +-- NO EXIST2IN +set optimizer_switch='exists_to_in=off,subquery_cache=off'; +SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1); +a a1 +c c +explain extended +SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t3 WHERE t3.b = t1.a and t3.b1 = t1.a1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL aa 8 NULL 2 100.00 Using where; Using index +2 DEPENDENT SUBQUERY t3 ref bb bb 8 test.t1.a,test.t1.a1 2 100.00 Using index +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1276 Field or reference 'test.t1.a1' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`a1` AS `a1` from `test`.`t1` where exists(select 1 from `test`.`t3` where ((`test`.`t3`.`b` = `test`.`t1`.`a`) and (`test`.`t3`.`b1` = `test`.`t1`.`a1`))) +set optimizer_switch=default; +set optimizer_switch='exists_to_in=on'; +drop table t1,t3; +# +# MDEV-159 Assertion about not marked for read failed in +# String* Field_varstring::val_str(String*, String*) +# +SET optimizer_switch = REPLACE( @@optimizer_switch, '=on', '=off' ); +SET optimizer_switch='in_to_exists=on,exists_to_in=on'; +CREATE TABLE t1 ( a VARCHAR(1) ); +INSERT INTO t1 VALUES ('k'),('m'); +CREATE TABLE t2 ( b INT, +c VARCHAR(1), +d VARCHAR(1) NOT NULL ); +INSERT INTO t2 VALUES +(4,'j','j'),(6,'v','v'); +CREATE ALGORITHM=MERGE VIEW v AS SELECT * FROM t2 WHERE b < 1; +SELECT c FROM v +WHERE EXISTS ( +SELECT * FROM t1, t2 +WHERE a <= v.d AND b = v.b +); +c +explain extended +SELECT c FROM v +WHERE EXISTS ( +SELECT * FROM t1, t2 +WHERE a <= v.d AND b = v.b +); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) +Warnings: +Note 1276 Field or reference 'v.d' of SELECT #2 was resolved in SELECT #1 +Note 1276 Field or reference 'v.b' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`t2`.`c` AS `c` from `test`.`t2` where (<in_optimizer>(`test`.`t2`.`b`,<exists>(select `test`.`t2`.`b` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`a` <= `test`.`t2`.`d`) and (<cache>(`test`.`t2`.`b`) = `test`.`t2`.`b`)))) and (`test`.`t2`.`b` < 1)) +set optimizer_switch=default; +set optimizer_switch='exists_to_in=on'; +drop view v; +drop table t1,t2; +# +# MDEV-160 Exists2In: Crash in in hp_movelink with subquery_cache=ON +# +SET optimizer_switch = 'in_to_exists=on,subquery_cache=on,exists_to_in=on'; +CREATE TABLE t1 ( +a VARCHAR(3) NOT NULL, +b VARCHAR(50) +); +INSERT INTO t1 VALUES +('USA','Chinese'),('USA','English'), +('FRA','French'),('ITA','Italian'); +CREATE TABLE t2 ( c VARCHAR(3) ); +INSERT INTO t2 VALUES ('USA'),('FRA'); +SELECT * FROM t1 AS alias1, t1 AS alias2 +WHERE EXISTS ( +SELECT * FROM t1, t2 +WHERE a <= alias2.a AND c = alias1.b +) OR alias1 .a = 'foo'; +a b a b +SELECT * FROM t1 AS alias1, t1 AS alias2 +WHERE EXISTS ( +SELECT * FROM t1, t2 +WHERE a <= alias2.a AND c = alias1.a +) OR alias1 .a = 'foo'; +a b a b +USA Chinese USA Chinese +USA English USA Chinese +FRA French USA Chinese +USA Chinese USA English +USA English USA English +FRA French USA English +USA Chinese FRA French +USA English FRA French +FRA French FRA French +USA Chinese ITA Italian +USA English ITA Italian +FRA French ITA Italian +drop table t1,t2; +set optimizer_switch=default; +set optimizer_switch='exists_to_in=on'; +# +# MDEV-160 Exists2In: Crash in in hp_movelink with subquery_cache=ON +# +SET optimizer_switch = 'in_to_exists=on,subquery_cache=on,exists_to_in=on'; +CREATE TABLE t1 ( +a VARCHAR(3) NOT NULL, +b VARCHAR(50) +); +INSERT INTO t1 VALUES +('USA','Chinese'),('USA','English'), +('FRA','French'),('ITA','Italian'); +CREATE TABLE t2 ( c VARCHAR(3) ); +INSERT INTO t2 VALUES ('USA'),('FRA'); +SELECT * FROM t1 AS alias1, t1 AS alias2 +WHERE EXISTS ( +SELECT * FROM t1, t2 +WHERE a <= alias2.a AND c = alias1.b +) OR alias1 .a = 'foo'; +a b a b +explain extended +SELECT * FROM t1 AS alias1, t1 AS alias2 +WHERE EXISTS ( +SELECT * FROM t1, t2 +WHERE a <= alias2.a AND c = alias1.b +) OR alias1 .a = 'foo'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY alias1 ALL NULL NULL NULL NULL 4 100.00 +1 PRIMARY alias2 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (flat, BNL join) +Warnings: +Note 1276 Field or reference 'test.alias2.a' of SELECT #2 was resolved in SELECT #1 +Note 1276 Field or reference 'test.alias1.b' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`alias1`.`a` AS `a`,`test`.`alias1`.`b` AS `b`,`test`.`alias2`.`a` AS `a`,`test`.`alias2`.`b` AS `b` from `test`.`t1` `alias1` join `test`.`t1` `alias2` where (<expr_cache><`test`.`alias1`.`b`,`test`.`alias2`.`a`>(<in_optimizer>(`test`.`alias1`.`b`,<exists>(select `test`.`t2`.`c` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`a` <= `test`.`alias2`.`a`) and (<cache>(`test`.`alias1`.`b`) = `test`.`t2`.`c`))))) or (`test`.`alias1`.`a` = 'foo')) +drop table t1,t2; +set optimizer_switch=default; +set optimizer_switch='exists_to_in=on'; +# +# MDEV-245 Exists2In: Wrong result (extra rows) with +# exists_to_in=ON, materialization=OFF, NOT EXISTS subquery +# +SET optimizer_switch='materialization=off,exists_to_in=on'; +CREATE TABLE t1 ( a INT ) ; +INSERT INTO t1 VALUES (0),(8),(1); +CREATE TABLE t2 ( b INT ) ; +INSERT INTO t2 VALUES (1),(2),(3); +SELECT * FROM t1 WHERE NOT EXISTS ( SELECT * FROM t2 WHERE b = a ); +a +0 +8 +explain extended +SELECT * FROM t1 WHERE NOT EXISTS ( SELECT * FROM t2 WHERE b = a ); +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 t2 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (not(((`test`.`t1`.`a` is not null) and <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`b` from `test`.`t2` where ((`test`.`t2`.`b` is not null) and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`b`)))))))) +drop table t1,t2; +set optimizer_switch=default; +set optimizer_switch='exists_to_in=on'; +# +# MDEV-243 Wrong result (extra or missing rows) with +# exists_to_in + materialization, EXISTS subquery +# +SET optimizer_switch='index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=on'; +CREATE TABLE t1 ( a VARCHAR(1), b VARCHAR(1) ); +INSERT INTO t1 VALUES ('v','v'),('s','v'); +SELECT * FROM t1 AS alias +WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b ); +a b +s v +explain extended +SELECT * FROM t1 AS alias +WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b ); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY alias ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(alias); Using join buffer (flat, BNL join) +Warnings: +Note 1276 Field or reference 'test.alias.a' of SELECT #2 was resolved in SELECT #1 +Note 1276 Field or reference 'test.alias.b' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`alias`.`a` AS `a`,`test`.`alias`.`b` AS `b` from `test`.`t1` `alias` semi join (`test`.`t1`) where ((`test`.`t1`.`a` = `test`.`alias`.`b`) and (`test`.`alias`.`b` > `test`.`alias`.`a`)) +SET optimizer_switch = REPLACE( @@optimizer_switch, '=on', '=off' ); +SET optimizer_switch = 'exists_to_in=on,materialization=on,semijoin=off'; +SELECT * FROM t1 AS alias +WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b ); +a b +s v +explain extended +SELECT * FROM t1 AS alias +WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b ); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY alias ALL NULL NULL NULL NULL 2 100.00 Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1276 Field or reference 'test.alias.a' of SELECT #2 was resolved in SELECT #1 +Note 1276 Field or reference 'test.alias.b' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`alias`.`a` AS `a`,`test`.`alias`.`b` AS `b` from `test`.`t1` `alias` where <in_optimizer>(`test`.`alias`.`b`,<exists>(select `test`.`t1`.`a` from `test`.`t1` where ((`test`.`t1`.`a` > `test`.`alias`.`a`) and (<cache>(`test`.`alias`.`b`) = `test`.`t1`.`a`)))) +SET optimizer_switch = 'exists_to_in=on,materialization=on,semijoin=on'; +SELECT * FROM t1 AS alias +WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b ); +a b +s v +explain extended +SELECT * FROM t1 AS alias +WHERE EXISTS ( SELECT * FROM t1 WHERE a > alias.a AND a = alias.b ); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY alias ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Start temporary; End temporary +Warnings: +Note 1276 Field or reference 'test.alias.a' of SELECT #2 was resolved in SELECT #1 +Note 1276 Field or reference 'test.alias.b' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`alias`.`a` AS `a`,`test`.`alias`.`b` AS `b` from `test`.`t1` `alias` semi join (`test`.`t1`) where ((`test`.`t1`.`a` = `test`.`alias`.`b`) and (`test`.`alias`.`b` > `test`.`alias`.`a`)) +drop table t1; +set optimizer_switch=default; +set optimizer_switch='exists_to_in=on'; +# +# MDEV-403 Wrong result (missing rows) with subquery in +# EXISTS and an OR condition outside +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (2),(3); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (1),(3); +SET optimizer_switch = 'exists_to_in=off,in_to_exists=on'; +SELECT * FROM t1 AS alias1, t2 AS alias2 +WHERE EXISTS ( +SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b +) OR a = 5; +a b +3 1 +SET optimizer_switch = 'exists_to_in=on,in_to_exists=on'; +SELECT * FROM t1 AS alias1, t2 AS alias2 +WHERE EXISTS ( +SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b +) OR a = 5; +a b +3 1 +explain extended +SELECT * FROM t1 AS alias1, t2 AS alias2 +WHERE EXISTS ( +SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b +) OR a = 5; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 100.00 +1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1276 Field or reference 'test.alias1.a' of SELECT #2 was resolved in SELECT #1 +Note 1276 Field or reference 'test.alias2.b' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`alias1`.`a` AS `a`,`test`.`alias2`.`b` AS `b` from `test`.`t1` `alias1` join `test`.`t2` `alias2` where (<expr_cache><`test`.`alias1`.`a`,`test`.`alias2`.`b`>(<in_optimizer>(`test`.`alias1`.`a`,<exists>(select `test`.`t2`.`b` from `test`.`t2` where ((`test`.`t2`.`b` > `test`.`alias2`.`b`) and (<cache>(`test`.`alias1`.`a`) = `test`.`t2`.`b`))))) or (`test`.`alias1`.`a` = 5)) +drop table t1, t2; +set optimizer_switch=default; +set optimizer_switch='exists_to_in=on'; +# +# MDEV-404: Wrong result (extra rows) with STRAIGHT_JOIN, +# EXISTS subquery, NOT NULL column +# (same as above) +# +SET optimizer_switch = 'exists_to_in=on,in_to_exists=on'; +CREATE TABLE t1 (a INT, b VARCHAR(1) NOT NULL); +INSERT INTO t1 VALUES (1,'s'),(2,'e'); +SELECT STRAIGHT_JOIN * FROM t1 AS alias1, t1 AS alias2 +WHERE EXISTS ( SELECT 1 FROM t1 WHERE b < alias2.b AND a = alias1.a ); +a b a b +2 e 1 s +drop table t1; +set optimizer_switch=default; +set optimizer_switch='exists_to_in=on'; +# +# MDEV-3800: ORDER BY doesn't work with exists_to_in=ON on +# a query with EXISTS subquery and OR condition +# +SET optimizer_switch = 'in_to_exists=on,exists_to_in=on'; +CREATE TABLE t1 (a INT, b VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (4,'j'),(6,'v'),(3,'c'); +CREATE TABLE t2 (c VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('b'),('y'); +SELECT a FROM t1 +WHERE EXISTS ( +SELECT 1 FROM t2 WHERE c = b +) OR b NOT IN ('U') +ORDER BY a; +a +3 +4 +6 +select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`b` in (select `test`.`t2`.`c` from `test`.`t2` where 1 ) or (`test`.`t1`.`b` <> 'U') order by `test`.`t1`.`a`; +a +3 +4 +6 +drop table t1,t2; +set optimizer_switch=default; +set optimizer_switch='exists_to_in=on'; +# +# correct calculation of reserved items (postreview-fix) +# +create table t1 (col1 int, col2 int, col3 int); +insert into t1 values (1,2,3),(2,3,4),(4,5,6); +create table t2 as select * from t1; +explain extended +select * from t1 where exists (select col2 from t2 where t2.col1=t1.col1 and t2.col2=t1.col2); +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 <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.col1' of SELECT #2 was resolved in SELECT #1 +Note 1276 Field or reference 'test.t1.col2' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`t1`.`col1` AS `col1`,`test`.`t1`.`col2` AS `col2`,`test`.`t1`.`col3` AS `col3` from `test`.`t1` semi join (`test`.`t2`) where 1 +select * from t1 where exists (select col2 from t2 where t2.col1=t1.col1 and t2.col2=t1.col2); +col1 col2 col3 +1 2 3 +2 3 4 +4 5 6 +drop table t1,t2; +# +# MDEV-3879: Exists2In: Wrong result (extra row) and unexpected +# warning with exists_to_in=on and a NOT EXISTS subquery +# +SET optimizer_switch = 'exists_to_in=on'; +CREATE TABLE t1 (a1 INT, b1 CHAR(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (3,'y'),(6,'w'); +CREATE TABLE t2 (a2 INT, b2 CHAR(1)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (3,'y'),(6,'d'); +SELECT * FROM t1 +WHERE NOT EXISTS ( SELECT * FROM t2 WHERE b2 = b1 AND a2 = a1 ); +a1 b1 +6 w +drop table t1, t2; +# +# MDEV-3880: Wrong result (missing rows) with exists_to_in=on, +# LEFT JOIN and NOT EXISTS subquery. +# (Duplicate of above MDEV-3879). +# +SET optimizer_switch = 'exists_to_in=on'; +CREATE TABLE t1 (a1 INT, b1 CHAR(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (4,'b'),(5,'y'); +CREATE TABLE t2 (b2 CHAR(1)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('z'),('b'); +CREATE TABLE t3 (a3 INT, b3 CHAR(1)) ENGINE=MyISAM; +INSERT INTO t3 VALUES (4,'j'),(6,'v'); +SELECT * FROM t1 LEFT JOIN t2 ON ( b2 = b1 ) +WHERE NOT EXISTS ( SELECT * FROM t3 WHERE b3 = b2 AND a3 = a1 ) ; +a1 b1 b2 +4 b b +5 y NULL +drop table t1, t2, t3; +# +# MDEV-3881: Endless loop and crash in Item_ref::real_item with +# exists_to_in=on, NOT EXISTS subquery, merge view or from subquery, +# constant table +# +SET optimizer_switch = 'exists_to_in=on'; +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(7); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (8); +CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t2; +CREATE TABLE t3 (c INT) ENGINE=MyISAM; +INSERT INTO t3 VALUES (4),(6); +SELECT * FROM t1, v1 WHERE NOT EXISTS ( SELECT * FROM t3 WHERE c = b ) AND a = b; +a b +drop view v1; +drop table t1, t2, t3; +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(7); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (8); +CREATE TABLE t3 (c INT) ENGINE=MyISAM; +INSERT INTO t3 VALUES (4),(6); +SELECT * FROM t1, ( SELECT * FROM t2 ) alias WHERE NOT EXISTS ( SELECT * FROM t3 WHERE c = b ) AND a = b; +a b +drop table t1, t2, t3; +# +# MDEV-3906: Server crashes in Dependency_marker::visit_field +# on 2nd execution of PS with exists_to_in and NOT EXISTS subquery +# +SET optimizer_switch='exists_to_in=on'; +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(7); +PREPARE stmt FROM ' +SELECT * FROM t1 AS alias +WHERE NOT EXISTS ( SELECT * FROM t1 WHERE t1.a = alias.a ) +'; +EXECUTE stmt; +a +EXECUTE stmt; +a +drop table t1; +# +# MDEV-3904: Assertion `in_subs->has_strategy()' failed in +# JOIN::choose_subquery_plan on 2nd execution of PS with +# exists_to_in+semijoin, EXISTS subquery, MERGE view or FROM subquery +# +SET optimizer_switch='in_to_exists=on,semijoin=on,exists_to_in=on'; +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (4),(6); +CREATE ALGORITHM=MERGE VIEW v AS +SELECT * FROM t1 WHERE EXISTS ( SELECT * FROM t2 WHERE b = a ); +PREPARE stmt FROM ' SELECT * FROM v '; +EXECUTE stmt; +a +EXECUTE stmt; +a +drop view v; +drop table t1,t2; +set optimizer_switch=default; +set optimizer_switch='exists_to_in=on'; +# +# MDEV-3903: Server crashes in Item_cond::fix_fields on 2nd execution +# of a prepared stmt with exists_to_in+materialization+semijoin, +# EXISTS subquery, STRAIGHT_JOIN +# +SET optimizer_switch='materialization=on,semijoin=on,exists_to_in=on'; +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (3),(4); +PREPARE stmt FROM +'SELECT STRAIGHT_JOIN * FROM t1 +WHERE EXISTS ( SELECT * FROM t2 WHERE b = a )'; +EXECUTE stmt; +a +EXECUTE stmt; +a +drop table t1,t2; +set optimizer_switch=default; +set optimizer_switch='exists_to_in=on'; +# +# MDEV-4152: Wrong result (missing rows) with exists_to_in=on, +# inner joins +# +SET optimizer_switch='materialization=on,semijoin=on,exists_to_in=on'; +CREATE TABLE t1 (i INT, c1 CHAR(5), c2 CHAR(5), t1_field VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1,'test1','test2','f'), (2,'test3','test4','d'); +CREATE TABLE t2 (t2_field VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('m'), ('b'); +CREATE TABLE t3 (t3_field VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t3 VALUES ('b'),('c'); +SELECT * FROM t1, t2 outer_t2 +WHERE EXISTS ( SELECT 1 FROM t2, t3 WHERE t3_field = outer_t2.t2_field AND t2_field <= t1_field ); +i c1 c2 t1_field t2_field +1 test1 test2 f b +2 test3 test4 d b +drop table t1,t2,t3; +set optimizer_switch=default; +set optimizer_switch='exists_to_in=on'; +set optimizer_switch=default; diff --git a/mysql-test/r/subselect_exists2in_costmat.result b/mysql-test/r/subselect_exists2in_costmat.result new file mode 100644 index 00000000000..a46996d9bad --- /dev/null +++ b/mysql-test/r/subselect_exists2in_costmat.result @@ -0,0 +1,103 @@ +set @subselect_mat_cost=@@optimizer_switch; +set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; +set long_query_time=0.1; +drop database if exists world; +set names utf8; +create database world; +use world; +CREATE TABLE Country ( +Code char(3) NOT NULL default '', +Name char(52) NOT NULL default '', +SurfaceArea float(10,2) NOT NULL default '0.00', +Population int(11) NOT NULL default '0', +Capital int(11) default NULL, +PRIMARY KEY (Code), +UNIQUE INDEX (Name) +); +CREATE TABLE City ( +ID int(11) NOT NULL auto_increment, +Name char(35) NOT NULL default '', +Country char(3) NOT NULL default '', +Population int(11) NOT NULL default '0', +PRIMARY KEY (ID), +INDEX (Population), +INDEX (Country) +); +CREATE TABLE CountryLanguage ( +Country char(3) NOT NULL default '', +Language char(30) NOT NULL default '', +Percentage float(3,1) NOT NULL default '0.0', +PRIMARY KEY (Country, Language), +INDEX (Percentage) +); +Make the schema and data more diverse by adding more indexes, nullable +columns, and NULL data. +create index SurfaceArea on Country(SurfaceArea); +create index Language on CountryLanguage(Language); +create index CityName on City(Name); +alter table City change population population int(11) null default 0; +select max(id) from City into @max_city_id; +insert into City values (@max_city_id + 1,'Kilifarevo','BGR',NULL); +SELECT COUNT(*) FROM Country; +COUNT(*) +239 +SELECT COUNT(*) FROM City; +COUNT(*) +4080 +SELECT COUNT(*) FROM CountryLanguage; +COUNT(*) +984 +set @@optimizer_switch = 'exists_to_in=on,in_to_exists=on,semijoin=on,materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on'; + +1. Subquery in a disjunctive WHERE clause of the outer query. + + +Q1.1m: +MATERIALIZATION: there are too many rows in the outer query +to be looked up in the inner table. +EXPLAIN +SELECT Name FROM Country +WHERE (EXISTS (select 1 from City where City.Population > 100000 and +Code = Country) OR +Name LIKE 'L%') AND +surfacearea > 1000000; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY Country ALL Name,SurfaceArea NULL NULL NULL 239 Using where +2 MATERIALIZED City ALL Population,Country NULL NULL NULL 4080 Using where +SELECT Name FROM Country +WHERE (EXISTS (select 1 from City where City.Population > 100000 and +Code = Country) OR +Name LIKE 'L%') AND +surfacearea > 1000000; +Name +Algeria +Angola +Argentina +Australia +Bolivia +Brazil +Egypt +South Africa +Ethiopia +Indonesia +India +Iran +Canada +Kazakstan +China +Colombia +Congo, The Democratic Republic of the +Libyan Arab Jamahiriya +Mali +Mauritania +Mexico +Mongolia +Niger +Peru +Saudi Arabia +Sudan +Chad +Russian Federation +United States +drop database world; +set optimizer_switch=@subselect_mat_cost; diff --git a/mysql-test/r/subselect_exists_to_in.result b/mysql-test/r/subselect_exists_to_in.result new file mode 100644 index 00000000000..f9d4c140936 --- /dev/null +++ b/mysql-test/r/subselect_exists_to_in.result @@ -0,0 +1,7021 @@ +select @@optimizer_switch like '%exists_to_in=on%'; +@@optimizer_switch like '%exists_to_in=on%' +0 +set optimizer_switch='exists_to_in=on'; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12; +drop view if exists v2; +set @subselect_tmp=@@optimizer_switch; +set @@optimizer_switch=ifnull(@optimizer_switch_for_subselect_test, +"semijoin=on,firstmatch=on,loosescan=on,semijoin_with_cache=on,partial_match_rowid_merge=off,partial_match_table_scan=off"); +set join_cache_level=1; +set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; +select (select 2); +(select 2) +2 +explain extended select (select 2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1249 Select 2 was reduced during optimization +Note 1003 select 2 AS `(select 2)` +SELECT (SELECT 1) UNION SELECT (SELECT 2); +(SELECT 1) +1 +2 +explain extended SELECT (SELECT 1) UNION SELECT (SELECT 2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1249 Select 2 was reduced during optimization +Note 1249 Select 4 was reduced during optimization +Note 1003 select 1 AS `(SELECT 1)` union select 2 AS `(SELECT 2)` +SELECT (SELECT (SELECT 0 UNION SELECT 0)); +(SELECT (SELECT 0 UNION SELECT 0)) +0 +explain extended SELECT (SELECT (SELECT 0 UNION SELECT 0)); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNION RESULT <union3,4> ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1249 Select 2 was reduced during optimization +Note 1003 select (select 0 union select 0) AS `(SELECT (SELECT 0 UNION SELECT 0))` +SELECT (SELECT 1 FROM (SELECT 1) as b HAVING a=1) as a; +ERROR 42S22: Reference 'a' not supported (forward reference in item list) +SELECT (SELECT 1 FROM (SELECT 1) as b HAVING b=1) as a,(SELECT 1 FROM (SELECT 1) as c HAVING a=1) as b; +ERROR 42S22: Reference 'b' not supported (forward reference in item list) +SELECT (SELECT 1),MAX(1) FROM (SELECT 1) as a; +(SELECT 1) MAX(1) +1 1 +SELECT (SELECT a) as a; +ERROR 42S22: Reference 'a' not supported (forward reference in item list) +EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00 +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 +Note 1276 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 +Note 1003 select 1 AS `1` from dual having ((select 1) = 1) +SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; +1 +1 +SELECT (SELECT 1), a; +ERROR 42S22: Unknown column 'a' in 'field list' +SELECT 1 as a FROM (SELECT 1) as b HAVING (SELECT a)=1; +a +1 +SELECT 1 FROM (SELECT (SELECT a) b) c; +ERROR 42S22: Unknown column 'a' in 'field list' +SELECT * FROM (SELECT 1 as id) b WHERE id IN (SELECT * FROM (SELECT 1 as id) c ORDER BY id); +id +1 +SELECT * FROM (SELECT 1) a WHERE 1 IN (SELECT 1,1); +ERROR 21000: Operand should contain 1 column(s) +SELECT 1 IN (SELECT 1); +1 IN (SELECT 1) +1 +SELECT 1 FROM (SELECT 1 as a) b WHERE 1 IN (SELECT (SELECT a)); +1 +1 +select (SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE(1)); +ERROR HY000: Incorrect usage of PROCEDURE and subquery +SELECT 1 FROM (SELECT 1) a PROCEDURE ANALYSE((SELECT 1)); +ERROR HY000: Incorrect parameters to procedure 'ANALYSE' +SELECT (SELECT 1) as a FROM (SELECT 1) b WHERE (SELECT a) IS NULL; +ERROR 42S22: Unknown column 'a' in 'field list' +SELECT (SELECT 1) as a FROM (SELECT 1) b WHERE (SELECT a) IS NOT NULL; +ERROR 42S22: Unknown column 'a' in 'field list' +SELECT (SELECT 1,2,3) = ROW(1,2,3); +(SELECT 1,2,3) = ROW(1,2,3) +1 +SELECT (SELECT 1,2,3) = ROW(1,2,1); +(SELECT 1,2,3) = ROW(1,2,1) +0 +SELECT (SELECT 1,2,3) < ROW(1,2,1); +(SELECT 1,2,3) < ROW(1,2,1) +0 +SELECT (SELECT 1,2,3) > ROW(1,2,1); +(SELECT 1,2,3) > ROW(1,2,1) +1 +SELECT (SELECT 1,2,3) = ROW(1,2,NULL); +(SELECT 1,2,3) = ROW(1,2,NULL) +NULL +SELECT ROW(1,2,3) = (SELECT 1,2,3); +ROW(1,2,3) = (SELECT 1,2,3) +1 +SELECT ROW(1,2,3) = (SELECT 1,2,1); +ROW(1,2,3) = (SELECT 1,2,1) +0 +SELECT ROW(1,2,3) < (SELECT 1,2,1); +ROW(1,2,3) < (SELECT 1,2,1) +0 +SELECT ROW(1,2,3) > (SELECT 1,2,1); +ROW(1,2,3) > (SELECT 1,2,1) +1 +SELECT ROW(1,2,3) = (SELECT 1,2,NULL); +ROW(1,2,3) = (SELECT 1,2,NULL) +NULL +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a'); +(SELECT 1.5,2,'a') = ROW(1.5,2,'a') +1 +SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b'); +(SELECT 1.5,2,'a') = ROW(1.5,2,'b') +0 +SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b'); +(SELECT 1.5,2,'a') = ROW('1.5b',2,'b') +0 +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: '1.5b' +SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a'); +(SELECT 'b',2,'a') = ROW(1.5,2,'a') +0 +SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a'); +(SELECT 1.5,2,'a') = ROW(1.5,'2','a') +1 +SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a'); +(SELECT 1.5,'c','a') = ROW(1.5,2,'a') +0 +SELECT (SELECT * FROM (SELECT 'test' a,'test' b) a); +ERROR 21000: Operand should contain 1 column(s) +SELECT 1 as a,(SELECT a+a) b,(SELECT b); +a b (SELECT b) +1 2 2 +create table t1 (a int); +create table t2 (a int, b int); +create table t3 (a int); +create table t4 (a int not null, b int not null); +insert into t1 values (2); +insert into t2 values (1,7),(2,7); +insert into t4 values (4,8),(3,8),(5,9); +select (select a from t1 where t1.a = a1) as a2, (select b from t2 where t2.b=a2) as a1; +ERROR 42S22: Reference 'a1' not supported (forward reference in item list) +select (select a from t1 where t1.a=t2.a), a from t2; +(select a from t1 where t1.a=t2.a) a +NULL 1 +2 2 +select (select a from t1 where t1.a=t2.b), a from t2; +(select a from t1 where t1.a=t2.b) a +NULL 1 +NULL 2 +select (select a from t1), a, (select 1 union select 2 limit 1) from t2; +(select a from t1) a (select 1 union select 2 limit 1) +2 1 1 +2 2 1 +select (select a from t3), a from t2; +(select a from t3) a +NULL 1 +NULL 2 +select * from t2 where t2.a=(select a from t1); +a b +2 7 +insert into t3 values (6),(7),(3); +select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1); +a b +1 7 +2 7 +(select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 order by a limit 2) limit 3; +a b +1 7 +2 7 +3 8 +(select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a); +a b +1 7 +2 7 +4 8 +3 8 +explain extended (select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where +2 SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using filesort +3 UNION t4 ALL NULL NULL NULL NULL 3 100.00 Using where +4 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 +NULL UNION RESULT <union1,3> ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` from `test`.`t3` order by 1 desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) from `test`.`t2`))) +select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2; +(select a from t3 where a<t2.a*4 order by 1 desc limit 1) a +3 1 +7 2 +select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from +(select * from t2 where a>1) as tt; +(select t3.a from t3 where a<8 order by 1 desc limit 1) a +7 2 +set @tmp_optimizer_switch=@@optimizer_switch; +set optimizer_switch='derived_merge=off,derived_with_keys=off'; +explain extended select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from +(select * from t2 where a>1) as tt; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 2 100.00 +3 DERIVED t2 ALL NULL NULL NULL NULL 2 100.00 Using where +2 SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using filesort +Warnings: +Note 1003 select (select `test`.`t3`.`a` from `test`.`t3` where (`test`.`t3`.`a` < 8) order by 1 desc limit 1) AS `(select t3.a from t3 where a<8 order by 1 desc limit 1)`,`tt`.`a` AS `a` from (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`a` > 1)) `tt` +set optimizer_switch=@tmp_optimizer_switch; +select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3) order by 1 desc limit 1); +a +2 +select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a > t1.a) order by 1 desc limit 1); +a +2 +select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a < t1.a) order by 1 desc limit 1); +a +select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; +b (select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) +8 7.5000 +8 4.5000 +9 7.5000 +explain extended select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t4 ALL NULL NULL NULL NULL 3 100.00 +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 +3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1276 Field or reference 'test.t4.a' of SELECT #3 was resolved in SELECT #1 +Note 1003 select `test`.`t4`.`b` AS `b`,<expr_cache><`test`.`t4`.`a`>((select avg((`test`.`t2`.`a` + (select min(`test`.`t3`.`a`) from `test`.`t3` where (`test`.`t3`.`a` >= `test`.`t4`.`a`)))) from `test`.`t2`)) AS `(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)` from `test`.`t4` +select * from t3 where exists (select * from t2 where t2.b=t3.a); +a +7 +select * from t3 where not exists (select * from t2 where t2.b=t3.a); +a +6 +3 +select * from t3 where a in (select b from t2); +a +7 +select * from t3 where a not in (select b from t2); +a +6 +3 +select * from t3 where a = some (select b from t2); +a +7 +select * from t3 where a <> any (select b from t2); +a +6 +3 +select * from t3 where a = all (select b from t2); +a +7 +select * from t3 where a <> all (select b from t2); +a +6 +3 +insert into t2 values (100, 5); +select * from t3 where a < any (select b from t2); +a +6 +3 +select * from t3 where a < all (select b from t2); +a +3 +select * from t3 where a >= any (select b from t2); +a +6 +7 +explain extended select * from t3 where a >= any (select b from t2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 Using where +2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(`test`.`t3`.`a`,((select min(`test`.`t2`.`b`) from `test`.`t2`) <= <cache>(`test`.`t3`.`a`)))) +select * from t3 where a >= all (select b from t2); +a +7 +delete from t2 where a=100; +select * from t3 where a in (select a,b from t2); +ERROR 21000: Operand should contain 1 column(s) +select * from t3 where a in (select * from t2); +ERROR 21000: Operand should contain 1 column(s) +insert into t4 values (12,7),(1,7),(10,9),(9,6),(7,6),(3,9),(1,10); +select b,max(a) as ma from t4 group by b having b < (select max(t2.a) from t2 where t2.b=t4.b); +b ma +insert into t2 values (2,10); +select b,max(a) as ma from t4 group by b having ma < (select max(t2.a) from t2 where t2.b=t4.b); +b ma +10 1 +delete from t2 where a=2 and b=10; +select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 where t2.b=t4.b); +b ma +7 12 +create table t5 (a int); +select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +NULL 1 +2 2 +insert into t5 values (5); +select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +NULL 1 +2 2 +insert into t5 values (2); +select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) a +NULL 1 +2 2 +explain extended select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 +2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 1 100.00 +3 DEPENDENT UNION t5 ALL NULL NULL NULL NULL 2 100.00 Using where +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1276 Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1 +Note 1276 Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1 +Note 1003 select <expr_cache><`test`.`t2`.`a`>((select 2 from dual where (2 = `test`.`t2`.`a`) union select `test`.`t5`.`a` from `test`.`t5` where (`test`.`t5`.`a` = `test`.`t2`.`a`))) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2` +select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; +ERROR 21000: Subquery returns more than 1 row +create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq)); +create table t7( uq int primary key, name char(25)); +insert into t7 values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta"); +insert into t6 values (1,1),(1,2),(2,2),(1,3); +select * from t6 where exists (select * from t7 where uq = clinic_uq); +patient_uq clinic_uq +1 1 +1 2 +2 2 +explain extended select * from t6 where exists (select * from t7 where uq = clinic_uq); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t7 index PRIMARY PRIMARY 4 NULL 2 100.00 Using index +1 PRIMARY t6 ALL i1 NULL NULL NULL 4 75.00 Using where; Using join buffer (flat, BNL join) +Warnings: +Note 1276 Field or reference 'test.t6.clinic_uq' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t7` join `test`.`t6` where (`test`.`t6`.`clinic_uq` = `test`.`t7`.`uq`) +select * from t1 where a= (select a from t2,t4 where t2.b=t4.b); +ERROR 23000: Column 'a' in field list is ambiguous +drop table t1,t2,t3; +CREATE TABLE t3 (a varchar(20),b char(1) NOT NULL default '0'); +INSERT INTO t3 VALUES ('W','a'),('A','c'),('J','b'); +CREATE TABLE t2 (a varchar(20),b int NOT NULL default '0'); +INSERT INTO t2 VALUES ('W','1'),('A','3'),('J','2'); +CREATE TABLE t1 (a varchar(20),b date NOT NULL default '0000-00-00'); +INSERT INTO t1 VALUES ('W','1732-02-22'),('A','1735-10-30'),('J','1743-04-13'); +SELECT * FROM t1 WHERE b = (SELECT MIN(b) FROM t1); +a b +W 1732-02-22 +SELECT * FROM t2 WHERE b = (SELECT MIN(b) FROM t2); +a b +W 1 +SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3); +a b +W a +CREATE TABLE `t8` ( +`pseudo` varchar(35) character set latin1 NOT NULL default '', +`email` varchar(60) character set latin1 NOT NULL default '', +PRIMARY KEY (`pseudo`), +UNIQUE KEY `email` (`email`) +) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC; +INSERT INTO t8 (pseudo,email) VALUES ('joce','test'); +INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1'); +INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1'); +EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index +4 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index +2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 +3 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index +Warnings: +Note 1003 select 'joce' AS `pseudo`,(select 'test' from `test`.`t8` where 1) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where 1 +SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM +t8 WHERE pseudo='joce'); +ERROR 21000: Operand should contain 1 column(s) +SELECT pseudo FROM t8 WHERE pseudo=(SELECT * FROM t8 WHERE +pseudo='joce'); +ERROR 21000: Operand should contain 1 column(s) +SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); +pseudo +joce +SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo LIKE '%joce%'); +ERROR 21000: Subquery returns more than 1 row +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8; +CREATE TABLE `t1` ( +`topic` mediumint(8) unsigned NOT NULL default '0', +`date` date NOT NULL default '0000-00-00', +`pseudo` varchar(35) character set latin1 NOT NULL default '', +PRIMARY KEY (`pseudo`,`date`,`topic`), +KEY `topic` (`topic`) +) ENGINE=MyISAM ROW_FORMAT=DYNAMIC; +INSERT INTO t1 (topic,date,pseudo) VALUES +('43506','2002-10-02','joce'),('40143','2002-08-03','joce'); +EXPLAIN EXTENDED SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index +Warnings: +Note 1003 select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03') +EXPLAIN EXTENDED SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +2 SUBQUERY t1 index NULL PRIMARY 43 NULL 2 100.00 Using where; Using index +Warnings: +Note 1003 select (select distinct `test`.`t1`.`date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')` +SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; +date +2002-08-03 +SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'); +(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03') +2002-08-03 +SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1) UNION ALL SELECT 1; +1 +1 +1 +1 +SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1) UNION SELECT 1; +ERROR 21000: Subquery returns more than 1 row +EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL topic 3 NULL 2 100.00 Using index +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 select 1 AS `1` from `test`.`t1` where 1 +drop table t1; +CREATE TABLE `t1` ( +`numeropost` mediumint(8) unsigned NOT NULL auto_increment, +`maxnumrep` int(10) unsigned NOT NULL default '0', +PRIMARY KEY (`numeropost`), +UNIQUE KEY `maxnumrep` (`maxnumrep`) +) ENGINE=MyISAM ROW_FORMAT=FIXED; +INSERT INTO t1 (numeropost,maxnumrep) VALUES (40143,1),(43506,2); +CREATE TABLE `t2` ( +`mot` varchar(30) NOT NULL default '', +`topic` mediumint(8) unsigned NOT NULL default '0', +`date` date NOT NULL default '0000-00-00', +`pseudo` varchar(35) NOT NULL default '', +PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`) +) ENGINE=MyISAM ROW_FORMAT=DYNAMIC; +INSERT INTO t2 (mot,topic,date,pseudo) VALUES ('joce','40143','2002-10-22','joce'), ('joce','43506','2002-10-22','joce'); +select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1); +a +40143 +SELECT numeropost,maxnumrep FROM t1 WHERE exists (SELECT 1 FROM t2 WHERE (mot='joce') AND date >= '2002-10-21' AND t1.numeropost = t2.topic) ORDER BY maxnumrep DESC LIMIT 0, 20; +numeropost maxnumrep +43506 2 +40143 1 +SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1) b; +ERROR 42S22: Unknown column 'a' in 'having clause' +SELECT 1 IN (SELECT 1 FROM t2 HAVING a); +ERROR 42S22: Unknown column 'a' in 'having clause' +SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY topic); +mot topic date pseudo +joce 40143 2002-10-22 joce +joce 43506 2002-10-22 joce +SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100); +mot topic date pseudo +SELECT * from t2 where topic IN (SELECT SUM(topic) FROM t1); +mot topic date pseudo +SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic); +mot topic date pseudo +joce 40143 2002-10-22 joce +joce 43506 2002-10-22 joce +SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100); +mot topic date pseudo +SELECT * from t2 where topic = any (SELECT SUM(topic) FROM t1); +mot topic date pseudo +SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic); +mot topic date pseudo +SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100); +mot topic date pseudo +joce 40143 2002-10-22 joce +joce 43506 2002-10-22 joce +SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) from t2; +mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) +joce 40143 2002-10-22 joce 1 +joce 43506 2002-10-22 joce 1 +SELECT * from t2 where topic = all (SELECT SUM(topic) FROM t2); +mot topic date pseudo +SELECT * from t2 where topic <> any (SELECT SUM(topic) FROM t2); +mot topic date pseudo +joce 40143 2002-10-22 joce +joce 43506 2002-10-22 joce +SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000); +mot topic date pseudo +joce 40143 2002-10-22 joce +SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000); +mot topic date pseudo +joce 40143 2002-10-22 joce +SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000); +mot topic date pseudo +joce 40143 2002-10-22 joce +SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) from t2; +mot topic date pseudo topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) +joce 40143 2002-10-22 joce 1 +joce 43506 2002-10-22 joce 0 +drop table t1,t2; +CREATE TABLE `t1` ( +`numeropost` mediumint(8) unsigned NOT NULL auto_increment, +`maxnumrep` int(10) unsigned NOT NULL default '0', +PRIMARY KEY (`numeropost`), +UNIQUE KEY `maxnumrep` (`maxnumrep`) +) ENGINE=MyISAM ROW_FORMAT=FIXED; +INSERT INTO t1 (numeropost,maxnumrep) VALUES (1,0),(2,1); +select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1); +ERROR 21000: Subquery returns more than 1 row +select numeropost as a FROM t1 ORDER BY (SELECT 1 FROM t1 HAVING a=1); +ERROR 21000: Subquery returns more than 1 row +show warnings; +Level Code Message +Error 1242 Subquery returns more than 1 row +Error 1028 Sort aborted: Subquery returns more than 1 row +drop table t1; +create table t1 (a int); +insert into t1 values (1),(2),(3); +(select * from t1) union (select * from t1) order by (select a from t1 limit 1); +a +1 +2 +3 +drop table t1; +CREATE TABLE t1 (field char(1) NOT NULL DEFAULT 'b'); +INSERT INTO t1 VALUES (); +SELECT field FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1 FROM (SELECT 1) a HAVING field='b'); +ERROR 21000: Subquery returns more than 1 row +drop table t1; +CREATE TABLE `t1` ( +`numeropost` mediumint(8) unsigned NOT NULL default '0', +`numreponse` int(10) unsigned NOT NULL auto_increment, +`pseudo` varchar(35) NOT NULL default '', +PRIMARY KEY (`numeropost`,`numreponse`), +UNIQUE KEY `numreponse` (`numreponse`), +KEY `pseudo` (`pseudo`,`numeropost`) +) ENGINE=MyISAM; +SELECT (SELECT numeropost FROM t1 HAVING numreponse=a),numreponse FROM (SELECT * FROM t1) as a; +ERROR 42S22: Reference 'numreponse' not supported (forward reference in item list) +SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=a) FROM (SELECT * FROM t1) as a; +ERROR 42S22: Unknown column 'a' in 'having clause' +SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT * FROM t1) as a; +numreponse (SELECT numeropost FROM t1 HAVING numreponse=1) +INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test'); +EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); +ERROR 21000: Subquery returns more than 1 row +SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); +ERROR 21000: Subquery returns more than 1 row +EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +Warnings: +Note 1003 select max(`test`.`t1`.`numreponse`) AS `MAX(numreponse)` from `test`.`t1` where (`test`.`t1`.`numeropost` = '1') +EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 100.00 Using index +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +Warnings: +Note 1003 select 3 AS `numreponse` from `test`.`t1` where (1 = '1') +drop table t1; +CREATE TABLE t1 (a int(1)); +INSERT INTO t1 VALUES (1); +SELECT 1 FROM (SELECT a FROM t1) b HAVING (SELECT b.a)=1; +1 +1 +drop table t1; +create table t1 (a int NOT NULL, b int, primary key (a)); +create table t2 (a int NOT NULL, b int, primary key (a)); +insert into t1 values (0, 10),(1, 11),(2, 12); +insert into t2 values (1, 21),(2, 22),(3, 23); +select * from t1; +a b +0 10 +1 11 +2 12 +update t1 set b= (select b from t1); +ERROR HY000: You can't specify target table 't1' for update in FROM clause +update t1 set b= (select b from t2); +ERROR 21000: Subquery returns more than 1 row +update t1 set b= (select b from t2 where t1.a = t2.a); +select * from t1; +a b +0 NULL +1 21 +2 22 +drop table t1, t2; +create table t1 (a int NOT NULL, b int, primary key (a)); +create table t2 (a int NOT NULL, b int, primary key (a)); +insert into t1 values (0, 10),(1, 11),(2, 12); +insert into t2 values (1, 21),(2, 12),(3, 23); +select * from t1; +a b +0 10 +1 11 +2 12 +select * from t1 where b = (select b from t2 where t1.a = t2.a); +a b +2 12 +delete from t1 where b in (select b from t1); +ERROR HY000: You can't specify target table 't1' for update in FROM clause +delete from t1 where b = (select b from t2); +ERROR 21000: Subquery returns more than 1 row +delete from t1 where b = (select b from t2 where t1.a = t2.a); +select * from t1; +a b +0 10 +1 11 +drop table t1, t2; +create table t11 (a int NOT NULL, b int, primary key (a)); +create table t12 (a int NOT NULL, b int, primary key (a)); +create table t2 (a int NOT NULL, b int, primary key (a)); +insert into t11 values (0, 10),(1, 11),(2, 12); +insert into t12 values (33, 10),(22, 11),(2, 12); +insert into t2 values (1, 21),(2, 12),(3, 23); +select * from t11; +a b +0 10 +1 11 +2 12 +select * from t12; +a b +33 10 +22 11 +2 12 +delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a); +ERROR HY000: You can't specify target table 't12' for update in FROM clause +delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2); +ERROR 21000: Subquery returns more than 1 row +delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a); +select * from t11; +a b +0 10 +1 11 +select * from t12; +a b +33 10 +22 11 +drop table t11, t12, t2; +CREATE TABLE t1 (x int) ENGINE=MyISAM; +create table t2 (a int) ENGINE=MyISAM; +create table t3 (b int); +insert into t2 values (1); +insert into t3 values (1),(2); +INSERT INTO t1 (x) VALUES ((SELECT x FROM t1)); +ERROR HY000: You can't specify target table 't1' for update in FROM clause +INSERT INTO t1 (x) VALUES ((SELECT b FROM t3)); +ERROR 21000: Subquery returns more than 1 row +INSERT INTO t1 (x) VALUES ((SELECT a FROM t2)); +select * from t1; +x +1 +insert into t2 values (1); +INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2)); +select * from t1; +x +1 +2 +INSERT INTO t1 (x) select (SELECT SUM(a)+1 FROM t2) FROM t2; +select * from t1; +x +1 +2 +3 +3 +INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2; +select * from t1; +x +1 +2 +3 +3 +11 +11 +INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2)); +ERROR 42S22: Unknown column 'x' in 'field list' +INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2)); +select * from t1; +x +1 +2 +3 +3 +11 +11 +2 +drop table t1, t2, t3; +CREATE TABLE t1 (x int not null, y int, primary key (x)) ENGINE=MyISAM; +create table t2 (a int); +create table t3 (a int); +insert into t2 values (1); +insert into t3 values (1),(2); +select * from t1; +x y +replace into t1 (x, y) VALUES ((SELECT x FROM t1), (SELECT a+1 FROM t2)); +ERROR HY000: You can't specify target table 't1' for update in FROM clause +replace into t1 (x, y) VALUES ((SELECT a FROM t3), (SELECT a+1 FROM t2)); +ERROR 21000: Subquery returns more than 1 row +replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+1 FROM t2)); +select * from t1; +x y +1 2 +replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+2 FROM t2)); +select * from t1; +x y +1 3 +replace DELAYED into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a FROM t2)); +select * from t1; +x y +1 3 +4 1 +replace DELAYED into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a+1 FROM t2)); +select * from t1; +x y +1 3 +4 2 +replace LOW_PRIORITY into t1 (x, y) VALUES ((SELECT a+1 FROM t2), (SELECT a FROM t2)); +select * from t1; +x y +1 3 +4 2 +2 1 +drop table t1, t2, t3; +SELECT * FROM (SELECT 1) b WHERE 1 IN (SELECT *); +ERROR HY000: No tables used +CREATE TABLE t2 (id int(11) default NULL, KEY id (id)) ENGINE=MyISAM CHARSET=latin1; +INSERT INTO t2 VALUES (1),(2); +SELECT * FROM t2 WHERE id IN (SELECT 1); +id +1 +EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ref id id 5 const 1 100.00 Using index +Warnings: +Note 1249 Select 2 was reduced during optimization +Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = 1) +SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3); +id +1 +SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1)); +id +2 +EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1)); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t2 ref id id 5 const 1 100.00 Using where; Using index +Warnings: +Note 1249 Select 3 was reduced during optimization +Note 1249 Select 2 was reduced during optimization +Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = <cache>((1 + 1))) +EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 index NULL id 5 NULL 2 100.00 Using where; Using index +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where <expr_cache><`test`.`t2`.`id`>(<in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1)) union select 3 having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3))))) +SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 3); +id +SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 2); +id +2 +INSERT INTO t2 VALUES ((SELECT * FROM t2)); +ERROR HY000: You can't specify target table 't2' for update in FROM clause +INSERT INTO t2 VALUES ((SELECT id FROM t2)); +ERROR HY000: You can't specify target table 't2' for update in FROM clause +SELECT * FROM t2; +id +1 +2 +CREATE TABLE t1 (id int(11) default NULL, KEY id (id)) ENGINE=MyISAM CHARSET=latin1; +INSERT INTO t1 values (1),(1); +UPDATE t2 SET id=(SELECT * FROM t1); +ERROR 21000: Subquery returns more than 1 row +drop table t2, t1; +create table t1 (a int); +insert into t1 values (1),(2),(3); +select 1 IN (SELECT * from t1); +1 IN (SELECT * from t1) +1 +select 10 IN (SELECT * from t1); +10 IN (SELECT * from t1) +0 +select NULL IN (SELECT * from t1); +NULL IN (SELECT * from t1) +NULL +update t1 set a=NULL where a=2; +select 1 IN (SELECT * from t1); +1 IN (SELECT * from t1) +1 +select 3 IN (SELECT * from t1); +3 IN (SELECT * from t1) +1 +select 10 IN (SELECT * from t1); +10 IN (SELECT * from t1) +NULL +select 1 > ALL (SELECT * from t1); +1 > ALL (SELECT * from t1) +0 +select 10 > ALL (SELECT * from t1); +10 > ALL (SELECT * from t1) +NULL +select 1 > ANY (SELECT * from t1); +1 > ANY (SELECT * from t1) +NULL +select 10 > ANY (SELECT * from t1); +10 > ANY (SELECT * from t1) +1 +drop table t1; +create table t1 (a varchar(20)); +insert into t1 values ('A'),('BC'),('DEF'); +select 'A' IN (SELECT * from t1); +'A' IN (SELECT * from t1) +1 +select 'XYZS' IN (SELECT * from t1); +'XYZS' IN (SELECT * from t1) +0 +select NULL IN (SELECT * from t1); +NULL IN (SELECT * from t1) +NULL +update t1 set a=NULL where a='BC'; +select 'A' IN (SELECT * from t1); +'A' IN (SELECT * from t1) +1 +select 'DEF' IN (SELECT * from t1); +'DEF' IN (SELECT * from t1) +1 +select 'XYZS' IN (SELECT * from t1); +'XYZS' IN (SELECT * from t1) +NULL +select 'A' > ALL (SELECT * from t1); +'A' > ALL (SELECT * from t1) +0 +select 'XYZS' > ALL (SELECT * from t1); +'XYZS' > ALL (SELECT * from t1) +NULL +select 'A' > ANY (SELECT * from t1); +'A' > ANY (SELECT * from t1) +NULL +select 'XYZS' > ANY (SELECT * from t1); +'XYZS' > ANY (SELECT * from t1) +1 +drop table t1; +create table t1 (a float); +insert into t1 values (1.5),(2.5),(3.5); +select 1.5 IN (SELECT * from t1); +1.5 IN (SELECT * from t1) +1 +select 10.5 IN (SELECT * from t1); +10.5 IN (SELECT * from t1) +0 +select NULL IN (SELECT * from t1); +NULL IN (SELECT * from t1) +NULL +update t1 set a=NULL where a=2.5; +select 1.5 IN (SELECT * from t1); +1.5 IN (SELECT * from t1) +1 +select 3.5 IN (SELECT * from t1); +3.5 IN (SELECT * from t1) +1 +select 10.5 IN (SELECT * from t1); +10.5 IN (SELECT * from t1) +NULL +select 1.5 > ALL (SELECT * from t1); +1.5 > ALL (SELECT * from t1) +0 +select 10.5 > ALL (SELECT * from t1); +10.5 > ALL (SELECT * from t1) +NULL +select 1.5 > ANY (SELECT * from t1); +1.5 > ANY (SELECT * from t1) +NULL +select 10.5 > ANY (SELECT * from t1); +10.5 > ANY (SELECT * from t1) +1 +explain extended select (select a+1) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1249 Select 2 was reduced during optimization +Note 1003 select (`test`.`t1`.`a` + 1) AS `(select a+1)` from `test`.`t1` +select (select a+1) from t1; +(select a+1) +2.5 +NULL +4.5 +drop table t1; +CREATE TABLE t1 (a int(11) NOT NULL default '0', PRIMARY KEY (a)); +CREATE TABLE t2 (a int(11) default '0', INDEX (a)); +INSERT INTO t1 VALUES (1),(2),(3),(4); +INSERT INTO t2 VALUES (1),(2),(3); +SELECT t1.a, t1.a in (select t2.a from t2) FROM t1; +a t1.a in (select t2.a from t2) +1 1 +2 1 +3 1 +4 0 +explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index +2 SUBQUERY t2 index_subquery a a 5 func 2 100.00 Using index +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in t2 on a checking NULL having <is_not_null_test>(`test`.`t2`.`a`))))) AS `t1.a in (select t2.a from t2)` from `test`.`t1` +CREATE TABLE t3 (a int(11) default '0'); +INSERT INTO t3 VALUES (1),(2),(3); +SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1; +a t1.a in (select t2.a from t2,t3 where t3.a=t2.a) +1 1 +2 1 +3 1 +4 0 +explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index +2 DEPENDENT SUBQUERY t2 ref_or_null a a 5 func 2 100.00 Using where; Using index +2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`)))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1` +drop table t1,t2,t3; +# check correct NULL Processing for normal IN/ALL/ANY +# and 2 ways of max/min optimization +create table t1 (a int); +insert into t1 values (1), (100), (NULL), (1000); +create table t2 (a int not null); +# subselect returns empty set (for NULL and non-NULL left part) +select a, a in (select * from t2) from t1; +a a in (select * from t2) +1 0 +100 0 +NULL 0 +1000 0 +select a, a > any (select * from t2) from t1; +a a > any (select * from t2) +1 0 +100 0 +NULL 0 +1000 0 +select a, a > all (select * from t2) from t1; +a a > all (select * from t2) +1 1 +100 1 +NULL 1 +1000 1 +select a from t1 where a in (select * from t2); +a +select a from t1 where a > any (select * from t2); +a +select a from t1 where a > all (select * from t2); +a +1 +100 +NULL +1000 +select a from t1 where a in (select * from t2 group by a); +a +select a from t1 where a > any (select * from t2 group by a); +a +select a from t1 where a > all (select * from t2 group by a); +a +1 +100 +NULL +1000 +insert into t2 values (1),(200); +# sebselect returns non-empty set without NULLs +select a, a in (select * from t2) from t1; +a a in (select * from t2) +1 1 +100 0 +NULL NULL +1000 0 +select a, a > any (select * from t2) from t1; +a a > any (select * from t2) +1 0 +100 1 +NULL NULL +1000 1 +select a, a > all (select * from t2) from t1; +a a > all (select * from t2) +1 0 +100 0 +NULL NULL +1000 1 +select a from t1 where a in (select * from t2); +a +1 +select a from t1 where a > any (select * from t2); +a +100 +1000 +select a from t1 where a > all (select * from t2); +a +1000 +select a from t1 where a in (select * from t2 group by a); +a +1 +select a from t1 where a > any (select * from t2 group by a); +a +100 +1000 +select a from t1 where a > all (select * from t2 group by a); +a +1000 +drop table t2; +create table t2 (a int); +insert into t2 values (1),(NULL),(200); +# sebselect returns non-empty set with NULLs +select a, a in (select * from t2) from t1; +a a in (select * from t2) +1 1 +100 NULL +NULL NULL +1000 NULL +select a, a > any (select * from t2) from t1; +a a > any (select * from t2) +1 NULL +100 1 +NULL NULL +1000 1 +select a, a > all (select * from t2) from t1; +a a > all (select * from t2) +1 0 +100 0 +NULL NULL +1000 NULL +select a from t1 where a in (select * from t2); +a +1 +select a from t1 where a > any (select * from t2); +a +100 +1000 +select a from t1 where a > all (select * from t2); +a +select a from t1 where a in (select * from t2 group by a); +a +1 +select a from t1 where a > any (select * from t2 group by a); +a +100 +1000 +select a from t1 where a > all (select * from t2 group by a); +a +drop table t1, t2; +create table t1 (a float); +select 10.5 IN (SELECT * from t1 LIMIT 1); +ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' +select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5); +ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' +drop table t1; +create table t1 (a int, b int, c varchar(10)); +create table t2 (a int); +insert into t1 values (1,2,'a'),(2,3,'b'),(3,4,'c'); +insert into t2 values (1),(2),(NULL); +select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a'),(select c from t1 where a=t2.a) from t2; +a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a') (select c from t1 where a=t2.a) +1 1 a +2 0 b +NULL NULL NULL +select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b'),(select c from t1 where a=t2.a) from t2; +a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b') (select c from t1 where a=t2.a) +1 0 a +2 1 b +NULL NULL NULL +select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,4,'c'),(select c from t1 where a=t2.a) from t2; +a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,4,'c') (select c from t1 where a=t2.a) +1 0 a +2 0 b +NULL NULL NULL +drop table t1,t2; +create table t1 (a int, b real, c varchar(10)); +insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b'); +select ROW(1, 1, 'a') IN (select a,b,c from t1); +ROW(1, 1, 'a') IN (select a,b,c from t1) +1 +select ROW(1, 2, 'a') IN (select a,b,c from t1); +ROW(1, 2, 'a') IN (select a,b,c from t1) +0 +select ROW(1, 1, 'a') IN (select b,a,c from t1); +ROW(1, 1, 'a') IN (select b,a,c from t1) +1 +select ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null); +ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null) +1 +select ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null); +ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null) +0 +select ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null); +ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null) +1 +select ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a'); +ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a') +1 +select ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a'); +ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a') +0 +select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a'); +ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a') +1 +select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2); +ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' +drop table t1; +create table t1 (a int); +insert into t1 values (1); +do @a:=(SELECT a from t1); +select @a; +@a +1 +set @a:=2; +set @a:=(SELECT a from t1); +select @a; +@a +1 +drop table t1; +do (SELECT a from t1); +ERROR 42S02: Table 'test.t1' doesn't exist +set @a:=(SELECT a from t1); +ERROR 42S02: Table 'test.t1' doesn't exist +CREATE TABLE t1 (a int, KEY(a)); +HANDLER t1 OPEN; +HANDLER t1 READ a=((SELECT 1)); +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 1))' at line 1 +HANDLER t1 CLOSE; +drop table t1; +create table t1 (a int); +create table t2 (b int); +insert into t1 values (1),(2); +insert into t2 values (1); +select a from t1 where a in (select a from t1 where a in (select b from t2)); +a +1 +drop table t1, t2; +create table t1 (a int, b int); +create table t2 like t1; +insert into t1 values (1,2),(1,3),(1,4),(1,5); +insert into t2 values (1,2),(1,3); +select * from t1 where row(a,b) in (select a,b from t2); +a b +1 2 +1 3 +drop table t1, t2; +CREATE TABLE `t1` (`i` int(11) NOT NULL default '0',PRIMARY KEY (`i`)) ENGINE=MyISAM CHARSET=latin1; +INSERT INTO t1 VALUES (1); +UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i)); +select * from t1; +i +2 +drop table t1; +CREATE TABLE t1 (a int(1)); +EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 system NULL NULL NULL NULL 0 0.00 const row not found +2 UNCACHEABLE SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 const row not found +Warnings: +Note 1003 select (select rand() from `test`.`t1`) AS `(SELECT RAND() FROM t1)` from `test`.`t1` +EXPLAIN EXTENDED SELECT (SELECT ENCRYPT('test') FROM t1) FROM t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 system NULL NULL NULL NULL 0 0.00 const row not found +2 UNCACHEABLE SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 const row not found +Warnings: +Note 1003 select (select encrypt('test') from `test`.`t1`) AS `(SELECT ENCRYPT('test') FROM t1)` from `test`.`t1` +EXPLAIN EXTENDED SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 system NULL NULL NULL NULL 0 0.00 const row not found +2 UNCACHEABLE SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 const row not found +Warnings: +Note 1003 select (select benchmark(1,1) from `test`.`t1`) AS `(SELECT BENCHMARK(1,1) FROM t1)` from `test`.`t1` +drop table t1; +CREATE TABLE `t1` ( +`mot` varchar(30) character set latin1 NOT NULL default '', +`topic` mediumint(8) unsigned NOT NULL default '0', +`date` date NOT NULL default '0000-00-00', +`pseudo` varchar(35) character set latin1 NOT NULL default '', +PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`), +KEY `pseudo` (`pseudo`,`date`,`topic`), +KEY `topic` (`topic`) +) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC; +CREATE TABLE `t2` ( +`mot` varchar(30) character set latin1 NOT NULL default '', +`topic` mediumint(8) unsigned NOT NULL default '0', +`date` date NOT NULL default '0000-00-00', +`pseudo` varchar(35) character set latin1 NOT NULL default '', +PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`), +KEY `pseudo` (`pseudo`,`date`,`topic`), +KEY `topic` (`topic`) +) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC; +CREATE TABLE `t3` ( +`numeropost` mediumint(8) unsigned NOT NULL auto_increment, +`maxnumrep` int(10) unsigned NOT NULL default '0', +PRIMARY KEY (`numeropost`), +UNIQUE KEY `maxnumrep` (`maxnumrep`) +) ENGINE=MyISAM CHARSET=latin1; +INSERT INTO t1 VALUES ('joce','1','','joce'),('test','2','','test'); +Warnings: +Warning 1265 Data truncated for column 'date' at row 1 +Warning 1265 Data truncated for column 'date' at row 2 +INSERT INTO t2 VALUES ('joce','1','','joce'),('test','2','','test'); +Warnings: +Warning 1265 Data truncated for column 'date' at row 1 +Warning 1265 Data truncated for column 'date' at row 2 +INSERT INTO t3 VALUES (1,1); +SELECT DISTINCT topic FROM t2 WHERE NOT EXISTS(SELECT * FROM t3 WHERE +numeropost=topic); +topic +2 +select * from t1; +mot topic date pseudo +joce 1 0000-00-00 joce +test 2 0000-00-00 test +DELETE FROM t1 WHERE topic IN (SELECT DISTINCT topic FROM t2 WHERE NOT +EXISTS(SELECT * FROM t3 WHERE numeropost=topic)); +select * from t1; +mot topic date pseudo +joce 1 0000-00-00 joce +drop table t1, t2, t3; +SELECT * FROM (SELECT 1 as a,(SELECT a)) a; +a (SELECT a) +1 1 +CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT 1)) a; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(1) NOT NULL DEFAULT '0', + `(SELECT 1)` int(1) NOT NULL DEFAULT '0' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a)) a; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(1) NOT NULL DEFAULT '0', + `(SELECT a)` int(1) NOT NULL DEFAULT '0' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(1) NOT NULL DEFAULT '0', + `(SELECT a+0)` int(3) NOT NULL DEFAULT '0' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +CREATE TABLE t1 SELECT (SELECT 1 as a UNION SELECT 1+1 limit 1,1) as a; +select * from t1; +a +2 +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` bigint(20) NOT NULL DEFAULT '0' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +create table t1 (a int); +insert into t1 values (1), (2), (3); +explain extended select a,(select (select rand() from t1 limit 1) from t1 limit 1) +from t1; +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 UNCACHEABLE SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 +3 UNCACHEABLE SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a`,(select (select rand() from `test`.`t1` limit 1) from `test`.`t1` limit 1) AS `(select (select rand() from t1 limit 1) from t1 limit 1)` from `test`.`t1` +drop table t1; +select t1.Continent, t2.Name, t2.Population from t1 LEFT JOIN t2 ON t1.Code = t2.Country where t2.Population IN (select max(t2.Population) AS Population from t2, t1 where t2.Country = t1.Code group by Continent); +ERROR 42S02: Table 'test.t1' doesn't exist +CREATE TABLE t1 ( +ID int(11) NOT NULL auto_increment, +name char(35) NOT NULL default '', +t2 char(3) NOT NULL default '', +District char(20) NOT NULL default '', +Population int(11) NOT NULL default '0', +PRIMARY KEY (ID) +) ENGINE=MyISAM; +INSERT INTO t1 VALUES (130,'Sydney','AUS','New South Wales',3276207); +INSERT INTO t1 VALUES (131,'Melbourne','AUS','Victoria',2865329); +INSERT INTO t1 VALUES (132,'Brisbane','AUS','Queensland',1291117); +CREATE TABLE t2 ( +Code char(3) NOT NULL default '', +Name char(52) NOT NULL default '', +Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia', +Region char(26) NOT NULL default '', +SurfaceArea float(10,2) NOT NULL default '0.00', +IndepYear smallint(6) default NULL, +Population int(11) NOT NULL default '0', +LifeExpectancy float(3,1) default NULL, +GNP float(10,2) default NULL, +GNPOld float(10,2) default NULL, +LocalName char(45) NOT NULL default '', +GovernmentForm char(45) NOT NULL default '', +HeadOfState char(60) default NULL, +Capital int(11) default NULL, +Code2 char(2) NOT NULL default '', +PRIMARY KEY (Code) +) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('AUS','Australia','Oceania','Australia and New Zealand',7741220.00,1901,18886000,79.8,351182.00,392911.00,'Australia','Constitutional Monarchy, Federation','Elisabeth II',135,'AU'); +INSERT INTO t2 VALUES ('AZE','Azerbaijan','Asia','Middle East',86600.00,1991,7734000,62.9,4127.00,4100.00,'Azärbaycan','Federal Republic','Heydär Äliyev',144,'AZ'); +select t2.Continent, t1.Name, t1.Population from t2 LEFT JOIN t1 ON t2.Code = t1.t2 where t1.Population IN (select max(t1.Population) AS Population from t1, t2 where t1.t2 = t2.Code group by Continent); +Continent Name Population +Oceania Sydney 3276207 +drop table t1, t2; +CREATE TABLE `t1` ( +`id` mediumint(8) unsigned NOT NULL auto_increment, +`pseudo` varchar(35) character set latin1 NOT NULL default '', +PRIMARY KEY (`id`), +UNIQUE KEY `pseudo` (`pseudo`) +) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC; +INSERT INTO t1 (pseudo) VALUES ('test'); +SELECT 0 IN (SELECT 1 FROM t1 a); +0 IN (SELECT 1 FROM t1 a) +0 +EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select <in_optimizer>(0,<exists>(select 1 from dual where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)` +INSERT INTO t1 (pseudo) VALUES ('test1'); +SELECT 0 IN (SELECT 1 FROM t1 a); +0 IN (SELECT 1 FROM t1 a) +0 +EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select <in_optimizer>(0,<exists>(select 1 from `test`.`t1` `a` where (0 = 1))) AS `0 IN (SELECT 1 FROM t1 a)` +drop table t1; +CREATE TABLE `t1` ( +`i` int(11) NOT NULL default '0', +PRIMARY KEY (`i`) +) ENGINE=MyISAM CHARSET=latin1; +INSERT INTO t1 VALUES (1); +UPDATE t1 SET i=i+(SELECT MAX(i) FROM (SELECT 1) t) WHERE i=(SELECT MAX(i)); +UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i)); +UPDATE t1 SET t.i=i+(SELECT MAX(i) FROM (SELECT 1) t); +ERROR 42S22: Unknown column 't.i' in 'field list' +select * from t1; +i +3 +drop table t1; +CREATE TABLE t1 ( +id int(11) default NULL +) ENGINE=MyISAM CHARSET=latin1; +INSERT INTO t1 VALUES (1),(1),(2),(2),(1),(3); +CREATE TABLE t2 ( +id int(11) default NULL, +name varchar(15) default NULL +) ENGINE=MyISAM CHARSET=latin1; +INSERT INTO t2 VALUES (4,'vita'), (1,'vita'), (2,'vita'), (1,'vita'); +update t1, t2 set t2.name='lenka' where t2.id in (select id from t1); +select * from t2; +id name +4 vita +1 lenka +2 lenka +1 lenka +drop table t1,t2; +create table t1 (a int, unique index indexa (a)); +insert into t1 values (-1), (-4), (-2), (NULL); +select -10 IN (select a from t1 FORCE INDEX (indexa)); +-10 IN (select a from t1 FORCE INDEX (indexa)) +NULL +drop table t1; +create table t1 (id int not null auto_increment primary key, salary int, key(salary)); +insert into t1 (salary) values (100),(1000),(10000),(10),(500),(5000),(50000); +explain extended SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ref salary salary 5 const 1 100.00 Using where +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +Warnings: +Note 1003 select `test`.`t1`.`id` AS `id` from `test`.`t1` where (`test`.`t1`.`salary` = (select max(`test`.`t1`.`salary`) from `test`.`t1`)) +drop table t1; +CREATE TABLE t1 ( +ID int(10) unsigned NOT NULL auto_increment, +SUB_ID int(3) unsigned NOT NULL default '0', +REF_ID int(10) unsigned default NULL, +REF_SUB int(3) unsigned default '0', +PRIMARY KEY (ID,SUB_ID), +UNIQUE KEY t1_PK (ID,SUB_ID), +KEY t1_FK (REF_ID,REF_SUB), +KEY t1_REFID (REF_ID) +) ENGINE=MyISAM CHARSET=cp1251; +INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL); +SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2); +REF_ID +DROP TABLE t1; +create table t1 (a int, b int); +create table t2 (a int, b int); +insert into t1 values (1,0), (2,0), (3,0); +insert into t2 values (1,1), (2,1), (3,1), (2,2); +update ignore t1 set b=(select b from t2 where t1.a=t2.a); +Warnings: +Warning 1242 Subquery returns more than 1 row +select * from t1; +a b +1 1 +2 NULL +3 1 +drop table t1, t2; +CREATE TABLE `t1` ( +`id` mediumint(8) unsigned NOT NULL auto_increment, +`pseudo` varchar(35) NOT NULL default '', +`email` varchar(60) NOT NULL default '', +PRIMARY KEY (`id`), +UNIQUE KEY `email` (`email`), +UNIQUE KEY `pseudo` (`pseudo`) +) ENGINE=MyISAM CHARSET=latin1 PACK_KEYS=1 ROW_FORMAT=DYNAMIC; +INSERT INTO t1 (id,pseudo,email) VALUES (1,'test','test'),(2,'test1','test1'); +SELECT pseudo as a, pseudo as b FROM t1 GROUP BY (SELECT a) ORDER BY (SELECT id*1); +a b +test test +test1 test1 +drop table if exists t1; +(SELECT 1 as a) UNION (SELECT 1) ORDER BY (SELECT a+0); +a +1 +create table t1 (a int not null, b int, primary key (a)); +create table t2 (a int not null, primary key (a)); +create table t3 (a int not null, b int, primary key (a)); +insert into t1 values (1,10), (2,20), (3,30), (4,40); +insert into t2 values (2), (3), (4), (5); +insert into t3 values (10,3), (20,4), (30,5); +select * from t2 where t2.a in (select a from t1); +a +2 +3 +4 +explain extended select * from t2 where t2.a in (select a from t1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index +1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 4 75.00 Using where; Using index; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`) +select * from t2 where t2.a in (select a from t1 where t1.b <> 30); +a +2 +4 +explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 75.00 Using where; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30)) +select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); +a +2 +3 +explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 75.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where ((`test`.`t3`.`a` = `test`.`t1`.`b`) and (`test`.`t1`.`a` = `test`.`t2`.`a`)) +drop table t1, t2, t3; +create table t1 (a int, b int, index a (a,b)); +create table t2 (a int, index a (a)); +create table t3 (a int, b int, index a (a)); +insert into t1 values (1,10), (2,20), (3,30), (4,40); +create table t0(a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +insert into t1 +select rand()*100000+200,rand()*100000 from t0 A, t0 B, t0 C, t0 D; +insert into t2 values (2), (3), (4), (5); +insert into t3 values (10,3), (20,4), (30,5); +select * from t2 where t2.a in (select a from t1); +a +2 +3 +4 +explain extended select * from t2 where t2.a in (select a from t1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index +1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using index; FirstMatch(t2) +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where (`test`.`t1`.`a` = `test`.`t2`.`a`) +select * from t2 where t2.a in (select a from t1 where t1.b <> 30); +a +2 +4 +explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index +1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using where; Using index; FirstMatch(t2) +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30)) +select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); +a +2 +3 +explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index +1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index +1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2) +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where ((`test`.`t1`.`b` = `test`.`t3`.`a`) and (`test`.`t1`.`a` = `test`.`t2`.`a`)) +insert into t1 values (3,31); +select * from t2 where t2.a in (select a from t1 where t1.b <> 30); +a +2 +3 +4 +select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31); +a +2 +4 +explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index +1 PRIMARY t1 ref a a 5 test.t2.a 101 100.00 Using where; Using index; FirstMatch(t2) +Warnings: +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30)) +drop table t0, t1, t2, t3; +create table t1 (a int, b int); +create table t2 (a int, b int); +create table t3 (a int, b int); +insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10); +insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1); +insert into t3 values (3,3), (2,2), (1,1); +select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) from t3; +a (select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) +3 1 +2 2 +1 2 +drop table t1,t2,t3; +create table t1 (s1 int); +create table t2 (s1 int); +insert into t1 values (1); +insert into t2 values (1); +select * from t1 where exists (select s1 from t2 having max(t2.s1)=t1.s1); +s1 +1 +drop table t1,t2; +create table t1 (s1 int); +create table t2 (s1 int); +insert into t1 values (1); +insert into t2 values (1); +update t1 set s1 = s1 + 1 where 1 = (select x.s1 as A from t2 WHERE t2.s1 > t1.s1 order by A); +ERROR 42S22: Unknown column 'x.s1' in 'field list' +DROP TABLE t1, t2; +CREATE TABLE t1 (s1 CHAR(5) COLLATE latin1_german1_ci, +s2 CHAR(5) COLLATE latin1_swedish_ci); +INSERT INTO t1 VALUES ('z','?'); +select * from t1 where s1 > (select max(s2) from t1); +ERROR HY000: Illegal mix of collations (latin1_german1_ci,IMPLICIT) and (latin1_swedish_ci,IMPLICIT) for operation '>' +select * from t1 where s1 > any (select max(s2) from t1); +ERROR HY000: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (latin1_german1_ci,IMPLICIT) for operation '<' +drop table t1; +create table t1(toid int,rd int); +create table t2(userid int,pmnew int,pmtotal int); +insert into t2 values(1,0,0),(2,0,0); +insert into t1 values(1,0),(1,0),(1,0),(1,12),(1,15),(1,123),(1,12312),(1,12312),(1,123),(2,0),(2,0),(2,1),(2,2); +select userid,pmtotal,pmnew, (select count(rd) from t1 where toid=t2.userid) calc_total, (select count(rd) from t1 where rd=0 and toid=t2.userid) calc_new from t2 where userid in (select distinct toid from t1); +userid pmtotal pmnew calc_total calc_new +1 0 0 9 3 +2 0 0 4 2 +drop table t1, t2; +create table t1 (s1 char(5)); +select (select 'a','b' from t1 union select 'a','b' from t1) from t1; +ERROR 21000: Operand should contain 1 column(s) +insert into t1 values ('tttt'); +select * from t1 where ('a','b')=(select 'a','b' from t1 union select 'a','b' from t1); +s1 +tttt +explain extended (select * from t1); +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 'tttt' AS `s1` from dual) +(select * from t1); +s1 +tttt +drop table t1; +create table t1 (s1 char(5), index s1(s1)); +create table t2 (s1 char(5), index s1(s1)); +insert into t1 values ('a1'),('a2'),('a3'); +insert into t2 values ('a1'),('a2'); +select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; +s1 s1 NOT IN (SELECT s1 FROM t2) +a1 0 +a2 0 +a3 1 +select s1, s1 = ANY (SELECT s1 FROM t2) from t1; +s1 s1 = ANY (SELECT s1 FROM t2) +a1 1 +a2 1 +a3 0 +select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; +s1 s1 <> ALL (SELECT s1 FROM t2) +a1 0 +a2 0 +a3 1 +select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; +s1 s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') +a1 0 +a2 1 +a3 1 +explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +Warnings: +Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` +explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +Warnings: +Note 1003 select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` +explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +Warnings: +Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` +explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index +2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key +Warnings: +Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < 'a2') having trigcond(<is_not_null_test>(`test`.`t2`.`s1`)))))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1` +drop table t1,t2; +create table t2 (a int, b int not null); +create table t3 (a int); +insert into t3 values (6),(7),(3); +select * from t3 where a >= all (select b from t2); +a +6 +7 +3 +explain extended select * from t3 where a >= all (select b from t2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 Using where +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +Warnings: +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>(<in_optimizer>(`test`.`t3`.`a`,((select max(NULL) from `test`.`t2`) > <cache>(`test`.`t3`.`a`)))) +select * from t3 where a >= some (select b from t2); +a +explain extended select * from t3 where a >= some (select b from t2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 Using where +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +Warnings: +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(`test`.`t3`.`a`,((select min(NULL) from `test`.`t2`) <= <cache>(`test`.`t3`.`a`)))) +select * from t3 where a >= all (select b from t2 group by 1); +a +6 +7 +3 +explain extended select * from t3 where a >= all (select b from t2 group by 1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 Using where +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +Warnings: +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>(<in_optimizer>(`test`.`t3`.`a`,((select max(NULL) from `test`.`t2`) > <cache>(`test`.`t3`.`a`)))) +select * from t3 where a >= some (select b from t2 group by 1); +a +explain extended select * from t3 where a >= some (select b from t2 group by 1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 Using where +2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found +Warnings: +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>(<in_optimizer>(`test`.`t3`.`a`,((select min(NULL) from `test`.`t2`) <= <cache>(`test`.`t3`.`a`)))) +select * from t3 where NULL >= any (select b from t2); +a +explain extended select * from t3 where NULL >= any (select b 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 NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table +Warnings: +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 +select * from t3 where NULL >= any (select b from t2 group by 1); +a +explain extended select * from t3 where NULL >= any (select b from t2 group by 1); +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 NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table +Warnings: +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 +select * from t3 where NULL >= some (select b from t2); +a +explain extended select * from t3 where NULL >= some (select b 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 NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table +Warnings: +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 +select * from t3 where NULL >= some (select b from t2 group by 1); +a +explain extended select * from t3 where NULL >= some (select b from t2 group by 1); +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 NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table +Warnings: +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0 +insert into t2 values (2,2), (2,1), (3,3), (3,1); +select * from t3 where a > all (select max(b) from t2 group by a); +a +6 +7 +explain extended select * from t3 where a > all (select max(b) from t2 group by a); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 Using where +2 SUBQUERY t2 ALL NULL NULL NULL NULL 4 100.00 Using temporary +Warnings: +Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>(<in_optimizer>(`test`.`t3`.`a`,(<max>(select max(`test`.`t2`.`b`) from `test`.`t2` group by `test`.`t2`.`a`) >= <cache>(`test`.`t3`.`a`)))) +drop table t2, t3; +CREATE TABLE `t1` ( `id` mediumint(9) NOT NULL auto_increment, `taskid` bigint(20) NOT NULL default '0', `dbid` int(11) NOT NULL default '0', `create_date` datetime NOT NULL default '0000-00-00 00:00:00', `last_update` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=3 ; +INSERT INTO `t1` (`id`, `taskid`, `dbid`, `create_date`,`last_update`) VALUES (1, 1, 15, '2003-09-29 10:31:36', '2003-09-29 10:31:36'), (2, 1, 21, now(), now()); +CREATE TABLE `t2` (`db_id` int(11) NOT NULL auto_increment,`name` varchar(200) NOT NULL default '',`primary_uid` smallint(6) NOT NULL default '0',`secondary_uid` smallint(6) NOT NULL default '0',PRIMARY KEY (`db_id`),UNIQUE KEY `name_2` (`name`),FULLTEXT KEY `name` (`name`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2147483647; +INSERT INTO `t2` (`db_id`, `name`, `primary_uid`, `secondary_uid`) VALUES (18, 'Not Set 1', 0, 0),(19, 'Valid', 1, 2),(20, 'Valid 2', 1, 2),(21, 'Should Not Return', 1, 2),(26, 'Not Set 2', 0, 0),(-1, 'ALL DB\'S', 0, 0); +CREATE TABLE `t3` (`taskgenid` mediumint(9) NOT NULL auto_increment,`dbid` int(11) NOT NULL default '0',`taskid` int(11) NOT NULL default '0',`mon` tinyint(4) NOT NULL default '1',`tues` tinyint(4) NOT NULL default '1',`wed` tinyint(4) NOT NULL default '1',`thur` tinyint(4) NOT NULL default '1',`fri` tinyint(4) NOT NULL default '1',`sat` tinyint(4) NOT NULL default '0',`sun` tinyint(4) NOT NULL default '0',`how_often` smallint(6) NOT NULL default '1',`userid` smallint(6) NOT NULL default '0',`active` tinyint(4) NOT NULL default '1',PRIMARY KEY (`taskgenid`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2 ; +INSERT INTO `t3` (`taskgenid`, `dbid`, `taskid`, `mon`, `tues`,`wed`, `thur`, `fri`, `sat`, `sun`, `how_often`, `userid`, `active`) VALUES (1,-1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1); +CREATE TABLE `t4` (`task_id` smallint(6) NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; +INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status'); +select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid; +dbid name (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') +-1 Valid 1 +-1 Valid 2 1 +-1 Should Not Return 0 +SELECT dbid, name FROM t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND ((date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01')) AND t4.task_id = taskid; +dbid name +-1 Valid +-1 Valid 2 +drop table t1,t2,t3,t4; +CREATE TABLE t1 (id int(11) default NULL) ENGINE=MyISAM CHARSET=latin1; +INSERT INTO t1 VALUES (1),(5); +CREATE TABLE t2 (id int(11) default NULL) ENGINE=MyISAM CHARSET=latin1; +INSERT INTO t2 VALUES (2),(6); +select * from t1 where (1,2,6) in (select * from t2); +ERROR 21000: Operand should contain 3 column(s) +DROP TABLE t1,t2; +create table t1 (s1 int); +insert into t1 values (1); +insert into t1 values (2); +set sort_buffer_size = (select s1 from t1); +ERROR 21000: Subquery returns more than 1 row +do (select * from t1); +Warnings: +Error 1242 Subquery returns more than 1 row +drop table t1; +create table t1 (s1 char); +insert into t1 values ('e'); +select * from t1 where 'f' > any (select s1 from t1); +s1 +e +select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1); +s1 +e +explain extended select * from t1 where 'f' > any (select s1 from t1 union select s1 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 t1 system NULL NULL NULL NULL 1 100.00 +3 UNION t1 system NULL NULL NULL NULL 1 100.00 +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 select 'e' AS `s1` from dual where 1 +drop table t1; +CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1; +INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874'); +CREATE TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM CHARSET=latin1; +INSERT INTO t2 VALUES ('1'),('1226'),('1245'),('1862'),('18623'),('1874'),('1967'),('6'); +select c.number as phone,(select p.code from t2 p where c.number like concat(p.code, '%') order by length(p.code) desc limit 1) as code from t1 c; +phone code +69294728265 6 +18621828126 1862 +89356874041 NULL +95895001874 NULL +drop table t1, t2; +create table t1 (s1 int); +create table t2 (s1 int); +select * from t1 where (select count(*) from t2 where t1.s2) = 1; +ERROR 42S22: Unknown column 't1.s2' in 'where clause' +select * from t1 where (select count(*) from t2 group by t1.s2) = 1; +ERROR 42S22: Unknown column 't1.s2' in 'group statement' +select count(*) from t2 group by t1.s2; +ERROR 42S22: Unknown column 't1.s2' in 'group statement' +drop table t1, t2; +CREATE TABLE t1(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC VARCHAR(20) DEFAULT NULL,PRIMARY KEY (COLA, COLB)); +CREATE TABLE t2(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC CHAR(1) NOT NULL,PRIMARY KEY (COLA)); +INSERT INTO t1 VALUES (1,1,'1A3240'), (1,2,'4W2365'); +INSERT INTO t2 VALUES (100, 200, 'C'); +SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1); +COLC +DROP TABLE t1, t2; +CREATE TABLE t1 (a int(1)); +INSERT INTO t1 VALUES (1),(1),(1),(1),(1),(2),(3),(4),(5); +SELECT DISTINCT (SELECT a) FROM t1 LIMIT 100; +(SELECT a) +1 +2 +3 +4 +5 +DROP TABLE t1; +create table t1 (a int, b decimal(13, 3)); +insert into t1 values (1, 0.123); +select a, (select max(b) from t1) into outfile "../../tmp/subselect.out.file.1" from t1; +delete from t1; +load data infile "../../tmp/subselect.out.file.1" into table t1; +select * from t1; +a b +1 0.123 +drop table t1; +CREATE TABLE `t1` ( +`id` int(11) NOT NULL auto_increment, +`id_cns` tinyint(3) unsigned NOT NULL default '0', +`tipo` enum('','UNO','DUE') NOT NULL default '', +`anno_dep` smallint(4) unsigned zerofill NOT NULL default '0000', +`particolare` mediumint(8) unsigned NOT NULL default '0', +`generale` mediumint(8) unsigned NOT NULL default '0', +`bis` tinyint(3) unsigned NOT NULL default '0', +PRIMARY KEY (`id`), +UNIQUE KEY `idx_cns_gen_anno` (`anno_dep`,`id_cns`,`generale`,`particolare`), +UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`) +); +INSERT INTO `t1` VALUES (1,16,'UNO',1987,2048,9681,0),(2,50,'UNO',1987,1536,13987,0),(3,16,'UNO',1987,2432,14594,0),(4,16,'UNO',1987,1792,13422,0),(5,16,'UNO',1987,1025,10240,0),(6,16,'UNO',1987,1026,7089,0); +CREATE TABLE `t2` ( +`id` tinyint(3) unsigned NOT NULL auto_increment, +`max_anno_dep` smallint(6) unsigned NOT NULL default '0', +PRIMARY KEY (`id`) +); +INSERT INTO `t2` VALUES (16,1987),(50,1990),(51,1990); +SELECT cns.id, cns.max_anno_dep, cns.max_anno_dep = (SELECT s.anno_dep FROM t1 AS s WHERE s.id_cns = cns.id ORDER BY s.anno_dep DESC LIMIT 1) AS PIPPO FROM t2 AS cns; +id max_anno_dep PIPPO +16 1987 1 +50 1990 0 +51 1990 NULL +DROP TABLE t1, t2; +create table t1 (a int); +insert into t1 values (1), (2), (3); +SET SQL_SELECT_LIMIT=1; +select sum(a) from (select * from t1) as a; +sum(a) +6 +select 2 in (select * from t1); +2 in (select * from t1) +1 +SET SQL_SELECT_LIMIT=default; +drop table t1; +CREATE TABLE t1 (a int, b int, INDEX (a)); +INSERT INTO t1 VALUES (1, 1), (1, 2), (1, 3); +SELECT * FROM t1 WHERE a = (SELECT MAX(a) FROM t1 WHERE a = 1) ORDER BY b; +a b +1 1 +1 2 +1 3 +DROP TABLE t1; +create table t1(val varchar(10)); +insert into t1 values ('aaa'), ('bbb'),('eee'),('mmm'),('ppp'); +select count(*) from t1 as w1 where w1.val in (select w2.val from t1 as w2 where w2.val like 'm%') and w1.val in (select w3.val from t1 as w3 where w3.val like 'e%'); +count(*) +0 +drop table t1; +create table t1 (id int not null, text varchar(20) not null default '', primary key (id)); +insert into t1 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text11'), (12, 'text12'); +select * from t1 where id not in (select id from t1 where id < 8); +id text +8 text8 +9 text9 +10 text10 +11 text11 +12 text12 +select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null); +id text +8 text8 +9 text9 +10 text10 +11 text11 +12 text12 +explain extended select * from t1 where id not in (select id from t1 where id < 8); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 12 100.00 Using where +2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index; Using where +Warnings: +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (not(<expr_cache><`test`.`t1`.`id`>(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where ((`test`.`t1`.`id` < 8) and (<cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`)))))))) +explain extended select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY tt ALL NULL NULL NULL NULL 12 100.00 Using where +2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 test.tt.id 1 100.00 Using where; Using index +Warnings: +Note 1276 Field or reference 'test.tt.id' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where (not(<in_optimizer>(1,<expr_cache><`test`.`tt`.`id`>(exists(select `test`.`t1`.`id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null)))))) +insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001'); +create table t2 (id int not null, text varchar(20) not null default '', primary key (id)); +insert into t2 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text1'), (12, 'text2'), (13, 'text3'), (14, 'text4'), (15, 'text5'), (16, 'text6'), (17, 'text7'), (18, 'text8'), (19, 'text9'), (20, 'text10'),(21, 'text1'), (22, 'text2'), (23, 'text3'), (24, 'text4'), (25, 'text5'), (26, 'text6'), (27, 'text7'), (28, 'text8'), (29, 'text9'), (30, 'text10'), (31, 'text1'), (32, 'text2'), (33, 'text3'), (34, 'text4'), (35, 'text5'), (36, 'text6'), (37, 'text7'), (38, 'text8'), (39, 'text9'), (40, 'text10'), (41, 'text1'), (42, 'text2'), (43, 'text3'), (44, 'text4'), (45, 'text5'), (46, 'text6'), (47, 'text7'), (48, 'text8'), (49, 'text9'), (50, 'text10'); +select * from t1 a left join t2 b on (a.id=b.id or b.id is null) join t1 c on (if(isnull(b.id), 1000, b.id)=c.id); +id text id text id text +1 text1 1 text1 1 text1 +2 text2 2 text2 2 text2 +3 text3 3 text3 3 text3 +4 text4 4 text4 4 text4 +5 text5 5 text5 5 text5 +6 text6 6 text6 6 text6 +7 text7 7 text7 7 text7 +8 text8 8 text8 8 text8 +9 text9 9 text9 9 text9 +10 text10 10 text10 10 text10 +11 text11 11 text1 11 text11 +12 text12 12 text2 12 text12 +1000 text1000 NULL NULL 1000 text1000 +1001 text1001 NULL NULL 1000 text1000 +explain extended select * from t1 a left join t2 b on (a.id=b.id or b.id is null) join t1 c on (if(isnull(b.id), 1000, b.id)=c.id); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE a ALL NULL NULL NULL NULL 14 100.00 +1 SIMPLE b eq_ref PRIMARY PRIMARY 4 test.a.id 2 100.00 +1 SIMPLE c eq_ref PRIMARY PRIMARY 4 func 1 100.00 Using index condition +Warnings: +Note 1003 select `test`.`a`.`id` AS `id`,`test`.`a`.`text` AS `text`,`test`.`b`.`id` AS `id`,`test`.`b`.`text` AS `text`,`test`.`c`.`id` AS `id`,`test`.`c`.`text` AS `text` from `test`.`t1` `a` left join `test`.`t2` `b` on(((`test`.`b`.`id` = `test`.`a`.`id`) or isnull(`test`.`b`.`id`))) join `test`.`t1` `c` where (if(isnull(`test`.`b`.`id`),1000,`test`.`b`.`id`) = `test`.`c`.`id`) +drop table t1,t2; +create table t1 (a int); +insert into t1 values (1); +explain select benchmark(1000, (select a from t1 where a=sha(rand()))); +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 +2 UNCACHEABLE SUBQUERY t1 system NULL NULL NULL NULL 1 +drop table t1; +create table t1(id int); +create table t2(id int); +create table t3(flag int); +select (select * from t3 where id not null) from t1, t2; +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 'null) from t1, t2' at line 1 +drop table t1,t2,t3; +CREATE TABLE t1 (id INT); +CREATE TABLE t2 (id INT); +INSERT INTO t1 VALUES (1), (2); +INSERT INTO t2 VALUES (1); +SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id); +id c +1 1 +2 0 +SELECT id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id); +id c +1 1 +2 0 +SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY t1.id; +id c +1 1 +2 0 +SELECT id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY id; +id c +1 1 +2 0 +DROP TABLE t1,t2; +CREATE TABLE t1 ( a int, b int ); +INSERT INTO t1 VALUES (1,1),(2,2),(3,3); +SELECT a FROM t1 WHERE a > ANY ( SELECT a FROM t1 WHERE b = 2 ); +a +3 +SELECT a FROM t1 WHERE a < ANY ( SELECT a FROM t1 WHERE b = 2 ); +a +1 +SELECT a FROM t1 WHERE a = ANY ( SELECT a FROM t1 WHERE b = 2 ); +a +2 +SELECT a FROM t1 WHERE a >= ANY ( SELECT a FROM t1 WHERE b = 2 ); +a +2 +3 +SELECT a FROM t1 WHERE a <= ANY ( SELECT a FROM t1 WHERE b = 2 ); +a +1 +2 +SELECT a FROM t1 WHERE a <> ANY ( SELECT a FROM t1 WHERE b = 2 ); +a +1 +3 +SELECT a FROM t1 WHERE a > ALL ( SELECT a FROM t1 WHERE b = 2 ); +a +3 +SELECT a FROM t1 WHERE a < ALL ( SELECT a FROM t1 WHERE b = 2 ); +a +1 +SELECT a FROM t1 WHERE a = ALL ( SELECT a FROM t1 WHERE b = 2 ); +a +2 +SELECT a FROM t1 WHERE a >= ALL ( SELECT a FROM t1 WHERE b = 2 ); +a +2 +3 +SELECT a FROM t1 WHERE a <= ALL ( SELECT a FROM t1 WHERE b = 2 ); +a +1 +2 +SELECT a FROM t1 WHERE a <> ALL ( SELECT a FROM t1 WHERE b = 2 ); +a +1 +3 +ALTER TABLE t1 ADD INDEX (a); +SELECT a FROM t1 WHERE a > ANY ( SELECT a FROM t1 WHERE b = 2 ); +a +3 +SELECT a FROM t1 WHERE a < ANY ( SELECT a FROM t1 WHERE b = 2 ); +a +1 +SELECT a FROM t1 WHERE a = ANY ( SELECT a FROM t1 WHERE b = 2 ); +a +2 +SELECT a FROM t1 WHERE a >= ANY ( SELECT a FROM t1 WHERE b = 2 ); +a +2 +3 +SELECT a FROM t1 WHERE a <= ANY ( SELECT a FROM t1 WHERE b = 2 ); +a +1 +2 +SELECT a FROM t1 WHERE a <> ANY ( SELECT a FROM t1 WHERE b = 2 ); +a +1 +3 +SELECT a FROM t1 WHERE a > ALL ( SELECT a FROM t1 WHERE b = 2 ); +a +3 +SELECT a FROM t1 WHERE a < ALL ( SELECT a FROM t1 WHERE b = 2 ); +a +1 +SELECT a FROM t1 WHERE a = ALL ( SELECT a FROM t1 WHERE b = 2 ); +a +2 +SELECT a FROM t1 WHERE a >= ALL ( SELECT a FROM t1 WHERE b = 2 ); +a +2 +3 +SELECT a FROM t1 WHERE a <= ALL ( SELECT a FROM t1 WHERE b = 2 ); +a +1 +2 +SELECT a FROM t1 WHERE a <> ALL ( SELECT a FROM t1 WHERE b = 2 ); +a +1 +3 +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 HAVING a = 2); +a +3 +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 HAVING a = 2); +a +1 +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 HAVING a = 2); +a +2 +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 HAVING a = 2); +a +2 +3 +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 HAVING a = 2); +a +1 +2 +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 HAVING a = 2); +a +1 +3 +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 HAVING a = 2); +a +3 +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 HAVING a = 2); +a +1 +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 HAVING a = 2); +a +2 +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 HAVING a = 2); +a +2 +3 +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 HAVING a = 2); +a +1 +2 +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 HAVING a = 2); +a +1 +3 +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); +a +3 +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); +a +1 +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); +a +2 +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); +a +2 +3 +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); +a +1 +2 +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); +a +1 +3 +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); +a +3 +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); +a +1 +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); +a +2 +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); +a +2 +3 +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); +a +1 +2 +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); +a +1 +3 +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); +a +3 +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); +a +1 +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); +a +2 +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); +a +2 +3 +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); +a +1 +2 +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); +a +1 +3 +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); +a +3 +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); +a +1 +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); +a +2 +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); +a +2 +3 +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); +a +1 +2 +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); +a +1 +3 +SELECT a FROM t1 WHERE (1,2) > ANY (SELECT a FROM t1 WHERE b = 2); +ERROR 21000: Operand should contain 1 column(s) +SELECT a FROM t1 WHERE a > ANY (SELECT a,2 FROM t1 WHERE b = 2); +ERROR 21000: Operand should contain 1 column(s) +SELECT a FROM t1 WHERE (1,2) > ANY (SELECT a,2 FROM t1 WHERE b = 2); +ERROR 21000: Operand should contain 1 column(s) +SELECT a FROM t1 WHERE (1,2) > ALL (SELECT a FROM t1 WHERE b = 2); +ERROR 21000: Operand should contain 1 column(s) +SELECT a FROM t1 WHERE a > ALL (SELECT a,2 FROM t1 WHERE b = 2); +ERROR 21000: Operand should contain 1 column(s) +SELECT a FROM t1 WHERE (1,2) > ALL (SELECT a,2 FROM t1 WHERE b = 2); +ERROR 21000: Operand should contain 1 column(s) +SELECT a FROM t1 WHERE (1,2) = ALL (SELECT a,2 FROM t1 WHERE b = 2); +ERROR 21000: Operand should contain 1 column(s) +SELECT a FROM t1 WHERE (1,2) <> ANY (SELECT a,2 FROM t1 WHERE b = 2); +ERROR 21000: Operand should contain 1 column(s) +SELECT a FROM t1 WHERE (1,2) = ANY (SELECT a FROM t1 WHERE b = 2); +ERROR 21000: Operand should contain 2 column(s) +SELECT a FROM t1 WHERE a = ANY (SELECT a,2 FROM t1 WHERE b = 2); +ERROR 21000: Operand should contain 1 column(s) +SELECT a FROM t1 WHERE (1,2) = ANY (SELECT a,2 FROM t1 WHERE b = 2); +a +SELECT a FROM t1 WHERE (1,2) <> ALL (SELECT a FROM t1 WHERE b = 2); +ERROR 21000: Operand should contain 2 column(s) +SELECT a FROM t1 WHERE a <> ALL (SELECT a,2 FROM t1 WHERE b = 2); +ERROR 21000: Operand should contain 1 column(s) +SELECT a FROM t1 WHERE (1,2) <> ALL (SELECT a,2 FROM t1 WHERE b = 2); +a +1 +2 +3 +SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 WHERE b = 2); +a +2 +SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 WHERE b = 2); +a +1 +3 +SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 HAVING a = 2); +a +2 +SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 HAVING a = 2); +a +1 +3 +SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 WHERE b = 2 UNION SELECT a,1 FROM t1 WHERE b = 2); +a +2 +SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 WHERE b = 2 UNION SELECT a,1 FROM t1 WHERE b = 2); +a +1 +3 +SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 HAVING a = 2 UNION SELECT a,1 FROM t1 HAVING a = 2); +a +2 +SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 HAVING a = 2 UNION SELECT a,1 FROM t1 HAVING a = 2); +a +1 +3 +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2 group by a); +a +3 +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2 group by a); +a +1 +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2 group by a); +a +2 +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2 group by a); +a +2 +3 +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2 group by a); +a +1 +2 +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2 group by a); +a +1 +3 +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2 group by a); +a +3 +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2 group by a); +a +1 +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2 group by a); +a +2 +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2 group by a); +a +2 +3 +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2 group by a); +a +1 +2 +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2 group by a); +a +1 +3 +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 group by a HAVING a = 2); +a +3 +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 group by a HAVING a = 2); +a +1 +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 group by a HAVING a = 2); +a +2 +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 group by a HAVING a = 2); +a +2 +3 +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 group by a HAVING a = 2); +a +1 +2 +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 group by a HAVING a = 2); +a +1 +3 +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 group by a HAVING a = 2); +a +3 +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 group by a HAVING a = 2); +a +1 +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 group by a HAVING a = 2); +a +2 +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 group by a HAVING a = 2); +a +2 +3 +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 group by a HAVING a = 2); +a +1 +2 +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 group by a HAVING a = 2); +a +1 +3 +SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a > t1.a), '-') from t1 a; +concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a > t1.a), '-') +0- +0- +1- +SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a < t1.a), '-') from t1 a; +concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a < t1.a), '-') +1- +0- +0- +SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a = t1.a), '-') from t1 a; +concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a = t1.a), '-') +0- +1- +0- +DROP TABLE t1; +CREATE TABLE t1 ( a double, b double ); +INSERT INTO t1 VALUES (1,1),(2,2),(3,3); +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2e0); +a +3 +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2e0); +a +1 +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2e0); +a +2 +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2e0); +a +2 +3 +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2e0); +a +1 +2 +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2e0); +a +1 +3 +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2e0); +a +3 +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2e0); +a +1 +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2e0); +a +2 +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2e0); +a +2 +3 +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2e0); +a +1 +2 +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2e0); +a +1 +3 +DROP TABLE t1; +CREATE TABLE t1 ( a char(1), b char(1)); +INSERT INTO t1 VALUES ('1','1'),('2','2'),('3','3'); +SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = '2'); +a +3 +SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = '2'); +a +1 +SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = '2'); +a +2 +SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = '2'); +a +2 +3 +SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = '2'); +a +1 +2 +SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = '2'); +a +1 +3 +SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = '2'); +a +3 +SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = '2'); +a +1 +SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = '2'); +a +2 +SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = '2'); +a +2 +3 +SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = '2'); +a +1 +2 +SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = '2'); +a +1 +3 +DROP TABLE t1; +create table t1 (a int, b int); +insert into t1 values (1,2),(3,4); +select * from t1 up where exists (select * from t1 where t1.a=up.a); +a b +1 2 +3 4 +explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY up ALL NULL NULL NULL NULL 2 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 +Warnings: +Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1 +Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` semi join (`test`.`t1`) where 1 +drop table t1; +CREATE TABLE t1 (t1_a int); +INSERT INTO t1 VALUES (1); +CREATE TABLE t2 (t2_a int, t2_b int, PRIMARY KEY (t2_a, t2_b)); +INSERT INTO t2 VALUES (1, 1), (1, 2); +SELECT * FROM t1, t2 table2 WHERE t1_a = 1 AND table2.t2_a = 1 +HAVING table2.t2_b = (SELECT MAX(t2_b) FROM t2 WHERE t2_a = table2.t2_a); +t1_a t2_a t2_b +1 1 2 +DROP TABLE t1, t2; +CREATE TABLE t1 (id int(11) default NULL,name varchar(10) default NULL); +INSERT INTO t1 VALUES (1,'Tim'),(2,'Rebecca'),(3,NULL); +CREATE TABLE t2 (id int(11) default NULL, pet varchar(10) default NULL); +INSERT INTO t2 VALUES (1,'Fido'),(2,'Spot'),(3,'Felix'); +SELECT a.*, b.* FROM (SELECT * FROM t1) AS a JOIN t2 as b on a.id=b.id; +id name id pet +1 Tim 1 Fido +2 Rebecca 2 Spot +3 NULL 3 Felix +drop table t1,t2; +CREATE TABLE t1 ( a int, b int ); +CREATE TABLE t2 ( c int, d int ); +INSERT INTO t1 VALUES (1,2), (2,3), (3,4); +SELECT a AS abc, b FROM t1 outr WHERE b = +(SELECT MIN(b) FROM t1 WHERE a=outr.a); +abc b +1 2 +2 3 +3 4 +INSERT INTO t2 SELECT a AS abc, b FROM t1 outr WHERE b = +(SELECT MIN(b) FROM t1 WHERE a=outr.a); +select * from t2; +c d +1 2 +2 3 +3 4 +CREATE TABLE t3 SELECT a AS abc, b FROM t1 outr WHERE b = +(SELECT MIN(b) FROM t1 WHERE a=outr.a); +select * from t3; +abc b +1 2 +2 3 +3 4 +prepare stmt1 from "INSERT INTO t2 SELECT a AS abc, b FROM t1 outr WHERE b = (SELECT MIN(b) FROM t1 WHERE a=outr.a);"; +execute stmt1; +deallocate prepare stmt1; +select * from t2; +c d +1 2 +2 3 +3 4 +1 2 +2 3 +3 4 +drop table t3; +prepare stmt1 from "CREATE TABLE t3 SELECT a AS abc, b FROM t1 outr WHERE b = (SELECT MIN(b) FROM t1 WHERE a=outr.a);"; +execute stmt1; +select * from t3; +abc b +1 2 +2 3 +3 4 +deallocate prepare stmt1; +DROP TABLE t1, t2, t3; +CREATE TABLE `t1` ( `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1; +insert into t1 values (1); +CREATE TABLE `t2` ( `b` int(11) default NULL, `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1; +insert into t2 values (1,2); +select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL (SELECT count(*) FROM t2 t001 WHERE t001.a=1); +a C +1 1 +drop table t1,t2; +create table t1 (a int not null auto_increment primary key, b varchar(40), fulltext(b)); +insert into t1 (b) values ('ball'),('ball games'), ('games'), ('foo'), ('foobar'), ('Serg'), ('Sergei'),('Georg'), ('Patrik'),('Hakan'); +create table t2 (a int); +insert into t2 values (1),(3),(2),(7); +select a,b from t1 where match(b) against ('Ball') > 0; +a b +1 ball +2 ball games +select a from t2 where a in (select a from t1 where match(b) against ('Ball') > 0); +a +1 +2 +drop table t1,t2; +CREATE TABLE t1(`IZAVORGANG_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin,`KUERZEL` VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_bin,`IZAANALYSEART_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin,`IZAPMKZ_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin); +CREATE INDEX AK01IZAVORGANG ON t1(izaAnalyseart_id,Kuerzel); +INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000001','601','D0000000001','I0000000001'); +INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000002','602','D0000000001','I0000000001'); +INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000003','603','D0000000001','I0000000001'); +INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000004','101','D0000000001','I0000000001'); +SELECT `IZAVORGANG_ID` FROM t1 WHERE `KUERZEL` IN(SELECT MIN(`KUERZEL`)`Feld1` FROM t1 WHERE `KUERZEL` LIKE'601%'And`IZAANALYSEART_ID`='D0000000001'); +IZAVORGANG_ID +D0000000001 +drop table t1; +CREATE TABLE `t1` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`)); +CREATE TABLE `t2` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`)); +insert into t1 values (1,1),(1,2),(2,1),(2,2); +insert into t2 values (1,2),(2,2); +select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); +aid bid +1 1 +2 1 +alter table t2 drop primary key; +alter table t2 add key KEY1 (aid, bid); +select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); +aid bid +1 1 +2 1 +alter table t2 drop key KEY1; +alter table t2 add primary key (bid, aid); +select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); +aid bid +1 1 +2 1 +drop table t1,t2; +CREATE TABLE t1 (howmanyvalues bigint, avalue int); +INSERT INTO t1 VALUES (1, 1),(2, 1),(2, 2),(3, 1),(3, 2),(3, 3),(4, 1),(4, 2),(4, 3),(4, 4); +SELECT howmanyvalues, count(*) from t1 group by howmanyvalues; +howmanyvalues count(*) +1 1 +2 2 +3 3 +4 4 +SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues; +howmanyvalues mycount +1 1 +2 2 +3 3 +4 4 +CREATE INDEX t1_howmanyvalues_idx ON t1 (howmanyvalues); +SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues+1 = a.howmanyvalues+1) as mycount from t1 a group by a.howmanyvalues; +howmanyvalues mycount +1 1 +2 2 +3 3 +4 4 +SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues; +howmanyvalues mycount +1 1 +2 2 +3 3 +4 4 +SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.avalue) as mycount from t1 a group by a.howmanyvalues; +howmanyvalues mycount +1 1 +2 1 +3 1 +4 1 +drop table t1; +create table t1 (x int); +select (select b.x from t1 as b where b.x=a.x) from t1 as a where a.x=2 group by a.x; +(select b.x from t1 as b where b.x=a.x) +drop table t1; +CREATE TABLE `t1` ( `master` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `slave` int(10) unsigned NOT NULL default '0', `access` int(10) unsigned NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`)); +INSERT INTO `t1` VALUES (1,0,0,700),(1,1,1,400),(1,5,5,400),(1,12,12,400),(1,12,32,400),(4,12,32,400); +CREATE TABLE `t2` ( `id` int(10) unsigned NOT NULL default '0', `pid` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `level` tinyint(4) unsigned NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ; +INSERT INTO `t2` VALUES (6,5,12,7,'a'),(12,0,0,7,'a'),(12,1,0,7,'a'),(12,5,5,7,'a'),(12,5,12,7,'a'); +SELECT b.sc FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b; +ERROR 42S22: Unknown column 'b.sc' in 'field list' +SELECT b.ac FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b; +ac +700 +NULL +drop tables t1,t2; +create table t1 (a int not null, b int not null, c int, primary key (a,b)); +insert into t1 values (1,1,1), (2,2,2), (3,3,3); +set @b:= 0; +explain select sum(a) from t1 where b > @b; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index NULL PRIMARY 8 NULL 3 Using where; Using index +set @a:= (select sum(a) from t1 where b > @b); +explain select a from t1 where c=2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +do @a:= (select sum(a) from t1 where b > @b); +explain select a from t1 where c=2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +drop table t1; +set @got_val= (SELECT 1 FROM (SELECT 'A' as my_col) as T1 ) ; +create table t1 (a int, b int); +create table t2 (a int, b int); +insert into t1 values (1,1),(1,2),(1,3),(2,4),(2,5); +insert into t2 values (1,3),(2,1); +select distinct a,b, (select max(b) from t2 where t1.b=t2.a) from t1 order by t1.b; +a b (select max(b) from t2 where t1.b=t2.a) +1 1 3 +1 2 1 +1 3 NULL +2 4 NULL +2 5 NULL +drop table t1, t2; +create table t1 (id int); +create table t2 (id int, body text, fulltext (body)); +insert into t1 values(1),(2),(3); +insert into t2 values (1,'test'), (2,'mysql'), (3,'test'), (4,'test'); +select count(distinct id) from t1 where id in (select id from t2 where match(body) against ('mysql' in boolean mode)); +count(distinct id) +1 +drop table t2,t1; +create table t1 (s1 int,s2 int); +insert into t1 values (20,15); +select * from t1 where (('a',null) <=> (select 'a',s2 from t1 where s1 = 0)); +s1 s2 +drop table t1; +create table t1 (s1 int); +insert into t1 values (1),(null); +select * from t1 where s1 < all (select s1 from t1); +s1 +select s1, s1 < all (select s1 from t1) from t1; +s1 s1 < all (select s1 from t1) +1 0 +NULL NULL +drop table t1; +CREATE TABLE t1 ( +Code char(3) NOT NULL default '', +Name char(52) NOT NULL default '', +Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia', +Region char(26) NOT NULL default '', +SurfaceArea float(10,2) NOT NULL default '0.00', +IndepYear smallint(6) default NULL, +Population int(11) NOT NULL default '0', +LifeExpectancy float(3,1) default NULL, +GNP float(10,2) default NULL, +GNPOld float(10,2) default NULL, +LocalName char(45) NOT NULL default '', +GovernmentForm char(45) NOT NULL default '', +HeadOfState char(60) default NULL, +Capital int(11) default NULL, +Code2 char(2) NOT NULL default '' +) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('XXX','Xxxxx','Oceania','Xxxxxx',26.00,0,0,0,0,0,'Xxxxx','Xxxxx','Xxxxx',NULL,'XX'); +INSERT INTO t1 VALUES ('ASM','American Samoa','Oceania','Polynesia',199.00,0,68000,75.1,334.00,NULL,'Amerika Samoa','US Territory','George W. Bush',54,'AS'); +INSERT INTO t1 VALUES ('ATF','French Southern territories','Antarctica','Antarctica',7780.00,0,0,NULL,0.00,NULL,'Terres australes françaises','Nonmetropolitan Territory of France','Jacques Chirac',NULL,'TF'); +INSERT INTO t1 VALUES ('UMI','United States Minor Outlying Islands','Oceania','Micronesia/Caribbean',16.00,0,0,NULL,0.00,NULL,'United States Minor Outlying Islands','Dependent Territory of the US','George W. Bush',NULL,'UM'); +/*!40000 ALTER TABLE t1 ENABLE KEYS */; +SELECT DISTINCT Continent AS c FROM t1 outr WHERE +Code <> SOME ( SELECT Code FROM t1 WHERE Continent = outr.Continent AND +Population < 200); +c +Oceania +drop table t1; +create table t1 (a1 int); +create table t2 (b1 int); +select * from t1 where a2 > any(select b1 from t2); +ERROR 42S22: Unknown column 'a2' in 'IN/ALL/ANY subquery' +select * from t1 where a1 > any(select b1 from t2); +a1 +drop table t1,t2; +create table t1 (a integer, b integer); +select (select * from t1) = (select 1,2); +(select * from t1) = (select 1,2) +NULL +select (select 1,2) = (select * from t1); +(select 1,2) = (select * from t1) +NULL +select row(1,2) = ANY (select * from t1); +row(1,2) = ANY (select * from t1) +0 +select row(1,2) != ALL (select * from t1); +row(1,2) != ALL (select * from t1) +1 +drop table t1; +create table t1 (a integer, b integer); +select row(1,(2,2)) in (select * from t1 ); +ERROR 21000: Operand should contain 2 column(s) +select row(1,(2,2)) = (select * from t1 ); +ERROR 21000: Operand should contain 2 column(s) +select (select * from t1) = row(1,(2,2)); +ERROR 21000: Operand should contain 1 column(s) +drop table t1; +create table t1 (a integer); +insert into t1 values (1); +select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx ; +ERROR 42S22: Reference 'xx' not supported (forward reference in item list) +select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx; +ERROR 42S22: Reference 'xx' not supported (forward reference in item list) +select 1 as xx, 1 = ALL ( select 1 from t1 where 1 = xx ); +xx 1 = ALL ( select 1 from t1 where 1 = xx ) +1 1 +select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx; +ERROR 42S22: Reference 'xx' not supported (forward reference in item list) +select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx from DUAL; +ERROR 42S22: Reference 'xx' not supported (forward reference in item list) +drop table t1; +CREATE TABLE t1 ( +categoryId int(11) NOT NULL, +courseId int(11) NOT NULL, +startDate datetime NOT NULL, +endDate datetime NOT NULL, +createDate datetime NOT NULL, +modifyDate timestamp NOT NULL, +attributes text NOT NULL +); +INSERT INTO t1 VALUES (1,41,'2004-02-09','2010-01-01','2004-02-09','2004-02-09',''), +(1,86,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''), +(1,87,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''), +(2,52,'2004-03-15','2004-10-01','2004-03-15','2004-09-17',''), +(2,53,'2004-03-16','2004-10-01','2004-03-16','2004-09-17',''), +(2,88,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''), +(2,89,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''), +(3,51,'2004-02-09','2010-01-01','2004-02-09','2004-02-09',''), +(5,12,'2004-02-18','2010-01-01','2004-02-18','2004-02-18',''); +CREATE TABLE t2 ( +userId int(11) NOT NULL, +courseId int(11) NOT NULL, +date datetime NOT NULL +); +INSERT INTO t2 VALUES (5141,71,'2003-11-18'), +(5141,72,'2003-11-25'),(5141,41,'2004-08-06'), +(5141,52,'2004-08-06'),(5141,53,'2004-08-06'), +(5141,12,'2004-08-06'),(5141,86,'2004-10-21'), +(5141,87,'2004-10-21'),(5141,88,'2004-10-21'), +(5141,89,'2004-10-22'),(5141,51,'2004-10-26'); +CREATE TABLE t3 ( +groupId int(11) NOT NULL, +parentId int(11) NOT NULL, +startDate datetime NOT NULL, +endDate datetime NOT NULL, +createDate datetime NOT NULL, +modifyDate timestamp NOT NULL, +ordering int(11) +); +INSERT INTO t3 VALUES (12,9,'1000-01-01','3999-12-31','2004-01-29','2004-01-29',NULL); +CREATE TABLE t4 ( +id int(11) NOT NULL, +groupTypeId int(11) NOT NULL, +groupKey varchar(50) NOT NULL, +name text, +ordering int(11), +description text, +createDate datetime NOT NULL, +modifyDate timestamp NOT NULL +); +INSERT INTO t4 VALUES (9,5,'stationer','stationer',0,'Stationer','2004-01-29','2004-01-29'), +(12,5,'group2','group2',0,'group2','2004-01-29','2004-01-29'); +CREATE TABLE t5 ( +userId int(11) NOT NULL, +groupId int(11) NOT NULL, +createDate datetime NOT NULL, +modifyDate timestamp NOT NULL +); +INSERT INTO t5 VALUES (5141,12,'2004-08-06','2004-08-06'); +select +count(distinct t2.userid) pass, +groupstuff.*, +count(t2.courseid) crse, +t1.categoryid, +t2.courseid, +date_format(date, '%b%y') as colhead +from t2 +join t1 on t2.courseid=t1.courseid +join +( +select +t5.userid, +parentid, +parentgroup, +childid, +groupname, +grouptypeid +from t5 +join +( +select t4.id as parentid, +t4.name as parentgroup, +t4.id as childid, +t4.name as groupname, +t4.grouptypeid +from t4 +) as gin on t5.groupid=gin.childid +) as groupstuff on t2.userid = groupstuff.userid +group by +groupstuff.groupname, colhead , t2.courseid; +pass userid parentid parentgroup childid groupname grouptypeid crse categoryid courseid colhead +1 5141 12 group2 12 group2 5 1 5 12 Aug04 +1 5141 12 group2 12 group2 5 1 1 41 Aug04 +1 5141 12 group2 12 group2 5 1 2 52 Aug04 +1 5141 12 group2 12 group2 5 1 2 53 Aug04 +1 5141 12 group2 12 group2 5 1 3 51 Oct04 +1 5141 12 group2 12 group2 5 1 1 86 Oct04 +1 5141 12 group2 12 group2 5 1 1 87 Oct04 +1 5141 12 group2 12 group2 5 1 2 88 Oct04 +1 5141 12 group2 12 group2 5 1 2 89 Oct04 +drop table t1, t2, t3, t4, t5; +create table t1 (a int); +insert into t1 values (1), (2), (3); +SELECT 1 FROM t1 WHERE (SELECT 1) in (SELECT 1); +1 +1 +1 +1 +drop table t1; +create table t1 (a int); +create table t2 (a int); +insert into t1 values (1),(2); +insert into t2 values (0),(1),(2),(3); +select a from t2 where a in (select a from t1); +a +1 +2 +select a from t2 having a in (select a from t1); +a +1 +2 +prepare stmt1 from "select a from t2 where a in (select a from t1)"; +execute stmt1; +a +1 +2 +execute stmt1; +a +1 +2 +deallocate prepare stmt1; +prepare stmt1 from "select a from t2 having a in (select a from t1)"; +execute stmt1; +a +1 +2 +execute stmt1; +a +1 +2 +deallocate prepare stmt1; +drop table t1, t2; +create table t1 (a int, b int); +insert into t1 values (1,2); +select 1 = (select * from t1); +ERROR 21000: Operand should contain 1 column(s) +select (select * from t1) = 1; +ERROR 21000: Operand should contain 2 column(s) +select (1,2) = (select a from t1); +ERROR 21000: Operand should contain 2 column(s) +select (select a from t1) = (1,2); +ERROR 21000: Operand should contain 1 column(s) +select (1,2,3) = (select * from t1); +ERROR 21000: Operand should contain 3 column(s) +select (select * from t1) = (1,2,3); +ERROR 21000: Operand should contain 2 column(s) +drop table t1; +CREATE TABLE `t1` ( +`itemid` bigint(20) unsigned NOT NULL auto_increment, +`sessionid` bigint(20) unsigned default NULL, +`time` int(10) unsigned NOT NULL default '0', +`type` set('A','D','E','F','G','I','L','N','U') collate latin1_general_ci NOT +NULL default '', +`data` text collate latin1_general_ci NOT NULL, +PRIMARY KEY (`itemid`) +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; +INSERT INTO `t1` VALUES (1, 1, 1, 'D', ''); +CREATE TABLE `t2` ( +`sessionid` bigint(20) unsigned NOT NULL auto_increment, +`pid` int(10) unsigned NOT NULL default '0', +`date` int(10) unsigned NOT NULL default '0', +`ip` varchar(15) collate latin1_general_ci NOT NULL default '', +PRIMARY KEY (`sessionid`) +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; +INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1'); +SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessionid WHERE e.sessionid = ( SELECT sessionid FROM t2 ORDER BY sessionid DESC LIMIT 1 ) GROUP BY s.ip HAVING count( e.itemid ) >0 LIMIT 0 , 30; +ip count( e.itemid ) +10.10.10.1 1 +drop tables t1,t2; +create table t1 (fld enum('0','1')); +insert into t1 values ('1'); +select * from (select max(fld) from t1) as foo; +max(fld) +1 +drop table t1; +set @tmp11867_optimizer_switch=@@optimizer_switch; +set optimizer_switch='semijoin_with_cache=off'; +CREATE TABLE t1 (one int, two int, flag char(1)); +CREATE TABLE t2 (one int, two int, flag char(1)); +INSERT INTO t1 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N'); +INSERT INTO t2 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N'); +SELECT * FROM t1 +WHERE ROW(one,two) IN (SELECT DISTINCT one,two FROM t2 WHERE flag = 'N'); +one two flag +5 6 N +7 8 N +SELECT * FROM t1 +WHERE ROW(one,two) IN (SELECT DISTINCT one,two FROM t1 WHERE flag = 'N'); +one two flag +5 6 N +7 8 N +insert into t2 values (null,null,'N'); +insert into t2 values (null,3,'0'); +insert into t2 values (null,5,'0'); +insert into t2 values (10,null,'0'); +insert into t1 values (10,3,'0'); +insert into t1 values (10,5,'0'); +insert into t1 values (10,10,'0'); +SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N') as 'test' from t1; +one two test +1 2 NULL +2 3 NULL +3 4 NULL +5 6 1 +7 8 1 +10 3 NULL +10 5 NULL +10 10 NULL +SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N'); +one two +5 6 +7 8 +SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N' group by one,two) as 'test' from t1; +one two test +1 2 NULL +2 3 NULL +3 4 NULL +5 6 1 +7 8 1 +10 3 NULL +10 5 NULL +10 10 NULL +SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as 'test' from t1; +one two test +1 2 0 +2 3 NULL +3 4 0 +5 6 0 +7 8 0 +10 3 NULL +10 5 NULL +10 10 NULL +SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1; +one two test +1 2 0 +2 3 NULL +3 4 0 +5 6 0 +7 8 0 +10 3 NULL +10 5 NULL +10 10 NULL +explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as 'test' from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`one`,`test`.`t1`.`two`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)))) and trigcond(trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1` +explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 9 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` semi join (`test`.`t2`) where (`test`.`t2`.`flag` = 'N') +explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`one`,`test`.`t1`.`two`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)))) and trigcond(trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1` +DROP TABLE t1,t2; +set optimizer_switch=@tmp11867_optimizer_switch; +CREATE TABLE t1 (a char(5), b char(5)); +INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa'); +SELECT * FROM t1 WHERE (a,b) IN (('aaa','aaa'), ('aaa','bbb')); +a b +aaa aaa +DROP TABLE t1; +CREATE TABLE t1 (a int); +CREATE TABLE t2 (a int, b int); +CREATE TABLE t3 (b int NOT NULL); +INSERT INTO t1 VALUES (1), (2), (3), (4); +INSERT INTO t2 VALUES (1,10), (3,30); +SELECT * FROM t2 LEFT JOIN t3 ON t2.b=t3.b +WHERE t3.b IS NOT NULL OR t2.a > 10; +a b b +SELECT * FROM t1 +WHERE t1.a NOT IN (SELECT a FROM t2 LEFT JOIN t3 ON t2.b=t3.b +WHERE t3.b IS NOT NULL OR t2.a > 10); +a +1 +2 +3 +4 +DROP TABLE t1,t2,t3; +CREATE TABLE t1 (f1 INT); +CREATE TABLE t2 (f2 INT); +INSERT INTO t1 VALUES (1); +SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2); +f1 +1 +SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE 1=0); +f1 +1 +INSERT INTO t2 VALUES (1); +INSERT INTO t2 VALUES (2); +SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE f2=0); +f1 +1 +DROP TABLE t1, t2; +select 1 from dual where 1 < any (select 2); +1 +1 +select 1 from dual where 1 < all (select 2); +1 +1 +select 1 from dual where 2 > any (select 1); +1 +1 +select 1 from dual where 2 > all (select 1); +1 +1 +select 1 from dual where 1 < any (select 2 from dual); +1 +1 +select 1 from dual where 1 < all (select 2 from dual where 1!=1); +1 +1 +create table t1 (s1 char); +insert into t1 values (1),(2); +select * from t1 where (s1 < any (select s1 from t1)); +s1 +1 +select * from t1 where not (s1 < any (select s1 from t1)); +s1 +2 +select * from t1 where (s1 < ALL (select s1+1 from t1)); +s1 +1 +select * from t1 where not(s1 < ALL (select s1+1 from t1)); +s1 +2 +select * from t1 where (s1+1 = ANY (select s1 from t1)); +s1 +1 +select * from t1 where NOT(s1+1 = ANY (select s1 from t1)); +s1 +2 +select * from t1 where (s1 = ALL (select s1/s1 from t1)); +s1 +1 +select * from t1 where NOT(s1 = ALL (select s1/s1 from t1)); +s1 +2 +drop table t1; +create table t1 ( +retailerID varchar(8) NOT NULL, +statusID int(10) unsigned NOT NULL, +changed datetime NOT NULL, +UNIQUE KEY retailerID (retailerID, statusID, changed) +); +INSERT INTO t1 VALUES("0026", "1", "2005-12-06 12:18:56"); +INSERT INTO t1 VALUES("0026", "2", "2006-01-06 12:25:53"); +INSERT INTO t1 VALUES("0037", "1", "2005-12-06 12:18:56"); +INSERT INTO t1 VALUES("0037", "2", "2006-01-06 12:25:53"); +INSERT INTO t1 VALUES("0048", "1", "2006-01-06 12:37:50"); +INSERT INTO t1 VALUES("0059", "1", "2006-01-06 12:37:50"); +select * from t1 r1 +where (r1.retailerID,(r1.changed)) in +(SELECT r2.retailerId,(max(changed)) from t1 r2 +group by r2.retailerId); +retailerID statusID changed +0026 2 2006-01-06 12:25:53 +0037 2 2006-01-06 12:25:53 +0048 1 2006-01-06 12:37:50 +0059 1 2006-01-06 12:37:50 +drop table t1; +create table t1(a int, primary key (a)); +insert into t1 values (10); +create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b)); +insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989'); +explain SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r +ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' + ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 +1 PRIMARY r const PRIMARY PRIMARY 4 const 1 +2 SUBQUERY t2 range b b 40 NULL 2 Using where +SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r +ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' + ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; +a a b +10 3 35989 +explain SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r +ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' + ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 +1 PRIMARY r const PRIMARY PRIMARY 4 const 1 +2 SUBQUERY t2 range b b 40 NULL 2 Using index condition +SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r +ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' + ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; +a a b +10 1 359 +drop table t1,t2; +CREATE TABLE t1 ( +field1 int NOT NULL, +field2 int NOT NULL, +field3 int NOT NULL, +PRIMARY KEY (field1,field2,field3) +); +CREATE TABLE t2 ( +fieldA int NOT NULL, +fieldB int NOT NULL, +PRIMARY KEY (fieldA,fieldB) +); +INSERT INTO t1 VALUES +(1,1,1), (1,1,2), (1,2,1), (1,2,2), (1,2,3), (1,3,1); +INSERT INTO t2 VALUES (1,1), (1,2), (1,3); +SELECT field1, field2, COUNT(*) +FROM t1 GROUP BY field1, field2; +field1 field2 COUNT(*) +1 1 2 +1 2 3 +1 3 1 +SELECT field1, field2 +FROM t1 +GROUP BY field1, field2 +HAVING COUNT(*) >= ALL (SELECT fieldB +FROM t2 WHERE fieldA = field1); +field1 field2 +1 2 +SELECT field1, field2 +FROM t1 +GROUP BY field1, field2 +HAVING COUNT(*) < ANY (SELECT fieldB +FROM t2 WHERE fieldA = field1); +field1 field2 +1 1 +1 3 +DROP TABLE t1, t2; +CREATE TABLE t1(a int, INDEX (a)); +INSERT INTO t1 VALUES (1), (3), (5), (7); +INSERT INTO t1 VALUES (NULL); +CREATE TABLE t2(a int); +INSERT INTO t2 VALUES (1),(2),(3); +EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 +2 SUBQUERY t1 index_subquery a a 5 func 2 Using index; Full scan on NULL key +SELECT a, a IN (SELECT a FROM t1) FROM t2; +a a IN (SELECT a FROM t1) +1 1 +2 NULL +3 1 +DROP TABLE t1,t2; +CREATE TABLE t1 (a DATETIME); +INSERT INTO t1 VALUES ('1998-09-23'), ('2003-03-25'); +CREATE TABLE t2 AS SELECT +(SELECT a FROM t1 WHERE a < '2000-01-01') AS sub_a +FROM t1 WHERE a > '2000-01-01'; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `sub_a` datetime DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +CREATE TABLE t3 AS (SELECT a FROM t1 WHERE a < '2000-01-01') UNION (SELECT a FROM t1 WHERE a > '2000-01-01'); +SHOW CREATE TABLE t3; +Table Create Table +t3 CREATE TABLE `t3` ( + `a` datetime DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1,t2,t3; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (1), (2); +SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) > 0; +a +SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) IS NULL; +a +1 +2 +EXPLAIN SELECT a FROM t1 WHERE (SELECT 1 FROM DUAL WHERE 1=0) IS NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +DROP TABLE t1; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (2), (4), (1), (3); +CREATE TABLE t2 (b int, c int); +INSERT INTO t2 VALUES +(2,1), (1,3), (2,1), (4,4), (2,2), (1,4); +SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 2 ); +a +2 +4 +1 +3 +SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 1); +ERROR 21000: Subquery returns more than 1 row +SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 2), a; +a +1 +2 +3 +4 +SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 1), a; +ERROR 21000: Subquery returns more than 1 row +SELECT b, MAX(c) FROM t2 GROUP BY b, (SELECT c FROM t2 WHERE b > 2); +b MAX(c) +1 4 +2 2 +4 4 +SELECT b, MAX(c) FROM t2 GROUP BY b, (SELECT c FROM t2 WHERE b > 1); +ERROR 21000: Subquery returns more than 1 row +SELECT a FROM t1 GROUP BY a +HAVING IFNULL((SELECT b FROM t2 WHERE b > 2), +(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3; +a +1 +2 +3 +4 +SELECT a FROM t1 GROUP BY a +HAVING IFNULL((SELECT b FROM t2 WHERE b > 1), +(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3; +ERROR 21000: Subquery returns more than 1 row +SELECT a FROM t1 GROUP BY a +HAVING IFNULL((SELECT b FROM t2 WHERE b > 4), +(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3; +a +4 +SELECT a FROM t1 GROUP BY a +HAVING IFNULL((SELECT b FROM t2 WHERE b > 4), +(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b)) > 3; +ERROR 21000: Subquery returns more than 1 row +SELECT a FROM t1 +ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 2), +(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)); +a +1 +2 +3 +4 +SELECT a FROM t1 +ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 1), +(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b)); +ERROR 21000: Subquery returns more than 1 row +SELECT a FROM t1 +ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 4), +(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)); +a +1 +2 +3 +4 +SELECT a FROM t1 +ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 4), +(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b)); +ERROR 21000: Subquery returns more than 1 row +DROP TABLE t1,t2; +create table t1 (df decimal(5,1)); +insert into t1 values(1.1); +insert into t1 values(2.2); +select * from t1 where df <= all (select avg(df) from t1 group by df); +df +1.1 +select * from t1 where df >= all (select avg(df) from t1 group by df); +df +2.2 +drop table t1; +create table t1 (df decimal(5,1)); +insert into t1 values(1.1); +select 1.1 * exists(select * from t1); +1.1 * exists(select * from t1) +1.1 +drop table t1; +CREATE TABLE t1 ( +grp int(11) default NULL, +a decimal(10,2) default NULL); +insert into t1 values (1, 1), (2, 2), (2, 3), (3, 4), (3, 5), (3, 6), (NULL, NULL); +select * from t1; +grp a +1 1.00 +2 2.00 +2 3.00 +3 4.00 +3 5.00 +3 6.00 +NULL NULL +select min(a) from t1 group by grp; +min(a) +NULL +1.00 +2.00 +4.00 +drop table t1; +CREATE table t1 ( c1 integer ); +INSERT INTO t1 VALUES ( 1 ); +INSERT INTO t1 VALUES ( 2 ); +INSERT INTO t1 VALUES ( 3 ); +CREATE TABLE t2 ( c2 integer ); +INSERT INTO t2 VALUES ( 1 ); +INSERT INTO t2 VALUES ( 4 ); +INSERT INTO t2 VALUES ( 5 ); +SELECT * FROM t1 LEFT JOIN t2 ON c1 = c2 WHERE c2 IN (1); +c1 c2 +1 1 +SELECT * FROM t1 LEFT JOIN t2 ON c1 = c2 +WHERE c2 IN ( SELECT c2 FROM t2 WHERE c2 IN ( 1 ) ); +c1 c2 +1 1 +DROP TABLE t1,t2; +CREATE TABLE t1 ( c1 integer ); +INSERT INTO t1 VALUES ( 1 ); +INSERT INTO t1 VALUES ( 2 ); +INSERT INTO t1 VALUES ( 3 ); +INSERT INTO t1 VALUES ( 6 ); +CREATE TABLE t2 ( c2 integer ); +INSERT INTO t2 VALUES ( 1 ); +INSERT INTO t2 VALUES ( 4 ); +INSERT INTO t2 VALUES ( 5 ); +INSERT INTO t2 VALUES ( 6 ); +CREATE TABLE t3 ( c3 integer ); +INSERT INTO t3 VALUES ( 7 ); +INSERT INTO t3 VALUES ( 8 ); +SELECT c1,c2 FROM t1 LEFT JOIN t2 ON c1 = c2 +WHERE EXISTS (SELECT c3 FROM t3 WHERE c2 IS NULL ); +c1 c2 +2 NULL +3 NULL +DROP TABLE t1,t2,t3; +CREATE TABLE `t1` ( +`itemid` bigint(20) unsigned NOT NULL auto_increment, +`sessionid` bigint(20) unsigned default NULL, +`time` int(10) unsigned NOT NULL default '0', +`type` set('A','D','E','F','G','I','L','N','U') collate latin1_general_ci NOT +NULL default '', +`data` text collate latin1_general_ci NOT NULL, +PRIMARY KEY (`itemid`) +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; +INSERT INTO `t1` VALUES (1, 1, 1, 'D', ''); +CREATE TABLE `t2` ( +`sessionid` bigint(20) unsigned NOT NULL auto_increment, +`pid` int(10) unsigned NOT NULL default '0', +`date` int(10) unsigned NOT NULL default '0', +`ip` varchar(15) collate latin1_general_ci NOT NULL default '', +PRIMARY KEY (`sessionid`) +) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; +INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1'); +SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessionid WHERE e.sessionid = ( SELECT sessionid FROM t2 ORDER BY sessionid DESC LIMIT 1 ) GROUP BY s.ip HAVING count( e.itemid ) >0 LIMIT 0 , 30; +ip count( e.itemid ) +10.10.10.1 1 +drop tables t1,t2; +CREATE TABLE t1 (EMPNUM CHAR(3)); +CREATE TABLE t2 (EMPNUM CHAR(3) ); +INSERT INTO t1 VALUES ('E1'),('E2'); +INSERT INTO t2 VALUES ('E1'); +DELETE FROM t1 +WHERE t1.EMPNUM NOT IN +(SELECT t2.EMPNUM +FROM t2 +WHERE t1.EMPNUM = t2.EMPNUM); +select * from t1; +EMPNUM +E1 +DROP TABLE t1,t2; +CREATE TABLE t1(select_id BIGINT, values_id BIGINT); +INSERT INTO t1 VALUES (1, 1); +CREATE TABLE t2 (select_id BIGINT, values_id BIGINT, +PRIMARY KEY(select_id,values_id)); +INSERT INTO t2 VALUES (0, 1), (0, 2), (0, 3), (1, 5); +SELECT values_id FROM t1 +WHERE values_id IN (SELECT values_id FROM t2 +WHERE select_id IN (1, 0)); +values_id +1 +SELECT values_id FROM t1 +WHERE values_id IN (SELECT values_id FROM t2 +WHERE select_id BETWEEN 0 AND 1); +values_id +1 +SELECT values_id FROM t1 +WHERE values_id IN (SELECT values_id FROM t2 +WHERE select_id = 0 OR select_id = 1); +values_id +1 +DROP TABLE t1, t2; +create table t1 (fld enum('0','1')); +insert into t1 values ('1'); +select * from (select max(fld) from t1) as foo; +max(fld) +1 +drop table t1; +CREATE TABLE t1 (a int, b int); +CREATE TABLE t2 (c int, d int); +CREATE TABLE t3 (e int); +INSERT INTO t1 VALUES +(1,10), (2,10), (1,20), (2,20), (3,20), (2,30), (4,40); +INSERT INTO t2 VALUES +(2,10), (2,20), (4,10), (5,10), (3,20), (2,40); +INSERT INTO t3 VALUES (10), (30), (10), (20) ; +SELECT a, MAX(b), MIN(b) FROM t1 GROUP BY a; +a MAX(b) MIN(b) +1 20 10 +2 30 10 +3 20 20 +4 40 40 +SELECT * FROM t2; +c d +2 10 +2 20 +4 10 +5 10 +3 20 +2 40 +SELECT * FROM t3; +e +10 +30 +10 +20 +SELECT a FROM t1 GROUP BY a +HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>20); +a +2 +4 +SELECT a FROM t1 GROUP BY a +HAVING a IN (SELECT c FROM t2 WHERE MAX(b)<d); +a +2 +SELECT a FROM t1 GROUP BY a +HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>d); +a +2 +4 +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 +SELECT a FROM t1 GROUP BY a +HAVING a IN (SELECT c FROM t2 +WHERE EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e <= d)); +a +2 +3 +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 +SELECT a FROM t1 GROUP BY a +HAVING a IN (SELECT c FROM t2 +WHERE EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e < d)); +a +2 +SELECT a FROM t1 GROUP BY a +HAVING a IN (SELECT c FROM t2 +WHERE MIN(b) < d AND +EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e <= d)); +a +2 +SELECT a, SUM(a) FROM t1 GROUP BY a; +a SUM(a) +1 2 +2 6 +3 3 +4 4 +SELECT a FROM t1 +WHERE EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) = c) GROUP BY a; +a +3 +4 +SELECT a FROM t1 GROUP BY a +HAVING EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) = c); +a +1 +3 +4 +SELECT a FROM t1 +WHERE a < 3 AND +EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) != c) GROUP BY a; +a +1 +2 +SELECT a FROM t1 +WHERE a < 3 AND +EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) != c); +a +1 +2 +1 +2 +2 +SELECT t1.a FROM t1 GROUP BY t1.a +HAVING t1.a < ALL(SELECT t2.c FROM t2 GROUP BY t2.c +HAVING EXISTS(SELECT t3.e FROM t3 GROUP BY t3.e +HAVING SUM(t1.a+t2.c) < t3.e/4)); +a +1 +2 +SELECT t1.a FROM t1 GROUP BY t1.a +HAVING t1.a > ALL(SELECT t2.c FROM t2 +WHERE EXISTS(SELECT t3.e FROM t3 GROUP BY t3.e +HAVING SUM(t1.a+t2.c) < t3.e/4)); +a +4 +SELECT t1.a FROM t1 GROUP BY t1.a +HAVING t1.a > ALL(SELECT t2.c FROM t2 +WHERE EXISTS(SELECT t3.e FROM t3 +WHERE SUM(t1.a+t2.c) < t3.e/4)); +ERROR HY000: Invalid use of group function +SELECT t1.a from t1 GROUP BY t1.a HAVING AVG(SUM(t1.b)) > 20; +ERROR HY000: Invalid use of group function +SELECT t1.a FROM t1 GROUP BY t1.a +HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c +HAVING AVG(t2.c+SUM(t1.b)) > 20); +a +2 +3 +4 +SELECT t1.a FROM t1 GROUP BY t1.a +HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c +HAVING AVG(SUM(t1.b)) > 20); +a +2 +4 +SELECT t1.a, SUM(b) AS sum FROM t1 GROUP BY t1.a +HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c +HAVING t2.c+sum > 20); +a sum +2 60 +3 20 +4 40 +DROP TABLE t1,t2,t3; +CREATE TABLE t1 (a varchar(5), b varchar(10)); +INSERT INTO t1 VALUES +('AAA', 5), ('BBB', 4), ('BBB', 1), ('CCC', 2), +('CCC', 7), ('AAA', 2), ('AAA', 4), ('BBB', 3), ('AAA', 8); +SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a); +a b +BBB 4 +CCC 7 +AAA 8 +EXPLAIN +SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 9 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 21 test.t1.a,test.t1.b 1 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 9 Using temporary +ALTER TABLE t1 ADD INDEX(a); +SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a); +a b +BBB 4 +CCC 7 +AAA 8 +EXPLAIN +SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL a NULL NULL NULL 9 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 21 test.t1.a,test.t1.b 1 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 9 Using temporary +DROP TABLE t1; +create table t1( f1 int,f2 int); +insert into t1 values (1,1),(2,2); +select tt.t from (select 'crash1' as t, f2 from t1) as tt left join t1 on tt.t = 'crash2' and tt.f2 = t1.f2 where tt.t = 'crash1'; +t +crash1 +crash1 +drop table t1; +create table t1 (c int, key(c)); +insert into t1 values (1142477582), (1142455969); +create table t2 (a int, b int); +insert into t2 values (2, 1), (1, 0); +delete from t1 where c <= 1140006215 and (select b from t2 where a = 2) = 1; +drop table t1, t2; +CREATE TABLE t1 (a INT); +CREATE VIEW v1 AS SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1); +ERROR 42S22: Unknown column 'no_such_column' in 'where clause' +CREATE VIEW v2 AS SELECT * FROM t1 WHERE no_such_column = (SELECT 1); +ERROR 42S22: Unknown column 'no_such_column' in 'where clause' +SELECT * FROM t1 WHERE no_such_column = ANY (SELECT 1); +ERROR 42S22: Unknown column 'no_such_column' in 'IN/ALL/ANY subquery' +DROP TABLE t1; +create table t1 (i int, j bigint); +insert into t1 values (1, 2), (2, 2), (3, 2); +select * from (select min(i) from t1 where j=(select * from (select min(j) from t1) t2)) t3; +min(i) +1 +drop table t1; +CREATE TABLE t1 (i BIGINT UNSIGNED); +INSERT INTO t1 VALUES (10000000000000000000); +INSERT INTO t1 VALUES (1); +CREATE TABLE t2 (i BIGINT UNSIGNED); +INSERT INTO t2 VALUES (10000000000000000000); +INSERT INTO t2 VALUES (1); +/* simple test */ +SELECT t1.i FROM t1 JOIN t2 ON t1.i = t2.i; +i +10000000000000000000 +1 +/* subquery test */ +SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2); +i +10000000000000000000 +/* subquery test with cast*/ +SELECT t1.i FROM t1 WHERE t1.i = CAST((SELECT MAX(i) FROM t2) AS UNSIGNED); +i +10000000000000000000 +DROP TABLE t1; +DROP TABLE t2; +CREATE TABLE t1 ( +id bigint(20) unsigned NOT NULL auto_increment, +name varchar(255) NOT NULL, +PRIMARY KEY (id) +); +INSERT INTO t1 VALUES +(1, 'Balazs'), (2, 'Joe'), (3, 'Frank'); +CREATE TABLE t2 ( +id bigint(20) unsigned NOT NULL auto_increment, +mid bigint(20) unsigned NOT NULL, +date date NOT NULL, +PRIMARY KEY (id) +); +INSERT INTO t2 VALUES +(1, 1, '2006-03-30'), (2, 2, '2006-04-06'), (3, 3, '2006-04-13'), +(4, 2, '2006-04-20'), (5, 1, '2006-05-01'); +SELECT *, +(SELECT date FROM t2 WHERE mid = t1.id +ORDER BY date DESC LIMIT 0, 1) AS date_last, +(SELECT date FROM t2 WHERE mid = t1.id +ORDER BY date DESC LIMIT 3, 1) AS date_next_to_last +FROM t1; +id name date_last date_next_to_last +1 Balazs 2006-05-01 NULL +2 Joe 2006-04-20 NULL +3 Frank 2006-04-13 NULL +SELECT *, +(SELECT COUNT(*) FROM t2 WHERE mid = t1.id +ORDER BY date DESC LIMIT 1, 1) AS date_count +FROM t1; +id name date_count +1 Balazs NULL +2 Joe NULL +3 Frank NULL +SELECT *, +(SELECT date FROM t2 WHERE mid = t1.id +ORDER BY date DESC LIMIT 0, 1) AS date_last, +(SELECT date FROM t2 WHERE mid = t1.id +ORDER BY date DESC LIMIT 1, 1) AS date_next_to_last +FROM t1; +id name date_last date_next_to_last +1 Balazs 2006-05-01 2006-03-30 +2 Joe 2006-04-20 2006-04-06 +3 Frank 2006-04-13 NULL +DROP TABLE t1,t2; +CREATE TABLE t1 ( +i1 int(11) NOT NULL default '0', +i2 int(11) NOT NULL default '0', +t datetime NOT NULL default '0000-00-00 00:00:00', +PRIMARY KEY (i1,i2,t) +); +INSERT INTO t1 VALUES +(24,1,'2005-03-03 16:31:31'),(24,1,'2005-05-27 12:40:07'), +(24,1,'2005-05-27 12:40:08'),(24,1,'2005-05-27 12:40:10'), +(24,1,'2005-05-27 12:40:25'),(24,1,'2005-05-27 12:40:30'), +(24,2,'2005-03-03 13:43:05'),(24,2,'2005-03-03 16:23:31'), +(24,2,'2005-03-03 16:31:30'),(24,2,'2005-05-27 12:37:02'), +(24,2,'2005-05-27 12:40:06'); +CREATE TABLE t2 ( +i1 int(11) NOT NULL default '0', +i2 int(11) NOT NULL default '0', +t datetime default NULL, +PRIMARY KEY (i1) +); +INSERT INTO t2 VALUES (24,1,'2006-06-20 12:29:40'); +EXPLAIN +SELECT * FROM t1,t2 +WHERE t1.t = (SELECT t1.t FROM t1 +WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 +ORDER BY t1.t DESC LIMIT 1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 system NULL NULL NULL NULL 1 +1 PRIMARY t1 index NULL PRIMARY 16 NULL 11 Using where; Using index +2 SUBQUERY t1 range PRIMARY PRIMARY 16 NULL 5 Using where; Using index +SELECT * FROM t1,t2 +WHERE t1.t = (SELECT t1.t FROM t1 +WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 +ORDER BY t1.t DESC LIMIT 1); +i1 i2 t i1 i2 t +24 1 2005-05-27 12:40:30 24 1 2006-06-20 12:29:40 +DROP TABLE t1, t2; +CREATE TABLE t1 (i INT); +(SELECT i FROM t1) UNION (SELECT i FROM t1); +i +SELECT sql_no_cache * FROM t1 WHERE NOT EXISTS +( +(SELECT i FROM t1) UNION +(SELECT i FROM t1) +); +i +SELECT * FROM t1 +WHERE NOT EXISTS (((SELECT i FROM t1) UNION (SELECT i FROM t1))); +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 'UNION (SELECT i FROM t1)))' at line 2 +explain select ((select t11.i from t1 t11) union (select t12.i from t1 t12)) +from t1; +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 'union (select t12.i from t1 t12)) +from t1' at line 1 +explain select * from t1 where not exists +((select t11.i from t1 t11) union (select t12.i from t1 t12)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +3 UNION NULL NULL NULL NULL NULL NULL NULL no matching row in const table +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b)); +insert into t1 (a) values (FLOOR(rand() * 100)); +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +insert into t1 (a) select FLOOR(rand() * 100) from t1; +SELECT a, +(SELECT REPEAT(' ',250) FROM t1 i1 +WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a +FROM t1 ORDER BY a LIMIT 5; +a a +0 NULL +0 NULL +0 NULL +0 NULL +0 NULL +DROP TABLE t1; +CREATE TABLE t1 (a INT, b INT); +CREATE TABLE t2 (a INT); +INSERT INTO t2 values (1); +INSERT INTO t1 VALUES (1,1),(1,2),(2,3),(3,4); +SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a; +(SELECT COUNT(DISTINCT t1.b) from t2) +2 +1 +1 +SELECT (SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) +FROM t1 GROUP BY t1.a; +(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) +2 +1 +1 +SELECT COUNT(DISTINCT t1.b), (SELECT COUNT(DISTINCT t1.b)) FROM t1 GROUP BY t1.a; +COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b)) +2 2 +1 1 +1 1 +SELECT COUNT(DISTINCT t1.b), +(SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) +FROM t1 GROUP BY t1.a; +COUNT(DISTINCT t1.b) (SELECT COUNT(DISTINCT t1.b) union select 1 from DUAL where 12 < 3) +2 2 +1 1 +1 1 +SELECT ( +SELECT ( +SELECT COUNT(DISTINCT t1.b) +) +) +FROM t1 GROUP BY t1.a; +( +SELECT ( +SELECT COUNT(DISTINCT t1.b) +) +) +2 +1 +1 +SELECT ( +SELECT ( +SELECT ( +SELECT COUNT(DISTINCT t1.b) +) +) +FROM t1 GROUP BY t1.a LIMIT 1) +FROM t1 t2 +GROUP BY t2.a; +( +SELECT ( +SELECT ( +SELECT COUNT(DISTINCT t1.b) +) +) +FROM t1 GROUP BY t1.a LIMIT 1) +2 +2 +2 +DROP TABLE t1,t2; +CREATE TABLE t1 (a int, b int, PRIMARY KEY (b)); +CREATE TABLE t2 (x int auto_increment, y int, z int, +PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b)); +create table t3 (a int); +insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +insert into t1 select RAND()*1000, A.a + 10*(B.a+10*(C.a+10*D.a)) +from t3 A, t3 B, t3 C, t3 D where D.a<3; +insert into t2(y,z) select t1.b, RAND()*1000 from t1, t3; +SET SESSION sort_buffer_size = 32 * 1024; +SELECT SQL_NO_CACHE COUNT(*) +FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c +FROM t1) t; +COUNT(*) +3000 +SET SESSION sort_buffer_size = 8 * 1024 * 1024; +SELECT SQL_NO_CACHE COUNT(*) +FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c +FROM t1) t; +COUNT(*) +3000 +DROP TABLE t1,t2,t3; +CREATE TABLE t1 (id char(4) PRIMARY KEY, c int); +CREATE TABLE t2 (c int); +INSERT INTO t1 VALUES ('aa', 1); +INSERT INTO t2 VALUES (1); +SELECT * FROM t1 +WHERE EXISTS (SELECT c FROM t2 WHERE c=1 +UNION +SELECT c from t2 WHERE c=t1.c); +id c +aa 1 +INSERT INTO t1 VALUES ('bb', 2), ('cc', 3), ('dd',1); +SELECT * FROM t1 +WHERE EXISTS (SELECT c FROM t2 WHERE c=1 +UNION +SELECT c from t2 WHERE c=t1.c); +id c +aa 1 +bb 2 +cc 3 +dd 1 +INSERT INTO t2 VALUES (2); +CREATE TABLE t3 (c int); +INSERT INTO t3 VALUES (1); +SELECT * FROM t1 +WHERE EXISTS (SELECT t2.c FROM t2 JOIN t3 ON t2.c=t3.c WHERE t2.c=1 +UNION +SELECT c from t2 WHERE c=t1.c); +id c +aa 1 +bb 2 +cc 3 +dd 1 +DROP TABLE t1,t2,t3; +CREATE TABLE t1(f1 int); +CREATE TABLE t2(f2 int, f21 int, f3 timestamp); +INSERT INTO t1 VALUES (1),(1),(2),(2); +INSERT INTO t2 VALUES (1,1,"2004-02-29 11:11:11"), (2,2,"2004-02-29 11:11:11"); +SELECT ((SELECT f2 FROM t2 WHERE f21=f1 LIMIT 1) * COUNT(f1)) AS sq FROM t1 GROUP BY f1; +sq +2 +4 +SELECT (SELECT SUM(1) FROM t2 ttt GROUP BY t2.f3 LIMIT 1) AS tt FROM t2; +tt +2 +2 +PREPARE stmt1 FROM 'SELECT ((SELECT f2 FROM t2 WHERE f21=f1 LIMIT 1) * COUNT(f1)) AS sq FROM t1 GROUP BY f1'; +EXECUTE stmt1; +sq +2 +4 +EXECUTE stmt1; +sq +2 +4 +DEALLOCATE PREPARE stmt1; +SELECT f2, AVG(f21), +(SELECT t.f3 FROM t2 AS t WHERE t2.f2=t.f2 AND t.f3=MAX(t2.f3)) AS test +FROM t2 GROUP BY f2; +f2 AVG(f21) test +1 1.0000 2004-02-29 11:11:11 +2 2.0000 2004-02-29 11:11:11 +DROP TABLE t1,t2; +CREATE TABLE t1 (a int, b INT, c CHAR(10) NOT NULL); +INSERT INTO t1 VALUES +(1,1,'a'), (1,2,'b'), (1,3,'c'), (1,4,'d'), (1,5,'e'), +(2,1,'f'), (2,2,'g'), (2,3,'h'), (3,4,'i'), (3,3,'j'), +(3,2,'k'), (3,1,'l'), (1,9,'m'); +SELECT a, MAX(b), +(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b)) AS test +FROM t1 GROUP BY a; +a MAX(b) test +1 9 m +2 3 h +3 4 i +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +DROP TABLE IF EXISTS t1xt2; +CREATE TABLE t1 ( +id_1 int(5) NOT NULL, +t varchar(4) DEFAULT NULL +); +CREATE TABLE t2 ( +id_2 int(5) NOT NULL, +t varchar(4) DEFAULT NULL +); +CREATE TABLE t1xt2 ( +id_1 int(5) NOT NULL, +id_2 int(5) NOT NULL +); +INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'); +INSERT INTO t2 VALUES (2, 'bb'), (3, 'cc'), (4, 'dd'), (12, 'aa'); +INSERT INTO t1xt2 VALUES (2, 2), (3, 3), (4, 4); +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)); +id_1 +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))); +id_1 +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)))); +id_1 +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 NOT IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)); +id_1 +1 +2 +3 +4 +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 NOT IN ((SELECT t1xt2.id_2 FROM t1xt2 where t1.id_1 = t1xt2.id_1))); +id_1 +1 +2 +3 +4 +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 NOT IN (((SELECT t1xt2.id_2 FROM t1xt2 where t1.id_1 = t1xt2.id_1)))); +id_1 +1 +2 +3 +4 +insert INTO t1xt2 VALUES (1, 12); +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)); +id_1 +1 +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))); +id_1 +1 +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)))); +id_1 +1 +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 NOT IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)); +id_1 +2 +3 +4 +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 NOT IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))); +id_1 +2 +3 +4 +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 NOT IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)))); +id_1 +2 +3 +4 +insert INTO t1xt2 VALUES (2, 12); +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)); +id_1 +1 +2 +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))); +id_1 +1 +2 +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)))); +id_1 +1 +2 +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 NOT IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)); +id_1 +3 +4 +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 NOT IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))); +id_1 +3 +4 +SELECT DISTINCT t1.id_1 FROM t1 WHERE +(12 NOT IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)))); +id_1 +3 +4 +DROP TABLE t1; +DROP TABLE t2; +DROP TABLE t1xt2; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (3), (1), (2); +SELECT 'this is ' 'a test.' AS col1, a AS col2 FROM t1; +col1 col2 +this is a test. 3 +this is a test. 1 +this is a test. 2 +SELECT * FROM (SELECT 'this is ' 'a test.' AS col1, a AS t2 FROM t1) t; +col1 t2 +this is a test. 3 +this is a test. 1 +this is a test. 2 +DROP table t1; +CREATE TABLE t1 (a int, b int); +CREATE TABLE t2 (m int, n int); +INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4); +INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44); +SELECT COUNT(*), a, +(SELECT m FROM t2 WHERE m = count(*) LIMIT 1) +FROM t1 GROUP BY a; +COUNT(*) a (SELECT m FROM t2 WHERE m = count(*) LIMIT 1) +2 2 2 +3 3 3 +1 4 1 +SELECT COUNT(*), a, +(SELECT MIN(m) FROM t2 WHERE m = count(*)) +FROM t1 GROUP BY a; +COUNT(*) a (SELECT MIN(m) FROM t2 WHERE m = count(*)) +2 2 2 +3 3 3 +1 4 1 +SELECT COUNT(*), a +FROM t1 GROUP BY a +HAVING (SELECT MIN(m) FROM t2 WHERE m = count(*)) > 1; +COUNT(*) a +2 2 +3 3 +DROP TABLE t1,t2; +CREATE TABLE t1 (a int, b int); +CREATE TABLE t2 (m int, n int); +INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4); +INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44); +SELECT COUNT(*) c, a, +(SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a) +FROM t1 GROUP BY a; +c a (SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a) +2 2 2 +3 3 3 +1 4 1,1 +SELECT COUNT(*) c, a, +(SELECT GROUP_CONCAT(COUNT(a)+1) FROM t2 WHERE m = a) +FROM t1 GROUP BY a; +c a (SELECT GROUP_CONCAT(COUNT(a)+1) FROM t2 WHERE m = a) +2 2 3 +3 3 4 +1 4 2,2 +DROP table t1,t2; +CREATE TABLE t1 (a int, b INT, d INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b)); +INSERT INTO t1 VALUES (1,1,0,'a'), (1,2,0,'b'), (1,3,0,'c'), (1,4,0,'d'), +(1,5,0,'e'), (2,1,0,'f'), (2,2,0,'g'), (2,3,0,'h'), (3,4,0,'i'), (3,3,0,'j'), +(3,2,0,'k'), (3,1,0,'l'), (1,9,0,'m'), (1,0,10,'n'), (2,0,5,'o'), (3,0,7,'p'); +SELECT a, MAX(b), +(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b + 0)) as test +FROM t1 GROUP BY a; +a MAX(b) test +1 9 m +2 3 h +3 4 i +SELECT a x, MAX(b), +(SELECT t.c FROM t1 AS t WHERE x=t.a AND t.b=MAX(t1.b + 0)) as test +FROM t1 GROUP BY a; +x MAX(b) test +1 9 m +2 3 h +3 4 i +SELECT a, AVG(b), +(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=AVG(t1.b)) AS test +FROM t1 WHERE t1.d=0 GROUP BY a; +a AVG(b) test +1 4.0000 d +2 2.0000 g +3 2.5000 NULL +SELECT tt.a, +(SELECT (SELECT c FROM t1 as t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a) +LIMIT 1) FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test +FROM t1 as tt; +a test +1 n +1 n +1 n +1 n +1 n +1 n +1 n +2 o +2 o +2 o +2 o +3 p +3 p +3 p +3 p +3 p +SELECT tt.a, +(SELECT (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a) +LIMIT 1) +FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test +FROM t1 as tt GROUP BY tt.a; +a test +1 n +2 o +3 p +SELECT tt.a, MAX( +(SELECT (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a) +LIMIT 1) +FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1)) as test +FROM t1 as tt GROUP BY tt.a; +a test +1 n +2 o +3 p +DROP TABLE t1; +CREATE TABLE t1 (a int, b int); +INSERT INTO t1 VALUES (2,22),(1,11),(2,22); +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 0 GROUP BY a; +a +1 +2 +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 1 GROUP BY a; +a +SELECT a FROM t1 t0 +WHERE (SELECT COUNT(t0.b) FROM t1 t WHERE t.b>20) GROUP BY a; +a +1 +2 +SET @@sql_mode='ansi'; +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 0 GROUP BY a; +ERROR HY000: Invalid use of group function +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 1 GROUP BY a; +ERROR HY000: Invalid use of group function +SELECT a FROM t1 t0 +WHERE (SELECT COUNT(t0.b) FROM t1 t WHERE t.b>20) GROUP BY a; +ERROR HY000: Invalid use of group function +SET @@sql_mode=default; +DROP TABLE t1; +CREATE TABLE t1 (a INT); +INSERT INTO t1 values (1),(1),(1),(1); +CREATE TABLE t2 (x INT); +INSERT INTO t1 values (1000),(1001),(1002); +SELECT SUM( (SELECT COUNT(a) FROM t2) ) FROM t1; +ERROR HY000: Invalid use of group function +SELECT SUM( (SELECT SUM(COUNT(a)) FROM t2) ) FROM t1; +ERROR HY000: Invalid use of group function +SELECT COUNT(1) FROM DUAL; +COUNT(1) +1 +SELECT SUM( (SELECT AVG( (SELECT t1.a FROM t2) ) FROM DUAL) ) FROM t1; +ERROR HY000: Invalid use of group function +SELECT +SUM( (SELECT AVG( (SELECT COUNT(*) FROM t1 t HAVING t1.a < 12) ) FROM t2) ) +FROM t1; +ERROR HY000: Invalid use of group function +SELECT t1.a as XXA, +SUM( (SELECT AVG( (SELECT COUNT(*) FROM t1 t HAVING XXA < 12) ) FROM t2) ) +FROM t1; +ERROR HY000: Invalid use of group function +DROP TABLE t1,t2; +CREATE TABLE t1 (a int, b int, KEY (a)); +INSERT INTO t1 VALUES (1,1),(2,1); +EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ref a a 5 const 1 Using where; Using index +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort +DROP TABLE t1; +CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)); +INSERT INTO t1 VALUES +(3,'FL'), (2,'GA'), (4,'FL'), (1,'GA'), (5,'NY'), (7,'FL'), (6,'NY'); +CREATE TABLE t2 (id int NOT NULL, INDEX idx(id)); +INSERT INTO t2 VALUES (7), (5), (1), (3); +SELECT id, st FROM t1 +WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id); +id st +3 FL +1 GA +7 FL +SELECT id, st FROM t1 +WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id) +GROUP BY id; +id st +1 GA +3 FL +7 FL +SELECT id, st FROM t1 +WHERE st IN ('GA','FL') AND NOT EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id); +id st +2 GA +4 FL +SELECT id, st FROM t1 +WHERE st IN ('GA','FL') AND NOT EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id) +GROUP BY id; +id st +2 GA +4 FL +DROP TABLE t1,t2; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (1), (2); +EXPLAIN EXTENDED +SELECT * FROM (SELECT count(*) FROM t1 GROUP BY a) as res; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00 +2 DERIVED t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary; Using filesort +Warnings: +Note 1003 select `res`.`count(*)` AS `count(*)` from (select count(0) AS `count(*)` from `test`.`t1` group by `test`.`t1`.`a`) `res` +DROP TABLE t1; +CREATE TABLE t1 ( +a varchar(255) default NULL, +b timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, +INDEX idx(a,b) +); +CREATE TABLE t2 ( +a varchar(255) default NULL +); +INSERT INTO t1 VALUES ('abcdefghijk','2007-05-07 06:00:24'); +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO `t1` VALUES ('asdf','2007-02-08 01:11:26'); +INSERT INTO `t2` VALUES ('abcdefghijk'); +INSERT INTO `t2` VALUES ('asdf'); +SET session sort_buffer_size=8192; +SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.a ORDER BY t1.b LIMIT 1) AS d1 FROM t2; +d1 +1 +1 +DROP TABLE t1,t2; +CREATE TABLE t1 (a INTEGER, b INTEGER); +CREATE TABLE t2 (x INTEGER); +INSERT INTO t1 VALUES (1,11), (2,22), (2,22); +INSERT INTO t2 VALUES (1), (2); +SELECT a, COUNT(b), (SELECT COUNT(b) FROM t2) FROM t1 GROUP BY a; +ERROR 21000: Subquery returns more than 1 row +SELECT a, COUNT(b), (SELECT COUNT(b)+0 FROM t2) FROM t1 GROUP BY a; +ERROR 21000: Subquery returns more than 1 row +SELECT (SELECT SUM(t1.a)/AVG(t2.x) FROM t2) FROM t1; +(SELECT SUM(t1.a)/AVG(t2.x) FROM t2) +3.3333 +DROP TABLE t1,t2; +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (1, 2), (1,3), (1,4), (2,1), (2,2); +SELECT a1.a, COUNT(*) FROM t1 a1 WHERE a1.a = 1 +AND EXISTS( SELECT a2.a FROM t1 a2 WHERE a2.a = a1.a) +GROUP BY a1.a; +a COUNT(*) +1 3 +DROP TABLE t1; +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT); +INSERT INTO t1 VALUES (1),(2); +INSERT INTO t2 VALUES (1),(2); +SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=0) FROM t1; +(SELECT SUM(t1.a) FROM t2 WHERE a=0) +NULL +SELECT (SELECT SUM(t1.a) FROM t2 WHERE a!=0) FROM t1; +ERROR 21000: Subquery returns more than 1 row +SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=1) FROM t1; +(SELECT SUM(t1.a) FROM t2 WHERE a=1) +3 +DROP TABLE t1,t2; +CREATE TABLE t1 (a1 INT, a2 INT); +CREATE TABLE t2 (b1 INT, b2 INT); +INSERT INTO t1 VALUES (100, 200); +INSERT INTO t1 VALUES (101, 201); +INSERT INTO t2 VALUES (101, 201); +INSERT INTO t2 VALUES (103, 203); +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 +DROP TABLE t1, t2; +CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5)); +INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43); +SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1); +s1 s2 +SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1); +s1 s2 +CREATE INDEX I1 ON t1 (s1); +CREATE INDEX I2 ON t1 (s2); +SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1); +s1 s2 +SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1); +s1 s2 +TRUNCATE t1; +INSERT INTO t1 VALUES (0x41,0x41); +SELECT * FROM t1 WHERE s1 = (SELECT s2 FROM t1); +s1 s2 +DROP TABLE t1; +CREATE TABLE t1 (a1 VARBINARY(2) NOT NULL DEFAULT '0', PRIMARY KEY (a1)); +CREATE TABLE t2 (a2 BINARY(2) default '0', INDEX (a2)); +CREATE TABLE t3 (a3 BINARY(2) default '0'); +INSERT INTO t1 VALUES (1),(2),(3),(4); +INSERT INTO t2 VALUES (1),(2),(3); +INSERT INTO t3 VALUES (1),(2),(3); +SELECT LEFT(t2.a2, 1) FROM t2,t3 WHERE t3.a3=t2.a2; +LEFT(t2.a2, 1) +1 +2 +3 +SELECT t1.a1, t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2) FROM t1; +a1 t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2) +1 0 +2 0 +3 0 +4 0 +DROP TABLE t1,t2,t3; +CREATE TABLE t1 (a1 BINARY(3) PRIMARY KEY, b1 VARBINARY(3)); +CREATE TABLE t2 (a2 VARBINARY(3) PRIMARY KEY); +CREATE TABLE t3 (a3 VARBINARY(3) PRIMARY KEY); +INSERT INTO t1 VALUES (1,10), (2,20), (3,30), (4,40); +INSERT INTO t2 VALUES (2), (3), (4), (5); +INSERT INTO t3 VALUES (10), (20), (30); +SELECT LEFT(t1.a1,1) FROM t1,t3 WHERE t1.b1=t3.a3; +LEFT(t1.a1,1) +1 +2 +3 +SELECT a2 FROM t2 WHERE t2.a2 IN (SELECT t1.a1 FROM t1,t3 WHERE t1.b1=t3.a3); +a2 +DROP TABLE t1, t2, t3; +SET @save_optimizer_switch=@@optimizer_switch; +SET optimizer_switch='semijoin_with_cache=off'; +SET optimizer_switch='materialization=off'; +CREATE TABLE t1 (a CHAR(1), b VARCHAR(10)); +INSERT INTO t1 VALUES ('a', 'aa'); +INSERT INTO t1 VALUES ('a', 'aaa'); +SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1); +a b +CREATE INDEX I1 ON t1 (a); +CREATE INDEX I2 ON t1 (b); +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 I2 NULL NULL NULL 2 Using where +1 PRIMARY t1 ref I1 I1 2 test.t1.b 2 Using where; Using index; FirstMatch(t1) +SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1); +a b +CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10)); +INSERT INTO t2 SELECT * FROM t1; +CREATE INDEX I1 ON t2 (a); +CREATE INDEX I2 ON t2 (b); +EXPLAIN SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL I2 NULL NULL NULL 2 Using where +1 PRIMARY t2 ref I1 I1 4 test.t2.b 2 Using where; Using index; FirstMatch(t2) +SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2); +a b +EXPLAIN +SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL I2 NULL NULL NULL 2 Using where +1 PRIMARY t1 ref I1 I1 2 test.t1.b 2 Using where; Using index; FirstMatch(t1) +SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500); +a b +DROP TABLE t1,t2; +SET optimizer_switch= @save_optimizer_switch; +CREATE TABLE t1(a INT, b INT); +INSERT INTO t1 VALUES (1,1), (1,2), (2,3), (2,4); +EXPLAIN +SELECT a AS out_a, MIN(b) FROM t1 +WHERE b > (SELECT MIN(b) FROM t1 WHERE a = out_a) +GROUP BY a; +ERROR 42S22: Unknown column 'out_a' in 'where clause' +SELECT a AS out_a, MIN(b) FROM t1 +WHERE b > (SELECT MIN(b) FROM t1 WHERE a = out_a) +GROUP BY a; +ERROR 42S22: Unknown column 'out_a' in 'where clause' +EXPLAIN +SELECT a AS out_a, MIN(b) FROM t1 t1_outer +WHERE b > (SELECT MIN(b) FROM t1 WHERE a = t1_outer.a) +GROUP BY a; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1_outer ALL NULL NULL NULL NULL 4 Using where; Using temporary; Using filesort +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 4 Using where +SELECT a AS out_a, MIN(b) FROM t1 t1_outer +WHERE b > (SELECT MIN(b) FROM t1 WHERE a = t1_outer.a) +GROUP BY a; +out_a MIN(b) +1 2 +2 4 +DROP TABLE t1; +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (a INT); +INSERT INTO t1 VALUES (1),(2); +INSERT INTO t2 VALUES (1),(2); +SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); +2 +2 +2 +EXPLAIN EXTENDED +SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); +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 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00 +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1003 select 2 AS `2` from `test`.`t1` semi join (`test`.`t2`) where 1 +EXPLAIN EXTENDED +SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION +(SELECT 1 FROM t2 WHERE t1.a = t2.a)); +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 t2 ALL NULL NULL NULL NULL 2 100.00 Using where +3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 2 100.00 Using where +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 +Note 1276 Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1 +Note 1003 select 2 AS `2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a`>(exists((select 1 from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)) union (select 1 from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)))) +DROP TABLE t1,t2; +create table t0(a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1(f11 int, f12 int); +create table t2(f21 int unsigned not null, f22 int, f23 varchar(10)); +insert into t1 values(1,1),(2,2), (3, 3); +insert into t2 +select -1 , (@a:=(A.a + 10 * (B.a + 10 * (C.a+10*D.a))))/5000 + 1, @a +from t0 A, t0 B, t0 C, t0 D; +set session sort_buffer_size= 33*1024; +select count(*) from t1 where f12 = +(select f22 from t2 where f22 = f12 order by f21 desc, f22, f23 limit 1); +count(*) +3 +drop table t0,t1,t2; +CREATE TABLE t4 ( +f7 varchar(32) collate utf8_bin NOT NULL default '', +f10 varchar(32) collate utf8_bin default NULL, +PRIMARY KEY (f7) +); +INSERT INTO t4 VALUES(1,1), (2,null); +CREATE TABLE t2 ( +f4 varchar(32) collate utf8_bin NOT NULL default '', +f2 varchar(50) collate utf8_bin default NULL, +f3 varchar(10) collate utf8_bin default NULL, +PRIMARY KEY (f4), +UNIQUE KEY uk1 (f2) +); +INSERT INTO t2 VALUES(1,1,null), (2,2,null); +CREATE TABLE t1 ( +f8 varchar(32) collate utf8_bin NOT NULL default '', +f1 varchar(10) collate utf8_bin default NULL, +f9 varchar(32) collate utf8_bin default NULL, +PRIMARY KEY (f8) +); +INSERT INTO t1 VALUES (1,'P',1), (2,'P',1), (3,'R',2); +CREATE TABLE t3 ( +f6 varchar(32) collate utf8_bin NOT NULL default '', +f5 varchar(50) collate utf8_bin default NULL, +PRIMARY KEY (f6) +); +INSERT INTO t3 VALUES (1,null), (2,null); +SELECT +IF(t1.f1 = 'R', a1.f2, t2.f2) AS a4, +IF(t1.f1 = 'R', a1.f3, t2.f3) AS f3, +SUM( +IF( +(SELECT VPC.f2 +FROM t2 VPC, t4 a2, t2 a3 +WHERE +VPC.f4 = a2.f10 AND a3.f2 = a4 +LIMIT 1) IS NULL, +0, +t3.f5 +) +) AS a6 +FROM +t2, t3, t1 JOIN t2 a1 ON t1.f9 = a1.f4 +GROUP BY a4; +a4 f3 a6 +1 NULL NULL +2 NULL NULL +DROP TABLE t1, t2, t3, t4; +create table t1 (a float(5,4) zerofill); +create table t2 (a float(5,4),b float(2,0)); +select t1.a from t1 where +t1.a= (select b from t2 limit 1) and not +t1.a= (select a from t2 limit 1) ; +a +drop table t1, t2; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +SET @save_join_cache_level=@@join_cache_level; +SET join_cache_level=0; +EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 GROUP BY a); +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 2 100.00 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary +Warnings: +Note 1003 select 1 AS `1` from <materialize> (select min(`test`.`t1`.`a`) from `test`.`t1` group by `test`.`t1`.`a`) join `test`.`t1` where (`<subquery2>`.`min(a)` = 1) +EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a); +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 2 100.00 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary +Warnings: +Note 1003 select 1 AS `1` from <materialize> (select min(`test`.`t1`.`a`) from `test`.`t1` where (`test`.`t1`.`a` > 3) group by `test`.`t1`.`a`) join `test`.`t1` where (`<subquery2>`.`min(a)` = 1) +SET join_cache_level=@save_join_cache_level; +DROP TABLE t1; +# +# Bug#45061: Incorrectly market field caused wrong result. +# +CREATE TABLE `C` ( +`int_nokey` int(11) NOT NULL, +`int_key` int(11) NOT NULL, +KEY `int_key` (`int_key`) +); +INSERT INTO `C` VALUES (9,9), (0,0), (8,6), (3,6), (7,6), (0,4), +(1,7), (9,4), (0,8), (9,4), (0,7), (5,5), (0,0), (8,5), (8,7), +(5,2), (1,8), (7,0), (0,9), (9,5); +SELECT * FROM C WHERE `int_key` IN (SELECT `int_nokey`); +int_nokey int_key +9 9 +0 0 +5 5 +0 0 +EXPLAIN EXTENDED SELECT * FROM C WHERE `int_key` IN (SELECT `int_nokey`); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE C ALL NULL NULL NULL NULL 20 100.00 Using where +DROP TABLE C; +# End of test for bug#45061. +# +# Bug #46749: Segfault in add_key_fields() with outer subquery level +# field references +# +CREATE TABLE t1 ( +a int, +b int, +UNIQUE (a), KEY (b) +); +INSERT INTO t1 VALUES (1,1), (2,1); +CREATE TABLE st1 like t1; +INSERT INTO st1 VALUES (1,1), (2,1); +CREATE TABLE st2 like t1; +INSERT INTO st2 VALUES (1,1), (2,1); +EXPLAIN +SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b) +FROM t1 +WHERE a = 230; +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 +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b) +FROM t1 +WHERE a = 230; +MAX(b) (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b) +NULL NULL +DROP TABLE t1, st1, st2; +# +# Bug #48709: Assertion failed in sql_select.cc:11782: +# int join_read_key(JOIN_TAB*) +# +CREATE TABLE t1 (pk int PRIMARY KEY, int_key int); +INSERT INTO t1 VALUES (10,1), (14,1); +CREATE TABLE t2 (pk int PRIMARY KEY, int_key int); +INSERT INTO t2 VALUES (3,3), (5,NULL), (7,3); +# should have eq_ref for t1 +EXPLAIN +SELECT * FROM t2 outr +WHERE outr.int_key NOT IN (SELECT t1.pk FROM t1, t2) +ORDER BY outr.pk; +id select_type table type possible_keys key key_len ref rows Extra +x x outr ALL x x x x x x +x x t1 eq_ref x x x x x x +x x t2 index x x x x x x +# should not crash on debug binaries +SELECT * FROM t2 outr +WHERE outr.int_key NOT IN (SELECT t1.pk FROM t1, t2) +ORDER BY outr.pk; +pk int_key +3 3 +7 3 +DROP TABLE t1,t2; +# +# Bug#12329653 +# EXPLAIN, UNION, PREPARED STATEMENT, CRASH, SQL_FULL_GROUP_BY +# +CREATE TABLE t1(a1 int); +INSERT INTO t1 VALUES (1),(2); +SELECT @@session.sql_mode INTO @old_sql_mode; +SET SESSION sql_mode='ONLY_FULL_GROUP_BY'; +EXPLAIN EXTENDED +SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1); +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 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 +Warnings: +Note 1003 select 1 AS `1` from `test`.`t1` where 1 +SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1); +1 +1 +1 +PREPARE stmt FROM +'SELECT 1 UNION ALL +SELECT 1 FROM t1 +ORDER BY +(SELECT 1 FROM t1 AS t1_0 + WHERE 1 < SOME (SELECT a1 FROM t1) +)' ; +EXECUTE stmt ; +ERROR 21000: Subquery returns more than 1 row +EXECUTE stmt ; +ERROR 21000: Subquery returns more than 1 row +SET SESSION sql_mode=@old_sql_mode; +DEALLOCATE PREPARE stmt; +DROP TABLE t1; +# +# Bug#12763207 - ASSERT IN SUBSELECT::SINGLE_VALUE_TRANSFORMER +# +CREATE TABLE t1(a1 int); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2(a1 int); +INSERT INTO t2 VALUES (3); +SELECT @@session.sql_mode INTO @old_sql_mode; +SET SESSION sql_mode='ONLY_FULL_GROUP_BY'; +SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2 FROM t2); +1 +1 +1 +SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2); +1 +1 +1 +SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2); +1 +SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2); +1 +1 +1 +SET SESSION sql_mode=@old_sql_mode; +DROP TABLE t1, t2; +# +# Bug#12763207 - ASSERT IN SUBSELECT::SINGLE_VALUE_TRANSFORMER +# +create table t2(i int); +insert into t2 values(0); +SELECT @@session.sql_mode INTO @old_sql_mode; +SET SESSION sql_mode='ONLY_FULL_GROUP_BY'; +CREATE VIEW v1 AS +SELECT 'f' FROM t2 UNION SELECT 'x' FROM t2 +; +CREATE TABLE t1 ( +pk int NOT NULL, +col_varchar_key varchar(1) DEFAULT NULL, +PRIMARY KEY (pk), +KEY col_varchar_key (col_varchar_key) +); +SELECT t1.pk +FROM t1 +WHERE t1.col_varchar_key < ALL ( SELECT * FROM v1 ) +; +pk +SET SESSION sql_mode=@old_sql_mode; +drop table t2, t1; +drop view v1; +End of 5.0 tests. +create table t_out (subcase char(3), +a1 char(2), b1 char(2), c1 char(2)); +create table t_in (a2 char(2), b2 char(2), c2 char(2)); +insert into t_out values ('A.1','2a', NULL, '2a'); +insert into t_out values ('A.3', '2a', NULL, '2a'); +insert into t_out values ('A.4', '2a', NULL, 'xx'); +insert into t_out values ('B.1', '2a', '2a', '2a'); +insert into t_out values ('B.2', '2a', '2a', '2a'); +insert into t_out values ('B.3', '3a', 'xx', '3a'); +insert into t_out values ('B.4', 'xx', '3a', '3a'); +insert into t_in values ('1a', '1a', '1a'); +insert into t_in values ('2a', '2a', '2a'); +insert into t_in values (NULL, '2a', '2a'); +insert into t_in values ('3a', NULL, '3a'); + +Test general IN semantics (not top-level) + +case A.1 +select subcase, +(a1, b1, c1) IN (select * from t_in where a2 = 'no_match') pred_in, +(a1, b1, c1) NOT IN (select * from t_in where a2 = 'no_match') pred_not_in +from t_out where subcase = 'A.1'; +subcase pred_in pred_not_in +A.1 0 1 +case A.2 - impossible +case A.3 +select subcase, +(a1, b1, c1) IN (select * from t_in) pred_in, +(a1, b1, c1) NOT IN (select * from t_in) pred_not_in +from t_out where subcase = 'A.3'; +subcase pred_in pred_not_in +A.3 NULL NULL +case A.4 +select subcase, +(a1, b1, c1) IN (select * from t_in) pred_in, +(a1, b1, c1) NOT IN (select * from t_in) pred_not_in +from t_out where subcase = 'A.4'; +subcase pred_in pred_not_in +A.4 0 1 +case B.1 +select subcase, +(a1, b1, c1) IN (select * from t_in where a2 = 'no_match') pred_in, +(a1, b1, c1) NOT IN (select * from t_in where a2 = 'no_match') pred_not_in +from t_out where subcase = 'B.1'; +subcase pred_in pred_not_in +B.1 0 1 +case B.2 +select subcase, +(a1, b1, c1) IN (select * from t_in) pred_in, +(a1, b1, c1) NOT IN (select * from t_in) pred_not_in +from t_out where subcase = 'B.2'; +subcase pred_in pred_not_in +B.2 1 0 +case B.3 +select subcase, +(a1, b1, c1) IN (select * from t_in) pred_in, +(a1, b1, c1) NOT IN (select * from t_in) pred_not_in +from t_out where subcase = 'B.3'; +subcase pred_in pred_not_in +B.3 NULL NULL +case B.4 +select subcase, +(a1, b1, c1) IN (select * from t_in) pred_in, +(a1, b1, c1) NOT IN (select * from t_in) pred_not_in +from t_out where subcase = 'B.4'; +subcase pred_in pred_not_in +B.4 0 1 + +Test IN as top-level predicate, and +as non-top level for cases A.3, B.3 (the only cases with NULL result). + +case A.1 +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out +where subcase = 'A.1' and +(a1, b1, c1) IN (select * from t_in where a1 = 'no_match'); +pred_in +F +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out +where subcase = 'A.1' and +(a1, b1, c1) NOT IN (select * from t_in where a1 = 'no_match'); +pred_not_in +T +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out +where subcase = 'A.1' and +NOT((a1, b1, c1) IN (select * from t_in where a1 = 'no_match')); +not_pred_in +T +case A.3 +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out +where subcase = 'A.3' and +(a1, b1, c1) IN (select * from t_in); +pred_in +F +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out +where subcase = 'A.3' and +(a1, b1, c1) NOT IN (select * from t_in); +pred_not_in +F +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out +where subcase = 'A.3' and +NOT((a1, b1, c1) IN (select * from t_in)); +not_pred_in +F +select case when count(*) > 0 then 'N' else 'wrong result' end as pred_in from t_out +where subcase = 'A.3' and +((a1, b1, c1) IN (select * from t_in)) is NULL and +((a1, b1, c1) NOT IN (select * from t_in)) is NULL; +pred_in +N +case A.4 +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out +where subcase = 'A.4' and +(a1, b1, c1) IN (select * from t_in); +pred_in +F +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out +where subcase = 'A.4' and +(a1, b1, c1) NOT IN (select * from t_in); +pred_not_in +T +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out +where subcase = 'A.4' and +NOT((a1, b1, c1) IN (select * from t_in)); +not_pred_in +T +case B.1 +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out +where subcase = 'B.1' and +(a1, b1, c1) IN (select * from t_in where a1 = 'no_match'); +pred_in +F +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out +where subcase = 'B.1' and +(a1, b1, c1) NOT IN (select * from t_in where a1 = 'no_match'); +pred_not_in +T +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out +where subcase = 'B.1' and +NOT((a1, b1, c1) IN (select * from t_in where a1 = 'no_match')); +not_pred_in +T +case B.2 +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out +where subcase = 'B.2' and +(a1, b1, c1) IN (select * from t_in); +pred_in +T +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out +where subcase = 'B.2' and +(a1, b1, c1) NOT IN (select * from t_in); +pred_not_in +F +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out +where subcase = 'B.2' and +NOT((a1, b1, c1) IN (select * from t_in)); +not_pred_in +F +case B.3 +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out +where subcase = 'B.3' and +(a1, b1, c1) IN (select * from t_in); +pred_in +F +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out +where subcase = 'B.3' and +(a1, b1, c1) NOT IN (select * from t_in); +pred_not_in +F +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out +where subcase = 'B.3' and +NOT((a1, b1, c1) IN (select * from t_in)); +not_pred_in +F +select case when count(*) > 0 then 'N' else 'wrong result' end as pred_in from t_out +where subcase = 'B.3' and +((a1, b1, c1) IN (select * from t_in)) is NULL and +((a1, b1, c1) NOT IN (select * from t_in)) is NULL; +pred_in +N +case B.4 +select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out +where subcase = 'B.4' and +(a1, b1, c1) IN (select * from t_in); +pred_in +F +select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out +where subcase = 'B.4' and +(a1, b1, c1) NOT IN (select * from t_in); +pred_not_in +T +select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out +where subcase = 'B.4' and +NOT((a1, b1, c1) IN (select * from t_in)); +not_pred_in +T +drop table t_out; +drop table t_in; +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (2,22),(1,11),(2,22); +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 0 GROUP BY a; +a +1 +2 +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 1 GROUP BY a; +a +SELECT a FROM t1 t0 +WHERE (SELECT COUNT(t0.b) FROM t1 t WHERE t.b>20) GROUP BY a; +a +1 +2 +SET @@sql_mode='ansi'; +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 0 GROUP BY a; +ERROR HY000: Invalid use of group function +SELECT a FROM t1 WHERE (SELECT COUNT(b) FROM DUAL) > 1 GROUP BY a; +ERROR HY000: Invalid use of group function +SELECT a FROM t1 t0 +WHERE (SELECT COUNT(t0.b) FROM t1 t WHERE t.b>20) GROUP BY a; +ERROR HY000: Invalid use of group function +SET @@sql_mode=default; +DROP TABLE t1; +CREATE TABLE t1 (s1 CHAR(1)); +INSERT INTO t1 VALUES ('a'); +SELECT * FROM t1 WHERE _utf8'a' = ANY (SELECT s1 FROM t1); +s1 +a +DROP TABLE t1; +CREATE TABLE t1(c INT, KEY(c)); +CREATE TABLE t2(a INT, b INT); +INSERT INTO t2 VALUES (1, 10), (2, NULL); +INSERT INTO t1 VALUES (1), (3); +SELECT * FROM t2 WHERE b NOT IN (SELECT max(t.c) FROM t1, t1 t WHERE t.c>10); +a b +DROP TABLE t1,t2; +CREATE TABLE t1(pk INT PRIMARY KEY, a INT, INDEX idx(a)); +INSERT INTO t1 VALUES (1, 10), (3, 30), (2, 20); +CREATE TABLE t2(pk INT PRIMARY KEY, a INT, b INT, INDEX idxa(a)); +INSERT INTO t2 VALUES (2, 20, 700), (1, 10, 200), (4, 10, 100); +SELECT * FROM t1 +WHERE EXISTS (SELECT DISTINCT a FROM t2 WHERE t1.a < t2.a ORDER BY b); +pk a +1 10 +DROP TABLE t1,t2; +CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), KEY b (b)); +INSERT INTO t1 VALUES (1,NULL), (9,NULL); +CREATE TABLE t2 ( +a INT, +b INT, +c INT, +d INT, +PRIMARY KEY (a), +UNIQUE KEY b (b,c,d), +KEY b_2 (b), +KEY c (c), +KEY d (d) +); +INSERT INTO t2 VALUES +(43, 2, 11 ,30), +(44, 2, 12 ,30), +(45, 1, 1 ,10000), +(46, 1, 2 ,10000), +(556,1, 32 ,10000); +CREATE TABLE t3 ( +a INT, +b INT, +c INT, +PRIMARY KEY (a), +UNIQUE KEY b (b,c), +KEY c (c), +KEY b_2 (b) +); +INSERT INTO t3 VALUES (1,1,1), (2,32,1); +explain +SELECT t1.a, (SELECT 1 FROM t2 WHERE t2.b=t3.c AND t2.c=t1.a ORDER BY t2.d LIMIT 1) AS incorrect FROM t1, t3 WHERE t3.b=t1.a; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 2 Using index +1 PRIMARY t3 ref b,b_2 b 5 test.t1.a 1 Using index +2 DEPENDENT SUBQUERY t2 ref b,b_2,c b 10 test.t3.c,test.t1.a 1 Using where; Using index; Using filesort +SELECT t1.a, (SELECT 1 FROM t2 WHERE t2.b=t3.c AND t2.c=t1.a ORDER BY t2.d LIMIT 1) AS incorrect FROM t1, t3 WHERE t3.b=t1.a; +a incorrect +1 1 +DROP TABLE t1,t2,t3; +CREATE TABLE t1 (id int); +CREATE TABLE t2 (id int, c int); +INSERT INTO t1 (id) VALUES (1); +INSERT INTO t2 (id) VALUES (1); +INSERT INTO t1 (id) VALUES (1); +INSERT INTO t2 (id) VALUES (1); +CREATE VIEW v1 AS +SELECT t2.c AS c FROM t1, t2 +WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION; +UPDATE v1 SET c=1; +CREATE VIEW v2 (a,b) AS +SELECT t2.id, t2.c AS c FROM t1, t2 +WHERE t1.id=t2.id AND 1 IN (SELECT id FROM t1) WITH CHECK OPTION; +INSERT INTO v2(a,b) VALUES (2,2); +ERROR HY000: CHECK OPTION failed 'test.v2' +SELECT * FROM v1; +c +1 +1 +1 +1 +CREATE VIEW v3 AS +SELECT t2.c AS c FROM t2 +WHERE 1 IN (SELECT id FROM t1) WITH CHECK OPTION; +DELETE FROM v3; +DROP VIEW v1,v2,v3; +DROP TABLE t1,t2; +# +# BUG#37822 Correlated subquery with IN and IS UNKNOWN provides wrong result +# +create table t1(id integer primary key, g integer, v integer, s char(1)); +create table t2(id integer primary key, g integer, v integer, s char(1)); +insert into t1 values +(10, 10, 10, 'l'), +(20, 20, 20, 'l'), +(40, 40, 40, 'l'), +(41, 40, null, 'l'), +(50, 50, 50, 'l'), +(51, 50, null, 'l'), +(60, 60, 60, 'l'), +(61, 60, null, 'l'), +(70, 70, 70, 'l'), +(90, 90, null, 'l'); +insert into t2 values +(10, 10, 10, 'r'), +(30, 30, 30, 'r'), +(50, 50, 50, 'r'), +(60, 60, 60, 'r'), +(61, 60, null, 'r'), +(70, 70, 70, 'r'), +(71, 70, null, 'r'), +(80, 80, 80, 'r'), +(81, 80, null, 'r'), +(100,100,null, 'r'); +select * +from t1 +where v in(select v +from t2 +where t1.g=t2.g) is unknown; +id g v s +51 50 NULL l +61 60 NULL l +drop table t1, t2; +# +# Bug#37822 Correlated subquery with IN and IS UNKNOWN provides wrong result +# +create table t1(id integer primary key, g integer, v integer, s char(1)); +create table t2(id integer primary key, g integer, v integer, s char(1)); +insert into t1 values +(10, 10, 10, 'l'), +(20, 20, 20, 'l'), +(40, 40, 40, 'l'), +(41, 40, null, 'l'), +(50, 50, 50, 'l'), +(51, 50, null, 'l'), +(60, 60, 60, 'l'), +(61, 60, null, 'l'), +(70, 70, 70, 'l'), +(90, 90, null, 'l'); +insert into t2 values +(10, 10, 10, 'r'), +(30, 30, 30, 'r'), +(50, 50, 50, 'r'), +(60, 60, 60, 'r'), +(61, 60, null, 'r'), +(70, 70, 70, 'r'), +(71, 70, null, 'r'), +(80, 80, 80, 'r'), +(81, 80, null, 'r'), +(100,100,null, 'r'); +select * +from t1 +where v in(select v +from t2 +where t1.g=t2.g) is unknown; +id g v s +51 50 NULL l +61 60 NULL l +drop table t1, t2; +# +# Bug#33204: INTO is allowed in subselect, causing inconsistent results +# +CREATE TABLE t1( a INT ); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2( a INT, b INT ); +SELECT * +FROM (SELECT a INTO @var FROM t1 WHERE a = 2) t1a; +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 'INTO @var FROM t1 WHERE a = 2) t1a' at line 2 +SELECT * +FROM (SELECT a INTO OUTFILE 'file' FROM t1 WHERE a = 2) t1a; +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 'INTO OUTFILE 'file' FROM t1 WHERE a = 2) t1a' at line 2 +SELECT * +FROM (SELECT a INTO DUMPFILE 'file' FROM t1 WHERE a = 2) t1a; +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 'INTO DUMPFILE 'file' FROM t1 WHERE a = 2) t1a' at line 2 +SELECT * FROM ( +SELECT 1 a +UNION +SELECT a INTO @var FROM t1 WHERE a = 2 +) t1a; +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 'INTO @var FROM t1 WHERE a = 2 +) t1a' at line 4 +SELECT * FROM ( +SELECT 1 a +UNION +SELECT a INTO OUTFILE 'file' FROM t1 WHERE a = 2 +) t1a; +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 'INTO OUTFILE 'file' FROM t1 WHERE a = 2 +) t1a' at line 4 +SELECT * FROM ( +SELECT 1 a +UNION +SELECT a INTO DUMPFILE 'file' FROM t1 WHERE a = 2 +) t1a; +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 'INTO DUMPFILE 'file' FROM t1 WHERE a = 2 +) t1a' at line 4 +SELECT * FROM (SELECT a FROM t1 WHERE a = 2) t1a; +a +2 +SELECT * FROM ( +SELECT a FROM t1 WHERE a = 2 +UNION +SELECT a FROM t1 WHERE a = 2 +) t1a; +a +2 +SELECT * FROM ( +SELECT 1 a +UNION +SELECT a FROM t1 WHERE a = 2 +UNION +SELECT a FROM t1 WHERE a = 2 +) t1a; +a +1 +2 +SELECT * FROM ((SELECT 1 a) UNION SELECT 1 a); +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 ')' at line 1 +SELECT * FROM (SELECT 1 a UNION (SELECT 1 a)) alias; +a +1 +SELECT * FROM (SELECT 1 UNION SELECT 1) t1a; +1 +1 +SELECT * FROM ((SELECT 1 a INTO @a)) t1a; +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 'INTO @a)) t1a' at line 1 +SELECT * FROM ((SELECT 1 a INTO OUTFILE 'file' )) t1a; +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 'INTO OUTFILE 'file' )) t1a' at line 1 +SELECT * FROM ((SELECT 1 a INTO DUMPFILE 'file' )) t1a; +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 'INTO DUMPFILE 'file' )) t1a' at line 1 +SELECT * FROM (SELECT 1 a UNION (SELECT 1 a INTO @a)) t1a; +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 'INTO @a)) t1a' at line 1 +SELECT * FROM (SELECT 1 a UNION (SELECT 1 a INTO DUMPFILE 'file' )) t1a; +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 'INTO DUMPFILE 'file' )) t1a' at line 1 +SELECT * FROM (SELECT 1 a UNION (SELECT 1 a INTO OUTFILE 'file' )) t1a; +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 'INTO OUTFILE 'file' )) t1a' at line 1 +SELECT * FROM (SELECT 1 a UNION ((SELECT 1 a INTO @a))) t1a; +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 'INTO @a))) t1a' at line 1 +SELECT * FROM (SELECT 1 a UNION ((SELECT 1 a INTO DUMPFILE 'file' ))) t1a; +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 'INTO DUMPFILE 'file' ))) t1a' at line 1 +SELECT * FROM (SELECT 1 a UNION ((SELECT 1 a INTO OUTFILE 'file' ))) t1a; +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 'INTO OUTFILE 'file' ))) t1a' at line 1 +SELECT * FROM (SELECT 1 a ORDER BY a) t1a; +a +1 +SELECT * FROM (SELECT 1 a UNION SELECT 1 a ORDER BY a) t1a; +a +1 +SELECT * FROM (SELECT 1 a UNION SELECT 1 a LIMIT 1) t1a; +a +1 +SELECT * FROM (SELECT 1 a UNION SELECT 1 a ORDER BY a LIMIT 1) t1a; +a +1 +SELECT * FROM t1 JOIN (SELECT 1 UNION SELECT 1) alias ON 1; +a 1 +1 1 +2 1 +SELECT * FROM t1 JOIN ((SELECT 1 UNION SELECT 1)) ON 1; +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 ')) ON 1' at line 1 +SELECT * FROM t1 JOIN (t1 t1a UNION SELECT 1) ON 1; +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 ') ON 1' at line 1 +SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1; +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 ')) ON 1' at line 1 +SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1; +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 't1a ON 1' at line 1 +SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1; +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 't1a ON 1' at line 1 +SELECT * FROM t1 JOIN (t1 t1a) ON 1; +a a +1 1 +2 1 +1 2 +2 2 +SELECT * FROM t1 JOIN ((t1 t1a)) ON 1; +a a +1 1 +2 1 +1 2 +2 2 +SELECT * FROM (t1 t1a); +a +1 +2 +SELECT * FROM ((t1 t1a)); +a +1 +2 +SELECT * FROM t1 JOIN (SELECT 1 t1a) alias ON 1; +a t1a +1 1 +2 1 +SELECT * FROM t1 JOIN ((SELECT 1 t1a)) alias ON 1; +a t1a +1 1 +2 1 +SELECT * FROM t1 JOIN (SELECT 1 a) a ON 1; +a a +1 1 +2 1 +SELECT * FROM t1 JOIN ((SELECT 1 a)) a ON 1; +a a +1 1 +2 1 +SELECT * FROM (t1 JOIN (SELECT 1) t1a1 ON 1) t1a2; +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 't1a2' at line 1 +SELECT * FROM t1 WHERE a = ALL ( SELECT 1 ); +a +1 +SELECT * FROM t1 WHERE a = ALL ( SELECT 1 UNION SELECT 1 ); +a +1 +SELECT * FROM t1 WHERE a = ANY ( SELECT 3 UNION SELECT 1 ); +a +1 +SELECT * FROM t1 WHERE a = ANY ( SELECT 1 UNION SELECT 1 INTO @a); +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 'INTO @a)' at line 1 +SELECT * FROM t1 WHERE a = ANY ( SELECT 1 UNION SELECT 1 INTO OUTFILE 'file' ); +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 'INTO OUTFILE 'file' )' at line 1 +SELECT * FROM t1 WHERE a = ANY ( SELECT 1 UNION SELECT 1 INTO DUMPFILE 'file' ); +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 'INTO DUMPFILE 'file' )' at line 1 +SELECT * FROM t1 WHERE a = ( SELECT 1 ); +a +1 +SELECT * FROM t1 WHERE a = ( SELECT 1 UNION SELECT 1 ); +a +1 +SELECT * FROM t1 WHERE a = ( SELECT 1 INTO @a); +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 'INTO @a)' at line 1 +SELECT * FROM t1 WHERE a = ( SELECT 1 INTO OUTFILE 'file' ); +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 'INTO OUTFILE 'file' )' at line 1 +SELECT * FROM t1 WHERE a = ( SELECT 1 INTO DUMPFILE 'file' ); +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 'INTO DUMPFILE 'file' )' at line 1 +SELECT * FROM t1 WHERE a = ( SELECT 1 UNION SELECT 1 INTO @a); +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 'INTO @a)' at line 1 +SELECT * FROM t1 WHERE a = ( SELECT 1 UNION SELECT 1 INTO OUTFILE 'file' ); +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 'INTO OUTFILE 'file' )' at line 1 +SELECT * FROM t1 WHERE a = ( SELECT 1 UNION SELECT 1 INTO DUMPFILE 'file' ); +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 'INTO DUMPFILE 'file' )' at line 1 +SELECT ( SELECT 1 INTO @v ); +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 'INTO @v )' at line 1 +SELECT ( SELECT 1 INTO OUTFILE 'file' ); +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 'INTO OUTFILE 'file' )' at line 1 +SELECT ( SELECT 1 INTO DUMPFILE 'file' ); +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 'INTO DUMPFILE 'file' )' at line 1 +SELECT ( SELECT 1 UNION SELECT 1 INTO @v ); +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 'INTO @v )' at line 1 +SELECT ( SELECT 1 UNION SELECT 1 INTO OUTFILE 'file' ); +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 'INTO OUTFILE 'file' )' at line 1 +SELECT ( SELECT 1 UNION SELECT 1 INTO DUMPFILE 'file' ); +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 'INTO DUMPFILE 'file' )' at line 1 +SELECT ( SELECT a FROM t1 WHERE a = 1 ), a FROM t1; +( SELECT a FROM t1 WHERE a = 1 ) a +1 1 +1 2 +SELECT ( SELECT a FROM t1 WHERE a = 1 UNION SELECT 1 ), a FROM t1; +( SELECT a FROM t1 WHERE a = 1 UNION SELECT 1 ) a +1 1 +1 2 +SELECT * FROM t2 WHERE (a, b) IN (SELECT a, b FROM t2); +a b +SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ); +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 'UNION SELECT 1 )' at line 1 +( SELECT 1 UNION SELECT 1 ) UNION SELECT 1; +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 'UNION SELECT 1 ) UNION SELECT 1' at line 1 +SELECT ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) ); +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 'UNION SELECT 1 ) )' at line 1 +SELECT ( ( SELECT 1 UNION SELECT 1 ) UNION SELECT 1; +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 'UNION SELECT 1' at line 1 +SELECT ( SELECT 1 UNION SELECT 1 UNION SELECT 1 ); +( SELECT 1 UNION SELECT 1 UNION SELECT 1 ) +1 +SELECT ((SELECT 1 UNION SELECT 1 UNION SELECT 1)); +((SELECT 1 UNION SELECT 1 UNION SELECT 1)) +1 +SELECT * FROM ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) ); +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 'UNION SELECT 1 ) )' at line 1 +SELECT * FROM ( ( SELECT 1 UNION SELECT 1 ) UNION SELECT 1 ); +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 ') UNION SELECT 1 )' at line 1 +SELECT * FROM ( SELECT 1 UNION SELECT 1 UNION SELECT 1 ) a; +1 +1 +SELECT * FROM t1 WHERE a = ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) ); +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 'UNION SELECT 1 ) )' at line 1 +SELECT * FROM t1 WHERE a = ALL ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) ); +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 'UNION SELECT 1 ) )' at line 1 +SELECT * FROM t1 WHERE a = ANY ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) ); +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 'UNION SELECT 1 ) )' at line 1 +SELECT * FROM t1 WHERE a IN ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) ); +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 'UNION SELECT 1 ) )' at line 1 +SELECT * FROM t1 WHERE a = ( ( SELECT 1 UNION SELECT 1 ) UNION SELECT 1 ); +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 'UNION SELECT 1 )' at line 1 +SELECT * FROM t1 WHERE a = ALL ( ( SELECT 1 UNION SELECT 1 ) UNION SELECT 1 ); +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 'UNION SELECT 1 ) UNION SELECT 1 )' at line 1 +SELECT * FROM t1 WHERE a = ANY ( ( SELECT 1 UNION SELECT 1 ) UNION SELECT 1 ); +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 'UNION SELECT 1 ) UNION SELECT 1 )' at line 1 +SELECT * FROM t1 WHERE a IN ( ( SELECT 1 UNION SELECT 1 ) UNION SELECT 1 ); +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 'UNION SELECT 1 )' at line 1 +SELECT * FROM t1 WHERE a = ( SELECT 1 UNION SELECT 1 UNION SELECT 1 ); +a +1 +SELECT * FROM t1 WHERE a = ALL ( SELECT 1 UNION SELECT 1 UNION SELECT 1 ); +a +1 +SELECT * FROM t1 WHERE a = ANY ( SELECT 1 UNION SELECT 1 UNION SELECT 1 ); +a +1 +SELECT * FROM t1 WHERE a IN ( SELECT 1 UNION SELECT 1 UNION SELECT 1 ); +a +1 +SELECT * FROM t1 WHERE EXISTS ( SELECT 1 UNION SELECT 1 INTO @v ); +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 'INTO @v )' at line 1 +SELECT EXISTS(SELECT 1+1); +EXISTS(SELECT 1+1) +1 +SELECT EXISTS(SELECT 1+1 INTO @test); +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 'INTO @test)' at line 1 +SELECT * FROM t1 WHERE a IN ( SELECT 1 UNION SELECT 1 INTO @v ); +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 'INTO @v )' at line 1 +SELECT * FROM t1 WHERE EXISTS ( SELECT 1 INTO @v ); +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 'INTO @v )' at line 1 +SELECT * FROM t1 WHERE a IN ( SELECT 1 INTO @v ); +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 'INTO @v )' at line 1 +DROP TABLE t1, t2; +CREATE TABLE t1 (a ENUM('rainbow')); +INSERT INTO t1 VALUES (),(),(),(),(); +SELECT 1 FROM t1 GROUP BY (SELECT 1 FROM t1 ORDER BY AVG(LAST_INSERT_ID())); +1 +1 +DROP TABLE t1; +CREATE TABLE t1 (a LONGBLOB); +INSERT INTO t1 SET a = 'aaaa'; +INSERT INTO t1 SET a = 'aaaa'; +SELECT 1 FROM t1 GROUP BY +(SELECT LAST_INSERT_ID() FROM t1 ORDER BY MIN(a) ASC LIMIT 1); +1 +1 +DROP TABLE t1; +# +# Bug #49512 : subquery with aggregate function crash +# subselect_single_select_engine::exec() +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUES(); +# should not crash +SELECT 1 FROM t1 WHERE a <> SOME +( +SELECT MAX((SELECT a FROM t1 LIMIT 1)) AS d +FROM t1,t1 a +); +1 +DROP TABLE t1; +# +# Bug #45989 take 2 : memory leak after explain encounters an +# error in the query +# +CREATE TABLE t1(a LONGTEXT); +INSERT INTO t1 VALUES (repeat('a',@@global.max_allowed_packet)); +INSERT INTO t1 VALUES (repeat('b',@@global.max_allowed_packet)); +EXPLAIN EXTENDED SELECT DISTINCT 1 FROM t1, +(SELECT DISTINCTROW a AS away FROM t1 GROUP BY a WITH ROLLUP) AS d1 +WHERE t1.a = d1.a; +ERROR 42S22: Unknown column 'd1.a' in 'where clause' +DROP TABLE t1; +Set up test tables. +CREATE TABLE t1 ( +t1_id INT UNSIGNED, +PRIMARY KEY(t1_id) +) Engine=MyISAM; +INSERT INTO t1 (t1_id) VALUES (1), (2), (3), (4), (5); +CREATE TABLE t2 SELECT * FROM t1; +CREATE TABLE t3 ( +t3_id INT UNSIGNED AUTO_INCREMENT, +t1_id INT UNSIGNED, +amount DECIMAL(16,2), +PRIMARY KEY(t3_id), +KEY(t1_id) +) Engine=MyISAM; +INSERT INTO t3 (t1_id, t3_id, amount) +VALUES (1, 1, 100.00), (2, 2, 200.00), (4, 4, 400.00); +This is the 'inner query' running by itself. +Produces correct results. +SELECT +t1.t1_id, +IFNULL((SELECT SUM(amount) FROM t3 WHERE t3.t1_id=t1.t1_id), 0) AS total_amount +FROM +t1 +LEFT JOIN t2 ON t2.t1_id=t1.t1_id +GROUP BY +t1.t1_id +; +t1_id total_amount +1 100.00 +2 200.00 +3 0.00 +4 400.00 +5 0.00 +SELECT * FROM (the same inner query) +Produces correct results. +SELECT * FROM ( +SELECT +t1.t1_id, +IFNULL((SELECT SUM(amount) FROM t3 WHERE t3.t1_id=t1.t1_id), 0) AS total_amount +FROM +t1 +LEFT JOIN t2 ON t2.t1_id=t1.t1_id +GROUP BY +t1.t1_id +) AS t; +t1_id total_amount +1 100.00 +2 200.00 +3 0.00 +4 400.00 +5 0.00 +Now make t2.t1_id part of a key. +ALTER TABLE t2 ADD PRIMARY KEY(t1_id); +Same inner query by itself. +Still correct results. +SELECT +t1.t1_id, +IFNULL((SELECT SUM(amount) FROM t3 WHERE t3.t1_id=t1.t1_id), 0) AS total_amount +FROM +t1 +LEFT JOIN t2 ON t2.t1_id=t1.t1_id +GROUP BY +t1.t1_id; +t1_id total_amount +1 100.00 +2 200.00 +3 0.00 +4 400.00 +5 0.00 +SELECT * FROM (the same inner query), now with indexes on the LEFT JOIN +SELECT * FROM ( +SELECT +t1.t1_id, +IFNULL((SELECT SUM(amount) FROM t3 WHERE t3.t1_id=t1.t1_id), 0) AS total_amount +FROM +t1 +LEFT JOIN t2 ON t2.t1_id=t1.t1_id +GROUP BY +t1.t1_id +) AS t; +t1_id total_amount +1 100.00 +2 200.00 +3 0.00 +4 400.00 +5 0.00 +DROP TABLE t3; +DROP TABLE t2; +DROP TABLE t1; +# +# Bug #52711: Segfault when doing EXPLAIN SELECT with +# union...order by (select... where...) +# +CREATE TABLE t1 (a VARCHAR(10), FULLTEXT KEY a (a)); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (1),(2); +# Should not crash +EXPLAIN +SELECT * FROM t2 UNION SELECT * FROM t2 +ORDER BY (SELECT * FROM t1 WHERE MATCH(a) AGAINST ('+abc' IN BOOLEAN MODE)); +# Should not crash +SELECT * FROM t2 UNION SELECT * FROM t2 +ORDER BY (SELECT * FROM t1 WHERE MATCH(a) AGAINST ('+abc' IN BOOLEAN MODE)); +DROP TABLE t1,t2; +# +# Bug #58818: Incorrect result for IN/ANY subquery +# with HAVING condition +# +CREATE TABLE t1(i INT); +INSERT INTO t1 VALUES (1), (2), (3); +CREATE TABLE t1s(i INT); +INSERT INTO t1s VALUES (10), (20), (30); +CREATE TABLE t2s(i INT); +INSERT INTO t2s VALUES (100), (200), (300); +SELECT * FROM t1 +WHERE t1.i NOT IN +( +SELECT STRAIGHT_JOIN t2s.i +FROM +t1s LEFT OUTER JOIN t2s ON t2s.i = t1s.i +HAVING t2s.i = 999 +); +i +1 +2 +3 +SELECT * FROM t1 +WHERE t1.I IN +( +SELECT STRAIGHT_JOIN t2s.i +FROM +t1s LEFT OUTER JOIN t2s ON t2s.i = t1s.i +HAVING t2s.i = 999 +) IS UNKNOWN; +i +SELECT * FROM t1 +WHERE NOT t1.I = ANY +( +SELECT STRAIGHT_JOIN t2s.i +FROM +t1s LEFT OUTER JOIN t2s ON t2s.i = t1s.i +HAVING t2s.i = 999 +); +i +1 +2 +3 +SELECT * FROM t1 +WHERE t1.i = ANY ( +SELECT STRAIGHT_JOIN t2s.i +FROM +t1s LEFT OUTER JOIN t2s ON t2s.i = t1s.i +HAVING t2s.i = 999 +) IS UNKNOWN; +i +DROP TABLE t1,t1s,t2s; +# LP BUG#675248 - select->prep_where references on freed memory +CREATE TABLE t1 (a int, b int); +insert into t1 values (1,1),(0,0); +CREATE TABLE t2 (c int); +insert into t2 values (1),(2); +prepare stmt1 from "select sum(a),(select sum(c) from t2 where table1.b) as sub +from t1 as table1 group by sub"; +execute stmt1; +sum(a) sub +0 NULL +1 3 +deallocate prepare stmt1; +prepare stmt1 from "select sum(a),(select sum(c) from t2 having table1.b) as sub +from t1 as table1"; +execute stmt1; +sum(a) sub +1 3 +deallocate prepare stmt1; +drop table t1,t2; +# +# Bug LP#693935/#58727: Assertion failure with +# a single row subquery returning more than one row +# +create table t1 (a char(1) charset utf8); +insert into t1 values ('a'), ('b'); +create table t2 (a binary(1)); +insert into t2 values ('x'), ('y'); +select * from t2 where a=(select a from t1) and a='x'; +ERROR 21000: Subquery returns more than 1 row +drop table t1,t2; +End of 5.1 tests +# +# Bug #11765713 58705: +# OPTIMIZER LET ENGINE DEPEND ON UNINITIALIZED VALUES +# CREATED BY OPT_SUM_QUERY +# +CREATE TABLE t1(a INT NOT NULL, KEY (a)); +INSERT INTO t1 VALUES (0), (1); +SELECT 1 as foo FROM t1 WHERE a < SOME +(SELECT a FROM t1 WHERE a <=> +(SELECT a FROM t1) +); +ERROR 21000: Subquery returns more than 1 row +SELECT 1 as foo FROM t1 WHERE a < SOME +(SELECT a FROM t1 WHERE a <=> +(SELECT a FROM t1 where a is null) +); +foo +DROP TABLE t1; +# +# Bug #57704: Cleanup code dies with void TABLE::set_keyread(bool): +# Assertion `file' failed. +# +CREATE TABLE t1 (a INT); +SELECT 1 FROM +(SELECT ROW( +(SELECT 1 FROM t1 RIGHT JOIN +(SELECT 1 FROM t1, t1 t2) AS d ON 1), +1) FROM t1) AS e; +ERROR 21000: Operand should contain 1 column(s) +DROP TABLE t1; +# +# Bug#13721076 CRASH WITH TIME TYPE/TIMESTAMP() AND WARNINGS IN SUBQUERY +# +CREATE TABLE t1(a TIME NOT NULL); +INSERT INTO t1 VALUES ('00:00:32'); +SELECT 1 FROM t1 WHERE a > +(SELECT timestamp(a) AS a FROM t1); +1 +DROP TABLE t1; +# +# No BUG#, a case brought from 5.2's innodb_mysql_lock.test +# +create table t1 (i int not null primary key); +insert into t1 values (1),(2),(3),(4),(5); +create table t2 (j int not null primary key); +insert into t2 values (1),(2),(3),(4),(5); +create table t3 (k int not null primary key); +insert into t3 values (1),(2),(3); +create view v2 as select t2.j as j from t2 where t2.j in (select t1.i from t1); +select * from t3 where k in (select j from v2); +k +1 +2 +3 +drop table t1,t2,t3; +drop view v2; +# +# Bug#52068: Optimizer generates invalid semijoin materialization plan +# +drop table if exists ot1, ot2, it1, it2; +CREATE TABLE ot1(a INTEGER); +INSERT INTO ot1 VALUES(5), (8); +CREATE TABLE it2(a INTEGER); +INSERT INTO it2 VALUES(9), (5), (1), (8); +CREATE TABLE it3(a INTEGER); +INSERT INTO it3 VALUES(7), (1), (0), (5), (1), (4); +CREATE TABLE ot4(a INTEGER); +INSERT INTO ot4 VALUES(1), (3), (5), (7), (9), (7), (3), (1); +SELECT * FROM ot1,ot4 +WHERE (ot1.a,ot4.a) IN (SELECT it2.a,it3.a +FROM it2,it3); +a a +5 1 +8 1 +5 5 +8 5 +5 7 +8 7 +5 7 +8 7 +5 1 +8 1 +explain SELECT * FROM ot1,ot4 +WHERE (ot1.a,ot4.a) IN (SELECT it2.a,it3.a +FROM it2,it3); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ot1 ALL NULL NULL NULL NULL 2 +1 PRIMARY ot4 ALL NULL NULL NULL NULL 8 Using join buffer (flat, BNL join) +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 +2 MATERIALIZED it2 ALL NULL NULL NULL NULL 4 +2 MATERIALIZED it3 ALL NULL NULL NULL NULL 6 Using join buffer (flat, BNL join) +DROP TABLE IF EXISTS ot1, ot4, it2, it3; +# +# Bug#729039: NULL keys used to evaluate subquery +# +CREATE TABLE t1 (a int) ; +INSERT INTO t1 VALUES (NULL), (1), (NULL), (2); +CREATE TABLE t2 (a int, INDEX idx(a)) ; +INSERT INTO t2 VALUES (NULL), (1), (NULL); +SELECT * FROM t1 +WHERE EXISTS (SELECT a FROM t2 USE INDEX () WHERE t2.a = t1.a); +a +1 +EXPLAIN +SELECT * FROM t1 +WHERE EXISTS (SELECT a FROM t2 USE INDEX() WHERE t2.a = t1.a); +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 ALL NULL NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 +SELECT * FROM t1 +WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a); +a +1 +EXPLAIN +SELECT * FROM t1 +WHERE EXISTS (SELECT a FROM t2 WHERE t2.a = t1.a); +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 ALL NULL NULL NULL NULL 4 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 index idx idx 5 NULL 3 Using index +DROP TABLE t1,t2; +# +# BUG#752992: Wrong results for a subquery with 'semijoin=on' +# +CREATE TABLE t1 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL); +INSERT INTO t1 VALUES (11,0); +INSERT INTO t1 VALUES (12,5); +INSERT INTO t1 VALUES (15,0); +CREATE TABLE t2 (pk INTEGER PRIMARY KEY, i INTEGER NOT NULL); +INSERT INTO t2 VALUES (11,1); +INSERT INTO t2 VALUES (12,2); +INSERT INTO t2 VALUES (15,4); +SET @save_join_cache_level=@@join_cache_level; +SET join_cache_level=0; +EXPLAIN SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 3 +1 PRIMARY it eq_ref PRIMARY PRIMARY 4 test.t1.pk 1 Using index +1 PRIMARY t2 index NULL PRIMARY 4 NULL 3 Using index; FirstMatch(it) +SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1); +pk i +11 0 +12 5 +15 0 +SET join_cache_level=@save_join_cache_level; +DROP table t1,t2; +# +# Bug#751350: crash with pushed condition for outer references when +# there should be none of such conditions +# +CREATE TABLE t1 (a int, b int) ; +INSERT INTO t1 VALUES (0,0),(0,0); +set @optimizer_switch_save=@@optimizer_switch; +set @@optimizer_switch='semijoin=off,materialization=on,in_to_exists=on'; +EXPLAIN +SELECT b FROM t1 +WHERE ('0') IN ( SELECT a FROM t1 GROUP BY a ) +GROUP BY b; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +SELECT b FROM t1 +WHERE ('0') IN ( SELECT a FROM t1 GROUP BY a ) +GROUP BY b; +b +0 +set @@optimizer_switch=@optimizer_switch_save; +DROP TABLE t1; +# +# Bug #11765713 58705: +# OPTIMIZER LET ENGINE DEPEND ON UNINITIALIZED VALUES +# CREATED BY OPT_SUM_QUERY +# +CREATE TABLE t1(a INT NOT NULL, KEY (a)); +INSERT INTO t1 VALUES (0), (1); +SELECT 1 as foo FROM t1 WHERE a < SOME +(SELECT a FROM t1 WHERE a <=> +(SELECT a FROM t1) +); +ERROR 21000: Subquery returns more than 1 row +SELECT 1 as foo FROM t1 WHERE a < SOME +(SELECT a FROM t1 WHERE a <=> +(SELECT a FROM t1 where a is null) +); +foo +DROP TABLE t1; +CREATE TABLE t1 (a int(11), b varchar(1)); +INSERT INTO t1 VALUES (2,NULL),(5,'d'),(7,'g'); +SELECT a FROM t1 WHERE b < ANY ( SELECT b FROM t1 GROUP BY b ); +a +5 +SELECT a FROM t1 WHERE b < ANY ( SELECT b FROM t1 ); +a +5 +SELECT a FROM t1 WHERE b > ANY ( SELECT b FROM t1 GROUP BY b ); +a +7 +SELECT a FROM t1 WHERE b > ANY ( SELECT b FROM t1 ); +a +7 +SELECT a FROM t1 WHERE b <= ANY ( SELECT b FROM t1 GROUP BY b ); +a +5 +7 +SELECT a FROM t1 WHERE b <= ANY ( SELECT b FROM t1 ); +a +5 +7 +SELECT a FROM t1 WHERE b >= ANY ( SELECT b FROM t1 GROUP BY b ); +a +5 +7 +SELECT a FROM t1 WHERE b >= ANY ( SELECT b FROM t1 ); +a +5 +7 +SELECT a FROM t1 WHERE b = ANY ( SELECT b FROM t1 ); +a +5 +7 +SELECT a FROM t1 WHERE b = ANY ( SELECT b FROM t1 GROUP BY b ); +a +5 +7 +SELECT a FROM t1 WHERE b <> ANY ( SELECT b FROM t1 ); +a +5 +7 +SELECT a FROM t1 WHERE b <> ANY ( SELECT b FROM t1 GROUP BY b ); +a +5 +7 +SELECT a FROM t1 WHERE b < ALL ( SELECT b FROM t1 GROUP BY b ); +a +SELECT a FROM t1 WHERE b < ALL ( SELECT b FROM t1 ); +a +SELECT a FROM t1 WHERE b > ALL ( SELECT b FROM t1 GROUP BY b ); +a +SELECT a FROM t1 WHERE b > ALL ( SELECT b FROM t1 ); +a +SELECT a FROM t1 WHERE b <= ALL ( SELECT b FROM t1 GROUP BY b ); +a +SELECT a FROM t1 WHERE b <= ALL ( SELECT b FROM t1 ); +a +SELECT a FROM t1 WHERE b >= ALL ( SELECT b FROM t1 GROUP BY b ); +a +SELECT a FROM t1 WHERE b >= ALL ( SELECT b FROM t1 ); +a +SELECT a FROM t1 WHERE b = ALL ( SELECT b FROM t1 ); +a +SELECT a FROM t1 WHERE b = ALL ( SELECT b FROM t1 GROUP BY b ); +a +SELECT a FROM t1 WHERE b <> ALL ( SELECT b FROM t1 ); +a +SELECT a FROM t1 WHERE b <> ALL ( SELECT b FROM t1 GROUP BY b ); +a +delete from t1; +INSERT INTO t1 VALUES (2,NULL),(5,'d'),(7,'g'); +SELECT a FROM t1 WHERE b < ANY ( SELECT b FROM t1 GROUP BY b ); +a +5 +SELECT a FROM t1 WHERE b < ANY ( SELECT b FROM t1 ); +a +5 +SELECT a FROM t1 WHERE b > ANY ( SELECT b FROM t1 GROUP BY b ); +a +7 +SELECT a FROM t1 WHERE b > ANY ( SELECT b FROM t1 ); +a +7 +SELECT a FROM t1 WHERE b <= ANY ( SELECT b FROM t1 GROUP BY b ); +a +5 +7 +SELECT a FROM t1 WHERE b <= ANY ( SELECT b FROM t1 ); +a +5 +7 +SELECT a FROM t1 WHERE b >= ANY ( SELECT b FROM t1 GROUP BY b ); +a +5 +7 +SELECT a FROM t1 WHERE b >= ANY ( SELECT b FROM t1 ); +a +5 +7 +SELECT a FROM t1 WHERE b = ANY ( SELECT b FROM t1 ); +a +5 +7 +SELECT a FROM t1 WHERE b = ANY ( SELECT b FROM t1 GROUP BY b ); +a +5 +7 +SELECT a FROM t1 WHERE b <> ANY ( SELECT b FROM t1 ); +a +5 +7 +SELECT a FROM t1 WHERE b <> ANY ( SELECT b FROM t1 GROUP BY b ); +a +5 +7 +SELECT a FROM t1 WHERE b < ALL ( SELECT b FROM t1 GROUP BY b ); +a +SELECT a FROM t1 WHERE b < ALL ( SELECT b FROM t1 ); +a +SELECT a FROM t1 WHERE b > ALL ( SELECT b FROM t1 GROUP BY b ); +a +SELECT a FROM t1 WHERE b > ALL ( SELECT b FROM t1 ); +a +SELECT a FROM t1 WHERE b <= ALL ( SELECT b FROM t1 GROUP BY b ); +a +SELECT a FROM t1 WHERE b <= ALL ( SELECT b FROM t1 ); +a +SELECT a FROM t1 WHERE b >= ALL ( SELECT b FROM t1 GROUP BY b ); +a +SELECT a FROM t1 WHERE b >= ALL ( SELECT b FROM t1 ); +a +SELECT a FROM t1 WHERE b = ALL ( SELECT b FROM t1 ); +a +SELECT a FROM t1 WHERE b = ALL ( SELECT b FROM t1 GROUP BY b ); +a +SELECT a FROM t1 WHERE b <> ALL ( SELECT b FROM t1 ); +a +SELECT a FROM t1 WHERE b <> ALL ( SELECT b FROM t1 GROUP BY b ); +a +drop table t1; +# +# Fix of lp:780386 (NULL left part with empty ALL subquery). +# +CREATE TABLE t1 ( f11 int) ; +INSERT IGNORE INTO t1 VALUES (0),(0); +CREATE TABLE t2 ( f3 int, f10 int, KEY (f10,f3)) ; +INSERT IGNORE INTO t2 VALUES (NULL,NULL),(5,0); +DROP TABLE IF EXISTS t3; +Warnings: +Note 1051 Unknown table 't3' +CREATE TABLE t3 ( f3 int) ; +INSERT INTO t3 VALUES (0),(0); +SELECT a1.f3 AS r FROM t2 AS a1 , t1 WHERE a1.f3 < ALL ( SELECT f3 FROM t3 WHERE f3 = 1 ) ; +r +NULL +5 +NULL +5 +DROP TABLE t1, t2, t3; +# +# Bug#12763207 - ASSERT IN SUBSELECT::SINGLE_VALUE_TRANSFORMER +# +CREATE TABLE t1(a1 int); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2(a1 int); +INSERT INTO t2 VALUES (3); +SELECT @@session.sql_mode INTO @old_sql_mode; +SET SESSION sql_mode='ONLY_FULL_GROUP_BY'; +SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2 FROM t2); +1 +1 +1 +SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 2.0 FROM t2); +1 +1 +1 +SELECT 1 FROM t1 WHERE 1 < SOME (SELECT 'a' FROM t2); +1 +SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t2); +1 +1 +1 +SET SESSION sql_mode=@old_sql_mode; +DROP TABLE t1, t2; +create table t2(i int); +insert into t2 values(0); +SELECT @@session.sql_mode INTO @old_sql_mode; +SET SESSION sql_mode='ONLY_FULL_GROUP_BY'; +CREATE VIEW v1 AS +SELECT 'f' FROM t2 UNION SELECT 'x' FROM t2 +; +CREATE TABLE t1 ( +pk int NOT NULL, +col_varchar_key varchar(1) DEFAULT NULL, +PRIMARY KEY (pk), +KEY col_varchar_key (col_varchar_key) +); +SELECT t1.pk +FROM t1 +WHERE t1.col_varchar_key < ALL ( SELECT * FROM v1 ) +; +pk +SET SESSION sql_mode=@old_sql_mode; +drop table t2, t1; +drop view v1; +# +# BUG#50257: Missing info in REF column of the EXPLAIN +# lines for subselects +# +CREATE TABLE t1 (a INT, b INT, INDEX (a)); +INSERT INTO t1 VALUES (3, 10), (2, 20), (7, 10), (5, 20); +EXPLAIN SELECT * FROM (SELECT * FROM t1 WHERE a=7) t; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 5 const 1 +EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 +2 SUBQUERY t1 ref a a 5 const 1 Using index +DROP TABLE t1; +# +# BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS) +# (duplicate of LP bug #888456) +# +CREATE TABLE t1 (f1 varchar(1)); +INSERT INTO t1 VALUES ('v'),('s'); +CREATE TABLE t2 (f1_key varchar(1), KEY (f1_key)); +INSERT INTO t2 VALUES ('j'),('v'),('c'),('m'),('d'), +('d'),('y'),('t'),('d'),('s'); +EXPLAIN +SELECT table1.f1, table2.f1_key FROM t1 AS table1, t2 AS table2 +WHERE EXISTS (SELECT DISTINCT f1_key FROM t2 +WHERE f1_key != table2.f1_key AND f1_key >= table1.f1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY table1 ALL NULL NULL NULL NULL 2 +1 PRIMARY table2 index NULL f1_key 4 NULL 10 Using where; Using index; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t2 index f1_key f1_key 4 NULL 10 Using where; Using index +SELECT table1.f1, table2.f1_key FROM t1 AS table1, t2 AS table2 +WHERE EXISTS (SELECT DISTINCT f1_key FROM t2 +WHERE f1_key != table2.f1_key AND f1_key >= table1.f1); +f1 f1_key +v j +s j +v v +s v +v c +s c +v m +s m +v d +s d +v d +s d +v y +s y +v t +s t +v d +s d +v s +s s +DROP TABLE t1,t2; +# +# LP bug 919427: EXPLAIN for a query over a single-row table +# with IN subquery in WHERE condition +# +CREATE TABLE ot ( +col_int_nokey int(11), +col_varchar_nokey varchar(1) +) ; +INSERT INTO ot VALUES (1,'x'); +CREATE TABLE it1( +col_int_key int(11), +col_varchar_key varchar(1), +KEY idx_cvk_cik (col_varchar_key,col_int_key) +); +INSERT INTO it1 VALUES (NULL,'x'), (NULL,'f'); +CREATE TABLE it2 ( +col_int_key int(11), +col_varchar_key varchar(1), +col_varchar_key2 varchar(1), +KEY idx_cvk_cvk2_cik (col_varchar_key, col_varchar_key2, col_int_key), +KEY idx_cvk_cik (col_varchar_key, col_int_key) +); +INSERT INTO it2 VALUES (NULL,'x','x'), (NULL,'f','f'); +EXPLAIN +SELECT col_int_nokey FROM ot +WHERE col_varchar_nokey IN +(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ot system NULL NULL NULL NULL 1 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED it1 ref idx_cvk_cik idx_cvk_cik 9 const,const 1 Using where; Using index +SELECT col_int_nokey FROM ot +WHERE col_varchar_nokey IN +(SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL); +col_int_nokey +1 +EXPLAIN +SELECT col_int_nokey FROM ot +WHERE (col_varchar_nokey, 'x') IN +(SELECT col_varchar_key, col_varchar_key2 FROM it2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ot system NULL NULL NULL NULL 1 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 +2 MATERIALIZED it2 ref idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 const,const 1 Using where; Using index +SELECT col_int_nokey FROM ot +WHERE (col_varchar_nokey, 'x') IN +(SELECT col_varchar_key, col_varchar_key2 FROM it2); +col_int_nokey +1 +DROP TABLE ot,it1,it2; +# +# MDEV-746 +# Bug#13651009 WRONG RESULT FROM DERIVED TABLE IF THE SUBQUERY +# HAS AN EMPTY RESULT +# +CREATE TABLE t1 ( +pk int NOT NULL, +col_int_nokey int NOT NULL, +col_int_key int NOT NULL, +col_time_key time NOT NULL, +col_varchar_key varchar(1) NOT NULL, +col_varchar_nokey varchar(1) NOT NULL, +PRIMARY KEY (pk), +KEY col_int_key (col_int_key), +KEY col_time_key (col_time_key), +KEY col_varchar_key (col_varchar_key,col_int_key) +) ENGINE=MyISAM; +CREATE TABLE t2 ( +pk int NOT NULL AUTO_INCREMENT, +col_int_nokey int NOT NULL, +col_int_key int NOT NULL, +col_time_key time NOT NULL, +col_varchar_key varchar(1) NOT NULL, +col_varchar_nokey varchar(1) NOT NULL, +PRIMARY KEY (pk), +KEY col_int_key (col_int_key), +KEY col_time_key (col_time_key), +KEY col_varchar_key (col_varchar_key,col_int_key) +) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,4,4,'00:00:00','b','b'); +SET @var2:=4, @var3:=8; + +Testcase without inner subquery +EXPLAIN SELECT @var3:=12, sq4_alias1.* +FROM t1 AS sq4_alias1 +WHERE (sq4_alias1.col_varchar_key + NULL) IS NULL OR +sq4_alias1.col_varchar_key = @var3; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +SELECT @var3:=12, sq4_alias1.* +FROM t1 AS sq4_alias1 +WHERE (sq4_alias1.col_varchar_key + NULL) IS NULL OR +sq4_alias1.col_varchar_key = @var3; +@var3:=12 pk col_int_nokey col_int_key col_time_key col_varchar_key col_varchar_nokey +SELECT @var3; +@var3 +8 +EXPLAIN SELECT * FROM ( SELECT @var3:=12, sq4_alias1.* +FROM t1 AS sq4_alias1 +WHERE (sq4_alias1.col_varchar_key + NULL) IS NULL OR +sq4_alias1.col_varchar_key = @var3 ) AS alias3; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> system NULL NULL NULL NULL 0 const row not found +2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +SELECT * FROM ( SELECT @var3:=12, sq4_alias1.* +FROM t1 AS sq4_alias1 +WHERE (sq4_alias1.col_varchar_key + NULL) IS NULL OR +sq4_alias1.col_varchar_key = @var3 ) AS alias3; +@var3:=12 pk col_int_nokey col_int_key col_time_key col_varchar_key col_varchar_nokey +SELECT @var3; +@var3 +8 + +Testcase with inner subquery; crashed WL#6095 +SET @var3=8; +EXPLAIN SELECT sq4_alias1.* +FROM t1 AS sq4_alias1 +WHERE (sq4_alias1.col_varchar_key , sq4_alias1.col_varchar_nokey) +NOT IN +(SELECT c_sq1_alias1.col_varchar_key AS c_sq1_field1, +c_sq1_alias1.col_varchar_nokey AS c_sq1_field2 +FROM t2 AS c_sq1_alias1 +WHERE (c_sq1_alias1.col_int_nokey != @var2 +OR c_sq1_alias1.pk != @var3)); +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 +2 DEPENDENT SUBQUERY c_sq1_alias1 system PRIMARY NULL NULL NULL 1 +SELECT sq4_alias1.* +FROM t1 AS sq4_alias1 +WHERE (sq4_alias1.col_varchar_key , sq4_alias1.col_varchar_nokey) +NOT IN +(SELECT c_sq1_alias1.col_varchar_key AS c_sq1_field1, +c_sq1_alias1.col_varchar_nokey AS c_sq1_field2 +FROM t2 AS c_sq1_alias1 +WHERE (c_sq1_alias1.col_int_nokey != @var2 +OR c_sq1_alias1.pk != @var3)); +pk col_int_nokey col_int_key col_time_key col_varchar_key col_varchar_nokey +EXPLAIN SELECT * FROM ( SELECT sq4_alias1.* +FROM t1 AS sq4_alias1 +WHERE (sq4_alias1.col_varchar_key , sq4_alias1.col_varchar_nokey) +NOT IN +(SELECT c_sq1_alias1.col_varchar_key AS c_sq1_field1, +c_sq1_alias1.col_varchar_nokey AS c_sq1_field2 +FROM t2 AS c_sq1_alias1 +WHERE (c_sq1_alias1.col_int_nokey != @var2 +OR c_sq1_alias1.pk != @var3)) ) AS alias3; +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 DEPENDENT SUBQUERY c_sq1_alias1 system PRIMARY NULL NULL NULL 1 +SELECT * FROM ( SELECT sq4_alias1.* +FROM t1 AS sq4_alias1 +WHERE (sq4_alias1.col_varchar_key , sq4_alias1.col_varchar_nokey) +NOT IN +(SELECT c_sq1_alias1.col_varchar_key AS c_sq1_field1, +c_sq1_alias1.col_varchar_nokey AS c_sq1_field2 +FROM t2 AS c_sq1_alias1 +WHERE (c_sq1_alias1.col_int_nokey != @var2 +OR c_sq1_alias1.pk != @var3)) ) AS alias3; +pk col_int_nokey col_int_key col_time_key col_varchar_key col_varchar_nokey +DROP TABLE t1,t2; +End of 5.2 tests +# +# BUG#779885: Crash in eliminate_item_equal with materialization=on in +# +CREATE TABLE t1 ( f1 int ); +INSERT INTO t1 VALUES (19), (20); +CREATE TABLE t2 ( f10 varchar(32) ); +INSERT INTO t2 VALUES ('c'),('d'); +CREATE TABLE t3 ( f10 varchar(32) ); +INSERT INTO t3 VALUES ('a'),('b'); +SELECT * +FROM t1 +WHERE +( 't' ) IN ( +SELECT t3.f10 +FROM t3 +JOIN t2 +ON t2.f10 = t3.f10 +); +f1 +DROP TABLE t1,t2,t3; +# +# BUG lp:813473: Wrong result with outer join + NOT IN subquery +# This bug is a duplicate of Bug#11764086 whose test case is added below +# +CREATE TABLE t1 (c int) ; +INSERT INTO t1 VALUES (5),(6); +CREATE TABLE t2 (a int, b int) ; +INSERT INTO t2 VALUES (20,9),(20,9); +create table t3 (d int, e int); +insert into t3 values (2, 9), (3,10); +SET @save_optimizer_switch=@@optimizer_switch; +SET optimizer_switch='outer_join_with_cache=off'; +EXPLAIN +SELECT t2.b , t1.c +FROM t2 LEFT JOIN t1 ON t1.c < 3 +WHERE (t2.b , t1.c) NOT IN (SELECT * from t3); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using where +SELECT t2.b , t1.c +FROM t2 LEFT JOIN t1 ON t1.c < 3 +WHERE (t2.b, t1.c) NOT IN (SELECT * from t3); +b c +9 NULL +9 NULL +SET optimizer_switch=@save_optimizer_switch; +drop table t1, t2, t3; +# +# BUG#50257: Missing info in REF column of the EXPLAIN +# lines for subselects +# +CREATE TABLE t1 (a INT, b INT, INDEX (a)); +INSERT INTO t1 VALUES (3, 10), (2, 20), (7, 10), (5, 20); + +set @tmp_optimizer_switch=@@optimizer_switch; +set optimizer_switch='derived_merge=off,derived_with_keys=off'; +EXPLAIN SELECT * FROM (SELECT * FROM t1 WHERE a=7) t; +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 ref a a 5 const 1 +set optimizer_switch=@tmp_optimizer_switch; + +EXPLAIN SELECT * FROM t1 WHERE EXISTS (SELECT * FROM t1 WHERE a=7); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 +2 SUBQUERY t1 ref a a 5 const 1 Using index + +DROP TABLE t1; +# +# Bug#11764086: Null left operand to NOT IN in WHERE clause +# behaves differently than real NULL +# +CREATE TABLE parent (id int); +INSERT INTO parent VALUES (1), (2); +CREATE TABLE child (parent_id int, other int); +INSERT INTO child VALUES (1,NULL); +# Offending query (c.parent_id is NULL for null-complemented rows only) +SELECT p.id, c.parent_id +FROM parent p +LEFT JOIN child c +ON p.id = c.parent_id +WHERE c.parent_id NOT IN ( +SELECT parent_id +FROM child +WHERE parent_id = 3 +); +id parent_id +1 1 +2 NULL +# Some syntactic variations with IS FALSE and IS NOT TRUE +SELECT p.id, c.parent_id +FROM parent p +LEFT JOIN child c +ON p.id = c.parent_id +WHERE c.parent_id IN ( +SELECT parent_id +FROM child +WHERE parent_id = 3 +) IS NOT TRUE; +id parent_id +1 1 +2 NULL +SELECT p.id, c.parent_id +FROM parent p +LEFT JOIN child c +ON p.id = c.parent_id +WHERE c.parent_id IN ( +SELECT parent_id +FROM child +WHERE parent_id = 3 +) IS FALSE; +id parent_id +1 1 +2 NULL +DROP TABLE parent, child; +# End of test for bug#11764086. +# +# Bug 11765699 - 58690: !TABLE || (!TABLE->READ_SET || +# BITMAP_IS_SET(TABLE->READ_SET, FIELD_INDEX +# +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUES (0), (1); +CREATE TABLE t2( +b TEXT, +c INT, +PRIMARY KEY (b(1)) +); +INSERT INTO t2 VALUES ('a', 2), ('b', 3); +SELECT 1 FROM t1 WHERE a = +(SELECT 1 FROM t2 WHERE b = +(SELECT 1 FROM t1 t11 WHERE c = 1 OR t1.a = 1 AND 1 = 2) +ORDER BY b +); +1 +SELECT 1 FROM t1 WHERE a = +(SELECT 1 FROM t2 WHERE b = +(SELECT 1 FROM t1 t11 WHERE c = 1 OR t1.a = 1 AND 1 = 2) +GROUP BY b +); +1 +DROP TABLE t1, t2; +# +# BUG#12616253 - WRONG RESULT WITH EXISTS(SUBQUERY) (MISSING ROWS) +# +CREATE TABLE t1 (f1 varchar(1)); +INSERT INTO t1 VALUES ('v'),('s'); +CREATE TABLE t2 (f1_key varchar(1), KEY (f1_key)); +INSERT INTO t2 VALUES ('j'),('v'),('c'),('m'),('d'), +('d'),('y'),('t'),('d'),('s'); +SELECT table1.f1, table2.f1_key +FROM t1 AS table1, t2 AS table2 +WHERE EXISTS +( +SELECT DISTINCT f1_key +FROM t2 +WHERE f1_key != table2.f1_key AND f1_key >= table1.f1 ); +f1 f1_key +v j +s j +v v +s v +v c +s c +v m +s m +v d +s d +v d +s d +v y +s y +v t +s t +v d +s d +v s +s s +explain SELECT table1.f1, table2.f1_key +FROM t1 AS table1, t2 AS table2 +WHERE EXISTS +( +SELECT DISTINCT f1_key +FROM t2 +WHERE f1_key != table2.f1_key AND f1_key >= table1.f1 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY table1 ALL NULL NULL NULL NULL 2 +1 PRIMARY table2 index NULL f1_key 4 NULL 10 Using where; Using index; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t2 index f1_key f1_key 4 NULL 10 Using where; Using index +DROP TABLE t1,t2; +# +# lp:826279: assertion failure with GROUP BY a result of subquery +# +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (0), (0); +CREATE TABLE t2 (a int, b int, c int); +INSERT INTO t2 VALUES (10,7,0), (0,7,0); +CREATE TABLE t3 (a int, b int); +INSERT INTO t3 VALUES (10,7), (0,7); +SELECT SUM(DISTINCT b), +(SELECT t2.a FROM t1 JOIN t2 ON t2.c != 0 +WHERE t.a != 0 AND t2.a != 0) +FROM (SELECT * FROM t3) AS t +GROUP BY 2; +SUM(DISTINCT b) (SELECT t2.a FROM t1 JOIN t2 ON t2.c != 0 +WHERE t.a != 0 AND t2.a != 0) +7 NULL +SELECT SUM(DISTINCT b), +(SELECT t2.a FROM t1,t2 WHERE t.a != 0 or 1=2 LIMIT 1) +FROM (SELECT * FROM t3) AS t +GROUP BY 2; +SUM(DISTINCT b) (SELECT t2.a FROM t1,t2 WHERE t.a != 0 or 1=2 LIMIT 1) +7 NULL +7 10 +DROP TABLE t1,t2,t3; +# +# Bug#12329653 +# EXPLAIN, UNION, PREPARED STATEMENT, CRASH, SQL_FULL_GROUP_BY +# +CREATE TABLE t1(a1 int); +INSERT INTO t1 VALUES (1),(2); +SELECT @@session.sql_mode INTO @old_sql_mode; +SET SESSION sql_mode='ONLY_FULL_GROUP_BY'; +SELECT 1 FROM t1 WHERE 1 < SOME (SELECT a1 FROM t1); +1 +1 +1 +PREPARE stmt FROM +'SELECT 1 UNION ALL +SELECT 1 FROM t1 +ORDER BY +(SELECT 1 FROM t1 AS t1_0 + WHERE 1 < SOME (SELECT a1 FROM t1) +)' ; +EXECUTE stmt ; +ERROR 21000: Subquery returns more than 1 row +EXECUTE stmt ; +ERROR 21000: Subquery returns more than 1 row +SET SESSION sql_mode=@old_sql_mode; +DEALLOCATE PREPARE stmt; +DROP TABLE t1; +# +# LP BUG#833777 Performance regression with deeply nested subqueries +# +create table t1 (a int not null, b char(10) not null); +insert into t1 values (1, 'a'); +set @@optimizer_switch='in_to_exists=on,semijoin=off,materialization=off,subquery_cache=off'; +select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1 where a in (select a from t1))))))))))))))))))))))))))))); +a +1 +set @@optimizer_switch=@subselect_tmp; +drop table t1; +# +# LP BUG#894397 Wrong result with in_to_exists, constant table , semijoin=OFF,materialization=OFF +# +CREATE TABLE t1 (a varchar(3)); +INSERT INTO t1 VALUES ('AAA'),('BBB'); +CREATE TABLE t2 (a varchar(3)); +INSERT INTO t2 VALUES ('CCC'); +set @@optimizer_switch='semijoin=off,materialization=off,in_to_exists=on,subquery_cache=off'; +SELECT * FROM t1 WHERE t1.a IN (SELECT t2.a FROM t2 WHERE t2.a < 'ZZZ'); +a +set @@optimizer_switch=@subselect_tmp; +drop table t1, t2; +# +# LP bug #859375: Assertion `0' failed in st_select_lex_unit::optimize +# with view , UNION and prepared statement (rewriting fake_select +# condition). +# +CREATE TABLE t1 ( f1 int NOT NULL, f4 varchar(1) NOT NULL) ; +INSERT INTO t1 VALUES (6,'d'),(7,'y'); +CREATE TABLE t2 ( f1 int NOT NULL, f2 int NOT NULL) ; +INSERT INTO t2 VALUES (10,7); +CREATE VIEW v2 AS SELECT * FROM t2; +PREPARE st1 FROM " + SELECT * + FROM t1 + LEFT JOIN v2 ON ( v2.f2 = t1.f1 ) + WHERE v2.f1 NOT IN ( + SELECT 1 UNION + SELECT 247 + ) +"; +EXECUTE st1; +f1 f4 f1 f2 +7 y 10 7 +deallocate prepare st1; +DROP VIEW v2; +DROP TABLE t1,t2; +# +# LP bug #887458 Crash in subselect_union_engine::no_rows with +# double UNION and join_cache_level=3,8 +# (IN/ALL/ANY optimizations should not be applied to fake_select) +CREATE TABLE t2 ( a int, b varchar(1)) ; +INSERT IGNORE INTO t2 VALUES (8,'y'),(8,'y'); +CREATE TABLE t1 ( b varchar(1)) ; +INSERT IGNORE INTO t1 VALUES (NULL),(NULL); +set @save_join_cache_level=@@join_cache_level; +SET SESSION join_cache_level=3; +SELECT * +FROM t1, t2 +WHERE t2.b IN ( +SELECT 'm' UNION +SELECT 'm' +) OR t1.b <> SOME ( +SELECT 'v' UNION +SELECT 't' +); +b a b +set @@join_cache_level= @save_join_cache_level; +drop table t1,t2; +# +# LP bug #885162 Got error 124 from storage engine with UNION inside +# subquery and join_cache_level=3..8 +# (IN/ALL/ANY optimizations should not be applied to fake_select) +# +CREATE TABLE t1 ( +f1 varchar(1) DEFAULT NULL +); +INSERT INTO t1 VALUES ('c'); +set @save_join_cache_level=@@join_cache_level; +SET SESSION join_cache_level=8; +SELECT * FROM t1 WHERE t1.f1 IN ( SELECT 'k' UNION SELECT 'e' ); +f1 +set @@join_cache_level= @save_join_cache_level; +drop table t1; +# +# LP BUG#747278 incorrect values of the NULL (no rows) single +# row subquery requested via element_index() interface +# +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 default 1, f3b int default 2); +INSERT INTO t3 VALUES (1,1),(2,2); +set @old_optimizer_switch = @@session.optimizer_switch; +set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,subquery_cache=off,semijoin=off'; +SELECT (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) FROM t2; +(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) +NULL +NULL +SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) FROM t2; +(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) +NULL +NULL +SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) FROM t2; +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +NULL +NULL +SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1); +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +NULL +SELECT (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2; +(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) +NULL +NULL +SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) FROM t2; +(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) +NULL +NULL +SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) FROM t2; +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +NULL +NULL +SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1); +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +NULL +set @@session.optimizer_switch=@old_optimizer_switch; +SELECT (SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) FROM t2; +(SELECT f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a FROM t1) +NULL +NULL +SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) FROM t2; +(SELECT f3a,f3a FROM t3 where f3a > 3) NOT IN (SELECT f1a,f1a FROM t1) +NULL +NULL +SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) FROM t2; +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +NULL +NULL +SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1); +(SELECT f3a, f3b FROM t3 where f3a > 3) NOT IN (SELECT f1a, f1b FROM t1) +NULL +SELECT (SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) FROM t2; +(SELECT f3a FROM t3 where f3a > 3) IN (SELECT f1a FROM t1) +NULL +NULL +SELECT (SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) FROM t2; +(SELECT f3a,f3a FROM t3 where f3a > 3) IN (SELECT f1a,f1a FROM t1) +NULL +NULL +SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) FROM t2; +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +NULL +NULL +SELECT (SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1); +(SELECT f3a, f3b FROM t3 where f3a > 3) IN (SELECT f1a, f1b FROM t1) +NULL +select (null, null) = (null, null); +(null, null) = (null, null) +NULL +SELECT (SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0); +(SELECT f3a, f3a FROM t3 where f3a > 3) = (0, 0) +NULL +drop tables t1,t2,t3; +# +# LP BUG#825051 Wrong result with date/datetime and subquery with GROUP BY and in_to_exists +# +CREATE TABLE t1 (a date, KEY (a)) ; +INSERT INTO t1 VALUES ('2009-01-01'),('2009-02-02'); +set @old_optimizer_switch = @@optimizer_switch; +SET @@optimizer_switch='semijoin=off,materialization=off,in_to_exists=on,subquery_cache=off'; +EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 index NULL a 4 NULL 2 Using where; Using index +2 DEPENDENT SUBQUERY t1 index_subquery a a 4 func 2 Using index +SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1); +a +2009-01-01 +2009-02-02 +SET @@optimizer_switch='semijoin=off,materialization=on,in_to_exists=off,subquery_cache=off'; +EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 index NULL a 4 NULL 2 Using where; Using index +2 MATERIALIZED t1 index NULL a 4 NULL 2 Using index +SELECT * FROM t1 WHERE a IN (SELECT a AS field1 FROM t1 GROUP BY field1); +a +2009-01-01 +2009-02-02 +set @@optimizer_switch=@old_optimizer_switch; +drop table t1; +# +# LP BUG#908269 incorrect condition in case of subqueries depending +# on constant tables +# +CREATE TABLE t1 ( a INT ); +INSERT INTO t1 VALUES (1),(5); +CREATE TABLE t2 ( b INT ) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1); +CREATE TABLE t3 ( c INT ); +INSERT INTO t3 VALUES (4),(5); +SET optimizer_switch='subquery_cache=off'; +SELECT ( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) FROM t1; +( SELECT b FROM t2 WHERE b = a OR EXISTS ( SELECT c FROM t3 WHERE c = b ) ) +1 +NULL +SELECT ( SELECT b FROM t2 WHERE b = a OR b * 0) FROM t1; +( SELECT b FROM t2 WHERE b = a OR b * 0) +1 +NULL +SELECT ( SELECT b FROM t2 WHERE b = a OR rand() * 0) FROM t1; +( SELECT b FROM t2 WHERE b = a OR rand() * 0) +1 +NULL +drop table t1,t2,t3; +set optimizer_switch=@subselect_tmp; +# +# LP BUG#905353 Wrong non-empty result with a constant table, +# aggregate function in subquery, MyISAM or Aria +# +CREATE TABLE t1 ( a INT ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1); +SELECT a FROM t1 WHERE ( SELECT MIN(a) = 100 ); +a +drop table t1; +# +# LP BUG#985667 Wrong result with subquery in SELECT clause, and constant table in +# main query and implicit grouping +# +CREATE TABLE t1 (f1 int) engine=MyISAM; +INSERT INTO t1 VALUES (7),(8); +CREATE TABLE t2 (f2 int, f3 varchar(1)) engine=MyISAM; +INSERT INTO t2 VALUES (3,'f'); +EXPLAIN +SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; +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 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +SELECT COUNT(f1), (SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; +COUNT(f1) f4 +0 NULL +EXPLAIN +SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; +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 +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +SELECT COUNT(f1), exists(SELECT f1 FROM t1 WHERE f2 > 0 limit 1) AS f4 FROM t2, t1 WHERE 'v'= f3; +COUNT(f1) f4 +0 0 +EXPLAIN +SELECT COUNT(f1), f2 > ALL (SELECT f1 FROM t1 WHERE f2 > 0) AS f4 FROM t2, t1 WHERE 'v'= f3; +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 +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +SELECT COUNT(f1), f2 > ALL (SELECT f1 FROM t1 WHERE f2 > 0) AS f4 FROM t2, t1 WHERE 'v'= f3; +COUNT(f1) f4 +0 1 +EXPLAIN +SELECT COUNT(f1), f2 IN (SELECT f1 FROM t1 WHERE f2 > 0) AS f4 FROM t2, t1 WHERE 'v'= f3; +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 +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +SELECT COUNT(f1), f2 IN (SELECT f1 FROM t1 WHERE f2 > 0) AS f4 FROM t2, t1 WHERE 'v'= f3; +COUNT(f1) f4 +0 0 +drop table t1,t2; +# +# LP BUG#1002079 Server crashes in Item_singlerow_subselect::val_int with constant table, +# HAVING, UNION in subquery +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (7),(0); +CREATE TABLE t2 (b INT); +EXPLAIN +SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 system NULL NULL NULL NULL 0 const row not found +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used +3 UNION NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL +SELECT SUM(a) AS f1, a AS f2 FROM (t1, t2) HAVING f2 >= ALL (SELECT 4 UNION SELECT 5) AND f1 = 7; +f1 f2 +drop table t1,t2; +# +# LP BUG#1008686 Server crashes in subselect_union_engine::no_rows on SELECT with impossible +# WHERE and UNION in HAVING +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(7); +EXPLAIN +SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1; +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 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used +3 DEPENDENT UNION NULL NULL NULL NULL NULL NULL NULL No tables used +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL +SELECT MIN(a) AS min_a, a FROM t1 WHERE 0 HAVING a NOT IN ( SELECT 2 UNION SELECT 5 ) OR min_a != 1; +min_a a +EXPLAIN +SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1; +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 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +3 DEPENDENT UNION t1 ALL NULL NULL NULL NULL 2 Using where +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL +SELECT MIN(a) AS min_a, a FROM t1 WHERE 1=2 HAVING a NOT IN ( SELECT a from t1 UNION select a+1 from t1 ) OR min_a != 1; +min_a a +drop table t1; +# +# MDEV-367: Different results with and without subquery_cache on +# a query with a constant NOT IN condition +# +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2),(3); +set @mdev367_optimizer_switch = @@optimizer_switch; +set optimizer_switch = 'subquery_cache=on'; +SELECT * FROM t1 WHERE ( 3, 3 ) NOT IN ( SELECT NULL, NULL ) OR a > 100; +a +SELECT *, ( 3, 3 ) NOT IN ( SELECT NULL, NULL ) FROM t1; +a ( 3, 3 ) NOT IN ( SELECT NULL, NULL ) +1 NULL +2 NULL +3 NULL +set optimizer_switch=@mdev367_optimizer_switch; +set optimizer_switch = 'subquery_cache=off'; +SELECT * FROM t1 WHERE ( 3, 3 ) NOT IN ( SELECT NULL, NULL ) OR a > 100; +a +SELECT *, ( 3, 3 ) NOT IN ( SELECT NULL, NULL ) FROM t1; +a ( 3, 3 ) NOT IN ( SELECT NULL, NULL ) +1 NULL +2 NULL +3 NULL +set optimizer_switch=@mdev367_optimizer_switch; +DROP TABLE t1; +# +# MDEV-521 single value subselect transformation problem +# +CREATE TABLE t1 (f1 char(2), PRIMARY KEY (f1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('u1'),('u2'); +SELECT a.* FROM t1 a WHERE ( SELECT EXISTS ( SELECT 1 FROM t1 b WHERE b.f1 = a.f1 ) ); +f1 +u1 +u2 +FLUSH TABLES; +SELECT a.* FROM t1 a WHERE ( SELECT EXISTS ( SELECT 1 FROM t1 b WHERE b.f1 = a.f1 ) ); +f1 +u1 +u2 +DROP TABLE t1; +# return optimizer switch changed in the beginning of this test +set optimizer_switch=@subselect_tmp; +# +# lp:944706 Query with impossible or constant subquery in WHERE or HAVING is not +# precomputed and thus not part of optimization +# +CREATE TABLE t1 ( a VARCHAR(16), KEY (a) ); +INSERT INTO t1 VALUES ('Abilene'),('Akron'),('Albany'),('Albuquerque'),('Alexandria'),('Allentown'), +('Amarillo'),('Anaheim'),('Anchorage'),('Ann Arbor'),('Arden-Arcade'); +EXPLAIN +SELECT MAX( alias2.a ) AS field +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR alias1.a = 'y' +HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a 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 HAVING +2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +SELECT MAX( alias2.a ) AS field +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR alias1.a = 'y' +HAVING field>'B' AND ( 'Moscow' ) IN ( SELECT a FROM t1 ); +field +EXPLAIN +SELECT MAX( alias2.a ) +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 index a a 19 NULL 11 Using where; Using index +1 PRIMARY alias2 ref a a 19 test.alias1.a 2 Using index +1 PRIMARY alias3 index NULL a 19 NULL 11 Using index; Using join buffer (flat, BNL join) +2 SUBQUERY t1 index_subquery a a 19 const 1 Using index; Using where +SELECT MAX( alias2.a ) +FROM t1 AS alias1, t1 AS alias2, t1 AS alias3 +WHERE alias1.a = alias2.a OR ('Moscow') IN ( SELECT a FROM t1 ); +MAX( alias2.a ) +Arden-Arcade +drop table t1; +# +# MDEV-277 CHEAP SQ: Server crashes in st_join_table::get_examined_rows +# with semijoin+materialization, IN and = subqueries +# +CREATE TABLE t1 (a1 INT); +INSERT INTO t1 VALUES (4),(6); +CREATE TABLE t2 (b1 INT); +INSERT INTO t2 VALUES (1),(7); +EXPLAIN +SELECT * FROM t1 +WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, 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 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 +3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +SELECT * FROM t1 +WHERE a1 = (SELECT COUNT(*) FROM t1 WHERE a1 IN (SELECT a1 FROM t1, t2)); +a1 +drop table t1, t2; +# +# MDEV-287 CHEAP SQ: A query with subquery in SELECT list, EXISTS, +# inner joins takes hundreds times longer +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(7); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (4),(5); +CREATE TABLE t3 (c INT); +INSERT INTO t3 VALUES (8),(3); +set @@expensive_subquery_limit= 0; +EXPLAIN +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 +1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 +flush status; +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +show status like "subquery_cache%"; +Variable_name Value +Subquery_cache_hit 6 +Subquery_cache_miss 2 +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 8 +Handler_read_last 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 22 +set @@expensive_subquery_limit= default; +EXPLAIN +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 +1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +1 PRIMARY alias3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t3 ALL NULL NULL NULL NULL 2 +flush status; +SELECT (SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +FROM t2 alias1, t1 alias2, t1 alias3; +(SELECT MIN(b) FROM t1, t2 WHERE b = a AND (b = alias1.b OR EXISTS (SELECT * FROM t3))) +NULL +NULL +NULL +NULL +NULL +NULL +NULL +NULL +show status like "subquery_cache%"; +Variable_name Value +Subquery_cache_hit 0 +Subquery_cache_miss 0 +show status like '%Handler_read%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 0 +Handler_read_last 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 16 +drop table t1, t2, t3; +# +# MDEV-288 CHEAP SQ: Valgrind warnings "Memory lost" with IN and EXISTS nested subquery, materialization+semijoin +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0),(8); +CREATE TABLE t2 (b INT PRIMARY KEY); +INSERT INTO t2 VALUES (1),(2); +EXPLAIN +SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * 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 +2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +SELECT * FROM t1 WHERE 4 IN (SELECT MAX(b) FROM t2 WHERE EXISTS (SELECT * FROM t1)); +a +drop table t1,t2; +# +# MDEV-410: EXPLAIN shows type=range, while SHOW EXPLAIN and userstat show full table scan is used +# +CREATE TABLE t1 (a VARCHAR(3) PRIMARY KEY) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('USA'); +CREATE TABLE t2 (b INT, c VARCHAR(52), KEY(b)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (3813,'United States'),(3940,'Russia'); +CREATE TABLE t3 (d INT, KEY(d)) ENGINE=MyISAM; +INSERT INTO t3 VALUES (12),(22),(9),(45); +create table t4 like t3; +insert into t4 select * from t3; +# This should not show range access for table t2 +explain +SELECT MIN(b) FROM ( SELECT * FROM t1, t2, t3 WHERE d = b ) AS alias1 +WHERE SLEEP(0.1) OR c < 'p' OR b = ( SELECT MIN(b) 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 ALL b NULL NULL NULL 2 Using where +1 PRIMARY t3 ref d d 5 test.t2.b 2 Using where; Using index +3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +set @tmp_mdev410=@@global.userstat; +set global userstat=on; +flush table_statistics; +flush index_statistics; +SELECT MIN(b) FROM ( SELECT * FROM t1, t2, t3 WHERE d = b ) AS alias1 +WHERE SLEEP(0.1) OR c < 'p' OR b = ( SELECT MIN(b) FROM t2 ); +MIN(b) +NULL +# The following shows that t2 was indeed scanned with a full scan. +show table_statistics; +Table_schema Table_name Rows_read Rows_changed Rows_changed_x_#indexes +test t1 2 0 0 +test t2 3 0 0 +show index_statistics; +Table_schema Table_name Index_name Rows_read +test t2 b 1 +set global userstat=@tmp_mdev410; +DROP TABLE t1,t2,t3,t4; +# +# MDEV-430: Server crashes in select_describe on EXPLAIN with +# materialization+semijoin, 2 nested subqueries, aggregate functions +# +CREATE TABLE t1 (a INT, KEY(a)); +INSERT INTO t1 VALUES (1),(8); +CREATE TABLE t2 (b INT, KEY(b)); +INSERT INTO t2 VALUES (45),(17),(20); +EXPLAIN SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t1, t2 WHERE b = a GROUP BY a HAVING a <> 1 ) ; +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 t1 index a a 5 NULL 2 Using where; Using index +2 SUBQUERY t2 ref b b 5 test.t1.a 2 Using index +DROP TABLE t1,t2; +# +# MDEV-435: Expensive subqueries may be evaluated during optimization in merge_key_fields +# +CREATE TABLE t1 (a INT, KEY(a)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (8),(0); +CREATE TABLE t2 (b INT, c VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (4,'j'),(6,'v'); +CREATE TABLE t3 (d VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t3 VALUES ('b'),('c'); +EXPLAIN +SELECT * FROM t1 +WHERE a = (SELECT MAX(b) FROM t2 WHERE c IN (SELECT MAX(d) FROM t3)) OR a = 10; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 index a a 5 NULL 2 Using where; Using index +2 SUBQUERY <subquery3> ALL distinct_key NULL NULL NULL 1 +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 +SELECT * FROM t1 +WHERE a = (SELECT MAX(b) FROM t2 WHERE c IN (SELECT MAX(d) FROM t3)) OR a = 10; +a +drop table t1, t2, t3; +# +# MDEV-405: Server crashes in test_if_skip_sort_order on EXPLAIN with GROUP BY and HAVING in EXISTS subquery +# +CREATE TABLE t1 (a INT, KEY(a)); +INSERT INTO t1 VALUES (1),(8); +CREATE TABLE t2 (b INT, KEY(b)); +INSERT INTO t2 VALUES (45),(17),(20); +EXPLAIN SELECT * FROM t1 WHERE EXISTS ( SELECT a FROM t1, t2 WHERE b = a GROUP BY a HAVING a <> 1 ) ; +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 t1 index a a 5 NULL 2 Using where; Using index +2 SUBQUERY t2 ref b b 5 test.t1.a 2 Using index +DROP TABLE t1,t2; +set optimizer_switch=default; +select @@optimizer_switch like '%exists_to_in=on%'; +@@optimizer_switch like '%exists_to_in=on%' +0 diff --git a/mysql-test/r/subselect_innodb.result b/mysql-test/r/subselect_innodb.result index e52a9078fca..a5800883711 100644 --- a/mysql-test/r/subselect_innodb.result +++ b/mysql-test/r/subselect_innodb.result @@ -248,6 +248,47 @@ NULL drop procedure p1; drop tables t1,t2,t3; # +# Bug #58756 +# Crash in heap_rrnd on query with HAVING ... IN (subquery) + LIMIT +# +CREATE TABLE t1 ( +col_time_key time DEFAULT NULL, +col_datetime_key datetime DEFAULT NULL, +col_varchar_nokey varchar(1) DEFAULT NULL, +KEY col_time_key (col_time_key), +KEY col_datetime_key (col_datetime_key) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +INSERT INTO t1 VALUES ('17:53:30','2005-11-10 12:40:29','h'); +INSERT INTO t1 VALUES ('11:35:49','2009-04-25 00:00:00','b'); +INSERT INTO t1 VALUES (NULL,'2002-11-27 00:00:00','s'); +INSERT INTO t1 VALUES ('06:01:40','2004-01-26 20:32:32','e'); +INSERT INTO t1 VALUES ('05:45:11','2007-10-26 11:41:40','j'); +INSERT INTO t1 VALUES ('00:00:00','2005-10-07 00:00:00','e'); +INSERT INTO t1 VALUES ('00:00:00','2000-07-15 05:00:34','f'); +INSERT INTO t1 VALUES ('06:11:01','2000-04-03 16:33:32','v'); +INSERT INTO t1 VALUES ('13:02:46',NULL,'x'); +INSERT INTO t1 VALUES ('21:44:25','2001-04-25 01:26:12','m'); +INSERT INTO t1 VALUES ('22:43:58','2000-12-27 00:00:00','c'); +CREATE TABLE t2 ( +col_time_key time DEFAULT NULL, +col_datetime_key datetime DEFAULT NULL, +col_varchar_nokey varchar(1) DEFAULT NULL, +KEY col_time_key (col_time_key), +KEY col_datetime_key (col_datetime_key) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +INSERT INTO t2 VALUES ('11:28:45','2004-10-11 18:13:16','w'); +SELECT col_time_key, col_datetime_key +FROM +( SELECT * FROM t1 ) AS table1 +HAVING ( 'r' , 'e' ) IN +( SELECT col_varchar_nokey , col_varchar_nokey FROM t2 ) +ORDER BY col_datetime_key +LIMIT 10; +col_time_key col_datetime_key +DROP TABLE t1; +DROP TABLE t2; +# End of Bug #58756 +# # Bug#60085 crash in Item::save_in_field() with time data type # CREATE TABLE t1(a date, b int, unique(b), unique(a), key(b)) engine=innodb; diff --git a/mysql-test/r/subselect_mat.result b/mysql-test/r/subselect_mat.result index 09271e21c66..cd78d9f93fb 100644 --- a/mysql-test/r/subselect_mat.result +++ b/mysql-test/r/subselect_mat.result @@ -1474,7 +1474,7 @@ 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; Rowid-ordered scan +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 @@ -2215,7 +2215,7 @@ 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 +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 diff --git a/mysql-test/r/subselect_mat_cost.result b/mysql-test/r/subselect_mat_cost.result index 081196a227b..a9f980fff5d 100644 --- a/mysql-test/r/subselect_mat_cost.result +++ b/mysql-test/r/subselect_mat_cost.result @@ -348,7 +348,7 @@ FROM City LEFT JOIN Country ON (Country = Code and City.Population < 10000)) AND Language IN ('English','Spanish'); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY CountryLanguage range Language Language 30 NULL 72 Using index condition; Using where; Rowid-ordered scan -2 DEPENDENT SUBQUERY City ref CityName CityName 35 func 1 Using index condition; Using where +2 DEPENDENT SUBQUERY City ref CityName CityName 35 func 1 Using index condition 2 DEPENDENT SUBQUERY Country eq_ref PRIMARY PRIMARY 3 world.City.Country 1 Using where; Using index select count(*) from CountryLanguage @@ -399,10 +399,10 @@ WHERE Code = Country GROUP BY Code) order by Country; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY CountryLanguage index NULL PRIMARY 33 NULL 984 Using where; Using index -3 MATERIALIZED CountryLanguage index PRIMARY PRIMARY 33 NULL 984 Using index; Using temporary -3 MATERIALIZED Country eq_ref PRIMARY PRIMARY 3 world.CountryLanguage.Country 1 Using index -2 MATERIALIZED CountryLanguage index PRIMARY PRIMARY 33 NULL 984 Using index; Using temporary -2 MATERIALIZED Country eq_ref PRIMARY PRIMARY 3 world.CountryLanguage.Country 1 Using index +3 MATERIALIZED Country index PRIMARY PRIMARY 3 NULL 239 Using index +3 MATERIALIZED CountryLanguage ref PRIMARY PRIMARY 3 world.Country.Code 4 Using index +2 MATERIALIZED Country index PRIMARY PRIMARY 3 NULL 239 Using index +2 MATERIALIZED CountryLanguage ref PRIMARY PRIMARY 3 world.Country.Code 4 Using index select count(*) from CountryLanguage where diff --git a/mysql-test/r/subselect_no_mat.result b/mysql-test/r/subselect_no_mat.result index e84d114124d..5850e9028ce 100644 --- a/mysql-test/r/subselect_no_mat.result +++ b/mysql-test/r/subselect_no_mat.result @@ -17,7 +17,7 @@ select (select 2); 2 explain extended select (select 2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1249 Select 2 was reduced during optimization Note 1003 select 2 AS `(select 2)` @@ -741,7 +741,7 @@ id 1 EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 ref id id 5 const 1 100.00 Using index +1 SIMPLE t2 ref id id 5 const 1 100.00 Using index Warnings: Note 1249 Select 2 was reduced during optimization Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = 1) @@ -753,7 +753,7 @@ id 2 EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 ref id id 5 const 1 100.00 Using where; Using index +1 SIMPLE t2 ref id id 5 const 1 100.00 Using where; Using index Warnings: Note 1249 Select 3 was reduced during optimization Note 1249 Select 2 was reduced during optimization @@ -887,7 +887,7 @@ select 10.5 > ANY (SELECT * from t1); 1 explain extended select (select a+1) from t1; 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 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 Note 1249 Select 2 was reduced during optimization @@ -2973,7 +2973,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`one`,`test`.`t1`.`two`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1` +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`one`,`test`.`t1`.`two`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)))) and trigcond(trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1` explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N'); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 @@ -2985,7 +2985,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`one`,`test`.`t1`.`two`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1` +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<expr_cache><`test`.`t1`.`one`,`test`.`t1`.`two`>(<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)))) and trigcond(trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`)))))) AS `test` from `test`.`t1` DROP TABLE t1,t2; set optimizer_switch=@tmp11867_optimizer_switch; CREATE TABLE t1 (a char(5), b char(5)); @@ -4556,7 +4556,7 @@ int_nokey int_key 0 0 EXPLAIN EXTENDED SELECT * FROM C WHERE `int_key` IN (SELECT `int_nokey`); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY C ALL NULL NULL NULL NULL 20 100.00 Using where +1 SIMPLE C ALL NULL NULL NULL NULL 20 100.00 Using where DROP TABLE C; # End of test for bug#45061. # @@ -6111,7 +6111,7 @@ FROM t1 AS sq4_alias1 WHERE (sq4_alias1.col_varchar_key + NULL) IS NULL OR sq4_alias1.col_varchar_key = @var3 ) AS alias3; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE <derived2> system NULL NULL NULL NULL 0 const row not found +1 PRIMARY <derived2> system NULL NULL NULL NULL 0 const row not found 2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table SELECT * FROM ( SELECT @var3:=12, sq4_alias1.* FROM t1 AS sq4_alias1 @@ -6156,7 +6156,7 @@ FROM t2 AS c_sq1_alias1 WHERE (c_sq1_alias1.col_int_nokey != @var2 OR c_sq1_alias1.pk != @var3)) ) AS alias3; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 DEPENDENT SUBQUERY c_sq1_alias1 system PRIMARY NULL NULL NULL 1 SELECT * FROM ( SELECT sq4_alias1.* FROM t1 AS sq4_alias1 diff --git a/mysql-test/r/subselect_no_opts.result b/mysql-test/r/subselect_no_opts.result index e524505d915..2ac977f4574 100644 --- a/mysql-test/r/subselect_no_opts.result +++ b/mysql-test/r/subselect_no_opts.result @@ -13,7 +13,7 @@ select (select 2); 2 explain extended select (select 2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1249 Select 2 was reduced during optimization Note 1003 select 2 AS `(select 2)` @@ -737,7 +737,7 @@ id 1 EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 ref id id 5 const 1 100.00 Using index +1 SIMPLE t2 ref id id 5 const 1 100.00 Using index Warnings: Note 1249 Select 2 was reduced during optimization Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = 1) @@ -749,7 +749,7 @@ id 2 EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 ref id id 5 const 1 100.00 Using where; Using index +1 SIMPLE t2 ref id id 5 const 1 100.00 Using where; Using index Warnings: Note 1249 Select 3 was reduced during optimization Note 1249 Select 2 was reduced during optimization @@ -883,7 +883,7 @@ select 10.5 > ANY (SELECT * from t1); 1 explain extended select (select a+1) from t1; 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 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 Note 1249 Select 2 was reduced during optimization @@ -2969,7 +2969,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1` +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)))) and trigcond(trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1` explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N'); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 Using where @@ -2981,7 +2981,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1` +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)))) and trigcond(trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1` DROP TABLE t1,t2; set optimizer_switch=@tmp11867_optimizer_switch; CREATE TABLE t1 (a char(5), b char(5)); @@ -4552,7 +4552,7 @@ int_nokey int_key 0 0 EXPLAIN EXTENDED SELECT * FROM C WHERE `int_key` IN (SELECT `int_nokey`); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY C ALL NULL NULL NULL NULL 20 100.00 Using where +1 SIMPLE C ALL NULL NULL NULL NULL 20 100.00 Using where DROP TABLE C; # End of test for bug#45061. # @@ -6107,7 +6107,7 @@ FROM t1 AS sq4_alias1 WHERE (sq4_alias1.col_varchar_key + NULL) IS NULL OR sq4_alias1.col_varchar_key = @var3 ) AS alias3; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE <derived2> system NULL NULL NULL NULL 0 const row not found +1 PRIMARY <derived2> system NULL NULL NULL NULL 0 const row not found 2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table SELECT * FROM ( SELECT @var3:=12, sq4_alias1.* FROM t1 AS sq4_alias1 @@ -6152,7 +6152,7 @@ FROM t2 AS c_sq1_alias1 WHERE (c_sq1_alias1.col_int_nokey != @var2 OR c_sq1_alias1.pk != @var3)) ) AS alias3; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 DEPENDENT SUBQUERY c_sq1_alias1 system PRIMARY NULL NULL NULL 1 SELECT * FROM ( SELECT sq4_alias1.* FROM t1 AS sq4_alias1 diff --git a/mysql-test/r/subselect_no_scache.result b/mysql-test/r/subselect_no_scache.result index 61c8e5fdc53..213eeff5572 100644 --- a/mysql-test/r/subselect_no_scache.result +++ b/mysql-test/r/subselect_no_scache.result @@ -16,7 +16,7 @@ select (select 2); 2 explain extended select (select 2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1249 Select 2 was reduced during optimization Note 1003 select 2 AS `(select 2)` @@ -740,7 +740,7 @@ id 1 EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 ref id id 5 const 1 100.00 Using index +1 SIMPLE t2 ref id id 5 const 1 100.00 Using index Warnings: Note 1249 Select 2 was reduced during optimization Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = 1) @@ -752,7 +752,7 @@ id 2 EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 ref id id 5 const 1 100.00 Using where; Using index +1 SIMPLE t2 ref id id 5 const 1 100.00 Using where; Using index Warnings: Note 1249 Select 3 was reduced during optimization Note 1249 Select 2 was reduced during optimization @@ -886,7 +886,7 @@ select 10.5 > ANY (SELECT * from t1); 1 explain extended select (select a+1) from t1; 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 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 Note 1249 Select 2 was reduced during optimization @@ -2972,7 +2972,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1` +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)))) and trigcond(trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1` explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N'); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 @@ -2985,7 +2985,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where Warnings: -Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1` +Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one`,`test`.`t2`.`two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`)))) and trigcond(trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1` DROP TABLE t1,t2; set optimizer_switch=@tmp11867_optimizer_switch; CREATE TABLE t1 (a char(5), b char(5)); @@ -4560,7 +4560,7 @@ int_nokey int_key 0 0 EXPLAIN EXTENDED SELECT * FROM C WHERE `int_key` IN (SELECT `int_nokey`); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY C ALL NULL NULL NULL NULL 20 100.00 Using where +1 SIMPLE C ALL NULL NULL NULL NULL 20 100.00 Using where DROP TABLE C; # End of test for bug#45061. # @@ -6118,7 +6118,7 @@ FROM t1 AS sq4_alias1 WHERE (sq4_alias1.col_varchar_key + NULL) IS NULL OR sq4_alias1.col_varchar_key = @var3 ) AS alias3; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE <derived2> system NULL NULL NULL NULL 0 const row not found +1 PRIMARY <derived2> system NULL NULL NULL NULL 0 const row not found 2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table SELECT * FROM ( SELECT @var3:=12, sq4_alias1.* FROM t1 AS sq4_alias1 @@ -6163,7 +6163,7 @@ FROM t2 AS c_sq1_alias1 WHERE (c_sq1_alias1.col_int_nokey != @var2 OR c_sq1_alias1.pk != @var3)) ) AS alias3; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 DEPENDENT SUBQUERY c_sq1_alias1 system PRIMARY NULL NULL NULL 1 SELECT * FROM ( SELECT sq4_alias1.* FROM t1 AS sq4_alias1 diff --git a/mysql-test/r/subselect_no_semijoin.result b/mysql-test/r/subselect_no_semijoin.result index afc172350b1..d05a703e647 100644 --- a/mysql-test/r/subselect_no_semijoin.result +++ b/mysql-test/r/subselect_no_semijoin.result @@ -13,7 +13,7 @@ select (select 2); 2 explain extended select (select 2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1249 Select 2 was reduced during optimization Note 1003 select 2 AS `(select 2)` @@ -737,7 +737,7 @@ id 1 EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 ref id id 5 const 1 100.00 Using index +1 SIMPLE t2 ref id id 5 const 1 100.00 Using index Warnings: Note 1249 Select 2 was reduced during optimization Note 1003 select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = 1) @@ -749,7 +749,7 @@ id 2 EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 ref id id 5 const 1 100.00 Using where; Using index +1 SIMPLE t2 ref id id 5 const 1 100.00 Using where; Using index Warnings: Note 1249 Select 3 was reduced during optimization Note 1249 Select 2 was reduced during optimization @@ -883,7 +883,7 @@ select 10.5 > ANY (SELECT * from t1); 1 explain extended select (select a+1) from t1; 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 SIMPLE t1 ALL NULL NULL NULL NULL 3 100.00 Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 Note 1249 Select 2 was reduced during optimization @@ -4552,7 +4552,7 @@ int_nokey int_key 0 0 EXPLAIN EXTENDED SELECT * FROM C WHERE `int_key` IN (SELECT `int_nokey`); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY C ALL NULL NULL NULL NULL 20 100.00 Using where +1 SIMPLE C ALL NULL NULL NULL NULL 20 100.00 Using where DROP TABLE C; # End of test for bug#45061. # @@ -6107,7 +6107,7 @@ FROM t1 AS sq4_alias1 WHERE (sq4_alias1.col_varchar_key + NULL) IS NULL OR sq4_alias1.col_varchar_key = @var3 ) AS alias3; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE <derived2> system NULL NULL NULL NULL 0 const row not found +1 PRIMARY <derived2> system NULL NULL NULL NULL 0 const row not found 2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table SELECT * FROM ( SELECT @var3:=12, sq4_alias1.* FROM t1 AS sq4_alias1 @@ -6152,7 +6152,7 @@ FROM t2 AS c_sq1_alias1 WHERE (c_sq1_alias1.col_int_nokey != @var2 OR c_sq1_alias1.pk != @var3)) ) AS alias3; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 3 DEPENDENT SUBQUERY c_sq1_alias1 system PRIMARY NULL NULL NULL 1 SELECT * FROM ( SELECT sq4_alias1.* FROM t1 AS sq4_alias1 diff --git a/mysql-test/r/subselect_sj.result b/mysql-test/r/subselect_sj.result index 0e028cc7f51..b5263163cb1 100644 --- a/mysql-test/r/subselect_sj.result +++ b/mysql-test/r/subselect_sj.result @@ -803,7 +803,7 @@ EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk 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 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 11 func,func 1 100.00 -2 MATERIALIZED t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Rowid-ordered scan +2 MATERIALIZED t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Using where; Rowid-ordered scan Warnings: Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`pk` > 0)) SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk > 0); @@ -941,9 +941,9 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.t1field 1 Using index EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 2 Using index -1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.t1field 1 Using index -1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.t1field 1 Using index +1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 2 Using index +1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.t1field 1 Using index +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.t1field 1 Using index DROP TABLE t1, t2, t3; DROP VIEW v2, v3; # End of Bug#49198 diff --git a/mysql-test/r/subselect_sj_jcl6.result b/mysql-test/r/subselect_sj_jcl6.result index af91cc3eeac..60e309cdf4a 100644 --- a/mysql-test/r/subselect_sj_jcl6.result +++ b/mysql-test/r/subselect_sj_jcl6.result @@ -816,7 +816,7 @@ EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk 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 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 11 func,func 1 100.00 -2 MATERIALIZED t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Rowid-ordered scan +2 MATERIALIZED t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Using where; Rowid-ordered scan Warnings: Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`pk` > 0)) SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk > 0); @@ -954,9 +954,9 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.t1field 1 Using index EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 2 Using index -1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.t1field 1 Using index -1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.t1field 1 Using index +1 PRIMARY t1 index PRIMARY PRIMARY 4 NULL 2 Using index +1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.t1field 1 Using index +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.t1field 1 Using index DROP TABLE t1, t2, t3; DROP VIEW v2, v3; # End of Bug#49198 diff --git a/mysql-test/r/subselect_sj_mat.result b/mysql-test/r/subselect_sj_mat.result index ba34543c2e3..efe1bcfe066 100644 --- a/mysql-test/r/subselect_sj_mat.result +++ b/mysql-test/r/subselect_sj_mat.result @@ -1511,7 +1511,7 @@ 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; Rowid-ordered scan +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 diff --git a/mysql-test/r/symlink.result b/mysql-test/r/symlink.result index 20736aec47f..279af1e44d2 100644 --- a/mysql-test/r/symlink.result +++ b/mysql-test/r/symlink.result @@ -120,7 +120,7 @@ CREATE TABLE t2(a INT) DATA DIRECTORY='TEST_DIR/tmp' INDEX DIRECTORY='TEST_DIR/tmp'; RENAME TABLE t2 TO t1; -ERROR HY000: Can't create/write to file 'TEST_DIR/tmp/t1.MYI' (Errcode: 17) +ERROR HY000: Can't create/write to file 'TEST_DIR/tmp/t1.MYI' (Errcode: 17 "File exists") DROP TABLE t2; create temporary table t1 (a int) engine=myisam data directory="MYSQLTEST_VARDIR/log" select 9 a; show create table t1; @@ -167,7 +167,7 @@ INDEX DIRECTORY='MYSQLD_DATADIR'; DROP TABLE IF EXISTS t1; CREATE TABLE t1(a INT) INDEX DIRECTORY='TEST_DIR/master-data_var'; -ERROR HY000: Can't create/write to file 'TEST_DIR/master-data_var/t1.MYI' (Errcode: 2) +ERROR HY000: Can't create/write to file 'TEST_DIR/master-data_var/t1.MYI' (Errcode: 2 "No such file or directory") SET @OLD_SQL_MODE=@@SQL_MODE, @@SQL_MODE='NO_DIR_IN_CREATE'; CREATE TABLE t1(a INT) DATA DIRECTORY='MYSQLTEST_VARDIR/tmp' INDEX DIRECTORY='MYSQLTEST_VARDIR/tmp'; Warnings: diff --git a/mysql-test/r/system_mysql_db.result b/mysql-test/r/system_mysql_db.result index d5409136ed4..c952426fc5a 100644 --- a/mysql-test/r/system_mysql_db.result +++ b/mysql-test/r/system_mysql_db.result @@ -1,22 +1,27 @@ show tables; Tables_in_db +column_stats columns_priv db event func general_log +gtid_slave_pos help_category help_keyword help_relation help_topic host +index_stats ndb_binlog_index plugin proc procs_priv proxies_priv +roles_mapping servers slow_log +table_stats tables_priv time_zone time_zone_leap_second @@ -29,7 +34,7 @@ Table Create Table db CREATE TABLE `db` ( `Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '', `Db` char(64) COLLATE utf8_bin NOT NULL DEFAULT '', - `User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '', + `User` char(80) COLLATE utf8_bin NOT NULL DEFAULT '', `Select_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N', `Insert_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N', `Update_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N', @@ -81,7 +86,7 @@ show create table user; Table Create Table user CREATE TABLE `user` ( `Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '', - `User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '', + `User` char(80) COLLATE utf8_bin NOT NULL DEFAULT '', `Password` char(41) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '', `Select_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N', `Insert_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N', @@ -122,6 +127,7 @@ user CREATE TABLE `user` ( `max_user_connections` int(11) NOT NULL DEFAULT '0', `plugin` char(64) CHARACTER SET latin1 NOT NULL DEFAULT '', `authentication_string` text COLLATE utf8_bin NOT NULL, + `is_role` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N', PRIMARY KEY (`Host`,`User`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Users and global privileges' show create table func; @@ -138,9 +144,9 @@ Table Create Table tables_priv CREATE TABLE `tables_priv` ( `Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '', `Db` char(64) COLLATE utf8_bin NOT NULL DEFAULT '', - `User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '', + `User` char(80) COLLATE utf8_bin NOT NULL DEFAULT '', `Table_name` char(64) COLLATE utf8_bin NOT NULL DEFAULT '', - `Grantor` char(77) COLLATE utf8_bin NOT NULL DEFAULT '', + `Grantor` char(141) COLLATE utf8_bin NOT NULL DEFAULT '', `Timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `Table_priv` set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger') CHARACTER SET utf8 NOT NULL DEFAULT '', `Column_priv` set('Select','Insert','Update','References') CHARACTER SET utf8 NOT NULL DEFAULT '', @@ -152,7 +158,7 @@ Table Create Table columns_priv CREATE TABLE `columns_priv` ( `Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '', `Db` char(64) COLLATE utf8_bin NOT NULL DEFAULT '', - `User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '', + `User` char(80) COLLATE utf8_bin NOT NULL DEFAULT '', `Table_name` char(64) COLLATE utf8_bin NOT NULL DEFAULT '', `Column_name` char(64) COLLATE utf8_bin NOT NULL DEFAULT '', `Timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, @@ -164,10 +170,10 @@ Table Create Table procs_priv CREATE TABLE `procs_priv` ( `Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '', `Db` char(64) COLLATE utf8_bin NOT NULL DEFAULT '', - `User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '', + `User` char(80) COLLATE utf8_bin NOT NULL DEFAULT '', `Routine_name` char(64) CHARACTER SET utf8 NOT NULL DEFAULT '', `Routine_type` enum('FUNCTION','PROCEDURE') COLLATE utf8_bin NOT NULL, - `Grantor` char(77) COLLATE utf8_bin NOT NULL DEFAULT '', + `Grantor` char(141) COLLATE utf8_bin NOT NULL DEFAULT '', `Proc_priv` set('Execute','Alter Routine','Grant') CHARACTER SET utf8 NOT NULL DEFAULT '', `Timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`Host`,`Db`,`User`,`Routine_name`,`Routine_type`), @@ -179,7 +185,7 @@ servers CREATE TABLE `servers` ( `Server_name` char(64) NOT NULL DEFAULT '', `Host` char(64) NOT NULL DEFAULT '', `Db` char(64) NOT NULL DEFAULT '', - `Username` char(64) NOT NULL DEFAULT '', + `Username` char(80) NOT NULL DEFAULT '', `Password` char(64) NOT NULL DEFAULT '', `Port` int(4) NOT NULL DEFAULT '0', `Socket` char(64) NOT NULL DEFAULT '', @@ -201,7 +207,7 @@ proc CREATE TABLE `proc` ( `param_list` blob NOT NULL, `returns` longblob NOT NULL, `body` longblob NOT NULL, - `definer` char(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', + `definer` char(141) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `modified` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `sql_mode` set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','IGNORE_BAD_TABLE_OPTIONS','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH') NOT NULL DEFAULT '', @@ -218,7 +224,7 @@ event CREATE TABLE `event` ( `db` char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `name` char(64) NOT NULL DEFAULT '', `body` longblob NOT NULL, - `definer` char(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', + `definer` char(141) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `execute_at` datetime DEFAULT NULL, `interval_value` int(11) DEFAULT NULL, `interval_field` enum('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK','SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR','DAY_MINUTE','DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND','DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND','SECOND_MICROSECOND') DEFAULT NULL, @@ -242,7 +248,7 @@ event CREATE TABLE `event` ( show create table general_log; Table Create Table general_log CREATE TABLE `general_log` ( - `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `user_host` mediumtext NOT NULL, `thread_id` int(11) NOT NULL, `server_id` int(10) unsigned NOT NULL, @@ -252,7 +258,7 @@ general_log CREATE TABLE `general_log` ( show create table slow_log; Table Create Table slow_log CREATE TABLE `slow_log` ( - `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `user_host` mediumtext NOT NULL, `query_time` time(6) NOT NULL, `lock_time` time(6) NOT NULL, @@ -264,5 +270,39 @@ slow_log CREATE TABLE `slow_log` ( `server_id` int(10) unsigned NOT NULL, `sql_text` mediumtext NOT NULL ) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log' +show create table table_stats; +Table Create Table +table_stats CREATE TABLE `table_stats` ( + `db_name` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `cardinality` bigint(21) unsigned DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Tables' +show create table column_stats; +Table Create Table +column_stats CREATE TABLE `column_stats` ( + `db_name` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `column_name` varchar(64) COLLATE utf8_bin NOT NULL, + `min_value` varchar(255) COLLATE utf8_bin DEFAULT NULL, + `max_value` varchar(255) COLLATE utf8_bin DEFAULT NULL, + `nulls_ratio` decimal(12,4) DEFAULT NULL, + `avg_length` decimal(12,4) DEFAULT NULL, + `avg_frequency` decimal(12,4) DEFAULT NULL, + `hist_size` tinyint(3) unsigned DEFAULT NULL, + `hist_type` enum('SINGLE_PREC_HB','DOUBLE_PREC_HB') COLLATE utf8_bin DEFAULT NULL, + `histogram` varbinary(255) DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`,`column_name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Columns' +show create table index_stats; +Table Create Table +index_stats CREATE TABLE `index_stats` ( + `db_name` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `index_name` varchar(64) COLLATE utf8_bin NOT NULL, + `prefix_arity` int(11) unsigned NOT NULL, + `avg_frequency` decimal(12,4) DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`,`index_name`,`prefix_arity`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Indexes' show tables; Tables_in_test diff --git a/mysql-test/r/system_mysql_db_fix40123.result b/mysql-test/r/system_mysql_db_fix40123.result index d5409136ed4..2746a7e04cc 100644 --- a/mysql-test/r/system_mysql_db_fix40123.result +++ b/mysql-test/r/system_mysql_db_fix40123.result @@ -1,22 +1,27 @@ show tables; Tables_in_db +column_stats columns_priv db event func general_log +gtid_slave_pos help_category help_keyword help_relation help_topic host +index_stats ndb_binlog_index plugin proc procs_priv proxies_priv +roles_mapping servers slow_log +table_stats tables_priv time_zone time_zone_leap_second @@ -120,6 +125,7 @@ user CREATE TABLE `user` ( `max_updates` int(11) unsigned NOT NULL DEFAULT '0', `max_connections` int(11) unsigned NOT NULL DEFAULT '0', `max_user_connections` int(11) NOT NULL DEFAULT '0', + `is_role` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N', `plugin` char(64) CHARACTER SET latin1 NOT NULL DEFAULT '', `authentication_string` text COLLATE utf8_bin NOT NULL, PRIMARY KEY (`Host`,`User`) @@ -164,10 +170,10 @@ Table Create Table procs_priv CREATE TABLE `procs_priv` ( `Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '', `Db` char(64) COLLATE utf8_bin NOT NULL DEFAULT '', - `User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '', + `User` char(80) COLLATE utf8_bin NOT NULL DEFAULT '', `Routine_name` char(64) CHARACTER SET utf8 NOT NULL DEFAULT '', `Routine_type` enum('FUNCTION','PROCEDURE') COLLATE utf8_bin NOT NULL, - `Grantor` char(77) COLLATE utf8_bin NOT NULL DEFAULT '', + `Grantor` char(141) COLLATE utf8_bin NOT NULL DEFAULT '', `Proc_priv` set('Execute','Alter Routine','Grant') CHARACTER SET utf8 NOT NULL DEFAULT '', `Timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`Host`,`Db`,`User`,`Routine_name`,`Routine_type`), @@ -179,7 +185,7 @@ servers CREATE TABLE `servers` ( `Server_name` char(64) NOT NULL DEFAULT '', `Host` char(64) NOT NULL DEFAULT '', `Db` char(64) NOT NULL DEFAULT '', - `Username` char(64) NOT NULL DEFAULT '', + `Username` char(80) NOT NULL DEFAULT '', `Password` char(64) NOT NULL DEFAULT '', `Port` int(4) NOT NULL DEFAULT '0', `Socket` char(64) NOT NULL DEFAULT '', @@ -218,7 +224,7 @@ event CREATE TABLE `event` ( `db` char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `name` char(64) NOT NULL DEFAULT '', `body` longblob NOT NULL, - `definer` char(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', + `definer` char(141) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `execute_at` datetime DEFAULT NULL, `interval_value` int(11) DEFAULT NULL, `interval_field` enum('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK','SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR','DAY_MINUTE','DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND','DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND','SECOND_MICROSECOND') DEFAULT NULL, @@ -242,7 +248,7 @@ event CREATE TABLE `event` ( show create table general_log; Table Create Table general_log CREATE TABLE `general_log` ( - `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `user_host` mediumtext NOT NULL, `thread_id` int(11) NOT NULL, `server_id` int(10) unsigned NOT NULL, @@ -252,7 +258,7 @@ general_log CREATE TABLE `general_log` ( show create table slow_log; Table Create Table slow_log CREATE TABLE `slow_log` ( - `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `user_host` mediumtext NOT NULL, `query_time` time(6) NOT NULL, `lock_time` time(6) NOT NULL, @@ -264,5 +270,36 @@ slow_log CREATE TABLE `slow_log` ( `server_id` int(10) unsigned NOT NULL, `sql_text` mediumtext NOT NULL ) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log' +show create table table_stats; +Table Create Table +table_stats CREATE TABLE `table_stats` ( + `db_name` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `cardinality` bigint(21) unsigned DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Tables' +show create table column_stats; +Table Create Table +column_stats CREATE TABLE `column_stats` ( + `db_name` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `column_name` varchar(64) COLLATE utf8_bin NOT NULL, + `min_value` varchar(255) COLLATE utf8_bin DEFAULT NULL, + `max_value` varchar(255) COLLATE utf8_bin DEFAULT NULL, + `nulls_ratio` double DEFAULT NULL, + `avg_length` double DEFAULT NULL, + `avg_frequency` double DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`,`column_name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Columns' +show create table index_stats; +Table Create Table +index_stats CREATE TABLE `index_stats` ( + `db_name` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `index_name` varchar(64) COLLATE utf8_bin NOT NULL, + `prefix_arity` int(11) unsigned NOT NULL, + `avg_frequency` double DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`,`index_name`,`prefix_arity`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Indexes' show tables; Tables_in_test diff --git a/mysql-test/r/system_mysql_db_fix50030.result b/mysql-test/r/system_mysql_db_fix50030.result index d5409136ed4..e81cc319468 100644 --- a/mysql-test/r/system_mysql_db_fix50030.result +++ b/mysql-test/r/system_mysql_db_fix50030.result @@ -1,22 +1,27 @@ show tables; Tables_in_db +column_stats columns_priv db event func general_log +gtid_slave_pos help_category help_keyword help_relation help_topic host +index_stats ndb_binlog_index plugin proc procs_priv proxies_priv +roles_mapping servers slow_log +table_stats tables_priv time_zone time_zone_leap_second @@ -120,6 +125,7 @@ user CREATE TABLE `user` ( `max_updates` int(11) unsigned NOT NULL DEFAULT '0', `max_connections` int(11) unsigned NOT NULL DEFAULT '0', `max_user_connections` int(11) NOT NULL DEFAULT '0', + `is_role` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N', `plugin` char(64) CHARACTER SET latin1 NOT NULL DEFAULT '', `authentication_string` text COLLATE utf8_bin NOT NULL, PRIMARY KEY (`Host`,`User`) @@ -218,7 +224,7 @@ event CREATE TABLE `event` ( `db` char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `name` char(64) NOT NULL DEFAULT '', `body` longblob NOT NULL, - `definer` char(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', + `definer` char(141) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `execute_at` datetime DEFAULT NULL, `interval_value` int(11) DEFAULT NULL, `interval_field` enum('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK','SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR','DAY_MINUTE','DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND','DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND','SECOND_MICROSECOND') DEFAULT NULL, @@ -242,7 +248,7 @@ event CREATE TABLE `event` ( show create table general_log; Table Create Table general_log CREATE TABLE `general_log` ( - `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `user_host` mediumtext NOT NULL, `thread_id` int(11) NOT NULL, `server_id` int(10) unsigned NOT NULL, @@ -252,7 +258,7 @@ general_log CREATE TABLE `general_log` ( show create table slow_log; Table Create Table slow_log CREATE TABLE `slow_log` ( - `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `user_host` mediumtext NOT NULL, `query_time` time(6) NOT NULL, `lock_time` time(6) NOT NULL, @@ -264,5 +270,36 @@ slow_log CREATE TABLE `slow_log` ( `server_id` int(10) unsigned NOT NULL, `sql_text` mediumtext NOT NULL ) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log' +show create table table_stats; +Table Create Table +table_stats CREATE TABLE `table_stats` ( + `db_name` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `cardinality` bigint(21) unsigned DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Tables' +show create table column_stats; +Table Create Table +column_stats CREATE TABLE `column_stats` ( + `db_name` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `column_name` varchar(64) COLLATE utf8_bin NOT NULL, + `min_value` varchar(255) COLLATE utf8_bin DEFAULT NULL, + `max_value` varchar(255) COLLATE utf8_bin DEFAULT NULL, + `nulls_ratio` double DEFAULT NULL, + `avg_length` double DEFAULT NULL, + `avg_frequency` double DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`,`column_name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Columns' +show create table index_stats; +Table Create Table +index_stats CREATE TABLE `index_stats` ( + `db_name` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `index_name` varchar(64) COLLATE utf8_bin NOT NULL, + `prefix_arity` int(11) unsigned NOT NULL, + `avg_frequency` double DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`,`index_name`,`prefix_arity`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Indexes' show tables; Tables_in_test diff --git a/mysql-test/r/system_mysql_db_fix50117.result b/mysql-test/r/system_mysql_db_fix50117.result index d5409136ed4..3c811f78a4f 100644 --- a/mysql-test/r/system_mysql_db_fix50117.result +++ b/mysql-test/r/system_mysql_db_fix50117.result @@ -1,22 +1,27 @@ show tables; Tables_in_db +column_stats columns_priv db event func general_log +gtid_slave_pos help_category help_keyword help_relation help_topic host +index_stats ndb_binlog_index plugin proc procs_priv proxies_priv +roles_mapping servers slow_log +table_stats tables_priv time_zone time_zone_leap_second @@ -120,6 +125,7 @@ user CREATE TABLE `user` ( `max_updates` int(11) unsigned NOT NULL DEFAULT '0', `max_connections` int(11) unsigned NOT NULL DEFAULT '0', `max_user_connections` int(11) NOT NULL DEFAULT '0', + `is_role` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N', `plugin` char(64) CHARACTER SET latin1 NOT NULL DEFAULT '', `authentication_string` text COLLATE utf8_bin NOT NULL, PRIMARY KEY (`Host`,`User`) @@ -242,7 +248,7 @@ event CREATE TABLE `event` ( show create table general_log; Table Create Table general_log CREATE TABLE `general_log` ( - `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `event_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `user_host` mediumtext NOT NULL, `thread_id` int(11) NOT NULL, `server_id` int(10) unsigned NOT NULL, @@ -252,7 +258,7 @@ general_log CREATE TABLE `general_log` ( show create table slow_log; Table Create Table slow_log CREATE TABLE `slow_log` ( - `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `start_time` timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), `user_host` mediumtext NOT NULL, `query_time` time(6) NOT NULL, `lock_time` time(6) NOT NULL, @@ -264,5 +270,36 @@ slow_log CREATE TABLE `slow_log` ( `server_id` int(10) unsigned NOT NULL, `sql_text` mediumtext NOT NULL ) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log' +show create table table_stats; +Table Create Table +table_stats CREATE TABLE `table_stats` ( + `db_name` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `cardinality` bigint(21) unsigned DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Tables' +show create table column_stats; +Table Create Table +column_stats CREATE TABLE `column_stats` ( + `db_name` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `column_name` varchar(64) COLLATE utf8_bin NOT NULL, + `min_value` varchar(255) COLLATE utf8_bin DEFAULT NULL, + `max_value` varchar(255) COLLATE utf8_bin DEFAULT NULL, + `nulls_ratio` double DEFAULT NULL, + `avg_length` double DEFAULT NULL, + `avg_frequency` double DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`,`column_name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Columns' +show create table index_stats; +Table Create Table +index_stats CREATE TABLE `index_stats` ( + `db_name` varchar(64) COLLATE utf8_bin NOT NULL, + `table_name` varchar(64) COLLATE utf8_bin NOT NULL, + `index_name` varchar(64) COLLATE utf8_bin NOT NULL, + `prefix_arity` int(11) unsigned NOT NULL, + `avg_frequency` double DEFAULT NULL, + PRIMARY KEY (`db_name`,`table_name`,`index_name`,`prefix_arity`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Statistics on Indexes' show tables; Tables_in_test diff --git a/mysql-test/r/table_elim.result b/mysql-test/r/table_elim.result index 3b4d64c1bfa..ff488fea427 100644 --- a/mysql-test/r/table_elim.result +++ b/mysql-test/r/table_elim.result @@ -119,27 +119,27 @@ t2 where id=f.id); This should use one table: explain select id from v1 where id=2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE f const PRIMARY PRIMARY 4 const 1 Using index +1 PRIMARY f const PRIMARY PRIMARY 4 const 1 Using index This should use one table: explain extended select id from v1 where id in (1,2,3,4); id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE f range PRIMARY PRIMARY 4 NULL 4 100.00 Using where; Using index +1 PRIMARY f range PRIMARY PRIMARY 4 NULL 4 100.00 Using where; Using index Warnings: Note 1276 Field or reference 'test.a2.id' of SELECT #3 was resolved in SELECT #2 Note 1003 select `f`.`id` AS `id` from `test`.`t0` `f` where (`f`.`id` in (1,2,3,4)) This should use facts and a1 tables: explain extended select id from v1 where attr1 between 12 and 14; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE a1 range PRIMARY,attr1 attr1 5 NULL 2 100.00 Using index condition -1 SIMPLE f eq_ref PRIMARY PRIMARY 4 test.a1.id 1 100.00 Using index +1 PRIMARY a1 range PRIMARY,attr1 attr1 5 NULL 2 100.00 Using index condition +1 PRIMARY f eq_ref PRIMARY PRIMARY 4 test.a1.id 1 100.00 Using index Warnings: Note 1276 Field or reference 'test.a2.id' of SELECT #3 was resolved in SELECT #2 Note 1003 select `f`.`id` AS `id` from `test`.`t0` `f` join `test`.`t1` `a1` where ((`f`.`id` = `a1`.`id`) and (`a1`.`attr1` between 12 and 14)) This should use facts, a2 and its subquery: explain extended select id from v1 where attr2 between 12 and 14; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE a2 range PRIMARY,attr2 attr2 5 NULL 5 100.00 Using index condition; Using where -1 SIMPLE f eq_ref PRIMARY PRIMARY 4 test.a2.id 1 100.00 Using index +1 PRIMARY a2 range PRIMARY,attr2 attr2 5 NULL 5 100.00 Using index condition; Using where +1 PRIMARY f eq_ref PRIMARY PRIMARY 4 test.a2.id 1 100.00 Using index 3 DEPENDENT SUBQUERY t2 ref PRIMARY PRIMARY 4 test.a2.id 2 100.00 Using index Warnings: Note 1276 Field or reference 'test.a2.id' of SELECT #3 was resolved in SELECT #2 @@ -147,27 +147,27 @@ Note 1003 select `f`.`id` AS `id` from `test`.`t0` `f` join `test`.`t2` `a2` whe This should use one table: explain select id from v2 where id=2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE f const PRIMARY PRIMARY 4 const 1 Using index +1 PRIMARY f const PRIMARY PRIMARY 4 const 1 Using index This should use one table: explain extended select id from v2 where id in (1,2,3,4); id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE f range PRIMARY PRIMARY 4 NULL 4 100.00 Using where; Using index +1 PRIMARY f range PRIMARY PRIMARY 4 NULL 4 100.00 Using where; Using index Warnings: Note 1276 Field or reference 'test.f.id' of SELECT #3 was resolved in SELECT #2 Note 1003 select `f`.`id` AS `id` from `test`.`t0` `f` where (`f`.`id` in (1,2,3,4)) This should use facts and a1 tables: explain extended select id from v2 where attr1 between 12 and 14; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE a1 range PRIMARY,attr1 attr1 5 NULL 2 100.00 Using index condition -1 SIMPLE f eq_ref PRIMARY PRIMARY 4 test.a1.id 1 100.00 Using index +1 PRIMARY a1 range PRIMARY,attr1 attr1 5 NULL 2 100.00 Using index condition +1 PRIMARY f eq_ref PRIMARY PRIMARY 4 test.a1.id 1 100.00 Using index Warnings: Note 1276 Field or reference 'test.f.id' of SELECT #3 was resolved in SELECT #2 Note 1003 select `f`.`id` AS `id` from `test`.`t0` `f` join `test`.`t1` `a1` where ((`f`.`id` = `a1`.`id`) and (`a1`.`attr1` between 12 and 14)) This should use facts, a2 and its subquery: explain extended select id from v2 where attr2 between 12 and 14; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE a2 range PRIMARY,attr2 attr2 5 NULL 5 100.00 Using index condition -1 SIMPLE f eq_ref PRIMARY PRIMARY 4 test.a2.id 1 100.00 Using where; Using index +1 PRIMARY a2 range PRIMARY,attr2 attr2 5 NULL 5 100.00 Using index condition +1 PRIMARY f eq_ref PRIMARY PRIMARY 4 test.a2.id 1 100.00 Using where; Using index 3 DEPENDENT SUBQUERY t2 ref PRIMARY PRIMARY 4 test.f.id 2 100.00 Using index Warnings: Note 1276 Field or reference 'test.f.id' of SELECT #3 was resolved in SELECT #2 diff --git a/mysql-test/r/testdb_only.require b/mysql-test/r/testdb_only.require deleted file mode 100644 index e717418fdb6..00000000000 --- a/mysql-test/r/testdb_only.require +++ /dev/null @@ -1,2 +0,0 @@ -Variable_name Value -use extern server NO diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result index 6047d00c858..b3965bef008 100644 --- a/mysql-test/r/trigger.result +++ b/mysql-test/r/trigger.result @@ -969,7 +969,7 @@ trigger_schema trigger_name event_object_schema event_object_table action_statem test t1_bi test t1 set @a:=new.id test t1_ai test t1 set @b:=new.id rename table t1 to t2; -ERROR HY000: Can't create/write to file './test/t1_ai.TRN~' (Errcode: 13) +ERROR HY000: Can't create/write to file './test/t1_ai.TRN~' (Errcode: 13 "Permission denied") insert into t1 values (102); select @a, @b; @a @b @@ -1163,9 +1163,9 @@ DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t2; CREATE TABLE t1(c INT); CREATE TABLE t2(c INT); -CREATE DEFINER=1234567890abcdefGHIKL@localhost +CREATE DEFINER=longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW SET @a = 1; -ERROR HY000: String '1234567890abcdefGHIKL' is too long for user name (should be no longer than 16) +ERROR HY000: String 'longer_than_80_4567890123456789012345678901234567890123456789012345678' is too long for user name (should be no longer than 80) CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY TRIGGER t2_bi BEFORE INSERT ON t2 FOR EACH ROW SET @a = 2; ERROR HY000: String '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY' is too long for host name (should be no longer than 60) diff --git a/mysql-test/r/trigger_notembedded.result b/mysql-test/r/trigger_notembedded.result index d94713cbe02..3349d5b007b 100644 --- a/mysql-test/r/trigger_notembedded.result +++ b/mysql-test/r/trigger_notembedded.result @@ -162,7 +162,7 @@ SELECT trigger_name, definer FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_n trigger_name definer trg1 trg2 @ -trg3 @abc@def@@ +trg3 @abc@def@@% trg4 @hostname trg5 @abcdef@@@hostname @@ -170,7 +170,7 @@ SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name; TRIGGER_CATALOG TRIGGER_SCHEMA TRIGGER_NAME EVENT_MANIPULATION EVENT_OBJECT_CATALOG EVENT_OBJECT_SCHEMA EVENT_OBJECT_TABLE ACTION_ORDER ACTION_CONDITION ACTION_STATEMENT ACTION_ORIENTATION ACTION_TIMING ACTION_REFERENCE_OLD_TABLE ACTION_REFERENCE_NEW_TABLE ACTION_REFERENCE_OLD_ROW ACTION_REFERENCE_NEW_ROW CREATED SQL_MODE DEFINER CHARACTER_SET_CLIENT COLLATION_CONNECTION DATABASE_COLLATION def mysqltest_db1 trg1 INSERT def mysqltest_db1 t1 0 NULL SET @a = 1 ROW BEFORE NULL NULL OLD NEW NULL latin1 latin1_swedish_ci latin1_swedish_ci def mysqltest_db1 trg2 INSERT def mysqltest_db1 t1 0 NULL SET @a = 2 ROW AFTER NULL NULL OLD NEW NULL @ latin1 latin1_swedish_ci latin1_swedish_ci -def mysqltest_db1 trg3 UPDATE def mysqltest_db1 t1 0 NULL SET @a = 3 ROW BEFORE NULL NULL OLD NEW NULL @abc@def@@ latin1 latin1_swedish_ci latin1_swedish_ci +def mysqltest_db1 trg3 UPDATE def mysqltest_db1 t1 0 NULL SET @a = 3 ROW BEFORE NULL NULL OLD NEW NULL @abc@def@@% latin1 latin1_swedish_ci latin1_swedish_ci def mysqltest_db1 trg4 UPDATE def mysqltest_db1 t1 0 NULL SET @a = 4 ROW AFTER NULL NULL OLD NEW NULL @hostname latin1 latin1_swedish_ci latin1_swedish_ci def mysqltest_db1 trg5 DELETE def mysqltest_db1 t1 0 NULL SET @a = 5 ROW BEFORE NULL NULL OLD NEW NULL @abcdef@@@hostname latin1 latin1_swedish_ci latin1_swedish_ci diff --git a/mysql-test/r/truncate_badse.result b/mysql-test/r/truncate_badse.result new file mode 100644 index 00000000000..16f44f180ed --- /dev/null +++ b/mysql-test/r/truncate_badse.result @@ -0,0 +1,13 @@ +install plugin example soname 'ha_example'; +create table t1 (a int) engine=example; +select 1; +1 +1 +uninstall plugin example; +flush tables; +select count(*) from information_schema.plugins where plugin_name='example'; +count(*) +0 +truncate table t1; +ERROR 42000: Unknown storage engine 'EXAMPLE' +drop table t1; diff --git a/mysql-test/r/type_timestamp.result b/mysql-test/r/type_timestamp.result index 52c7f05839e..e7add0d80a7 100644 --- a/mysql-test/r/type_timestamp.result +++ b/mysql-test/r/type_timestamp.result @@ -148,15 +148,15 @@ ix+0 20030101000000 drop table t1; create table t1 (t1 timestamp, t2 timestamp default now()); -ERROR HY000: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause +drop table t1; create table t1 (t1 timestamp, t2 timestamp on update now()); -ERROR HY000: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause +drop table t1; create table t1 (t1 timestamp, t2 timestamp default now() on update now()); -ERROR HY000: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause +drop table t1; create table t1 (t1 timestamp default now(), t2 timestamp on update now()); -ERROR HY000: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause +drop table t1; create table t1 (t1 timestamp on update now(), t2 timestamp default now() on update now()); -ERROR HY000: Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause +drop table t1; create table t1 (t1 timestamp default '2003-01-01 00:00:00', t2 datetime, t3 timestamp); SET TIMESTAMP=1000000000; insert into t1 values (); diff --git a/mysql-test/r/type_timestamp_hires.result b/mysql-test/r/type_timestamp_hires.result index 3f1e05f4870..cc2cb6a403d 100644 --- a/mysql-test/r/type_timestamp_hires.result +++ b/mysql-test/r/type_timestamp_hires.result @@ -63,15 +63,15 @@ a show create table t1; Table Create Table t1 CREATE TABLE `t1` ( - `a` timestamp(4) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + `a` timestamp(4) NOT NULL DEFAULT CURRENT_TIMESTAMP(4) ON UPDATE CURRENT_TIMESTAMP(4) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 show columns from t1; Field Type Null Key Default Extra -a timestamp(4) NO CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP +a timestamp(4) NO CURRENT_TIMESTAMP(4) on update CURRENT_TIMESTAMP select table_name, column_name, column_default, is_nullable, data_type, character_maximum_length, character_octet_length, numeric_precision, numeric_scale, datetime_precision, character_set_name, collation_name, column_type, column_key, extra from information_schema.columns where table_name='t1'; table_name t1 column_name a -column_default CURRENT_TIMESTAMP +column_default CURRENT_TIMESTAMP(4) is_nullable NO data_type timestamp character_maximum_length NULL @@ -113,7 +113,7 @@ t2 CREATE TABLE `t2` ( show create table t3; Table Create Table t3 CREATE TABLE `t3` ( - `a` timestamp(4) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + `a` timestamp(4) NOT NULL DEFAULT CURRENT_TIMESTAMP(4) ON UPDATE CURRENT_TIMESTAMP(4) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 drop table t2, t3; insert t1 values ('2010-12-13 14:15:16.222222'); @@ -278,3 +278,23 @@ select * from t1; a 2011-01-01 01:01:01.12345 drop table t1; +create table t1 (a timestamp(5) default current_timestamp); +drop table t1; +create table t1 (a timestamp(5) default current_timestamp()); +drop table t1; +create table t1 (a timestamp(5) default current_timestamp(2)); +ERROR 42000: Invalid default value for 'a' +create table t1 (a timestamp(5) default current_timestamp(5)); +drop table t1; +create table t1 (a timestamp(5) default current_timestamp(6)); +drop table t1; +create table t1 (a timestamp(5) on update current_timestamp); +drop table t1; +create table t1 (a timestamp(5) on update current_timestamp()); +drop table t1; +create table t1 (a timestamp(5) on update current_timestamp(3)); +ERROR HY000: Invalid ON UPDATE clause for 'a' column +create table t1 (a timestamp(5) on update current_timestamp(5)); +drop table t1; +create table t1 (a timestamp(5) on update current_timestamp(6)); +drop table t1; diff --git a/mysql-test/r/upgrade.result b/mysql-test/r/upgrade.result index ec63cc0d98c..48f0cd4ffb5 100644 --- a/mysql-test/r/upgrade.result +++ b/mysql-test/r/upgrade.result @@ -1,3 +1,4 @@ +call mtr.add_suppression("Invalid .old.. table or database name"); drop database if exists `mysqltest1`; drop database if exists `mysqltest-1`; drop database if exists `#mysql50#mysqltest-1`; @@ -33,26 +34,28 @@ show create database `#mysql50#mysqltest-1`; ERROR 42000: Unknown database '#mysql50#mysqltest-1' show tables in `mysqltest1`; Tables_in_mysqltest1 -t1 t-1 +t1 show tables in `mysqltest-1`; Tables_in_mysqltest-1 -t1 t-1 +t1 drop database `mysqltest1`; drop database `mysqltest-1`; -drop table if exists `txu@0023p@0023p1`; -drop table if exists `txu#p#p1`; create table `txu#p#p1` (s1 int); insert into `txu#p#p1` values (1); select * from `txu@0023p@0023p1`; ERROR 42S02: Table 'test.txu@0023p@0023p1' doesn't exist create table `txu@0023p@0023p1` (s1 int); -ERROR 42S01: Table '#mysql50#txu@0023p@0023p1' already exists +show tables; +Tables_in_test +txu#p#p1 +txu@0023p@0023p1 select * from `txu#p#p1`; s1 1 drop table `txu#p#p1`; +drop table `txu@0023p@0023p1`; # # Bug#37631 Incorrect key file for table after upgrading from 5.0 to 5.1 # diff --git a/mysql-test/r/user_var-binlog.result b/mysql-test/r/user_var-binlog.result index 8aae1bca4f6..eaaf5c39ec4 100644 --- a/mysql-test/r/user_var-binlog.result +++ b/mysql-test/r/user_var-binlog.result @@ -8,11 +8,11 @@ SET @var2=char(ascii('a')); insert into t1 values (@var1),(@var2); show binlog events from <binlog_start>; Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # User var # # @`a b`=_latin1 X'68656C6C6F' COLLATE latin1_swedish_ci master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES(@`a b`) master-bin.000001 # Query # # COMMIT -master-bin.000001 # Query # # BEGIN +master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # User var # # @`var1`=_latin1 X'273B616161' COLLATE latin1_swedish_ci master-bin.000001 # User var # # @`var2`=_binary X'61' COLLATE binary master-bin.000001 # Query # # use `test`; insert into t1 values (@var1),(@var2) @@ -23,6 +23,10 @@ flush logs; /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/; DELIMITER /*!*/; ROLLBACK/*!*/; +BEGIN +/*!*/; +SET @`a b`:=_latin1 X'68656C6C6F' COLLATE `latin1_swedish_ci`/*!*/; +use `test`/*!*/; SET TIMESTAMP=10000/*!*/; SET @@session.pseudo_thread_id=999999999/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; @@ -32,17 +36,11 @@ SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/ 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/*!*/; -BEGIN -/*!*/; -SET @`a b`:=_latin1 X'68656C6C6F' COLLATE `latin1_swedish_ci`/*!*/; -use `test`/*!*/; -SET TIMESTAMP=10000/*!*/; INSERT INTO t1 VALUES(@`a b`) /*!*/; SET TIMESTAMP=10000/*!*/; COMMIT /*!*/; -SET TIMESTAMP=10000/*!*/; BEGIN /*!*/; SET @`var1`:=_latin1 X'273B616161' COLLATE `latin1_swedish_ci`/*!*/; diff --git a/mysql-test/r/user_var.result b/mysql-test/r/user_var.result index 2a3cdc49802..178f9fb7db4 100644 --- a/mysql-test/r/user_var.result +++ b/mysql-test/r/user_var.result @@ -126,14 +126,14 @@ select @a+0, @a:=@a+0+count(*), count(*), @a+0 from t1 group by i; set @a=0; select @a,@a:="hello",@a,@a:=3,@a,@a:="hello again" from t1 group by i; @a @a:="hello" @a @a:=3 @a @a:="hello again" -0 hello 0 3 0 hello again -0 hello 0 3 0 hello again -0 hello 0 3 0 hello again +0 hello 0 3 3 hello again +0 hello 0 3 3 hello again +0 hello 0 3 3 hello again select @a,@a:="hello",@a,@a:=3,@a,@a:="hello again" from t1 group by i; @a @a:="hello" @a @a:=3 @a @a:="hello again" -hello again hello hello again 3 hello again hello again -hello again hello hello again 3 hello again hello again -hello again hello hello again 3 hello again hello again +hello again hello hello 3 3 hello again +hello again hello hello 3 3 hello again +hello again hello hello 3 3 hello again drop table t1; set @a=_latin2'test'; select charset(@a),collation(@a),coercibility(@a); @@ -526,4 +526,47 @@ f1 f2 1 4 DROP TRIGGER trg1; DROP TABLE t1; +# +# Bug #12408412: GROUP_CONCAT + ORDER BY + INPUT/OUTPUT +# SAME USER VARIABLE = CRASH +# +SET @bug12408412=1; +SELECT GROUP_CONCAT(@bug12408412 ORDER BY 1) INTO @bug12408412; +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUES (0); +SELECT DISTINCT POW(COUNT(*), @a:=(SELECT 1 FROM t1 LEFT JOIN t1 AS t2 ON @a)) +AS b FROM t1 GROUP BY a; +b +1 +SELECT @a; +@a +1 +DROP TABLE t1; +CREATE TABLE t1(f1 INT, f2 INT); +INSERT INTO t1 VALUES (1,2),(2,3),(3,1); +CREATE TABLE t2(a INT); +INSERT INTO t2 VALUES (1); +SET @var=NULL; +SELECT @var:=(SELECT f2 FROM t2 WHERE @var) FROM t1 GROUP BY f1 ORDER BY f2 DESC +LIMIT 1; +@var:=(SELECT f2 FROM t2 WHERE @var) +NULL +SELECT @var; +@var +NULL +DROP TABLE t1, t2; +CREATE TABLE t1(a INT); +INSERT INTO t1 VALUES (0),(1),(3); +SELECT DISTINCT POW(COUNT(distinct a), @a:=(SELECT 1 FROM t1 LEFT JOIN t1 AS t2 ON @a limit 1)) AS b FROM t1 GROUP BY a; +b +1 +SELECT @a; +@a +1 +DROP TABLE t1; End of 5.5 tests +# +# Check that used memory extends if we set a variable +# +set @var= repeat('a',20000); +1 diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result index dd74e02a26f..083a5e92a8e 100644 --- a/mysql-test/r/variables.result +++ b/mysql-test/r/variables.result @@ -211,10 +211,10 @@ VARIABLE_NAME VARIABLE_VALUE DEFAULT_STORAGE_ENGINE MEMORY show global variables like 'default_storage_engine'; Variable_name Value -default_storage_engine MRG_MYISAM +default_storage_engine MRG_MyISAM select * from information_schema.global_variables where variable_name like 'default_storage_engine'; VARIABLE_NAME VARIABLE_VALUE -DEFAULT_STORAGE_ENGINE MRG_MYISAM +DEFAULT_STORAGE_ENGINE MRG_MyISAM set GLOBAL myisam_max_sort_file_size=2000000; Warnings: Warning 1292 Truncated incorrect myisam_max_sort_file_size value: '2000000' @@ -1479,16 +1479,6 @@ SELECT @@GLOBAL.server_id; @@GLOBAL.server_id 0 SET GLOBAL server_id = @old_server_id; -SELECT @@GLOBAL.INIT_CONNECT, @@GLOBAL.INIT_CONNECT IS NULL; -@@GLOBAL.INIT_CONNECT @@GLOBAL.INIT_CONNECT IS NULL - 1 -CREATE TABLE t1 (a INT); -INSERT INTO t1 VALUES (); -SET @bug42778= @@sql_safe_updates; -SET @@sql_safe_updates= 0; -DELETE FROM t1 ORDER BY (@@GLOBAL.INIT_CONNECT) ASC LIMIT 10; -SET @@sql_safe_updates= @bug42778; -DROP TABLE t1; # # BUG#10206 - InnoDB: Transaction requiring Max_BinLog_Cache_size > 4GB always rollsback # @@ -1559,7 +1549,7 @@ one 1 explain SELECT 1 as 'one' FROM t1 GROUP BY @a:= (SELECT ROUND(f1) FROM t1 WHERE f1 = 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 t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where SELECT 1 as 'one' FROM t1 GROUP BY @a:= (SELECT ROUND(f1) FROM t1 WHERE f1 = 0); one @@ -1570,7 +1560,7 @@ one set sql_buffer_result=1; explain SELECT 1 as 'one' FROM t1 GROUP BY @a:= (SELECT ROUND(f1) FROM t1 WHERE f1 = 0); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using temporary +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where SELECT 1 as 'one' FROM t1 GROUP BY @a:= (SELECT ROUND(f1) FROM t1 WHERE f1 = 0); one diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index ee43b3a3fcd..8097d088aca 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -119,7 +119,7 @@ c 12 explain extended select c from v5; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE <derived3> ALL NULL NULL NULL NULL 5 100.00 +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 5 100.00 3 DERIVED t1 ALL NULL NULL NULL NULL 5 100.00 Warnings: Note 1003 select (`v2`.`c` + 1) AS `c` from `test`.`v2` @@ -2917,9 +2917,9 @@ DROP TABLE IF EXISTS t1; DROP VIEW IF EXISTS v1; DROP VIEW IF EXISTS v2; CREATE TABLE t1(a INT, b INT); -CREATE DEFINER=1234567890abcdefGHIKL@localhost +CREATE DEFINER=longer_than_80_456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789@localhost VIEW v1 AS SELECT a FROM t1; -ERROR HY000: String '1234567890abcdefGHIKL' is too long for user name (should be no longer than 16) +ERROR HY000: String 'longer_than_80_4567890123456789012345678901234567890123456789012345678' is too long for user name (should be no longer than 80) CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY VIEW v2 AS SELECT b FROM t1; ERROR HY000: String '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY' is too long for host name (should be no longer than 60) @@ -4475,8 +4475,8 @@ f1 f1 1 1 EXPLAIN EXTENDED SELECT * FROM v2 AS a1, v2 AS a2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE <derived3> ALL NULL NULL NULL NULL 2 100.00 Using temporary; Using filesort -1 SIMPLE <derived5> ALL NULL NULL NULL NULL 2 100.00 Using join buffer (flat, BNL join) +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 2 100.00 Using temporary; Using filesort +1 PRIMARY <derived5> ALL NULL NULL NULL NULL 2 100.00 Using join buffer (flat, BNL join) 5 DERIVED t1 ALL NULL NULL NULL NULL 2 100.00 3 DERIVED t1 ALL NULL NULL NULL NULL 2 100.00 Warnings: diff --git a/mysql-test/r/view_grant.result b/mysql-test/r/view_grant.result index ac09c19a4b4..330889f8df7 100644 --- a/mysql-test/r/view_grant.result +++ b/mysql-test/r/view_grant.result @@ -531,13 +531,13 @@ drop user mysqltest_1@localhost; drop database mysqltest; create definer=some_user@`` sql security invoker view v1 as select 1; Warnings: -Note 1449 The user specified as a definer ('some_user'@'') does not exist +Note 1449 The user specified as a definer ('some_user'@'%') does not exist create definer=some_user@localhost sql security invoker view v2 as select 1; Warnings: Note 1449 The user specified as a definer ('some_user'@'localhost') does not exist show create view v1; View Create View character_set_client collation_connection -v1 CREATE ALGORITHM=UNDEFINED DEFINER=`some_user`@`` SQL SECURITY INVOKER VIEW `v1` AS select 1 AS `1` latin1 latin1_swedish_ci +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`some_user`@`%` SQL SECURITY INVOKER VIEW `v1` AS select 1 AS `1` latin1 latin1_swedish_ci show create view v2; View Create View character_set_client collation_connection v2 CREATE ALGORITHM=UNDEFINED DEFINER=`some_user`@`localhost` SQL SECURITY INVOKER VIEW `v2` AS select 1 AS `1` latin1 latin1_swedish_ci diff --git a/mysql-test/r/windows.require b/mysql-test/r/windows.require deleted file mode 100644 index 09aae1ed1d0..00000000000 --- a/mysql-test/r/windows.require +++ /dev/null @@ -1,2 +0,0 @@ -TRUE -1 diff --git a/mysql-test/r/xa_binlog.result b/mysql-test/r/xa_binlog.result index 3ce64953902..619a6e08b20 100644 --- a/mysql-test/r/xa_binlog.result +++ b/mysql-test/r/xa_binlog.result @@ -18,15 +18,15 @@ a 1 2 3 -SHOW BINLOG EVENTS LIMIT 1,9; +SHOW BINLOG EVENTS LIMIT 3,9; Log_name Pos Event_type Server_id End_log_pos Info -master-bin.000001 # Query 1 # BEGIN +master-bin.000001 # Gtid 1 # BEGIN GTID #-#-# master-bin.000001 # Query 1 # use `test`; INSERT INTO t1 VALUES (1) master-bin.000001 # Query 1 # COMMIT -master-bin.000001 # Query 1 # BEGIN +master-bin.000001 # Gtid 1 # BEGIN GTID #-#-# master-bin.000001 # Query 1 # use `test`; INSERT INTO t1 VALUES (2) master-bin.000001 # Query 1 # COMMIT -master-bin.000001 # Query 1 # BEGIN +master-bin.000001 # Gtid 1 # BEGIN GTID #-#-# master-bin.000001 # Query 1 # use `test`; INSERT INTO t1 VALUES (3) master-bin.000001 # Xid 1 # COMMIT /* xid=XX */ DROP TABLE t1; |