fix(server): deadlock when fetching vector count (#18728)

move row count query
This commit is contained in:
Mert 2025-05-28 17:23:49 -04:00 committed by GitHub
parent 78224961d1
commit be247395db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -246,6 +246,7 @@ export class DatabaseRepository {
return; return;
} }
const dimSize = await this.getDimensionSize(table); const dimSize = await this.getDimensionSize(table);
lists ||= this.targetListCount(await this.getRowCount(table));
await this.db.schema.dropIndex(indexName).ifExists().execute(); await this.db.schema.dropIndex(indexName).ifExists().execute();
if (table === 'smart_search') { if (table === 'smart_search') {
await this.db.schema.alterTable(table).dropConstraint('dim_size_constraint').ifExists().execute(); await this.db.schema.alterTable(table).dropConstraint('dim_size_constraint').ifExists().execute();
@ -262,7 +263,6 @@ export class DatabaseRepository {
ALTER TABLE ${sql.raw(table)} ALTER TABLE ${sql.raw(table)}
ALTER COLUMN embedding ALTER COLUMN embedding
SET DATA TYPE ${sql.raw(schema)}vector(${sql.raw(String(dimSize))})`.execute(tx); SET DATA TYPE ${sql.raw(schema)}vector(${sql.raw(String(dimSize))})`.execute(tx);
lists ||= this.targetListCount(await this.getRowCount(table));
await sql.raw(vectorIndexQuery({ vectorExtension, table, indexName, lists })).execute(tx); await sql.raw(vectorIndexQuery({ vectorExtension, table, indexName, lists })).execute(tx);
}); });
try { try {