Bug #111827 Error log: Got error 155 when reading table
Submitted: 20 Jul 2023 11:55 Modified: 26 Jul 2023 7:06
Reporter: linkang zhang (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:5.7.42 OS:Any
Assigned to: CPU Architecture:Any
Tags: contributions, error log

[20 Jul 2023 11:55] linkang zhang
Description:
There is a bug reported in 2017: https://bugs.mysql.com/bug.php?id=86257

In fact, a lot of bugs with this problem have been reported, but be set to duplicated.
However, This bug has not been fixed yet.

So We want to contribute a bugfix for this bug.

And We hope MySQL Verification Team can accept this patch.

How to repeat:

// create database and use it.
mysql > DROP DATABASE test;

mysql > CREATE DATABASE test;

mysql > USE test;

// just create a normal table.
mysql > CREATE TABLE t1(c1 YEAR KEY,c2 INT,c3 BINARY);

// discard the tablespace of it.
mysql > ALTER TABLE t1 DISCARD TABLESPACE;

// just select the data of the table.
mysql > SELECT hex(c1),hex(c2) FROM t1 ORDER BY c1 DESC;

// and then, we find 'error 155' in master-error.log

Suggested fix:

// We will contribute a patch to fix this bug. This patch is only 6 lines.

// And We will explain every single line for this code.

// The first line:
// In fact, In this case, MySQL just cann't find the talespace of table instead of 'NO_SUCH_TABLE'.
// So, We think HA_ERR_NO_SUCH_TABLE is not clear, and the error 'HA_ERR_TABLESPACE_MISSING' is more clear.
// In fact, in other cases, when MySQL get the error DB_TABLESPACE_DELETED in InnoDB, MySQL will  change it to HA_ERR_TABLESPACE_MISSING. 
// For example, in convert_error_code_to_mysql(..),MySQL convert DB_TABLESPACE_DELETED to HA_ERR_TABLESPACE_MISSING rather than HA_ERR_NO_SUCH_TABLE.

diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index 2b9be6f65ef..5d760657a7b 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -9233,7 +9233,7 @@ ha_innobase::index_read(
                        table->s->table_name.str);

                table->status = STATUS_NOT_FOUND;
-               error = HA_ERR_NO_SUCH_TABLE;
+               error = HA_ERR_TABLESPACE_MISSING;
                break;

// Other lines:
// MySQL use report_handler_error() when MySQL want to select some data.
// So, we add more clear error-message in file sql_executor.cc. we use this message.

diff --git a/sql/sql_executor.cc b/sql/sql_executor.cc
index 0972dadbbc8..e4da6b8e407 100644
--- a/sql/sql_executor.cc
+++ b/sql/sql_executor.cc
@@ -1812,12 +1812,16 @@ int report_handler_error(TABLE *table, int error)
     table->status= STATUS_GARBAGE;
     return -1;                                 // key not found; ok
   }
+
+  if (error == HA_ERR_TABLESPACE_MISSING && !table->in_use->killed)
+    sql_print_error("The table '%s' doesn't have a corresponding tablespace",
+                    table->s->table_name.str);
   /*
     Do not spam the error log with these temporary errors:
        LOCK_DEADLOCK LOCK_WAIT_TIMEOUT TABLE_DEF_CHANGED
     Also skip printing to error log if the current thread has been killed.
   */
-  if (error != HA_ERR_LOCK_DEADLOCK &&
+  else if (error != HA_ERR_LOCK_DEADLOCK &&
       error != HA_ERR_LOCK_WAIT_TIMEOUT &&
       error != HA_ERR_TABLE_DEF_CHANGED &&
       !table->in_use->killed)

// That is all the code.

// We provide .test and .result for this patch.

// By the way, we fix all the affected testcases.
[20 Jul 2023 12:01] linkang zhang
The .result file of this patch.

Attachment: result.diff (application/octet-stream, text), 1.04 KiB.

[20 Jul 2023 12:02] linkang zhang
The .test file for this patch.

Attachment: test.diff (application/octet-stream, text), 2.06 KiB.

[20 Jul 2023 12:05] linkang zhang
We fix all the affected testcases.

Attachment: fix_all_the_affected_testcases.diff (application/octet-stream, text), 2.76 KiB.

[21 Jul 2023 11:42] MySQL Verification Team
Hello linkang zhang,

Thank you for the report and contribution.
Kindly request you to re-upload the patch via "Contributions" tab otherwise we will not be able to accept it.

Technically, newer bug(Bug #111827) are set to be duplicate of old bug(Bug #86257) but I'm verifying instead of marking this as a duplicate of Bug #86257 so as contribution is not lost. Alternatively, you can contribute to the base bug(Bug #86257) so that this one is closed as duplicate. Thank you.

regards,
Umesh
[21 Jul 2023 16:46] linkang zhang
The patch I want to contribute.

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: source_code.diff (application/octet-stream, text), 1.43 KiB.

[21 Jul 2023 16:46] linkang zhang
The test case for this bugfix.

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: result.diff (application/octet-stream, text), 1.04 KiB.

[21 Jul 2023 16:47] linkang zhang
The result file for this bugfix.

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: result.diff (application/octet-stream, text), 1.04 KiB.

[21 Jul 2023 16:48] linkang zhang
All the affected testcase is fixed in this file.

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: fix_all_the_affected_testcases.diff (application/octet-stream, text), 2.76 KiB.

[21 Jul 2023 17:06] linkang zhang
Thank you for dealing with this contribution, I have re-uploaded all the file for this bugfix.

Best wishes.
[26 Jul 2023 7:06] linkang zhang
Hi, MySQL Verification Team 

We want to confirm if this bugfix is accepted.