mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
972879f413
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>
39 lines
1.9 KiB
Text
39 lines
1.9 KiB
Text
#
|
|
# 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
|