drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Native .explain() method on all query builders for query plan analysis

Open
#6,128 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Feature hasn't been suggested before.

- [x] I have verified this feature I'm about to request hasn't been suggested before.

### Describe the enhancement you want to request

#### Problem
Drizzle ORM currently has no native way to get the execution plan of a query.
Developers must manually extract SQL with `.toSQL()`, wrap it in a raw
`EXPLAIN ANALYZE` call and lose all type safety:
```ts
// Current workaround
const query = db.select().from(users).where(eq(users.id, 1));
const sqlObj = query.toSQL();
const result = await db.execute(sql`EXPLAIN ANALYZE ${sql.raw(sqlObj.sql)}`);

Contributor guide

Open the contributing guide

Research direction

Start by reading the query-builder APIs and the existing toSQL() path, then compare how query-plan analysis would need to work across the ORM's database integrations. Done means all query builders expose a type-safe .explain() method without requiring manual SQL extraction.

Written by the indexing model from the issue text.

Assessment

Tech stack
sql, typescript
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.