Skip to content

Commit 693716f

Browse files
committed
fix: query-do executeCount() fast path bypassed with filterGroups, join, distinct, etc.
The metadata-only fast path only checked filters.length === 0 but skipped guards for filterGroups (OR filters), aggregates, groupBy, distinct, join, vectorSearch, setOperation, subqueryIn, and computedColumns. This returned wrong counts for any non-trivial query that happened to have no AND filters. Aligns with the same fix already applied to local-executor.ts count().
1 parent eb04362 commit 693716f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/query-do.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ export class QueryDO extends DurableObject<Env> {
697697

698698
/** Core count logic shared by HTTP handler and RPC. */
699699
private async executeCount(query: QueryDescriptor): Promise<number> {
700-
if (query.filters.length === 0) {
700+
if (query.filters.length === 0 && !query.filterGroups?.length && !query.aggregates?.length && !query.groupBy?.length && !query.distinct && !query.join && !query.vectorSearch && !query.setOperation && !query.subqueryIn && !query.computedColumns?.length) {
701701
const meta = this.footerCache.get(query.table)
702702
?? (await this.loadTableFromR2(query.table)) ?? undefined;
703703
if (meta) return meta.columns[0]?.pages.reduce((s, p) => s + p.rowCount, 0) ?? meta.totalRows;

0 commit comments

Comments
 (0)