midenok / mariadb

MariaDB server is a community developed fork of MySQL server. Started by core members of the original MySQL team, MariaDB actively works with outside developers to deliver the most featureful, stable, and sanely licensed open SQL server in the industry.
GNU General Public License v2.0
0 stars 0 forks source link

MDEV-21155 Server crashes in close_thread_tables, Assertion `file->s->temporary' failed, Assertion `!m_file' failed with versioned tables, views and PS protocol #64

Open midenok opened 5 years ago

midenok commented 5 years ago

Reproduce

create table t1 (a int);
create table t2 (b int) with system versioning;
create view v1 as select * from t1;
create view v2 as select * from v1;
create or replace view v1 as select * from t2;
delete from v2;

# cleanup
drop view v2;
drop view v1;
drop table t1, t2;

Result

#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007f2d2edd8535 in __GI_abort () at abort.c:79
#2  0x00007f2d2edd840f in __assert_fail_base (fmt=0x7f2d2ef66588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x16a0aba "m_lock_type == 2", file=0x169f2e0 "/home/midenok/src/mariadb/10.3/src/sql/handler.cc", line=4696, function=<optimized out>) at assert.c:92
#3  0x00007f2d2ede7fb2 in __GI___assert_fail (assertion=0x16a0aba "m_lock_type == 2", file=0x169f2e0 "/home/midenok/src/mariadb/10.3/src/sql/handler.cc", line=4696, function=0x16a0cef "void handler::ha_drop_table(const char *)") at assert.c:101
#4  0x0000000000b0e1fd in handler::ha_drop_table (this=0x7f2d10033590, name=0x7f2d10030118 "./test/t2") at /home/midenok/src/mariadb/10.3/src/sql/handler.cc:4696
#5  0x0000000000807192 in free_tmp_table (thd=0x7f2d10000ce8, entry=0x7f2d100325c8) at /home/midenok/src/mariadb/10.3/src/sql/sql_select.cc:18863
#6  0x0000000000737e2e in mysql_derived_prepare (thd=0x7f2d10000ce8, lex=0x7f2d10004ae0, derived=0x7f2d10013c88) at /home/midenok/src/mariadb/10.3/src/sql/sql_derived.cc:822
#7  0x000000000073a8f4 in mysql_handle_single_derived (lex=0x7f2d10004ae0, derived=0x7f2d10013c88, phases=2) at /home/midenok/src/mariadb/10.3/src/sql/sql_derived.cc:199
#8  0x00000000008f418f in TABLE_LIST::handle_derived (this=0x7f2d10013c88, lex=0x7f2d10004ae0, phases=2) at /home/midenok/src/mariadb/10.3/src/sql/table.cc:8287
#9  0x0000000000755a34 in LEX::handle_list_of_derived (this=0x7f2d10004ae0, table_list=0x7f2d10013c88, phases=2) at /home/midenok/src/mariadb/10.3/src/sql/sql_lex.h:4019
#10 0x0000000000d08e53 in mysql_delete (thd=0x7f2d10000ce8, table_list=0x7f2d10013c88, conds=0x0, order_list=0x7f2d100055a0, limit=18446744073709551615, options=0, result=0x0) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:304
#11 0x0000000000797b54 in mysql_execute_command (thd=0x7f2d10000ce8) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:4658
#12 0x000000000078ef60 in mysql_parse (thd=0x7f2d10000ce8, rawbuf=0x7f2d10013bc0 "delete from v2", length=14, parser_state=0x7f2d281385e8, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7818

Good

#0  mysql_derived_prepare (thd=0x7fcf7c000ce8, lex=0x7fcf7c004ae0, derived=0x7fcf7c015e50) at /home/midenok/src/mariadb/10.3/src/sql/sql_derived.cc:623
#1  0x00000000007655f4 in mysql_handle_single_derived (lex=0x7fcf7c004ae0, derived=0x7fcf7c015e50, phases=2) at /home/midenok/src/mariadb/10.3/src/sql/sql_derived.cc:199
#2  0x000000000091ee8f in TABLE_LIST::handle_derived (this=0x7fcf7c015e50, lex=0x7fcf7c004ae0, phases=2) at /home/midenok/src/mariadb/10.3/src/sql/table.cc:8287
#3  0x0000000000780734 in LEX::handle_list_of_derived (this=0x7fcf7c004ae0, table_list=0x7fcf7c015e50, phases=2) at /home/midenok/src/mariadb/10.3/src/sql/sql_lex.h:4019
#4  0x000000000078e34a in st_select_lex::handle_derived (this=0x7fcf7c014d78, lex=0x7fcf7c004ae0, phases=2) at /home/midenok/src/mariadb/10.3/src/sql/sql_lex.cc:4132
#5  0x000000000080e8e4 in JOIN::prepare (this=0x7fcf7c03b680, tables_init=0x7fcf7c015e50, wild_num=0, conds_init=0x0, og_num=0, order_init=0x0, skip_order_by=false, group_init=0x0, having_init=0x0, proc_param_init=0x0, select_lex_arg=0x7fcf7c014d78, unit_arg=0x7fcf7c0145f8) at /home/midenok/src/mariadb/10.3/src/sql/sql_select.cc:1032
#6  0x00000000008e9303 in st_select_lex_unit::prepare_join (this=0x7fcf7c0145f8, thd_arg=0x7fcf7c000ce8, sl=0x7fcf7c014d78, tmp_result=0x0, additional_options=0, is_union_select=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_union.cc:655
#7  0x00000000008e3eee in st_select_lex_unit::prepare (this=0x7fcf7c0145f8, derived_arg=0x7fcf7c013c88, sel_result=0x0, additional_options=0) at /home/midenok/src/mariadb/10.3/src/sql/sql_union.cc:981
#8  0x00000000007622af in mysql_derived_prepare (thd=0x7fcf7c000ce8, lex=0x7fcf7c004ae0, derived=0x7fcf7c013c88) at /home/midenok/src/mariadb/10.3/src/sql/sql_derived.cc:700
#9  0x00000000007655f4 in mysql_handle_single_derived (lex=0x7fcf7c004ae0, derived=0x7fcf7c013c88, phases=2) at /home/midenok/src/mariadb/10.3/src/sql/sql_derived.cc:199
#10 0x000000000091ee8f in TABLE_LIST::handle_derived (this=0x7fcf7c013c88, lex=0x7fcf7c004ae0, phases=2) at /home/midenok/src/mariadb/10.3/src/sql/table.cc:8287
#11 0x0000000000780734 in LEX::handle_list_of_derived (this=0x7fcf7c004ae0, table_list=0x7fcf7c013c88, phases=2) at /home/midenok/src/mariadb/10.3/src/sql/sql_lex.h:4019
#12 0x0000000000d338c3 in mysql_delete (thd=0x7fcf7c000ce8, table_list=0x7fcf7c013c88, conds=0x0, order_list=0x7fcf7c0055a0, limit=18446744073709551615, options=0, result=0x0) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:304
#13 0x00000000007c2854 in mysql_execute_command (thd=0x7fcf7c000ce8) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:4658
#14 0x00000000007b9c60 in mysql_parse (thd=0x7fcf7c000ce8, rawbuf=0x7fcf7c013bc0 "DELETE FROM v2", length=14, parser_state=0x7fcf8dc155e8, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7818
#0  Item_field::fix_outer_field (this=0x7fcf7c015cc0, thd=0x7fcf7c000ce8, from_field=0x7fcf8dc10a90, reference=0x7fcf7c015de8) at /home/midenok/src/mariadb/10.3/src/sql/item.cc:5715
#1  0x0000000000b5f6c1 in Item_field::fix_fields (this=0x7fcf7c015cc0, thd=0x7fcf7c000ce8, reference=0x7fcf7c015de8) at /home/midenok/src/mariadb/10.3/src/sql/item.cc:6156
#2  0x00000000006865e7 in Item::fix_fields_if_needed (this=0x7fcf7c015cc0, thd=0x7fcf7c000ce8, ref=0x7fcf7c015de8) at /home/midenok/src/mariadb/10.3/src/sql/item.h:823
#3  0x0000000000685a37 in Item::fix_fields_if_needed_for_scalar (this=0x7fcf7c015cc0, thd=0x7fcf7c000ce8, ref=0x7fcf7c015de8) at /home/midenok/src/mariadb/10.3/src/sql/item.h:827
#4  0x0000000000717c02 in setup_fields (thd=0x7fcf7c000ce8, ref_pointer_array=..., fields=..., column_usage=MARK_COLUMNS_READ, sum_func_list=0x7fcf7c03b9a0, pre_fix=0x7fcf7c014eb8, allow_sum_func=true) at /home/midenok/src/mariadb/10.3/src/sql/sql_base.cc:7456
#5  0x000000000080f01a in JOIN::prepare (this=0x7fcf7c03b680, tables_init=0x7fcf7c015e50, wild_num=0, conds_init=0x0, og_num=0, order_init=0x0, skip_order_by=false, group_init=0x0, having_init=0x0, proc_param_init=0x0, select_lex_arg=0x7fcf7c014d78, unit_arg=0x7fcf7c0145f8) at /home/midenok/src/mariadb/10.3/src/sql/sql_select.cc:1134
#6  0x00000000008e9303 in st_select_lex_unit::prepare_join (this=0x7fcf7c0145f8, thd_arg=0x7fcf7c000ce8, sl=0x7fcf7c014d78, tmp_result=0x0, additional_options=0, is_union_select=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_union.cc:655
#7  0x00000000008e3eee in st_select_lex_unit::prepare (this=0x7fcf7c0145f8, derived_arg=0x7fcf7c013c88, sel_result=0x0, additional_options=0) at /home/midenok/src/mariadb/10.3/src/sql/sql_union.cc:981
#8  0x00000000007622af in mysql_derived_prepare (thd=0x7fcf7c000ce8, lex=0x7fcf7c004ae0, derived=0x7fcf7c013c88) at /home/midenok/src/mariadb/10.3/src/sql/sql_derived.cc:700
#9  0x00000000007655f4 in mysql_handle_single_derived (lex=0x7fcf7c004ae0, derived=0x7fcf7c013c88, phases=2) at /home/midenok/src/mariadb/10.3/src/sql/sql_derived.cc:199
#10 0x000000000091ee8f in TABLE_LIST::handle_derived (this=0x7fcf7c013c88, lex=0x7fcf7c004ae0, phases=2) at /home/midenok/src/mariadb/10.3/src/sql/table.cc:8287
#11 0x0000000000780734 in LEX::handle_list_of_derived (this=0x7fcf7c004ae0, table_list=0x7fcf7c013c88, phases=2) at /home/midenok/src/mariadb/10.3/src/sql/sql_lex.h:4019
#12 0x0000000000d338c3 in mysql_delete (thd=0x7fcf7c000ce8, table_list=0x7fcf7c013c88, conds=0x0, order_list=0x7fcf7c0055a0, limit=18446744073709551615, options=0, result=0x0) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:304
#13 0x00000000007c2854 in mysql_execute_command (thd=0x7fcf7c000ce8) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:4658
#14 0x00000000007b9c60 in mysql_parse (thd=0x7fcf7c000ce8, rawbuf=0x7fcf7c013bc0 "DELETE FROM v2", length=14, parser_state=0x7fcf8dc155e8, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7818
midenok commented 5 years ago

Bad

#0  Item_field::fix_outer_field (this=0x7fcf7c015cc0, thd=0x7fcf7c000ce8, from_field=0x7fcf8dc10a90, reference=0x7fcf7c015de8) at /home/midenok/src/mariadb/10.3/src/sql/item.cc:5715
#1  0x0000000000b5f6c1 in Item_field::fix_fields (this=0x7fcf7c015cc0, thd=0x7fcf7c000ce8, reference=0x7fcf7c015de8) at /home/midenok/src/mariadb/10.3/src/sql/item.cc:6156
#2  0x00000000006865e7 in Item::fix_fields_if_needed (this=0x7fcf7c015cc0, thd=0x7fcf7c000ce8, ref=0x7fcf7c015de8) at /home/midenok/src/mariadb/10.3/src/sql/item.h:823
#3  0x0000000000685a37 in Item::fix_fields_if_needed_for_scalar (this=0x7fcf7c015cc0, thd=0x7fcf7c000ce8, ref=0x7fcf7c015de8) at /home/midenok/src/mariadb/10.3/src/sql/item.h:827
#4  0x0000000000717c02 in setup_fields (thd=0x7fcf7c000ce8, ref_pointer_array=..., fields=..., column_usage=MARK_COLUMNS_READ, sum_func_list=0x7fcf7c03b9a0, pre_fix=0x7fcf7c014eb8, allow_sum_func=true) at /home/midenok/src/mariadb/10.3/src/sql/sql_base.cc:7456
#5  0x000000000080f01a in JOIN::prepare (this=0x7fcf7c03b680, tables_init=0x7fcf7c015e50, wild_num=0, conds_init=0x0, og_num=0, order_init=0x0, skip_order_by=false, group_init=0x0, having_init=0x0, proc_param_init=0x0, select_lex_arg=0x7fcf7c014d78, unit_arg=0x7fcf7c0145f8) at /home/midenok/src/mariadb/10.3/src/sql/sql_select.cc:1134
#6  0x00000000008e9303 in st_select_lex_unit::prepare_join (this=0x7fcf7c0145f8, thd_arg=0x7fcf7c000ce8, sl=0x7fcf7c014d78, tmp_result=0x0, additional_options=0, is_union_select=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_union.cc:655
#7  0x00000000008e3eee in st_select_lex_unit::prepare (this=0x7fcf7c0145f8, derived_arg=0x7fcf7c013c88, sel_result=0x0, additional_options=0) at /home/midenok/src/mariadb/10.3/src/sql/sql_union.cc:981
#8  0x00000000007622af in mysql_derived_prepare (thd=0x7fcf7c000ce8, lex=0x7fcf7c004ae0, derived=0x7fcf7c013c88) at /home/midenok/src/mariadb/10.3/src/sql/sql_derived.cc:700
#9  0x00000000007655f4 in mysql_handle_single_derived (lex=0x7fcf7c004ae0, derived=0x7fcf7c013c88, phases=2) at /home/midenok/src/mariadb/10.3/src/sql/sql_derived.cc:199
#10 0x000000000091ee8f in TABLE_LIST::handle_derived (this=0x7fcf7c013c88, lex=0x7fcf7c004ae0, phases=2) at /home/midenok/src/mariadb/10.3/src/sql/table.cc:8287
#11 0x0000000000780734 in LEX::handle_list_of_derived (this=0x7fcf7c004ae0, table_list=0x7fcf7c013c88, phases=2) at /home/midenok/src/mariadb/10.3/src/sql/sql_lex.h:4019
#12 0x0000000000d338c3 in mysql_delete (thd=0x7fcf7c000ce8, table_list=0x7fcf7c013c88, conds=0x0, order_list=0x7fcf7c0055a0, limit=18446744073709551615, options=0, result=0x0) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:304
#13 0x00000000007c2854 in mysql_execute_command (thd=0x7fcf7c000ce8) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:4658
#14 0x00000000007b9c60 in mysql_parse (thd=0x7fcf7c000ce8, rawbuf=0x7fcf7c013bc0 "DELETE FROM v2", length=14, parser_state=0x7fcf8dc155e8, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7818
(rr) pitem this
$18 = 0x1e8d600 <dbug_item_print_buf> "v1.a"

#8 0x00000000007622af in mysql_derived_prepare

(rr) p dbug_print_select((st_select_lex *)derived->view.unit.slave)
$10 = 0x1e49400 <dbug_item_print_buf> "select v1.a AS a from test.v1"

Cause

Wrong field from t1. derived->view.unit has stale SELECT.

midenok commented 5 years ago

derived->view inited

#0  mysql_make_view (thd=0x7f25cc000ce8, share=0x7f25cc037eb0, table=0x7f25cc013c88, open_view_no_parse=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_view.cc:1391
#1  0x00000000006df090 in open_table (thd=0x7f25cc000ce8, table_list=0x7f25cc013c88, ot_ctx=0x7f25e2d7cab8) at /home/midenok/src/mariadb/10.3/src/sql/sql_base.cc:1897
#2  0x00000000006e3db5 in open_and_process_table (thd=0x7f25cc000ce8, tables=0x7f25cc013c88, counter=0x7f25e2d7cbbc, flags=0, prelocking_strategy=0x7f25e2d7cc30, has_prelocking_list=false, ot_ctx=0x7f25e2d7cab8) at /home/midenok/src/mariadb/10.3/src/sql/sql_base.cc:3675
#3  0x00000000006e278d in open_tables (thd=0x7f25cc000ce8, options=..., start=0x7f25e2d7cbd0, counter=0x7f25e2d7cbbc, flags=0, prelocking_strategy=0x7f25e2d7cc30) at /home/midenok/src/mariadb/10.3/src/sql/sql_base.cc:4144
#4  0x00000000006e7205 in open_and_lock_tables (thd=0x7f25cc000ce8, options=..., tables=0x7f25cc013c88, derived=true, flags=0, prelocking_strategy=0x7f25e2d7cc30) at /home/midenok/src/mariadb/10.3/src/sql/sql_base.cc:5032
#5  0x00000000006939dc in open_and_lock_tables (thd=0x7f25cc000ce8, tables=0x7f25cc013c88, derived=true, flags=0) at /home/midenok/src/mariadb/10.3/src/sql/sql_base.h:503
#6  0x0000000000d08d41 in mysql_delete (thd=0x7f25cc000ce8, table_list=0x7f25cc013c88, conds=0x0, order_list=0x7f25cc0055a0, limit=18446744073709551615, options=0, result=0x0) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:295
#7  0x0000000000797b54 in mysql_execute_command (thd=0x7f25cc000ce8) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:4658
#8  0x000000000078ef60 in mysql_parse (thd=0x7f25cc000ce8, rawbuf=0x7f25cc013bc0 "delete from v2", length=14, parser_state=0x7f25e2d805e8, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7818
p table->select_stmt.str
$19 = 0x7f25cc014450 "select `v1`.`a` AS `a` from `test`.`v1`"

Notes

v2 has wrong fields, but this is ok. The problem is that v1 is processed and then v2 is processed and both try to get versioning conditions as they both point to t2. v1 is processed correctly, but v2 should not be processed: versioning conditions already acquired.

midenok commented 5 years ago

Info

Update versioning conditions via mysql_derived_prepare() is needed for this case:

create or replace table t1 (x int) with system versioning;
insert into t1 values (1), (2);
create or replace view v1 as select * from t1 where x > 1;
update v1 set x= x + 1;

create or replace database test;

REPLACE works just fine without it.