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/r/func_group.result b/mysql-test/r/func_group.result index 017a6a239df..6aadcd359b7 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -757,6 +757,15 @@ 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; create table t1(f1 datetime); insert into t1 values (now()); create table t2 select f2 from (select max(now()) f2 from t1) a; diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index 7fe67eb22fe..7d008c6e753 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -129,7 +129,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 1a2d366fb2a..7abd65beb46 100644 --- a/mysql-test/r/select_found.result +++ b/mysql-test/r/select_found.result @@ -246,6 +246,31 @@ 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 CREATE TABLE t1 (a int, b int); INSERT INTO t1 VALUES (1,2), (1,3), (1,4), (1,5); SELECT SQL_CALC_FOUND_ROWS DISTINCT 'a' FROM t1 GROUP BY b LIMIT 2; 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/r/show_check.result b/mysql-test/r/show_check.result index 53882e6be69..a2b2eebf628 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -252,9 +252,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; 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/mysql-test/t/func_group.test b/mysql-test/t/func_group.test index 9a61e6f7029..51528be8952 100644 --- a/mysql-test/t/func_group.test +++ b/mysql-test/t/func_group.test @@ -479,6 +479,15 @@ 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; # # Bug 7833: Wrong datatype of aggregate column is returned diff --git a/mysql-test/t/select_found.test b/mysql-test/t/select_found.test index 5bd068eb0e6..91879015b51 100644 --- a/mysql-test/t/select_found.test +++ b/mysql-test/t/select_found.test @@ -167,6 +167,21 @@ 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(); + # # Bug #7945: group by + distinct with constant expression + limit # 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/mysqld.cc b/sql/mysqld.cc index ef982e489c9..4d66a2757c3 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4268,7 +4268,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}, {"auto-increment-increment", OPT_AUTO_INCREMENT, "Auto-increment columns are incremented by this", diff --git a/sql/sql_class.cc b/sql/sql_class.cc index eb98b96c9ec..527f349038c 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -183,6 +183,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 7521de854d9..cbe7937355c 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -664,7 +664,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 && @@ -1194,7 +1194,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; diff --git a/strings/ctype-bin.c b/strings/ctype-bin.c index 916ef6d271b..9f0e334d3a9 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, @@ -443,7 +450,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,