Skip to content

Commit 0b41b5a

Browse files
committed
build bundles
1 parent 4b3e7e7 commit 0b41b5a

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212002,6 +212002,7 @@ int diskAnnCreateIndex(
212002212002
int type, dims;
212003212003
u64 maxNeighborsParam, blockSizeBytes;
212004212004
char *zSql;
212005+
const char *zRowidColumnName;
212005212006
char columnSqlDefs[VECTOR_INDEX_SQL_RENDER_LIMIT]; // definition of columns (e.g. index_key INTEGER BINARY, index_key1 TEXT, ...)
212006212007
char columnSqlNames[VECTOR_INDEX_SQL_RENDER_LIMIT]; // just column names (e.g. index_key, index_key1, index_key2, ...)
212007212008
if( vectorIdxKeyDefsRender(pKey, "index_key", columnSqlDefs, sizeof(columnSqlDefs)) != 0 ){
@@ -212069,6 +212070,7 @@ int diskAnnCreateIndex(
212069212070
columnSqlDefs,
212070212071
columnSqlNames
212071212072
);
212073+
zRowidColumnName = "index_key";
212072212074
}else{
212073212075
zSql = sqlite3MPrintf(
212074212076
db,
@@ -212078,9 +212080,31 @@ int diskAnnCreateIndex(
212078212080
columnSqlDefs,
212079212081
columnSqlNames
212080212082
);
212083+
zRowidColumnName = "rowid";
212081212084
}
212082212085
rc = sqlite3_exec(db, zSql, 0, 0, 0);
212083212086
sqlite3DbFree(db, zSql);
212087+
if( rc != SQLITE_OK ){
212088+
return rc;
212089+
}
212090+
/*
212091+
* vector blobs are usually pretty huge (more than a page size, for example, node block for 1024d f32 embeddings with 1bit compression will occupy ~20KB)
212092+
* in this case, main table B-Tree takes on redundant shape where all leaf nodes has only 1 cell
212093+
*
212094+
* as we have a query which selects random row using OFFSET/LIMIT trick - we will need to read all these leaf nodes pages just to skip them
212095+
* so, in order to remove this overhead for random row selection - we creating an index with just single column used
212096+
* in this case B-Tree leafs will be full of rowids and the overhead for page reads will be very small
212097+
*/
212098+
zSql = sqlite3MPrintf(
212099+
db,
212100+
"CREATE INDEX IF NOT EXISTS \"%w\".%s_shadow_idx ON %s_shadow (%s)",
212101+
zDbSName,
212102+
zIdxName,
212103+
zIdxName,
212104+
zRowidColumnName
212105+
);
212106+
rc = sqlite3_exec(db, zSql, 0, 0, 0);
212107+
sqlite3DbFree(db, zSql);
212084212108
return rc;
212085212109
}
212086212110

@@ -212110,8 +212134,8 @@ static int diskAnnSelectRandomShadowRow(const DiskAnnIndex *pIndex, u64 *pRowid)
212110212134

212111212135
zSql = sqlite3MPrintf(
212112212136
pIndex->db,
212113-
"SELECT rowid FROM \"%w\".%s LIMIT 1 OFFSET ABS(RANDOM()) %% MAX((SELECT COUNT(*) FROM %s), 1)",
212114-
pIndex->zDbSName, pIndex->zShadow, pIndex->zShadow
212137+
"SELECT rowid FROM \"%w\".%s LIMIT 1 OFFSET ABS(RANDOM()) %% MAX((SELECT COUNT(*) FROM \"%w\".%s), 1)",
212138+
pIndex->zDbSName, pIndex->zShadow, pIndex->zDbSName, pIndex->zShadow
212115212139
);
212116212140
if( zSql == NULL ){
212117212141
rc = SQLITE_NOMEM_BKPT;

libsql-ffi/bundled/src/sqlite3.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212002,6 +212002,7 @@ int diskAnnCreateIndex(
212002212002
int type, dims;
212003212003
u64 maxNeighborsParam, blockSizeBytes;
212004212004
char *zSql;
212005+
const char *zRowidColumnName;
212005212006
char columnSqlDefs[VECTOR_INDEX_SQL_RENDER_LIMIT]; // definition of columns (e.g. index_key INTEGER BINARY, index_key1 TEXT, ...)
212006212007
char columnSqlNames[VECTOR_INDEX_SQL_RENDER_LIMIT]; // just column names (e.g. index_key, index_key1, index_key2, ...)
212007212008
if( vectorIdxKeyDefsRender(pKey, "index_key", columnSqlDefs, sizeof(columnSqlDefs)) != 0 ){
@@ -212069,6 +212070,7 @@ int diskAnnCreateIndex(
212069212070
columnSqlDefs,
212070212071
columnSqlNames
212071212072
);
212073+
zRowidColumnName = "index_key";
212072212074
}else{
212073212075
zSql = sqlite3MPrintf(
212074212076
db,
@@ -212078,9 +212080,31 @@ int diskAnnCreateIndex(
212078212080
columnSqlDefs,
212079212081
columnSqlNames
212080212082
);
212083+
zRowidColumnName = "rowid";
212081212084
}
212082212085
rc = sqlite3_exec(db, zSql, 0, 0, 0);
212083212086
sqlite3DbFree(db, zSql);
212087+
if( rc != SQLITE_OK ){
212088+
return rc;
212089+
}
212090+
/*
212091+
* vector blobs are usually pretty huge (more than a page size, for example, node block for 1024d f32 embeddings with 1bit compression will occupy ~20KB)
212092+
* in this case, main table B-Tree takes on redundant shape where all leaf nodes has only 1 cell
212093+
*
212094+
* as we have a query which selects random row using OFFSET/LIMIT trick - we will need to read all these leaf nodes pages just to skip them
212095+
* so, in order to remove this overhead for random row selection - we creating an index with just single column used
212096+
* in this case B-Tree leafs will be full of rowids and the overhead for page reads will be very small
212097+
*/
212098+
zSql = sqlite3MPrintf(
212099+
db,
212100+
"CREATE INDEX IF NOT EXISTS \"%w\".%s_shadow_idx ON %s_shadow (%s)",
212101+
zDbSName,
212102+
zIdxName,
212103+
zIdxName,
212104+
zRowidColumnName
212105+
);
212106+
rc = sqlite3_exec(db, zSql, 0, 0, 0);
212107+
sqlite3DbFree(db, zSql);
212084212108
return rc;
212085212109
}
212086212110

@@ -212110,8 +212134,8 @@ static int diskAnnSelectRandomShadowRow(const DiskAnnIndex *pIndex, u64 *pRowid)
212110212134

212111212135
zSql = sqlite3MPrintf(
212112212136
pIndex->db,
212113-
"SELECT rowid FROM \"%w\".%s LIMIT 1 OFFSET ABS(RANDOM()) %% MAX((SELECT COUNT(*) FROM %s), 1)",
212114-
pIndex->zDbSName, pIndex->zShadow, pIndex->zShadow
212137+
"SELECT rowid FROM \"%w\".%s LIMIT 1 OFFSET ABS(RANDOM()) %% MAX((SELECT COUNT(*) FROM \"%w\".%s), 1)",
212138+
pIndex->zDbSName, pIndex->zShadow, pIndex->zDbSName, pIndex->zShadow
212115212139
);
212116212140
if( zSql == NULL ){
212117212141
rc = SQLITE_NOMEM_BKPT;

0 commit comments

Comments
 (0)