Search before asking
Motivation
Currently DELETE FROM on a primary-key table always scans the target table to find matching rows, even when the condition is just primary keys, e.g.:
DELETE FROM t WHERE id IN (1, 2, 3);
DELETE FROM t WHERE id IN (SELECT id FROM keys_to_delete);
For these cases the matched keys are already fully described by the condition itself, so we can build the -D records directly and skip the target table scan entirely. On large tables (we have a case deleting ~10 million keys from a multi-billion-row table by a key table) this is orders of magnitude cheaper than the current scan / join based path.
Solution
Add a fast path in DeleteFromPaimonTableCommand for the pk-upsert delete:
- If the condition is a conjunction of
pk = literal / pk IN (literals) covering all primary key columns: extract keys from the condition and write -D rows directly (with a config to cap the driver-side cartesian expansion, falling back to scan when exceeded).
- If the condition is
pk IN (subquery) covering all primary key columns: use the subquery result as the key DataFrame, fully distributed.
- Any other condition falls back to the existing scan-based path, so behavior stays unchanged.
Keys absent from the table are harmless since the -D records simply merge away in compaction.
I have a working implementation with tests, will submit a PR.
Anything else?
No response
Are you willing to submit a PR?
Search before asking
Motivation
Currently
DELETE FROMon a primary-key table always scans the target table to find matching rows, even when the condition is just primary keys, e.g.:For these cases the matched keys are already fully described by the condition itself, so we can build the
-Drecords directly and skip the target table scan entirely. On large tables (we have a case deleting ~10 million keys from a multi-billion-row table by a key table) this is orders of magnitude cheaper than the current scan / join based path.Solution
Add a fast path in
DeleteFromPaimonTableCommandfor the pk-upsert delete:pk = literal/pk IN (literals)covering all primary key columns: extract keys from the condition and write-Drows directly (with a config to cap the driver-side cartesian expansion, falling back to scan when exceeded).pk IN (subquery)covering all primary key columns: use the subquery result as the key DataFrame, fully distributed.Keys absent from the table are harmless since the
-Drecords simply merge away in compaction.I have a working implementation with tests, will submit a PR.
Anything else?
No response
Are you willing to submit a PR?