Skip to content

Conversation

@krleonid
Copy link
Owner

Instead of fetching columns by rowid in PhysicalDelete for RETURNING clause, add required columns to the initial table scan and pass them through directly. This eliminates expensive point lookups and improves performance significantly.

Benchmark results (1M rows):

  • 3 columns: 2.2x faster
  • 10 columns: 6.4x faster

For tables with generated columns, falls back to the original fetch-by-rowid path since generated columns cannot be scanned directly.

Changes:

  • Add return_columns vector to LogicalDelete to track column mappings
  • Modify bind_delete.cpp to add RETURNING columns to scan
  • Update PhysicalDelete to reference columns from input chunk
  • Add benchmarks for DELETE RETURNING performance

Instead of fetching columns by rowid in PhysicalDelete for RETURNING clause,
add required columns to the initial table scan and pass them through directly.
This eliminates expensive point lookups and improves performance significantly.

Benchmark results (1M rows):
- 3 columns: 2.2x faster
- 10 columns: 6.4x faster

For tables with generated columns, falls back to the original fetch-by-rowid
path since generated columns cannot be scanned directly.

Changes:
- Add return_columns vector to LogicalDelete to track column mappings
- Modify bind_delete.cpp to add RETURNING columns to scan
- Update PhysicalDelete to reference columns from input chunk
- Add benchmarks for DELETE RETURNING performance
@krleonid krleonid force-pushed the optimize-delete-returning branch from ef28123 to bdc3976 Compare January 12, 2026 07:31
Tests added to test/sql/returning/returning_delete.test:
- DELETE RETURNING without generated columns (optimized scan pass-through path)
- DELETE RETURNING with column in both WHERE and RETURNING
- DELETE RETURNING with VIRTUAL generated columns (fallback fetch-by-rowid path)
- DELETE RETURNING with generated column in middle of table
- DELETE RETURNING with multiple generated columns
- DELETE RETURNING with generated VARCHAR column
@krleonid krleonid merged commit 175069f into main Jan 14, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants