Skip to content

Commit 44c05bc

Browse files
committed
use generic_plan for unsafe explain
1 parent e330e8c commit 44c05bc

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

apps/dbagent/src/lib/targetdb/unsafe-explain.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,17 +262,14 @@ export async function unsafeExplainQuery(client: ClientBase, schema: string, que
262262
return 'The query is not a single safe statement. Only SELECT, INSERT, UPDATE, DELETE, and WITH statements are allowed.';
263263
}
264264

265-
if (query.includes('$1') || query.includes('$2') || query.includes('$3') || query.includes('$4')) {
266-
// TODO: we could use `GENERIC_PLAN` to still get the plan in this case.
267-
return 'The query seems to contain placeholders ($1, $2, etc). Replace them with actual values and try again.';
268-
}
265+
const hasPlaceholders = /\$\d+/.test(query);
269266
let toReturn = '';
270267
try {
271268
await client.query('BEGIN');
272269
await client.query("SET LOCAL statement_timeout = '2000ms'");
273270
await client.query("SET LOCAL lock_timeout = '200ms'");
274271
await client.query(`SET search_path TO ${schema}`);
275-
const explainQuery = `EXPLAIN ${query}`;
272+
const explainQuery = hasPlaceholders ? `EXPLAIN (GENERIC_PLAN true) ${query}` : `EXPLAIN ${query}`;
276273
console.log(schema);
277274
console.log(explainQuery);
278275
const result = await client.query(explainQuery);

0 commit comments

Comments
 (0)