diff options
-rw-r--r-- | client/mysqltest.cc | 11 | ||||
-rw-r--r-- | mysql-test/r/func_in.result | 9 | ||||
-rw-r--r-- | mysql-test/r/func_test.result | 41 | ||||
-rw-r--r-- | mysql-test/r/mysqltest_256.result | 1 | ||||
-rw-r--r-- | mysql-test/r/negation_elimination.result | 4 | ||||
-rw-r--r-- | mysql-test/r/ps.result | 56 | ||||
-rw-r--r-- | mysql-test/r/user_var.result | 7 | ||||
-rw-r--r-- | mysql-test/t/func_in.test | 11 | ||||
-rw-r--r-- | mysql-test/t/func_test.test | 20 | ||||
-rw-r--r-- | mysql-test/t/mysqltest_256.test | 17 | ||||
-rw-r--r-- | mysql-test/t/ps.test | 65 | ||||
-rw-r--r-- | mysql-test/t/user_var.test | 11 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 41 | ||||
-rw-r--r-- | sql/item_cmpfunc.h | 3 | ||||
-rw-r--r-- | sql/item_func.cc | 1 | ||||
-rw-r--r-- | sql/item_row.cc | 1 | ||||
-rw-r--r-- | sql/item_sum.cc | 3 | ||||
-rw-r--r-- | sql/sql_class.h | 3 | ||||
-rw-r--r-- | sql/sql_select.cc | 2 |
19 files changed, 300 insertions, 7 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 6cf9918e829..00ed5f700b2 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -8330,8 +8330,12 @@ int main(int argc, char **argv) command->abort_on_error= (command->expected_errors.count == 0 && abort_on_error); - /* delimiter needs to be executed so we can continue to parse */ - ok_to_do= cur_block->ok || command->type == Q_DELIMITER; + /* + some commmands need to be executed or at least parsed unconditionally, + because they change the grammar. + */ + ok_to_do= cur_block->ok || command->type == Q_DELIMITER + || command->type == Q_PERL; /* Some commands need to be "done" the first time if they may get re-iterated over in a true context. This can only happen if there's @@ -8342,8 +8346,7 @@ int main(int argc, char **argv) if (command->type == Q_SOURCE || command->type == Q_ERROR || command->type == Q_WRITE_FILE || - command->type == Q_APPEND_FILE || - command->type == Q_PERL) + command->type == Q_APPEND_FILE) { for (struct st_block *stb= cur_block-1; stb >= block_stack; stb--) { diff --git a/mysql-test/r/func_in.result b/mysql-test/r/func_in.result index 7f0e607e789..e45c775b377 100644 --- a/mysql-test/r/func_in.result +++ b/mysql-test/r/func_in.result @@ -787,3 +787,12 @@ DROP TABLE t1; # End of test BUG#13012483 # End of 5.1 tests +# +# LP bug#992380 Crash when creating PS for a query with +# subquery in WHERE (see also mysql bug#13012483) +# +CREATE TABLE t1 (a INT); +PREPARE s FROM "SELECT 1 FROM t1 WHERE 1 < ALL (SELECT @:= (1 IN (SELECT 1 FROM t1)) FROM t1)"; +EXECUTE s; +1 +DROP TABLE t1; diff --git a/mysql-test/r/func_test.result b/mysql-test/r/func_test.result index a97e6869d09..e3c77a40a77 100644 --- a/mysql-test/r/func_test.result +++ b/mysql-test/r/func_test.result @@ -279,3 +279,44 @@ NULL SELECT GREATEST(1.5E+2,1.3E+2,NULL) FROM DUAL; GREATEST(1.5E+2,1.3E+2,NULL) NULL +create table t1 (a int); +insert into t1 values (1), (100), (0), (NULL); +select not a from t1; +not a +0 +0 +1 +NULL +explain extended select not a from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00 +Warnings: +Note 1003 select (`test`.`t1`.`a` = 0) AS `not a` from `test`.`t1` +select * from t1 where not a; +a +0 +explain extended select * from t1 where not a; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 0) +select not (a+0) from t1; +not (a+0) +0 +0 +1 +NULL +explain extended select not (a+0) from t1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00 +Warnings: +Note 1003 select (not((`test`.`t1`.`a` + 0))) AS `not (a+0)` from `test`.`t1` +select * from t1 where not (a+0); +a +0 +explain extended select * from t1 where not (a+0); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where (not((`test`.`t1`.`a` + 0))) +drop table t1; diff --git a/mysql-test/r/mysqltest_256.result b/mysql-test/r/mysqltest_256.result new file mode 100644 index 00000000000..043c7208382 --- /dev/null +++ b/mysql-test/r/mysqltest_256.result @@ -0,0 +1 @@ +# Done diff --git a/mysql-test/r/negation_elimination.result b/mysql-test/r/negation_elimination.result index af48002ed0f..35510242bcb 100644 --- a/mysql-test/r/negation_elimination.result +++ b/mysql-test/r/negation_elimination.result @@ -321,7 +321,7 @@ select * from t1 where not(NULL or a); a explain select * from t1 where not(NULL and a); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index NULL a 5 NULL 21 Using where; Using index +1 SIMPLE t1 ref a a 5 const 1 Using where; Using index select * from t1 where not(NULL and a); a 0 @@ -387,5 +387,5 @@ explain extended select a, not(not(a)), not(a <= 2 and not(a)), not(a not like " id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 range a a 5 NULL 4 100.00 Using where; Using index Warnings: -Note 1003 select `test`.`t1`.`a` AS `a`,(`test`.`t1`.`a` <> 0) AS `not(not(a))`,((`test`.`t1`.`a` > 2) or `test`.`t1`.`a`) AS `not(a <= 2 and not(a))`,(`test`.`t1`.`a` like '1') AS `not(a not like "1")`,(`test`.`t1`.`a` in (1,2)) AS `not (a not in (1,2))`,(`test`.`t1`.`a` = 2) AS `not(a != 2)` from `test`.`t1` where (`test`.`t1`.`a` <> 0) having (`test`.`t1`.`a` <> 0) +Note 1003 select `test`.`t1`.`a` AS `a`,(`test`.`t1`.`a` <> 0) AS `not(not(a))`,((`test`.`t1`.`a` > 2) or (`test`.`t1`.`a` <> 0)) AS `not(a <= 2 and not(a))`,(`test`.`t1`.`a` like '1') AS `not(a not like "1")`,(`test`.`t1`.`a` in (1,2)) AS `not (a not in (1,2))`,(`test`.`t1`.`a` = 2) AS `not(a != 2)` from `test`.`t1` where (`test`.`t1`.`a` <> 0) having (`test`.`t1`.`a` <> 0) drop table t1; diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index b3f4ad017d3..72558324b50 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -3040,3 +3040,59 @@ id select_type table type possible_keys key key_len ref rows Extra DEALLOCATE PREPARE stmt; DROP TABLE t1; End of 5.1 tests. +# +# LP bug#1001500 Crash on the second execution of the PS for +# a query with degenerated conjunctive condition +# (see also mysql bug#12582849) +# +CREATE TABLE t1 ( +pk INTEGER AUTO_INCREMENT, +col_int_nokey INTEGER, +col_int_key INTEGER, +col_varchar_key VARCHAR(1), +col_varchar_nokey VARCHAR(1), +PRIMARY KEY (pk), +KEY (col_int_key), +KEY (col_varchar_key, col_int_key) +); +INSERT INTO t1 ( +col_int_key, col_int_nokey, +col_varchar_key, col_varchar_nokey +) VALUES +(4, 2, 'v', 'v'), +(62, 150, 'v', 'v'); +CREATE TABLE t2 ( +pk INTEGER AUTO_INCREMENT, +col_int_nokey INTEGER, +col_int_key INTEGER, +col_varchar_key VARCHAR(1), +col_varchar_nokey VARCHAR(1), +PRIMARY KEY (pk), +KEY (col_int_key), +KEY (col_varchar_key, col_int_key) +); +INSERT INTO t2 ( +col_int_key, col_int_nokey, +col_varchar_key, col_varchar_nokey +) VALUES +(8, NULL, 'x', 'x'), +(7, 8, 'd', 'd'); +PREPARE stmt FROM ' +SELECT + ( SELECT MAX( SQ1_alias2 .col_int_nokey ) AS SQ1_field1 + FROM ( t2 AS SQ1_alias1 RIGHT JOIN t1 AS SQ1_alias2 + ON ( SQ1_alias2.col_varchar_key = SQ1_alias1.col_varchar_nokey ) + ) + WHERE SQ1_alias2.pk < alias1.col_int_nokey OR alias1.pk + ) AS field1 +FROM ( t1 AS alias1 JOIN t2 AS alias2 ON alias2.pk ) +GROUP BY field1 +'; +EXECUTE stmt; +field1 +150 +EXECUTE stmt; +field1 +150 +DEALLOCATE PREPARE stmt; +DROP TABLE t1, t2; diff --git a/mysql-test/r/user_var.result b/mysql-test/r/user_var.result index 374520ff610..19cb54ad2bc 100644 --- a/mysql-test/r/user_var.result +++ b/mysql-test/r/user_var.result @@ -456,4 +456,11 @@ SELECT (@v:=a) <> (@v:=1) FROM t1; (@v:=a) <> (@v:=1) 1 DROP TABLE t1; +CREATE TABLE t1(a int); +INSERT INTO t1 VALUES (1), (2); +SELECT DISTINCT @a:=MIN(t1.a) FROM t1, t1 AS t2 +GROUP BY @b:=(SELECT COUNT(*) > t2.a); +@a:=MIN(t1.a) +1 +DROP TABLE t1; End of 5.1 tests diff --git a/mysql-test/t/func_in.test b/mysql-test/t/func_in.test index dd4194e2a4e..9e054da3fe2 100644 --- a/mysql-test/t/func_in.test +++ b/mysql-test/t/func_in.test @@ -576,3 +576,14 @@ DROP TABLE t1; --echo # --echo End of 5.1 tests + +--echo # +--echo # LP bug#992380 Crash when creating PS for a query with +--echo # subquery in WHERE (see also mysql bug#13012483) +--echo # +CREATE TABLE t1 (a INT); +PREPARE s FROM "SELECT 1 FROM t1 WHERE 1 < ALL (SELECT @:= (1 IN (SELECT 1 FROM t1)) FROM t1)"; +EXECUTE s; + +DROP TABLE t1; + diff --git a/mysql-test/t/func_test.test b/mysql-test/t/func_test.test index 77bf3be5e72..4cba29986a1 100644 --- a/mysql-test/t/func_test.test +++ b/mysql-test/t/func_test.test @@ -160,3 +160,23 @@ SELECT LEAST(1.1,1.2,NULL,1.0) FROM DUAL; SELECT GREATEST(1.5E+2,1.3E+2,NULL) FROM DUAL; # End of 4.1 tests + +# +# test of replacing NOT <field> +# +create table t1 (a int); +insert into t1 values (1), (100), (0), (NULL); + +select not a from t1; +explain extended select not a from t1; + +select * from t1 where not a; +explain extended select * from t1 where not a; + +select not (a+0) from t1; +explain extended select not (a+0) from t1; + +select * from t1 where not (a+0); +explain extended select * from t1 where not (a+0); + +drop table t1; diff --git a/mysql-test/t/mysqltest_256.test b/mysql-test/t/mysqltest_256.test new file mode 100644 index 00000000000..fd9447cd2d8 --- /dev/null +++ b/mysql-test/t/mysqltest_256.test @@ -0,0 +1,17 @@ +# +# MDEV-256 lp:995501 - mysqltest attempts to parse Perl code inside a block +# with false condition, gets confused and throws wrong errors +# + +let $run = 0; +if ($run) +{ + --perl + foreach (1) + { + print "In perl\n"; + } + EOF + SELECT 1; +} +--echo # Done diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index 9b3f3e750e1..e3f2a5c87d1 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -3102,3 +3102,68 @@ DEALLOCATE PREPARE stmt; DROP TABLE t1; --echo End of 5.1 tests. + +--echo # +--echo # LP bug#1001500 Crash on the second execution of the PS for +--echo # a query with degenerated conjunctive condition +--echo # (see also mysql bug#12582849) +--echo # + +CREATE TABLE t1 ( + pk INTEGER AUTO_INCREMENT, + col_int_nokey INTEGER, + col_int_key INTEGER, + + col_varchar_key VARCHAR(1), + col_varchar_nokey VARCHAR(1), + + PRIMARY KEY (pk), + KEY (col_int_key), + KEY (col_varchar_key, col_int_key) +); + +INSERT INTO t1 ( + col_int_key, col_int_nokey, + col_varchar_key, col_varchar_nokey +) VALUES +(4, 2, 'v', 'v'), +(62, 150, 'v', 'v'); + +CREATE TABLE t2 ( + pk INTEGER AUTO_INCREMENT, + col_int_nokey INTEGER, + col_int_key INTEGER, + + col_varchar_key VARCHAR(1), + col_varchar_nokey VARCHAR(1), + + PRIMARY KEY (pk), + KEY (col_int_key), + KEY (col_varchar_key, col_int_key) +); + +INSERT INTO t2 ( + col_int_key, col_int_nokey, + col_varchar_key, col_varchar_nokey +) VALUES +(8, NULL, 'x', 'x'), +(7, 8, 'd', 'd'); + +PREPARE stmt FROM ' +SELECT + ( SELECT MAX( SQ1_alias2 .col_int_nokey ) AS SQ1_field1 + FROM ( t2 AS SQ1_alias1 RIGHT JOIN t1 AS SQ1_alias2 + ON ( SQ1_alias2.col_varchar_key = SQ1_alias1.col_varchar_nokey ) + ) + WHERE SQ1_alias2.pk < alias1.col_int_nokey OR alias1.pk + ) AS field1 +FROM ( t1 AS alias1 JOIN t2 AS alias2 ON alias2.pk ) +GROUP BY field1 +'; + +EXECUTE stmt; +EXECUTE stmt; + +DEALLOCATE PREPARE stmt; + +DROP TABLE t1, t2; diff --git a/mysql-test/t/user_var.test b/mysql-test/t/user_var.test index efaf8afd91e..2782f61994d 100644 --- a/mysql-test/t/user_var.test +++ b/mysql-test/t/user_var.test @@ -365,4 +365,15 @@ SELECT (@v:=a) <> (@v:=1) FROM t1; DROP TABLE t1; +# +# LP BUG#1001506 Crash on a query with GROUP BY and user variables +# MySQL Bug #11764372 57197: EVEN MORE USER VARIABLE CRASHING FUN +# + +CREATE TABLE t1(a int); +INSERT INTO t1 VALUES (1), (2); +SELECT DISTINCT @a:=MIN(t1.a) FROM t1, t1 AS t2 +GROUP BY @b:=(SELECT COUNT(*) > t2.a); +DROP TABLE t1; + --echo End of 5.1 tests diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index ea216944dbb..61554bdf420 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1791,6 +1791,7 @@ bool Item_in_optimizer::fix_fields(THD *thd, Item **ref) } if (args[1]->maybe_null) maybe_null=1; + with_subselect= 1; with_sum_func= with_sum_func || args[1]->with_sum_func; used_tables_cache|= args[1]->used_tables(); not_null_tables_cache|= args[1]->not_null_tables(); @@ -4270,6 +4271,22 @@ Item_cond::fix_fields(THD *thd, Item **ref) if (abort_on_null) item->top_level_item(); + /* + replace degraded condition: + was: <field> + become: <field> = 1 + */ + if (item->type() == FIELD_ITEM) + { + Query_arena backup, *arena; + Item *new_item; + arena= thd->activate_stmt_arena_if_needed(&backup); + if ((new_item= new Item_func_ne(item, new Item_int(0, 1)))) + li.replace(item= new_item); + if (arena) + thd->restore_active_arena(arena, &backup); + } + // item can be substituted in fix_fields if ((!item->fixed && item->fix_fields(thd, li.ref())) || @@ -4907,6 +4924,7 @@ Item_func_regex::fix_fields(THD *thd, Item **ref) args[1]->fix_fields(thd, args + 1)) || args[1]->check_cols(1)) return TRUE; /* purecov: inspected */ with_sum_func=args[0]->with_sum_func || args[1]->with_sum_func; + with_subselect|= args[0]->with_subselect | args[1]->with_subselect; max_length= 1; decimals= 0; @@ -5281,6 +5299,28 @@ Item *Item_func_not::neg_transformer(THD *thd) /* NOT(x) -> x */ } +bool Item_func_not::fix_fields(THD *thd, Item **ref) +{ + if (args[0]->type() == FIELD_ITEM) + { + /* replace "NOT <field>" with "<filed> == 0" */ + Query_arena backup, *arena; + Item *new_item; + bool rc= TRUE; + arena= thd->activate_stmt_arena_if_needed(&backup); + if ((new_item= new Item_func_eq(args[0], new Item_int(0, 1)))) + { + new_item->name= name; + rc= (*ref= new_item)->fix_fields(thd, ref); + } + if (arena) + thd->restore_active_arena(arena, &backup); + return rc; + } + return Item_func::fix_fields(thd, ref); +} + + Item *Item_bool_rowready_func2::neg_transformer(THD *thd) { Item *item= negated_item(); @@ -5597,6 +5637,7 @@ bool Item_equal::fix_fields(THD *thd, Item **ref) used_tables_cache|= item->used_tables(); tmp_table_map= item->not_null_tables(); not_null_tables_cache|= tmp_table_map; + DBUG_ASSERT(!item->with_sum_func && !item->with_subselect); if (item->maybe_null) maybe_null=1; } diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 25b636397a8..7239079c56f 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -413,6 +413,7 @@ public: enum Functype functype() const { return NOT_FUNC; } const char *func_name() const { return "not"; } Item *neg_transformer(THD *thd); + bool fix_fields(THD *, Item **); virtual void print(String *str, enum_query_type query_type); }; @@ -479,6 +480,8 @@ public: longlong val_int(); enum Functype functype() const { return NOT_ALL_FUNC; } const char *func_name() const { return "<not>"; } + bool fix_fields(THD *thd, Item **ref) + {return Item_func::fix_fields(thd, ref);} virtual void print(String *str, enum_query_type query_type); void set_sum_test(Item_sum_hybrid *item) { test_sum_item= item; }; void set_sub_test(Item_maxmin_subselect *item) { test_sub_item= item; }; diff --git a/sql/item_func.cc b/sql/item_func.cc index ed771b60769..8028ae53eaf 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2918,6 +2918,7 @@ udf_handler::fix_fields(THD *thd, Item_result_field *func, if (item->maybe_null) func->maybe_null=1; func->with_sum_func= func->with_sum_func || item->with_sum_func; + func->with_subselect|= item->with_subselect; used_tables_cache|=item->used_tables(); const_item_cache&=item->const_item(); f_args.arg_type[i]=item->result_type(); diff --git a/sql/item_row.cc b/sql/item_row.cc index 4040dbff7c6..5296f866248 100644 --- a/sql/item_row.cc +++ b/sql/item_row.cc @@ -88,6 +88,7 @@ bool Item_row::fix_fields(THD *thd, Item **ref) } maybe_null|= item->maybe_null; with_sum_func= with_sum_func || item->with_sum_func; + with_subselect|= item->with_subselect; } fixed= 1; return FALSE; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index ac6ddc0fd54..61a780b6222 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -574,6 +574,7 @@ Item_sum_num::fix_fields(THD *thd, Item **ref) if (args[i]->fix_fields(thd, args + i) || args[i]->check_cols(1)) return TRUE; set_if_bigger(decimals, args[i]->decimals); + with_subselect|= args[i]->with_subselect; } result_field=0; max_length=float_length(decimals); @@ -604,6 +605,7 @@ Item_sum_hybrid::fix_fields(THD *thd, Item **ref) (item= args[0])->check_cols(1)) return TRUE; decimals=item->decimals; + with_subselect= args[0]->with_subselect; switch (hybrid_type= item->result_type()) { case INT_RESULT: @@ -3216,6 +3218,7 @@ Item_func_group_concat::fix_fields(THD *thd, Item **ref) args[i]->fix_fields(thd, args + i)) || args[i]->check_cols(1)) return TRUE; + with_subselect|= args[i]->with_subselect; } if (agg_item_charsets(collation, func_name(), diff --git a/sql/sql_class.h b/sql/sql_class.h index 4bf1bc3964c..14f4f022de3 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2880,7 +2880,8 @@ public: if (copy_field) /* Fix for Intel compiler */ { delete [] copy_field; - save_copy_field= copy_field= 0; + save_copy_field= copy_field= NULL; + save_copy_field_end= copy_field_end= NULL; } } }; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 150f19f96a6..46b4511e24f 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -16072,6 +16072,8 @@ copy_fields(TMP_TABLE_PARAM *param) Copy_field *ptr=param->copy_field; Copy_field *end=param->copy_field_end; + DBUG_ASSERT((ptr != NULL && end >= ptr) || (ptr == NULL && end == NULL)); + for (; ptr != end; ptr++) (*ptr->do_copy)(ptr); |