Bug #111292 GIPK still dumped in SK even with skip GIPK
Submitted: 6 Jun 2023 11:36 Modified: 8 Jun 2023 13:39
Reporter: liu hickey (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: mysqldump Command-line Client Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[6 Jun 2023 11:36] liu hickey
Description:
GIPK(generated invisible primary key) should be filtered out if mysqldump with skip-generated-invisible-primary-key.

How to repeat:
# 1. create table with index containing gipk
 /* make sure @@sql_generate_invisible_primary_key = 0, which is default value */
 CREATE TABLE t1 (my_row_id bigint unsigned NOT NULL AUTO_INCREMENT INVISIBLE, f INT, PRIMARY KEY(my_row_id));
 ALTER TABLE t1 ADD INDEX(f, my_row_id);
 INSERT INTO t1 VALUES (1), (3), (7), (8), (4);

# 2. dump table with skip gipk
../bin/mysqldump --databases test --skip-generated-invisible-primary-key
should be shown:
```
CREATE TABLE `t1` (
  `f` int DEFAULT NULL,
  KEY `f` (`f`,`my_row_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
```

# 3. failed to source dump sql
ERROR 1072 (42000): Key column 'my_row_id' doesn't exist in table

Suggested fix:
```
diff --git a/mysql-test/t/mysqlpump_basic.test b/mysql-test/t/mysqlpump_basic.test
index 42d13d7c02b..874f1ad10d2 100644
--- a/mysql-test/t/mysqlpump_basic.test
+++ b/mysql-test/t/mysqlpump_basic.test
@@ -684,6 +684,7 @@ SET @saved_session_sql_generate_invisible_primary_key =
 # key column.
 CREATE TABLE t1 (my_row_id bigint unsigned NOT NULL AUTO_INCREMENT INVISIBLE, f INT,
                  PRIMARY KEY(my_row_id));
+ALTER TABLE t1 ADD INDEX(f, my_row_id);
 INSERT INTO t1 VALUES (1), (3), (7), (8), (4);

 SET SESSION sql_generate_invisible_primary_key=ON;
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 0fc83dd572d..6a7e999ab88 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -2242,6 +2242,10 @@ bool store_create_info(THD *thd, Table_ref *table_list, String *packet,
     packet->append(STRING_WITH_LEN(" ("));

     for (uint j = 0; j < key_info->user_defined_key_parts; j++, key_part++) {
+      assert(key_part->field);
+      if (skip_gipk && key_part->field->is_hidden_by_user())
+        continue;
+
       if (j) packet->append(',');

       if (key_part->field) {

```
[6 Jun 2023 11:40] liu hickey
bug111292_dump_gipk.patch

Attachment: bug111292_dump_gipk.patch (application/octet-stream, text), 3.60 KiB.

[6 Jun 2023 12:55] MySQL Verification Team
Hi Mr. liu,

Thank you for your bug report.

We are very interested in verifying and fixing this bug.

However, we need additional feedback from you.

First of all, our current version is 8.0.33,  so we would like you to check whether your report still applies to that release, as well.

Next, since the mysqlpump utility will be soon deprecated, we should appreciate a test done with mysqldump.

When we get the feedback from you and we check it out ourselves, we shall be happy to verify it.

We are waiting on your feedback.
[8 Jun 2023 11:45] liu hickey
1. I verified for 8.0.33, this bug still repeatable (also repeatable in 8.0 master).
2. Though I added repeatable SQL in mysql-test/t/mysqlpump_basic.test, but you can see, mysqldump is used for step2, not mysqlpump. As you mentioned that mysqlbump will be deprecated, they should add into some where like mysqldump_*.test.
[8 Jun 2023 13:39] MySQL Verification Team
Hi Mr. liu,

Thank you for the additional info ....

We were able to repeat the behaviour.

These are the contents of the dumped file:

-------------------------------------------------

- MySQL dump 10.13  Distrib 8.0.33, for macos13.3 (x86_64)
--
-- Host: localhost    Database: test
-- ------------------------------------------------------
-- Server version	8.0.33

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Current Database: `test`
--

CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;

USE `test`;

--
-- Table structure for table `t1`
--

DROP TABLE IF EXISTS `t1`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `t1` (
  `f` int DEFAULT NULL,
  KEY `f` (`f`,`my_row_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `t1`
--

LOCK TABLES `t1` WRITE;
/*!40000 ALTER TABLE `t1` DISABLE KEYS */;
INSERT INTO `t1` VALUES (1),(3),(4),(7),(8);
/*!40000 ALTER TABLE `t1` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2023-06-08 16:31:57

-------------------------------------------------

This is the error from the loading of the same file:

mysql -uUSER -p < xx

ERROR 1072 (42000) at line 33: Key column 'my_row_id' doesn't exist in table

Hence, the test case is repeated, which makes your report a verified bug for the version 8.0.

Thank you very much for your report and even much more, thank you very much for your patches, which are very useful.

This is now a verified bug report.