Skip to content

Commit 6ecf6d8

Browse files
committed
MDEV-7827: Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed in Field_long::val_str on EXPLAIN EXTENDED
(Solution by Sergei Petrunia) It appeared that semijoin conditions was not iterated when we were updating used tables. So now they do.
1 parent 9f3b53f commit 6ecf6d8

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

mysql-test/r/derived.result

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,3 +580,28 @@ select x.id, message from (select id from t1) x left join
580580
where coalesce(message,0) <> 0;
581581
id message
582582
drop table t1,t2;
583+
#
584+
# MDEV-7827: Assertion `!table || (!table->read_set ||
585+
# bitmap_is_set(table->read_set, field_index))' failed
586+
# in Field_long::val_str on EXPLAIN EXTENDED
587+
#
588+
CREATE TABLE t1 (f1 INT, f2 INT, KEY(f2)) ENGINE=MyISAM;
589+
INSERT INTO t1 VALUES (6,9);
590+
CREATE TABLE t2 (f3 INT) ENGINE=MyISAM;
591+
INSERT INTO t2 VALUES (2),(0);
592+
EXPLAIN EXTENDED
593+
SELECT f1 FROM ( SELECT * FROM t1 ) AS sq
594+
WHERE f1 IN (
595+
SELECT f3 FROM t2 WHERE f2 IN (
596+
SELECT f3 FROM t2 HAVING f3 >= 8
597+
)
598+
);
599+
id select_type table type possible_keys key key_len ref rows filtered Extra
600+
1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00
601+
1 PRIMARY <subquery4> eq_ref distinct_key distinct_key 4 test.t1.f2 1 100.00
602+
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(<subquery4>); Using join buffer (flat, BNL join)
603+
4 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00
604+
Warnings:
605+
Note 1276 Field or reference 'f2' of SELECT #3 was resolved in SELECT #1
606+
Note 1003 select 6 AS `f1` from <materialize> (select `test`.`t2`.`f3` from `test`.`t2` having (`test`.`t2`.`f3` >= 8)) semi join (`test`.`t2`) where ((`test`.`t2`.`f3` = 6) and (9 = `<subquery4>`.`f3`))
607+
DROP TABLE t2,t1;

mysql-test/t/derived.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,3 +506,25 @@ select x.id, message from (select id from t1) x left join
506506
(select id, 1 as message from t2) y on x.id=y.id
507507
where coalesce(message,0) <> 0;
508508
drop table t1,t2;
509+
510+
--echo #
511+
--echo # MDEV-7827: Assertion `!table || (!table->read_set ||
512+
--echo # bitmap_is_set(table->read_set, field_index))' failed
513+
--echo # in Field_long::val_str on EXPLAIN EXTENDED
514+
--echo #
515+
516+
CREATE TABLE t1 (f1 INT, f2 INT, KEY(f2)) ENGINE=MyISAM;
517+
INSERT INTO t1 VALUES (6,9);
518+
519+
CREATE TABLE t2 (f3 INT) ENGINE=MyISAM;
520+
INSERT INTO t2 VALUES (2),(0);
521+
522+
EXPLAIN EXTENDED
523+
SELECT f1 FROM ( SELECT * FROM t1 ) AS sq
524+
WHERE f1 IN (
525+
SELECT f3 FROM t2 WHERE f2 IN (
526+
SELECT f3 FROM t2 HAVING f3 >= 8
527+
)
528+
);
529+
530+
DROP TABLE t2,t1;

sql/sql_lex.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3866,6 +3866,19 @@ void SELECT_LEX::update_used_tables()
38663866
tl->on_expr->update_used_tables();
38673867
tl->on_expr->walk(&Item::eval_not_null_tables, 0, NULL);
38683868
}
3869+
/*
3870+
- There is no need to check sj_on_expr, because merged semi-joins inject
3871+
sj_on_expr into the parent's WHERE clase.
3872+
- For non-merged semi-joins (aka JTBMs), we need to check their
3873+
left_expr. There is no need to check the rest of the subselect, we know
3874+
it is uncorrelated and so cannot refer to any tables in this select.
3875+
*/
3876+
if (tl->jtbm_subselect)
3877+
{
3878+
Item *left_expr= tl->jtbm_subselect->left_expr;
3879+
left_expr->walk(&Item::update_table_bitmaps_processor, FALSE, NULL);
3880+
}
3881+
38693882
embedding= tl->embedding;
38703883
while (embedding)
38713884
{

0 commit comments

Comments
 (0)