From f317cafc5921050198b980c8418461a0fe79e4b6 Mon Sep 17 00:00:00 2001 From: "ram@gw.mysql.r18.ru" <> Date: Mon, 11 Oct 2004 18:38:48 +0500 Subject: [PATCH 1/7] A fix (bug #5615 type of aggregate function column wrong when using group by). --- mysql-test/r/func_group.result | 9 +++++++++ mysql-test/t/func_group.test | 10 ++++++++++ sql/sql_select.cc | 9 +++++++++ 3 files changed, 28 insertions(+) diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result index c25f89d4df3..ecf6422261f 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -719,3 +719,12 @@ one 2 two 2 three 1 drop table t1; +create table t1(a int, b datetime); +insert into t1 values (1, NOW()), (2, NOW()); +create table t2 select MAX(b) from t1 group by a; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `MAX(b)` datetime default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1, t2; diff --git a/mysql-test/t/func_group.test b/mysql-test/t/func_group.test index 3e001961f90..ecd3bf97f0b 100644 --- a/mysql-test/t/func_group.test +++ b/mysql-test/t/func_group.test @@ -458,3 +458,13 @@ INSERT INTO t1 VALUES select val, count(*) from t1 group by val; drop table t1; + +# +# Bug #5615: type of aggregate function column wrong when using group by +# + +create table t1(a int, b datetime); +insert into t1 values (1, NOW()), (2, NOW()); +create table t2 select MAX(b) from t1 group by a; +show create table t2; +drop table t1, t2; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 638ed229a70..7ffef151457 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4744,6 +4744,15 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, item->name,table,item_sum->decimals); case Item_sum::UNIQUE_USERS_FUNC: return new Field_long(9,maybe_null,item->name,table,1); + case Item_sum::MIN_FUNC: + case Item_sum::MAX_FUNC: + if (item_sum->args[0]->type() == Item::FIELD_ITEM) + { + *from_field= ((Item_field*) item_sum->args[0])->field; + return create_tmp_field_from_field(thd, *from_field, item, table, + modify_item, convert_blob_length); + } + /* fall through */ default: switch (item_sum->result_type()) { case REAL_RESULT: From 725fd87d39832e04b6d413a4b45080e27b8d8fd5 Mon Sep 17 00:00:00 2001 From: "ram@gw.mysql.r18.ru" <> Date: Mon, 11 Oct 2004 19:17:13 +0500 Subject: [PATCH 2/7] An addition (see ChangeSet 1.2082 04/10/11 18:38:48 ram@gw.mysql.r18.ru +3 -0 A fix (bug #5615 type of aggregate function column wrong when using group by).) Shouldn't it be 'int(11) not null' == the same as in the t1? --- mysql-test/r/show_check.result | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result index 8256c8d692a..5ea17c93f48 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -250,9 +250,11 @@ type_bool type_tiny type_short type_mediumint type_bigint type_decimal type_nume drop table t1; create table t1 (a int not null); create table t2 select max(a) from t1; +Warnings: +Warning 1263 Data truncated; NULL supplied to NOT NULL column 'max(a)' at row 1 show columns from t2; Field Type Null Key Default Extra -max(a) bigint(20) YES NULL +max(a) int(11) 0 drop table t1,t2; create table t1 (c decimal, d double, f float, r real); show columns from t1; From 07743423f74e6613e69835fc46c8cb05b172591d Mon Sep 17 00:00:00 2001 From: "ram@gw.mysql.r18.ru" <> Date: Wed, 27 Oct 2004 14:51:17 +0500 Subject: [PATCH 3/7] A fix (bug #6089: FOUND_ROWS returns wrong values when no table/view is used). --- mysql-test/r/ps.result | 2 +- mysql-test/r/select_found.result | 25 +++++++++++++++++++++++++ mysql-test/t/select_found.test | 15 +++++++++++++++ sql/sql_class.cc | 1 + sql/sql_select.cc | 4 +++- 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index 6cad58282a2..8c55bb08249 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -135,7 +135,7 @@ FOUND_ROWS() 1 execute stmt1; FOUND_ROWS() -0 +1 deallocate prepare stmt1; drop table t1; create table t1 diff --git a/mysql-test/r/select_found.result b/mysql-test/r/select_found.result index 00dbcb54d93..1eaa7033c99 100644 --- a/mysql-test/r/select_found.result +++ b/mysql-test/r/select_found.result @@ -246,3 +246,28 @@ SELECT FOUND_ROWS(); FOUND_ROWS() 0 DROP TABLE t1; +SELECT 'foo'; +foo +foo +SELECT FOUND_ROWS(); +FOUND_ROWS() +1 +SELECT SQL_CALC_FOUND_ROWS 'foo'; +foo +foo +SELECT FOUND_ROWS(); +FOUND_ROWS() +1 +SELECT SQL_CALC_FOUND_ROWS 'foo' limit 0; +foo +SELECT FOUND_ROWS(); +FOUND_ROWS() +1 +SELECT FOUND_ROWS(); +FOUND_ROWS() +1 +SELECT SQL_CALC_FOUND_ROWS 'foo' UNION SELECT 'bar' LIMIT 0; +foo +SELECT FOUND_ROWS(); +FOUND_ROWS() +2 diff --git a/mysql-test/t/select_found.test b/mysql-test/t/select_found.test index 943174462e3..e51dd2442b9 100644 --- a/mysql-test/t/select_found.test +++ b/mysql-test/t/select_found.test @@ -166,3 +166,18 @@ INSERT INTO t1 VALUES (0), (0), (1), (2); SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a = 0 GROUP BY a HAVING a > 10; SELECT FOUND_ROWS(); DROP TABLE t1; + +# +# Bug #6089: queries which don't use any tables +# + +SELECT 'foo'; +SELECT FOUND_ROWS(); +SELECT SQL_CALC_FOUND_ROWS 'foo'; +SELECT FOUND_ROWS(); +SELECT SQL_CALC_FOUND_ROWS 'foo' limit 0; +SELECT FOUND_ROWS(); +SELECT FOUND_ROWS(); + +SELECT SQL_CALC_FOUND_ROWS 'foo' UNION SELECT 'bar' LIMIT 0; +SELECT FOUND_ROWS(); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index abe00027b07..b6fdac03526 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -177,6 +177,7 @@ THD::THD() lock=locked_tables=0; used_tables=0; cuted_fields= sent_row_count= 0L; + limit_found_rows= 0; statement_id_counter= 0UL; // Must be reset to handle error with THD's created for init of mysqld lex->current_select= 0; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index df74a946b5c..1610057f877 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1067,7 +1067,9 @@ JOIN::exec() else error=(int) result->send_eof(); } - thd->limit_found_rows= thd->examined_row_count= 0; + /* Single select (without union and limit) always returns 1 row */ + thd->limit_found_rows= 1; + thd->examined_row_count= 0; DBUG_VOID_RETURN; } thd->limit_found_rows= thd->examined_row_count= 0; From 511a166d559c37ca7a1f03234db2cbf11bf04a10 Mon Sep 17 00:00:00 2001 From: "sergefp@mysql.com" <> Date: Sat, 5 Feb 2005 06:23:23 +0300 Subject: [PATCH 4/7] Fix for BUG#7519: Index statistics is not displayed after ANALYZE for temporary tables: Call file->extra() with HA_STATUS_CONST in mysqld_show_keys. The fix will not be merged into 4.1/5.0 because they don't have this problem already. --- mysql-test/r/show_check.result | 22 ++++++++++++++++++++++ mysql-test/t/show_check.test | 16 ++++++++++++++++ sql/sql_show.cc | 3 ++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result index f40b0693585..6d23dde1f1b 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -233,3 +233,25 @@ c decimal(4,3) YES NULL d double(4,3) YES NULL f float(4,3) YES NULL drop table t1; +CREATE TABLE t1 ( a VARCHAR(20) ); +INSERT INTO t1 VALUES ('one'),('two'),('three'),('four'),('five'); +CREATE TEMPORARY TABLE t2 ( index (a(20)) ) SELECT a FROM t1 GROUP BY a; +SHOW INDEX FROM t2; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment +t2 X a X X X NULL X X X BTREE +ANALYZE TABLE t2; +Table Op Msg_type Msg_text +test.t2 analyze status OK +SHOW INDEX FROM t2; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment +t2 X a X X X 5 X X X BTREE +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TEMPORARY TABLE `t2` ( + `a` varchar(20) default NULL, + KEY `a` (`a`) +) TYPE=MyISAM +SHOW INDEX FROM t2; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment +t2 X a X X X 5 X X X BTREE +DROP TEMPORARY TABLE t2; diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test index 2cd2012d109..e712ed77f04 100644 --- a/mysql-test/t/show_check.test +++ b/mysql-test/t/show_check.test @@ -131,3 +131,19 @@ drop table t1; create table t1 (c decimal(3,3), d double(3,3), f float(3,3)); show columns from t1; drop table t1; + +# Fix for BUG#7519: For temporary tables, SHOW INDEX doesn't display index +# cardinality after ANALYZE. +CREATE TABLE t1 ( a VARCHAR(20) ); +INSERT INTO t1 VALUES ('one'),('two'),('three'),('four'),('five'); +CREATE TEMPORARY TABLE t2 ( index (a(20)) ) SELECT a FROM t1 GROUP BY a; +--replace_column 2 X 4 X 5 X 6 X 8 X 9 X 10 X +SHOW INDEX FROM t2; +ANALYZE TABLE t2; +--replace_column 2 X 4 X 5 X 6 X 8 X 9 X 10 X +SHOW INDEX FROM t2; +SHOW CREATE TABLE t2; +--replace_column 2 X 4 X 5 X 6 X 8 X 9 X 10 X +SHOW INDEX FROM t2; +DROP TEMPORARY TABLE t2; + diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 2506033cda5..27246729162 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -686,7 +686,8 @@ mysqld_show_keys(THD *thd, TABLE_LIST *table_list) String *packet= &thd->packet; KEY *key_info=table->key_info; - table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK | HA_STATUS_TIME); + table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK | HA_STATUS_TIME | + HA_STATUS_CONST); for (uint i=0 ; i < table->keys ; i++,key_info++) { KEY_PART_INFO *key_part= key_info->key_part; From eb5d5de05fb6fe47c2283e62d83ab203e4a65d48 Mon Sep 17 00:00:00 2001 From: "sergefp@mysql.com" <> Date: Sat, 26 Feb 2005 17:15:04 +0300 Subject: [PATCH 5/7] Fix for BUG#8560: Set max_sort_char for any 8-bit charset with binary collation. max_sort_char is needed by my_like_range_simple to produce upper bound constants for LIKE "str_%" and similar expressions. --- mysql-test/r/ctype_cp1251.result | 16 ++++++++++++++++ mysql-test/t/ctype_cp1251.test | 14 ++++++++++++++ strings/ctype-bin.c | 9 ++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/ctype_cp1251.result b/mysql-test/r/ctype_cp1251.result index 3793e962d40..647f8c6236c 100644 --- a/mysql-test/r/ctype_cp1251.result +++ b/mysql-test/r/ctype_cp1251.result @@ -54,3 +54,19 @@ select collation(a), collation(b), collation(binary 'ccc') from t1 limit 1; collation(a) collation(b) collation(binary 'ccc') cp1251_bin binary binary drop table t1; +create table t1 ( +a varchar(16) character set cp1251 collate cp1251_bin not null, +b int(10) default null, +primary key(a) +) charset=cp1251; +insert into t1 (a) values ('air'), +('we'),('g'),('we_toshko'), ('s0urce'),('we_ivo'),('we_iliyan'), +('we_martin'),('vw_grado'),('vw_vasko'),('tn_vili'),('tn_kalina'), +('tn_fakira'),('vw_silvia'),('vw_starshi'),('vw_geo'),('vw_b0x1'); +select * from t1 where a like 'we_%'; +a b +we_iliyan NULL +we_ivo NULL +we_martin NULL +we_toshko NULL +drop table t1; diff --git a/mysql-test/t/ctype_cp1251.test b/mysql-test/t/ctype_cp1251.test index 66a8a5aa909..2d670ec3607 100644 --- a/mysql-test/t/ctype_cp1251.test +++ b/mysql-test/t/ctype_cp1251.test @@ -32,3 +32,17 @@ select * from t1 where lower(b)='bbb'; select charset(a), charset(b), charset(binary 'ccc') from t1 limit 1; select collation(a), collation(b), collation(binary 'ccc') from t1 limit 1; drop table t1; + +# Test for BUG#8560 +create table t1 ( + a varchar(16) character set cp1251 collate cp1251_bin not null, + b int(10) default null, + primary key(a) +) charset=cp1251; +insert into t1 (a) values ('air'), + ('we'),('g'),('we_toshko'), ('s0urce'),('we_ivo'),('we_iliyan'), + ('we_martin'),('vw_grado'),('vw_vasko'),('tn_vili'),('tn_kalina'), + ('tn_fakira'),('vw_silvia'),('vw_starshi'),('vw_geo'),('vw_b0x1'); + +select * from t1 where a like 'we_%'; +drop table t1; diff --git a/strings/ctype-bin.c b/strings/ctype-bin.c index 618879607ec..425985e6bc1 100644 --- a/strings/ctype-bin.c +++ b/strings/ctype-bin.c @@ -67,6 +67,13 @@ static uchar bin_char_array[] = }; +static my_bool +my_coll_init_8bit_bin(CHARSET_INFO *cs, + void *(*alloc)(uint) __attribute__((unused))) +{ + cs->max_sort_char=255; + return FALSE; +} static int my_strnncoll_binary(CHARSET_INFO * cs __attribute__((unused)), const uchar *s, uint slen, @@ -428,7 +435,7 @@ skip: MY_COLLATION_HANDLER my_collation_8bit_bin_handler = { - NULL, /* init */ + my_coll_init_8bit_bin, my_strnncoll_8bit_bin, my_strnncollsp_8bit_bin, my_strnxfrm_8bit_bin, From a6ad8a4d0f6d405919c1968450ff64b1dbded38d Mon Sep 17 00:00:00 2001 From: "sergefp@mysql.com" <> Date: Mon, 28 Feb 2005 20:21:21 +0300 Subject: [PATCH 6/7] Fix for BUG#8726: In JOIN::optimize on ER_TOO_BIG_SELECT error set JOIN::error to -1 to cause the error to be sent to the client. --- mysql-test/r/select_safe.result | 15 +++++++++++++++ mysql-test/t/select_safe.test | 20 ++++++++++++++++++++ sql/sql_select.cc | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/select_safe.result b/mysql-test/r/select_safe.result index 766ee8c0e14..7a29db42dd9 100644 --- a/mysql-test/r/select_safe.result +++ b/mysql-test/r/select_safe.result @@ -78,4 +78,19 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ref b b 21 test.t1.b 6 Using where SET MAX_SEEKS_FOR_KEY=DEFAULT; drop table t1; +create table t1 (a int); +insert into t1 values (1),(2),(3),(4),(5); +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; +set local max_join_size=8; +select * from (select * from t1) x; +ERROR 42000: The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay +set local max_join_size=1; +select * from (select * from t1 a, t1 b) x; +ERROR 42000: The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay +set local max_join_size=1; +select * from (select 1 union select 2 union select 3) x; +ERROR 42000: The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay +drop table t1; SET SQL_SAFE_UPDATES=0,SQL_SELECT_LIMIT=DEFAULT, SQL_MAX_JOIN_SIZE=DEFAULT; diff --git a/mysql-test/t/select_safe.test b/mysql-test/t/select_safe.test index 3cafd31a879..5b2dfb00bb7 100644 --- a/mysql-test/t/select_safe.test +++ b/mysql-test/t/select_safe.test @@ -66,4 +66,24 @@ SET MAX_SEEKS_FOR_KEY=DEFAULT; drop table t1; +# BUG#8726 +create table t1 (a int); +insert into t1 values (1),(2),(3),(4),(5); +insert into t1 select * from t1; +insert into t1 select * from t1; +insert into t1 select * from t1; + +set local max_join_size=8; +--error 1104 +select * from (select * from t1) x; + +set local max_join_size=1; +--error 1104 +select * from (select * from t1 a, t1 b) x; + +set local max_join_size=1; +--error 1104 +select * from (select 1 union select 2 union select 3) x; +drop table t1; + SET SQL_SAFE_UPDATES=0,SQL_SELECT_LIMIT=DEFAULT, SQL_MAX_JOIN_SIZE=DEFAULT; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index a210fbbbe02..d207d50e306 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -579,7 +579,7 @@ JOIN::optimize() !(select_options & SELECT_DESCRIBE)) { /* purecov: inspected */ my_message(ER_TOO_BIG_SELECT, ER(ER_TOO_BIG_SELECT), MYF(0)); - error= 1; /* purecov: inspected */ + error= -1; DBUG_RETURN(1); } if (const_tables && !thd->locked_tables && From 530b12166e1f0fba65d0454c189c5b21dcc22fb8 Mon Sep 17 00:00:00 2001 From: "jani@ua141d10.elisa.omakaista.fi" <> Date: Tue, 1 Mar 2005 14:13:25 +0200 Subject: [PATCH 7/7] Fixed Bug#7906, "Cmdline help for mysqld --ansi option misses some info". --- sql/mysqld.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index f1b1d8a7d86..b5674d17901 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4173,7 +4173,7 @@ struct my_option my_long_options[] = (gptr*) &abort_slave_event_count, (gptr*) &abort_slave_event_count, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #endif /* HAVE_REPLICATION */ - {"ansi", 'a', "Use ANSI SQL syntax instead of MySQL syntax.", 0, 0, 0, + {"ansi", 'a', "Use ANSI SQL syntax instead of MySQL syntax. This mode will also set transaction isolation level 'serializable'.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"basedir", 'b', "Path to installation directory. All paths are usually resolved relative to this.",