summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2020-12-16 19:35:24 +0100
committerSergei Golubchik <serg@mariadb.org>2020-12-19 11:44:42 +0100
commit5785de72ac85ba37eda837c691aaf9a9195ba45d (patch)
tree35e2e60b7a604af74430faf2cbbbcee298430672
parentd1e9a4c15c7ea4121408c21e02a0006a19689508 (diff)
downloadmariadb-git-5785de72ac85ba37eda837c691aaf9a9195ba45d.tar.gz
Item_func_like calls escape_item->fix_fields() twice
this happens if Item_func_like is copied (get_copy()). after one copy gets fixed, the other tries to fix escape item again.
-rw-r--r--mysql-test/r/func_like.result5
-rw-r--r--mysql-test/t/func_like.test10
-rw-r--r--sql/item_cmpfunc.cc2
3 files changed, 15 insertions, 2 deletions
diff --git a/mysql-test/r/func_like.result b/mysql-test/r/func_like.result
index 0ba8e41f164..ee8f9734754 100644
--- a/mysql-test/r/func_like.result
+++ b/mysql-test/r/func_like.result
@@ -289,3 +289,8 @@ a b c d
3 f_ 1 0 1
3 f\_ 0 1 0
drop table t1;
+create table t1 (f int);
+insert t1 values (1),(2);
+select 1 from (select distinct * from t1) as x where f < (select 1 like 2 escape (3=1));
+1
+drop table t1;
diff --git a/mysql-test/t/func_like.test b/mysql-test/t/func_like.test
index 5026bb76aa3..bc0000046ef 100644
--- a/mysql-test/t/func_like.test
+++ b/mysql-test/t/func_like.test
@@ -187,7 +187,7 @@ DROP TABLE t1;
--echo #
#
-# Item_func_line::print()
+# Item_func_like::print()
#
create view v1 as select 'foo!' like 'foo!!', 'foo!' like 'foo!!' escape '!';
show create view v1;
@@ -207,3 +207,11 @@ insert t1 (a) values ('3 f_'), ('3 f\_');
set sql_mode=default;
select * from t1;
drop table t1;
+
+#
+# Item_func_like::fix_fields()
+#
+create table t1 (f int);
+insert t1 values (1),(2);
+select 1 from (select distinct * from t1) as x where f < (select 1 like 2 escape (3=1));
+drop table t1;
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 2a0972216f8..d0941ef58c2 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -5413,7 +5413,7 @@ bool Item_func_like::fix_fields(THD *thd, Item **ref)
{
DBUG_ASSERT(fixed == 0);
if (Item_bool_func2::fix_fields(thd, ref) ||
- escape_item->fix_fields(thd, &escape_item) ||
+ (!escape_item->fixed && escape_item->fix_fields(thd, &escape_item)) ||
fix_escape_item(thd, escape_item, &cmp_value1, escape_used_in_parsing,
cmp_collation.collation, &escape))
return TRUE;