Skip to content

Commit e8e5870

Browse files
committed
don't change idxType as sqlite rely on it pretty much
1 parent 9000742 commit e8e5870

3 files changed

Lines changed: 7 additions & 14 deletions

File tree

libsql-sqlite3/src/build.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ static void SQLITE_NOINLINE deleteTable(sqlite3 *db, Table *pTable){
833833
for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
834834
pNext = pIndex->pNext;
835835
assert( pIndex->pSchema==pTable->pSchema
836-
|| (IsVirtual(pTable) && !IsAppDefIndex(pIndex)) );
836+
|| (IsVirtual(pTable) && pIndex->idxType!=SQLITE_IDXTYPE_APPDEF) );
837837
if( db->pnBytesFreed==0 && !IsVirtual(pTable) ){
838838
char *zName = pIndex->zName;
839839
TESTONLY ( Index *pOld = ) sqlite3HashInsert(
@@ -4345,13 +4345,12 @@ void sqlite3CreateIndex(
43454345
goto exit_create_index;
43464346
}
43474347
if( vectorIdxRc >= 1 ){
4348-
idxType = SQLITE_IDXTYPE_VECTOR;
43494348
/*
43504349
* SQLite can use B-Tree indices in some optimizations (like SELECT COUNT(*) can use any full B-Tree index instead of PK index)
43514350
* But, SQLite pretty conservative about usage of unordered indices - that's what we need here
43524351
*/
43534352
pIndex->bUnordered = 1;
4354-
pIndex->idxType = idxType;
4353+
pIndex->idxIsVector = 1;
43554354
}
43564355
if( vectorIdxRc == 1 ){
43574356
skipRefill = 1;
@@ -4399,7 +4398,7 @@ void sqlite3CreateIndex(
43994398
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
44004399
int k;
44014400
assert( IsUniqueIndex(pIdx) );
4402-
assert( !IsAppDefIndex(pIdx) );
4401+
assert( pIdx->idxType!=SQLITE_IDXTYPE_APPDEF );
44034402
assert( IsUniqueIndex(pIndex) );
44044403

44054404
if( pIdx->nKeyCol!=pIndex->nKeyCol ) continue;
@@ -4680,7 +4679,7 @@ void sqlite3DropIndex(Parse *pParse, SrcList *pName, int ifExists){
46804679
pParse->checkSchema = 1;
46814680
goto exit_drop_index;
46824681
}
4683-
if( !IsAppDefIndex(pIndex) ){
4682+
if( pIndex->idxType!=SQLITE_IDXTYPE_APPDEF ){
46844683
sqlite3ErrorMsg(pParse, "index associated with UNIQUE "
46854684
"or PRIMARY KEY constraint cannot be dropped", 0);
46864685
goto exit_drop_index;

libsql-sqlite3/src/parse.y

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,9 +1451,6 @@ paren_exprlist(A) ::= LP exprlist(X) RP. {A = X;}
14511451
cmd ::= createkw(S) uniqueflag(U) INDEX ifnotexists(NE) nm(X) dbnm(D) indextype(T)
14521452
ON nm(Y) LP sortlist(Z) RP where_opt(W). {
14531453
u8 idxType = SQLITE_IDXTYPE_APPDEF;
1454-
if( T.pUsing!=0 ){
1455-
idxType = SQLITE_IDXTYPE_VECTOR;
1456-
}
14571454
sqlite3CreateIndex(pParse, &X, &D,
14581455
sqlite3SrcListAppend(pParse,0,&Y,0), Z, U,
14591456
&S, W, SQLITE_SO_ASC, NE, idxType, T.pUsing);

libsql-sqlite3/src/sqliteInt.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2799,7 +2799,8 @@ struct Index {
27992799
u16 nKeyCol; /* Number of columns forming the key */
28002800
u16 nColumn; /* Number of columns stored in the index */
28012801
u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
2802-
unsigned idxType:3; /* 0:Normal 1:UNIQUE, 2:PRIMARY KEY, 3:IPK, 4:VECTOR INDEX */
2802+
unsigned idxType:2; /* 0:Normal 1:UNIQUE, 2:PRIMARY KEY, 3:IPK */
2803+
unsigned idxIsVector:1; /* 0:Normal 1:VECTOR INDEX */
28032804
unsigned bUnordered:1; /* Use this index for == or IN queries only */
28042805
unsigned uniqNotNull:1; /* True if UNIQUE and NOT NULL for all columns */
28052806
unsigned isResized:1; /* True if resizeIndexObject() has been called */
@@ -2831,7 +2832,6 @@ struct Index {
28312832
#define SQLITE_IDXTYPE_UNIQUE 1 /* Implements a UNIQUE constraint */
28322833
#define SQLITE_IDXTYPE_PRIMARYKEY 2 /* Is the PRIMARY KEY for the table */
28332834
#define SQLITE_IDXTYPE_IPK 3 /* INTEGER PRIMARY KEY index */
2834-
#define SQLITE_IDXTYPE_VECTOR 4 /* libSQL vector index */
28352835

28362836
/* Return true if index X is a PRIMARY KEY index */
28372837
#define IsPrimaryKeyIndex(X) ((X)->idxType==SQLITE_IDXTYPE_PRIMARYKEY)
@@ -2840,10 +2840,7 @@ struct Index {
28402840
#define IsUniqueIndex(X) ((X)->onError!=OE_None)
28412841

28422842
/* Return true if index X is a vector index */
2843-
#define IsVectorIndex(X) ((X)->idxType==SQLITE_IDXTYPE_VECTOR)
2844-
2845-
/* Return true if index X is an user defined index (APPDEF or VECTOR) */
2846-
#define IsAppDefIndex(X) ((X)->idxType==SQLITE_IDXTYPE_APPDEF||(X)->idxType==SQLITE_IDXTYPE_VECTOR)
2843+
#define IsVectorIndex(X) ((X)->idxIsVector==1)
28472844

28482845
/* The Index.aiColumn[] values are normally positive integer. But
28492846
** there are some negative values that have special meaning:

0 commit comments

Comments
 (0)