Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-33408 Introduce session variables to manage HNSW index parameters #3226

Open
wants to merge 28 commits into
base: bb-11.4-vec-vicentiu-hugo
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7b87e01
MDEV-32885 VEC_DISTANCE() function
vuvova Nov 25, 2023
ed8b6da
make INFORMATION_SCHEMA.STATISTICS.COMMENT not nullable
vuvova Jan 19, 2024
4bea056
fix main.plugin_vars test to cleanup after itself
vuvova Feb 5, 2024
62e6031
cleanup: spaces, casts, comments
vuvova Jan 8, 2024
e409868
cleanup: pass TABLE_SHARE to store_key_options()
vuvova Jan 26, 2024
bc8a7a3
reject invalid spatial key declarations in the parser
vuvova Jan 8, 2024
16846b5
cleanup: remove unconditional #ifdef's
vuvova Jan 10, 2024
2cd2320
cleanup: lex_string_set3()
vuvova Jan 27, 2024
8ddb99a
cleanup: Queue and Bounded_queue
vuvova Feb 6, 2024
ef14f42
cleanup: key algorithm vs key flags
vuvova Jan 14, 2024
022bc34
cleanup: make_long_hash_field_name() and add_hash_field()
vuvova Jan 18, 2024
38e84a8
cleanup: generalize ER_SPATIAL_CANT_HAVE_NULL
vuvova Jan 17, 2024
f1d0352
cleanup: generalize ER_INNODB_NO_FT_TEMP_TABLE
vuvova Jan 25, 2024
0cbd050
cleanup: extract ha_create_table_from_share()
vuvova Jan 25, 2024
cdcf739
open frm for DROP TABLE
vuvova Jan 26, 2024
3fa8be1
cleanup: unused function argument
vuvova Jan 26, 2024
cc82b35
Revert "MDEV-15458 Segfault in heap_scan() upon UPDATE after ADD SYST…
vuvova Feb 9, 2024
a857b68
initial support for vector indexes
vuvova Jan 17, 2024
9ca6554
Initial fixup
cvicentiu Feb 17, 2024
1568677
Wip
cvicentiu Feb 21, 2024
e944876
Graph insert possibly working ok
cvicentiu Feb 22, 2024
b34a896
Search is now working, but layer unaware
cvicentiu Feb 22, 2024
8aa7c1e
wip
cvicentiu Feb 22, 2024
3d0e4ea
Vec insert and search working on a multi-layer
cvicentiu Feb 23, 2024
437e214
MDEV-33408 Alter HNSW graph storage and fix memory leak
HugoWenTD Apr 12, 2024
ee2cc47
Support files for ann-workspace
cvicentiu Apr 15, 2024
7829259
Bug fixes - on top of Hugo's patch
cvicentiu Apr 18, 2024
5899540
Introduce session variables to manage HNSW index parameters
HugoWenTD Apr 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -501,14 +501,6 @@
#cmakedefine HAVE_EncryptAes128Gcm 1
#cmakedefine HAVE_hkdf 1

/*
Stuff that always need to be defined (compile breaks without it)
*/
#define HAVE_SPATIAL 1
#define HAVE_RTREE_KEYS 1
#define HAVE_QUERY_CACHE 1
#define BIG_TABLES 1

/*
Important storage engines (those that really need define
WITH_<ENGINE>_STORAGE_ENGINE for the whole server)
Expand Down
6 changes: 0 additions & 6 deletions include/m_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,6 @@ static inline void lex_string_set(LEX_CSTRING *lex_str, const char *c_str)
lex_str->str= c_str;
lex_str->length= strlen(c_str);
}
static inline void lex_string_set3(LEX_CSTRING *lex_str, const char *c_str,
size_t len)
{
lex_str->str= c_str;
lex_str->length= len;
}

/*
Copies src into dst and ensures dst is a NULL terminated C string.
Expand Down
89 changes: 42 additions & 47 deletions include/my_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,18 @@ enum ha_rkey_function {
HA_READ_MBR_EQUAL
};

/* Key algorithm types */
/* Key algorithm types (stored in .frm) */

enum ha_key_alg {
HA_KEY_ALG_UNDEF= 0, /* Not specified (old file) */
HA_KEY_ALG_BTREE= 1, /* B-tree, default one */
HA_KEY_ALG_RTREE= 2, /* R-tree, for spatial searches */
HA_KEY_ALG_HASH= 3, /* HASH keys (HEAP tables) */
HA_KEY_ALG_FULLTEXT= 4, /* FULLTEXT (MyISAM tables) */
HA_KEY_ALG_LONG_HASH= 5, /* long BLOB keys */
HA_KEY_ALG_UNIQUE_HASH= 6 /* Internal UNIQUE hash (Aria) */
HA_KEY_ALG_UNDEF= 0, /* Not specified. Practically the
key will be B-tree or hash */
HA_KEY_ALG_BTREE= 1, /* B-tree, default one */
HA_KEY_ALG_RTREE= 2, /* R-tree, for spatial searches */
HA_KEY_ALG_HASH= 3, /* HASH keys (HEAP tables) */
HA_KEY_ALG_FULLTEXT= 4, /* FULLTEXT */
HA_KEY_ALG_LONG_HASH= 5, /* long BLOB keys */
HA_KEY_ALG_UNIQUE_HASH= 6, /* Internal UNIQUE hash (Aria) */
HA_KEY_ALG_MHNSW= 7 /* HNSW for k-ANN vector search */
};

/* Storage media types */
Expand Down Expand Up @@ -267,51 +269,49 @@ enum ha_base_keytype {
Note that these can only be up to 16 bits!
*/

#define HA_NOSAME 1U /* Set if not dupplicated records */
#define HA_PACK_KEY 2U /* Pack string key to previous key */
#define HA_AUTO_KEY 16U /* MEMORY/MyISAM/Aria internal */
#define HA_BINARY_PACK_KEY 32U /* Packing of all keys to prev key */
#define HA_FULLTEXT 128U /* For full-text search */
#define HA_SPATIAL 1024U /* For spatial search */
#define HA_NULL_ARE_EQUAL 2048U /* NULL in key are cmp as equal */
#define HA_GENERATED_KEY 8192U /* Automatically generated key */
/*
Part of unique hash key. Used only for temporary (work) tables so is not
written to .frm files.
*/
#define HA_UNIQUE_HASH 262144U

/* The combination of the above can be used for key type comparison. */
#define HA_KEYFLAG_MASK (HA_NOSAME | HA_AUTO_KEY | \
HA_FULLTEXT | \
HA_SPATIAL | HA_NULL_ARE_EQUAL | HA_GENERATED_KEY | \
HA_UNIQUE_HASH)
#define HA_NOSAME 1U /* Set if not dupplicated records */
#define HA_PACK_KEY 2U /* Pack string key to previous key */
#define HA_SPACE_PACK_USED 4U /* Test for if SPACE_PACK used */
#define HA_VAR_LENGTH_KEY 8U /* automatic bit */
#define HA_AUTO_KEY 16U /* MEMORY/MyISAM/Aria internal */
#define HA_BINARY_PACK_KEY 32U /* Packing of all keys to prev key */
#define HA_NULL_PART_KEY 64U /* automatic bit */
#define HA_FULLTEXT_legacy 128U /* For full-text search */
#define HA_SORT_ALLOWS_SAME 512U /* Intern bit when sorting records */
#define HA_SPATIAL_legacy 1024U /* For spatial search */
#define HA_NULL_ARE_EQUAL 2048U /* NULL in key are cmp as equal */
#define HA_USES_COMMENT 4096U /* automatic bit */
#define HA_GENERATED_KEY 8192U /* Automatically generated key */
#define HA_USES_PARSER 16384U /* Fulltext index uses [pre]parser */
#define HA_USES_BLOCK_SIZE 32768U /* automatic bit */

/*
Key contains partial segments.

This flag is internal to the MySQL server by design. It is not supposed
neither to be saved in FRM-files, nor to be passed to storage engines.
It is intended to pass information into internal static sort_keys(KEY *,
KEY *) function.
It is intended to pass information into internal sort_keys(KEY *, KEY *)
function.

This flag can be calculated -- it's based on key lengths comparison.
*/
#define HA_KEY_HAS_PART_KEY_SEG 65536
/* Internal Flag Can be calculated */
#define HA_INVISIBLE_KEY 2<<18
/* Automatic bits in key-flag */

#define HA_SPACE_PACK_USED 4 /* Test for if SPACE_PACK used */
#define HA_VAR_LENGTH_KEY 8
#define HA_NULL_PART_KEY 64
#define HA_USES_COMMENT 4096
#define HA_USES_PARSER 16384 /* Fulltext index uses [pre]parser */
#define HA_USES_BLOCK_SIZE ((uint) 32768)
#define HA_SORT_ALLOWS_SAME 512 /* Intern bit when sorting records */
#define HA_KEY_HAS_PART_KEY_SEG 65536U

/* This flag can be used only in KEY::ext_key_flags */
#define HA_EXT_NOSAME 131072
#define HA_EXT_NOSAME 131072U

/*
Part of unique hash key. Used only for temporary (work) tables so is not
written to .frm files.
*/
#define HA_UNIQUE_HASH 262144U

/* Internal Flag Can be calculated */
#define HA_INVISIBLE_KEY (2<<18)

/* The combination of the above can be used for key type comparison. */
#define HA_KEYFLAG_MASK (HA_NOSAME | HA_AUTO_KEY | HA_NULL_ARE_EQUAL | \
HA_GENERATED_KEY | HA_UNIQUE_HASH)

/* These flags can be added to key-seg-flag */

Expand Down Expand Up @@ -666,13 +666,8 @@ typedef struct st_page_range
#define unused_page_range { UNUSED_PAGE_NO, UNUSED_PAGE_NO }

/* For number of records */
#ifdef BIG_TABLES
#define rows2double(A) ulonglong2double(A)
typedef my_off_t ha_rows;
#else
#define rows2double(A) (double) (A)
typedef ulong ha_rows;
#endif

#define HA_POS_ERROR (~ (ha_rows) 0)
#define HA_OFFSET_ERROR (~ (my_off_t) 0)
Expand Down
6 changes: 0 additions & 6 deletions include/myisampack.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,8 @@

/* Fix to avoid warnings when sizeof(ha_rows) == sizeof(long) */

#ifdef BIG_TABLES
#define mi_rowstore(T,A) mi_int8store(T, A)
#define mi_rowkorr(T) mi_uint8korr(T)
#else
#define mi_rowstore(T,A) { mi_int4store(T, 0);\
mi_int4store(((uchar*) (T) + 4), A); }
#define mi_rowkorr(T) mi_uint4korr((const uchar*) (T) + 4)
#endif

#if SIZEOF_OFF_T > 4
#define mi_sizestore(T,A) mi_int8store(T, A)
Expand Down
2 changes: 2 additions & 0 deletions include/mysql.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ typedef unsigned long long my_ulonglong;
#define ER_UNSUPPORTED_ENGINE_FOR_VIRTUAL_COLUMNS ER_UNSUPPORTED_ENGINE_FOR_GENERATED_COLUMNS
#define ER_KEY_COLUMN_DOES_NOT_EXITS ER_KEY_COLUMN_DOES_NOT_EXIST
#define ER_DROP_PARTITION_NON_EXISTENT ER_PARTITION_DOES_NOT_EXIST
#define ER_SPATIAL_CANT_HAVE_NULL ER_INDEX_CANNOT_HAVE_NULL
#define ER_INNODB_NO_FT_TEMP_TABLE ER_NO_INDEX_ON_TEMPORARY

typedef struct st_mysql_rows {
struct st_mysql_rows *next; /* list of rows */
Expand Down
2 changes: 1 addition & 1 deletion include/queues.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ uchar *queue_remove(QUEUE *queue,uint idx);
void queue_replace(QUEUE *queue,uint idx);

#define queue_remove_all(queue) { (queue)->elements= 0; }
#define queue_is_full(queue) (queue->elements == queue->max_elements)
#define queue_is_full(queue) ((queue)->elements == (queue)->max_elements)
void _downheap(QUEUE *queue, uint idx);
void queue_fix(QUEUE *queue);
#define is_queue_inited(queue) ((queue)->root != 0)
Expand Down
4 changes: 0 additions & 4 deletions libmysqld/emb_qcache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "mariadb.h"
#include "sql_priv.h"

#ifdef HAVE_QUERY_CACHE
#include <mysql.h>
#include "sql_basic_types.h"
#include "emb_qcache.h"
Expand Down Expand Up @@ -497,6 +496,3 @@ int emb_load_querycache_result(THD *thd, Querycache_stream *src)
err:
DBUG_RETURN(1);
}

#endif /*HAVE_QUERY_CACHE*/

2 changes: 0 additions & 2 deletions mysql-test/main/alter_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,6 @@ ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used le
ALTER TABLE t1 ADD d INT;
ALTER TABLE t1 ADD KEY (d(20));
ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys
ALTER TABLE t1 ADD e GEOMETRY NOT NULL, ADD SPATIAL KEY (e(30));
ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys
DROP TABLE t1;
CREATE TABLE t1 (s CHAR(8) BINARY);
INSERT INTO t1 VALUES ('test');
Expand Down
4 changes: 0 additions & 4 deletions mysql-test/main/alter_table.test
Original file line number Diff line number Diff line change
Expand Up @@ -705,10 +705,6 @@ ALTER TABLE t1 ADD d INT;
--error ER_WRONG_SUB_KEY
ALTER TABLE t1 ADD KEY (d(20));

# the 5.1 part of the test
--error ER_WRONG_SUB_KEY
ALTER TABLE t1 ADD e GEOMETRY NOT NULL, ADD SPATIAL KEY (e(30));

DROP TABLE t1;

#
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/main/features.result
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ create table t2 (b int, constraint foo check (b < 10));
drop table t1, t2;
show status like "feature_check_constraint";
Variable_name Value
Feature_check_constraint 2
Feature_check_constraint 4
#
# Feature insert...returning
#
Expand Down
26 changes: 26 additions & 0 deletions mysql-test/main/gis-rtree.result
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
create table t1 (g geometry not null, spatial key(g(10)));
ERROR 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 '(10)))' at line 1
create table t1 (g geometry not null, spatial key(g asc));
ERROR 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 'asc))' at line 1
create table t1 (g geometry not null, spatial key(g desc));
ERROR 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 'desc))' at line 1
create table t1 (g geometry not null, f geometry not null, spatial key(g,f));
ERROR 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 'f))' at line 1
create table t1 (g geometry not null, f geometry not null);
create spatial index bad on t1 (g(10));
ERROR 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 '(10))' at line 1
create spatial index bad on t1 (g asc);
ERROR 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 'asc)' at line 1
create spatial index bad on t1 (g desc);
ERROR 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 'desc)' at line 1
create spatial index bad on t1 (f,g);
ERROR 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 'g)' at line 1
alter table t1 add spatial index bad (g(10));
ERROR 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 '(10))' at line 1
alter table t1 add spatial index bad (g asc);
ERROR 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 'asc)' at line 1
alter table t1 add spatial index bad (g desc);
ERROR 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 'desc)' at line 1
alter table t1 add spatial index bad (f,g);
ERROR 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 'g)' at line 1
drop table t1;
CREATE TABLE t1 (
fid INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
g GEOMETRY NOT NULL,
Expand Down
33 changes: 33 additions & 0 deletions mysql-test/main/gis-rtree.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
-- source include/have_geometry.inc

#
# invalid index specifications
#
--error ER_PARSE_ERROR
create table t1 (g geometry not null, spatial key(g(10)));
--error ER_PARSE_ERROR
create table t1 (g geometry not null, spatial key(g asc));
--error ER_PARSE_ERROR
create table t1 (g geometry not null, spatial key(g desc));
--error ER_PARSE_ERROR
create table t1 (g geometry not null, f geometry not null, spatial key(g,f));

create table t1 (g geometry not null, f geometry not null);
--error ER_PARSE_ERROR
create spatial index bad on t1 (g(10));
--error ER_PARSE_ERROR
create spatial index bad on t1 (g asc);
--error ER_PARSE_ERROR
create spatial index bad on t1 (g desc);
--error ER_PARSE_ERROR
create spatial index bad on t1 (f,g);

--error ER_PARSE_ERROR
alter table t1 add spatial index bad (g(10));
--error ER_PARSE_ERROR
alter table t1 add spatial index bad (g asc);
--error ER_PARSE_ERROR
alter table t1 add spatial index bad (g desc);
--error ER_PARSE_ERROR
alter table t1 add spatial index bad (f,g);

drop table t1;

#
# test of rtree (using with spatial data)
#
Expand Down
9 changes: 0 additions & 9 deletions mysql-test/main/gis.result
Original file line number Diff line number Diff line change
Expand Up @@ -1098,15 +1098,6 @@ col0 INTEGER NOT NULL,
col1 POINT,
col2 POINT
);
CREATE SPATIAL INDEX idx0 ON t2 (col1, col2);
ERROR HY000: Incorrect arguments to SPATIAL INDEX
CREATE TABLE t3 (
col0 INTEGER NOT NULL,
col1 POINT,
col2 LINESTRING,
SPATIAL INDEX i1 (col1, col2)
);
ERROR HY000: Incorrect arguments to SPATIAL INDEX
DROP TABLE t0, t1, t2;
#
# BUG#12414917 - ISCLOSED() CRASHES ON 64-BIT BUILDS
Expand Down
11 changes: 0 additions & 11 deletions mysql-test/main/gis.test
Original file line number Diff line number Diff line change
Expand Up @@ -826,17 +826,6 @@ CREATE TABLE t2 (
col2 POINT
);

--error ER_WRONG_ARGUMENTS
CREATE SPATIAL INDEX idx0 ON t2 (col1, col2);

--error ER_WRONG_ARGUMENTS
CREATE TABLE t3 (
col0 INTEGER NOT NULL,
col1 POINT,
col2 LINESTRING,
SPATIAL INDEX i1 (col1, col2)
);

# cleanup
DROP TABLE t0, t1, t2;

Expand Down
2 changes: 1 addition & 1 deletion mysql-test/main/invisible_field.result
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ d int(11) YES UNI NULL
drop table t1;
SHOW STATUS LIKE 'Feature_invisible_columns';
Variable_name Value
Feature_invisible_columns 52
Feature_invisible_columns 54
#invisible is non reserved
create table t1(a int unique , invisible int invisible, c int );
desc t1;
Expand Down
5 changes: 1 addition & 4 deletions mysql-test/main/myisam.result
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,6 @@ select * from t1 where a='807780' and b='477' and c='165';
a b c
807780 477 165
drop table t1;
DROP TABLE IF EXISTS t1;
Warnings:
Note 1051 Unknown table 'test.t1'
CREATE TABLE t1 (a varchar(150) NOT NULL, KEY (a));
INSERT t1 VALUES ("can \tcan");
INSERT t1 VALUES ("can can");
Expand Down Expand Up @@ -579,7 +576,7 @@ t1c1 t2c1
UNLOCK TABLES;
DROP TABLE t1,t2;
CREATE TABLE t1 (`a` int(11) NOT NULL default '0', `b` int(11) NOT NULL default '0', UNIQUE KEY `a` USING RTREE (`a`,`b`)) ENGINE=MyISAM;
Got one of the listed errors
ERROR HY000: Incorrect arguments to RTREE INDEX
create table t1 (a int, b varchar(200), c text not null) checksum=1;
create table t2 (a int, b varchar(200), c text not null) checksum=0;
insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
Expand Down
9 changes: 4 additions & 5 deletions mysql-test/main/myisam.test
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,6 @@ drop table t1;
#
# space-stripping in _mi_prefix_search: BUG#5284
#
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a varchar(150) NOT NULL, KEY (a));
INSERT t1 VALUES ("can \tcan");
INSERT t1 VALUES ("can can");
Expand Down Expand Up @@ -543,7 +542,7 @@ DROP TABLE t1,t2;
#
# Test RTREE index
#
--error 1235, 1289
--error ER_WRONG_ARGUMENTS
CREATE TABLE t1 (`a` int(11) NOT NULL default '0', `b` int(11) NOT NULL default '0', UNIQUE KEY `a` USING RTREE (`a`,`b`)) ENGINE=MyISAM;
# INSERT INTO t1 VALUES (1,1),(1,1);
# DELETE FROM rt WHERE a<1;
Expand Down Expand Up @@ -1129,7 +1128,7 @@ drop table t1;
create table t1 (c1 int) engine=myisam pack_keys=0;
create table t2 (c1 int) engine=myisam pack_keys=1;
create table t3 (c1 int) engine=myisam pack_keys=default;
--error 1064
--error ER_PARSE_ERROR
create table t4 (c1 int) engine=myisam pack_keys=2;
drop table t1, t2, t3;

Expand Down Expand Up @@ -1316,9 +1315,9 @@ create table t1 (a int not null, key `a` (a) key_block_size=1025);
show create table t1;
drop table t1;

--error 1064
--error ER_PARSE_ERROR
create table t1 (a int not null, key key_block_size=1024 (a));
--error 1064
--error ER_PARSE_ERROR
create table t1 (a int not null, key `a` key_block_size=1024 (a));

#
Expand Down