Skip to content

Commit 1393f47

Browse files
committed
fix: bug fixes in benchmark-queries (#68)
1 parent 9ca3367 commit 1393f47

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/scripts/benchmark-queries.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,14 @@ function summarizePlan(plan: ExplainPlanNode): { indexes: string[]; scans: strin
150150
}
151151

152152
async function explain(db: Knex, query: Knex.QueryBuilder | Knex.Raw): Promise<ExplainResult> {
153-
const { sql, bindings } = query.toSQL().toNative
154-
? (query as any).toSQL().toNative()
155-
: { sql: query.toString(), bindings: [] as unknown[] }
153+
// Keep placeholders in Knex's `?` form so `db.raw(sql, bindings)` substitutes
154+
// them correctly — `.toNative()` rewrites them to `$1, $2, …`, which makes
155+
// Knex's binding check fail ("Expected N bindings, saw 0").
156+
const { sql, bindings } = query.toSQL()
156157

157158
const { rows } = await db.raw<{ rows: { 'QUERY PLAN': ExplainResult[] }[] }>(
158159
`EXPLAIN (ANALYZE, BUFFERS, VERBOSE, FORMAT JSON) ${sql}`,
159-
bindings,
160+
bindings as readonly unknown[],
160161
)
161162
return rows[0]['QUERY PLAN'][0]
162163
}

0 commit comments

Comments
 (0)