Repository navigation
perf(cockroachdb): batch DROP statements in clearDatabase() - #12159
Conversation
Review Summary by QodoBatch DROP statements in CockroachDB clearDatabase()
WalkthroughsDescription• Batch DROP statements for views, tables, sequences, and enums • Reduce database round-trips from 4×(N+1) to 4×2 per clearDatabase() call • Refactor query generation to collect object names then execute single batched DROP • Significantly improve CockroachDB test performance (20+ minutes to 2-3 minutes) Diagramflowchart LR
A["SELECT object names<br/>views, tables, sequences, enums"] -->|"Collect names"| B["Build batched<br/>DROP statements"]
B -->|"Single query per type"| C["Execute DROP<br/>with all objects"]
C -->|"Reduce round-trips"| D["Improved test<br/>performance"]
File Changes1. src/driver/cockroachdb/CockroachQueryRunner.ts
|
commit: |
Code Review by Qodo
1. Views dropped as tables
|
14d3ffe to
cb8267f
Compare
|
Persistent review updated to latest commit cb8267f |
Deploying typeorm with
|
| Latest commit: |
8b3a977
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d5310218.typeorm.pages.dev |
| Branch Preview URL: | https://perf-batch-cockroachdb-drop.typeorm.pages.dev |
|
Persistent review updated to latest commit 8b3a977 |
…hdb-drop-statements
- use quote_ident() for enum type names instead of manual quoting - add IF EXISTS to DROP SEQUENCE for resilience to concurrent cleanup - filter information_schema.tables by table_type = 'BASE TABLE'
|
|
Persistent review updated to latest commit 7af618e |



CockroachDB tests take 20+ minutes while other databases complete in 2–3 minutes. A major contributor is
clearDatabase(), which is called viasynchronize(true)in every test'sbeforeEach. Previously, it executed each DROP as a separate query — for N tables, that meant N+1 round-trips (1 SELECT + N individual DROPs), repeated for views, tables, sequences, and enum types.This batches all DROP operations into single statements:
Applied to all four object types (views, tables, sequences, enums), reducing the total from 4×(N+1) queries down to 4×2 queries per
clearDatabase()call.Additionally hardens the DROP statements:
quote_ident()for enum type names instead of manual double-quote concatenationIF EXISTStoDROP SEQUENCEfor resilience to concurrent cleanupinformation_schema.tablesbytable_type = 'BASE TABLE'to avoid dropping views as tables