Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for DELETE query planning #538

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

seonWKim
Copy link
Contributor

@seonWKim seonWKim commented Dec 22, 2024

Purpose of this PR

Support for DELETE query execution planning

Implementation Details

The main entry point for planning DELETE queries is the translate_delete function. It is composed of three primary steps:

  • prepare_delete_plan:

    • Reuses the existing SELECT query's WHERE clause parsing logic to interpret and construct the initial delete plan.
  • optimize_delete_plan:

    • eliminating BETWEEN expressions
    • usage of indexes
  • emit_program_for_delete:

    • Add instructions for delete operation

I've tried to reuse existing logic(mostly on SELECT operations) as much as I can, so that we can automatically incorporate new changes automatically.

Delete planning debug

I've used println!(...) to specify the rows to delete. Example below
image

Bytecode compatibility

EXPLAIN DELETE FROM users WHERE id = 1;

image

EXPLAIN DELETE FROM users WHERE id > 3

image

EXPLAIN DELETE FROM users WHERE id < 3

image

TODO(future works)

  • Add support for Clear opcode
  • Add test when delete is implemented in Cursor
image

@seonWKim seonWKim force-pushed the feature/delete-planning branch from a55b0d4 to a42b185 Compare December 22, 2024 05:22
@seonWKim seonWKim force-pushed the feature/delete-planning branch from 3d2ac33 to 57c7a56 Compare December 22, 2024 05:27
@seonWKim seonWKim force-pushed the feature/delete-planning branch from f46fcee to e83819e Compare December 22, 2024 07:00
@seonWKim seonWKim marked this pull request as ready for review December 22, 2024 07:20
group_by: None,
order_by: None,
aggregates: vec![],
limit: None, // TODO: add support for limit
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fairly simple to add, search for DecrJumpZero in emitter.rs and put one of those in emit_delete_insns()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to maintain this PR small for now. And I want to improve my understanding on limit(+ order by).

What do you think of I add a follow up PR right after?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed my mind. Added limit support 🤖

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