Skip to content

[Feature] Point-delete fast path for primary key DELETE to skip the target table scan #8836

Description

@ZZZxDong

Search before asking

  • I searched in the issues and found nothing similar.

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?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions