Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ scalability_jobs_*

.serena
.merge_conflicts
build.dir/
14 changes: 9 additions & 5 deletions include/my_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,11 @@ enum ha_key_alg {
SEs default algorithm for keys in mysql_prepare_create_table().
*/
HA_KEY_ALG_SE_SPECIFIC = 0,
HA_KEY_ALG_BTREE = 1, /* B-tree. */
HA_KEY_ALG_RTREE = 2, /* R-tree, for spatial searches */
HA_KEY_ALG_HASH = 3, /* HASH keys (HEAP, NDB). */
HA_KEY_ALG_FULLTEXT = 4 /* FULLTEXT. */
HA_KEY_ALG_BTREE = 1, /* B-tree. */
HA_KEY_ALG_RTREE = 2, /* R-tree, for spatial searches */
HA_KEY_ALG_HASH = 3, /* HASH keys (HEAP, NDB). */
HA_KEY_ALG_FULLTEXT = 4, /* FULLTEXT. */
HA_KEY_ALG_VECTOR = 5, /* VECTOR. */
};

/* Storage media types */
Expand Down Expand Up @@ -521,11 +522,14 @@ enum ha_base_keytype {
#define HA_USES_COMMENT (1 << 12)
/** Key was automatically created to support Foreign Key constraint. */
#define HA_GENERATED_KEY (1 << 13)
/** Vector key (Percona). */
#define HA_VECTOR (1 << 30)

/* The combination of the above can be used for key type comparison. */
#define HA_KEYFLAG_MASK \
(HA_NOSAME | HA_PACK_KEY | HA_AUTO_KEY | HA_BINARY_PACK_KEY | HA_FULLTEXT | \
HA_UNIQUE_CHECK | HA_SPATIAL | HA_NULL_ARE_EQUAL | HA_GENERATED_KEY)
HA_UNIQUE_CHECK | HA_SPATIAL | HA_NULL_ARE_EQUAL | HA_GENERATED_KEY | \
HA_VECTOR)

/** Fulltext index uses [pre]parser */
#define HA_USES_PARSER (1 << 14)
Expand Down
266 changes: 266 additions & 0 deletions mysql-test/suite/percona/r/vector_index_syntax.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
CREATE TABLE t1 (
id BIGINT UNSIGNED PRIMARY KEY,
v1 VECTOR( 1234 ),
VECTOR KEY( v1 ) TYPE hnsw WITH ( M = 6 )
);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` bigint unsigned NOT NULL,
`v1` vector(1234) DEFAULT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v1` (`v1`) TYPE `hnsw` WITH (`M`=6)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
t1 0 PRIMARY 1 id A 0 NULL NULL BTREE YES NULL
t1 1 v1 1 v1 A 0 1 NULL YES VECTOR YES NULL
ALTER TABLE t1 DROP PRIMARY KEY;
ERROR HY000: Vector index can only be created in tables with a BIGINT UNSIGNED primary key.
ALTER TABLE t1 ADD INDEX v2 (v1);
ERROR 42000: Specified key was too long; max key length is 3072 bytes
ALTER TABLE t1 ADD INDEX v2 (v1(1));
ALTER TABLE t1 ADD UNIQUE (v1);
ERROR 42000: Specified key was too long; max key length is 3072 bytes
ALTER TABLE t1 ADD UNIQUE (v1(1));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` bigint unsigned NOT NULL,
`v1` vector(1234) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `v1_2` (`v1`(1)),
VECTOR KEY `v1` (`v1`) TYPE `hnsw`,
KEY `v2` (`v1`(1))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
ALTER TABLE t1 DROP INDEX v1;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` bigint unsigned NOT NULL,
`v1` vector(1234) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `v1_2` (`v1`(1)),
KEY `v2` (`v1`(1))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
t1 0 PRIMARY 1 id A 0 NULL NULL BTREE YES NULL
t1 0 v1_2 1 v1 A 0 1 NULL YES BTREE YES NULL
t1 1 v2 1 v1 A 0 1 NULL YES BTREE YES NULL
DROP TABLE t1;
CREATE TABLE t1 (
id BIGINT UNSIGNED PRIMARY KEY,
v1 VECTOR( 8 )
);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` bigint unsigned NOT NULL,
`v1` vector(8) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
t1 0 PRIMARY 1 id A 0 NULL NULL BTREE YES NULL
ALTER TABLE t1 ADD INDEX ix (v1);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` bigint unsigned NOT NULL,
`v1` vector(8) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `ix` (`v1`(32))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
t1 0 PRIMARY 1 id A 0 NULL NULL BTREE YES NULL
t1 1 ix 1 v1 A 0 32 NULL YES BTREE YES NULL
ALTER TABLE t1 ADD VECTOR INDEX vx (v1) TYPE hnsw;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` bigint unsigned NOT NULL,
`v1` vector(8) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `ix` (`v1`(32)),
VECTOR KEY `vx` (`v1`) TYPE `hnsw`
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
t1 0 PRIMARY 1 id A 0 NULL NULL BTREE YES NULL
t1 1 ix 1 v1 A 0 32 NULL YES BTREE YES NULL
t1 1 vx 1 v1 A 0 1 NULL YES VECTOR YES NULL
DROP TABLE t1;
CREATE TABLE t1 (
id BIGINT UNSIGNED PRIMARY KEY,
v1 VECTOR( 1234 ),
VECTOR KEY( v1 ) TYPE hnsw COMMENT 'abc' WITH ( M = 6 )
);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WITH ( M = 6 )
)' at line 4
CREATE TABLE t1 (
id BIGINT UNSIGNED PRIMARY KEY,
v1 VECTOR( 1234 ),
VECTOR KEY( v1 ) TYPE hnsw WITH ( M = 6 ) COMMENT 'abc'
);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` bigint unsigned NOT NULL,
`v1` vector(1234) DEFAULT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v1` (`v1`) TYPE `hnsw` WITH (`M`=6) COMMENT 'abc'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
t1 0 PRIMARY 1 id A 0 NULL NULL BTREE YES NULL
t1 1 v1 1 v1 A 0 1 NULL YES VECTOR abc YES NULL
DROP TABLE t1;
CREATE TABLE t1 (
id BIGINT UNSIGNED PRIMARY KEY,
v1 VECTOR( 1234 )
);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` bigint unsigned NOT NULL,
`v1` vector(1234) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
t1 0 PRIMARY 1 id A 0 NULL NULL BTREE YES NULL
CREATE VECTOR INDEX ix ON t1(v1) TYPE Hnsw WITH ();
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
CREATE VECTOR INDEX ix ON t1(v1) TYPE Hnsw WITH ( M = 6.0 );
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '6.0 )' at line 1
CREATE VECTOR INDEX ix ON t1(v1) TYPE Hnsw WITH ( M = "6" );
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"6" )' at line 1
CREATE VECTOR INDEX ix ON t1(v1) TYPE Hnsw WITH ( bogus = 1 );
ERROR HY000: Illegal index construction parameter: bogus.
CREATE VECTOR INDEX ix ON t1(v1) TYPE no_such_type;
ERROR HY000: The index type no_such_type is not supported for vector indexes.
CREATE VECTOR INDEX ix ON t1(v1);
ERROR HY000: Type is required for vector indexes.
CREATE VECTOR INDEX ix ON t1(v1) TYPE Hnsw WITH ( m = 6 );
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
t1 0 PRIMARY 1 id A 0 NULL NULL BTREE YES NULL
t1 1 ix 1 v1 A 0 1 NULL YES VECTOR YES NULL
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` bigint unsigned NOT NULL,
`v1` vector(1234) DEFAULT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `ix` (`v1`) TYPE `Hnsw` WITH (`m`=6)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
ALTER TABLE t1 DROP PRIMARY KEY;
ERROR HY000: Vector index can only be created in tables with a BIGINT UNSIGNED primary key.
ALTER TABLE t1 DROP INDEX ix;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` bigint unsigned NOT NULL,
`v1` vector(1234) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
t1 0 PRIMARY 1 id A 0 NULL NULL BTREE YES NULL
CREATE VECTOR INDEX ix ON t1(v1) TYPE Hnsw WITH ( m = 6, metric = Euclidean );
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
t1 0 PRIMARY 1 id A 0 NULL NULL BTREE YES NULL
t1 1 ix 1 v1 A 0 1 NULL YES VECTOR YES NULL
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` bigint unsigned NOT NULL,
`v1` vector(1234) DEFAULT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `ix` (`v1`) TYPE `Hnsw` WITH (`m`=6, `metric`=Euclidean)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
ALTER TABLE t1 DROP INDEX ix;
CREATE VECTOR INDEX ix ON t1(v1) TYPE Hnsw WITH ( metric = Euclidean, m = 6 );
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
t1 0 PRIMARY 1 id A 0 NULL NULL BTREE YES NULL
t1 1 ix 1 v1 A 0 1 NULL YES VECTOR YES NULL
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` bigint unsigned NOT NULL,
`v1` vector(1234) DEFAULT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `ix` (`v1`) TYPE `Hnsw` WITH (`metric`=Euclidean, `m`=6)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
ALTER TABLE t1 DROP INDEX ix;
ALTER TABLE t1 DROP PRIMARY KEY;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` bigint unsigned NOT NULL,
`v1` vector(1234) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
DROP TABLE t1;
CREATE TABLE t1 (
id BIGINT UNSIGNED PRIMARY KEY,
v1 VECTOR( 1234 ),
VECTOR KEY( v1 )
);
ERROR HY000: Type is required for vector indexes.
CREATE TABLE t1 (
id BIGINT UNSIGNED PRIMARY KEY,
v1 VECTOR( 1234 ),
VECTOR KEY( v1 ) USING btree
);
ERROR HY000: The index type BTREE is not supported for vector indexes.
CREATE TABLE t1 (
id BIGINT UNSIGNED PRIMARY KEY,
v1 VECTOR( 1234 ),
VECTOR KEY( v1 ) USING rtree
);
ERROR HY000: The index type RTREE is not supported for vector indexes.
CREATE TABLE t1 (
id BIGINT UNSIGNED PRIMARY KEY,
v1 VECTOR( 1234 ),
VECTOR KEY( v1 ) USING hash
);
ERROR HY000: The index type HASH is not supported for vector indexes.
CREATE TABLE t1 (
id BIGINT UNSIGNED PRIMARY KEY,
c INT,
VECTOR KEY (c) TYPE hnsw
);
ERROR HY000: A VECTOR index may only contain a vector type column.
CREATE TABLE t1 (
id BIGINT UNSIGNED PRIMARY KEY,
v1 VECTOR( 1234 ),
v2 VECTOR( 1234 )
);
CREATE VECTOR INDEX ix ON t1( v1, v2 ) TYPE hnsw;
ERROR 42000: Too many key parts specified; max 1 parts allowed
DROP TABLE t1;
CREATE TABLE t1 (
id BIGINT UNSIGNED NOT NULL,
v1 VECTOR(8),
UNIQUE KEY u_id (id),
VECTOR KEY (v1) TYPE hnsw
);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` bigint unsigned NOT NULL,
`v1` vector(8) DEFAULT NULL,
UNIQUE KEY `u_id` (`id`),
VECTOR KEY `v1` (`v1`) TYPE `hnsw`
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
SHOW INDEXES FROM t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
t1 0 u_id 1 id A 0 NULL NULL BTREE YES NULL
t1 1 v1 1 v1 A 0 1 NULL YES VECTOR YES NULL
DROP TABLE t1;
Loading
Loading