Skip to content

Commit cff6879

Browse files
mariadb-OlegSmirnovOlernov
authored andcommitted
MDEV-30721: Assertion `fixed()' failed in Item_cond_and::val_bool()
When processing a degenerate JTBM semi-join (a subquery that produces 0 or 1 rows), `execute_degenerate_jtbm_semi_join()` creates equality conditions and adds them to `eq_list`. These equalities are then merged with existing conditions via `and_new_conditions_to_optimized_cond()`, creating an `Item_cond_and`. When multiple conditions need to be combined, a new `Item_cond_and` is created and populated. However, this item was not fixed before being walked by the `is_simplified_cond_processor`, which calls `val_bool()` to check if the condition is a known constant. Calling `val_bool()` on an unfixed item triggers the assertion. Solution: Fix the newly created `Item_cond_and` immediately after it's populated ensuring it's ready for any subsequent operations including evaluation.
1 parent 57629c2 commit cff6879

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

mysql-test/main/subselect_mat.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,6 +2744,17 @@ ORDER BY l_orderkey, l_linenumber;
27442744
l_orderkey l_linenumber l_quantity
27452745
DROP TABLE t1;
27462746
# end of 10.6 tests
2747+
#
2748+
# MDEV-30721: Assertion `fixed()' failed in Item_cond_and::val_bool()
2749+
# with degenerate JTBM semi-join
2750+
#
2751+
CREATE TABLE t1 (c INT KEY);
2752+
INSERT INTO t1 (c) VALUES (0);
2753+
SELECT * FROM t1 WHERE (0,0) IN (SELECT MAX(c),MIN(c) FROM t1);
2754+
c
2755+
0
2756+
DROP TABLE t1;
2757+
# end of 10.11 tests
27472758
set @subselect_mat_test_optimizer_switch_value=null;
27482759
set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off';
27492760
set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on';

mysql-test/main/subselect_sj_mat.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,3 +2786,14 @@ ORDER BY l_orderkey, l_linenumber;
27862786
l_orderkey l_linenumber l_quantity
27872787
DROP TABLE t1;
27882788
# end of 10.6 tests
2789+
#
2790+
# MDEV-30721: Assertion `fixed()' failed in Item_cond_and::val_bool()
2791+
# with degenerate JTBM semi-join
2792+
#
2793+
CREATE TABLE t1 (c INT KEY);
2794+
INSERT INTO t1 (c) VALUES (0);
2795+
SELECT * FROM t1 WHERE (0,0) IN (SELECT MAX(c),MIN(c) FROM t1);
2796+
c
2797+
0
2798+
DROP TABLE t1;
2799+
# end of 10.11 tests

mysql-test/main/subselect_sj_mat.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,3 +2456,20 @@ ORDER BY l_orderkey, l_linenumber;
24562456
DROP TABLE t1;
24572457

24582458
--echo # end of 10.6 tests
2459+
2460+
--echo #
2461+
--echo # MDEV-30721: Assertion `fixed()' failed in Item_cond_and::val_bool()
2462+
--echo # with degenerate JTBM semi-join
2463+
--echo #
2464+
2465+
CREATE TABLE t1 (c INT KEY);
2466+
INSERT INTO t1 (c) VALUES (0);
2467+
2468+
# This query triggered an assertion because the Item_cond_and created
2469+
# during condition merging in and_new_conditions_to_optimized_cond()
2470+
# was evaluated before being fixed.
2471+
SELECT * FROM t1 WHERE (0,0) IN (SELECT MAX(c),MIN(c) FROM t1);
2472+
2473+
DROP TABLE t1;
2474+
2475+
--echo # end of 10.11 tests

sql/opt_subselect.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6138,7 +6138,7 @@ Item *and_new_conditions_to_optimized_cond(THD *thd, Item *cond,
61386138
}
61396139
}
61406140

6141-
if (!cond)
6141+
if (!cond || cond->fix_fields_if_needed(thd, &cond))
61426142
return NULL;
61436143

61446144
if (*cond_eq)
@@ -6171,9 +6171,6 @@ Item *and_new_conditions_to_optimized_cond(THD *thd, Item *cond,
61716171
if (cond && is_simplified_cond)
61726172
cond= cond->remove_eq_conds(thd, cond_value, true);
61736173

6174-
if (cond && cond->fix_fields_if_needed(thd, NULL))
6175-
return NULL;
6176-
61776174
return cond;
61786175
}
61796176

0 commit comments

Comments
 (0)