@@ -216063,7 +216063,7 @@ int vectorIndexSearch(
216063216063 int *nWrites,
216064216064 char **pzErrMsg
216065216065) {
216066- int type, dims, k, rc;
216066+ int type, dims, k, rc, iDb = -1 ;
216067216067 double kDouble;
216068216068 const char *zIdxFullName;
216069216069 char *zIdxDbSNameAlloc = NULL; // allocated managed schema name string - must be freed if not null
@@ -216141,6 +216141,18 @@ int vectorIndexSearch(
216141216141 } else{
216142216142 zIdxDbSName = zIdxDbSNameAlloc;
216143216143 zIdxName = zIdxNameAlloc;
216144+ iDb = sqlite3FindDbName(db, zIdxDbSName);
216145+ if( iDb < 0 ){
216146+ *pzErrMsg = sqlite3_mprintf("vector index(search): unknown schema '%s'", zIdxDbSName);
216147+ rc = SQLITE_ERROR;
216148+ goto out;
216149+ }
216150+ // we need to hold mutex to protect schema against unwanted changes
216151+ // this code is necessary, otherwise sqlite3SchemaMutexHeld assert will fail
216152+ if( iDb !=1 ){
216153+ // not "main" DB which we already hold mutex for
216154+ sqlite3BtreeEnter(db->aDb[iDb].pBt);
216155+ }
216144216156 }
216145216157
216146216158 if( vectorIndexGetParameters(db, zIdxDbSName, zIdxName, &idxParams) != 0 ){
@@ -216176,6 +216188,9 @@ int vectorIndexSearch(
216176216188 }
216177216189 sqlite3DbFree(db, zIdxNameAlloc);
216178216190 sqlite3DbFree(db, zIdxDbSNameAlloc);
216191+ if( iDb >= 0 && iDb != 1 ){
216192+ sqlite3BtreeLeave(db->aDb[iDb].pBt);
216193+ }
216179216194 return rc;
216180216195}
216181216196
0 commit comments