diff options
109 files changed, 1803 insertions, 245 deletions
diff --git a/mysql-test/r/auto_increment.result b/mysql-test/r/auto_increment.result index 8c898bae699..113c2930977 100644 --- a/mysql-test/r/auto_increment.result +++ b/mysql-test/r/auto_increment.result @@ -112,6 +112,11 @@ insert into t1 set i = null; select last_insert_id(); last_insert_id() 255 +explain extended select last_insert_id(); +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 high_priority no_cache 255 AS `last_insert_id()` insert into t1 set i = 254; ERROR 23000: Duplicate entry '254' for key 1 select last_insert_id(); diff --git a/mysql-test/r/bench_count_distinct.result b/mysql-test/r/bench_count_distinct.result index d414e8e466e..2b4701389db 100644 --- a/mysql-test/r/bench_count_distinct.result +++ b/mysql-test/r/bench_count_distinct.result @@ -3,4 +3,9 @@ create table t1(n int not null, key(n)) delay_key_write = 1; select count(distinct n) from t1; count(distinct n) 100 +explain extended select count(distinct n) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index NULL n 4 NULL 200 Using index +Warnings: +Note 1003 select high_priority count(distinct test.t1.n) AS `count(distinct n)` from test.t1 drop table t1; diff --git a/mysql-test/r/case.result b/mysql-test/r/case.result index 08f148f94c0..4aab3defa2b 100644 --- a/mysql-test/r/case.result +++ b/mysql-test/r/case.result @@ -23,6 +23,11 @@ false select CASE 1 when 1 then "one" WHEN 2 then "two" ELSE "more" END; CASE 1 when 1 then "one" WHEN 2 then "two" ELSE "more" END one +explain extended select CASE 1 when 1 then "one" WHEN 2 then "two" ELSE "more" END; +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 high_priority (case 1 when 1 then _latin1'one' when 2 then _latin1'two' else _latin1'more' end) AS `CASE 1 when 1 then "one" WHEN 2 then "two" ELSE "more" END` select CASE 2.0 when 1 then "one" WHEN 2.0 then "two" ELSE "more" END; CASE 2.0 when 1 then "one" WHEN 2.0 then "two" ELSE "more" END two @@ -57,6 +62,11 @@ fcase count(*) 0 2 2 1 3 1 +explain extended select case a when 1 then 2 when 2 then 3 else 0 end as fcase, count(*) from t1 group by fcase; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using temporary; Using filesort +Warnings: +Note 1003 select high_priority (case test.t1.a when 1 then 2 when 2 then 3 else 0 end) AS `fcase`,count(0) AS `count(*)` from test.t1 group by (case test.t1.a when 1 then 2 when 2 then 3 else 0 end) select case a when 1 then "one" when 2 then "two" else "nothing" end as fcase, count(*) from t1 group by fcase; fcase count(*) nothing 2 @@ -122,6 +132,14 @@ CREATE TABLE t1 SELECT COALESCE(1), COALESCE(1.0),COALESCE('a'), COALESCE(1,1.0), COALESCE(1,'1'),COALESCE(1.1,'1'), COALESCE('a' COLLATE latin1_bin,'b'); +explain extended SELECT +COALESCE(1), COALESCE(1.0),COALESCE('a'), +COALESCE(1,1.0), COALESCE(1,'1'),COALESCE(1.1,'1'), +COALESCE('a' COLLATE latin1_bin,'b'); +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 high_priority coalesce(1) AS `COALESCE(1)`,coalesce(1.0) AS `COALESCE(1.0)`,coalesce(_latin1'a') AS `COALESCE('a')`,coalesce(1,1.0) AS `COALESCE(1,1.0)`,coalesce(1,_latin1'1') AS `COALESCE(1,'1')`,coalesce(1.1,_latin1'1') AS `COALESCE(1.1,'1')`,coalesce((_latin1'a' collate _latin1'latin1_bin'),_latin1'b') AS `COALESCE('a' COLLATE latin1_bin,'b')` SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result index d604a17d270..974a79580ae 100644 --- a/mysql-test/r/cast.result +++ b/mysql-test/r/cast.result @@ -16,6 +16,11 @@ cast(-5 as unsigned) -1 cast(-5 as unsigned) + 1 select ~5, cast(~5 as signed); ~5 cast(~5 as signed) 18446744073709551610 -6 +explain extended select ~5, cast(~5 as signed); +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 high_priority ~(5) AS `~5`,cast(~(5) as signed) AS `cast(~5 as signed)` select cast(5 as unsigned) -6.0; cast(5 as unsigned) -6.0 -1.0 diff --git a/mysql-test/r/ctype_collate.result b/mysql-test/r/ctype_collate.result index b865084b409..6a9da97042b 100644 --- a/mysql-test/r/ctype_collate.result +++ b/mysql-test/r/ctype_collate.result @@ -521,6 +521,11 @@ character_set_client latin1 SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; charset('a') collation('a') coercibility('a') 'a'='A' latin1 latin1_swedish_ci 3 1 +explain extended SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; +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 high_priority charset(_latin1'a') AS `charset('a')`,collation(_latin1'a') AS `collation('a')`,coercibility(_latin1'a') AS `coercibility('a')`,(_latin1'a' = _latin1'A') AS `'a'='A'` SET CHARACTER SET koi8r; SHOW VARIABLES LIKE 'collation_client'; Variable_name Value diff --git a/mysql-test/r/ctype_many.result b/mysql-test/r/ctype_many.result index ebc84db7115..c465655473d 100644 --- a/mysql-test/r/ctype_many.result +++ b/mysql-test/r/ctype_many.result @@ -340,6 +340,129 @@ CYR CAPIT SOFT SIGN ø ø CYR CAPIT E ü ü CYR CAPIT YU à à CYR CAPIT YA ñ ñ +select CONVERT(koi8_ru_f, 'cp1251_general_ci', 'utf8_general_ci'), comment from t1; +CONVERT(koi8_ru_f, 'cp1251_general_ci', 'utf8_general_ci') comment +a LAT SMALL A +b LAT SMALL B +c LAT SMALL C +d LAT SMALL D +e LAT SMALL E +f LAT SMALL F +g LAT SMALL G +h LAT SMALL H +i LAT SMALL I +j LAT SMALL J +k LAT SMALL K +l LAT SMALL L +m LAT SMALL M +n LAT SMALL N +o LAT SMALL O +p LAT SMALL P +q LAT SMALL Q +r LAT SMALL R +s LAT SMALL S +t LAT SMALL T +u LAT SMALL U +v LAT SMALL V +w LAT SMALL W +x LAT SMALL X +y LAT SMALL Y +z LAT SMALL Z +A LAT CAPIT A +B LAT CAPIT B +C LAT CAPIT C +D LAT CAPIT D +E LAT CAPIT E +F LAT CAPIT F +G LAT CAPIT G +H LAT CAPIT H +I LAT CAPIT I +J LAT CAPIT J +K LAT CAPIT K +L LAT CAPIT L +M LAT CAPIT M +N LAT CAPIT N +O LAT CAPIT O +P LAT CAPIT P +Q LAT CAPIT Q +R LAT CAPIT R +S LAT CAPIT S +T LAT CAPIT T +U LAT CAPIT U +V LAT CAPIT V +W LAT CAPIT W +X LAT CAPIT X +Y LAT CAPIT Y +Z LAT CAPIT Z +â CYR SMALL A +÷ CYR SMALL BE +þ CYR SMALL VE +ú CYR SMALL GE +ä CYR SMALL DE +å CYR SMALL IE +? CYR SMALL IO +ã CYR SMALL ZHE +ÿ CYR SMALL ZE +ê CYR SMALL I +ì CYR SMALL KA +í CYR SMALL EL +î CYR SMALL EM +ï CYR SMALL EN +ð CYR SMALL O +ò CYR SMALL PE +ô CYR SMALL ER +õ CYR SMALL ES +æ CYR SMALL TE +è CYR SMALL U +ö CYR SMALL EF +é CYR SMALL HA +ç CYR SMALL TSE +à CYR SMALL CHE +ù CYR SMALL SHA +ü CYR SMALL SCHA +ñ CYR SMALL HARD SIGN +ý CYR SMALL YERU +û CYR SMALL SOFT SIGN +ø CYR SMALL E +á CYR SMALL YU +ó CYR SMALL YA +Â CYR CAPIT A +× CYR CAPIT BE +Þ CYR CAPIT VE +Ú CYR CAPIT GE +Ä CYR CAPIT DE +Å CYR CAPIT IE +? CYR CAPIT IO +Ã CYR CAPIT ZHE +ß CYR CAPIT ZE +Ê CYR CAPIT I +Ì CYR CAPIT KA +Í CYR CAPIT EL +Î CYR CAPIT EM +Ï CYR CAPIT EN +Ð CYR CAPIT O +Ò CYR CAPIT PE +Ô CYR CAPIT ER +Õ CYR CAPIT ES +Æ CYR CAPIT TE +È CYR CAPIT U +Ö CYR CAPIT EF +É CYR CAPIT HA +Ç CYR CAPIT TSE +À CYR CAPIT CHE +Ù CYR CAPIT SHA +Ü CYR CAPIT SCHA +Ñ CYR CAPIT HARD SIGN +Ý CYR CAPIT YERU +Û CYR CAPIT SOFT SIGN +Ø CYR CAPIT E +Á CYR CAPIT YU +Ó CYR CAPIT YA +explain extended select CONVERT(koi8_ru_f, 'cp1251_general_ci', 'utf8_general_ci'), comment from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 116 +Warnings: +Note 1003 select high_priority convert(test.t1.koi8_ru_f,_latin1'utf8_general_ci',_latin1'cp1251_general_ci') AS `CONVERT(koi8_ru_f, 'cp1251_general_ci', 'utf8_general_ci')`,test.t1.comment AS `comment` from test.t1 ALTER TABLE t1 ADD bin_f CHAR(32) BYTE NOT NULL; UPDATE t1 SET bin_f=koi8_ru_f; SELECT COUNT(DISTINCT bin_f),COUNT(DISTINCT koi8_ru_f),COUNT(DISTINCT utf8_f) FROM t1; diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 1f07de17b14..1aef43cd570 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -47,6 +47,9 @@ locate(_utf8 0xD091, _utf8 0xD0B0D0B1D0B2 collate utf8_bin) select locate(_utf8 0xD0B1, _utf8 0xD0B0D091D0B2 collate utf8_bin); locate(_utf8 0xD0B1, _utf8 0xD0B0D091D0B2 collate utf8_bin) 0 +select length(_utf8 0xD0B1), bit_length(_utf8 0xD0B1), char_length(_utf8 0xD0B1); +length(_utf8 0xD0B1) bit_length(_utf8 0xD0B1) char_length(_utf8 0xD0B1) +2 16 1 select 'a' like 'a'; 'a' like 'a' 1 diff --git a/mysql-test/r/date_formats.result b/mysql-test/r/date_formats.result index 590a1d6904b..e21e05b4dfe 100644 --- a/mysql-test/r/date_formats.result +++ b/mysql-test/r/date_formats.result @@ -155,3 +155,8 @@ a select get_format(DATETIME, 'eur') as a; a %Y-%m-%d-%H.%i.%s +explain extended select makedate(1997,1), addtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002"),subtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002"),timediff("01.01.97 11:59:59.000001 PM","31.12.95 11:59:59.000002 PM"),cast(str_to_date("15-01-2001 12:59:59", "%d-%m-%Y %H:%i:%S") as TIME), maketime(23,11,12),microsecond("1997-12-31 23:59:59.000001"); +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 high_priority makedate(1997,1) AS `makedate(1997,1)`,addtime(_latin1'31.12.97 11.59.59.999999 PM',_latin1'31.12.97 11.59.59.999999 PM') AS `addtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002")`,subtime(_latin1'31.12.97 11.59.59.999999 PM',_latin1'31.12.97 11.59.59.999999 PM') AS `subtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002")`,timediff(_latin1'01.01.97 11:59:59.000001 PM',_latin1'31.12.95 11:59:59.000002 PM') AS `timediff("01.01.97 11:59:59.000001 PM","31.12.95 11:59:59.000002 PM")`,cast(str_to_date(_latin1'15-01-2001 12:59:59',_latin1'%d-%m-%Y %H:%i:%S') as time) AS `cast(str_to_date("15-01-2001 12:59:59", "%d-%m-%Y %H:%i:%S") as TIME)`,maketime(23,11,12) AS `maketime(23,11,12)`,microsecond(_latin1'1997-12-31 23:59:59.000001') AS `microsecond("1997-12-31 23:59:59.000001")` diff --git a/mysql-test/r/derived.result b/mysql-test/r/derived.result index 12d8bbaf8ae..37742893c2b 100644 --- a/mysql-test/r/derived.result +++ b/mysql-test/r/derived.result @@ -227,6 +227,4 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 THEMAX.E2 1 Using where 2 DERIVED t1 ALL NULL NULL NULL NULL 2 Using where 3 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 2 Using where -Warnings: -Note 1275 Field or reference 'A.E2' of SELECT #3 was resolved in SELECT #2 drop table t1; diff --git a/mysql-test/r/fulltext.result b/mysql-test/r/fulltext.result index 31ed252b22d..da3b3d0b8da 100644 --- a/mysql-test/r/fulltext.result +++ b/mysql-test/r/fulltext.result @@ -9,6 +9,11 @@ select * from t1 where MATCH(a,b) AGAINST ("collections"); a b Only MyISAM tables support collections Full-text indexes are called collections +explain extended select * from t1 where MATCH(a,b) AGAINST ("collections"); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 fulltext a a 0 1 Using where +Warnings: +Note 1003 select high_priority test.t1.a AS `a`,test.t1.b AS `b` from test.t1 where (match test.t1.a,test.t1.b against (_latin1'collections')) select * from t1 where MATCH(a,b) AGAINST ("indexes"); a b Full-text indexes are called collections @@ -65,6 +70,11 @@ id select_type table type possible_keys key key_len ref rows Extra select * from t1 where MATCH(a,b) AGAINST("support -collections" IN BOOLEAN MODE); a b MySQL has now support for full-text search +explain extended select * from t1 where MATCH(a,b) AGAINST("support -collections" IN BOOLEAN MODE); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 fulltext a a 0 1 Using where +Warnings: +Note 1003 select high_priority test.t1.a AS `a`,test.t1.b AS `b` from test.t1 where (match test.t1.a,test.t1.b against (_latin1'support -collections' in boolean mode)) select * from t1 where MATCH(a,b) AGAINST("support collections" IN BOOLEAN MODE); a b MySQL has now support for full-text search diff --git a/mysql-test/r/func_compress.result b/mysql-test/r/func_compress.result index 85842f28e64..0e46f7dd16d 100644 --- a/mysql-test/r/func_compress.result +++ b/mysql-test/r/func_compress.result @@ -7,9 +7,19 @@ length(@test_compress_string) select uncompress(compress(@test_compress_string)); uncompress(compress(@test_compress_string)) string for test compress function aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +explain extended select uncompress(compress(@test_compress_string)); +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 high_priority no_cache uncompress(compress((@test_compress_string))) AS `uncompress(compress(@test_compress_string))` select uncompressed_length(compress(@test_compress_string))=length(@test_compress_string); uncompressed_length(compress(@test_compress_string))=length(@test_compress_string) 1 +explain extended select uncompressed_length(compress(@test_compress_string))=length(@test_compress_string); +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 high_priority no_cache (uncompressed_length(compress((@test_compress_string))) = length((@test_compress_string))) AS `uncompressed_length(compress(@test_compress_string))=length(@test_compress_string)` select uncompressed_length(compress(@test_compress_string)); uncompressed_length(compress(@test_compress_string)) 117 diff --git a/mysql-test/r/func_default.result b/mysql-test/r/func_default.result new file mode 100644 index 00000000000..fe3f5b9473a --- /dev/null +++ b/mysql-test/r/func_default.result @@ -0,0 +1,18 @@ +drop table if exists t1,t2; +create table t1(str varchar(10) default 'def',strnull varchar(10),intg int default '10',rel double default '3.14'); +insert into t1 values ('','',0,0.0); +select default(str), default(strnull), default(intg), default(rel) from t1; +default(str) default(strnull) default(intg) default(rel) +def NULL 10 3.14 +explain extended select default(str), default(strnull), default(intg), default(rel) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 system NULL NULL NULL NULL 1 +Warnings: +Note 1003 select high_priority default(test.t1.str) AS `default(str)`,default(test.t1.strnull) AS `default(strnull)`,default(test.t1.intg) AS `default(intg)`,default(test.t1.rel) AS `default(rel)` from test.t1 +select * from t1 where str <> default(str); +str strnull intg rel + 0 0 +explain select * from t1 where str <> default(str); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 system NULL NULL NULL NULL 1 +drop table t1; diff --git a/mysql-test/r/func_gconcat.result b/mysql-test/r/func_gconcat.result index 5eae6b4b871..af6f7956fe3 100644 --- a/mysql-test/r/func_gconcat.result +++ b/mysql-test/r/func_gconcat.result @@ -14,6 +14,11 @@ grp group_concat(c) 1 a 2 b,c 3 E,C,D,d,d,D +explain extended select grp,group_concat(c) from t1 group by grp; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 9 Using filesort +Warnings: +Note 1003 select high_priority test.t1.grp AS `grp`,group_concat(test.t1.c seperator ',') AS `group_concat(c)` from test.t1 group by test.t1.grp select grp,group_concat(a,c) from t1 group by grp; grp group_concat(a,c) 1 1a @@ -79,6 +84,11 @@ grp group_concat(distinct c order by c desc) 1 a 2 c,b 3 E,D,C +explain extended select grp,group_concat(distinct c order by c desc) from t1 group by grp; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 9 Using filesort +Warnings: +Note 1003 select high_priority test.t1.grp AS `grp`,group_concat(distinct test.t1.c order by test.t1.c seperator ',') AS `group_concat(distinct c order by c desc)` from test.t1 group by test.t1.grp select grp,group_concat(c order by c separator ",") from t1 group by grp; grp group_concat(c order by c separator ",") 1 a @@ -94,6 +104,11 @@ grp group_concat(distinct c order by c separator ",") 1 a 2 b,c 3 C,D,E +explain extended select grp,group_concat(distinct c order by c separator ",") from t1 group by grp; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 9 Using filesort +Warnings: +Note 1003 select high_priority test.t1.grp AS `grp`,group_concat(distinct test.t1.c order by test.t1.c seperator ',') AS `group_concat(distinct c order by c separator ",")` from test.t1 group by test.t1.grp select grp,group_concat(distinct c order by c desc separator ",") from t1 group by grp; grp group_concat(distinct c order by c desc separator ",") 1 a diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result index 2fb38ffe592..7b084626f39 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -597,11 +597,16 @@ a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) 1 0 NULL NULL NULL NULL NULL 0 0 2 1 1 1.0000 0.0000 1 1 0 1 3 1 1 1.0000 0.0000 1 1 1 1 -select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; -a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) -1 0 NULL NULL NULL NULL NULL 18446744073709551615 0 -2 1 1 1.0000 0.0000 1 1 1 1 -3 1 1 1.0000 0.0000 1 1 1 1 +select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b), bit_xor(b) from t1 group by a; +a count(b) sum(b) avg(b) std(b) min(b) max(b) bit_and(b) bit_or(b) bit_xor(b) +1 0 NULL NULL NULL NULL NULL 18446744073709551615 0 0 +2 1 1 1.0000 0.0000 1 1 1 1 1 +3 1 1 1.0000 0.0000 1 1 1 1 1 +explain extended select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b), bit_xor(b) 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 5 Using filesort +Warnings: +Note 1003 select high_priority big_result test.t1.a AS `a`,count(test.t1.b) AS `count(b)`,sum(test.t1.b) AS `sum(b)`,avg(test.t1.b) AS `avg(b)`,std(test.t1.b) AS `std(b)`,min(test.t1.b) AS `min(b)`,max(test.t1.b) AS `max(b)`,bit_and(test.t1.b) AS `bit_and(b)`,bit_or(test.t1.b) AS `bit_or(b)`,bit_xor(test.t1.b) AS `bit_xor(b)` from test.t1 group by test.t1.a drop table t1; create table t1 (USR_ID integer not null, MAX_REQ integer not null, constraint PK_SEA_USER primary key (USR_ID)) type=InnoDB; insert into t1 values (1, 3); diff --git a/mysql-test/r/func_if.result b/mysql-test/r/func_if.result index 0ab41258091..64070179395 100644 --- a/mysql-test/r/func_if.result +++ b/mysql-test/r/func_if.result @@ -39,6 +39,25 @@ a a aa aaa +explain extended select if(u=1,st,binary st) s from t1 where st like "%a%" order by s; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 7 Using where; Using filesort +Warnings: +Note 1003 select high_priority if((test.t1.u = 1),test.t1.st,(test.t1.st collate _latin1'BINARY')) AS `s` from test.t1 where (test.t1.st like _latin1'%a%') order by if((test.t1.u = 1),test.t1.st,(test.t1.st collate _latin1'BINARY')) +select nullif(u=0, 'test') from t1; +nullif(u=0, 'test') +NULL +NULL +NULL +NULL +NULL +1 +1 +explain extended select nullif(u=0, 'test') from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 7 +Warnings: +Note 1003 select high_priority nullif((test.t1.u = 0),_latin1'test') AS `nullif(u=0, 'test')` from test.t1 drop table t1; create table t1 (num double(12,2)); insert into t1 values (144.54); diff --git a/mysql-test/r/func_in.result b/mysql-test/r/func_in.result index a197371b345..04b6fc038b0 100644 --- a/mysql-test/r/func_in.result +++ b/mysql-test/r/func_in.result @@ -142,6 +142,11 @@ a c c select * from t1 where 'a' in (a,b,c collate latin1_bin); a b c a c c +explain extended select * from t1 where 'a' in (a,b,c collate latin1_bin); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where +Warnings: +Note 1003 select high_priority test.t1.a AS `a`,test.t1.b AS `b`,test.t1.c AS `c` from test.t1 where (_latin1'a' in (test.t1.a,test.t1.b,(test.t1.c collate _latin1'latin1_bin'))) drop table t1; select '1.0' in (1,2); '1.0' in (1,2) diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result index d6596e51db4..151a2902423 100644 --- a/mysql-test/r/func_math.result +++ b/mysql-test/r/func_math.result @@ -1,43 +1,108 @@ select floor(5.5),floor(-5.5); floor(5.5) floor(-5.5) 5 -6 +explain extended select floor(5.5),floor(-5.5); +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 high_priority floor(5.5) AS `floor(5.5)`,floor(-(5.5)) AS `floor(-5.5)` select ceiling(5.5),ceiling(-5.5); ceiling(5.5) ceiling(-5.5) 6 -5 +explain extended select ceiling(5.5),ceiling(-5.5); +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 high_priority ceiling(5.5) AS `ceiling(5.5)`,ceiling(-(5.5)) AS `ceiling(-5.5)` select truncate(52.64,1),truncate(52.64,2),truncate(52.64,-1),truncate(52.64,-2), truncate(-52.64,1),truncate(-52.64,-1); truncate(52.64,1) truncate(52.64,2) truncate(52.64,-1) truncate(52.64,-2) truncate(-52.64,1) truncate(-52.64,-1) 52.6 52.64 50 0 -52.6 -50 +explain extended select truncate(52.64,1),truncate(52.64,2),truncate(52.64,-1),truncate(52.64,-2), truncate(-52.64,1),truncate(-52.64,-1); +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 high_priority truncate(52.64,1) AS `truncate(52.64,1)`,truncate(52.64,2) AS `truncate(52.64,2)`,truncate(52.64,-(1)) AS `truncate(52.64,-1)`,truncate(52.64,-(2)) AS `truncate(52.64,-2)`,truncate(-(52.64),1) AS `truncate(-52.64,1)`,truncate(-(52.64),-(1)) AS `truncate(-52.64,-1)` select round(5.5),round(-5.5); round(5.5) round(-5.5) 6 -6 +explain extended select round(5.5),round(-5.5); +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 high_priority round(5.5,0) AS `round(5.5)`,round(-(5.5),0) AS `round(-5.5)` select round(5.64,1),round(5.64,2),round(5.64,-1),round(5.64,-2); round(5.64,1) round(5.64,2) round(5.64,-1) round(5.64,-2) 5.6 5.64 10 0 select abs(-10), sign(-5), sign(5), sign(0); abs(-10) sign(-5) sign(5) sign(0) 10 -1 1 0 +explain extended select abs(-10), sign(-5), sign(5), sign(0); +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 high_priority abs(-(10)) AS `abs(-10)`,sign(-(5)) AS `sign(-5)`,sign(5) AS `sign(5)`,sign(0) AS `sign(0)` select log(exp(10)),exp(log(sqrt(10))*2),log(-1),log(NULL),log(1,1),log(3,9),log(-1,2),log(NULL,2); log(exp(10)) exp(log(sqrt(10))*2) log(-1) log(NULL) log(1,1) log(3,9) log(-1,2) log(NULL,2) 10.000000 10.000000 NULL NULL NULL 2.000000 NULL NULL +explain extended select log(exp(10)),exp(log(sqrt(10))*2),log(-1),log(NULL),log(1,1),log(3,9),log(-1,2),log(NULL,2); +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 high_priority log(exp(10)) AS `log(exp(10))`,exp((log(sqrt(10)) * 2)) AS `exp(log(sqrt(10))*2)`,log(-(1)) AS `log(-1)`,log(NULL) AS `log(NULL)`,log(1,1) AS `log(1,1)`,log(3,9) AS `log(3,9)`,log(-(1),2) AS `log(-1,2)`,log(NULL,2) AS `log(NULL,2)` select ln(exp(10)),exp(ln(sqrt(10))*2),ln(-1),ln(0),ln(NULL); ln(exp(10)) exp(ln(sqrt(10))*2) ln(-1) ln(0) ln(NULL) 10.000000 10.000000 NULL NULL NULL +explain extended select ln(exp(10)),exp(ln(sqrt(10))*2),ln(-1),ln(0),ln(NULL); +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 high_priority ln(exp(10)) AS `ln(exp(10))`,exp((ln(sqrt(10)) * 2)) AS `exp(ln(sqrt(10))*2)`,ln(-(1)) AS `ln(-1)`,ln(0) AS `ln(0)`,ln(NULL) AS `ln(NULL)` select log2(8),log2(15),log2(-2),log2(0),log2(NULL); log2(8) log2(15) log2(-2) log2(0) log2(NULL) 3.000000 3.906891 NULL NULL NULL +explain extended select log2(8),log2(15),log2(-2),log2(0),log2(NULL); +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 high_priority log2(8) AS `log2(8)`,log2(15) AS `log2(15)`,log2(-(2)) AS `log2(-2)`,log2(0) AS `log2(0)`,log2(NULL) AS `log2(NULL)` select log10(100),log10(18),log10(-4),log10(0),log10(NULL); log10(100) log10(18) log10(-4) log10(0) log10(NULL) 2.000000 1.255273 NULL NULL NULL +explain extended select log10(100),log10(18),log10(-4),log10(0),log10(NULL); +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 high_priority log10(100) AS `log10(100)`,log10(18) AS `log10(18)`,log10(-(4)) AS `log10(-4)`,log10(0) AS `log10(0)`,log10(NULL) AS `log10(NULL)` select pow(10,log10(10)),power(2,4); pow(10,log10(10)) power(2,4) 10.000000 16.000000 +explain extended select pow(10,log10(10)),power(2,4); +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 high_priority pow(10,log10(10)) AS `pow(10,log10(10))`,pow(2,4) AS `power(2,4)` set @@rand_seed1=10000000,@@rand_seed2=1000000; select rand(999999),rand(); rand(999999) rand() 0.014231365187309 0.028870999839968 +explain extended select rand(999999),rand(); +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 high_priority no_cache rand(999999) AS `rand(999999)`,rand() AS `rand()` select pi(),sin(pi()/2),cos(pi()/2),abs(tan(pi())),cot(1),asin(1),acos(0),atan(1); pi() sin(pi()/2) cos(pi()/2) abs(tan(pi())) cot(1) asin(1) acos(0) atan(1) 3.141593 1.000000 0.000000 0.000000 0.64209262 1.570796 1.570796 0.785398 +explain extended select pi(),sin(pi()/2),cos(pi()/2),abs(tan(pi())),cot(1),asin(1),acos(0),atan(1); +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 high_priority pi() AS `pi()`,sin((pi() / 2)) AS `sin(pi()/2)`,cos((pi() / 2)) AS `cos(pi()/2)`,abs(tan(pi())) AS `abs(tan(pi()))`,(1 / tan(1)) AS `cot(1)`,asin(1) AS `asin(1)`,acos(0) AS `acos(0)`,atan(1) AS `atan(1)` select degrees(pi()),radians(360); degrees(pi()) radians(360) 180 6.2831853071796 +explain extended select degrees(pi()),radians(360); +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 high_priority degrees(pi()) AS `degrees(pi())`,radians(360) AS `radians(360)` diff --git a/mysql-test/r/func_op.result b/mysql-test/r/func_op.result index 9f49b5809df..25a7ac20b66 100644 --- a/mysql-test/r/func_op.result +++ b/mysql-test/r/func_op.result @@ -1,9 +1,19 @@ select 1+1,1-1,1+1*2,8/5,8%5,mod(8,5),mod(8,5)|0,-(1+1)*-2; 1+1 1-1 1+1*2 8/5 8%5 mod(8,5) mod(8,5)|0 -(1+1)*-2 2 0 3 1.60 3 3 3 4 +explain extended select 1+1,1-1,1+1*2,8/5,8%5,mod(8,5),mod(8,5)|0,-(1+1)*-2; +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 high_priority (1 + 1) AS `1+1`,(1 - 1) AS `1-1`,(1 + (1 * 2)) AS `1+1*2`,(8 / 5) AS `8/5`,(8 % 5) AS `8%5`,(8 % 5) AS `mod(8,5)`,((8 % 5) | 0) AS `mod(8,5)|0`,(-((1 + 1)) * -(2)) AS `-(1+1)*-2` select 1 | (1+1),5 & 3,bit_count(7) ; 1 | (1+1) 5 & 3 bit_count(7) 3 1 3 +explain extended select 1 | (1+1),5 & 3,bit_count(7) ; +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 high_priority (1 | (1 + 1)) AS `1 | (1+1)`,(5 & 3) AS `5 & 3`,bit_count(7) AS `bit_count(7)` select 1 << 32,1 << 63, 1 << 64, 4 >> 2, 4 >> 63, 1<< 63 >> 60; 1 << 32 1 << 63 1 << 64 4 >> 2 4 >> 63 1<< 63 >> 60 4294967296 9223372036854775808 0 1 0 8 diff --git a/mysql-test/r/func_regexp.result b/mysql-test/r/func_regexp.result index 35742136ee6..323642cab8c 100644 --- a/mysql-test/r/func_regexp.result +++ b/mysql-test/r/func_regexp.result @@ -36,6 +36,11 @@ insert into t1 (xxx) values('this is a test of some long text to see what happen select * from t1 where xxx regexp('is a test of some long text to'); xxx this is a test of some long text to see what happens +explain extended select * from t1 where xxx regexp('is a test of some long text to'); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 system NULL NULL NULL NULL 1 +Warnings: +Note 1003 select high_priority test.t1.xxx AS `xxx` from test.t1 where (test.t1.xxx regexp _latin1'is a test of some long text to') select * from t1 where xxx regexp('is a test of some long text to '); xxx this is a test of some long text to see what happens diff --git a/mysql-test/r/func_set.result b/mysql-test/r/func_set.result index 86608e7c247..2a3631140b0 100644 --- a/mysql-test/r/func_set.result +++ b/mysql-test/r/func_set.result @@ -1,6 +1,11 @@ select interval(55,10,20,30,40,50,60,70,80,90,100),interval(3,1,1+1,1+1+1+1),field("IBM","NCA","ICL","SUN","IBM","DIGITAL"),field("A","B","C"),elt(2,"ONE","TWO","THREE"),interval(0,1,2,3,4),elt(1,1,2,3)|0,elt(1,1.1,1.2,1.3)+0; interval(55,10,20,30,40,50,60,70,80,90,100) interval(3,1,1+1,1+1+1+1) field("IBM","NCA","ICL","SUN","IBM","DIGITAL") field("A","B","C") elt(2,"ONE","TWO","THREE") interval(0,1,2,3,4) elt(1,1,2,3)|0 elt(1,1.1,1.2,1.3)+0 5 2 4 0 TWO 0 1 1.1 +explain extended select INTERVAL(55,10,20,30,40,50,60,70,80,90,100),interval(3,1,1+1,1+1+1+1),field("IBM","NCA","ICL","SUN","IBM","DIGITAL"),field("A","B","C"),elt(2,"ONE","TWO","THREE"),interval(0,1,2,3,4),elt(1,1,2,3)|0,elt(1,1.1,1.2,1.3)+0; +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 high_priority interval((55,10,20,30,40,50,60,70,80,90,100)) AS `INTERVAL(55,10,20,30,40,50,60,70,80,90,100)`,interval((3,1,(1 + 1),(((1 + 1) + 1) + 1))) AS `interval(3,1,1+1,1+1+1+1)`,field(_latin1'IBM',_latin1'NCA',_latin1'ICL',_latin1'SUN',_latin1'IBM',_latin1'DIGITAL') AS `field("IBM","NCA","ICL","SUN","IBM","DIGITAL")`,field(_latin1'A',_latin1'B',_latin1'C') AS `field("A","B","C")`,elt(2,_latin1'ONE',_latin1'TWO',_latin1'THREE') AS `elt(2,"ONE","TWO","THREE")`,interval((0,1,2,3,4)) AS `interval(0,1,2,3,4)`,(elt(1,1,2,3) | 0) AS `elt(1,1,2,3)|0`,(elt(1,1.1,1.2,1.3) + 0) AS `elt(1,1.1,1.2,1.3)+0` select find_in_set("b","a,b,c"),find_in_set("c","a,b,c"),find_in_set("dd","a,bbb,dd"),find_in_set("bbb","a,bbb,dd"); find_in_set("b","a,b,c") find_in_set("c","a,b,c") find_in_set("dd","a,bbb,dd") find_in_set("bbb","a,bbb,dd") 2 3 3 2 diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index ac25277351c..1a4e2fa498b 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -12,9 +12,15 @@ length('\n\t\r\b\0\_\%\\') select bit_length('\n\t\r\b\0\_\%\\'); bit_length('\n\t\r\b\0\_\%\\') 80 -select concat('monty',' was here ','again'),length('hello'),char(ascii('h')); -concat('monty',' was here ','again') length('hello') char(ascii('h')) -monty was here again 5 h +select char_length('\n\t\r\b\0\_\%\\'); +char_length('\n\t\r\b\0\_\%\\') +10 +select length(_latin1'\n\t\n\b\0\\_\\%\\'); +length(_latin1'\n\t\n\b\0\\_\\%\\') +10 +select concat('monty',' was here ','again'),length('hello'),char(ascii('h')),ord('h'); +concat('monty',' was here ','again') length('hello') char(ascii('h')) ord('h') +monty was here again 5 h 104 select locate('he','hello'),locate('he','hello',2),locate('lo','hello',2) ; locate('he','hello') locate('he','hello',2) locate('lo','hello',2) 1 0 4 @@ -99,6 +105,9 @@ NULL select md5('hello'); md5('hello') 5d41402abc4b2a76b9719d911017c592 +select crc32("123"); +crc32("123") +2286445522 select sha('abc'); sha('abc') a9993e364706816aba3e25717850c26c9cd0d89d @@ -579,3 +588,8 @@ CONCAT("</a>",RPAD("",(55 - LENGTH(title)),".")) NULL </a>.......................... DROP TABLE t1; +explain extended select md5('hello'), sha('abc'), sha1('abc'), soundex(''), 'mood' sounds like 'mud', aes_decrypt(aes_encrypt('abc','1'),'1'),concat('*',space(5),'*'), reverse('abc'), rpad('a',4,'1'), lpad('a',4,'1'), concat_ws(',','',NULL,'a'),make_set(255,_latin2'a',_latin2'b',_latin2'c'),elt(2,1),locate("a","b",2),format(130,10),char(0),conv(130,16,10),hex(130),binary 'HE', export_set(255,_latin2'y',_latin2'n',_latin2' '),FIELD('b' COLLATE latin1_bin,'A','B'),FIND_IN_SET(_latin1'B',_latin1'a,b,c,d'),collation(conv(130,16,10)), coercibility(conv(130,16,10)),length('\n\t\r\b\0\_\%\\'),bit_length('\n\t\r\b\0\_\%\\'),bit_length('\n\t\r\b\0\_\%\\'),concat('monty',' was here ','again'),length('hello'),char(ascii('h')),ord('h'),quote(1/0),crc32("123"); +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 high_priority md5(_latin1'hello') AS `md5('hello')`,sha(_latin1'abc') AS `sha('abc')`,sha(_latin1'abc') AS `sha1('abc')`,soundex(_latin1'') AS `soundex('')`,(soundex(_latin1'mood') = soundex(_latin1'mud')) AS `'mood' sounds like 'mud'`,aes_decrypt(aes_encrypt(_latin1'abc',_latin1'1'),_latin1'1') AS `aes_decrypt(aes_encrypt('abc','1'),'1')`,concat(_latin1'*',repeat(_latin1' ',5),_latin1'*') AS `concat('*',space(5),'*')`,reverse(_latin1'abc') AS `reverse('abc')`,rpad(_latin1'a',4,_latin1'1') AS `rpad('a',4,'1')`,lpad(_latin1'a',4,_latin1'1') AS `lpad('a',4,'1')`,concat_ws(_latin1',',_latin1'',NULL,_latin1'a') AS `concat_ws(',','',NULL,'a')`,make_set(255,_latin2'a',_latin2'b',_latin2'c') AS `make_set(255,_latin2'a',_latin2'b',_latin2'c')`,elt(2,1) AS `elt(2,1)`,locate(_latin1'a',_latin1'b',2) AS `locate("a","b",2)`,format(130,10) AS `format(130,10)`,char(0) AS `char(0)`,conv(130,16,10) AS `conv(130,16,10)`,hex(130) AS `hex(130)`,(_latin1'HE' collate _latin1'BINARY') AS `binary 'HE'`,export_set(255,_latin2'y',_latin2'n',_latin2' ') AS `export_set(255,_latin2'y',_latin2'n',_latin2' ')`,field((_latin1'b' collate _latin1'latin1_bin'),_latin1'A',_latin1'B') AS `FIELD('b' COLLATE latin1_bin,'A','B')`,find_in_set(_latin1'B',_latin1'a,b,c,d') AS `FIND_IN_SET(_latin1'B',_latin1'a,b,c,d')`,collation(conv(130,16,10)) AS `collation(conv(130,16,10))`,coercibility(conv(130,16,10)) AS `coercibility(conv(130,16,10))`,length(_latin1'\n\t\r\b\0\\_\\%\\') AS `length('\n\t\r\b\0\_\%\\')`,bit_length(_latin1'\n\t\r\b\0\\_\\%\\') AS `bit_length('\n\t\r\b\0\_\%\\')`,bit_length(_latin1'\n\t\r\b\0\\_\\%\\') AS `bit_length('\n\t\r\b\0\_\%\\')`,concat(_latin1'monty',_latin1' was here ',_latin1'again') AS `concat('monty',' was here ','again')`,length(_latin1'hello') AS `length('hello')`,char(ascii(_latin1'h')) AS `char(ascii('h'))`,ord(_latin1'h') AS `ord('h')`,quote((1 / 0)) AS `quote(1/0)`,crc32(_latin1'123') AS `crc32("123")` diff --git a/mysql-test/r/func_system.result b/mysql-test/r/func_system.result index a52d5613c04..9d370b43099 100644 --- a/mysql-test/r/func_system.result +++ b/mysql-test/r/func_system.result @@ -37,6 +37,11 @@ version()>=_latin1"3.23.29" select charset(version()); charset(version()) utf8 +explain extended select database(), user(); +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 high_priority no_cache database() AS `database()`,user() AS `user()` create table t1 (version char(40)) select database(), user(), version() as 'version'; show create table t1; Table Create Table diff --git a/mysql-test/r/func_test.result b/mysql-test/r/func_test.result index 851c308ba3e..4951d954abb 100644 --- a/mysql-test/r/func_test.result +++ b/mysql-test/r/func_test.result @@ -44,19 +44,47 @@ select -1.49 or -1.49,0.6 or 0.6; select 3 ^ 11, 1 ^ 1, 1 ^ 0, 1 ^ NULL, NULL ^ 1; 3 ^ 11 1 ^ 1 1 ^ 0 1 ^ NULL NULL ^ 1 8 0 1 NULL NULL +explain extended select 3 ^ 11, 1 ^ 1, 1 ^ 0, 1 ^ NULL, NULL ^ 1; +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 high_priority (3 ^ 11) AS `3 ^ 11`,(1 ^ 1) AS `1 ^ 1`,(1 ^ 0) AS `1 ^ 0`,(1 ^ NULL) AS `1 ^ NULL`,(NULL ^ 1) AS `NULL ^ 1` select 1 XOR 1, 1 XOR 0, 0 XOR 1, 0 XOR 0, NULL XOR 1, 1 XOR NULL, 0 XOR NULL; 1 XOR 1 1 XOR 0 0 XOR 1 0 XOR 0 NULL XOR 1 1 XOR NULL 0 XOR NULL 0 1 1 0 NULL NULL NULL select 10 % 7, 10 mod 7, 10 div 3; 10 % 7 10 mod 7 10 div 3 3 3 3 +explain extended select 10 % 7, 10 mod 7, 10 div 3; +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 high_priority (10 % 7) AS `10 % 7`,(10 % 7) AS `10 mod 7`,(10 DIV 3) AS `10 div 3` select (1 << 64)-1, ((1 << 64)-1) DIV 1, ((1 << 64)-1) DIV 2; (1 << 64)-1 ((1 << 64)-1) DIV 1 ((1 << 64)-1) DIV 2 18446744073709551615 18446744073709551615 9223372036854775807 +explain extended select (1 << 64)-1, ((1 << 64)-1) DIV 1, ((1 << 64)-1) DIV 2; +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 high_priority ((1 << 64) - 1) AS `(1 << 64)-1`,(((1 << 64) - 1) DIV 1) AS `((1 << 64)-1) DIV 1`,(((1 << 64) - 1) DIV 2) AS `((1 << 64)-1) DIV 2` create table t1 (a int); insert t1 values (1); select * from t1 where 1 xor 1; a +explain extended select * from t1 where 1 xor 1; +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 +Warnings: +Note 1003 select high_priority test.t1.a AS `a` from test.t1 where (1 xor 1) +select - a from t1; +- a +-1 +explain extended select - a from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 system NULL NULL NULL NULL 1 +Warnings: +Note 1003 select high_priority -(test.t1.a) AS `- a` from test.t1 drop table t1; select 5 between 0 and 10 between 0 and 1,(5 between 0 and 10) between 0 and 1; 5 between 0 and 10 between 0 and 1 (5 between 0 and 10) between 0 and 1 @@ -73,6 +101,11 @@ _koi8r'a' = _koi8r'A' select _koi8r'a' = _koi8r'A' COLLATE koi8r_general_ci; _koi8r'a' = _koi8r'A' COLLATE koi8r_general_ci 1 +explain extended select _koi8r'a' = _koi8r'A' COLLATE koi8r_general_ci; +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 high_priority (_koi8r'a' = (_koi8r'A' collate _latin1'koi8r_general_ci')) AS `_koi8r'a' = _koi8r'A' COLLATE koi8r_general_ci` select _koi8r'a' = _koi8r'A' COLLATE koi8r_bin; _koi8r'a' = _koi8r'A' COLLATE koi8r_bin 0 diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index b8709487c6d..9d38083f48a 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -486,3 +486,8 @@ strcmp(date_format(utc_timestamp(),"%Y-%m-%d"), utc_date())=0 select strcmp(concat(utc_date(),' ',utc_time()),utc_timestamp())=0; strcmp(concat(utc_date(),' ',utc_time()),utc_timestamp())=0 1 +explain extended select period_add("9602",-12),period_diff(199505,"9404"),from_days(to_days("960101")),dayofmonth("1997-01-02"), month("1997-01-02"), monthname("1972-03-04"),dayofyear("0000-00-00"),HOUR("1997-03-03 23:03:22"),MINUTE("23:03:22"),SECOND(230322),QUARTER(980303),WEEK("1998-03-03"),yearweek("2000-01-01",1),week(19950101,1),year("98-02-03"),weekday(curdate())-weekday(now()),dayname("1962-03-03"),unix_timestamp(),sec_to_time(time_to_sec("0:30:47")/6.21),curtime(),utc_time(),curdate(),utc_date(),utc_timestamp(),date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w"),from_unixtime(unix_timestamp("1994-03-02 10:11:12")),"1997-12-31 23:59:59" + INTERVAL 1 SECOND,"1998-01-01 00:00:00" - INTERVAL 1 SECOND,INTERVAL 1 DAY + "1997-12-31", extract(YEAR FROM "1999-01-02 10:11:12"),date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND); +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 high_priority no_cache period_add(_latin1'9602',-(12)) AS `period_add("9602",-12)`,period_diff(199505,_latin1'9404') AS `period_diff(199505,"9404")`,from_days(to_days(_latin1'960101')) AS `from_days(to_days("960101"))`,dayofmonth(_latin1'1997-01-02') AS `dayofmonth("1997-01-02")`,month(_latin1'1997-01-02') AS `month("1997-01-02")`,monthname(_latin1'1972-03-04') AS `monthname("1972-03-04")`,dayofyear(_latin1'0000-00-00') AS `dayofyear("0000-00-00")`,hour(_latin1'1997-03-03 23:03:22') AS `HOUR("1997-03-03 23:03:22")`,minute(_latin1'23:03:22') AS `MINUTE("23:03:22")`,second(230322) AS `SECOND(230322)`,quarter(980303) AS `QUARTER(980303)`,week(_latin1'1998-03-03',0) AS `WEEK("1998-03-03")`,yearweek(_latin1'2000-01-01',1) AS `yearweek("2000-01-01",1)`,week(19950101,1) AS `week(19950101,1)`,year(_latin1'98-02-03') AS `year("98-02-03")`,(weekday(to_days(curdate())) - weekday(to_days(now()))) AS `weekday(curdate())-weekday(now())`,dayname(to_days(_latin1'1962-03-03')) AS `dayname("1962-03-03")`,unix_timestamp() AS `unix_timestamp()`,sec_to_time((time_to_sec(_latin1'0:30:47') / 6.21)) AS `sec_to_time(time_to_sec("0:30:47")/6.21)`,curtime() AS `curtime()`,utc_time() AS `utc_time()`,curdate() AS `curdate()`,utc_date() AS `utc_date()`,utc_timestamp() AS `utc_timestamp()`,date_format(_latin1'1997-01-02 03:04:05',_latin1'%M %W %D %Y %y %m %d %h %i %s %w') AS `date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w")`,from_unixtime(unix_timestamp(_latin1'1994-03-02 10:11:12')) AS `from_unixtime(unix_timestamp("1994-03-02 10:11:12"))`,(_latin1'1997-12-31 23:59:59' + interval 1 second) AS `"1997-12-31 23:59:59" + INTERVAL 1 SECOND`,(_latin1'1998-01-01 00:00:00' - interval 1 second) AS `"1998-01-01 00:00:00" - INTERVAL 1 SECOND`,(_latin1'1997-12-31' + interval 1 day) AS `INTERVAL 1 DAY + "1997-12-31"`,extract(year from _latin1'1999-01-02 10:11:12') AS `extract(YEAR FROM "1999-01-02 10:11:12")`,(_latin1'1997-12-31 23:59:59' + interval 1 second) AS `date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND)` diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index c286b4d8fc4..b9eaa81ba2a 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -284,9 +284,11 @@ select spid,count(*) from t1 where spid between 1 and 2 group by spid desc; spid count(*) 2 2 1 1 -explain select sql_big_result spid,sum(userid) from t1 group by spid desc; +explain extended select sql_big_result spid,sum(userid) from t1 group by spid desc; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 8 Using filesort +Warnings: +Note 1003 select high_priority big_result test.t1.spID AS `spid`,sum(test.t1.userID) AS `sum(userid)` from test.t1 group by test.t1.spID desc explain select sql_big_result spid,sum(userid) from t1 group by spid desc order by null; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 8 diff --git a/mysql-test/r/having.result b/mysql-test/r/having.result index fc0b3c652ef..7c88776579b 100644 --- a/mysql-test/r/having.result +++ b/mysql-test/r/having.result @@ -8,6 +8,11 @@ b select count(a) as b from t1 where a=0 having b >=0; b 0 +explain extended select count(a) as b from t1 where a=0 having b >=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 noticed after reading const tables +Warnings: +Note 1003 select high_priority count(test.t1.a) AS `b` from test.t1 where (test.t1.a = 0) having (count(test.t1.a) >= 0) drop table t1; CREATE TABLE t1 ( raw_id int(10) NOT NULL default '0', diff --git a/mysql-test/r/insert_update.result b/mysql-test/r/insert_update.result index 4ef25781331..3a7679ce1e3 100644 --- a/mysql-test/r/insert_update.result +++ b/mysql-test/r/insert_update.result @@ -56,4 +56,14 @@ a b c VALUES(a) 5 0 30 NULL 8 9 60 NULL 2 1 11 NULL +explain extended SELECT *, VALUES(a) FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 5 +Warnings: +Note 1003 select high_priority test.t1.a AS `a`,test.t1.b AS `b`,test.t1.c AS `c`,values(test.t1.a) AS `VALUES(a)` from test.t1 +explain extended select * from t1 where values(a); +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 high_priority test.t1.a AS `a`,test.t1.b AS `b`,test.t1.c AS `c` from test.t1 DROP TABLE t1; diff --git a/mysql-test/r/null.result b/mysql-test/r/null.result index 2ef1f0c86f9..9de9fdce2db 100644 --- a/mysql-test/r/null.result +++ b/mysql-test/r/null.result @@ -2,6 +2,11 @@ drop table if exists t1; select null,\N,isnull(null),isnull(1/0),isnull(1/0 = null),ifnull(null,1),ifnull(null,"TRUE"),ifnull("TRUE","ERROR"),1/0 is null,1 is not null; NULL NULL isnull(null) isnull(1/0) isnull(1/0 = null) ifnull(null,1) ifnull(null,"TRUE") ifnull("TRUE","ERROR") 1/0 is null 1 is not null NULL NULL 1 1 1 1 TRUE TRUE 1 1 +explain extended select null,\N,isnull(null),isnull(1/0),isnull(1/0 = null),ifnull(null,1),ifnull(null,"TRUE"),ifnull("TRUE","ERROR"),1/0 is null,1 is not null; +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 high_priority NULL AS `NULL`,NULL AS `NULL`,isnull(NULL) AS `isnull(null)`,isnull((1 / 0)) AS `isnull(1/0)`,isnull(((1 / 0) = NULL)) AS `isnull(1/0 = null)`,ifnull(NULL,1) AS `ifnull(null,1)`,ifnull(NULL,_latin1'TRUE') AS `ifnull(null,"TRUE")`,ifnull(_latin1'TRUE',_latin1'ERROR') AS `ifnull("TRUE","ERROR")`,isnull((1 / 0)) AS `1/0 is null`,(1 is not null) AS `1 is not null` select 1 | NULL,1 & NULL,1+NULL,1-NULL; 1 | NULL 1 & NULL 1+NULL 1-NULL NULL NULL NULL NULL @@ -23,6 +28,11 @@ field(NULL,"a","b","c") select 2 between null and 1,2 between 3 AND NULL,NULL between 1 and 2,2 between NULL and 3, 2 between 1 AND null; 2 between null and 1 2 between 3 AND NULL NULL between 1 and 2 2 between NULL and 3 2 between 1 AND null 0 0 NULL NULL NULL +explain extended select 2 between null and 1,2 between 3 AND NULL,NULL between 1 and 2,2 between NULL and 3, 2 between 1 AND null; +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 high_priority (2 between NULL and 1) AS `2 between null and 1`,(2 between 3 and NULL) AS `2 between 3 AND NULL`,(NULL between 1 and 2) AS `NULL between 1 and 2`,(2 between NULL and 3) AS `2 between NULL and 3`,(2 between 1 and NULL) AS `2 between 1 AND null` SELECT NULL AND NULL, 1 AND NULL, NULL AND 1, NULL OR NULL, 0 OR NULL, NULL OR 0; NULL AND NULL 1 AND NULL NULL AND 1 NULL OR NULL 0 OR NULL NULL OR 0 NULL NULL NULL NULL NULL NULL @@ -35,6 +45,11 @@ NULL AND 0 0 and NULL select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton(""); inet_ntoa(null) inet_aton(null) inet_aton("122.256") inet_aton("122.226.") inet_aton("") NULL NULL NULL NULL NULL +explain extended select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton(""); +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 high_priority inet_ntoa(NULL) AS `inet_ntoa(null)`,inet_aton(NULL) AS `inet_aton(null)`,inet_aton(_latin1'122.256') AS `inet_aton("122.256")`,inet_aton(_latin1'122.226.') AS `inet_aton("122.226.")`,inet_aton(_latin1'') AS `inet_aton("")` create table t1 (x int); insert into t1 values (null); select * from t1 where x != 0; diff --git a/mysql-test/r/olap.result b/mysql-test/r/olap.result index 84e37bf56a9..37e68d8b13e 100644 --- a/mysql-test/r/olap.result +++ b/mysql-test/r/olap.result @@ -81,9 +81,11 @@ TV 2 2000 200 TV 2 NULL 200 TV NULL NULL 600 NULL NULL NULL 7785 -explain select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup; +explain extended select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 15 Using temporary; Using filesort +Warnings: +Note 1003 select high_priority test.t1.product AS `product`,test.t1.country_id AS `country_id`,test.t1.year AS `year`,sum(test.t1.profit) AS `sum(profit)` from test.t1 group by test.t1.product,test.t1.country_id,test.t1.year with rollup select product, country_id , sum(profit) from t1 group by product desc, country_id with rollup; product country_id sum(profit) TV 1 400 diff --git a/mysql-test/r/query_cache.result b/mysql-test/r/query_cache.result index 1a1eec1f915..b446d30c83f 100644 --- a/mysql-test/r/query_cache.result +++ b/mysql-test/r/query_cache.result @@ -300,6 +300,11 @@ select USER() from t1; USER() select benchmark(1,1) from t1; benchmark(1,1) +explain extended select benchmark(1,1) 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 +Warnings: +Note 1003 select high_priority no_cache benchmark(1,1) AS `benchmark(1,1)` from test.t1 show status like "Qcache_queries_in_cache"; Variable_name Value Qcache_queries_in_cache 0 diff --git a/mysql-test/r/row.result b/mysql-test/r/row.result index ab60f714d82..37d4f1d9b26 100644 --- a/mysql-test/r/row.result +++ b/mysql-test/r/row.result @@ -40,6 +40,11 @@ ERROR 21000: Operand should contain 2 column(s) select row(1,2,row(3,4)) IN (row(3,2,row(3,4)), row(1,2,row(3,NULL))); row(1,2,row(3,4)) IN (row(3,2,row(3,4)), row(1,2,row(3,NULL))) NULL +explain extended select row(1,2,row(3,4)) IN (row(3,2,row(3,4)), row(1,2,row(3,NULL))); +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 high_priority ((1,2,(3,4)) in ((3,2,(3,4)),(1,2,(3,NULL)))) AS `row(1,2,row(3,4)) IN (row(3,2,row(3,4)), row(1,2,row(3,NULL)))` SELECT (1,2,3)=(0,NULL,3); (1,2,3)=(0,NULL,3) 0 diff --git a/mysql-test/r/rpl000001.result b/mysql-test/r/rpl000001.result index 79438f8fa40..b8071b16c2e 100644 --- a/mysql-test/r/rpl000001.result +++ b/mysql-test/r/rpl000001.result @@ -40,10 +40,20 @@ create table t1(n int); select get_lock("hold_slave",10); get_lock("hold_slave",10) 1 +explain extended select get_lock("hold_slave",10); +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 high_priority no_cache get_lock(_latin1'hold_slave',10) AS `get_lock("hold_slave",10)` start slave; select release_lock("hold_slave"); release_lock("hold_slave") 1 +explain extended select release_lock("hold_slave"); +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 high_priority no_cache release_lock(_latin1'hold_slave') AS `release_lock("hold_slave")` unlock tables; create table t2(id int); insert into t2 values(connection_id()); diff --git a/mysql-test/r/rpl_get_lock.result b/mysql-test/r/rpl_get_lock.result index 369fde7ef8f..8e3e335b2d0 100644 --- a/mysql-test/r/rpl_get_lock.result +++ b/mysql-test/r/rpl_get_lock.result @@ -18,9 +18,14 @@ get_lock("lock",3) select * from t1; n 1 -select is_free_lock("lock"); -is_free_lock("lock") -0 +select is_free_lock("lock"), is_used_lock("lock"); +is_free_lock("lock") is_used_lock("lock") +0 6 +explain extended select is_free_lock("lock"), is_used_lock("lock"); +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 high_priority no_cache is_free_lock(_latin1'lock') AS `is_free_lock("lock")`,is_used_lock(_latin1'lock') AS `is_used_lock("lock")` select is_free_lock("lock2"); is_free_lock("lock2") 1 diff --git a/mysql-test/r/rpl_master_pos_wait.result b/mysql-test/r/rpl_master_pos_wait.result index bbd125a98d6..ea917805560 100644 --- a/mysql-test/r/rpl_master_pos_wait.result +++ b/mysql-test/r/rpl_master_pos_wait.result @@ -7,6 +7,11 @@ start slave; select master_pos_wait('master-bin.999999',0,2); master_pos_wait('master-bin.999999',0,2) -1 +explain extended select master_pos_wait('master-bin.999999',0,2); +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 high_priority no_cache master_pos_wait(_latin1'master-bin.999999',0,2) AS `master_pos_wait('master-bin.999999',0,2)` select master_pos_wait('master-bin.999999',0); stop slave sql_thread; master_pos_wait('master-bin.999999',0) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index fca4a0549d3..b9218942a5e 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -1466,6 +1466,11 @@ companynr count(*) select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>""; count(*) min(fld4) max(fld4) sum(fld1) avg(fld1) std(fld1) variance(fld1) 70 absentee vest 17788966 254128.0857 3272.5940 10709871.3069 +explain extended select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>""; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +Warnings: +Note 1003 select high_priority count(0) AS `count(*)`,min(test.t2.fld4) AS `min(fld4)`,max(test.t2.fld4) AS `max(fld4)`,sum(test.t2.fld1) AS `sum(fld1)`,avg(test.t2.fld1) AS `avg(fld1)`,std(test.t2.fld1) AS `std(fld1)`,variance(test.t2.fld1) AS `variance(fld1)` from test.t2 where ((test.t2.companynr = 34) and (test.t2.fld4 <> _latin1'')) select companynr,count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 group by companynr limit 3; companynr count(*) min(fld4) max(fld4) sum(fld1) avg(fld1) std(fld1) variance(fld1) 00 82 Anthony windmills 10355753 126289.6707 115550.9757 13352027981.7087 diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index a2e83729513..048464e6b84 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -2,32 +2,35 @@ drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12; select (select 2); (select 2) 2 -explain select (select 2); +explain extended select (select 2); 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 Warnings: Note 1248 Select 2 was reduced during optimisation +Note 1003 select high_priority 2 AS `(select 2)` SELECT (SELECT 1) UNION SELECT (SELECT 2); (SELECT 1) 1 2 -explain SELECT (SELECT 1) UNION SELECT (SELECT 2); +explain extended SELECT (SELECT 1) UNION SELECT (SELECT 2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used 3 UNION NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1248 Select 2 was reduced during optimisation Note 1248 Select 4 was reduced during optimisation +Note 1003 select high_priority 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 SELECT (SELECT (SELECT 0 UNION SELECT 0)); +explain extended SELECT (SELECT (SELECT 0 UNION SELECT 0)); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used 3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used 4 UNION NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1248 Select 2 was reduced during optimisation +Note 1003 select high_priority (select 0 AS `0` union select 0 AS `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; @@ -37,7 +40,7 @@ SELECT (SELECT 1),MAX(1) FROM (SELECT 1) as a; 1 1 SELECT (SELECT a) as a; ERROR 42S22: Reference 'a' not supported (forward reference in item list) -EXPLAIN SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; +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 Extra 1 PRIMARY <derived2> system NULL NULL NULL NULL 1 3 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used @@ -45,6 +48,7 @@ id select_type table type possible_keys key key_len ref rows Extra Warnings: Note 1275 Field or reference 'a' of SELECT #3 was resolved in SELECT #1 Note 1275 Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1 +Note 1003 select high_priority 1 AS `1` from (select 1 AS `a`) b having ((select b.a AS `a`) = 1) SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; 1 1 @@ -172,12 +176,14 @@ a b 2 7 3 8 4 8 -explain (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); +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 Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where 2 SUBQUERY t3 ALL NULL NULL NULL NULL 3 Using filesort 3 UNION t4 ALL NULL NULL NULL NULL 3 Using where; Using filesort 4 SUBQUERY t2 ALL NULL NULL NULL NULL 2 +Warnings: +Note 1003 (select high_priority test.t2.a AS `a`,test.t2.b AS `b` from test.t2 where (test.t2.b = (select test.t3.a AS `a` from test.t3 order by test.t3.a 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) AS `max(t2.a)*4` from test.t2)) order by test.t4.a) 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 @@ -186,12 +192,14 @@ 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 -explain select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from +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 Extra 1 PRIMARY <derived3> system NULL NULL NULL NULL 1 3 DERIVED t2 ALL NULL NULL NULL NULL 2 Using where 2 SUBQUERY t3 ALL NULL NULL NULL NULL 3 Using where; Using filesort +Warnings: +Note 1003 select high_priority (select test.t3.a AS `a` from test.t3 where (test.t3.a < 8) order by test.t3.a 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 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 @@ -205,13 +213,14 @@ 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 select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; +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 Extra 1 PRIMARY t4 ALL NULL NULL NULL NULL 3 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 Using where Warnings: Note 1275 Field or reference 't4.a' of SELECT #3 was resolved in SELECT #1 +Note 1003 select high_priority test.t4.b AS `b`,(select avg((test.t2.a + (select min(test.t3.a) AS `min(t3.a)` from test.t3 where (test.t3.a >= test.t4.a)))) AS `avg(t2.a+(select min(t3.a) from t3 where t3.a >= 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 @@ -252,10 +261,12 @@ select * from t3 where a >= any (select b from t2); a 6 7 -explain select * from t3 where a >= any (select b from t2); +explain extended select * from t3 where a >= any (select b from t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t3 ALL NULL NULL NULL NULL 3 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 3 +Warnings: +Note 1003 select high_priority test.t3.a AS `a` from test.t3 where (test.t3.a >= (select min(test.t2.b) from test.t2 limit 1)) select * from t3 where a >= all (select b from t2); a 7 @@ -290,7 +301,7 @@ select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a) (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 select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +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 Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 1 @@ -298,6 +309,7 @@ id select_type table type possible_keys key key_len ref rows Extra Warnings: Note 1275 Field or reference 't2.a' of SELECT #2 was resolved in SELECT #1 Note 1275 Field or reference 't2.a' of SELECT #3 was resolved in SELECT #1 +Note 1003 select high_priority (select test.t1.a AS `a` from test.t1 where (test.t1.a = test.t2.a) union select test.t5.a AS `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)); @@ -309,12 +321,13 @@ patient_uq clinic_uq 1 1 1 2 2 2 -explain select * from t6 where exists (select * from t7 where uq = clinic_uq); +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 Extra 1 PRIMARY t6 ALL NULL NULL NULL NULL 4 Using where 2 DEPENDENT SUBQUERY t7 eq_ref PRIMARY PRIMARY 4 test.t6.clinic_uq 1 Warnings: Note 1275 Field or reference 'clinic_uq' of SELECT #2 was resolved in SELECT #1 +Note 1003 select high_priority test.t6.patient_uq AS `patient_uq`,test.t6.clinic_uq AS `clinic_uq` from test.t6 where exists(select test.t7.uq AS `uq`,test.t7.name AS `name` from test.t7 where (test.t7.uq = test.t6.clinic_uq) limit 1) 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 if exists t1,t2,t3; @@ -342,12 +355,14 @@ UNIQUE KEY `email` (`email`) 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 SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); +EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t8 const PRIMARY PRIMARY 35 const 1 4 SUBQUERY t8 const PRIMARY PRIMARY 35 1 2 SUBQUERY t8 const PRIMARY PRIMARY 35 const 1 3 SUBQUERY t8 const PRIMARY PRIMARY 35 1 +Warnings: +Note 1003 select high_priority test.t8.pseudo AS `pseudo`,(select test.t8.email AS `email` from test.t8 where (test.t8.pseudo = (select test.t8.pseudo AS `pseudo` from test.t8 where (test.t8.pseudo = _latin1'joce')))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from test.t8 where (test.t8.pseudo = (select test.t8.pseudo AS `pseudo` from test.t8 where (test.t8.pseudo = _latin1'joce'))) SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM t8 WHERE pseudo='joce'); ERROR 21000: Operand should contain 1 column(s) @@ -369,13 +384,17 @@ KEY `topic` (`topic`) ) TYPE=MyISAM ROW_FORMAT=DYNAMIC; INSERT INTO t1 (topic,date,pseudo) VALUES ('43506','2002-10-02','joce'),('40143','2002-08-03','joce'); -EXPLAIN SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; +EXPLAIN EXTENDED SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL PRIMARY 41 NULL 2 Using where; Using index -EXPLAIN SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'); +Warnings: +Note 1003 select high_priority distinct test.t1.date AS `date` from test.t1 where (test.t1.date = 20020803) +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 Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used 2 SUBQUERY t1 index NULL PRIMARY 41 NULL 2 Using where; Using index +Warnings: +Note 1003 select high_priority (select distinct test.t1.date AS `date` from test.t1 where (test.t1.date = 20020803)) 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 @@ -389,11 +408,13 @@ SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1) UNION ALL SELECT 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 SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1); +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 Extra 1 PRIMARY t1 index NULL topic 3 NULL 2 Using index 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL No tables used 3 UNION NULL NULL NULL NULL NULL NULL NULL No tables used +Warnings: +Note 1003 select high_priority 1 AS `1` from test.t1 drop table t1; CREATE TABLE `t1` ( `numeropost` mediumint(8) unsigned NOT NULL auto_increment, @@ -507,15 +528,19 @@ 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 SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); +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 -EXPLAIN SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; +EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -EXPLAIN SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'); +Warnings: +Note 1003 select high_priority max(test.t1.numreponse) AS `MAX(numreponse)` from test.t1 where (test.t1.numeropost = _latin1'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 Extra 1 PRIMARY t1 const PRIMARY,numreponse PRIMARY 7 const,const 1 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +Warnings: +Note 1003 select high_priority test.t1.numreponse AS `numreponse` from test.t1 where ((test.t1.numeropost = _latin1'1') and (test.t1.numreponse = 3)) drop table t1; CREATE TABLE t1 (a int(1)); INSERT INTO t1 VALUES (1); @@ -678,28 +703,32 @@ INSERT INTO t2 VALUES (1),(2); SELECT * FROM t2 WHERE id IN (SELECT 1); id 1 -EXPLAIN SELECT * FROM t2 WHERE id IN (SELECT 1); +EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 ref id id 5 const 1 Using where; Using index Warnings: Note 1248 Select 2 was reduced during optimisation +Note 1003 select high_priority 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 SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1)); +EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1)); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 ref id id 5 const 1 Using where; Using index Warnings: Note 1248 Select 3 was reduced during optimisation Note 1248 Select 2 was reduced during optimisation -EXPLAIN SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3); +Note 1003 select high_priority test.t2.id AS `id` from test.t2 where (test.t2.id = (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 Extra 1 PRIMARY t2 index NULL id 5 NULL 2 Using where; Using index 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 +Warnings: +Note 1003 select high_priority test.t2.id AS `id` from test.t2 where <in_optimizer>(test.t2.id,<exists>(select 1 AS `Not_used` having (<cache>(test.t2.id) = <null_helper>(1)) limit 1 union select 1 AS `Not_used` having (<cache>(test.t2.id) = <null_helper>(3)) limit 1)) SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 3); id SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 2); @@ -819,12 +848,13 @@ NULL select 10.5 > ANY (SELECT * from t1); 10.5 > ANY (SELECT * from t1) 1 -explain select (select a+1) from t1; +explain extended select (select a+1) from t1; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Warnings: Note 1275 Field or reference 'a' of SELECT #2 was resolved in SELECT #1 Note 1248 Select 2 was reduced during optimisation +Note 1003 select high_priority (test.t1.a + 1) AS `(select a+1)` from test.t1 select (select a+1) from t1; (select a+1) 2.5 @@ -841,10 +871,12 @@ a t1.a in (select t2.a from t2) 2 1 3 1 4 0 -explain SELECT t1.a, t1.a in (select t2.a from t2) FROM t1; +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 Extra 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 Using index 2 DEPENDENT SUBQUERY t2 index_subquery a a 5 func 2 Using index +Warnings: +Note 1003 select high_priority test.t1.a AS `a`,<in_optimizer>(test.t1.a,<exists>(<index_lookup>(<cache>(test.t1.a) in t2 on a chicking NULL))) 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; @@ -853,11 +885,13 @@ a t1.a in (select t2.a from t2,t3 where t3.a=t2.a) 2 1 3 1 4 0 -explain SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1; +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 Extra 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 Using index 2 DEPENDENT SUBQUERY t2 ref_or_null a a 5 func 2 Using where; Using index 2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 Using where +Warnings: +Note 1003 select high_priority test.t1.a AS `a`,<in_optimizer>(test.t1.a,<exists>(select 1 AS `Not_used` 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) limit 1)) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from test.t1 drop table t1,t2,t3; create table t1 (a float); select 10.5 IN (SELECT * from t1 LIMIT 1); @@ -962,18 +996,24 @@ UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i)); ERROR HY000: Invalid use of group function drop table t1; CREATE TABLE t1 (a int(1)); -EXPLAIN SELECT (SELECT RAND() FROM t1) FROM t1; +EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1; 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 UNCACHEABLE SUBQUERY t1 system NULL NULL NULL NULL 0 const row not found -EXPLAIN SELECT (SELECT ENCRYPT('test') FROM t1) FROM t1; +Warnings: +Note 1003 select high_priority no_cache (select no_cache rand() AS `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 Extra 1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found 2 UNCACHEABLE SUBQUERY t1 system NULL NULL NULL NULL 0 const row not found -EXPLAIN SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1; +Warnings: +Note 1003 select high_priority no_cache (select no_cache ecrypt(_latin1'test') AS `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 Extra 1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found 2 UNCACHEABLE SUBQUERY t1 system NULL NULL NULL NULL 0 const row not found +Warnings: +Note 1003 select high_priority no_cache (select no_cache benchmark(1,1) AS `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 '', @@ -1061,12 +1101,14 @@ t1 CREATE TABLE `t1` ( drop table t1; create table t1 (a int); insert into t1 values (1), (2), (3); -explain select a,(select (select rand() from t1 limit 1) from t1 limit 1) +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 Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 2 UNCACHEABLE SUBQUERY t1 ALL NULL NULL NULL NULL 3 3 UNCACHEABLE SUBQUERY t1 ALL NULL NULL NULL NULL 3 +Warnings: +Note 1003 select high_priority no_cache test.t1.a AS `a`,(select no_cache (select no_cache rand() AS `rand()` from test.t1 limit 1) AS `(select rand() from 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 @@ -1115,18 +1157,22 @@ INSERT INTO t1 (pseudo) VALUES ('test'); SELECT 0 IN (SELECT 1 FROM t1 a); 0 IN (SELECT 1 FROM t1 a) 0 -EXPLAIN SELECT 0 IN (SELECT 1 FROM t1 a); +EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); 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 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select high_priority <in_optimizer>(0,<exists>(select 1 AS `Not_used` from test.t1 a where isnull(1) having <is_not_null_test>(1) limit 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 SELECT 0 IN (SELECT 1 FROM t1 a); +EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); 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 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Note 1003 select high_priority <in_optimizer>(0,<exists>(select 1 AS `Not_used` from test.t1 a where isnull(1) having <is_not_null_test>(1) limit 1)) AS `0 IN (SELECT 1 FROM t1 a)` drop table t1; CREATE TABLE `t1` ( `i` int(11) NOT NULL default '0', @@ -1165,10 +1211,12 @@ 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 SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1); +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 Extra 1 PRIMARY t1 ref salary salary 5 const 1 Using where 2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +Warnings: +Note 1003 select high_priority test.t1.id AS `id` from test.t1 where (test.t1.salary = (select max(test.t1.salary) AS `MAX(salary)` from test.t1)) drop table t1; CREATE TABLE t1 ( ID int(10) unsigned NOT NULL auto_increment, @@ -1255,27 +1303,33 @@ a 2 3 4 -explain select * from t2 where t2.a in (select a from t1); +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 Extra 1 PRIMARY t2 index NULL PRIMARY 4 NULL 4 Using where; Using index 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 Using index +Warnings: +Note 1003 select high_priority test.t2.a AS `a` from test.t2 where <in_optimizer>(test.t2.a,<exists>(<primary_index_lookup>(<cache>(test.t2.a) in t1 on PRIMARY))) select * from t2 where t2.a in (select a from t1 where t1.b <> 30); a 2 4 -explain select * from t2 where t2.a in (select a from t1 where t1.b <> 30); +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 Extra 1 PRIMARY t2 index NULL PRIMARY 4 NULL 4 Using where; Using index 2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 Using index; Using where +Warnings: +Note 1003 select high_priority test.t2.a AS `a` from test.t2 where <in_optimizer>(test.t2.a,<exists>(<primary_index_lookup>(<cache>(test.t2.a) in t1 on PRIMARY where (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 select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); +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 Extra 1 PRIMARY t2 index NULL PRIMARY 4 NULL 4 Using where; Using index 2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 func 1 Using where 2 DEPENDENT SUBQUERY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 Using where; Using index +Warnings: +Note 1003 select high_priority test.t2.a AS `a` from test.t2 where <in_optimizer>(test.t2.a,<exists>(select 1 AS `Not_used` from test.t1 join test.t3 where ((test.t1.b = test.t3.a) and (<cache>(test.t2.a) = test.t1.a)) limit 1)) drop table t1, t2, t3; create table t1 (a int, b int, index a (a,b)); create table t2 (a int, index a (a)); @@ -1288,27 +1342,33 @@ a 2 3 4 -explain select * from t2 where t2.a in (select a from t1); +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 Extra 1 PRIMARY t2 index NULL a 5 NULL 4 Using where; Using index 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 Using index +Warnings: +Note 1003 select high_priority test.t2.a AS `a` from test.t2 where <in_optimizer>(test.t2.a,<exists>(<index_lookup>(<cache>(test.t2.a) in t1 on a))) select * from t2 where t2.a in (select a from t1 where t1.b <> 30); a 2 4 -explain select * from t2 where t2.a in (select a from t1 where t1.b <> 30); +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 Extra 1 PRIMARY t2 index NULL a 5 NULL 4 Using where; Using index 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 Using index; Using where +Warnings: +Note 1003 select high_priority test.t2.a AS `a` from test.t2 where <in_optimizer>(test.t2.a,<exists>(<index_lookup>(<cache>(test.t2.a) in t1 on a where (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 select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); +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 Extra 1 PRIMARY t2 index NULL a 5 NULL 4 Using where; Using index 2 DEPENDENT SUBQUERY t3 index a a 5 NULL 3 Using index 2 DEPENDENT SUBQUERY t1 ref a a 10 func,test.t3.a 1000 Using where; Using index +Warnings: +Note 1003 select high_priority test.t2.a AS `a` from test.t2 where <in_optimizer>(test.t2.a,<exists>(select 1 AS `Not_used` from test.t1 join test.t3 where ((test.t1.b = test.t3.a) and (<cache>(test.t2.a) = test.t1.a)) limit 1)) insert into t1 values (3,31); select * from t2 where t2.a in (select a from t1 where t1.b <> 30); a @@ -1319,10 +1379,12 @@ select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31 a 2 4 -explain select * from t2 where t2.a in (select a from t1 where t1.b <> 30); +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 Extra 1 PRIMARY t2 index NULL a 5 NULL 4 Using where; Using index 2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 1001 Using index; Using where +Warnings: +Note 1003 select high_priority test.t2.a AS `a` from test.t2 where <in_optimizer>(test.t2.a,<exists>(<index_lookup>(<cache>(test.t2.a) in t1 on a where (test.t1.b <> 30)))) drop table t1, t2, t3; create table t1 (a int, b int); create table t2 (a int, b int); @@ -1387,9 +1449,11 @@ 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 (select * from t1); +explain extended (select * from t1); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 +Warnings: +Note 1003 (select high_priority test.t1.s1 AS `s1` from test.t1) (select * from t1); s1 tttt @@ -1418,22 +1482,30 @@ s1 s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') a1 0 a2 1 a3 1 -explain select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; +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 Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 Using index 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 Using index -explain select s1, s1 = ANY (SELECT s1 FROM t2) from t1; +Warnings: +Note 1003 select high_priority test.t1.s1 AS `s1`,not(<in_optimizer>(test.t1.s1,<exists>(<index_lookup>(<cache>(test.t1.s1) in t2 on s1 chicking NULL)))) 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 Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 Using index 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 Using index -explain select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; +Warnings: +Note 1003 select high_priority test.t1.s1 AS `s1`,<in_optimizer>(test.t1.s1,<exists>(<index_lookup>(<cache>(test.t1.s1) in t2 on s1 chicking NULL))) 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 Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 Using index 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 Using index -explain select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; +Warnings: +Note 1003 select high_priority test.t1.s1 AS `s1`,not(<in_optimizer>(test.t1.s1,<exists>(<index_lookup>(<cache>(test.t1.s1) in t2 on s1 chicking NULL)))) 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 Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 Using index 2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 1 Using index; Using where +Warnings: +Note 1003 select high_priority test.t1.s1 AS `s1`,not(<in_optimizer>(test.t1.s1,<exists>(<index_lookup>(<cache>(test.t1.s1) in t2 on s1 chicking NULL where (test.t2.s1 < _latin1'a2'))))) 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); create table t3 (a int); @@ -1443,19 +1515,23 @@ a 6 7 3 -explain select * from t3 where a >= all (select b from t2); +explain extended select * from t3 where a >= all (select b from t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t3 ALL NULL NULL NULL NULL 3 Using where 2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found +Warnings: +Note 1003 select high_priority test.t3.a AS `a` from test.t3 where <not>((test.t3.a < (select max(test.t2.b) from test.t2 limit 1))) 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 select * from t3 where a > all (select max(b) from t2 group by a); +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 Extra 1 PRIMARY t3 ALL NULL NULL NULL NULL 3 Using where 2 SUBQUERY t2 ALL NULL NULL NULL NULL 4 Using temporary; Using filesort +Warnings: +Note 1003 select high_priority test.t3.a AS `a` from test.t3 where <not>((test.t3.a <= <max>(select max(test.t2.b) AS `max(b)` from test.t2 group by test.t2.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`)) TYPE=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()); diff --git a/mysql-test/r/type_blob.result b/mysql-test/r/type_blob.result index f12be1d363c..82aefa78bb2 100644 --- a/mysql-test/r/type_blob.result +++ b/mysql-test/r/type_blob.result @@ -492,6 +492,14 @@ collation(load_file('../../std_data/words.dat')), coercibility(load_file('../../std_data/words.dat')); charset(load_file('../../std_data/words.dat')) collation(load_file('../../std_data/words.dat')) coercibility(load_file('../../std_data/words.dat')) binary binary 3 +explain extended select +charset(load_file('../../std_data/words.dat')), +collation(load_file('../../std_data/words.dat')), +coercibility(load_file('../../std_data/words.dat')); +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 high_priority no_cache charset(load_file(_latin1'../../std_data/words.dat')) AS `charset(load_file('../../std_data/words.dat'))`,collation(load_file(_latin1'../../std_data/words.dat')) AS `collation(load_file('../../std_data/words.dat'))`,coercibility(load_file(_latin1'../../std_data/words.dat')) AS `coercibility(load_file('../../std_data/words.dat'))` update t1 set imagem=load_file('../../std_data/words.dat') where id=1; select if(imagem is null, "ERROR", "OK"),length(imagem) from t1 where id = 1; if(imagem is null, "ERROR", "OK") length(imagem) diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result index bf47e6ad430..5729d3b32ee 100644 --- a/mysql-test/r/union.result +++ b/mysql-test/r/union.result @@ -86,10 +86,12 @@ a b 1 a (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by t1.b; ERROR 42000: Table 't1' from one of SELECT's can not be used in global ORDER clause -explain (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc; +explain extended (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 4 2 UNION t2 ALL NULL NULL NULL NULL 4 Using filesort +Warnings: +Note 1003 (select high_priority test.t1.a AS `a`,test.t1.b AS `b` from test.t1 limit 2) union all (select test.t2.a AS `a`,test.t2.b AS `b` from test.t2 order by test.t2.a limit 1) order by b desc (select sql_calc_found_rows a,b from t1 limit 2) union all (select a,b from t2 order by a) limit 2; a b 1 a @@ -463,10 +465,12 @@ create table t1 (a int not null primary key auto_increment, b int, key(b)); create table t2 (a int not null primary key auto_increment, b int); insert into t1 (b) values (1),(2),(2),(3); insert into t2 (b) values (10),(11),(12),(13); -explain (select * from t1 where a=1) union (select * from t2 where a=1); +explain extended (select * from t1 where a=1) union (select * from t2 where a=1); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 const PRIMARY PRIMARY 4 const 1 2 UNION t2 const PRIMARY PRIMARY 4 const 1 +Warnings: +Note 1003 (select high_priority test.t1.a AS `a`,test.t1.b AS `b` from test.t1 where (test.t1.a = 1)) union (select test.t2.a AS `a`,test.t2.b AS `b` from test.t2 where (test.t2.a = 1)) (select * from t1 where a=5) union (select * from t2 where a=1); a b 1 10 diff --git a/mysql-test/r/varbinary.result b/mysql-test/r/varbinary.result index 5464d741f70..cf001158ae2 100644 --- a/mysql-test/r/varbinary.result +++ b/mysql-test/r/varbinary.result @@ -11,9 +11,11 @@ x'31' X'ffff'+0 create table t1 (ID int(8) unsigned zerofill not null auto_increment,UNIQ bigint(21) unsigned zerofill not null,primary key (ID),unique (UNIQ) ); insert into t1 set UNIQ=0x38afba1d73e6a18a; insert into t1 set UNIQ=123; -explain select * from t1 where UNIQ=0x38afba1d73e6a18a; +explain extended select * from t1 where UNIQ=0x38afba1d73e6a18a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 const UNIQ UNIQ 8 const 1 +Warnings: +Note 1003 select high_priority test.t1.ID AS `ID`,test.t1.UNIQ AS `UNIQ` from test.t1 where (test.t1.UNIQ = 4084688022709641610) drop table t1; select x'hello'; ERROR 42000: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'x'hello'' at line 1 diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result index 52ea28e6076..90654bece2e 100644 --- a/mysql-test/r/variables.result +++ b/mysql-test/r/variables.result @@ -22,6 +22,11 @@ NULL NULL NULL NULL select @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3; @t1:=(@t2:=1)+@t3:=4 @t1 @t2 @t3 5 5 1 4 +explain extended select @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3; +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 high_priority no_cache (@t1:=((@t2:=1) + (@t3:=4))) AS `@t1:=(@t2:=1)+@t3:=4`,(@t1) AS `@t1`,(@t2) AS `@t2`,(@t3) AS `@t3` select @t5; @t5 1.23456 @@ -76,9 +81,19 @@ select @@VERSION=version(); select last_insert_id(345); last_insert_id(345) 345 +explain extended select last_insert_id(345); +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 high_priority no_cache last_insert_id(345) AS `last_insert_id(345)` select @@IDENTITY,last_insert_id(), @@identity; @@IDENTITY last_insert_id() @@identity 345 345 345 +explain extended select @@IDENTITY,last_insert_id(), @@identity; +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 high_priority no_cache 345 AS `@@IDENTITY`,345 AS `last_insert_id()`,345 AS `@@identity` set big_tables=OFF, big_tables=ON, big_tables=0, big_tables=1, big_tables="OFF", big_tables="ON"; set global concurrent_insert=ON; show variables like 'concurrent_insert'; diff --git a/mysql-test/t/auto_increment.test b/mysql-test/t/auto_increment.test index a036121f297..d02850f6745 100644 --- a/mysql-test/t/auto_increment.test +++ b/mysql-test/t/auto_increment.test @@ -80,6 +80,7 @@ create table t1 (i tinyint unsigned not null auto_increment primary key); insert into t1 set i = 254; insert into t1 set i = null; select last_insert_id(); +explain extended select last_insert_id(); --error 1062 insert into t1 set i = 254; select last_insert_id(); diff --git a/mysql-test/t/bench_count_distinct.test b/mysql-test/t/bench_count_distinct.test index c1adeab2c44..3ffb95a69c2 100644 --- a/mysql-test/t/bench_count_distinct.test +++ b/mysql-test/t/bench_count_distinct.test @@ -16,4 +16,5 @@ while ($1) } enable_query_log; select count(distinct n) from t1; +explain extended select count(distinct n) from t1; drop table t1; diff --git a/mysql-test/t/case.test b/mysql-test/t/case.test index 4d4ceb062e4..9a1b6b6bbfe 100644 --- a/mysql-test/t/case.test +++ b/mysql-test/t/case.test @@ -14,6 +14,7 @@ select CASE "b" when "a" then 1 when binary "B" then 2 WHEN "b" then "ok" END; select CASE concat("a","b") when concat("ab","") then "a" when "b" then "b" end; select CASE when 1=0 then "true" else "false" END; select CASE 1 when 1 then "one" WHEN 2 then "two" ELSE "more" END; +explain extended select CASE 1 when 1 then "one" WHEN 2 then "two" ELSE "more" END; select CASE 2.0 when 1 then "one" WHEN 2.0 then "two" ELSE "more" END; select (CASE "two" when "one" then "1" WHEN "two" then "2" END) | 0; select (CASE "two" when "one" then 1.00 WHEN "two" then 2.00 END) +0.0; @@ -30,6 +31,7 @@ select case when 1<0 then "TRUE" else "FALSE" END; create table t1 (a int); insert into t1 values(1),(2),(3),(4); select case a when 1 then 2 when 2 then 3 else 0 end as fcase, count(*) from t1 group by fcase; +explain extended select case a when 1 then 2 when 2 then 3 else 0 end as fcase, count(*) from t1 group by fcase; select case a when 1 then "one" when 2 then "two" else "nothing" end as fcase, count(*) from t1 group by fcase; drop table t1; @@ -98,5 +100,9 @@ CREATE TABLE t1 SELECT COALESCE(1), COALESCE(1.0),COALESCE('a'), COALESCE(1,1.0), COALESCE(1,'1'),COALESCE(1.1,'1'), COALESCE('a' COLLATE latin1_bin,'b'); +explain extended SELECT + COALESCE(1), COALESCE(1.0),COALESCE('a'), + COALESCE(1,1.0), COALESCE(1,'1'),COALESCE(1.1,'1'), + COALESCE('a' COLLATE latin1_bin,'b'); SHOW CREATE TABLE t1; DROP TABLE t1; diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test index b3ae8981671..dd17904effb 100644 --- a/mysql-test/t/cast.test +++ b/mysql-test/t/cast.test @@ -8,6 +8,7 @@ select CONVERT('-1',UNSIGNED); select cast(-5 as unsigned) | 1, cast(-5 as unsigned) & -1; select cast(-5 as unsigned) -1, cast(-5 as unsigned) + 1; select ~5, cast(~5 as signed); +explain extended select ~5, cast(~5 as signed); select cast(5 as unsigned) -6.0; select cast("A" as binary) = "a", cast(BINARY "a" as CHAR) = "A"; select cast("2001-1-1" as DATE), cast("2001-1-1" as DATETIME); diff --git a/mysql-test/t/ctype_collate.test b/mysql-test/t/ctype_collate.test index d42696e693b..2d9a4be5b36 100644 --- a/mysql-test/t/ctype_collate.test +++ b/mysql-test/t/ctype_collate.test @@ -139,6 +139,7 @@ SHOW FIELDS FROM t1; SET CHARACTER SET 'latin1'; SHOW VARIABLES LIKE 'character_set_client'; SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; +explain extended SELECT charset('a'),collation('a'),coercibility('a'),'a'='A'; SET CHARACTER SET koi8r; SHOW VARIABLES LIKE 'collation_client'; diff --git a/mysql-test/t/ctype_many.test b/mysql-test/t/ctype_many.test index 66732520f4d..a1549f952e5 100644 --- a/mysql-test/t/ctype_many.test +++ b/mysql-test/t/ctype_many.test @@ -147,6 +147,12 @@ UPDATE t1 SET utf8_f=CONVERT(koi8_ru_f USING utf8); SET CHARACTER SET koi8r; SELECT * FROM t1; +# +# codecovarage for Item_func_conv_charset3 +# +select CONVERT(koi8_ru_f, 'cp1251_general_ci', 'utf8_general_ci'), comment from t1; +explain extended select CONVERT(koi8_ru_f, 'cp1251_general_ci', 'utf8_general_ci'), comment from t1; + ALTER TABLE t1 ADD bin_f CHAR(32) BYTE NOT NULL; UPDATE t1 SET bin_f=koi8_ru_f; SELECT COUNT(DISTINCT bin_f),COUNT(DISTINCT koi8_ru_f),COUNT(DISTINCT utf8_f) FROM t1; diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 46359e84f1d..54d934b66db 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -23,6 +23,8 @@ select locate(_utf8 0xD0B1, _utf8 0xD0B0D091D0B2); select locate(_utf8 0xD091, _utf8 0xD0B0D0B1D0B2 collate utf8_bin); select locate(_utf8 0xD0B1, _utf8 0xD0B0D091D0B2 collate utf8_bin); +select length(_utf8 0xD0B1), bit_length(_utf8 0xD0B1), char_length(_utf8 0xD0B1); + select 'a' like 'a'; select 'A' like 'a'; select 'A' like 'a' collate utf8_bin; diff --git a/mysql-test/t/date_formats.test b/mysql-test/t/date_formats.test index 9551efaa648..e2d0e5d2c6d 100644 --- a/mysql-test/t/date_formats.test +++ b/mysql-test/t/date_formats.test @@ -80,3 +80,4 @@ select get_format(DATE, 'USA') as a; select get_format(TIME, 'internal') as a; select get_format(DATETIME, 'eur') as a; +explain extended select makedate(1997,1), addtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002"),subtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002"),timediff("01.01.97 11:59:59.000001 PM","31.12.95 11:59:59.000002 PM"),cast(str_to_date("15-01-2001 12:59:59", "%d-%m-%Y %H:%i:%S") as TIME), maketime(23,11,12),microsecond("1997-12-31 23:59:59.000001"); diff --git a/mysql-test/t/fulltext.test b/mysql-test/t/fulltext.test index 37913d2d747..9c48f84161a 100644 --- a/mysql-test/t/fulltext.test +++ b/mysql-test/t/fulltext.test @@ -16,6 +16,7 @@ INSERT INTO t1 VALUES('MySQL has now support', 'for full-text search'), # nl search select * from t1 where MATCH(a,b) AGAINST ("collections"); +explain extended select * from t1 where MATCH(a,b) AGAINST ("collections"); select * from t1 where MATCH(a,b) AGAINST ("indexes"); select * from t1 where MATCH(a,b) AGAINST ("indexes collections"); select * from t1 where MATCH(a,b) AGAINST ("only"); @@ -42,6 +43,7 @@ explain select * from t1 where MATCH(a,b) AGAINST ("collections")>0 and a like ' # boolean search select * from t1 where MATCH(a,b) AGAINST("support -collections" IN BOOLEAN MODE); +explain extended select * from t1 where MATCH(a,b) AGAINST("support -collections" IN BOOLEAN MODE); select * from t1 where MATCH(a,b) AGAINST("support collections" IN BOOLEAN MODE); select * from t1 where MATCH(a,b) AGAINST("support +collections" IN BOOLEAN MODE); select * from t1 where MATCH(a,b) AGAINST("sear*" IN BOOLEAN MODE); diff --git a/mysql-test/t/func_compress.test b/mysql-test/t/func_compress.test index 069fbed8562..06ebb388517 100644 --- a/mysql-test/t/func_compress.test +++ b/mysql-test/t/func_compress.test @@ -7,7 +7,9 @@ select @test_compress_string:='string for test compress function aaaaaaaaaaaaaaa select length(@test_compress_string); select uncompress(compress(@test_compress_string)); +explain extended select uncompress(compress(@test_compress_string)); select uncompressed_length(compress(@test_compress_string))=length(@test_compress_string); +explain extended select uncompressed_length(compress(@test_compress_string))=length(@test_compress_string); select uncompressed_length(compress(@test_compress_string)); select length(compress(@test_compress_string))<length(@test_compress_string); diff --git a/mysql-test/t/func_default.test b/mysql-test/t/func_default.test new file mode 100644 index 00000000000..6ae9f088f92 --- /dev/null +++ b/mysql-test/t/func_default.test @@ -0,0 +1,19 @@ +--disable_warnings +drop table if exists t1,t2; +--enable_warnings + + +create table t1(str varchar(10) default 'def',strnull varchar(10),intg int default '10',rel double default '3.14'); + +insert into t1 values ('','',0,0.0); +select default(str), default(strnull), default(intg), default(rel) from t1; +explain extended select default(str), default(strnull), default(intg), default(rel) from t1; +select * from t1 where str <> default(str); +explain select * from t1 where str <> default(str); + +#TODO: uncomment when bug will be fixed +#create table t2 select default(str), default(strnull), default(intg), default(rel) from t1; +#show create table from t1; +#insert into t2 select select default(str), default(strnull), default(intg), default(rel) from t1; + +drop table t1;
\ No newline at end of file diff --git a/mysql-test/t/func_gconcat.test b/mysql-test/t/func_gconcat.test index 041225bdaf5..d004c81f14e 100644 --- a/mysql-test/t/func_gconcat.test +++ b/mysql-test/t/func_gconcat.test @@ -18,6 +18,7 @@ insert into t1 values (3,9,"D","c"); # Test of MySQL simple request select grp,group_concat(c) from t1 group by grp; +explain extended select grp,group_concat(c) from t1 group by grp; select grp,group_concat(a,c) from t1 group by grp; select grp,group_concat("(",a,":",c,")") from t1 group by grp; @@ -33,9 +34,11 @@ select grp,group_concat(c order by 1) from t1 group by grp; select grp,group_concat(c order by "c") from t1 group by grp; select grp,group_concat(distinct c order by c) from t1 group by grp; select grp,group_concat(distinct c order by c desc) from t1 group by grp; +explain extended select grp,group_concat(distinct c order by c desc) from t1 group by grp; select grp,group_concat(c order by c separator ",") from t1 group by grp; select grp,group_concat(c order by c desc separator ",") from t1 group by grp; select grp,group_concat(distinct c order by c separator ",") from t1 group by grp; +explain extended select grp,group_concat(distinct c order by c separator ",") from t1 group by grp; select grp,group_concat(distinct c order by c desc separator ",") from t1 group by grp; # Test of SQL_LIST objects diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test index ac3a1986d93..9e0184d35ce 100644 --- a/mysql-test/t/func_group.test +++ b/mysql-test/t/func_group.test @@ -346,7 +346,8 @@ select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; insert into t1 values (3,1); select a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; -select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b) from t1 group by a; +select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b), bit_xor(b) from t1 group by a; +explain extended select SQL_BIG_RESULT a,count(b), sum(b), avg(b), std(b), min(b), max(b), bit_and(b), bit_or(b), bit_xor(b) from t1 group by a; drop table t1; --disable_warnings create table t1 (USR_ID integer not null, MAX_REQ integer not null, constraint PK_SEA_USER primary key (USR_ID)) type=InnoDB; diff --git a/mysql-test/t/func_if.test b/mysql-test/t/func_if.test index 21e5836c781..7842df4fd0a 100644 --- a/mysql-test/t/func_if.test +++ b/mysql-test/t/func_if.test @@ -20,6 +20,13 @@ select if(1,st,st) s from t1 order by s; select if(u=1,st,st) s from t1 order by s; select if(u=1,binary st,st) s from t1 order by s; select if(u=1,st,binary st) s from t1 where st like "%a%" order by s; +explain extended select if(u=1,st,binary st) s from t1 where st like "%a%" order by s; + +# +# NULLIF test +# +select nullif(u=0, 'test') from t1; +explain extended select nullif(u=0, 'test') from t1; drop table t1; # diff --git a/mysql-test/t/func_in.test b/mysql-test/t/func_in.test index 689b061f88d..9ff768ec76b 100644 --- a/mysql-test/t/func_in.test +++ b/mysql-test/t/func_in.test @@ -72,6 +72,7 @@ select * from t1 where a in ('a'); select * from t1 where 'a' collate latin1_general_ci in (a,b,c); select * from t1 where 'a' collate latin1_bin in (a,b,c); select * from t1 where 'a' in (a,b,c collate latin1_bin); +explain extended select * from t1 where 'a' in (a,b,c collate latin1_bin); drop table t1; select '1.0' in (1,2); diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test index bd125dafd53..b6e2d3bd725 100644 --- a/mysql-test/t/func_math.test +++ b/mysql-test/t/func_math.test @@ -3,17 +3,30 @@ # select floor(5.5),floor(-5.5); +explain extended select floor(5.5),floor(-5.5); select ceiling(5.5),ceiling(-5.5); +explain extended select ceiling(5.5),ceiling(-5.5); select truncate(52.64,1),truncate(52.64,2),truncate(52.64,-1),truncate(52.64,-2), truncate(-52.64,1),truncate(-52.64,-1); +explain extended select truncate(52.64,1),truncate(52.64,2),truncate(52.64,-1),truncate(52.64,-2), truncate(-52.64,1),truncate(-52.64,-1); select round(5.5),round(-5.5); +explain extended select round(5.5),round(-5.5); select round(5.64,1),round(5.64,2),round(5.64,-1),round(5.64,-2); select abs(-10), sign(-5), sign(5), sign(0); +explain extended select abs(-10), sign(-5), sign(5), sign(0); select log(exp(10)),exp(log(sqrt(10))*2),log(-1),log(NULL),log(1,1),log(3,9),log(-1,2),log(NULL,2); +explain extended select log(exp(10)),exp(log(sqrt(10))*2),log(-1),log(NULL),log(1,1),log(3,9),log(-1,2),log(NULL,2); select ln(exp(10)),exp(ln(sqrt(10))*2),ln(-1),ln(0),ln(NULL); +explain extended select ln(exp(10)),exp(ln(sqrt(10))*2),ln(-1),ln(0),ln(NULL); select log2(8),log2(15),log2(-2),log2(0),log2(NULL); +explain extended select log2(8),log2(15),log2(-2),log2(0),log2(NULL); select log10(100),log10(18),log10(-4),log10(0),log10(NULL); +explain extended select log10(100),log10(18),log10(-4),log10(0),log10(NULL); select pow(10,log10(10)),power(2,4); +explain extended select pow(10,log10(10)),power(2,4); set @@rand_seed1=10000000,@@rand_seed2=1000000; select rand(999999),rand(); +explain extended select rand(999999),rand(); select pi(),sin(pi()/2),cos(pi()/2),abs(tan(pi())),cot(1),asin(1),acos(0),atan(1); +explain extended select pi(),sin(pi()/2),cos(pi()/2),abs(tan(pi())),cot(1),asin(1),acos(0),atan(1); select degrees(pi()),radians(360); +explain extended select degrees(pi()),radians(360); diff --git a/mysql-test/t/func_op.test b/mysql-test/t/func_op.test index 778c8406b8d..cb6ca58f193 100644 --- a/mysql-test/t/func_op.test +++ b/mysql-test/t/func_op.test @@ -3,5 +3,7 @@ # Simple operands and arithmetic grouping select 1+1,1-1,1+1*2,8/5,8%5,mod(8,5),mod(8,5)|0,-(1+1)*-2; +explain extended select 1+1,1-1,1+1*2,8/5,8%5,mod(8,5),mod(8,5)|0,-(1+1)*-2; select 1 | (1+1),5 & 3,bit_count(7) ; +explain extended select 1 | (1+1),5 & 3,bit_count(7) ; select 1 << 32,1 << 63, 1 << 64, 4 >> 2, 4 >> 63, 1<< 63 >> 60; diff --git a/mysql-test/t/func_regexp.test b/mysql-test/t/func_regexp.test index 6ecb56ef9c4..edfa9afcfa6 100644 --- a/mysql-test/t/func_regexp.test +++ b/mysql-test/t/func_regexp.test @@ -36,6 +36,7 @@ drop table t1; create table t1 (xxx char(128)); insert into t1 (xxx) values('this is a test of some long text to see what happens'); select * from t1 where xxx regexp('is a test of some long text to'); +explain extended select * from t1 where xxx regexp('is a test of some long text to'); select * from t1 where xxx regexp('is a test of some long text to '); select * from t1 where xxx regexp('is a test of some long text to s'); select * from t1 where xxx regexp('is a test of some long text to se'); diff --git a/mysql-test/t/func_set.test b/mysql-test/t/func_set.test index b152c94096c..7d24140c75d 100644 --- a/mysql-test/t/func_set.test +++ b/mysql-test/t/func_set.test @@ -3,6 +3,7 @@ # select interval(55,10,20,30,40,50,60,70,80,90,100),interval(3,1,1+1,1+1+1+1),field("IBM","NCA","ICL","SUN","IBM","DIGITAL"),field("A","B","C"),elt(2,"ONE","TWO","THREE"),interval(0,1,2,3,4),elt(1,1,2,3)|0,elt(1,1.1,1.2,1.3)+0; +explain extended select INTERVAL(55,10,20,30,40,50,60,70,80,90,100),interval(3,1,1+1,1+1+1+1),field("IBM","NCA","ICL","SUN","IBM","DIGITAL"),field("A","B","C"),elt(2,"ONE","TWO","THREE"),interval(0,1,2,3,4),elt(1,1,2,3)|0,elt(1,1.1,1.2,1.3)+0; select find_in_set("b","a,b,c"),find_in_set("c","a,b,c"),find_in_set("dd","a,bbb,dd"),find_in_set("bbb","a,bbb,dd"); select find_in_set("d","a,b,c"),find_in_set("dd","a,bbb,d"),find_in_set("bb","a,bbb,dd"); select make_set(0,'a','b','c'),make_set(-1,'a','b','c'),make_set(1,'a','b','c'),make_set(2,'a','b','c'),make_set(1+2,concat('a','b'),'c'); diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index b421f47e5b8..835172fe3fa 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -14,7 +14,9 @@ select 'hello',"'hello'",'""hello""','''h''e''l''l''o''',"hel""lo",'hel\'lo'; select 'hello' 'monty'; select length('\n\t\r\b\0\_\%\\'); select bit_length('\n\t\r\b\0\_\%\\'); -select concat('monty',' was here ','again'),length('hello'),char(ascii('h')); +select char_length('\n\t\r\b\0\_\%\\'); +select length(_latin1'\n\t\n\b\0\\_\\%\\'); +select concat('monty',' was here ','again'),length('hello'),char(ascii('h')),ord('h'); select locate('he','hello'),locate('he','hello',2),locate('lo','hello',2) ; select instr('hello','HE'), instr('hello',binary 'HE'), instr(binary 'hello','HE'); select position(binary 'll' in 'hello'),position('a' in binary 'hello'); @@ -46,6 +48,7 @@ select null sounds like 'null'; select 'null' sounds like null; select null sounds like null; select md5('hello'); +select crc32("123"); select sha('abc'); select sha1('abc'); select aes_decrypt(aes_encrypt('abc','1'),'1'); @@ -336,3 +339,5 @@ INSERT INTO t1 VALUES ('Congress reconvenes in September to debate welfare and a INSERT INTO t1 VALUES ('House passes the CAREERS bill'); SELECT CONCAT("</a>",RPAD("",(55 - LENGTH(title)),".")) from t1; DROP TABLE t1; + +explain extended select md5('hello'), sha('abc'), sha1('abc'), soundex(''), 'mood' sounds like 'mud', aes_decrypt(aes_encrypt('abc','1'),'1'),concat('*',space(5),'*'), reverse('abc'), rpad('a',4,'1'), lpad('a',4,'1'), concat_ws(',','',NULL,'a'),make_set(255,_latin2'a',_latin2'b',_latin2'c'),elt(2,1),locate("a","b",2),format(130,10),char(0),conv(130,16,10),hex(130),binary 'HE', export_set(255,_latin2'y',_latin2'n',_latin2' '),FIELD('b' COLLATE latin1_bin,'A','B'),FIND_IN_SET(_latin1'B',_latin1'a,b,c,d'),collation(conv(130,16,10)), coercibility(conv(130,16,10)),length('\n\t\r\b\0\_\%\\'),bit_length('\n\t\r\b\0\_\%\\'),bit_length('\n\t\r\b\0\_\%\\'),concat('monty',' was here ','again'),length('hello'),char(ascii('h')),ord('h'),quote(1/0),crc32("123"); diff --git a/mysql-test/t/func_system.test b/mysql-test/t/func_system.test index 998b2a5c3f4..f3b9b4ffc3f 100644 --- a/mysql-test/t/func_system.test +++ b/mysql-test/t/func_system.test @@ -17,6 +17,7 @@ select version()>="3.23.29"; select version()>=_utf8"3.23.29"; select version()>=_latin1"3.23.29"; select charset(version()); +explain extended select database(), user(); create table t1 (version char(40)) select database(), user(), version() as 'version'; show create table t1; diff --git a/mysql-test/t/func_test.test b/mysql-test/t/func_test.test index 95b10c4ffb9..86e0ee2637b 100644 --- a/mysql-test/t/func_test.test +++ b/mysql-test/t/func_test.test @@ -19,13 +19,19 @@ select 'b' between 'a' and 'c', 'B' between 'a' and 'c'; select 2 in (3,2,5,9,5,1),"monty" in ("david","monty","allan"), 1.2 in (1.4,1.2,1.0); select -1.49 or -1.49,0.6 or 0.6; select 3 ^ 11, 1 ^ 1, 1 ^ 0, 1 ^ NULL, NULL ^ 1; +explain extended select 3 ^ 11, 1 ^ 1, 1 ^ 0, 1 ^ NULL, NULL ^ 1; select 1 XOR 1, 1 XOR 0, 0 XOR 1, 0 XOR 0, NULL XOR 1, 1 XOR NULL, 0 XOR NULL; select 10 % 7, 10 mod 7, 10 div 3; +explain extended select 10 % 7, 10 mod 7, 10 div 3; select (1 << 64)-1, ((1 << 64)-1) DIV 1, ((1 << 64)-1) DIV 2; +explain extended select (1 << 64)-1, ((1 << 64)-1) DIV 1, ((1 << 64)-1) DIV 2; create table t1 (a int); insert t1 values (1); select * from t1 where 1 xor 1; +explain extended select * from t1 where 1 xor 1; +select - a from t1; +explain extended select - a from t1; drop table t1; # @@ -41,6 +47,7 @@ select 1 and 0 or 2, 2 or 1 and 0; # select _koi8r'a' = _koi8r'A'; select _koi8r'a' = _koi8r'A' COLLATE koi8r_general_ci; +explain extended select _koi8r'a' = _koi8r'A' COLLATE koi8r_general_ci; select _koi8r'a' = _koi8r'A' COLLATE koi8r_bin; select _koi8r'a' COLLATE koi8r_general_ci = _koi8r'A'; select _koi8r'a' COLLATE koi8r_bin = _koi8r'A'; diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index 30d616915ab..96bdb547469 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -7,6 +7,7 @@ drop table if exists t1,t2,t3; select from_days(to_days("960101")),to_days(960201)-to_days("19960101"),to_days(date_add(curdate(), interval 1 day))-to_days(curdate()),weekday("1997-11-29"); select period_add("9602",-12),period_diff(199505,"9404") ; + select now()-now(),weekday(curdate())-weekday(now()),unix_timestamp()-unix_timestamp(now()); select from_unixtime(unix_timestamp("1994-03-02 10:11:12")),from_unixtime(unix_timestamp("1994-03-02 10:11:12"),"%Y-%m-%d %h:%i:%s"),from_unixtime(unix_timestamp("1994-03-02 10:11:12"))+0; select sec_to_time(9001),sec_to_time(9001)+0,time_to_sec("15:12:22"), @@ -231,3 +232,5 @@ select strcmp(date_format(date_sub(localtimestamp(), interval 3 hour),"%Y-%m-%d" select strcmp(date_format(utc_timestamp(),"%T"), utc_time())=0; select strcmp(date_format(utc_timestamp(),"%Y-%m-%d"), utc_date())=0; select strcmp(concat(utc_date(),' ',utc_time()),utc_timestamp())=0; + +explain extended select period_add("9602",-12),period_diff(199505,"9404"),from_days(to_days("960101")),dayofmonth("1997-01-02"), month("1997-01-02"), monthname("1972-03-04"),dayofyear("0000-00-00"),HOUR("1997-03-03 23:03:22"),MINUTE("23:03:22"),SECOND(230322),QUARTER(980303),WEEK("1998-03-03"),yearweek("2000-01-01",1),week(19950101,1),year("98-02-03"),weekday(curdate())-weekday(now()),dayname("1962-03-03"),unix_timestamp(),sec_to_time(time_to_sec("0:30:47")/6.21),curtime(),utc_time(),curdate(),utc_date(),utc_timestamp(),date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w"),from_unixtime(unix_timestamp("1994-03-02 10:11:12")),"1997-12-31 23:59:59" + INTERVAL 1 SECOND,"1998-01-01 00:00:00" - INTERVAL 1 SECOND,INTERVAL 1 DAY + "1997-12-31", extract(YEAR FROM "1999-01-02 10:11:12"),date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND); diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index 752896ce7b2..705e32c82df 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -260,7 +260,7 @@ explain select spid,count(*) from t1 where spid between 1 and 2 group by spid; explain select spid,count(*) from t1 where spid between 1 and 2 group by spid order by null; select spid,count(*) from t1 where spid between 1 and 2 group by spid; select spid,count(*) from t1 where spid between 1 and 2 group by spid desc; -explain select sql_big_result spid,sum(userid) from t1 group by spid desc; +explain extended select sql_big_result spid,sum(userid) from t1 group by spid desc; explain select sql_big_result spid,sum(userid) from t1 group by spid desc order by null; select sql_big_result spid,sum(userid) from t1 group by spid desc; explain select sql_big_result score,count(*) from t1 group by score desc; diff --git a/mysql-test/t/having.test b/mysql-test/t/having.test index 7d5fbee011f..7e4cbe76cca 100644 --- a/mysql-test/t/having.test +++ b/mysql-test/t/having.test @@ -10,6 +10,7 @@ select count(a) as b from t1 where a=0 having b > 0; insert into t1 values (null); select count(a) as b from t1 where a=0 having b > 0; select count(a) as b from t1 where a=0 having b >=0; +explain extended select count(a) as b from t1 where a=0 having b >=0; drop table t1; # diff --git a/mysql-test/t/insert_update.test b/mysql-test/t/insert_update.test index 4f19aca8738..550bce867cd 100644 --- a/mysql-test/t/insert_update.test +++ b/mysql-test/t/insert_update.test @@ -23,4 +23,6 @@ INSERT t1 SET a=5 ON DUPLICATE KEY UPDATE b=0; SELECT * FROM t1; INSERT t1 VALUES (2,1,11), (7,4,40) ON DUPLICATE KEY UPDATE c=c+VALUES(a); SELECT *, VALUES(a) FROM t1; +explain extended SELECT *, VALUES(a) FROM t1; +explain extended select * from t1 where values(a); DROP TABLE t1; diff --git a/mysql-test/t/null.test b/mysql-test/t/null.test index fa36249dce0..0be755ba7ad 100644 --- a/mysql-test/t/null.test +++ b/mysql-test/t/null.test @@ -8,6 +8,7 @@ drop table if exists t1; # select null,\N,isnull(null),isnull(1/0),isnull(1/0 = null),ifnull(null,1),ifnull(null,"TRUE"),ifnull("TRUE","ERROR"),1/0 is null,1 is not null; +explain extended select null,\N,isnull(null),isnull(1/0),isnull(1/0 = null),ifnull(null,1),ifnull(null,"TRUE"),ifnull("TRUE","ERROR"),1/0 is null,1 is not null; select 1 | NULL,1 & NULL,1+NULL,1-NULL; select NULL=NULL,NULL<>NULL,IFNULL(NULL,1.1)+0,IFNULL(NULL,1) | 0; select strcmp("a",NULL),(1<NULL)+0.0,NULL regexp "a",null like "a%","a%" like null; @@ -15,10 +16,12 @@ select concat("a",NULL),replace(NULL,"a","b"),replace("string","i",NULL),replace select repeat("a",0),repeat("ab",5+5),repeat("ab",-1),reverse(NULL); select field(NULL,"a","b","c"); select 2 between null and 1,2 between 3 AND NULL,NULL between 1 and 2,2 between NULL and 3, 2 between 1 AND null; +explain extended select 2 between null and 1,2 between 3 AND NULL,NULL between 1 and 2,2 between NULL and 3, 2 between 1 AND null; SELECT NULL AND NULL, 1 AND NULL, NULL AND 1, NULL OR NULL, 0 OR NULL, NULL OR 0; SELECT (NULL OR NULL) IS NULL; select NULL AND 0, 0 and NULL; select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton(""); +explain extended select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton(""); create table t1 (x int); insert into t1 values (null); diff --git a/mysql-test/t/olap.test b/mysql-test/t/olap.test index 17bf6230f76..7443aeee6f4 100644 --- a/mysql-test/t/olap.test +++ b/mysql-test/t/olap.test @@ -32,7 +32,7 @@ select product, sum(profit),avg(profit) from t1 group by product with rollup; # Sub totals select product, country_id , year, sum(profit) from t1 group by product, country_id, year; select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup; -explain select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup; +explain extended select product, country_id , year, sum(profit) from t1 group by product, country_id, year with rollup; select product, country_id , sum(profit) from t1 group by product desc, country_id with rollup; # limit diff --git a/mysql-test/t/query_cache.test b/mysql-test/t/query_cache.test index ed4c5c91c4d..0ec6e5ecb73 100644 --- a/mysql-test/t/query_cache.test +++ b/mysql-test/t/query_cache.test @@ -184,6 +184,7 @@ select RAND() from t1; select UNIX_TIMESTAMP() from t1; select USER() from t1; select benchmark(1,1) from t1; +explain extended select benchmark(1,1) from t1; show status like "Qcache_queries_in_cache"; # # Tests when the cache is filled diff --git a/mysql-test/t/row.test b/mysql-test/t/row.test index 252830cfc98..ecb0c6adfc1 100644 --- a/mysql-test/t/row.test +++ b/mysql-test/t/row.test @@ -18,6 +18,7 @@ select (1,2,(3,4)) IN ((3,2,(3,4)), (1,2,(3,4))); -- error 1240 select row(1,2,row(3,4)) IN (row(3,2,row(3,4)), row(1,2,4)); select row(1,2,row(3,4)) IN (row(3,2,row(3,4)), row(1,2,row(3,NULL))); +explain extended select row(1,2,row(3,4)) IN (row(3,2,row(3,4)), row(1,2,row(3,NULL))); SELECT (1,2,3)=(0,NULL,3); SELECT (1,2,3)=(1,NULL,3); diff --git a/mysql-test/t/rpl000001.test b/mysql-test/t/rpl000001.test index f464f1e2751..445bd579279 100644 --- a/mysql-test/t/rpl000001.test +++ b/mysql-test/t/rpl000001.test @@ -62,10 +62,12 @@ enable_query_log; # Try to cause a large relay log lag on the slave connection slave; select get_lock("hold_slave",10); +explain extended select get_lock("hold_slave",10); start slave; #hope this is long enough for I/O thread to fetch over 16K relay log data sleep 3; select release_lock("hold_slave"); +explain extended select release_lock("hold_slave"); unlock tables; connection master; diff --git a/mysql-test/t/rpl_get_lock.test b/mysql-test/t/rpl_get_lock.test index e93268e6074..c3b033fb03a 100644 --- a/mysql-test/t/rpl_get_lock.test +++ b/mysql-test/t/rpl_get_lock.test @@ -5,6 +5,7 @@ insert into t1 values(get_lock("lock",2)); dirty_close master; connection master1; select get_lock("lock",2); + select release_lock("lock"); #ignore disable_query_log; @@ -21,7 +22,8 @@ connection slave; sync_with_master; select get_lock("lock",3); select * from t1; -select is_free_lock("lock"); +select is_free_lock("lock"), is_used_lock("lock"); +explain extended select is_free_lock("lock"), is_used_lock("lock"); # Check lock functions select is_free_lock("lock2"); select is_free_lock(NULL); diff --git a/mysql-test/t/rpl_master_pos_wait.test b/mysql-test/t/rpl_master_pos_wait.test index 24479636c91..4d4d51b04ab 100644 --- a/mysql-test/t/rpl_master_pos_wait.test +++ b/mysql-test/t/rpl_master_pos_wait.test @@ -7,6 +7,7 @@ sync_with_master; # Ask for a master log that has certainly not been reached yet # timeout= 2 seconds select master_pos_wait('master-bin.999999',0,2); +explain extended select master_pos_wait('master-bin.999999',0,2); # Testcase for bug 651 (master_pos_wait() hangs if slave idle and STOP SLAVE). send select master_pos_wait('master-bin.999999',0); connection slave1; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index d727befe661..b817544bfb9 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -1596,6 +1596,7 @@ select count(*) from t1; select companynr,count(*),sum(fld1) from t2 group by companynr; select companynr,count(*) from t2 group by companynr order by companynr desc limit 5; select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>""; +explain extended select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>""; select companynr,count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 group by companynr limit 3; select companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr,t2nr limit 10; select /*! SQL_SMALL_RESULT */ companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr,t2nr limit 10; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 3648210b943..bc49f0c28cd 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -4,11 +4,11 @@ drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12; --enable_warnings select (select 2); -explain select (select 2); +explain extended select (select 2); SELECT (SELECT 1) UNION SELECT (SELECT 2); -explain SELECT (SELECT 1) UNION SELECT (SELECT 2); +explain extended SELECT (SELECT 1) UNION SELECT (SELECT 2); SELECT (SELECT (SELECT 0 UNION SELECT 0)); -explain SELECT (SELECT (SELECT 0 UNION SELECT 0)); +explain extended SELECT (SELECT (SELECT 0 UNION SELECT 0)); -- error 1246 SELECT (SELECT 1 FROM (SELECT 1) as b HAVING a=1) as a; -- error 1246 @@ -16,7 +16,7 @@ SELECT (SELECT 1 FROM (SELECT 1) as b HAVING b=1) as a,(SELECT 1 FROM (SELECT 1) SELECT (SELECT 1),MAX(1) FROM (SELECT 1) as a; -- error 1246 SELECT (SELECT a) as a; -EXPLAIN SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; +EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1; -- error 1054 SELECT (SELECT 1), a; @@ -74,17 +74,17 @@ insert into t3 values (6),(7),(3); select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1); (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; (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); -explain (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); +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); select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2; 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; -explain select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from +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; 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); 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); 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); select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; -explain select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; +explain extended select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; select * from t3 where exists (select * from t2 where t2.b=t3.a); select * from t3 where not exists (select * from t2 where t2.b=t3.a); select * from t3 where a in (select b from t2); @@ -100,7 +100,7 @@ insert into t2 values (100, 5); select * from t3 where a < any (select b from t2); select * from t3 where a < all (select b from t2); select * from t3 where a >= any (select b from t2); -explain select * from t3 where a >= any (select b from t2); +explain extended select * from t3 where a >= any (select b from t2); select * from t3 where a >= all (select b from t2); delete from t2 where a=100; -- error 1240 @@ -120,7 +120,7 @@ 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; 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; -explain select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; +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; -- error 1241 select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq)); @@ -128,7 +128,7 @@ 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); -explain select * from t6 where exists (select * from t7 where uq = clinic_uq); +explain extended select * from t6 where exists (select * from t7 where uq = clinic_uq); # not unique fields -- error 1052 @@ -157,7 +157,7 @@ CREATE TABLE `t8` ( 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 SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); +EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); -- error 1240 SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM t8 WHERE pseudo='joce'); @@ -180,14 +180,14 @@ CREATE TABLE `t1` ( ) TYPE=MyISAM ROW_FORMAT=DYNAMIC; INSERT INTO t1 (topic,date,pseudo) VALUES ('43506','2002-10-02','joce'),('40143','2002-08-03','joce'); -EXPLAIN SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; -EXPLAIN SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'); +EXPLAIN EXTENDED SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; +EXPLAIN EXTENDED SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'); SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'); SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1) UNION ALL SELECT 1; -- error 1241 SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1) UNION SELECT 1; -EXPLAIN SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1); +EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1); drop table t1; #forumconthardwarefr7 searchconthardwarefr7 @@ -276,9 +276,9 @@ SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=a) FROM (SELECT SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT * FROM t1) as a; INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test'); -- error 1241 -EXPLAIN SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); -EXPLAIN SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; -EXPLAIN SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'); +EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); +EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; +EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'); drop table t1; CREATE TABLE t1 (a int(1)); @@ -395,11 +395,11 @@ SELECT * FROM (SELECT 1) b WHERE 1 IN (SELECT *); CREATE TABLE t2 (id int(11) default NULL, KEY id (id)) TYPE=MyISAM CHARSET=latin1; INSERT INTO t2 VALUES (1),(2); SELECT * FROM t2 WHERE id IN (SELECT 1); -EXPLAIN SELECT * FROM t2 WHERE id IN (SELECT 1); +EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1); SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3); SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1)); -EXPLAIN SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1)); -EXPLAIN SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3); +EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1)); +EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3); SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 3); SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 2); -- error 1093 @@ -455,7 +455,7 @@ select 1.5 > ALL (SELECT * from t1); select 10.5 > ALL (SELECT * from t1); select 1.5 > ANY (SELECT * from t1); select 10.5 > ANY (SELECT * from t1); -explain select (select a+1) from t1; +explain extended select (select a+1) from t1; select (select a+1) from t1; drop table t1; @@ -468,11 +468,11 @@ 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; -explain SELECT t1.a, t1.a in (select t2.a from t2) FROM t1; +explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM 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; -explain SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1; +explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1; drop table t1,t2,t3; #LIMIT is not supported now @@ -549,9 +549,9 @@ drop table t1; #test of uncacheable subqueries CREATE TABLE t1 (a int(1)); -EXPLAIN SELECT (SELECT RAND() FROM t1) FROM t1; -EXPLAIN SELECT (SELECT ENCRYPT('test') FROM t1) FROM t1; -EXPLAIN SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1; +EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1; +EXPLAIN EXTENDED SELECT (SELECT ENCRYPT('test') FROM t1) FROM t1; +EXPLAIN EXTENDED SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1; drop table t1; @@ -613,7 +613,7 @@ drop table t1; create table t1 (a int); insert into t1 values (1), (2), (3); -explain select a,(select (select rand() from t1 limit 1) from t1 limit 1) +explain extended select a,(select (select rand() from t1 limit 1) from t1 limit 1) from t1; drop table t1; @@ -677,10 +677,10 @@ CREATE TABLE `t1` ( ) TYPE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC; INSERT INTO t1 (pseudo) VALUES ('test'); SELECT 0 IN (SELECT 1 FROM t1 a); -EXPLAIN SELECT 0 IN (SELECT 1 FROM t1 a); +EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); INSERT INTO t1 (pseudo) VALUES ('test1'); SELECT 0 IN (SELECT 1 FROM t1 a); -EXPLAIN SELECT 0 IN (SELECT 1 FROM t1 a); +EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); drop table t1; CREATE TABLE `t1` ( @@ -727,7 +727,7 @@ 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 SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1); +explain extended SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1); drop table t1; CREATE TABLE t1 ( @@ -824,11 +824,11 @@ 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); -explain select * from t2 where t2.a in (select a from t1); +explain extended select * from t2 where t2.a in (select a from t1); select * from t2 where t2.a in (select a from t1 where t1.b <> 30); -explain select * from t2 where t2.a in (select a from t1 where t1.b <> 30); +explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30); select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); -explain select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); +explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.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)); @@ -846,15 +846,15 @@ enable_query_log; 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); -explain select * from t2 where t2.a in (select a from t1); +explain extended select * from t2 where t2.a in (select a from t1); select * from t2 where t2.a in (select a from t1 where t1.b <> 30); -explain select * from t2 where t2.a in (select a from t1 where t1.b <> 30); +explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30); select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); -explain select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); +explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); insert into t1 values (3,31); select * from t2 where t2.a in (select a from t1 where t1.b <> 30); select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31); -explain select * from t2 where t2.a in (select a from t1 where t1.b <> 30); +explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30); drop table t1, t2, t3; # @@ -935,7 +935,7 @@ create table t1 (s1 char(5)); select (select 'a','b' from t1 union select 'a','b' from t1) from t1; insert into t1 values ('tttt'); select * from t1 where ('a','b')=(select 'a','b' from t1 union select 'a','b' from t1); -explain (select * from t1); +explain extended (select * from t1); (select * from t1); drop table t1; @@ -950,10 +950,10 @@ select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; select s1, s1 = ANY (SELECT s1 FROM t2) from t1; select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; -explain select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; -explain select s1, s1 = ANY (SELECT s1 FROM t2) from t1; -explain select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; -explain select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; +explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; +explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1; +explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; +explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; drop table t1,t2; # @@ -963,14 +963,14 @@ create table t2 (a int, b int); create table t3 (a int); insert into t3 values (6),(7),(3); select * from t3 where a >= all (select b from t2); -explain select * from t3 where a >= all (select b from t2); +explain extended select * from t3 where a >= all (select b from t2); # # optimized static ALL/ANY with grouping # 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); -explain select * from t3 where a > all (select max(b) from t2 group by a); +explain extended select * from t3 where a > all (select max(b) from t2 group by a); drop table t2, t3; # diff --git a/mysql-test/t/type_blob.test b/mysql-test/t/type_blob.test index ebe342a4ef5..c9c3284fe0d 100644 --- a/mysql-test/t/type_blob.test +++ b/mysql-test/t/type_blob.test @@ -298,6 +298,10 @@ select charset(load_file('../../std_data/words.dat')), collation(load_file('../../std_data/words.dat')), coercibility(load_file('../../std_data/words.dat')); +explain extended select + charset(load_file('../../std_data/words.dat')), + collation(load_file('../../std_data/words.dat')), + coercibility(load_file('../../std_data/words.dat')); update t1 set imagem=load_file('../../std_data/words.dat') where id=1; select if(imagem is null, "ERROR", "OK"),length(imagem) from t1 where id = 1; drop table t1; diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test index b64f0b4e2ee..1f3f4085734 100644 --- a/mysql-test/t/union.test +++ b/mysql-test/t/union.test @@ -25,7 +25,7 @@ select 't1',b,count(*) from t1 group by b UNION select 't2',b,count(*) from t2 g (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc; --error 1249 (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by t1.b; -explain (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc; +explain extended (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc; (select sql_calc_found_rows a,b from t1 limit 2) union all (select a,b from t2 order by a) limit 2; select found_rows(); select sql_calc_found_rows a,b from t1 union all select a,b from t2 limit 2; @@ -275,7 +275,7 @@ create table t2 (a int not null primary key auto_increment, b int); insert into t1 (b) values (1),(2),(2),(3); insert into t2 (b) values (10),(11),(12),(13); -explain (select * from t1 where a=1) union (select * from t2 where a=1); +explain extended (select * from t1 where a=1) union (select * from t2 where a=1); (select * from t1 where a=5) union (select * from t2 where a=1); (select * from t1 where a=5 and a=6) union (select * from t2 where a=1); (select t1.a,t1.b from t1,t2 where t1.a=5) union (select * from t2 where a=1); diff --git a/mysql-test/t/varbinary.test b/mysql-test/t/varbinary.test index d58954a189b..9425bd7bd99 100644 --- a/mysql-test/t/varbinary.test +++ b/mysql-test/t/varbinary.test @@ -18,7 +18,7 @@ select x'31',X'ffff'+0; create table t1 (ID int(8) unsigned zerofill not null auto_increment,UNIQ bigint(21) unsigned zerofill not null,primary key (ID),unique (UNIQ) ); insert into t1 set UNIQ=0x38afba1d73e6a18a; insert into t1 set UNIQ=123; -explain select * from t1 where UNIQ=0x38afba1d73e6a18a; +explain extended select * from t1 where UNIQ=0x38afba1d73e6a18a; drop table t1; # diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index c53559ed4cf..6365ad77c57 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -16,6 +16,7 @@ select @test_int,@test_double,@test_string,@test_string2; set @test_int=null,@test_double=null,@test_string=null,@test_string2=null; select @test_int,@test_double,@test_string,@test_string2; select @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3; +explain extended select @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3; select @t5; # @@ -52,7 +53,9 @@ select @@local.max_join_size, @@global.max_join_size; select @@identity, length(@@version)>0; select @@VERSION=version(); select last_insert_id(345); +explain extended select last_insert_id(345); select @@IDENTITY,last_insert_id(), @@identity; +explain extended select @@IDENTITY,last_insert_id(), @@identity; set big_tables=OFF, big_tables=ON, big_tables=0, big_tables=1, big_tables="OFF", big_tables="ON"; diff --git a/sql/item.cc b/sql/item.cc index 7c7cad7c290..0fbf3ae587b 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -87,6 +87,19 @@ Item::Item(THD *c_thd, Item &item): thd->free_list= this; } + +void Item::print_item_w_name(String *str) +{ + print(str); + if (name) + { + str->append(" AS `", 5); + str->append(name); + str->append('`'); + } +} + + // Constructor used by Item_field & Item_ref (see Item comment) Item_ident::Item_ident(THD *thd, Item_ident &item): Item(thd, item), @@ -422,6 +435,7 @@ bool Item_field::eq(const Item *item, bool binary_cmp) const db_name)))))); } + table_map Item_field::used_tables() const { if (field->table->const_table) @@ -429,6 +443,7 @@ table_map Item_field::used_tables() const return (depended_from ? OUTER_REF_TABLE_BIT : field->table->map); } + Item *Item_field::get_tmp_table_item(THD *thd) { Item_field *new_item= new Item_field(thd, *this); @@ -437,6 +452,7 @@ Item *Item_field::get_tmp_table_item(THD *thd) return new_item; } + String *Item_int::val_str(String *str) { str->set(value, default_charset()); @@ -445,28 +461,24 @@ String *Item_int::val_str(String *str) void Item_int::print(String *str) { - if (!name) - { - str_value.set(value, default_charset()); - name=str_value.c_ptr(); - } - str->append(name); + // latin1 is good enough for numbers + str_value.set(value, &my_charset_latin1); + str->append(str_value); } + String *Item_uint::val_str(String *str) { str->set((ulonglong) value, default_charset()); return str; } + void Item_uint::print(String *str) { - if (!name) - { - str_value.set((ulonglong) value, default_charset()); - name=str_value.c_ptr(); - } - str->append(name); + // latin1 is good enough for numbers + str_value.set((ulonglong) value, default_charset()); + str->append(str_value); } @@ -476,10 +488,46 @@ String *Item_real::val_str(String *str) return str; } + void Item_string::print(String *str) { + str->append('_'); + str->append(collation.collation->csname); str->append('\''); - str->append(full_name()); + char *st= (char*)str_value.ptr(), *end= st+str_value.length(); + for(; st < end; st++) + { + uchar c= *st; + switch (c) + { + case '\\': + str->append("\\\\", 2); + break; + case '\0': + str->append("\\0", 2); + break; + case '\'': + str->append("\\'", 2); + break; + case '\n': + str->append("\\n", 2); + break; + case '\r': + str->append("\\r", 2); + break; + case '\t': + str->append("\\t", 2); + break; + case '\b': + str->append("\\b", 2); + break; + case 26: //Ctrl-Z + str->append("\\z", 2); + break; + default: + str->append(c); + } + } str->append('\''); } @@ -700,7 +748,7 @@ String *Item_param::query_val_str(String* str) make_datetime(str, <ime, is_time_only, 0, tmp_format->format, tmp_format->format_length, 0); } - str->append("'"); + str->append('\''); } return str; } @@ -777,7 +825,7 @@ static void mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current, // store pointer on SELECT_LEX from wich item is dependent item->depended_from= last; current->mark_as_dependent(last); - if (thd->lex.describe) + if (thd->lex.describe & DESCRIBE_EXTENDED) { char warn_buff[MYSQL_ERRMSG_SIZE]; sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED), @@ -1533,6 +1581,34 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) } +void Item_ref::print(String *str) +{ + if (ref && *ref) + (*ref)->print(str); + else + Item_ident::print(str); +} + + +void Item_ref_null_helper::print(String *str) +{ + str->append("<ref_null_helper>(", 18); + if (ref && *ref) + (*ref)->print(str); + else + str->append('?'); + str->append(')'); +} + + +void Item_null_helper::print(String *str) +{ + str->append("<null_helper>(", 14); + store->print(str); + str->append(')'); +} + + bool Item_default_value::eq(const Item *item, bool binary_cmp) const { return item->type() == DEFAULT_VALUE_ITEM && @@ -1574,10 +1650,10 @@ void Item_default_value::print(String *str) { if (!arg) { - str->append("DEFAULT"); + str->append("default", 7); return; } - str->append("DEFAULT("); + str->append("default(", 8); arg->print(str); str->append(')'); } @@ -1630,7 +1706,7 @@ bool Item_insert_value::fix_fields(THD *thd, struct st_table_list *table_list, I void Item_insert_value::print(String *str) { - str->append("VALUE("); + str->append("values(", 7); arg->print(str); str->append(')'); } @@ -1754,6 +1830,34 @@ Item_cache* Item_cache::get_cache(Item_result type) } } + +void Item_cache::print(String *str) +{ + str->append("<cache>(", 8); + if (example) + example->print(str); + else + Item::print(str); + str->append(')'); +} + + +void Item_cache_int::store(Item *item) +{ + value= item->val_int_result(); + null_value= item->null_value; + collation.set(item->collation); +} + + +void Item_cache_real::store(Item *item) +{ + value= item->val_result(); + null_value= item->null_value; + collation.set(item->collation); +} + + void Item_cache_str::store(Item *item) { value_buff.set(buffer, sizeof(buffer), item->collation.collation); @@ -1804,6 +1908,7 @@ bool Item_cache_row::allocate(uint num) bool Item_cache_row::setup(Item * item) { + example= item; if (!values && allocate(item->cols())) return 1; for (uint i= 0; i < item_count; i++) diff --git a/sql/item.h b/sql/item.h index 8bb28068618..dcefde05605 100644 --- a/sql/item.h +++ b/sql/item.h @@ -182,6 +182,7 @@ public: { return decimals != NOT_FIXED_DEC ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;} virtual bool const_item() const { return used_tables() == 0; } virtual void print(String *str_arg) { str_arg->append(full_name()); } + void print_item_w_name(String *); virtual void update_used_tables() {} virtual void split_sum_func(Item **ref_pointer_array, List<Item> &fields) {} virtual bool get_date(TIME *ltime,bool fuzzydate); @@ -318,6 +319,7 @@ public: bool basic_const_item() const { return 1; } Item *new_item() { return new Item_null(name); } bool is_null() { return 1; } + void print(String *str) { str->append("NULL", 4); } }; class Item_param :public Item @@ -368,6 +370,7 @@ public: String *query_val_str(String *str); enum_field_types field_type() const { return MYSQL_TYPE_STRING; } Item *new_item() { return new Item_param(pos_in_query); } + void print(String *str) { str->append('?'); } }; class Item_int :public Item @@ -640,6 +643,7 @@ public: (*ref)->save_in_field(result_field, no_conversions); } Item *real_item() { return *ref; } + void print(String *str); }; class Item_in_subselect; @@ -655,15 +659,7 @@ public: longlong val_int(); String* val_str(String* s); bool get_date(TIME *ltime, bool fuzzydate); - void print(String *str) - { - str->append("ref_null_helper("); - if (ref && *ref) - (*ref)->print(str); - else - str->append('?'); - str->append(')'); - } + void print(String *str); }; class Item_null_helper :public Item_ref_null_helper @@ -675,6 +671,7 @@ public: :Item_ref_null_helper(master, &store, table_name_par, field_name_par), store(item) {} + void print(String *str); }; /* @@ -856,14 +853,16 @@ public: class Item_cache: public Item { +protected: + Item *example; table_map used_table_map; public: - Item_cache(): used_table_map(0) {fixed= 1; null_value= 1;} + Item_cache(): example(0), used_table_map(0) {fixed= 1; null_value= 1;} void set_used_tables(table_map map) { used_table_map= map; } virtual bool allocate(uint i) { return 0; }; - virtual bool setup(Item *) { return 0; }; + virtual bool setup(Item *item) { example= item; return 0; }; virtual void store(Item *)= 0; void set_len_n_dec(uint32 max_len, uint8 dec) { @@ -873,6 +872,7 @@ public: enum Type type() const { return CACHE_ITEM; } static Item_cache* get_cache(Item_result type); table_map used_tables() const { return used_table_map; } + void print(String *str); }; class Item_cache_int: public Item_cache @@ -881,12 +881,7 @@ class Item_cache_int: public Item_cache public: Item_cache_int(): Item_cache() {} - void store(Item *item) - { - value= item->val_int_result(); - null_value= item->null_value; - collation.set(item->collation); - } + void store(Item *item); double val() { return (double) value; } longlong val_int() { return value; } String* val_str(String *str) { str->set(value, default_charset()); return str; } @@ -899,12 +894,7 @@ class Item_cache_real: public Item_cache public: Item_cache_real(): Item_cache() {} - void store(Item *item) - { - value= item->val_result(); - null_value= item->null_value; - collation.set(item->collation); - } + void store(Item *item); double val() { return value; } longlong val_int() { return (longlong) (value+(value > 0 ? 0.5 : -0.5)); } String* val_str(String *str) diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index d6c05f47964..3897022e8ce 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -113,6 +113,14 @@ longlong Item_func_not_all::val_int() return (!null_value && value == 0) ? 1 : 0; } +void Item_func_not_all::print(String *str) +{ + if (show) + Item_func::print(str); + else + args[0]->print(str); +} + /* Convert a constant expression or string to an integer. This is done when comparing DATE's of different formats and @@ -707,6 +715,18 @@ longlong Item_func_between::val_int() return 0; } + +void Item_func_between::print(String *str) +{ + str->append('('); + args[0]->print(str); + str->append(" between ", 9); + args[1]->print(str); + str->append(" and ", 5); + args[2]->print(str); + str->append(')'); +} + void Item_func_ifnull::fix_length_and_dec() { @@ -863,7 +883,7 @@ Item_func_nullif::fix_length_and_dec() } /* - nullif () returns NULL if arguments are different, else it returns the + nullif () returns NULL if arguments are equal, else it returns the first argument. Note that we have to evaluate the first argument twice as the compare may have been done with a different type than return value @@ -1100,7 +1120,27 @@ void Item_func_case::fix_length_and_dec() void Item_func_case::print(String *str) { - str->append("case "); // Not yet complete + str->append("(case ", 6); + if (first_expr_num != -1) + { + args[first_expr_num]->print(str); + str->append(' '); + } + for (uint i=0 ; i < ncases ; i+=2) + { + str->append("when ", 5); + args[i]->print(str); + str->append(" then ", 6); + args[i+1]->print(str); + str->append(' '); + } + if (else_expr_num != -1) + { + str->append("else ", 5); + args[else_expr_num]->print(str); + str->append(' '); + } + str->append("end)", 4); } /* @@ -1507,8 +1547,15 @@ void Item_func_in::fix_length_and_dec() void Item_func_in::print(String *str) { str->append('('); - Item_func::print(str); - str->append(')'); + args[0]->print(str); + str->append(" in (", 5); + for (uint i=1 ; i < arg_count ; i++) + { + if (i > 1) + str->append(','); + args[i]->print(str); + } + str->append("))", 2); } @@ -1882,12 +1929,21 @@ void Item_is_not_null_test::update_used_tables() } } + longlong Item_func_isnotnull::val_int() { return args[0]->is_null() ? 0 : 1; } +void Item_func_isnotnull::print(String *str) +{ + str->append('('); + args[0]->print(str); + str->append(" is not null)", 13); +} + + longlong Item_func_like::val_int() { String* res = args[0]->val_str(&tmp_value1); diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 9a1b087a63c..3f73c7736da 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -105,7 +105,7 @@ public: Item_in_optimizer return NULL, else it evaluate Item_in_subselect. */ longlong val_int(); - const char *func_name() const { return "IN_OPTIMIZER"; } + const char *func_name() const { return "<in_optimizer>"; } Item_cache **get_cache() { return &cache; } }; @@ -162,12 +162,15 @@ class Item_func_not_all :public Item_func_not { bool abort_on_null; public: - Item_func_not_all(Item *a) :Item_func_not(a), abort_on_null(0) {} + bool show; + + Item_func_not_all(Item *a) :Item_func_not(a), abort_on_null(0), show(0) {} virtual void top_level_item() { abort_on_null= 1; } bool top_level() { return abort_on_null; } longlong val_int(); enum Functype functype() const { return NOT_ALL_FUNC; } - const char *func_name() const { return "not_all"; } + const char *func_name() const { return "<not>"; } + void print(String *str); }; class Item_func_eq :public Item_bool_rowready_func2 @@ -272,6 +275,7 @@ public: enum Functype functype() const { return BETWEEN; } const char *func_name() const { return "between"; } void fix_length_and_dec(); + void print(String *str); }; @@ -354,6 +358,7 @@ public: enum Item_result result_type () const { return cached_result_type; } void fix_length_and_dec(); const char *func_name() const { return "nullif"; } + void print(String *str) { Item_func::print(str); } table_map not_null_tables() const { return 0; } }; @@ -714,7 +719,7 @@ public: {} enum Functype functype() const { return ISNOTNULLTEST_FUNC; } longlong val_int(); - const char *func_name() const { return "is_not_null_test"; } + const char *func_name() const { return "<is_not_null_test>"; } void update_used_tables(); }; @@ -733,6 +738,7 @@ public: optimize_type select_optimize() const { return OPTIMIZE_NULL; } table_map not_null_tables() const { return 0; } Item *neg_transformer(); + void print(String *str); }; @@ -785,7 +791,8 @@ public: ~Item_func_regex(); longlong val_int(); bool fix_fields(THD *thd, struct st_table_list *tlist, Item **ref); - const char *func_name() const { return "regex"; } + const char *func_name() const { return "regexp"; } + void print(String *str) { print_op(str); } }; #else @@ -796,6 +803,7 @@ public: Item_func_regex(Item *a,Item *b) :Item_bool_func(a,b) {} longlong val_int() { return 0;} const char *func_name() const { return "regex"; } + void print(String *str) { print_op(str); } }; #endif /* USE_REGEX */ diff --git a/sql/item_create.cc b/sql/item_create.cc index fce59d68c1f..a25ccfe984b 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -292,7 +292,7 @@ Item *create_func_period_diff(Item* a, Item *b) Item *create_func_pi(void) { - return new Item_real(NullS,M_PI,6,8); + return new Item_real("pi()",M_PI,6,8); } Item *create_func_pow(Item* a, Item *b) diff --git a/sql/item_func.cc b/sql/item_func.cc index b47c833d404..7717eaee425 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -287,13 +287,19 @@ void Item_func::print(String *str) { str->append(func_name()); str->append('('); + print_args(str); + str->append(')'); +} + + +void Item_func::print_args(String *str) +{ for (uint i=0 ; i < arg_count ; i++) { if (i) str->append(','); args[i]->print(str); } - str->append(')'); } @@ -462,6 +468,24 @@ String *Item_num_op::val_str(String *str) } +void Item_func_signed::print(String *str) +{ + str->append("cast(", 5); + args[0]->print(str); + str->append(" as signed)", 11); + +} + + +void Item_func_unsigned::print(String *str) +{ + str->append("cast(", 5); + args[0]->print(str); + str->append(" as unsigned)", 13); + +} + + double Item_func_plus::val() { double value=args[0]->val()+args[1]->val(); @@ -1184,6 +1208,21 @@ longlong Item_func_locate::val_int() } +void Item_func_locate::print(String *str) +{ + str->append("locate(", 7); + args[1]->print(str); + str->append(','); + args[0]->print(str); + if (arg_count == 3) + { + str->append(','); + args[2]->print(str); + } + str->append(')'); +} + + longlong Item_func_field::val_int() { if (cmp_type == STRING_RESULT) @@ -1764,7 +1803,7 @@ void item_user_lock_release(ULL *ull) String tmp(buf,sizeof(buf), system_charset_info); tmp.copy(command, strlen(command), tmp.charset()); tmp.append(ull->key,ull->key_length); - tmp.append("\")"); + tmp.append("\")", 2); Query_log_event qev(current_thd, tmp.ptr(), tmp.length(),1); qev.error_code=0; // this query is always safe to run on slave mysql_bin_log.write(&qev); @@ -2049,6 +2088,19 @@ longlong Item_func_benchmark::val_int() } +void Item_func_benchmark::print(String *str) +{ + str->append("benchmark(", 10); + char buffer[20]; + // latin1 is good enough for numbers + String st(buffer, sizeof(buffer), &my_charset_latin1); + st.set((ulonglong)loop_count, &my_charset_latin1); + str->append(st); + str->append(','); + args[0]->print(str); + str->append(')'); +} + #define extra_size sizeof(double) static user_var_entry *get_variable(HASH *hash, LEX_STRING &name, @@ -2387,9 +2439,9 @@ String *Item_func_set_user_var::val_str(String *str) void Item_func_set_user_var::print(String *str) { - str->append("(@@",3); - str->append(name.str,name.length); - str->append(":=",2); + str->append("(@", 2); + str->append(name.str, name.length); + str->append(":=", 2); args[0]->print(str); str->append(')'); } @@ -2535,7 +2587,7 @@ enum Item_result Item_func_get_user_var::result_type() const void Item_func_get_user_var::print(String *str) { - str->append('@'); + str->append("(@", 2); str->append(name.str,name.length); str->append(')'); } @@ -2815,6 +2867,26 @@ double Item_func_match::val() table->record[0], 0)); } +void Item_func_match::print(String *str) +{ + str->append("(match ", 7); + List_iterator_fast<Item> li(fields); + Item *item; + bool first= 1; + while ((item= li++)) + { + if (first) + first= 0; + else + str->append(','); + item->print(str); + } + str->append(" against (", 10); + args[0]->print(str); + if (mode == FT_BOOL) + str->append(" in boolean mode", 16); + str->append("))", 2); +} longlong Item_func_bit_xor::val_int() { diff --git a/sql/item_func.h b/sql/item_func.h index 29e40f603b4..cee1d73847a 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -125,6 +125,7 @@ public: virtual void split_sum_func(Item **ref_pointer_array, List<Item> &fields); void print(String *str); void print_op(String *str); + void print_args(String *str); void fix_num_length_and_dec(); inline bool get_arg0_date(TIME *ltime,bool fuzzy_date) { @@ -215,6 +216,7 @@ public: longlong val_int() { return args[0]->val_int(); } void fix_length_and_dec() { max_length=args[0]->max_length; unsigned_flag=0; } + void print(String *str); }; @@ -226,6 +228,7 @@ public: longlong val_int() { return args[0]->val_int(); } void fix_length_and_dec() { max_length=args[0]->max_length; unsigned_flag=1; } + void print(String *str); }; @@ -607,6 +610,7 @@ public: const char *func_name() const { return "locate"; } longlong val_int(); void fix_length_and_dec(); + void print(String *str); }; @@ -663,6 +667,7 @@ public: longlong val_int(); const char *func_name() const { return "|"; } void fix_length_and_dec() { unsigned_flag=1; } + void print(String *str) { print_op(str); } }; class Item_func_bit_and :public Item_int_func @@ -672,6 +677,7 @@ public: longlong val_int(); const char *func_name() const { return "&"; } void fix_length_and_dec() { unsigned_flag=1; } + void print(String *str) { print_op(str); } }; class Item_func_bit_count :public Item_int_func @@ -690,6 +696,7 @@ public: longlong val_int(); const char *func_name() const { return "<<"; } void fix_length_and_dec() { unsigned_flag=1; } + void print(String *str) { print_op(str); } }; class Item_func_shift_right :public Item_int_func @@ -698,6 +705,7 @@ public: Item_func_shift_right(Item *a,Item *b) :Item_int_func(a,b) {} longlong val_int(); const char *func_name() const { return ">>"; } + void print(String *str) { print_op(str); } }; class Item_func_bit_neg :public Item_int_func @@ -728,6 +736,7 @@ class Item_func_benchmark :public Item_int_func longlong val_int(); const char *func_name() const { return "benchmark"; } void fix_length_and_dec() { max_length=1; maybe_null=0; } + void print(String *str); }; @@ -1005,6 +1014,7 @@ public: bool eq(const Item *, bool binary_cmp) const; longlong val_int() { return val()!=0.0; } double val(); + void print(String *str); bool fix_index(); void init_search(bool no_order); @@ -1018,6 +1028,7 @@ public: longlong val_int(); const char *func_name() const { return "^"; } void fix_length_xor_dec() { unsigned_flag=1; } + void print(String *str) { print_op(str); } }; class Item_func_is_free_lock :public Item_int_func @@ -1026,7 +1037,7 @@ class Item_func_is_free_lock :public Item_int_func public: Item_func_is_free_lock(Item *a) :Item_int_func(a) {} longlong val_int(); - const char *func_name() const { return "check_lock"; } + const char *func_name() const { return "is_free_lock"; } void fix_length_and_dec() { decimals=0; max_length=1; maybe_null=1;} }; diff --git a/sql/item_geofunc.h b/sql/item_geofunc.h index 79e45cca26f..72dc6620f3b 100644 --- a/sql/item_geofunc.h +++ b/sql/item_geofunc.h @@ -118,6 +118,7 @@ public: case SP_EXTERIORRING: return "exteriorring"; default: + DBUG_ASSERT(0); // Should never happened return "spatial_decomp_unknown"; } } @@ -142,6 +143,7 @@ public: case SP_INTERIORRINGN: return "interiorringn"; default: + DBUG_ASSERT(0); // Should never happened return "spatial_decomp_n_unknown"; } } @@ -210,6 +212,7 @@ public: case SP_OVERLAPS_FUNC: return "overlaps"; default: + DBUG_ASSERT(0); // Should never happened return "sp_unknown"; } } diff --git a/sql/item_row.cc b/sql/item_row.cc index fcc6e5192ec..89b38c8a753 100644 --- a/sql/item_row.cc +++ b/sql/item_row.cc @@ -118,6 +118,18 @@ bool Item_row::check_cols(uint c) return 0; } +void Item_row::print(String *str) +{ + str->append('('); + for (uint i= 0; i < arg_count; i++) + { + if (i) + str->append(','); + items[i]->print(str); + } + str->append(')'); +} + bool Item_row::walk(Item_processor processor, byte *arg) { for (uint i= 0; i < arg_count; i++) diff --git a/sql/item_row.h b/sql/item_row.h index 6dd955ed426..a09bd1a2c31 100644 --- a/sql/item_row.h +++ b/sql/item_row.h @@ -68,6 +68,7 @@ public: bool const_item() const { return const_item_cache; }; enum Item_result result_type() const { return ROW_RESULT; } void update_used_tables(); + void print(String *str); bool walk(Item_processor processor, byte *arg); diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 99dd06c566c..70f98783624 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -654,6 +654,17 @@ void Item_func_concat_ws::update_used_tables() const_item_cache&=separator->const_item(); } +void Item_func_concat_ws::print(String *str) +{ + str->append("concat_ws(", 10); + separator->print(str); + if (arg_count) + { + str->append(','); + print_args(str); + } + str->append(')'); +} String *Item_func_reverse::val_str(String *str) { @@ -1613,6 +1624,19 @@ String *Item_func_format::val_str(String *str) } +void Item_func_format::print(String *str) +{ + str->append("format(", 7); + args[0]->print(str); + str->append(','); + // latin1 is good enough for numbers + char buffer[20]; + String st(buffer, sizeof(buffer), &my_charset_latin1); + st.set((ulonglong)decimals, &my_charset_latin1); + str->append(st); + str->append(')'); +} + void Item_func_elt::fix_length_and_dec() { max_length=0; @@ -1764,6 +1788,19 @@ String *Item_func_make_set::val_str(String *str) } +void Item_func_make_set::print(String *str) +{ + str->append("make_set(", 9); + item->print(str); + if (arg_count) + { + str->append(','); + print_args(str); + } + str->append(')'); +} + + String *Item_func_char::val_str(String *str) { str->length(0); @@ -2077,7 +2114,14 @@ void Item_func_conv_charset::fix_length_and_dec() max_length = args[0]->max_length*conv_charset->mbmaxlen; } - +void Item_func_conv_charset::print(String *str) +{ + str->append("convert(", 8); + args[0]->print(str); + str->append(" using ", 7); + str->append(conv_charset->csname); + str->append(')'); +} String *Item_func_conv_charset3::val_str(String *str) { @@ -2271,6 +2315,14 @@ String *Item_func_hex::val_str(String *str) } +void Item_func_binary::print(String *str) +{ + str->append("cast(", 5); + args[0]->print(str); + str->append(" as binary)", 11); +} + + #include <my_dir.h> // For my_stat String *Item_load_file::val_str(String *str) diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index b82dacb4fe0..00b1ebb0732 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -112,6 +112,7 @@ public: return separator->walk(processor, arg) || Item_str_func::walk(processor, arg); } + void print(String *str); }; class Item_func_reverse :public Item_str_func @@ -120,6 +121,7 @@ public: Item_func_reverse(Item *a) :Item_str_func(a) {} String *val_str(String *); void fix_length_and_dec(); + const char *func_name() const { return "reverse"; } }; @@ -324,10 +326,12 @@ public: Item_func_encrypt(Item *a, Item *b): Item_str_func(a,b) {} String *val_str(String *); void fix_length_and_dec() { maybe_null=1; max_length = 13; } + const char *func_name() const { return "ecrypt"; } }; #include "sql_crypt.h" + class Item_func_encode :public Item_str_func { protected: @@ -337,13 +341,16 @@ public: Item_str_func(a),sql_crypt(seed) {} String *val_str(String *); void fix_length_and_dec(); + const char *func_name() const { return "encode"; } }; + class Item_func_decode :public Item_func_encode { public: Item_func_decode(Item *a, char *seed): Item_func_encode(a,seed) {} String *val_str(String *); + const char *func_name() const { return "decode"; } }; @@ -420,6 +427,7 @@ public: return item->walk(processor, arg) || Item_str_func::walk(processor, arg); } + void print(String *str); }; @@ -435,6 +443,7 @@ public: max_length=args[0]->max_length+(args[0]->max_length-args[0]->decimals)/3; } const char *func_name() const { return "format"; } + void print(String *); }; @@ -520,7 +529,6 @@ class Item_func_binary :public Item_str_func { public: Item_func_binary(Item *a) :Item_str_func(a) {} - const char *func_name() const { return "binary"; } String *val_str(String *a) { String *tmp=args[0]->val_str(a); @@ -534,7 +542,7 @@ public: collation.set(&my_charset_bin); max_length=args[0]->max_length; } - void print(String *str) { print_op(str); } + void print(String *str); }; @@ -597,7 +605,8 @@ public: { conv_charset=cs; } String *val_str(String *); void fix_length_and_dec(); - const char *func_name() const { return "conv_charset"; } + const char *func_name() const { return "convert"; } + void print(String *str); }; class Item_func_set_collation :public Item_str_func @@ -607,7 +616,8 @@ public: String *val_str(String *); void fix_length_and_dec(); bool eq(const Item *item, bool binary_cmp) const; - const char *func_name() const { return "set_collation"; } + const char *func_name() const { return "collate"; } + void print(String *str) { print_op(str); } }; class Item_func_conv_charset3 :public Item_str_func @@ -617,7 +627,7 @@ public: :Item_str_func(arg1,arg2,arg3) {} String *val_str(String *); void fix_length_and_dec(); - const char *func_name() const { return "conv_charset3"; } + const char *func_name() const { return "convert"; } }; class Item_func_charset :public Item_str_func diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 589a41052c5..ae44647b11c 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -146,21 +146,25 @@ Item::Type Item_subselect::type() const return SUBSELECT_ITEM; } + void Item_subselect::fix_length_and_dec() { engine->fix_length_and_dec(0); } + table_map Item_subselect::used_tables() const { return (table_map) (engine->dependent() ? used_tables_cache : 0L); } + bool Item_subselect::const_item() const { return const_item_cache; } + void Item_subselect::update_used_tables() { if (!engine->uncacheable()) @@ -171,6 +175,15 @@ void Item_subselect::update_used_tables() } } + +void Item_subselect::print(String *str) +{ + str->append('('); + engine->print(str); + str->append(')'); +} + + Item_singlerow_subselect::Item_singlerow_subselect(st_select_lex *select_lex) :Item_subselect(), value(0) { @@ -184,11 +197,12 @@ Item_singlerow_subselect::Item_singlerow_subselect(st_select_lex *select_lex) Item_maxmin_subselect::Item_maxmin_subselect(Item_subselect *parent, st_select_lex *select_lex, - bool max) + bool max_arg) :Item_singlerow_subselect() { DBUG_ENTER("Item_maxmin_subselect::Item_maxmin_subselect"); - init(select_lex, new select_max_min_finder_subselect(this, max)); + max= max_arg; + init(select_lex, new select_max_min_finder_subselect(this, max_arg)); max_columns= 1; maybe_null= 1; max_columns= 1; @@ -203,6 +217,12 @@ Item_maxmin_subselect::Item_maxmin_subselect(Item_subselect *parent, DBUG_VOID_RETURN; } +void Item_maxmin_subselect::print(String *str) +{ + str->append(max?"<max>":"<min>", 5); + Item_singlerow_subselect::print(str); +} + void Item_singlerow_subselect::reset() { null_value= 1; @@ -245,7 +265,7 @@ Item_singlerow_subselect::select_transformer(JOIN *join) */ substitution->walk(&Item::remove_dependence_processor, (byte *) select_lex->outer_select()); - if (select_lex->where || select_lex->having) + if (join->conds || join->having) { Item *cond; if (!join->having) @@ -365,6 +385,7 @@ String *Item_singlerow_subselect::val_str (String *str) } } + Item_exists_subselect::Item_exists_subselect(st_select_lex *select_lex): Item_subselect() { @@ -379,6 +400,14 @@ Item_exists_subselect::Item_exists_subselect(st_select_lex *select_lex): DBUG_VOID_RETURN; } + +void Item_exists_subselect::print(String *str) +{ + str->append("exists", 6); + Item_subselect::print(str); +} + + bool Item_in_subselect::test_limit(SELECT_LEX_UNIT *unit) { if (unit->fake_select_lex && @@ -396,7 +425,7 @@ bool Item_in_subselect::test_limit(SELECT_LEX_UNIT *unit) Item_in_subselect::Item_in_subselect(Item * left_exp, st_select_lex *select_lex): - Item_exists_subselect(), upper_not(0) + Item_exists_subselect(), transformed(0), upper_not(0) { DBUG_ENTER("Item_in_subselect::Item_in_subselect"); left_expr= left_exp; @@ -412,8 +441,9 @@ Item_in_subselect::Item_in_subselect(Item * left_exp, Item_allany_subselect::Item_allany_subselect(Item * left_exp, compare_func_creator fn, - st_select_lex *select_lex) - :Item_in_subselect() + st_select_lex *select_lex, + bool all_arg) + :Item_in_subselect(), all(all_arg) { DBUG_ENTER("Item_in_subselect::Item_in_subselect"); left_expr= left_exp; @@ -800,6 +830,7 @@ Item_in_subselect::row_value_transformer(JOIN *join, Item_subselect::trans_res Item_in_subselect::select_transformer(JOIN *join) { + transformed= 1; if (left_expr->cols() == 1) return single_value_transformer(join, left_expr, &Item_bool_func2::eq_creator); @@ -807,12 +838,82 @@ Item_in_subselect::select_transformer(JOIN *join) } +void Item_in_subselect::print(String *str) +{ + if (transformed) + str->append("<exists>", 8); + else + { + left_expr->print(str); + str->append(" in ", 4); + } + Item_subselect::print(str); +} + + Item_subselect::trans_res Item_allany_subselect::select_transformer(JOIN *join) { + transformed= 1; + if (upper_not) + upper_not->show= 1; return single_value_transformer(join, left_expr, func); } + +void Item_allany_subselect::print(String *str) +{ + if (transformed) + str->append("<exists>", 8); + else + { + left_expr->print(str); + str->append(' '); + if (all) + { + if (func == &Item_bool_func2::lt_creator) + str->append(">=", 2); + else if (func == &Item_bool_func2::gt_creator) + str->append("<=", 2); + else if (func == &Item_bool_func2::le_creator) + str->append('>'); + else if (func == &Item_bool_func2::ge_creator) + str->append('<'); + else if (func == &Item_bool_func2::eq_creator) + str->append("<>", 2); + else if (func == &Item_bool_func2::ne_creator) + str->append('='); + else + { + DBUG_ASSERT(0); // Impossible + } + str->append(" all ", 5); + } + else + { + if (func == &Item_bool_func2::lt_creator) + str->append('<'); + else if (func == &Item_bool_func2::gt_creator) + str->append('>'); + else if (func == &Item_bool_func2::le_creator) + str->append("<=", 2); + else if (func == &Item_bool_func2::ge_creator) + str->append(">=", 2); + else if (func == &Item_bool_func2::eq_creator) + str->append('='); + else if (func == &Item_bool_func2::ne_creator) + str->append("<>", 2); + else + { + DBUG_ASSERT(0); // Impossible + } + str->append(" any ", 5); + } + } + Item_subselect::print(str); +} + + subselect_single_select_engine:: subselect_single_select_engine(st_select_lex *select, select_subselect *result, @@ -1140,11 +1241,13 @@ uint subselect_single_select_engine::cols() return select_lex->item_list.elements; } + uint subselect_union_engine::cols() { return unit->first_select()->item_list.elements; } + bool subselect_single_select_engine::dependent() { return select_lex->dependent; @@ -1155,16 +1258,19 @@ bool subselect_union_engine::dependent() return unit->dependent; } + bool subselect_single_select_engine::uncacheable() { return select_lex->uncacheable; } + bool subselect_union_engine::uncacheable() { return unit->uncacheable; } + void subselect_single_select_engine::exclude() { select_lex->master_unit()->exclude_level(); @@ -1175,6 +1281,7 @@ void subselect_union_engine::exclude() unit->exclude_level(); } + void subselect_uniquesubquery_engine::exclude() { //this never should be called @@ -1201,8 +1308,59 @@ table_map subselect_single_select_engine::upper_select_const_tables() table_list.first); } + table_map subselect_union_engine::upper_select_const_tables() { return calc_const_tables((TABLE_LIST *) unit->outer_select()-> table_list.first); } + + +void subselect_single_select_engine::print(String *str) +{ + select_lex->print(thd, str); +} + + +void subselect_union_engine::print(String *str) +{ + unit->print(str); +} + + +void subselect_uniquesubquery_engine::print(String *str) +{ + str->append("<primary_index_lookup>(", 23); + tab->ref.items[0]->print(str); + str->append(" in ", 4); + str->append(tab->table->real_name); + KEY *key_info= tab->table->key_info+ tab->ref.key; + str->append(" on ", 4); + str->append(key_info->name); + if (cond) + { + str->append(" where ", 7); + cond->print(str); + } + str->append(')'); +} + + +void subselect_indexsubquery_engine::print(String *str) +{ + str->append("<index_lookup>(", 15); + tab->ref.items[0]->print(str); + str->append(" in ", 4); + str->append(tab->table->real_name); + KEY *key_info= tab->table->key_info+ tab->ref.key; + str->append(" on ", 4); + str->append(key_info->name); + if (check_null) + str->append(" chicking NULL", 14); + if (cond) + { + str->append(" where ", 7); + cond->print(str); + } + str->append(')'); +} diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 7e735165c02..8d438d0e72f 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -92,13 +92,7 @@ public: inline table_map get_used_tables_cache() { return used_tables_cache; } inline bool get_const_item_cache() { return const_item_cache; } void update_used_tables(); - void print(String *str) - { - if (name) - str->append(name); - else - str->append("-subselect-"); - } + void print(String *str); bool change_engine(subselect_engine *eng) { engine= eng; @@ -147,9 +141,11 @@ public: /* used in static ALL/ANY optimisation */ class Item_maxmin_subselect :public Item_singlerow_subselect { + bool max; public: Item_maxmin_subselect(Item_subselect *parent, st_select_lex *select_lex, bool max); + void print(String *str); }; /* exists subselect */ @@ -174,6 +170,7 @@ public: double val(); String *val_str(String*); void fix_length_and_dec(); + void print(String *str); friend class select_exists_subselect; friend class subselect_uniquesubquery_engine; @@ -194,12 +191,15 @@ protected: Item_in_optimizer *optimizer; bool was_null; bool abort_on_null; + bool transformed; public: Item_func_not_all *upper_not; // point on NOT before ALL subquery Item_in_subselect(Item * left_expr, st_select_lex *select_lex); Item_in_subselect() - :Item_exists_subselect(), abort_on_null(0), upper_not(0) {} + :Item_exists_subselect(), abort_on_null(0), transformed(0), upper_not(0) + + {} subs_type substype() { return IN_SUBS; } void reset() @@ -219,6 +219,7 @@ public: String *val_str(String*); void top_level_item() { abort_on_null=1; } bool test_limit(st_select_lex_unit *unit); + void print(String *str); friend class Item_ref_null_helper; friend class Item_is_not_null_test; @@ -233,12 +234,15 @@ protected: compare_func_creator func; public: + bool all; + Item_allany_subselect(Item * left_expr, compare_func_creator f, - st_select_lex *select_lex); + st_select_lex *select_lex, bool all); // only ALL subquery has upper not subs_type substype() { return upper_not?ALL_SUBS:ANY_SUBS; } trans_res select_transformer(JOIN *join); + void print(String *str); }; @@ -276,6 +280,7 @@ public: bool may_be_null() { return maybe_null; }; virtual table_map upper_select_const_tables()= 0; static table_map calc_const_tables(TABLE_LIST *); + virtual void print(String *str)= 0; }; @@ -298,6 +303,7 @@ public: bool uncacheable(); void exclude(); table_map upper_select_const_tables(); + void print (String *str); }; @@ -316,6 +322,7 @@ public: bool uncacheable(); void exclude(); table_map upper_select_const_tables(); + void print (String *str); }; @@ -343,6 +350,7 @@ public: bool uncacheable() { return 1; } void exclude(); table_map upper_select_const_tables() { return 0; } + void print (String *str); }; @@ -359,4 +367,5 @@ public: check_null(chk_null) {} int exec(); + void print (String *str); }; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index ed2a03beccf..74dd95bf0ab 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -1366,6 +1366,14 @@ longlong Item_sum_count_distinct::val_int() return table->file->records; } + +void Item_sum_count_distinct::print(String *str) +{ + str->append("count(distinct ", 15); + args[0]->print(str); + str->append(')'); +} + /**************************************************************************** ** Functions to handle dynamic loadable aggregates ** Original source by: Alexis Mikhailov <root@medinf.chuvashia.su> @@ -1960,3 +1968,29 @@ String* Item_func_group_concat::val_str(String* str) } return &result; } + +void Item_func_group_concat::print(String *str) +{ + str->append("group_concat(", 13); + if (distinct) + str->append("distinct ", 9); + for (uint i= 0; i < arg_count; i++) + { + if (i) + str->append(','); + args[i]->print(str); + } + if (arg_count_order) + { + str->append(" order by ", 10); + for (uint i= 0 ; i < arg_count_order ; i++) + { + if (i) + str->append(','); + (*order[i]->item)->print(str); + } + } + str->append(" seperator \'", 12); + str->append(*separator); + str->append("\')", 2); +} diff --git a/sql/item_sum.h b/sql/item_sum.h index e5061e1e05a..d454f06ccde 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -238,6 +238,7 @@ class Item_sum_count_distinct :public Item_sum_int void make_unique(); Item *copy_or_same(THD* thd); void no_rows_in_result() {} + void print(String *str); }; @@ -748,4 +749,5 @@ class Item_func_group_concat : public Item_sum String* val_str(String* str); Item *copy_or_same(THD* thd); void no_rows_in_result() {} + void print(String *str); }; diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 4009256ee17..4f1d6c5d63e 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -433,7 +433,7 @@ String *make_datetime(String *str, TIME *l_time, length= int10_to_str(l_time->day, intbuff, 10) - intbuff; str->append_with_prefill(intbuff, length, 1, '0'); if (l_time->day >= 10 && l_time->day <= 19) - str->append("th"); + str->append("th", 2); else { switch (l_time->day %10) { @@ -531,7 +531,7 @@ String *make_datetime(String *str, TIME *l_time, str->append_with_prefill(intbuff, length, 2, '0'); if (add_second_frac) { - str->append(".", 1); + str->append('.'); length= int10_to_str(l_time->second_part, intbuff, 10) - intbuff; str->append_with_prefill(intbuff, length, 6, '0'); } @@ -1644,6 +1644,36 @@ longlong Item_date_add_interval::val_int() ((date*100L + ltime.hour)*100L+ ltime.minute)*100L + ltime.second; } +static const char *interval_names[]= +{ + "year", "month", "day", "hour", "minute", + "second", "microsecond", "year_month", + "day_hour", "day_minute", "day_second", + "hour_minute", "hour_second", "minute_second", + "day_microsecond", "hour_microsecond", + "minute_microsecond", "second_microsecond" +}; + +void Item_date_add_interval::print(String *str) +{ + str->append('('); + args[0]->print(str); + str->append(date_sub_interval?" - interval ":" + interval "); + args[1]->print(str); + str->append(' '); + str->append(interval_names[int_type]); + str->append(')'); +} + +void Item_extract::print(String *str) +{ + str->append("extract(", 8); + str->append(interval_names[int_type]); + str->append(" from ", 6); + args[0]->print(str); + str->append(')'); +} + void Item_extract::fix_length_and_dec() { value.alloc(32); // alloc buffer @@ -1751,10 +1781,33 @@ bool Item_extract::eq(const Item *item, bool binary_cmp) const void Item_typecast::print(String *str) { - str->append("CAST("); + str->append("cast(", 5); + args[0]->print(str); + str->append(" as ", 4); + str->append(cast_type()); + str->append(')'); +} + +void Item_char_typecast::print(String *str) +{ + str->append("cast(", 5); args[0]->print(str); - str->append(" AS "); - str->append(func_name()); + str->append(" as char", 8); + if (cast_length >= 0) + { + str->append('('); + char buffer[20]; + // latin1 is good enough for numbers + String st(buffer, sizeof(buffer), &my_charset_latin1); + st.set((ulonglong)cast_length, &my_charset_latin1); + str->append(st); + str->append(')'); + } + if (cast_cs) + { + str->append(" charset ", 9); + str->append(cast_cs->name); + } str->append(')'); } @@ -2039,6 +2092,28 @@ null_date: return 0; } + +void Item_func_add_time::print(String *str) +{ + if (is_date) + { + DBUG_ASSERT(sign > 0); + str->append("timestamp(", 10); + } + else + { + if (sign > 0) + str->append("addtime(", 8); + else + str->append("subtime(", 8); + } + args[0]->print(str); + str->append(','); + args[0]->print(str); + str->append(')'); +} + + /* TIMEDIFF(t,s) is a time function that calculates the time value between a start and end time. diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index b7bf294b83d..af71322ff0c 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -285,7 +285,7 @@ public: Item_func_unix_timestamp() :Item_int_func() {} Item_func_unix_timestamp(Item *a) :Item_int_func(a) {} longlong val_int(); - const char *func_name() const { return "timestamp"; } + const char *func_name() const { return "unix_timestamp"; } void fix_length_and_dec() { decimals=0; @@ -544,13 +544,13 @@ public: enum interval_type { INTERVAL_YEAR, INTERVAL_MONTH, INTERVAL_DAY, INTERVAL_HOUR, INTERVAL_MINUTE, - INTERVAL_SECOND, INTERVAL_MICROSECOND ,INTERVAL_YEAR_MONTH, INTERVAL_DAY_HOUR, - INTERVAL_DAY_MINUTE, INTERVAL_DAY_SECOND, INTERVAL_HOUR_MINUTE, - INTERVAL_HOUR_SECOND, INTERVAL_MINUTE_SECOND, INTERVAL_DAY_MICROSECOND, - INTERVAL_HOUR_MICROSECOND, INTERVAL_MINUTE_MICROSECOND, INTERVAL_SECOND_MICROSECOND + INTERVAL_SECOND, INTERVAL_MICROSECOND ,INTERVAL_YEAR_MONTH, + INTERVAL_DAY_HOUR, INTERVAL_DAY_MINUTE, INTERVAL_DAY_SECOND, + INTERVAL_HOUR_MINUTE, INTERVAL_HOUR_SECOND, INTERVAL_MINUTE_SECOND, + INTERVAL_DAY_MICROSECOND, INTERVAL_HOUR_MICROSECOND, + INTERVAL_MINUTE_MICROSECOND, INTERVAL_SECOND_MICROSECOND }; - class Item_date_add_interval :public Item_date_func { const interval_type int_type; @@ -568,6 +568,7 @@ public: double val() { return (double) val_int(); } longlong val_int(); bool get_date(TIME *res,bool fuzzy_date); + void print(String *str); }; @@ -583,6 +584,7 @@ class Item_extract :public Item_int_func const char *func_name() const { return "extract"; } void fix_length_and_dec(); bool eq(const Item *item, bool binary_cmp) const; + void print(String *str); }; @@ -590,7 +592,6 @@ class Item_typecast :public Item_str_func { public: Item_typecast(Item *a) :Item_str_func(a) {} - const char *func_name() const { return "char"; } String *val_str(String *a) { String *tmp=args[0]->val_str(a); @@ -604,6 +605,7 @@ public: collation.set(default_charset()); max_length=args[0]->max_length; } + virtual const char* cast_type() const= 0; void print(String *str); }; @@ -617,8 +619,10 @@ class Item_char_typecast :public Item_typecast public: Item_char_typecast(Item *a, int length_arg, CHARSET_INFO *cs_arg) :Item_typecast(a), cast_length(length_arg), cast_cs(cs_arg) {} + const char* cast_type() const { return "char"; }; String *val_str(String *a); void fix_length_and_dec(); + void print(String *str); }; @@ -628,7 +632,7 @@ public: Item_date_typecast(Item *a) :Item_typecast(a) {} String *val_str(String *str); bool get_date(TIME *ltime, bool fuzzy_date); - const char *func_name() const { return "date"; } + const char *cast_type() const { return "date"; } enum_field_types field_type() const { return MYSQL_TYPE_DATE; } Field *tmp_table_field(TABLE *t_arg) { @@ -643,7 +647,7 @@ public: Item_time_typecast(Item *a) :Item_typecast(a) {} String *val_str(String *str); bool get_time(TIME *ltime); - const char *func_name() const { return "time"; } + const char *cast_type() const { return "time"; } enum_field_types field_type() const { return MYSQL_TYPE_TIME; } Field *tmp_table_field(TABLE *t_arg) { @@ -657,7 +661,7 @@ class Item_datetime_typecast :public Item_typecast public: Item_datetime_typecast(Item *a) :Item_typecast(a) {} String *val_str(String *str); - const char *func_name() const { return "datetime"; } + const char *cast_type() const { return "datetime"; } enum_field_types field_type() const { return MYSQL_TYPE_DATETIME; } Field *tmp_table_field(TABLE *t_arg) { @@ -694,7 +698,6 @@ public: Item_func_add_time(Item *a, Item *b, bool type_arg, bool neg_arg) :Item_str_func(a, b), is_date(type_arg) { sign= neg_arg ? -1 : 1; } String *val_str(String *str); - const char *func_name() const { return "addtime"; } enum_field_types field_type() const { return cached_field_type; } void fix_length_and_dec(); @@ -711,6 +714,7 @@ public: return (new Field_datetime(maybe_null, name, t_arg, &my_charset_bin)); return (new Field_string(max_length, maybe_null, name, t_arg, &my_charset_bin)); } + void print(String *str); }; class Item_func_timediff :public Item_str_func diff --git a/sql/item_uniq.h b/sql/item_uniq.h index 9b370b70181..5c6f6eefb6b 100644 --- a/sql/item_uniq.h +++ b/sql/item_uniq.h @@ -29,6 +29,7 @@ public: :Item_real_func(list) {} double val() { return 0.0; } void fix_length_and_dec() { decimals=0; max_length=6; } + void print(String *str) { str->append("0.0", 3); } }; @@ -54,4 +55,5 @@ public: { return new Item_sum_unique_users(thd, *this); } + void print(String *str) { str->append("0.0", 3); } }; diff --git a/sql/key.cc b/sql/key.cc index 37ef6339f20..639b1e535a6 100644 --- a/sql/key.cc +++ b/sql/key.cc @@ -227,7 +227,7 @@ void key_unpack(String *to,TABLE *table,uint idx) { if (table->record[0][key_part->null_offset] & key_part->null_bit) { - to->append("NULL"); + to->append("NULL", 4); continue; } } @@ -239,7 +239,7 @@ void key_unpack(String *to,TABLE *table,uint idx) to->append(tmp); } else - to->append("???"); + to->append("???", 3); } DBUG_VOID_RETURN; } diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index f7b12bd959c..88061354b68 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -204,6 +204,9 @@ extern CHARSET_INFO *national_charset_info, *table_alias_charset; #define OPTION_QUOTE_SHOW_CREATE OPTION_QUICK*2 #define OPTION_INTERNAL_SUBTRANSACTIONS OPTION_QUOTE_SHOW_CREATE*2 +/* options for UNION set by the yacc parser (stored in unit->union_option) */ +#define UNION_ALL 1 + /* Set if we are updating a non-transaction safe table */ #define OPTION_STATUS_NO_TRANS_UPDATE OPTION_INTERNAL_SUBTRANSACTIONS*2 diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 7fd2b751c1d..719686a56c3 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -222,10 +222,6 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, else unit->exclude_tree(); org_table_list->db= (char *)""; -#ifndef DBUG_OFF - /* Try to catch errors if this is accessed */ - org_table_list->derived=(SELECT_LEX_UNIT *) 1; -#endif // Force read of table stats in the optimizer table->file->info(HA_STATUS_VARIABLE); } diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index c3ff69184e6..5aaeef57669 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1502,7 +1502,75 @@ bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num) order_group_num)* 5)) == 0; } +void st_select_lex_unit::print(String *str) +{ + for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select()) + { + if (sl != first_select()) + { + str->append(" union ", 7); + if (union_option & UNION_ALL) + str->append("all ", 4); + } + if (sl->braces) + str->append('('); + sl->print(thd, str); + if (sl->braces) + str->append(')'); + } + if (fake_select_lex == global_parameters) + { + if (fake_select_lex->order_list.elements) + { + str->append(" order by ", 10); + fake_select_lex->print_order(str, + (ORDER *) fake_select_lex-> + order_list.first); + } + fake_select_lex->print_limit(thd, str); + } +} + + +void st_select_lex::print_order(String *str, ORDER *order) +{ + for (; order; order= order->next) + { + (*order->item)->print(str); + if (!order->asc) + str->append(" desc", 5); + if (order->next) + str->append(','); + } +} + +void st_select_lex::print_limit(THD *thd, String *str) +{ + if (!thd) + thd= current_thd; + + if (select_limit != thd->variables.select_limit || + select_limit != HA_POS_ERROR || + offset_limit != 0L) + { + str->append(" limit ", 7); + char buff[20]; + // latin1 is good enough for numbers + String st(buff, sizeof(buff), &my_charset_latin1); + st.set((ulonglong)select_limit, &my_charset_latin1); + str->append(st); + if (offset_limit) + { + str->append(','); + st.set((ulonglong)select_limit, &my_charset_latin1); + str->append(st); + } + } +} + /* There are st_select_lex::add_table_to_list & st_select_lex::set_lock_for_tables in sql_parse.cc + + st_select_lex::print is in sql_select.h */ diff --git a/sql/sql_lex.h b/sql/sql_lex.h index c31420b951c..20b796bb1ba 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -80,6 +80,10 @@ enum enum_sql_command { SQLCOM_END }; +// describe/explain types +#define DESCRIBE_NORMAL 1 +#define DESCRIBE_EXTENDED 2 + typedef List<Item> List_item; typedef struct st_lex_master_info @@ -335,7 +339,9 @@ public: int prepare(THD *thd, select_result *result, bool tables_and_fields_initied); int exec(); int cleanup(); - + + void print(String *str); + friend void mysql_init_query(THD *thd); friend int subselect_union_engine::exec(); private: @@ -476,6 +482,9 @@ public: init_select(); } bool setup_ref_array(THD *thd, uint order_group_num); + void print(THD *thd, String *str); + static void print_order(String *str, ORDER *order); + void print_limit(THD *thd, String *str); }; typedef class st_select_lex SELECT_LEX; @@ -550,9 +559,10 @@ typedef struct st_lex uint fk_delete_opt, fk_update_opt, fk_match_option; uint param_count; uint slave_thd_opt; + uint8 describe; bool drop_primary, drop_if_exists, drop_temporary, local_file; bool in_comment, ignore_space, verbose, simple_alter, no_write_to_binlog; - bool derived_tables, describe; + bool derived_tables; bool safe_to_cache_query; st_lex() {} inline void uncacheable() diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 704ac726fa6..5a69a3a1017 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1777,6 +1777,16 @@ mysql_execute_command(THD *thd) res= mysql_explain_union(thd, &thd->lex.unit, result); MYSQL_LOCK *save_lock= thd->lock; thd->lock= (MYSQL_LOCK *)0; + if (lex->describe & DESCRIBE_EXTENDED) + { + char buff[1024]; + String str(buff,(uint32) sizeof(buff), system_charset_info); + str.length(0); + thd->lex.unit.print(&str); + str.append('\0'); + push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, + ER_YES, str.ptr()); + } result->send_eof(); thd->lock= save_lock; } @@ -4687,7 +4697,7 @@ Item * all_any_subquery_creator(Item *left_expr, return new Item_func_not(new Item_in_subselect(left_expr, select_lex)); Item_allany_subselect *it= - new Item_allany_subselect(left_expr, (*cmp)(all), select_lex); + new Item_allany_subselect(left_expr, (*cmp)(all), select_lex, all); if (all) return it->upper_not= new Item_func_not_all(it); /* ALL */ diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 5db3be7599b..ecad84ba0cb 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -625,7 +625,7 @@ Increase max_allowed_packet on master"; goto err; } packet->length(0); - packet->append("\0",1); + packet->append('\0'); } } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 222f5707c69..00d8ea4c114 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -331,6 +331,20 @@ JOIN::prepare(Item ***rref_pointer_array, having->split_sum_func(ref_pointer_array, all_fields); } +#ifndef DEBUG_OFF + { + char buff[256]; + String str(buff,(uint32) sizeof(buff), system_charset_info); + str.length(0); + if (select_lex->master_unit()->item) + select_lex->master_unit()->item->print(&str); + else + unit->print(&str); + str.append('\0'); + DBUG_PRINT("info", ("(SUB)SELECT: %s", str.ptr())); + } +#endif + // Is it subselect { Item_subselect *subselect; @@ -883,12 +897,12 @@ JOIN::optimize() need_tmp=1; simple_order=simple_group=0; // Force tmp table without sort } + tmp_having= having; if (select_options & SELECT_DESCRIBE) { error= 0; DBUG_RETURN(0); } - tmp_having= having; having= 0; /* Perform FULLTEXT search before all regular searches */ @@ -1550,11 +1564,23 @@ mysql_select(THD *thd, Item ***rref_pointer_array, goto err; // 1 } + if (thd->lex.describe & DESCRIBE_EXTENDED) + { + join->conds_history= join->conds; + join->having_history= (join->having?join->having:join->tmp_having); + } + if (thd->net.report_error) goto err; join->exec(); + if (thd->lex.describe & DESCRIBE_EXTENDED) + { + select_lex->where= join->conds_history; + select_lex->having= join->having_history; + } + err: if (free_join) { @@ -9001,3 +9027,159 @@ int mysql_explain_select(THD *thd, SELECT_LEX *select_lex, char const *type, result, unit, select_lex, 0); DBUG_RETURN(res); } + + +void st_select_lex::print(THD *thd, String *str) +{ + if (!thd) + thd= current_thd; + + str->append("select ", 7); + + //options + if (options & SELECT_STRAIGHT_JOIN) + str->append("straight_join ", 14); + if ((thd->lex.lock_option & TL_READ_HIGH_PRIORITY) && + (this == &thd->lex.select_lex)) + str->append("high_priority ", 14); + if (options & SELECT_DISTINCT) + str->append("distinct ", 9); + if (options & SELECT_SMALL_RESULT) + str->append("small_result ", 13); + if (options & SELECT_BIG_RESULT) + str->append("big_result ", 11); + if (options & OPTION_BUFFER_RESULT) + str->append("buffer_result ", 14); + if (options & OPTION_FOUND_ROWS) + str->append("calc_found_rows ", 16); + if (!thd->lex.safe_to_cache_query) + str->append("no_cache ", 9); + if (options & OPTION_TO_QUERY_CACHE) + str->append("cache ", 6); + + //Item List + bool first= 1; + List_iterator_fast<Item> it(item_list); + Item *item; + while ((item= it++)) + { + if (first) + first= 0; + else + str->append(','); + item->print_item_w_name(str); + } + + /* + from clause + TODO: support USING/FORCE/IGNORE index + */ + if (table_list.elements) + { + str->append(" from ", 6); + Item *next_on= 0; + for (TABLE_LIST *table= (TABLE_LIST *) table_list.first; + table; + table= table->next) + { + if (table->derived) + { + str->append('('); + table->derived->print(str); + str->append(") "); + str->append(table->alias); + } + else + { + str->append(table->db); + str->append('.'); + str->append(table->real_name); + if (strcmp(table->real_name, table->alias)) + { + str->append(' '); + str->append(table->alias); + } + } + + if (table->on_expr && ((table->outer_join & JOIN_TYPE_LEFT) || + !(table->outer_join & JOIN_TYPE_RIGHT))) + next_on= table->on_expr; + + if (next_on) + { + str->append(" on(", 4); + next_on->print(str); + str->append(')'); + next_on= 0; + } + + TABLE_LIST *next; + if ((next= table->next)) + { + if (table->outer_join & JOIN_TYPE_RIGHT) + { + str->append(" right join ", 12); + if (!(table->outer_join & JOIN_TYPE_LEFT) && + table->on_expr) + next_on= table->on_expr; + } + else if (next->straight) + str->append(" straight_join ", 15); + else if (next->outer_join & JOIN_TYPE_LEFT) + str->append(" left join ", 11); + else + str->append(" join ", 6); + } + } + } + + //where + Item *where= this->where; + if (join) + where= join->conds; + if (where) + { + str->append(" where ", 7); + where->print(str); + } + + //group by & olap + if (group_list.elements) + { + str->append(" group by ", 10); + print_order(str, (ORDER *) group_list.first); + switch (olap) + { + case CUBE_TYPE: + str->append(" with cube", 10); + break; + case ROLLUP_TYPE: + str->append(" with rollup", 12); + break; + default: + ; //satisfy compiler + } + } + + //having + Item *having= this->having; + if (join) + having= join->having; + + if (having) + { + str->append(" having ", 8); + having->print(str); + } + + if (order_list.elements) + { + str->append(" order by ", 10); + print_order(str, (ORDER *) order_list.first); + } + + // limit + print_limit(thd, str); + + // PROCEDURE unsupported here +} diff --git a/sql/sql_select.h b/sql/sql_select.h index 7306f609f66..cdf528060f7 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -151,7 +151,8 @@ class JOIN :public Sql_alloc Item_sum **sum_funcs2, ***sum_funcs_end2; Procedure *procedure; Item *having; - Item *tmp_having; // To store Having when processed temporary table + Item *tmp_having; // To store having when processed temporary table + Item *having_history; // Store having for explain uint select_options; select_result *result; TMP_TABLE_PARAM tmp_table_param; @@ -181,6 +182,7 @@ class JOIN :public Sql_alloc ORDER *order, *group_list, *proc_param; //hold parameters of mysql_select COND *conds; // ---"--- + Item *conds_history; // store WHERE for explain TABLE_LIST *tables_list; //hold 'tables' parameter of mysql_selec SQL_SELECT *select; //created in optimisation phase Item **ref_pointer_array; //used pointer reference for this select @@ -217,8 +219,7 @@ class JOIN :public Sql_alloc thd= thd_arg; sum_funcs= sum_funcs2= 0; procedure= 0; - having= 0; - tmp_having= 0; + having= tmp_having= having_history= 0; select_options= select_options_arg; result= result_arg; lock= thd_arg->lock; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 4f453bce903..95a6ebb36fb 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1111,12 +1111,12 @@ store_create_info(THD *thd, TABLE *table, String *packet) if (field->has_charset()) { if (field->charset() == &my_charset_bin) - packet->append(" binary"); + packet->append(" binary", 7); else if (!limited_mysql_mode && !foreign_db_mode) { if (field->charset() != table->table_charset) { - packet->append(" character set "); + packet->append(" character set ", 15); packet->append(field->charset()->csname); } /* @@ -1253,32 +1253,32 @@ store_create_info(THD *thd, TABLE *table, String *packet) !(thd->variables.sql_mode & MODE_MYSQL323) && !(thd->variables.sql_mode & MODE_MYSQL40)) { - packet->append(" CHARSET="); + packet->append(" CHARSET=", 9); packet->append(table->table_charset->csname); if (!(table->table_charset->state & MY_CS_PRIMARY)) { - packet->append(" COLLATE="); + packet->append(" COLLATE=", 9); packet->append(table->table_charset->name); } } if (table->min_rows) { - packet->append(" MIN_ROWS="); + packet->append(" MIN_ROWS=", 10); end= longlong10_to_str(table->min_rows, buff, 10); packet->append(buff, (uint) (end- buff)); } if (table->max_rows) { - packet->append(" MAX_ROWS="); + packet->append(" MAX_ROWS=", 10); end= longlong10_to_str(table->max_rows, buff, 10); packet->append(buff, (uint) (end - buff)); } if (table->avg_row_length) { - packet->append(" AVG_ROW_LENGTH="); + packet->append(" AVG_ROW_LENGTH=", 16); end= longlong10_to_str(table->avg_row_length, buff,10); packet->append(buff, (uint) (end - buff)); } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 00277759763..997e2122e2b 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -713,6 +713,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); union_clause union_list union_option precision subselect_start opt_and charset subselect_end select_var_list select_var_list_init help opt_len + opt_extended_describe END_OF_INPUT %type <NONE> @@ -2924,17 +2925,19 @@ opt_gconcat_separator: opt_gorder_clause: - /* empty */ - { - LEX *lex=Lex; - lex->gorder_list = NULL; - } - | order_clause - { - LEX *lex=Lex; - lex->gorder_list= (SQL_LIST*) sql_memdup((char*) &lex->current_select->order_list,sizeof(st_sql_list)); - lex->current_select->order_list.empty(); - }; + /* empty */ + { + LEX *lex=Lex; + lex->gorder_list = NULL; + } + | order_clause + { + LEX *lex=Lex; + lex->gorder_list= + (SQL_LIST*) sql_memdup((char*) &lex->current_select->order_list, + sizeof(st_sql_list)); + lex->current_select->order_list.empty(); + }; in_sum_expr: @@ -4073,7 +4076,9 @@ describe: YYABORT; } opt_describe_column {} - | describe_command { Lex->describe=1; } select + | describe_command opt_extended_describe + { Lex->describe|= DESCRIBE_NORMAL; } + select { LEX *lex=Lex; lex->select_lex.options|= SELECT_DESCRIBE; @@ -4084,6 +4089,11 @@ describe_command: DESC | DESCRIBE; +opt_extended_describe: + /* empty */ {} + | EXTENDED_SYM { Lex->describe|= DESCRIBE_EXTENDED; } + ; + opt_describe_column: /* empty */ {} | text_string { Lex->wild= $1; } @@ -4339,8 +4349,9 @@ literal: { Item *tmp= new Item_varbinary($2.str,$2.length); String *str= tmp ? tmp->val_str((String*) 0) : (String*) 0; - $$ = new Item_string(str ? str->ptr() : "", str ? str->length() : - 0, Lex->charset); + $$= new Item_string(str ? str->ptr() : "", + str ? str->length() : 0, + Lex->charset); } | DATE_SYM text_literal { $$ = $2; } | TIME_SYM text_literal { $$ = $2; } @@ -5399,7 +5410,7 @@ order_or_limit: union_option: /* empty */ {} - | ALL {Select->master_unit()->union_option= 1;}; + | ALL {Select->master_unit()->union_option|= UNION_ALL;}; singlerow_subselect: subselect_start singlerow_subselect_init |