[MDEV-22058] Assertion `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())' failed in Diagnostics_area::set_ok_status Created: 2020-03-27  Updated: 2021-04-20  Resolved: 2020-07-12

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.2, 10.3, 10.4, 10.5
Fix Version/s: 10.2.33, 10.3.24, 10.4.14, 10.5.5

Type: Bug Priority: Major
Reporter: Roel Van de Paar Assignee: Rucha Deodhar
Resolution: Fixed Votes: 0
Labels: affects-tests, not-10.1

Issue Links:
Relates
relates to MDEV-25460 Assertion `!is_set() || (m_status == ... Closed

 Description   

SET @cmd:="SET @@SESSION.SQL_MODE=(SELECT 'a')";
SET @@SESSION.OPTIMIZER_SWITCH="materialization=OFF";
SET @@SESSION.OPTIMIZER_SWITCH="in_to_exists=OFF";
PREPARE stmt FROM @cmd;

Leads to:

mysqld: /data/git/10.5_dbg/sql/sql_error.cc:335: void Diagnostics_area::set_ok_status(ulonglong, ulonglong, const char*): Assertion `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())' failed.

Core was generated by `/data/MD180320-mariadb-10.5.2-linux-x86_64-dbg/bin/mysqld --no-defaults --core-'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
57	../sysdeps/unix/sysv/linux/pthread_kill.c: No such file or directory.
[Current thread is 1 (Thread 0x7f2b2c7c8700 (LWP 24499))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
#1  0x0000560dec9ba7d4 in my_write_core (sig=sig@entry=6)
    at /data/git/10.5_dbg/mysys/stacktrace.c:518
#2  0x0000560dec163b5f in handle_fatal_signal (sig=6) at /data/git/10.5_dbg/sql/signal_handler.cc:325
#3  <signal handler called>
#4  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#5  0x00007f2b2af0c801 in __GI_abort () at abort.c:79
#6  0x00007f2b2aefc39a in __assert_fail_base (
    fmt=0x7f2b2b0837d8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", 
    assertion=assertion@entry=0x560decb292e0 "!is_set() || (m_status == DA_OK_BULK && is_bulk_op())", file=file@entry=0x560decb29280 "/data/git/10.5_dbg/sql/sql_error.cc", line=line@entry=335, 
    function=function@entry=0x560decb29e00 <Diagnostics_area::set_ok_status(unsigned long long, unsigned long long, char const*)::__PRETTY_FUNCTION__> "void Diagnostics_area::set_ok_status(ulonglong, ulonglong, const char*)") at assert.c:92
#7  0x00007f2b2aefc412 in __GI___assert_fail (
    assertion=assertion@entry=0x560decb292e0 "!is_set() || (m_status == DA_OK_BULK && is_bulk_op())", file=file@entry=0x560decb29280 "/data/git/10.5_dbg/sql/sql_error.cc", line=line@entry=335, 
    function=function@entry=0x560decb29e00 <Diagnostics_area::set_ok_status(unsigned long long, unsigned long long, char const*)::__PRETTY_FUNCTION__> "void Diagnostics_area::set_ok_status(ulonglong, ulonglong, const char*)") at assert.c:101
#8  0x0000560debe723c3 in Diagnostics_area::set_ok_status (this=0x7f2affc1ab70, 
    affected_rows=affected_rows@entry=0, last_insert_id=last_insert_id@entry=0, 
    message=message@entry=0x560decb39602 "Statement prepared")
    at /data/git/10.5_dbg/sql/sql_error.cc:335
#9  0x0000560debee19dc in my_ok (message=0x560decb39602 "Statement prepared", id=0, 
    affected_rows_arg=0, thd=0x7f2affc15088) at /data/git/10.5_dbg/sql/sql_class.h:5155
#10 mysql_sql_stmt_prepare (thd=thd@entry=0x7f2affc15088)
    at /data/git/10.5_dbg/sql/sql_prepare.cc:2887
#11 0x0000560debebc36b in mysql_execute_command (thd=thd@entry=0x7f2affc15088)
    at /data/git/10.5_dbg/sql/sql_parse.cc:3910
#12 0x0000560debec97a5 in mysql_parse (thd=thd@entry=0x7f2affc15088, rawbuf=<optimized out>, 
    length=<optimized out>, parser_state=parser_state@entry=0x7f2b2c7c7450, 
    is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false)
    at /data/git/10.5_dbg/sql/sql_parse.cc:7926
#13 0x0000560debeb5664 in dispatch_command (command=command@entry=COM_QUERY, 
    thd=thd@entry=0x7f2affc15088, packet=packet@entry=0x7f2affc67089 "PREPARE stmt FROM @cmd", 
    packet_length=packet_length@entry=22, is_com_multi=is_com_multi@entry=false, 
    is_next_command=is_next_command@entry=false) at /data/git/10.5_dbg/sql/sql_parse.cc:1839
#14 0x0000560debeb3eaf in do_command (thd=0x7f2affc15088) at /data/git/10.5_dbg/sql/sql_parse.cc:1358
#15 0x0000560dec00da09 in do_handle_one_connection (connect=<optimized out>, 
    connect@entry=0x7f2b08e2b3a8, put_in_cache=put_in_cache@entry=true)
    at /data/git/10.5_dbg/sql/sql_connect.cc:1422
#16 0x0000560dec00dd38 in handle_one_connection (arg=arg@entry=0x7f2b08e2b3a8)
    at /data/git/10.5_dbg/sql/sql_connect.cc:1319
#17 0x0000560dec46acfc in pfs_spawn_thread (arg=0x7f2b2a445888)
    at /data/git/10.5_dbg/storage/perfschema/pfs.cc:2201
#18 0x00007f2b2bbef6db in start_thread (arg=0x7f2b2c7c8700) at pthread_create.c:463
#19 0x00007f2b2afed88f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.2.32 (dbg), 10.3.23 (dbg), 10.4.13 (dbg), 10.5.2 (dbg)

Bug confirmed not present in:
MariaDB: 10.1.45 (dbg), 10.1.45 (opt), 10.2.32 (opt), 10.3.23 (opt), 10.4.13 (opt), 10.5.2 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.47 (dbg), 5.6.47 (opt), 5.7.29 (dbg), 5.7.29 (opt), 8.0.19 (dbg), 8.0.19 (opt)



 Comments   
Comment by Roel Van de Paar [ 2020-03-27 ]

With credit to Elena who found a great shorter testcase:

SET @cmd:="SET @x=(SELECT 'a')";
SET @@SESSION.OPTIMIZER_SWITCH="materialization=OFF,in_to_exists=OFF";
PREPARE stmt FROM @cmd;

Comment by Roel Van de Paar [ 2020-05-08 ]

This is a fairly common assert it seems, and may block other bugs from showing. I am currently seeing another crash in:

!is_set() || (m_status == DA_OK_BULK && is_bulk_op())|SIGABRT|Diagnostics_area::set_ok_status|my_ok|mysql_load|mysql_execute_command

Vs the one from this bug:

!is_set() || (m_status == DA_OK_BULK && is_bulk_op())|SIGABRT|Diagnostics_area::set_ok_status|my_ok|mysql_sql_stmt_prepare|mysql_execute_command 

On a very different use case. A fix would be great to avoid filtering this generic assert and thereby masking other bugs.

Comment by Rucha Deodhar [ 2020-07-02 ]

Patch: https://github.com/MariaDB/server/commit/cb2cd9c3a43eacf489ac8a637f556cbbcc0bcaa1

Comment by Rucha Deodhar [ 2020-07-06 ]

Patch: https://github.com/MariaDB/server/commit/9ca75fef5eab8f5a26a067918806ce80ab3635ce

Comment by Sergei Golubchik [ 2020-07-10 ]

Looks good, but please combine these two commits into one

Generated at Thu Feb 08 09:11:52 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.