Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-34669

ER_NEED_REPREPARE on SELECT DEFAULT(name) FROM table1_containing_sequence

Details

    Description

      from: https://stackoverflow.com/questions/78807751/error-1615-hy000-prepared-statement-needs-to-be-re-prepared-error-occures-o

      create sequence seq;
      create table table1
      (
          id   int          default nextval(`seq`) not null primary key,
          name varchar(200) default 'auto'                   not null
      );
      

      And run:

      for a in `seq 1000`; do client/mariadb -S /tmp/build-mariadb-server-rebase.sock  -Be 'execute immediate "SELECT
              DEFAULT(name)
              FROM table1";execute immediate "SELECT
              DEFAULT(name)
              FROM table1";execute immediate "SELECT
              DEFAULT(name)' &
      done
      

      Need to start server with rasied max-connection (2k) and potentially more execute immediate SQL statements in the command line to trigger the race condition.

      Will cause connection to error

       1615 (HY000)        FROM table1";' test
       at line 1: Prepared statement needs to be re-prepared
      

      Attachments

        Activity

          danblack Daniel Black added a comment -

          Hi sanja, can you review https://github.com/MariaDB/server/pull/3434 please.

          Guidance around writing test case appreciated.

          danblack Daniel Black added a comment - Hi sanja , can you review https://github.com/MariaDB/server/pull/3434 please. Guidance around writing test case appreciated.
          sanja Oleksandr Byelkin added a comment - - edited

          I cnow the only method to emulae an race condition - debug sync (DEBUG_SYNC).

          sanja Oleksandr Byelkin added a comment - - edited I cnow the only method to emulae an race condition - debug sync (DEBUG_SYNC).
          danblack Daniel Black added a comment -

          The point of the error is:

          Point of error - TABLE_LIST::is_the_same_definition failure on seq TABLE_LIST (10.5)

          Thread 2 hit Breakpoint 1.1, Diagnostics_area::set_error_status (this=0x7f2f08322d70, sql_errno=1615) at /home/dan/repos/mariadb-server-rebase/sql/sql_error.cc:419
           
          #0  Diagnostics_area::set_error_status (this=0x7f2f08322d70, sql_errno=1615) at /home/dan/repos/mariadb-server-rebase/sql/sql_error.cc:419
          #1  0x000000000091f13e in Reprepare_observer::report_error (this=0x7f2f181b0f4f, thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:3931
          #2  0x0000000000822bb3 in check_and_update_table_version (thd=0x7f2f0831d0a8, tables=0x7f2f083bc260, table_share=0x7f2ef002e130)
              at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:2845
          #3  0x0000000000827446 in open_and_process_table (thd=0x7f2f0831d0a8, tables=0x7f2f083bc260, counter=0x7f2f181af47c, flags=0, prelocking_strategy=0x7f2f181af4e0, 
              has_prelocking_list=false, ot_ctx=0x7f2f181af3d0) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:3874
          #4  0x0000000000825aab in open_tables (thd=0x7f2f0831d0a8, options=@0x7f2f082f87e8: {m_options = DDL_options_st::OPT_NONE}, start=0x7f2f181af490, counter=0x7f2f181af47c, flags=0, 
              prelocking_strategy=0x7f2f181af4e0) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:4303
          #5  0x000000000082a9bf in open_and_lock_tables (thd=0x7f2f0831d0a8, options=@0x7f2f082f87e8: {m_options = DDL_options_st::OPT_NONE}, tables=0x7f2f0830d7e0, derived=true, flags=0, 
              prelocking_strategy=0x7f2f181af4e0) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:5250
          #6  0x00000000007d058e in open_and_lock_tables (thd=0x7f2f0831d0a8, tables=0x7f2f0830d7e0, derived=true, flags=0) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.h:509
          #7  0x00000000008fb53e in execute_sqlcom_select (thd=0x7f2f0831d0a8, all_tables=0x7f2f0830d7e0) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:6346
          #8  0x00000000008eeeb0 in mysql_execute_command (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:4030
          #9  0x0000000000922798 in Prepared_statement::execute (this=0x7f2f08341238, expanded_query=0x7f2f181b1010, open_cursor=false)
              at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:5131
          #10 0x000000000091dde7 in Prepared_statement::execute_loop (this=0x7f2f08341238, expanded_query=0x7f2f181b1010, open_cursor=false, packet=0x0, packet_end=0x0)
              at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:4553
          #11 0x000000000091c276 in Prepared_statement::execute_immediate (this=0x7f2f08341238, query=0x7f2f08342590 "SELECT  DEFAULT(name)    FROM table1", query_len=36)
              at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:5259
          #12 0x000000000091be9b in mysql_sql_stmt_execute_immediate (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:3008
          #13 0x00000000008eeedd in mysql_execute_command (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:4036
          #14 0x00000000008e5aed in mysql_parse (thd=0x7f2f0831d0a8, rawbuf=0x7f2f08341180 "execute immediate \"SELECT  DEFAULT(name)    FROM table1\"", length=56, parser_state=0x7f2f181b2af8, 
              is_com_multi=false, is_next_command=false) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:8223
          #15 0x00000000008e1fc1 in dispatch_command (command=COM_QUERY, thd=0x7f2f0831d0a8, packet=0x7f2f083a6bc9 "execute immediate \"SELECT  DEFAULT(name)    FROM table1\"", 
              packet_length=56, is_com_multi=false, is_next_command=false) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:1892
          #16 0x00000000008e69d4 in do_command (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:1376
          #17 0x0000000000aca140 in do_handle_one_connection (connect=0x30c025f8, put_in_cache=true) at /home/dan/repos/mariadb-server-rebase/sql/sql_connect.cc:1417
          #18 0x0000000000ac9ec2 in handle_one_connection (arg=0x30b99598) at /home/dan/repos/mariadb-server-rebase/sql/sql_connect.cc:1319
          #19 0x00007f2f3a6a6507 in start_thread () from /lib64/libc.so.6
          #20 0x00007f2f3a72a214 in clone () from /lib64/libc.so.6
          

          Prepared_statement::execute_loop installs a Reprepare_observer before calling ::execute

          The report error is called in check_and_update_table_version because the TABLE_LIST::is_the_same_definition fails.

          TABLE_LIST::m_table_ref_type at the time of calling check_and_update_table_version is TABLE_REF_NULL resulting in
          no match. The table list is pointing to the "seq" table. This object is this=0x7f2f0833fa60

          The TABLE_LIST for the table1 is 0x7f2f0830d7e0 also had TABLE_REF_NULL, but was called when the Prepared_statement::prepare phase without a Reprepare_observer installed

          is_the_same_defination check for table1 - no error

          #0  TABLE_LIST::is_the_same_definition (this=0x7f2f0830d7e0, thd=0x7f2f0831d0a8, s=0x7f2ef4039bd0) at /home/dan/repos/mariadb-server-rebase/sql/table.cc:9677
          #1  0x0000000000822b85 in check_and_update_table_version (thd=0x7f2f0831d0a8, tables=0x7f2f0830d7e0, table_share=0x7f2ef4039bd0)
              at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:2842
          #2  0x0000000000827446 in open_and_process_table (thd=0x7f2f0831d0a8, tables=0x7f2f0830d7e0, counter=0x7f2f181b07e4, flags=512, prelocking_strategy=0x7f2f181b07e8, 
              has_prelocking_list=false, ot_ctx=0x7f2f181b06f0) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:3874
          #3  0x0000000000825aab in open_tables (thd=0x7f2f0831d0a8, options=@0x7f2f082f87e8: {m_options = DDL_options_st::OPT_NONE}, start=0x7f2f181b07f8, counter=0x7f2f181b07e4, flags=512, 
              prelocking_strategy=0x7f2f181b07e8) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:4303
          #4  0x000000000082af3a in open_tables (thd=0x7f2f0831d0a8, tables=0x7f2f181b07f8, counter=0x7f2f181b07e4, flags=512, prelocking_strategy=0x7f2f181b07e8)
              at /home/dan/repos/mariadb-server-rebase/sql/sql_base.h:264
          #5  0x000000000082ac8e in open_normal_and_derived_tables (thd=0x7f2f0831d0a8, tables=0x7f2f0830d7e0, flags=512, dt_phases=3)
              at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:5314
          #6  0x000000000092871c in mysql_test_select (stmt=0x7f2f08341238, tables=0x7f2f0830d7e0) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:1567
          #7  0x00000000009213da in check_prepared_statement (stmt=0x7f2f08341238) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:2399
          #8  0x000000000091ade8 in Prepared_statement::prepare (this=0x7f2f08341238, packet=0x7f2f08342590 "SELECT  DEFAULT(name)    FROM table1", packet_len=36)
              at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:4337
          #9  0x000000000091c146 in Prepared_statement::execute_immediate (this=0x7f2f08341238, query=0x7f2f08342590 "SELECT  DEFAULT(name)    FROM table1", query_len=36)
              at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:5248
          #10 0x000000000091be9b in mysql_sql_stmt_execute_immediate (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:3008
          #11 0x00000000008eeedd in mysql_execute_command (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:4036
          #12 0x00000000008e5aed in mysql_parse (thd=0x7f2f0831d0a8, rawbuf=0x7f2f08341180 "execute immediate \"SELECT  DEFAULT(name)    FROM table1\"", length=56, parser_state=0x7f2f181b2af8, 
              is_com_multi=false, is_next_command=false) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:8223
          #13 0x00000000008e1fc1 in dispatch_command (command=COM_QUERY, thd=0x7f2f0831d0a8, packet=0x7f2f083a6bc9 "execute immediate \"SELECT  DEFAULT(name)    FROM table1\"", 
              packet_length=56, is_com_multi=false, is_next_command=false) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:1892
          #14 0x00000000008e69d4 in do_command (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:1376
          #15 0x0000000000aca140 in do_handle_one_connection (connect=0x30c025f8, put_in_cache=true) at /home/dan/repos/mariadb-server-rebase/sql/sql_connect.cc:1417
          #16 0x0000000000ac9ec2 in handle_one_connection (arg=0x30b99598) at /home/dan/repos/mariadb-server-rebase/sql/sql_connect.cc:1319
          #17 0x00007f2f3a6a6507 in start_thread () from /lib64/libc.so.6
          #18 0x00007f2f3a72a214 in clone () from /lib64/libc.so.6
          

          Sequences are added because of the extend_table_list

          #2  0x00000000007d4dd5 in TABLE_LIST::init_one_table (this=0x7f2f0833fa60, db_arg=0x7f2f14036238, table_name_arg=0x7f2f14036248, alias_arg=0x0, lock_type_arg=TL_WRITE_ALLOW_WRITE)
              at /home/dan/repos/mariadb-server-rebase/sql/table.h:2221
          #3  0x00000000007d0d2b in TABLE_LIST::init_one_table_for_prelocking (this=0x7f2f0833fa60, db_arg=0x7f2f14036238, table_name_arg=0x7f2f14036248, alias_arg=0x0, 
              lock_type_arg=TL_WRITE_ALLOW_WRITE, prelocking_type=TABLE_LIST::PRELOCK_NONE, belong_to_view_arg=0x0, trg_event_map_arg=0 '\000', last_ptr=0x7f2f082f70a8, insert_data=0 '\000')
              at /home/dan/repos/mariadb-server-rebase/sql/table.h:2254
          #4  0x0000000000828bee in add_internal_tables (thd=0x7f2f0831d0a8, prelocking_ctx=0x7f2f082f7098, tables=0x7f2f14036220) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:4616
          #5  0x0000000000828945 in DML_prelocking_strategy::handle_table (this=0x7f2f181b07e8, thd=0x7f2f0831d0a8, prelocking_ctx=0x7f2f082f7098, table_list=0x7f2f0830d7e0, 
              need_prelocking=0x7f2f181b0346) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:4771
          #6  0x00000000008252ee in extend_table_list (thd=0x7f2f0831d0a8, tables=0x7f2f0830d7e0, prelocking_strategy=0x7f2f181b07e8, has_prelocking_list=false)
              at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:3581
          #7  0x000000000082748a in open_and_process_table (thd=0x7f2f0831d0a8, tables=0x7f2f0830d7e0, counter=0x7f2f181b07e4, flags=512, prelocking_strategy=0x7f2f181b07e8, 
              has_prelocking_list=false, ot_ctx=0x7f2f181b06f0) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:3879
          #8  0x0000000000825aab in open_tables (thd=0x7f2f0831d0a8, options=@0x7f2f082f87e8: {m_options = DDL_options_st::OPT_NONE}, start=0x7f2f181b07f8, counter=0x7f2f181b07e4, flags=512, 
              prelocking_strategy=0x7f2f181b07e8) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:4303
          #9  0x000000000082af3a in open_tables (thd=0x7f2f0831d0a8, tables=0x7f2f181b07f8, counter=0x7f2f181b07e4, flags=512, prelocking_strategy=0x7f2f181b07e8)
              at /home/dan/repos/mariadb-server-rebase/sql/sql_base.h:264
          #10 0x000000000082ac8e in open_normal_and_derived_tables (thd=0x7f2f0831d0a8, tables=0x7f2f0830d7e0, flags=512, dt_phases=3)
              at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:5314
          #11 0x000000000092871c in mysql_test_select (stmt=0x7f2f08341238, tables=0x7f2f0830d7e0) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:1567
          #12 0x00000000009213da in check_prepared_statement (stmt=0x7f2f08341238) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:2399
          #13 0x000000000091ade8 in Prepared_statement::prepare (this=0x7f2f08341238, packet=0x7f2f08342590 "SELECT  DEFAULT(name)    FROM table1", packet_len=36)
              at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:4337
          #14 0x000000000091c146 in Prepared_statement::execute_immediate (this=0x7f2f08341238, query=0x7f2f08342590 "SELECT  DEFAULT(name)    FROM table1", query_len=36)
              at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:5248
          #15 0x000000000091be9b in mysql_sql_stmt_execute_immediate (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:3008
          #16 0x00000000008eeedd in mysql_execute_command (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:4036
          #17 0x00000000008e5aed in mysql_parse (thd=0x7f2f0831d0a8, rawbuf=0x7f2f08341180 "execute immediate \"SELECT  DEFAULT(name)    FROM table1\"", length=56, parser_state=0x7f2f181b2af8, 
              is_com_multi=false, is_next_command=false) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:8223
          #18 0x00000000008e1fc1 in dispatch_command (command=COM_QUERY, thd=0x7f2f0831d0a8, packet=0x7f2f083a6bc9 "execute immediate \"SELECT  DEFAULT(name)    FROM table1\"", 
              packet_length=56, is_com_multi=false, is_next_command=false) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:1892
          #19 0x00000000008e69d4 in do_command (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:1376
          #20 0x0000000000aca140 in do_handle_one_connection (connect=0x30c025f8, put_in_cache=true) at /home/dan/repos/mariadb-server-rebase/sql/sql_connect.cc:1417
          #21 0x0000000000ac9ec2 in handle_one_connection (arg=0x30b99598) at /home/dan/repos/mariadb-server-rebase/sql/sql_connect.cc:1319
          #22 0x00007f2f3a6a6507 in start_thread () from /lib64/libc.so.6
          #23 0x00007f2f3a72a214 in clone () from /lib64/libc.so.6
          

          Title open_and_process_table

          ...
                if (!error && !tables->table)
                  error= open_table(thd, tables, ot_ctx);
          ...
          ...
              /* Check and update metadata version of a base table. */
              error= check_and_update_table_version(thd, tables, tables->table->s);
              
              if (unlikely(error))
                goto end;
            
              error= extend_table_list(thd, tables, prelocking_strategy, has_prelocking_list,);
              if (unlikely(error))
          

          The extend_table_list tables, like seq, are not checked in the prepare phase - (check_and_update_table_version). For the to work the open_table should have been called.

          The reason any checking of seq actually occurs is because on:

           
          bool extend_table_list(THD *thd, TABLE_LIST *tables,   
                                   Prelocking_strategy *prelocking_strategy,
                                   bool has_prelocking_list, Open_table_context *ot_ctx)
            {                                    
              bool error= false;                 
              LEX *lex= thd->lex;
              bool maybe_need_prelocking=
                (tables->updating && tables->lock_type >= TL_WRITE_ALLOW_WRITE)
                || thd->lex->default_used;
          
          

          Any DEFAULT() usage in the syntax parsing sets default_used. At the point of parsing the resolution of the type of the argument isn't set.

          So I think the DEFAULT() needs to save a list in the parser and use that in the extend_table_list or somewhere to populate the cases if needed.

          I have confirmed it takes a race conditions to trigger, but don't know why/how yet.

          danblack Daniel Black added a comment - The point of the error is: Point of error - TABLE_LIST::is_the_same_definition failure on seq TABLE_LIST (10.5) Thread 2 hit Breakpoint 1.1, Diagnostics_area::set_error_status (this=0x7f2f08322d70, sql_errno=1615) at /home/dan/repos/mariadb-server-rebase/sql/sql_error.cc:419   #0 Diagnostics_area::set_error_status (this=0x7f2f08322d70, sql_errno=1615) at /home/dan/repos/mariadb-server-rebase/sql/sql_error.cc:419 #1 0x000000000091f13e in Reprepare_observer::report_error (this=0x7f2f181b0f4f, thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:3931 #2 0x0000000000822bb3 in check_and_update_table_version (thd=0x7f2f0831d0a8, tables=0x7f2f083bc260, table_share=0x7f2ef002e130) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:2845 #3 0x0000000000827446 in open_and_process_table (thd=0x7f2f0831d0a8, tables=0x7f2f083bc260, counter=0x7f2f181af47c, flags=0, prelocking_strategy=0x7f2f181af4e0, has_prelocking_list=false, ot_ctx=0x7f2f181af3d0) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:3874 #4 0x0000000000825aab in open_tables (thd=0x7f2f0831d0a8, options=@0x7f2f082f87e8: {m_options = DDL_options_st::OPT_NONE}, start=0x7f2f181af490, counter=0x7f2f181af47c, flags=0, prelocking_strategy=0x7f2f181af4e0) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:4303 #5 0x000000000082a9bf in open_and_lock_tables (thd=0x7f2f0831d0a8, options=@0x7f2f082f87e8: {m_options = DDL_options_st::OPT_NONE}, tables=0x7f2f0830d7e0, derived=true, flags=0, prelocking_strategy=0x7f2f181af4e0) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:5250 #6 0x00000000007d058e in open_and_lock_tables (thd=0x7f2f0831d0a8, tables=0x7f2f0830d7e0, derived=true, flags=0) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.h:509 #7 0x00000000008fb53e in execute_sqlcom_select (thd=0x7f2f0831d0a8, all_tables=0x7f2f0830d7e0) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:6346 #8 0x00000000008eeeb0 in mysql_execute_command (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:4030 #9 0x0000000000922798 in Prepared_statement::execute (this=0x7f2f08341238, expanded_query=0x7f2f181b1010, open_cursor=false) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:5131 #10 0x000000000091dde7 in Prepared_statement::execute_loop (this=0x7f2f08341238, expanded_query=0x7f2f181b1010, open_cursor=false, packet=0x0, packet_end=0x0) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:4553 #11 0x000000000091c276 in Prepared_statement::execute_immediate (this=0x7f2f08341238, query=0x7f2f08342590 "SELECT DEFAULT(name) FROM table1", query_len=36) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:5259 #12 0x000000000091be9b in mysql_sql_stmt_execute_immediate (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:3008 #13 0x00000000008eeedd in mysql_execute_command (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:4036 #14 0x00000000008e5aed in mysql_parse (thd=0x7f2f0831d0a8, rawbuf=0x7f2f08341180 "execute immediate \"SELECT DEFAULT(name) FROM table1\"", length=56, parser_state=0x7f2f181b2af8, is_com_multi=false, is_next_command=false) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:8223 #15 0x00000000008e1fc1 in dispatch_command (command=COM_QUERY, thd=0x7f2f0831d0a8, packet=0x7f2f083a6bc9 "execute immediate \"SELECT DEFAULT(name) FROM table1\"", packet_length=56, is_com_multi=false, is_next_command=false) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:1892 #16 0x00000000008e69d4 in do_command (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:1376 #17 0x0000000000aca140 in do_handle_one_connection (connect=0x30c025f8, put_in_cache=true) at /home/dan/repos/mariadb-server-rebase/sql/sql_connect.cc:1417 #18 0x0000000000ac9ec2 in handle_one_connection (arg=0x30b99598) at /home/dan/repos/mariadb-server-rebase/sql/sql_connect.cc:1319 #19 0x00007f2f3a6a6507 in start_thread () from /lib64/libc.so.6 #20 0x00007f2f3a72a214 in clone () from /lib64/libc.so.6 Prepared_statement::execute_loop installs a Reprepare_observer before calling ::execute The report error is called in check_and_update_table_version because the TABLE_LIST::is_the_same_definition fails. TABLE_LIST::m_table_ref_type at the time of calling check_and_update_table_version is TABLE_REF_NULL resulting in no match. The table list is pointing to the "seq" table. This object is this=0x7f2f0833fa60 The TABLE_LIST for the table1 is 0x7f2f0830d7e0 also had TABLE_REF_NULL , but was called when the Prepared_statement::prepare phase without a Reprepare_observer installed is_the_same_defination check for table1 - no error #0 TABLE_LIST::is_the_same_definition (this=0x7f2f0830d7e0, thd=0x7f2f0831d0a8, s=0x7f2ef4039bd0) at /home/dan/repos/mariadb-server-rebase/sql/table.cc:9677 #1 0x0000000000822b85 in check_and_update_table_version (thd=0x7f2f0831d0a8, tables=0x7f2f0830d7e0, table_share=0x7f2ef4039bd0) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:2842 #2 0x0000000000827446 in open_and_process_table (thd=0x7f2f0831d0a8, tables=0x7f2f0830d7e0, counter=0x7f2f181b07e4, flags=512, prelocking_strategy=0x7f2f181b07e8, has_prelocking_list=false, ot_ctx=0x7f2f181b06f0) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:3874 #3 0x0000000000825aab in open_tables (thd=0x7f2f0831d0a8, options=@0x7f2f082f87e8: {m_options = DDL_options_st::OPT_NONE}, start=0x7f2f181b07f8, counter=0x7f2f181b07e4, flags=512, prelocking_strategy=0x7f2f181b07e8) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:4303 #4 0x000000000082af3a in open_tables (thd=0x7f2f0831d0a8, tables=0x7f2f181b07f8, counter=0x7f2f181b07e4, flags=512, prelocking_strategy=0x7f2f181b07e8) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.h:264 #5 0x000000000082ac8e in open_normal_and_derived_tables (thd=0x7f2f0831d0a8, tables=0x7f2f0830d7e0, flags=512, dt_phases=3) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:5314 #6 0x000000000092871c in mysql_test_select (stmt=0x7f2f08341238, tables=0x7f2f0830d7e0) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:1567 #7 0x00000000009213da in check_prepared_statement (stmt=0x7f2f08341238) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:2399 #8 0x000000000091ade8 in Prepared_statement::prepare (this=0x7f2f08341238, packet=0x7f2f08342590 "SELECT DEFAULT(name) FROM table1", packet_len=36) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:4337 #9 0x000000000091c146 in Prepared_statement::execute_immediate (this=0x7f2f08341238, query=0x7f2f08342590 "SELECT DEFAULT(name) FROM table1", query_len=36) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:5248 #10 0x000000000091be9b in mysql_sql_stmt_execute_immediate (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:3008 #11 0x00000000008eeedd in mysql_execute_command (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:4036 #12 0x00000000008e5aed in mysql_parse (thd=0x7f2f0831d0a8, rawbuf=0x7f2f08341180 "execute immediate \"SELECT DEFAULT(name) FROM table1\"", length=56, parser_state=0x7f2f181b2af8, is_com_multi=false, is_next_command=false) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:8223 #13 0x00000000008e1fc1 in dispatch_command (command=COM_QUERY, thd=0x7f2f0831d0a8, packet=0x7f2f083a6bc9 "execute immediate \"SELECT DEFAULT(name) FROM table1\"", packet_length=56, is_com_multi=false, is_next_command=false) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:1892 #14 0x00000000008e69d4 in do_command (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:1376 #15 0x0000000000aca140 in do_handle_one_connection (connect=0x30c025f8, put_in_cache=true) at /home/dan/repos/mariadb-server-rebase/sql/sql_connect.cc:1417 #16 0x0000000000ac9ec2 in handle_one_connection (arg=0x30b99598) at /home/dan/repos/mariadb-server-rebase/sql/sql_connect.cc:1319 #17 0x00007f2f3a6a6507 in start_thread () from /lib64/libc.so.6 #18 0x00007f2f3a72a214 in clone () from /lib64/libc.so.6 Sequences are added because of the extend_table_list #2 0x00000000007d4dd5 in TABLE_LIST::init_one_table (this=0x7f2f0833fa60, db_arg=0x7f2f14036238, table_name_arg=0x7f2f14036248, alias_arg=0x0, lock_type_arg=TL_WRITE_ALLOW_WRITE) at /home/dan/repos/mariadb-server-rebase/sql/table.h:2221 #3 0x00000000007d0d2b in TABLE_LIST::init_one_table_for_prelocking (this=0x7f2f0833fa60, db_arg=0x7f2f14036238, table_name_arg=0x7f2f14036248, alias_arg=0x0, lock_type_arg=TL_WRITE_ALLOW_WRITE, prelocking_type=TABLE_LIST::PRELOCK_NONE, belong_to_view_arg=0x0, trg_event_map_arg=0 '\000', last_ptr=0x7f2f082f70a8, insert_data=0 '\000') at /home/dan/repos/mariadb-server-rebase/sql/table.h:2254 #4 0x0000000000828bee in add_internal_tables (thd=0x7f2f0831d0a8, prelocking_ctx=0x7f2f082f7098, tables=0x7f2f14036220) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:4616 #5 0x0000000000828945 in DML_prelocking_strategy::handle_table (this=0x7f2f181b07e8, thd=0x7f2f0831d0a8, prelocking_ctx=0x7f2f082f7098, table_list=0x7f2f0830d7e0, need_prelocking=0x7f2f181b0346) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:4771 #6 0x00000000008252ee in extend_table_list (thd=0x7f2f0831d0a8, tables=0x7f2f0830d7e0, prelocking_strategy=0x7f2f181b07e8, has_prelocking_list=false) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:3581 #7 0x000000000082748a in open_and_process_table (thd=0x7f2f0831d0a8, tables=0x7f2f0830d7e0, counter=0x7f2f181b07e4, flags=512, prelocking_strategy=0x7f2f181b07e8, has_prelocking_list=false, ot_ctx=0x7f2f181b06f0) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:3879 #8 0x0000000000825aab in open_tables (thd=0x7f2f0831d0a8, options=@0x7f2f082f87e8: {m_options = DDL_options_st::OPT_NONE}, start=0x7f2f181b07f8, counter=0x7f2f181b07e4, flags=512, prelocking_strategy=0x7f2f181b07e8) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:4303 #9 0x000000000082af3a in open_tables (thd=0x7f2f0831d0a8, tables=0x7f2f181b07f8, counter=0x7f2f181b07e4, flags=512, prelocking_strategy=0x7f2f181b07e8) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.h:264 #10 0x000000000082ac8e in open_normal_and_derived_tables (thd=0x7f2f0831d0a8, tables=0x7f2f0830d7e0, flags=512, dt_phases=3) at /home/dan/repos/mariadb-server-rebase/sql/sql_base.cc:5314 #11 0x000000000092871c in mysql_test_select (stmt=0x7f2f08341238, tables=0x7f2f0830d7e0) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:1567 #12 0x00000000009213da in check_prepared_statement (stmt=0x7f2f08341238) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:2399 #13 0x000000000091ade8 in Prepared_statement::prepare (this=0x7f2f08341238, packet=0x7f2f08342590 "SELECT DEFAULT(name) FROM table1", packet_len=36) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:4337 #14 0x000000000091c146 in Prepared_statement::execute_immediate (this=0x7f2f08341238, query=0x7f2f08342590 "SELECT DEFAULT(name) FROM table1", query_len=36) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:5248 #15 0x000000000091be9b in mysql_sql_stmt_execute_immediate (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_prepare.cc:3008 #16 0x00000000008eeedd in mysql_execute_command (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:4036 #17 0x00000000008e5aed in mysql_parse (thd=0x7f2f0831d0a8, rawbuf=0x7f2f08341180 "execute immediate \"SELECT DEFAULT(name) FROM table1\"", length=56, parser_state=0x7f2f181b2af8, is_com_multi=false, is_next_command=false) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:8223 #18 0x00000000008e1fc1 in dispatch_command (command=COM_QUERY, thd=0x7f2f0831d0a8, packet=0x7f2f083a6bc9 "execute immediate \"SELECT DEFAULT(name) FROM table1\"", packet_length=56, is_com_multi=false, is_next_command=false) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:1892 #19 0x00000000008e69d4 in do_command (thd=0x7f2f0831d0a8) at /home/dan/repos/mariadb-server-rebase/sql/sql_parse.cc:1376 #20 0x0000000000aca140 in do_handle_one_connection (connect=0x30c025f8, put_in_cache=true) at /home/dan/repos/mariadb-server-rebase/sql/sql_connect.cc:1417 #21 0x0000000000ac9ec2 in handle_one_connection (arg=0x30b99598) at /home/dan/repos/mariadb-server-rebase/sql/sql_connect.cc:1319 #22 0x00007f2f3a6a6507 in start_thread () from /lib64/libc.so.6 #23 0x00007f2f3a72a214 in clone () from /lib64/libc.so.6 Title open_and_process_table ... if (!error && !tables->table) error= open_table(thd, tables, ot_ctx); ... ... /* Check and update metadata version of a base table. */ error= check_and_update_table_version(thd, tables, tables->table->s); if (unlikely(error)) goto end; error= extend_table_list(thd, tables, prelocking_strategy, has_prelocking_list,); if (unlikely(error)) The extend_table_list tables, like seq, are not checked in the prepare phase - (check_and_update_table_version). For the to work the open_table should have been called. The reason any checking of seq actually occurs is because on:   bool extend_table_list(THD *thd, TABLE_LIST *tables, Prelocking_strategy *prelocking_strategy, bool has_prelocking_list, Open_table_context *ot_ctx) { bool error= false ; LEX *lex= thd->lex; bool maybe_need_prelocking= (tables->updating && tables->lock_type >= TL_WRITE_ALLOW_WRITE) || thd->lex->default_used; Any DEFAULT() usage in the syntax parsing sets default_used . At the point of parsing the resolution of the type of the argument isn't set. So I think the DEFAULT() needs to save a list in the parser and use that in the extend_table_list or somewhere to populate the cases if needed. I have confirmed it takes a race conditions to trigger, but don't know why/how yet.
          danblack Daniel Black added a comment -

          sanja can I get a review on https://github.com/MariaDB/server/pull/3434 please.

          danblack Daniel Black added a comment - sanja can I get a review on https://github.com/MariaDB/server/pull/3434 please.

          OK to push

          sanja Oleksandr Byelkin added a comment - OK to push
          danblack Daniel Black added a comment -

          Thank you sanja!

          danblack Daniel Black added a comment - Thank you sanja !

          People

            danblack Daniel Black
            danblack Daniel Black
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.