Skip to content

Commit 397f5cf

Browse files
committed
MDEV-27238: Assertion `got_name == named_item_expected()' failed in Json_writer
make_join_select() calls const_cond->val_int(). There are edge cases where const_cond may have a not-yet optimized subquery. (The subquery will have used_tables() covered by join->const_tables. It will still have const_item()==false, so other parts of the optimizer will not try to evaluate it. We should probably mark such subqueries as constant but that is outside the scope of this MDEV)
1 parent 0165a06 commit 397f5cf

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

mysql-test/main/opt_trace.result

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,8 @@ select t1.a from t1 left join t2 on t1.a=t2.a {
23932393
"best_join_order": ["t2", "t1"]
23942394
},
23952395
{
2396-
"condition_on_constant_tables": "1"
2396+
"condition_on_constant_tables": "1",
2397+
"computing_condition": []
23972398
},
23982399
{
23992400
"attaching_conditions_to_tables": {
@@ -2550,7 +2551,8 @@ explain select * from t1 left join t2 on t2.a=t1.a {
25502551
"best_join_order": ["t1", "t2"]
25512552
},
25522553
{
2553-
"condition_on_constant_tables": "1"
2554+
"condition_on_constant_tables": "1",
2555+
"computing_condition": []
25542556
},
25552557
{
25562558
"attaching_conditions_to_tables": {
@@ -2708,7 +2710,8 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and
27082710
"best_join_order": ["t3", "t2", "t1"]
27092711
},
27102712
{
2711-
"condition_on_constant_tables": "1"
2713+
"condition_on_constant_tables": "1",
2714+
"computing_condition": []
27122715
},
27132716
{
27142717
"attaching_conditions_to_tables": {
@@ -3021,7 +3024,8 @@ explain extended select * from t1 where a in (select pk from t10) {
30213024
"best_join_order": ["t1", "<subquery2>"]
30223025
},
30233026
{
3024-
"condition_on_constant_tables": "1"
3027+
"condition_on_constant_tables": "1",
3028+
"computing_condition": []
30253029
},
30263030
{
30273031
"attaching_conditions_to_tables": {
@@ -4719,7 +4723,8 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_
47194723
"best_join_order": ["t1", "<subquery2>"]
47204724
},
47214725
{
4722-
"condition_on_constant_tables": "1"
4726+
"condition_on_constant_tables": "1",
4727+
"computing_condition": []
47234728
},
47244729
{
47254730
"attaching_conditions_to_tables": {
@@ -7365,7 +7370,8 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) {
73657370
]
73667371
},
73677372
{
7368-
"condition_on_constant_tables": "1"
7373+
"condition_on_constant_tables": "1",
7374+
"computing_condition": []
73697375
},
73707376
{
73717377
"attaching_conditions_to_tables": {
@@ -8632,5 +8638,14 @@ SELECT 'a\0' LIMIT 0 {
86328638
}
86338639
SET optimizer_trace=DEFAULT;
86348640
#
8641+
# MDEV-27238: Assertion `got_name == named_item_expected()' failed in Json_writer::on_start_object
8642+
#
8643+
CREATE TABLE t1 (a INT KEY,b INT,KEY(b)) ENGINE=MEMORY;
8644+
SET optimizer_trace=1;
8645+
INSERT INTO t1 VALUES (0,0);
8646+
SELECT a FROM t1 WHERE (a,b) in (SELECT @c,@d);
8647+
a
8648+
DROP TABLE t1;
8649+
#
86358650
# End of 10.4 tests
86368651
#

mysql-test/main/opt_trace.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,16 @@ SELECT 'a\0' LIMIT 0;
643643
SELECT query, trace FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;
644644
SET optimizer_trace=DEFAULT;
645645

646+
--echo #
647+
--echo # MDEV-27238: Assertion `got_name == named_item_expected()' failed in Json_writer::on_start_object
648+
--echo #
649+
650+
CREATE TABLE t1 (a INT KEY,b INT,KEY(b)) ENGINE=MEMORY;
651+
SET optimizer_trace=1;
652+
INSERT INTO t1 VALUES (0,0);
653+
SELECT a FROM t1 WHERE (a,b) in (SELECT @c,@d);
654+
DROP TABLE t1;
655+
646656
--echo #
647657
--echo # End of 10.4 tests
648658
--echo #

sql/sql_select.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11409,7 +11409,11 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
1140911409
}
1141011410
else
1141111411
{
11412-
const bool const_cond_result = const_cond->val_int() != 0;
11412+
bool const_cond_result;
11413+
{
11414+
Json_writer_array a(thd, "computing_condition");
11415+
const_cond_result= const_cond->val_int() != 0;
11416+
}
1141311417
if (!const_cond_result)
1141411418
{
1141511419
DBUG_PRINT("info",("Found impossible WHERE condition"));

0 commit comments

Comments
 (0)