Skip to content

Commit 0292609

Browse files
author
Sergey Glukhov
committed
Bug#22186926: CONVERT_CONSTANT_ITEM(THD*, ITEM_FIELD*, ITEM**): ASSERTION `!RESULT' FAILED.
Problem statement uses MAX/MIN optimization in opt_sum_query. Index access is used to check if optmization is possible and datetime column is not present in the index. So datetime field is unread after optmization. In convert_constant_item() incorrect value is obtained from the field since field is not evaluated. Attempt to store this incorrect value to the field later leads to assert failure.
1 parent 8fbb2bc commit 0292609

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

mysql-test/r/group_by.result

+26
Original file line numberDiff line numberDiff line change
@@ -3247,3 +3247,29 @@ WHERE b.b = c.b
32473247
GROUP BY c.c;
32483248
ERROR 42000: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.a.b' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
32493249
DROP TABLE t1;
3250+
#
3251+
# Bug #22186926 CONVERT_CONSTANT_ITEM(THD*, ITEM_FIELD*, ITEM**): ASSERTION `!RESULT' FAILED.
3252+
#
3253+
CREATE TABLE t1
3254+
(
3255+
f1 INTEGER NOT NULL,
3256+
f2 DATETIME NOT NULL,
3257+
f3 VARCHAR(1) NOT NULL,
3258+
KEY (f3)
3259+
);
3260+
INSERT INTO t1(f1, f2, f3) VALUES
3261+
(5, '2001-07-25 08:40:24.058646', 'j'),
3262+
(2, '1900-01-01 00:00:00', 's'),
3263+
(4, '2001-01-20 12:47:23.022022', 'x');
3264+
CREATE TABLE t2 (f1 VARCHAR(1) NOT NULL);
3265+
FLUSH TABLES;
3266+
EXPLAIN SELECT MIN(t1.f3 ) FROM t1
3267+
WHERE t1.f3 IN (SELECT t2.f1 FROM t2 WHERE NOT t1.f2 IS NOT NULL) AND t1.f1 IS NULL OR
3268+
NOT t1 . f3 < 'q';
3269+
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
3270+
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
3271+
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table
3272+
Warnings:
3273+
Note 1276 Field or reference 'test.t1.f2' of SELECT #2 was resolved in SELECT #1
3274+
Note 1003 /* select#1 */ select min(`test`.`t1`.`f3`) AS `MIN(t1.f3 )` from `test`.`t1` where (`test`.`t1`.`f3` >= 'q')
3275+
DROP TABLE t1,t2;

mysql-test/t/group_by.test

+28
Original file line numberDiff line numberDiff line change
@@ -2435,3 +2435,31 @@ GROUP BY c.c;
24352435

24362436
DROP TABLE t1;
24372437

2438+
--echo #
2439+
--echo # Bug #22186926 CONVERT_CONSTANT_ITEM(THD*, ITEM_FIELD*, ITEM**): ASSERTION `!RESULT' FAILED.
2440+
--echo #
2441+
2442+
CREATE TABLE t1
2443+
(
2444+
f1 INTEGER NOT NULL,
2445+
f2 DATETIME NOT NULL,
2446+
f3 VARCHAR(1) NOT NULL,
2447+
KEY (f3)
2448+
);
2449+
2450+
INSERT INTO t1(f1, f2, f3) VALUES
2451+
(5, '2001-07-25 08:40:24.058646', 'j'),
2452+
(2, '1900-01-01 00:00:00', 's'),
2453+
(4, '2001-01-20 12:47:23.022022', 'x');
2454+
2455+
2456+
CREATE TABLE t2 (f1 VARCHAR(1) NOT NULL);
2457+
2458+
FLUSH TABLES;
2459+
2460+
EXPLAIN SELECT MIN(t1.f3 ) FROM t1
2461+
WHERE t1.f3 IN (SELECT t2.f1 FROM t2 WHERE NOT t1.f2 IS NOT NULL) AND t1.f1 IS NULL OR
2462+
NOT t1 . f3 < 'q';
2463+
2464+
2465+
DROP TABLE t1,t2;

sql/opt_sum.cc

+8
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,14 @@ int opt_sum_query(THD *thd,
451451
get_index_min_value(table, &ref, item_field, range_fl,
452452
prefix_len);
453453

454+
/*
455+
Set TABLE::status to STATUS_GARBAGE since original and
456+
real read_set are different, i.e. some field values
457+
from original read set could be unread.
458+
*/
459+
if (!bitmap_is_subset(&table->def_read_set, &table->tmp_set))
460+
table->status|= STATUS_GARBAGE;
461+
454462
table->read_set= &table->def_read_set;
455463
bitmap_clear_all(&table->tmp_set);
456464
/* Verify that the read tuple indeed matches the search key */

0 commit comments

Comments
 (0)