Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-42132

CTAS over a flushed vector-indexed table fails with error 1939 when innodb_force_primary_key is enabled

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 11.8, 12.3, 13.1, 12.3.3
    • 11.8, 12.3, 13.1
    • Vector search
    • MariaDB 12.3.3-MariaDB-ubu2404 on Linux x86_64

    Description

      With innodb_force_primary_key enabled, a cold CREATE TABLE ... AS SELECT from an InnoDB table with a vector index fails during discovery of the vector index's internal table. The destination explicitly has a primary key, while the equivalent CTAS succeeds with enforcement disabled.

      This occurs when CTAS reads a flushed InnoDB table through a vector index while primary-key creation policy is enabled.

      The recorded initial value of @@GLOBAL.innodb_force_primary_key was 0. Check that prerequisite before running the case; if the value differs, do not continue without arranging to restore the existing server configuration afterward.

      SELECT @@GLOBAL.innodb_force_primary_key;

      With that query returning 0, run the following SQL in one session with permission to change global variables:

      CREATE DATABASE vec_test;
      USE vec_test;
      CREATE TABLE vectors (id INT PRIMARY KEY, v VECTOR(1) NOT NULL, VECTOR INDEX v_idx(v)) ENGINE=InnoDB;
      INSERT INTO vectors VALUES (1,VEC_FromText('[1]'));
      FLUSH TABLES vectors;
      CREATE TABLE ctas_control (id INT PRIMARY KEY) ENGINE=InnoDB AS SELECT id FROM vectors ORDER BY VEC_DISTANCE_EUCLIDEAN(v,VEC_FromText('[1]')) LIMIT 1;
      SELECT 'control_ok', COUNT(*)=1 AND MIN(id)=1 FROM ctas_control;
      SET GLOBAL innodb_force_primary_key=1;
      SELECT 'select_ok', id FROM vectors ORDER BY VEC_DISTANCE_EUCLIDEAN(v,VEC_FromText('[1]')) LIMIT 1;
      EXPLAIN SELECT id FROM vectors ORDER BY VEC_DISTANCE_EUCLIDEAN(v,VEC_FromText('[1]')) LIMIT 1;
      FLUSH TABLES vectors;
      CREATE TABLE result (id INT PRIMARY KEY) ENGINE=InnoDB AS SELECT id FROM vectors ORDER BY VEC_DISTANCE_EUCLIDEAN(v,VEC_FromText('[1]')) LIMIT 1;
      SELECT 'ctas_ok', COUNT(*)=1 AND MIN(id)=1 FROM result;

      The recorded control CTAS returned control_ok 1. The direct SELECT returned id 1, and EXPLAIN selected v_idx. The final CTAS failed with:

      ERROR 1939 (HY000): Engine InnoDB failed to discover table `vec_test`.`vectors` with 'CREATE TABLE i (                     layer tinyint not null,            tref varbinary(4),                vec blob not null,                 neighbors blob not null,           unique (tref),                     key (layer))                     '

      The server log additionally reported error 126 while reading vectors and said its index was corrupt. The server remained running, but result was not created.

      The final CTAS should succeed and copy id 1. Its destination already declares id INT PRIMARY KEY, so enabling innodb_force_primary_key should not prevent discovery of an existing source table's internal vector-index definition.

      Restore the recorded initial setting and remove the database after the test:

      SET GLOBAL innodb_force_primary_key=0;
      DROP DATABASE IF EXISTS vec_test;

      Attachments

        Issue Links

          Activity

            People

              serg Sergei Golubchik
              faner fan
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.