Skip to content

Support Generated Invisible Primary Keys (GIPK) round-trip #23

@kyleconroy

Description

@kyleconroy

Summary

When sql_generate_invisible_primary_key=ON, MySQL silently injects a my_row_id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY INVISIBLE column on InnoDB tables that have no PK. The output of SHOW CREATE TABLE then includes that column. Marino currently parses INVISIBLE columns but should be exercised against — and ideally round-trip — the canonical GIPK DDL emitted by the server.

MySQL version

Introduced in MySQL 8.0.30.

Current state in marino

INVISIBLE is supported (parser/parser.y:7225-7229). The composite BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY INVISIBLE declaration is expressible. What is missing is:

  1. A test fixture covering the GIPK column declaration as emitted by SHOW CREATE TABLE so we can guarantee round-trip.
  2. Parsing the related session variables and the new replication option REQUIRE_TABLE_PRIMARY_KEY_CHECK = GENERATE (added in 8.0.32) — which depends on issue Remove stale TiDB references from documentation #12.

Example SQL

Server-side reproduction:

SET sql_generate_invisible_primary_key = ON;
CREATE TABLE gipk_t (col1 INT);
SHOW CREATE TABLE gipk_t;

The SHOW CREATE TABLE output (which marino must round-trip) is:

CREATE TABLE `gipk_t` (
  `my_row_id` bigint unsigned NOT NULL AUTO_INCREMENT /*!80023 INVISIBLE */,
  `col1` int DEFAULT NULL,
  PRIMARY KEY (`my_row_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

Toggling visibility after creation:

ALTER TABLE gipk_t ALTER COLUMN my_row_id SET VISIBLE;
ALTER TABLE gipk_t ALTER COLUMN my_row_id SET INVISIBLE;

The replication option (depends on issue #12):

CHANGE REPLICATION SOURCE TO REQUIRE_TABLE_PRIMARY_KEY_CHECK = GENERATE;

Validation

Both DDL forms above run successfully against MySQL 9.2.0 Community with sql_generate_invisible_primary_key=ON.

Notes for the implementer

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions