Skip to content

Conversation

@krleonid
Copy link
Owner

Summary

This PR extends the DELETE RETURNING optimization from PR duckdb#20485 to support tables with generated columns.

Problem

Previously, DELETE RETURNING would fall back to the slower row-ID-fetch path when the table had generated columns because generated columns cannot be scanned directly from disk - they must be computed from their expressions.

Solution

Instead of falling back, we now:

  1. Scan all physical columns and pass them through from the scan (same as before for non-generated tables)
  2. Let the RETURNING projection compute generated columns using their expressions

This is the same approach already used by INSERT RETURNING and UPDATE RETURNING.

Changes

  • bind_delete.cpp: Removed the HasGeneratedColumns() check that was skipping the optimization
  • physical_delete.cpp: Updated comment to reflect that generated columns are no longer a fallback reason
  • returning_delete.test: Updated test comments
  • delete_returning_3col_generated.benchmark: Updated description

Testing

All existing tests pass, including the tests for DELETE RETURNING with generated columns.

Previously, DELETE RETURNING would fall back to fetching columns by row ID
when the table had generated columns. This was because generated columns
cannot be scanned directly - they must be computed from their expressions.

This change allows the optimization to work with generated columns by:
1. Scanning all physical columns and passing them through from the scan
2. Letting the RETURNING projection compute generated columns using their
   expressions (same approach as INSERT/UPDATE RETURNING)

The comment in the fallback path is updated to reflect that generated
columns are no longer a reason to use the fallback path.
@krleonid krleonid merged commit 9612b5b into main Jan 20, 2026
117 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