Skip to content

Commit c599602

Browse files
committed
build bundles
1 parent d665e15 commit c599602

2 files changed

Lines changed: 84 additions & 78 deletions

File tree

libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -85130,7 +85130,7 @@ typedef struct VectorIdxCursor VectorIdxCursor;
8513085130

8513185131
int vectorIdxParseColumnType(const char *, int *, int *, const char **);
8513285132

85133-
int vectorIndexCreate(Parse*, Index*, const char *, const IdList*);
85133+
int vectorIndexCreate(Parse*, const Index*, const char *, const IdList*);
8513485134
int vectorIndexClear(sqlite3 *, const char *, const char *);
8513585135
int vectorIndexDrop(sqlite3 *, const char *, const char *);
8513685136
int vectorIndexSearch(sqlite3 *, const char *, int, sqlite3_value **, VectorOutRows *, char **);
@@ -126105,10 +126105,13 @@ SQLITE_PRIVATE void sqlite3CreateIndex(
126105126105
if( vectorIdxRc < 0 ){
126106126106
goto exit_create_index;
126107126107
}
126108+
if( vectorIdxRc >= 1 ){
126109+
idxType = SQLITE_IDXTYPE_VECTOR;
126110+
pIndex->idxType = idxType;
126111+
}
126108126112
if( vectorIdxRc == 1 ){
126109126113
skipRefill = 1;
126110126114
}
126111-
idxType = pIndex->idxType; // vectorIndexCreate can update idxType to 4 (VECTOR INDEX)
126112126115
#endif
126113126116

126114126117
/* Append the table key to the end of the index. For WITHOUT ROWID
@@ -212159,6 +212162,9 @@ int vectorIndexGetParameters(
212159212162
int rc = SQLITE_OK;
212160212163

212161212164
static const char* zSelectSql = "SELECT metadata FROM " VECTOR_INDEX_GLOBAL_META_TABLE " WHERE name = ?";
212165+
// zSelectSqlPekkaLegacy handles the case when user created DB before 04 July 2024 (https://discord.com/channels/933071162680958986/1225560924526477322/1258367912402489397)
212166+
// when instead of table with binary parameters rigid schema was used for index settings
212167+
// we should drop this eventually - but for now we postponed this decision
212162212168
static const char* zSelectSqlPekkaLegacy = "SELECT vector_type, block_size, dims, distance_ops FROM libsql_vector_index WHERE name = ?";
212163212169
rc = vectorIndexTryGetParametersFromBinFormat(db, zSelectSql, zIdxName, pParams);
212164212170
if( rc == SQLITE_OK ){
@@ -212205,19 +212211,24 @@ int vectorIndexClear(sqlite3 *db, const char *zDbSName, const char *zIdxName) {
212205212211
* dump populates tables first and create indices after
212206212212
* so we must omit them because shadow tables already filled
212207212213
*
212208-
* 1. if vector index must not be created : 0 returned and pIdx is unchanged
212209-
* 2. if vector index must be created and refilled from base table: 0 returned and pIdx->idxType set to SQLITE_IDXTYPE_VECTOR
212210-
* 3. if vector index must be created but refill must be skipped : 1 returned and pIdx->idxType set to SQLITE_IDXTYPE_VECTOR
212211-
* 4. in case of any error :-1 returned (and pParse errMsg is populated with some error message)
212214+
* 1. in case of any error :-1 returned (and pParse errMsg is populated with some error message)
212215+
* 2. if vector index must not be created : 0 returned
212216+
* 3. if vector index must be created but refill must be skipped : 1 returned
212217+
* 4. if vector index must be created and refilled from base table: 2 returned
212212212218
*/
212213-
int vectorIndexCreate(Parse *pParse, Index *pIdx, const char *zDbSName, const IdList *pUsing) {
212219+
int vectorIndexCreate(Parse *pParse, const Index *pIdx, const char *zDbSName, const IdList *pUsing) {
212220+
static const int CREATE_FAIL = -1;
212221+
static const int CREATE_IGNORE = 0;
212222+
static const int CREATE_OK_SKIP_REFILL = 1;
212223+
static const int CREATE_OK = 2;
212224+
212214212225
int i, rc = SQLITE_OK;
212215212226
int dims, type;
212216212227
int hasLibsqlVectorIdxFn = 0, hasCollation = 0;
212217212228
const char *pzErrMsg;
212218212229

212219212230
if( IsVacuum(pParse->db) ){
212220-
return SQLITE_OK;
212231+
return CREATE_IGNORE;
212221212232
}
212222212233

212223212234
assert( zDbSName != NULL );
@@ -212235,7 +212246,7 @@ int vectorIndexCreate(Parse *pParse, Index *pIdx, const char *zDbSName, const Id
212235212246
if( pParse->eParseMode ){
212236212247
// scheme can be re-parsed by SQLite for different reasons (for example, to check schema after
212237212248
// ALTER COLUMN statements) - so we must skip creation in such cases
212238-
goto ignore;
212249+
return CREATE_IGNORE;
212239212250
}
212240212251

212241212252
// backward compatibility: preserve old indices with deprecated syntax but forbid creation of new indices with this syntax
@@ -212245,15 +212256,15 @@ int vectorIndexCreate(Parse *pParse, Index *pIdx, const char *zDbSName, const Id
212245212256
} else {
212246212257
sqlite3ErrorMsg(pParse, "USING syntax is deprecated, please use plain CREATE INDEX: CREATE INDEX xxx ON yyy ( " VECTOR_INDEX_MARKER_FUNCTION "(zzz) )");
212247212258
}
212248-
goto fail;
212259+
return CREATE_FAIL;
212249212260
}
212250212261
if( db->init.busy == 1 && pUsing != NULL ){
212251-
goto ok;
212262+
return CREATE_OK;
212252212263
}
212253212264

212254212265
// vector index must have expressions over column
212255212266
if( pIdx->aColExpr == NULL ) {
212256-
goto ignore;
212267+
return CREATE_IGNORE;
212257212268
}
212258212269

212259212270
pListItem = pIdx->aColExpr->a;
@@ -212268,94 +212279,86 @@ int vectorIndexCreate(Parse *pParse, Index *pIdx, const char *zDbSName, const Id
212268212279
}
212269212280
}
212270212281
if( !hasLibsqlVectorIdxFn ) {
212271-
goto ignore;
212282+
return CREATE_IGNORE;
212272212283
}
212273212284
if( hasCollation ){
212274212285
sqlite3ErrorMsg(pParse, "vector index can't have collation");
212275-
goto fail;
212286+
return CREATE_FAIL;
212276212287
}
212277212288
if( pIdx->aColExpr->nExpr != 1 ) {
212278212289
sqlite3ErrorMsg(pParse, "vector index must contain exactly one column wrapped into the " VECTOR_INDEX_MARKER_FUNCTION " function");
212279-
goto fail;
212290+
return CREATE_FAIL;
212280212291
}
212281212292
// we are able to support this but I doubt this works for now - more polishing required to make this work
212282212293
if( pIdx->pPartIdxWhere != NULL ) {
212283212294
sqlite3ErrorMsg(pParse, "partial vector index is not supported");
212284-
goto fail;
212295+
return CREATE_FAIL;
212285212296
}
212286212297

212287212298
pArgsList = pIdx->aColExpr->a[0].pExpr->x.pList;
212288212299
pListItem = pArgsList->a;
212289212300

212290212301
if( pArgsList->nExpr < 1 ){
212291212302
sqlite3ErrorMsg(pParse, VECTOR_INDEX_MARKER_FUNCTION " must contain at least one argument");
212292-
goto fail;
212303+
return CREATE_FAIL;
212293212304
}
212294212305
if( pListItem[0].pExpr->op != TK_COLUMN ) {
212295212306
sqlite3ErrorMsg(pParse, VECTOR_INDEX_MARKER_FUNCTION " first argument must be a column token");
212296-
goto fail;
212307+
return CREATE_FAIL;
212297212308
}
212298212309
iEmbeddingColumn = pListItem[0].pExpr->iColumn;
212299212310
if( iEmbeddingColumn < 0 ) {
212300212311
sqlite3ErrorMsg(pParse, VECTOR_INDEX_MARKER_FUNCTION " first argument must be column with vector type");
212301-
goto fail;
212312+
return CREATE_FAIL;
212302212313
}
212303212314
assert( iEmbeddingColumn >= 0 && iEmbeddingColumn < pTable->nCol );
212304212315

212305212316
zEmbeddingColumnTypeName = sqlite3ColumnType(&pTable->aCol[iEmbeddingColumn], "");
212306212317
if( vectorIdxParseColumnType(zEmbeddingColumnTypeName, &type, &dims, &pzErrMsg) != 0 ){
212307212318
sqlite3ErrorMsg(pParse, "%s: %s", pzErrMsg, zEmbeddingColumnTypeName);
212308-
goto fail;
212319+
return CREATE_FAIL;
212309212320
}
212310212321

212311212322
// schema is locked while db is initializing and we need to just proceed here
212312212323
if( db->init.busy == 1 ){
212313-
goto ok;
212324+
return CREATE_OK;
212314212325
}
212315212326

212316212327
rc = initVectorIndexMetaTable(db, zDbSName);
212317212328
if( rc != SQLITE_OK ){
212318212329
sqlite3ErrorMsg(pParse, "failed to init vector index meta table: %s", sqlite3_errmsg(db));
212319-
goto fail;
212330+
return CREATE_FAIL;
212320212331
}
212321212332
rc = parseVectorIdxParams(pParse, &idxParams, type, dims, pListItem + 1, pArgsList->nExpr - 1);
212322212333
if( rc != SQLITE_OK ){
212323212334
sqlite3ErrorMsg(pParse, "failed to parse vector idx params");
212324-
goto fail;
212335+
return CREATE_FAIL;
212325212336
}
212326212337
if( vectorIdxKeyGet(pTable, &idxKey, &pzErrMsg) != 0 ){
212327212338
sqlite3ErrorMsg(pParse, "failed to detect underlying table key: %s", pzErrMsg);
212328-
goto fail;
212339+
return CREATE_FAIL;
212329212340
}
212330212341
if( idxKey.nKeyColumns != 1 ){
212331212342
sqlite3ErrorMsg(pParse, "vector index for tables without ROWID and composite primary key are not supported");
212332-
goto fail;
212343+
return CREATE_FAIL;
212333212344
}
212334212345
rc = diskAnnCreateIndex(db, zDbSName, pIdx->zName, &idxKey, &idxParams);
212335212346
if( rc != SQLITE_OK ){
212336212347
sqlite3ErrorMsg(pParse, "unable to initialize diskann vector index");
212337-
goto fail;
212348+
return CREATE_FAIL;
212338212349
}
212339212350
rc = insertIndexParameters(db, zDbSName, pIdx->zName, &idxParams);
212340212351
if( rc == SQLITE_CONSTRAINT ){
212341212352
// we are violating unique constraint here which means that someone inserted parameters in the table before us
212342-
// taking aside corruption scenarios, this can be in case of loading dump (because tables are loaded before indices) or vacuum-ing DB
212343-
// both these cases are valid and we must proceed with index creating but avoid index-refill step as it is already filled
212344-
goto skip_refill;
212353+
// taking aside corruption scenarios, this can be in case of loading dump (because tables and data are loaded before indices)
212354+
// this case is valid and we must proceed with index creating but avoid index-refill step as it is already filled
212355+
return CREATE_OK_SKIP_REFILL;
212345212356
}
212346212357
if( rc != SQLITE_OK ){
212347212358
sqlite3ErrorMsg(pParse, "unable to update global metadata table");
212348-
goto fail;
212359+
return CREATE_FAIL;
212349212360
}
212350-
ok:
212351-
pIdx->idxType = SQLITE_IDXTYPE_VECTOR;
212352-
ignore:
212353-
return 0;
212354-
skip_refill:
212355-
pIdx->idxType = SQLITE_IDXTYPE_VECTOR;
212356-
return 1;
212357-
fail:
212358-
return -1;
212361+
return CREATE_OK;
212359212362
}
212360212363

212361212364
int vectorIndexSearch(sqlite3 *db, const char* zDbSName, int argc, sqlite3_value **argv, VectorOutRows *pRows, char **pzErrMsg) {

0 commit comments

Comments
 (0)