Bug #97271 Assertion ".num_rows == .~.ha_rows"
Submitted: 17 Oct 2019 12:26 Modified: 10 Dec 2019 20:16
Reporter: Hrvoje Matijakovic Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S6 (Debug Builds)
Version:8.0.18, 8.0.17 OS:Linux
Assigned to: CPU Architecture:x86
Tags: regression

[17 Oct 2019 12:26] Hrvoje Matijakovic
Description:
Running the query results in the assertion on 8.0.18 (debug):

gdb from the debug build:
Core was generated by `/sdc/MS151019-mysql-8.0.18-linux-x86_64-debug/bin/mysqld --no-defaults --basedi'.
Program terminated with signal 6, Aborted.
#0  0x00007f6feabcaa61 in __pthread_kill (threadid=<optimized out>, signo=6) at ../nptl/sysdeps/unix/sysv/linux/pthread_kill.c:59
59        val = INTERNAL_SYSCALL (tgkill, err, 3, THREAD_GETMEM (THREAD_SELF, pid),
(gdb) bt
+bt
#0  0x00007f6feabcaa61 in __pthread_kill (threadid=<optimized out>, signo=6) at ../nptl/sysdeps/unix/sysv/linux/pthread_kill.c:59
#1  0x00000000048f003d in my_write_core (sig=6) at /sdc/MS-8.0.18_dbg/mysys/stacktrace.cc:305
#2  0x00000000035e030e in handle_fatal_signal (sig=6) at /sdc/MS-8.0.18_dbg/sql/signal_handler.cc:169
#3  <signal handler called>
#4  0x00007f6fe8a12337 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:55
#5  0x00007f6fe8a13a28 in __GI_abort () at abort.c:90
#6  0x00007f6fe8a0b156 in __assert_fail_base (fmt=0x7f6fe8b66be0 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x5c52d5c "*num_rows == (~(ha_rows)0)", file=file@entry=0x5c51ee0 "/sdc/MS-8.0.18_dbg/sql/handler.cc", line=line@entry=3068, function=function@entry=0x5c55540 <handler::handle_record
s_error(int, unsigned long long*)::__PRETTY_FUNCTION__> "int handler::handle_records_error(int, ha_rows*)") at assert.c:92
#7  0x00007f6fe8a0b202 in __GI___assert_fail (assertion=0x5c52d5c "*num_rows == (~(ha_rows)0)", file=0x5c51ee0 "/sdc/MS-8.0.18_dbg/sql/handler.cc", line=3068, function=0x5c55540 <handler::handle_records_error(int, unsigned long long*)::__PRETTY_FUNCTION__> "int handler::handle_records_error(int, ha_rows*)") at assert
.c:101
#8  0x00000000037836f6 in handler::handle_records_error (this=0x7f6f8f1f3028, error=155, num_rows=0x7f6fe73b20f0) at /sdc/MS-8.0.18_dbg/sql/handler.cc:3068
#9  0x00000000032af626 in handler::ha_records (this=0x7f6f8f1f3028, num_rows=0x7f6fe73b20f0) at /sdc/MS-8.0.18_dbg/sql/handler.h:4801
#10 0x000000000338cb69 in get_exact_record_count (qep_tab=0x7f6f8f1c0ec0, table_count=1, error=0x7f6fe73b214c) at /sdc/MS-8.0.18_dbg/sql/sql_executor.cc:5360
#11 0x0000000003395663 in UnqualifiedCountIterator::Read (this=0x7f6f8f1c1140) at /sdc/MS-8.0.18_dbg/sql/sql_executor.cc:8696
#12 0x0000000003517bcc in SELECT_LEX_UNIT::ExecuteIteratorQuery (this=0x7f6f8f1bf338, thd=0x7f6f8f020000) at /sdc/MS-8.0.18_dbg/sql/sql_union.cc:1505
#13 0x0000000003518026 in SELECT_LEX_UNIT::execute (this=0x7f6f8f1bf338, thd=0x7f6f8f020000) at /sdc/MS-8.0.18_dbg/sql/sql_union.cc:1577
#14 0x000000000347679e in Sql_cmd_dml::execute_inner (this=0x7f6f8f1c0478, thd=0x7f6f8f020000) at /sdc/MS-8.0.18_dbg/sql/sql_select.cc:899
#15 0x0000000003475ec3 in Sql_cmd_dml::execute (this=0x7f6f8f1c0478, thd=0x7f6f8f020000) at /sdc/MS-8.0.18_dbg/sql/sql_select.cc:704
#16 0x0000000003413287 in mysql_execute_command (thd=0x7f6f8f020000, first_level=true) at /sdc/MS-8.0.18_dbg/sql/sql_parse.cc:4453
#17 0x0000000003415bb6 in mysql_parse (thd=0x7f6f8f020000, parser_state=0x7f6fe73b3ae0) at /sdc/MS-8.0.18_dbg/sql/sql_parse.cc:5257
#18 0x000000000340b046 in dispatch_command (thd=0x7f6f8f020000, com_data=0x7f6fe73b4b90, command=COM_QUERY) at /sdc/MS-8.0.18_dbg/sql/sql_parse.cc:1765
#19 0x000000000340958b in do_command (thd=0x7f6f8f020000) at /sdc/MS-8.0.18_dbg/sql/sql_parse.cc:1273
#20 0x00000000035caf99 in handle_connection (arg=0x7f6f9a07a3e0) at /sdc/MS-8.0.18_dbg/sql/conn_handler/connection_handler_per_thread.cc:302
#21 0x00000000050ac3c0 in pfs_spawn_thread (arg=0x7f6fe686a360) at /sdc/MS-8.0.18_dbg/storage/perfschema/pfs.cc:2854
#22 0x00007f6feabc5e65 in start_thread (arg=0x7f6fe73b5700) at pthread_create.c:307
#23 0x00007f6fe8ada88d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
(gdb) quit

Can't reproduce it on the release build (results in an error instead of assertion):root@bionic:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.18 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> drop database test;
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE DATABASE test;
Query OK, 1 row affected (0.01 sec)

mysql> USE test;
Database changed
mysql> CREATE TABLE t1(a int)PARTITION BY LIST (a) (PARTITION x1 VALUES IN (2),PARTITION x2 VALUES IN (3));
Query OK, 0 rows affected (0.12 sec)

mysql> ALTER TABLE t1 DISCARD TABLESPACE;
Query OK, 0 rows affected (0.04 sec)

mysql> SELECT COUNT(*)FROM t1;
ERROR 1814 (HY000): Tablespace has been discarded for table 'test/t1#P#x1'

How to repeat:
CREATE DATABASE test;
USE test;
CREATE TABLE t1(a int)PARTITION BY LIST (a) (PARTITION x1 VALUES IN (2),PARTITION x2 VALUES IN (3));
ALTER TABLE t1 DISCARD TABLESPACE;
SELECT COUNT(*)FROM t1;
[18 Oct 2019 5:09] MySQL Verification Team
Hello Hrvoje Matijakovic,

Thank you for the bug report and test case.
Confirmed that issue exists since 8.0.17.

regards,
Umesh
[10 Dec 2019 20:16] Daniel Price
Posted by developer:
 
Fixed as of the upcoming 8.0.20 release, and here's the changelog entry:

A query executed on a partitioned table with a discarded tablespace
raised an assertion failure.