-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDEV-33010 Crash when pushing condition with CHARSET()/COERCIBILITY()…
… into derived table Based on the current logic, objects of classes Item_func_charset and Item_func_coercibility (responsible for CHARSET() and COERCIBILITY() functions) are always considered constant. However, SQL syntax allows their use in a non-constant manner, such as CHARSET(t1.a), COERCIBILITY(t1.a). In these cases, the `used_tables()` parameter corresponds to table names in the function parameters, creating an inconsistency: the item is marked as constant but accesses tables. This leads to crashes when conditions with CHARSET()/COERCIBILITY() are pushed into derived tables. This commit addresses the issue by setting `used_tables()` to 0 for `Item_func_charset` and `Item_func_coercibility`. Additionally, the items now store the return values during the preparation phase and return them during the execution phase. This ensures that the items do not call its arguments methods during the execution and are truly constant. Reviewer: Alexander Barkov <bar@mariadb.com>
- Loading branch information
Showing
8 changed files
with
112 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# | ||
# MDEV-33010: Crash when pushing condition with CHARSET()/COERCIBILITY() | ||
# into derived table | ||
# | ||
CREATE TABLE t1 (c1 BIGINT, KEY (c1)) ENGINE=InnoDB; | ||
INSERT INTO t1 VALUES (1); | ||
CREATE TABLE t2 (c2 DOUBLE UNSIGNED); | ||
INSERT INTO t2 VALUES (1); | ||
SET optimizer_switch='derived_merge=off'; | ||
EXPLAIN EXTENDED | ||
SELECT dt1_c1 FROM | ||
(SELECT c1 AS dt1_c1 FROM t1) AS dt1 | ||
JOIN | ||
(SELECT 1 AS dt2_c2 FROM t2) AS dt2 | ||
ON CHARSET(dt2_c2) BETWEEN dt1_c1 AND dt1_c1; | ||
id select_type table type possible_keys key key_len ref rows filtered Extra | ||
1 PRIMARY <derived3> system NULL NULL NULL NULL 1 100.00 | ||
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00 Using where | ||
3 DERIVED t2 system NULL NULL NULL NULL 1 100.00 | ||
2 DERIVED t1 ref c1 c1 9 const 1 100.00 Using where; Using index | ||
Warnings: | ||
Warning 1292 Truncated incorrect DECIMAL value: 'binary' | ||
Note 1003 /* select#1 */ select `dt1`.`dt1_c1` AS `dt1_c1` from (/* select#2 */ select `test`.`t1`.`c1` AS `dt1_c1` from `test`.`t1` where <cache>(charset(1)) between `test`.`t1`.`c1` and `test`.`t1`.`c1`) `dt1` where <cache>(charset(1)) between `dt1`.`dt1_c1` and `dt1`.`dt1_c1` | ||
EXPLAIN EXTENDED | ||
SELECT dt1_c1 FROM | ||
(SELECT c1 AS dt1_c1 FROM t1) AS dt1 | ||
JOIN | ||
(SELECT 1 AS dt2_c2 FROM t2) AS dt2 | ||
ON COERCIBILITY(dt2_c2) BETWEEN dt1_c1 AND dt1_c1; | ||
id select_type table type possible_keys key key_len ref rows filtered Extra | ||
1 PRIMARY <derived3> system NULL NULL NULL NULL 1 100.00 | ||
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 100.00 Using where | ||
3 DERIVED t2 system NULL NULL NULL NULL 1 100.00 | ||
2 DERIVED t1 ref c1 c1 9 const 1 100.00 Using where; Using index | ||
Warnings: | ||
Note 1003 /* select#1 */ select `dt1`.`dt1_c1` AS `dt1_c1` from (/* select#2 */ select `test`.`t1`.`c1` AS `dt1_c1` from `test`.`t1` where <cache>(coercibility(1)) between `test`.`t1`.`c1` and `test`.`t1`.`c1`) `dt1` where <cache>(coercibility(1)) between `dt1`.`dt1_c1` and `dt1`.`dt1_c1` | ||
SET optimizer_switch=DEFAULT; | ||
DROP TABLE t1, t2; | ||
# End of 10.4 tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--source include/have_innodb.inc | ||
|
||
--echo # | ||
--echo # MDEV-33010: Crash when pushing condition with CHARSET()/COERCIBILITY() | ||
--echo # into derived table | ||
--echo # | ||
CREATE TABLE t1 (c1 BIGINT, KEY (c1)) ENGINE=InnoDB; | ||
INSERT INTO t1 VALUES (1); | ||
CREATE TABLE t2 (c2 DOUBLE UNSIGNED); | ||
INSERT INTO t2 VALUES (1); | ||
|
||
SET optimizer_switch='derived_merge=off'; | ||
|
||
EXPLAIN EXTENDED | ||
SELECT dt1_c1 FROM | ||
(SELECT c1 AS dt1_c1 FROM t1) AS dt1 | ||
JOIN | ||
(SELECT 1 AS dt2_c2 FROM t2) AS dt2 | ||
ON CHARSET(dt2_c2) BETWEEN dt1_c1 AND dt1_c1; | ||
|
||
EXPLAIN EXTENDED | ||
SELECT dt1_c1 FROM | ||
(SELECT c1 AS dt1_c1 FROM t1) AS dt1 | ||
JOIN | ||
(SELECT 1 AS dt2_c2 FROM t2) AS dt2 | ||
ON COERCIBILITY(dt2_c2) BETWEEN dt1_c1 AND dt1_c1; | ||
|
||
SET optimizer_switch=DEFAULT; | ||
DROP TABLE t1, t2; | ||
|
||
--echo # End of 10.4 tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters