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

DELETE implementation #475

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

krishvishal
Copy link
Contributor

  • I want to initially make it work for a simple DELETE statement like the following.
CREATE TABLE test(id INTEGER PRIMARY KEY, value TEXT);
INSERT INTO test VALUES(1, 'test');
DELETE FROM test WHERE id = 1;
  • currently doesn't work because inside core/storage/btree.rs delete_record cell_idx is being calculated wrong.

I'm still studying the sqlite source code and some other material. So this implementation can be wrong.

- currently doesn't work because in delete_record `cell_idx` is being calculated wrong.
page.set_dirty();
self.pager.add_dirty(page.get().id);

return_if_io!(self.balance_after_delete());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would need more time to reviews this. As far as I know sqlite deletes a cell from a page and the there is a loop that calls balance. balance checks wether there is an overflow (what we do now) or underflow. I want to refactor the balance because it should be as close to sqlite as possible so we should stick to that instead of having different types of balancing.

Copy link
Collaborator

@pereman2 pereman2 left a comment

Choose a reason for hiding this comment

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

Btw we need a lot of tests for this

);
let start_offset = program.offset();

let table_name = &qualified_table_name.name.0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

need to use normalize_ident() for this to make sure e.g. both "users" and [users] match the table users

let table_name = &qualified_table_name.name.0;
let table = match schema.get_table(table_name) {
Some(t) => t,
None => crate::bail_corrupt_error!("No such table: {}", table_name),
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 bail_parse_error!

let mut expr = *where_expr.clone();
bind_column_references(&mut expr, &referenced_tables)?;

// Handle WHERE id = value case
Copy link
Collaborator

Choose a reason for hiding this comment

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

you should be able to use translate_condition_expr() for this

returning,
..
} => {
assert!(returning.is_none()); // Don't handle RETURNING yet
Copy link
Collaborator

@jussisaurio jussisaurio Dec 22, 2024

Choose a reason for hiding this comment

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

bail_parse_error!("DELETE ... RETURNING is not supported yet")

..
} => {
assert!(returning.is_none()); // Don't handle RETURNING yet
let boxed_where = where_clause.map(Box::new);
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this boxed?

@seonWKim
Copy link
Contributor

Is this PR being actively worked on? 🙏

@krishvishal
Copy link
Contributor Author

@seonWKim, yes I'm working on it. I'm working on making the PR more comprehensive.

I was away for the past two weeks.

@seonWKim
Copy link
Contributor

seonWKim commented Dec 28, 2024

@krishvishal PR for delete planning has been added to main. Maybe you can make use of it.

Btw, is there any docs or code you are referring to when implementing DELETE on btree.rs? I also want to take a look

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.

4 participants