kaxil opened a new pull request, #60955:
URL: https://github.com/apache/airflow/pull/60955
## Summary
The `XComModel.clear()` method was loading all matching XCom records into
memory and deleting them one by one:
```python
# Before: Load all records, delete one by one
for xcom in session.scalars(query):
session.delete(xcom)
```
For tasks with many XCom entries (e.g., mapped tasks with many keys), this
caused:
- Unnecessary memory usage (loading all XCom objects into Python)
- N+1 DELETE statements (one per record)
This change uses a single bulk DELETE statement:
```python
# After: Single bulk delete
session.execute(delete_stmt)
```
This is both more memory-efficient and faster.
## Why the change is safe
1. **No ORM events needed**: The `XComModel` class doesn't define any
`before_delete` or `after_delete` event listeners that would require individual
object deletion
2. **No cascade relationships to trigger**: The XCom table has foreign keys
TO task_instance (with `ondelete="CASCADE"`), not FROM other tables - so there
are no child records that need individual handling
3. **Existing pattern in codebase**: The `XComModel.set()` method already
uses bulk delete for removing duplicates (line 226-234)
## Verification
- All existing `TestXComClear` tests pass
- All 37 tests in `test_xcom.py` pass
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]