[MDEV-29289] uncleaned LIMIT ROWS EXAMINED Created: 2022-08-11  Updated: 2024-01-19

Status: In Review
Project: MariaDB Server
Component/s: Data Definition - Temporary, Data Manipulation - Insert
Affects Version/s: 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10
Fix Version/s: 10.4, 10.5, 10.6

Type: Bug Priority: Major
Reporter: Roel Van de Paar Assignee: Michael Widenius
Resolution: Unresolved Votes: 0
Labels: not-10.3, regression


 Description   

Affects InnoDB, MyISAM, Aria and likely other engines

CREATE TABLE t (c INT);
CREATE TEMPORARY TABLE t (id INT);
DROP TABLE t;
SET GLOBAL general_log=ON,log_output='TABLE';
EXPLAIN SELECT * FROM t LIMIT ROWS EXAMINED 1;
INSERT INTO dummy SET a=0;

Leads to:

10.10.0 e1caa4bd5e8b4645944b85d4b603bf9fc9ef6ca4 (Debug)

mysqld: /test/10.10_dbg/sql/protocol.cc:617: void Protocol::end_statement(): Assertion `0' failed.

10.10.0 e1caa4bd5e8b4645944b85d4b603bf9fc9ef6ca4 (Debug)

Core was generated by `/test/MD290722-mariadb-10.10.0-linux-x86_64-dbg/bin/mysqld --no-defaults --core'.
Program terminated with signal SIGABRT, Aborted.
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
[Current thread is 1 (Thread 0x153b96147700 (LWP 4109880))]
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x0000153bbbec9859 in __GI_abort () at abort.c:79
#2  0x0000153bbbec9729 in __assert_fail_base (fmt=0x153bbc05f588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x558a73b579d9 "0", file=0x558a73980428 "/test/10.10_dbg/sql/protocol.cc", line=617, function=<optimized out>) at assert.c:92
#3  0x0000153bbbedafd6 in __GI___assert_fail (assertion=assertion@entry=0x558a73b579d9 "0", file=file@entry=0x558a73980428 "/test/10.10_dbg/sql/protocol.cc", line=line@entry=617, function=function@entry=0x558a73980cc8 "void Protocol::end_statement()") at assert.c:101
#4  0x0000558a72cc3a39 in Protocol::end_statement (this=0x153b380013c0) at /test/10.10_dbg/sql/protocol.cc:617
#5  0x0000558a72dbb839 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x153b38000db8, packet=<optimized out>, packet@entry=0x153b3800b6e9 "INSERT INTO dummy SET a=0", packet_length=packet_length@entry=25, blocking=blocking@entry=true) at /test/10.10_dbg/sql/sql_parse.cc:2401
#6  0x0000558a72dbc226 in do_command (thd=0x153b38000db8, blocking=blocking@entry=true) at /test/10.10_dbg/sql/sql_parse.cc:1407
#7  0x0000558a72f1d744 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x558a750a11b8, put_in_cache=put_in_cache@entry=true) at /test/10.10_dbg/sql/sql_connect.cc:1418
#8  0x0000558a72f1dc4d in handle_one_connection (arg=0x558a750a11b8) at /test/10.10_dbg/sql/sql_connect.cc:1312
#9  0x0000153bbc3da609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#10 0x0000153bbbfc6133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.4.26 (dbg), 10.5.17 (dbg), 10.7.5 (dbg), 10.8.4 (dbg), 10.9.2 (dbg), 10.10.0 (dbg)

Bug (or feature/syntax) confirmed not present in:
MariaDB: 10.3.36 (dbg), 10.3.36 (opt), 10.4.26 (opt), 10.5.17 (opt), 10.6.9 (dbg), 10.6.9 (opt), 10.7.5 (opt), 10.8.4 (opt), 10.9.2 (opt), 10.10.0 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.51 (dbg), 5.6.51 (opt), 5.7.38 (dbg), 5.7.38 (opt), 8.0.29 (dbg), 8.0.29 (opt)



 Comments   
Comment by Oleksandr Byelkin [ 2023-09-26 ]

THD::check_limit_rows_examined set thd->killed in writing to the log, so it detect KILL state even before opening the inexistent table.

Comment by Oleksandr Byelkin [ 2023-09-26 ]

0x000055fdf7cfd669 in THD::set_killed_no_mutex (this=0x7ffa3c000d38, 
    killed_arg=ABORT_QUERY, killed_errno_arg=0, killed_err_msg_arg=0x0)
    at /home/sanja/maria/git/10.4/sql/sql_class.h:4155
4155	      killed= killed_arg;
(rr) where
#0  0x000055fdf7cfd669 in THD::set_killed_no_mutex (this=0x7ffa3c000d38, 
    killed_arg=ABORT_QUERY, killed_errno_arg=0, killed_err_msg_arg=0x0)
    at /home/sanja/maria/git/10.4/sql/sql_class.h:4155
#1  0x000055fdf7cfd607 in THD::set_killed (this=0x7ffa3c000d38, 
    killed_arg=ABORT_QUERY, killed_errno_arg=0, killed_err_msg_arg=0x0)
    at /home/sanja/maria/git/10.4/sql/sql_class.h:4140
#2  0x000055fdf7f003a1 in THD::check_limit_rows_examined (this=0x7ffa3c000d38)
    at /home/sanja/maria/git/10.4/sql/sql_class.h:3055
#3  0x000055fdf7f0042e in handler::increment_statistics (this=0x7ffa3c07de50, 
    offset=&system_status_var::ha_write_count)
    at /home/sanja/maria/git/10.4/sql/sql_class.h:6763
#4  0x000055fdf81f9650 in handler::ha_write_row (this=0x7ffa3c07de50, 
    buf=0x7ffa3c08e500 "e\023\b\024")
    at /home/sanja/maria/git/10.4/sql/handler.cc:6839
#5  0x000055fdf832c58c in Log_to_csv_event_handler::log_general (
    this=0x55fdfa8b5160, thd=0x7ffa3c000d38, event_time=..., 
    user_host=0x7ffa5804f010 "root[root] @ localhost []", user_host_len=25, 
    thread_id_arg=4, command_type=0x55fdf8e23db6 "Query", command_type_len=5, 
    sql_text=0x7ffa3c017200 "INSERT INTO dummy SET a=0", sql_text_len=25, 
    client_cs=0x55fdf9816ac0 <my_charset_latin1>)
    at /home/sanja/maria/git/10.4/sql/log.cc:786
#6  0x000055fdf832e698 in LOGGER::general_log_write (
    this=0x55fdf9960400 <logger>, thd=0x7ffa3c000d38, command=COM_QUERY, 
    query=0x7ffa3c017200 "INSERT INTO dummy SET a=0", query_length=25)
    at /home/sanja/maria/git/10.4/sql/log.cc:1380
#7  0x000055fdf833f9ce in general_log_write (thd=0x7ffa3c000d38, 
    command=COM_QUERY, query=0x7ffa3c017200 "INSERT INTO dummy SET a=0", 
    query_length=25) at /home/sanja/maria/git/10.4/sql/log.cc:6686
#8  0x000055fdf7e4ede1 in dispatch_command (command=COM_QUERY, 
    thd=0x7ffa3c000d38, packet=0x7ffa3c00a179 "INSERT INTO dummy SET a=0", 
    packet_length=25, is_com_multi=false, is_next_command=false)
    at /home/sanja/maria/git/10.4/sql/sql_parse.cc:1828
#9  0x000055fdf7e4d889 in do_command (thd=0x7ffa3c000d38)
    at /home/sanja/maria/git/10.4/sql/sql_parse.cc:1378

Comment by Oleksandr Byelkin [ 2023-09-26 ]

limit_rows_examined_cnt was set in explain and used in the INSERT

Comment by Oleksandr Byelkin [ 2023-09-26 ]

the set s case without unneeded rubbish

CREATE TABLE t (c INT);
SET @save_general_log=@@general_log;
SET @save_log_output=@@log_output;
SET GLOBAL general_log=ON,log_output='TABLE';
EXPLAIN SELECT * FROM t LIMIT ROWS EXAMINED 1;
--error ER_NO_SUCH_TABLE
INSERT INTO dummy SET a=0;
DROP TABLE t;
SET GLOBAL general_log=@save_general_log, log_output=@save_log_output;

Comment by Oleksandr Byelkin [ 2023-09-26 ]

commit 05f6e368db3a367f2057d116dafa5cc34ca746a4 (HEAD -> bb-10.4-MDEV-29289, origin/bb-10.4-MDEV-29289)
Author: Oleksandr Byelkin <sanja@mariadb.com>
Date:   Tue Sep 26 19:59:50 2023 +0200
 
    MDEV-29289 uncleaned LIMIT ROWS EXAMINED
    
    Clean thd->lex->limit_rows_examined_cnt at the end of dispatch_command to avoid side effects

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