[MDEV-5740] Assertion `!derived->first_select()->exclude_from_table_unique_test || derived->outer_select()-> exclude_from_table_unique_test' failed on 2nd execution of PS with derived_merge Created: 2014-02-26  Updated: 2014-03-11  Resolved: 2014-03-11

Status: Closed
Project: MariaDB Server
Component/s: None
Affects Version/s: 5.3.12, 5.5.36, 10.0.8
Fix Version/s: 5.5.37, 10.0.10, 5.3.13

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

Issue Links:
Relates

 Description   

SET optimizer_switch = 'derived_merge=on';
 
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (1),(2);
 
PREPARE stmt FROM '
  INSERT INTO t1 SELECT * FROM t2 UNION SELECT * FROM (SELECT * FROM t1) AS sq  
';
EXECUTE stmt;
EXECUTE stmt;

mysqld: table.cc:4438: void TABLE_LIST::set_check_merged(): Assertion `!derived->first_select()->exclude_from_table_unique_test || derived->outer_select()-> exclude_from_table_unique_test' failed.

#6  0x00007fb0847f0621 in *__GI___assert_fail (assertion=0xd36e28 "!derived->first_select()->exclude_from_table_unique_test || derived->outer_select()-> exclude_from_table_unique_test", file=<optimized out>, line=4438, function=0xd386a0 "void TABLE_LIST::set_check_merged()") at assert.c:81
#7  0x00000000007207c3 in TABLE_LIST::set_check_merged (this=0x1f5b3d0) at table.cc:4436
#8  0x00000000007249b1 in TABLE_LIST::set_merged_derived (this=0x1f5b3d0) at table.h:1796
#9  0x00000000007241c9 in TABLE_LIST::init_derived (this=0x1f5b3d0, thd=0x1ea0b88, init_view=true) at table.cc:6034
#10 0x00000000008b28d6 in mysql_derived_init (thd=0x1ea0b88, lex=0x1f57958, derived=0x1f5b3d0) at sql_derived.cc:542
#11 0x00000000008b1f24 in mysql_handle_derived (lex=0x1f57958, phases=1) at sql_derived.cc:112
#12 0x00000000007086b4 in open_and_lock_tables_derived (thd=0x1ea0b88, tables=0x1f58b80, derived=true) at sql_base.cc:5262
#13 0x00000000006bbd14 in open_and_lock_tables (thd=0x1ea0b88, tables=0x1f58b80) at mysql_priv.h:1826
#14 0x00000000006ae385 in mysql_execute_command (thd=0x1ea0b88) at sql_parse.cc:3305
#15 0x0000000000786882 in Prepared_statement::execute (this=0x1f57588, expanded_query=0x7fb07bd0ccb0, open_cursor=false) at sql_prepare.cc:3764
#16 0x0000000000785acf in Prepared_statement::execute_loop (this=0x1f57588, expanded_query=0x7fb07bd0ccb0, open_cursor=false, packet=0x0, packet_end=0x0) at sql_prepare.cc:3445
#17 0x0000000000783f26 in mysql_sql_stmt_execute (thd=0x1ea0b88) at sql_prepare.cc:2670
#18 0x00000000006ab6f6 in mysql_execute_command (thd=0x1ea0b88) at sql_parse.cc:2314
#19 0x00000000006b6e93 in mysql_parse (thd=0x1ea0b88, rawbuf=0x1f248c0 "EXECUTE stmt", length=12, found_semicolon=0x7fb07bd0dcb8) at sql_parse.cc:6173
#20 0x00000000006a8ea8 in dispatch_command (command=COM_QUERY, thd=0x1ea0b88, packet=0x1f1b459 "EXECUTE stmt", packet_length=12) at sql_parse.cc:1243
#21 0x00000000006a8194 in do_command (thd=0x1ea0b88) at sql_parse.cc:923
#22 0x00000000006a5025 in handle_one_connection (arg=0x1ea0b88) at sql_connect.cc:1231
#23 0x00007fb0854fcb50 in start_thread (arg=<optimized out>) at pthread_create.c:304
#24 0x00007fb08489fa7d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112

Stack trace from:

revision-id: igor@askmonty.org-20140221052733-ypg4dpfcmy5l0b3q
date: 2014-02-20 21:27:33 -0800
build-date: 2014-02-26 03:02:19 +0400
revno: 3765
branch-nick: 5.3
BUILD/compile-pentium-debug-max-no-ndb



 Comments   
Comment by Oleksandr Byelkin [ 2014-02-27 ]

probably exclude_from_table_unique_test is not reset.

Comment by Oleksandr Byelkin [ 2014-02-28 ]

Above is not reset because mysql_derived_fill was never called despite switching to materialized derived.

Comment by Oleksandr Byelkin [ 2014-03-03 ]

The problem is that after set_materialized_derived() call the table still merged

Comment by Oleksandr Byelkin [ 2014-03-03 ]

set_materialized_derived() run in one execution, then nothing was done to execute, the derived, reinitialization do not call unit->cleanup() so exclude_from_table_unique_test is not reset which was detected by set_merged_derived() on the next execution.

Adding unit->cleanup() to mysql_derived_reinit() leads to crash (there is even unit->unclean() call in mysql_derived_reinit()).

Comment by Oleksandr Byelkin [ 2014-03-05 ]

Decision to materialize derived appeared when UNION already executed during "fake select" execution.
Checking of underlying tables on this stage is wrong, because fake select works on temporary tables.

Comment by Oleksandr Byelkin [ 2014-03-06 ]

Sent for review...

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