-
Notifications
You must be signed in to change notification settings - Fork 339
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
Adds Drop Table #897
base: main
Are you sure you want to change the base?
Adds Drop Table #897
Conversation
Very nice @redixhumayun! I don't understand things below the btree yet but I can give my 2 cents about other things. Idk if you ran CREATE TABLE a (a); EXPLAIN DROP TABLE a (a);
There are some bytecodes that afaik we don't have implemented yet, like |
@diegoreis42 Hey, thanks for taking a look. Yeah, I took a look at the SQLite bytecode before I started working on this. Although, after your comment I went back fixed a few things. Yeah, I'm skipping the instructions that don't exist like ![]() |
@diegoreis42 @PThorpe92 @jussisaurio Btw how closely are we shooting to match the bytecodes across Limbo & SQLite? Because even for |
Hey @redixhumayun, I haven't taken a look at this quite yet, but to answer your question, with the exception of the obvious places we will differ like I'll have a look at this in the morning 👍 |
In case it uncovers any bugs; |
core/storage/btree.rs
Outdated
} | ||
} | ||
} else { | ||
// if the node is a leaf node, clear overflow pages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not for now but we also need to check overflow pages on interior index pages because they have variable size payload.
core/storage/btree.rs
Outdated
self.payload_overflow_threshold_min(contents.page_type()), | ||
self.usable_space(), | ||
)?; | ||
return_if_io!(self.clear_overflow_pages(&cell)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this returns Locked
then we will try to run the traversal again for every overflow page we try to load which is quite inefficient and I don't know if it's safe. It looks like we will need a state machine to keep track of all pages that are being deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pereman2 Regarding performance concerns, all pages should be in the page cache if the routine resumes, right?. Yes, traversal would be repeated.
I don't understand why it wouldn't be safe though. Could you explain?
Should I go ahead and add a state machine implementation to this routine? Guessing I need to add a new variant to CursorState
and use that to track?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pereman2 Regarding performance concerns, all pages should be in the page cache if the routine resumes, right?. Yes, traversal would be repeated.
There are no guarantees of a page being in cache unless you pin them. For example, there are no set_dirty
or pager.add_dirty
calls which marks them as pinned. But even though if we were to pin all of these pages, imagine the case where you drop a table which has 50GB worth of pages, now this means that would have to hold ALL pages in memory, but this is a problem that happens regardless of this destroy stuff anyways. Good thing about a state machine is that you can resume where you started, in this case maybe the PageStack
could be enough to ensure we don't traverse again from root to child page every time.
I don't understand why it wouldn't be safe though. Could you explain?
For example you call clear_overflow_pages
, which clears the first overflow page, and then it will try to load the second overflow page, but this page could return I/O because it's not in cache. This means that first page is now "freed" and somehow we need to traverse again "first page -> second page" but first page is not there now? This might be also a problem with current clear overflow pages because it should behave like a state machine with DFS
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pereman2 I've addressed your comments in f2e11a1 and 4eaeb18.
Can you take a look?
It adds a state machine to keep track of Destroy
operations and also adds another state machine to keep track of ClearOverflowPage
operations.
The reason for two separate state machines is because clear_overflow_pages
has two separate call sites (one from btree_destroy
and one from delete
) and I don't want to complicate the code by linking the state machine used by btree_destroy
to the state machine used in clear_overflow_pages
I wanted to assist the current development in an up-to-date fashion, this PR adds drop table(which is being implemented currently in #897) testing support to the generator. Unfortunately, we don't have feature flags in the simulator yet, so the users should manually fix the generation probability in `simulator/generation/plan.rs#L644` and `simulator/generation/property.rs#L629`. Closes #949
c892d70
to
f2e11a1
Compare
this commit adds the final touches to the state machine for btree_destroy and also introduces a state machine for clear_overflow_pages this addresses the issue of IO interrupting an operation in progress and solves the following problems: * performance issues with repeating an operation * missing page issues with clear overflow pages
this commit adds the final touches to the state machine for btree_destroy and also introduces a state machine for clear_overflow_pages this addresses the issue of IO interrupting an operation in progress and solves the following problems: * performance issues with repeating an operation * missing page issues with clear overflow pages
…LE to be implemented this is the initial commit is for the implementation of DROP TABLE. It adds support for the DROP TABLE instruction and adds a DropBTree instruction. It also implements the btree_drop method in btree.rs which makes use of free_page method which will be implemented via PR tursodatabase#785
the command for drop table translation has been updated so that it more closely matches the semantics of SQLite's drop table command. there are a few more things missing like ephemeral tables, destroy etc.
added required functionality for destroy. minor cleanup of print statements
correctly emitting constant instructions and also calling Destroy instead of DropTable instruction for removing btree pages
this more closely matches semantics
modified the Null instruction to more closely match SQLite semantics. Allows passing in a second register and all registers from r1..r2 area set to null
the instruction DropTable has been modified to correctly match SQLite semantics
added helper methods to Schema to remove table and indices from in-memory structures completed the implementation for DropTable using that
modified the btree_destroy subroutine to do an iterative DFS and use the stack cell counters to keep track of whether children have been removed. adds a unit test.
added missing instructions to drop the indices for a table physically from btree pages in a loop
this commit adds the final touches to the state machine for btree_destroy and also introduces a state machine for clear_overflow_pages this addresses the issue of IO interrupting an operation in progress and solves the following problems: * performance issues with repeating an operation * missing page issues with clear overflow pages
This PR adds support for
DROP TABLE
and addresses issue #894It depends on #785 being merged in because it requires the implementation of
free_page
.EDIT: The PR above has been merged.
It adds the following:
DropTable
AST instruction via a method calledtranslate_drop_table
Destroy
andDropTable
. The former is to modify physical b-tree pages and the latter is to modify in-memory structures like the schema hash table.btree_destroy
onBTreeCursor
to walk the tree of pages for this table and place it in free list.btree_destroy
andclear_overflow_pages
to ensure performant, correct code.Null
instruction to follow SQLite semantics and accept a second register. It will set all registers in this range to null. This is required forDROP TABLE
.Bytecode Compatibility
The screenshots below have a comparison of the bytecodes generated via SQLite & Limbo.
Limbo has the same instruction set except for the subroutines which involve opening an ephemeral table, copying over the triggers from the
sqlite_schema
table and then re-inserting them back into thesqlite_schema
table.This is because
OpenEphemeral
is still a WIP and is being tracked at #768