[MDEV-9619] Assertion `null_ref_table' failed in virtual table_map Item_direct_view_ref::used_tables() const on 2nd execution of PS Created: 2016-02-23  Updated: 2017-10-13  Resolved: 2017-10-13

Status: Closed
Project: MariaDB Server
Component/s: Optimizer, Prepared Statements
Affects Version/s: 5.5.43, 5.5, 10.0, 10.1, 10.2
Fix Version/s: 5.5.58, 10.0.33, 10.1.29, 10.2.10

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Oleksandr Byelkin
Resolution: Fixed Votes: 0
Labels: None

Sprint: 5.5.55, 5.5.58

 Description   

CREATE TABLE t1 (f1 VARCHAR(10)) ENGINE=MyISAM;
CREATE ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1;
INSERT INTO t1 VALUES ('a'),('b');
 
CREATE TABLE t2 (f2 VARCHAR(10)) ENGINE=MyISAM;
INSERT INTO t2 VALUES ('c'),('d');
 
PREPARE stmt FROM "SELECT * FROM v1 WHERE f1 = SOME ( SELECT f2 FROM t2 )";
EXECUTE stmt;
EXECUTE stmt;

Stack trace from 5.5 commit ceba41c0951d1d8c9b4961772b4a088769814a66

mysqld: /src/5.5/sql/item.cc:9873: virtual table_map Item_direct_view_ref::used_tables() const: Assertion `null_ref_table' failed.
160223 23:53:41 [ERROR] mysqld got signal 6 ;
 
#7  0x00007fa6ed15b1d2 in __assert_fail () from /lib64/libc.so.6
#8  0x00000000007fbd04 in Item_direct_view_ref::used_tables (this=0x7fa6e87acd38) at /src/5.5/sql/item.cc:9873
#9  0x00000000007638a3 in get_bound_sj_equalities (sj_nest=0x7fa6e87acec0, remaining_tables=3) at /src/5.5/sql/opt_subselect.cc:3196
#10 0x00000000006917d3 in Loose_scan_opt::init (this=0x7fa6eeba93c0, join=0x7fa6e87c63b0, s=0x7fa6e87c7830, remaining_tables=3) at /src/5.5/sql/opt_subselect.h:133
#11 0x000000000065fe10 in best_access_path (join=0x7fa6e87c63b0, s=0x7fa6e87c7830, remaining_tables=3, idx=0, disable_jbuf=true, record_count=1, pos=0x7fa6e87c7d78, loose_scan_pos=0x7fa6eeba95a0) at /src/5.5/sql/sql_select.cc:5435
#12 0x00000000006637c8 in best_extension_by_limited_search (join=0x7fa6e87c63b0, remaining_tables=3, idx=0, record_count=1, read_time=0, search_depth=62, prune_level=1) at /src/5.5/sql/sql_select.cc:7029
#13 0x0000000000662b73 in greedy_search (join=0x7fa6e87c63b0, remaining_tables=3, search_depth=62, prune_level=1) at /src/5.5/sql/sql_select.cc:6620
#14 0x0000000000662209 in choose_plan (join=0x7fa6e87c63b0, join_tables=3) at /src/5.5/sql/sql_select.cc:6207
#15 0x000000000065bc83 in make_join_statistics (join=0x7fa6e87c63b0, tables_list=..., conds=0x7fa6e87c7280, keyuse_array=0x7fa6e87c66c8) at /src/5.5/sql/sql_select.cc:3800
#16 0x0000000000652be0 in JOIN::optimize (this=0x7fa6e87c63b0) at /src/5.5/sql/sql_select.cc:1229
#17 0x00000000006595a0 in mysql_select (thd=0x7fa6eb7c3a20, rref_pointer_array=0x7fa6e87c9280, tables=0x7fa6e87c9dc8, wild_num=0, fields=..., conds=0x7fa6e87c61a8, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2416184064, result=0x7fa6e87aa040, unit=0x7fa6e87c8930, select_lex=0x7fa6e87c9010) at /src/5.5/sql/sql_select.cc:3080
#18 0x000000000064fed1 in handle_select (thd=0x7fa6eb7c3a20, lex=0x7fa6e87c8880, result=0x7fa6e87aa040, setup_tables_done_option=0) at /src/5.5/sql/sql_select.cc:319
#19 0x0000000000629364 in execute_sqlcom_select (thd=0x7fa6eb7c3a20, all_tables=0x7fa6e87c9dc8) at /src/5.5/sql/sql_parse.cc:4689
#20 0x0000000000622697 in mysql_execute_command (thd=0x7fa6eb7c3a20) at /src/5.5/sql/sql_parse.cc:2234
#21 0x00000000006435be in Prepared_statement::execute (this=0x7fa6e87b3060, expanded_query=0x7fa6eebaad00, open_cursor=false) at /src/5.5/sql/sql_prepare.cc:3930
#22 0x00000000006426fb in Prepared_statement::execute_loop (this=0x7fa6e87b3060, expanded_query=0x7fa6eebaad00, open_cursor=false, packet=0x0, packet_end=0x0) at /src/5.5/sql/sql_prepare.cc:3589
#23 0x0000000000640833 in mysql_sql_stmt_execute (thd=0x7fa6eb7c3a20) at /src/5.5/sql/sql_prepare.cc:2738
#24 0x00000000006226c5 in mysql_execute_command (thd=0x7fa6eb7c3a20) at /src/5.5/sql/sql_parse.cc:2244
#25 0x000000000062be44 in mysql_parse (thd=0x7fa6eb7c3a20, rawbuf=0x7fa6e87c6078 "EXECUTE stmt", length=12, parser_state=0x7fa6eebab650) at /src/5.5/sql/sql_parse.cc:5914
#26 0x000000000061fc36 in dispatch_command (command=COM_QUERY, thd=0x7fa6eb7c3a20, packet=0x7fa6e8d4f361 "EXECUTE stmt", packet_length=12) at /src/5.5/sql/sql_parse.cc:1079
#27 0x000000000061edc9 in do_command (thd=0x7fa6eb7c3a20) at /src/5.5/sql/sql_parse.cc:793
#28 0x000000000072185f in do_handle_one_connection (thd_arg=0x7fa6eb7c3a20) at /src/5.5/sql/sql_connect.cc:1269
#29 0x00000000007215ec in handle_one_connection (arg=0x7fa6eb7c3a20) at /src/5.5/sql/sql_connect.cc:1185
#30 0x0000000000c8b271 in pfs_spawn_thread (arg=0x7fa6eb7f3140) at /src/5.5/storage/perfschema/pfs.cc:1015
#31 0x00007fa6ee8230a4 in start_thread () from /lib64/libpthread.so.0
#32 0x00007fa6ed21204d in clone () from /lib64/libc.so.6

The problem appeared in 5.5 tree with this revision:

commit 54b998173b128bb8362b5dbafbd66c4199776937
Author: Oleksandr Byelkin <sanja@mariadb.com>
Date:   Thu Apr 23 20:08:57 2015 +0200
 
    MDEV-7846: Server crashes in Item_subselect::fix_fields or fails with Thread stack overrun
    
    Substitute into transformed subselects original left expression and than register its change in case it was substituted.



 Comments   
Comment by Oleksandr Byelkin [ 2017-02-16 ]

It looks like f1 lost its NULL reference table

Comment by Oleksandr Byelkin [ 2017-02-16 ]

f1 was never inner table of outer JOIN so it does not need NULL table reference

Comment by Oleksandr Byelkin [ 2017-02-16 ]

So it must (and was) set to 0x1 (NO_NULL_TABLE) but somehow was reset.

Comment by Oleksandr Byelkin [ 2017-02-16 ]

the field was cleaned up, but fix_field() was not called for it again.

Comment by Oleksandr Byelkin [ 2017-02-16 ]

It looks like saving old link on Item when other already allocated

Comment by Oleksandr Byelkin [ 2017-02-16 ]

The link on the old item stuck in sj_outer_expr_list

Comment by Oleksandr Byelkin [ 2017-02-16 ]

Need to discuss sj_outer_expr_list & convert_subq_to_sj() with psergey

Comment by Oleksandr Byelkin [ 2017-02-18 ]

revision-id: e0a1e632e4e6084cd989f217943618f4e9ac9179 (mariadb-5.5.54-25-ge0a1e63)
parent(s): 29d78dbb44ee9890b6bc28873344f20fc9157928
committer: Oleksandr Byelkin
timestamp: 2017-02-18 17:47:31 +0100
message:

MDEV-9619: Assertion `null_ref_table' failed in virtual table_map Item_direct_view_ref::used_tables() const on 2nd execution of PS

Refer left expression indirectly in case it changes from execution to execution.

Comment by Oleksandr Byelkin [ 2017-02-18 ]

bb-5.5-MDEV-9619 on github

Comment by Oleksandr Byelkin [ 2017-02-22 ]

revision-id: ffa50282e2ba147019e77972ae14972d77a0354b (mariadb-5.5.54-30-gffa5028)
parent(s): 5ddfcb05ca98a62b01da1c8b939e5303f900a5cc
committer: Oleksandr Byelkin
timestamp: 2017-02-22 14:17:27 +0100
message:

MDEV-9619: Assertion `null_ref_table' failed in virtual table_map Item_direct_view_ref::used_tables() const on 2nd execution of PS

Refer left expression indirectly in case it changes from execution to execution.

Comment by Oleksandr Byelkin [ 2017-02-27 ]

revision-id: 144b1552d2c3dced53d8e111e213117861ff8b95 (mariadb-5.5.54-38-g144b155)
parent(s): ac78927aefa2bd0d869d999839480d69086a9882
committer: Oleksandr Byelkin
timestamp: 2017-02-27 12:37:32 +0100
message:

MDEV-9619: Assertion `null_ref_table' failed in virtual table_map Item_direct_view_ref::used_tables() const on 2nd execution of PS

Refer left expression indirectly in case it changes from execution to execution.

Comment by Elena Stepanova [ 2017-09-03 ]

10.3 is also affected.

Generated at Thu Feb 08 07:36:03 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.