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

create vector table failed with VECTOR INDEX when innodb_force_primary_key=on

    XMLWordPrintable

Details

    • Can result in unexpected behaviour
    • Q3/2025 Maintenance

    Description

      when I set the database variables innodb_force_primary_key=on ,create vetor table with not vector index succeed,but with vector index will failed because of table struct ? and table struct file can not be found in table's data path,but table's data file can be found. when I set innodb_force_primary_key=off, the problem can be solved .

      1) innodb_force_primary_key=on

      MariaDB [tt]> use tt
      Database changed
      MariaDB [tt]> CREATE TABLE v (
          ->      id INT PRIMARY KEY,
          ->      v VECTOR(5) NOT NULL,
          ->      VECTOR INDEX (v)
          -> );
      ERROR 1939 (HY000): Engine InnoDB failed to discover table `tt`.`v` with 'CREATE TABLE i (                     layer tinyint not null,            tref varbinary(4),                vec blob not null,                 neighbors blob not null,           unique (tref),                     key (layer))                     '
      MariaDB [tt]> drop table v;
      Query OK, 0 rows affected (0.006 sec)
       
      MariaDB [tt]> exit
      

      2) innodb_force_primary_key=off

      MariaDB [tt]> CREATE TABLE products ( name varchar(128), description varchar(2000), embedding VECTOR(4) NOT NULL, VECTOR INDEX (embedding) M=6 DISTANCE=euclidean) ENGINE=InnoDB;
      ERROR 1173 (42000): This table type requires a primary key
      MariaDB [tt]> set global '%primary%';
      ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''%primary%'' at line 1
      MariaDB [tt]> set global '%p^Cma%';
      MariaDB [tt]> show variables like '%primary%';
      +--------------------------+-------+
      | Variable_name            | Value |
      +--------------------------+-------+
      | innodb_force_primary_key | ON    |
      +--------------------------+-------+
      1 row in set (0.003 sec)
       
      MariaDB [tt]> set innodb_force_primary_key=off;
      ERROR 1229 (HY000): Variable 'innodb_force_primary_key' is a GLOBAL variable and should be set with SET GLOBAL
      MariaDB [tt]> set global innodb_force_primary_key=off;
      Query OK, 0 rows affected (0.000 sec)
       
      MariaDB [tt]> CREATE TABLE products ( name varchar(128), description varchar(2000), embedding VECTOR(4) NOT NULL, VECTOR INDEX (embedding) M=6 DISTANCE=euclidean) ENGINE=InnoDB;
      Query OK, 0 rows affected (0.010 sec)
       
      MariaDB [tt]> CREATE TABLE embeddings ( doc_id BIGINT UNSIGNED PRIMARY KEY, embedding VECTOR(1536) NOT NULL, VECTOR INDEX (embedding) M=8 DISTANCE=cosine );
      Query OK, 0 rows affected (0.010 sec)
       
      MariaDB [tt]> show tables;
      +--------------+
      | Tables_in_tt |
      +--------------+
      | embeddings   |
      | products     |
      | test         |
      | tt           |
      +--------------+
      4 rows in set (0.000 sec)
       
      MariaDB [tt]> CREATE TABLE doc_vectors( doc_id INT PRIMARY KEY, metadata VARCHAR(4000), content TEXT, embedding VECTOR(1024) NOT NULL, VECTOR INDEX (embedding) M=8 DISTANCE=cosine );
      Query OK, 0 rows affected (0.011 sec)
      

      Attachments

        Issue Links

          Activity

            People

              serg Sergei Golubchik
              williamChung yuehuizhong
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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