Repository navigation
Adds Drop Table - #897
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 @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; |
| } | ||
| } | ||
| } else { | ||
| // if the node is a leaf node, clear overflow pages |
There was a problem hiding this comment.
Maybe not for now but we also need to check overflow pages on interior index pages because they have variable size payload.
| 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.
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.
@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.
@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.
@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
…emented 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 #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 commit changes the contents of the state machine state for ClearOverflowPages to contain the BTreeCell instead of the cell index. this avoids having to repeatedly do an operation to get the BTreeCell from the cell index each time the state is reached
this commit introduces the ability of the state machine traversal to handle index interior cell overflow pages. it also makes the state machine states more explicit with match arms.
| let init_label = program.emit_init(); | ||
| let start_offset = program.offset(); | ||
|
|
||
| let r1 = program.alloc_register(); // r1 |
renames the variable r1 to null_reg since that's the purpose anyway
I wanted to assist the current development in an up-to-date fashion, this PR adds drop table(which is being implemented currently in tursodatabase#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 tursodatabase#949
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 changes the contents of the state machine state for ClearOverflowPages to contain the BTreeCell instead of the cell index. this avoids having to repeatedly do an operation to get the BTreeCell from the cell index each time the state is reached
…#897 (comment) by @pereman2 this commit introduces the ability of the state machine traversal to handle index interior cell overflow pages. it also makes the state machine states more explicit with match arms.
renames the variable r1 to null_reg since that's the purpose anyway
This PR adds support for `DROP TABLE` and addresses issue tursodatabase#894 It depends on tursodatabase#785 being merged in because it requires the implementation of `free_page`. EDIT: The PR above has been merged. It adds the following: * an implementation for the `DropTable` AST instruction via a method called `translate_drop_table` * a couple of new instructions - `Destroy` and `DropTable`. 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` on `BTreeCursor` to walk the tree of pages for this table and place it in free list. * state machine traversal for both `btree_destroy` and `clear_overflow_pages` to ensure performant, correct code. * unit & tcl tests * modifies the `Null` instruction to follow SQLite semantics and accept a second register. It will set all registers in this range to null. This is required for `DROP TABLE`. 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 the `sqlite_schema` table. This is because `OpenEphemeral` is still a WIP and is being tracked at tursodatabase#768   Reviewed-by: Pere Diaz Bou <pere-altea@homail.com> Closes tursodatabase#897
…amples/react-native' from app/dependabot Bumps [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml- parser) from 5.11.1 to 5.12.1. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/NaturalIntelligence/fast-xml- parser/releases">fast-xml-parser's releases</a>.</em></p> <blockquote> <h2>v5.12.1</h2> <h2>What's Changed</h2> <ul> <li>fix: correct demo parser and builder options by <a href="https://github.com/arba- octo"><code>@arba-octo</code></a> in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/897">NaturalIntelligence/fast-xml-parser#897</a></li> <li>Bump github/codeql-action/init from 4.36.2 to 4.39.1 by <a href="https://github.com/dependabot"><code>@dependabot</code></a>[bot] in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/907">NaturalIntelligence/fast-xml-parser#907</a></li> <li>Bump github/codeql-action/analyze from 4.36.2 to 4.39.1 by <a href="https://github.com/dependabot"><code>@dependabot</code></a>[bot] in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/905">NaturalIntelligence/fast-xml-parser#905</a></li> <li>perf: skip quoted attribute values in one step (long SVG path data 4-5x faster) by <a href="https://github.com/deadstrobe5"><code>@deadstrobe5</code></a> in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/919">NaturalIntelligence/fast-xml-parser#919</a></li> </ul> <h2>New Contributors</h2> <ul> <li><a href="https://github.com/arba- octo"><code>@arba-octo</code></a> made their first contribution in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/897">NaturalIntelligence/fast-xml-parser#897</a></li> <li><a href="https://github.com/deadstrobe5"><code>@deadstrobe5</code></a> made their first contribution in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/919">NaturalIntelligence/fast-xml-parser#919</a></li> </ul> <p><strong>Full Changelog</strong>: <a href="https://github.com/NaturalIntelligence/fast-xml-parser/compare/v5. 12.0...v5.12.1">https://github.com/NaturalIntelligence/fast-xml- parser/compare/v5.12.0...v5.12.1</a></p> <h2>v5.12.0</h2> <h2>What's Changed</h2> <ul> <li>fix: add endIndex to the CommonJS XMLMetaData declaration by <a href="https://github.com/dualfroz"><code>@dualfroz</code></a> in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/896">NaturalIntelligence/fast-xml-parser#896</a></li> <li>Bump zizmorcore/zizmor-action from 0.6.1 to 0.8.0 by <a href="https://github.com/dependabot"><code>@dependabot</code></a>[bot] in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/906">NaturalIntelligence/fast-xml-parser#906</a></li> <li>Bump actions/setup-node from 7.0.0 to 7.1.0 by <a href="https://github.com/dependabot"><code>@dependabot</code></a>[bot] in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/904">NaturalIntelligence/fast-xml-parser#904</a></li> <li>fix: preserve original metadata offsets for CRLF input by <a href="https://github.com/Sskift"><code>@Sskift</code></a> in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/911">NaturalIntelligence/fast-xml-parser#911</a></li> <li>docs: update NASA link in users list by <a href="https://github.com/CodeVertex55"><code>@CodeVertex55</code></a> in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/885">NaturalIntelligence/fast-xml-parser#885</a></li> <li>README.md: fix documentation links by <a href="https://github.com/maxlath"><code>@maxlath</code></a> in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/872">NaturalIntelligence/fast-xml-parser#872</a></li> <li>test: drop shadowed ignoreAttributes option by <a href="https://github.com/rajanpanth"><code>@rajanpanth</code></a> in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/863">NaturalIntelligence/fast-xml-parser#863</a></li> </ul> <h2>New Contributors</h2> <ul> <li><a href="https://github.com/dualfroz"><code>@dualfroz</code></a> made their first contribution in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/896">NaturalIntelligence/fast-xml-parser#896</a></li> <li><a href="https://github.com/Sskift"><code>@Sskift</code></a> made their first contribution in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/911">NaturalIntelligence/fast-xml-parser#911</a></li> <li><a href="https://github.com/CodeVertex55"><code>@CodeVertex55</code></a> made their first contribution in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/885">NaturalIntelligence/fast-xml-parser#885</a></li> <li><a href="https://github.com/maxlath"><code>@maxlath</code></a> made their first contribution in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/872">NaturalIntelligence/fast-xml-parser#872</a></li> </ul> <p><strong>Full Changelog</strong>: <a href="https://github.com/NaturalIntelligence/fast-xml-parser/compare/v5. 11.2...v5.12.0">https://github.com/NaturalIntelligence/fast-xml- parser/compare/v5.11.2...v5.12.0</a></p> <h2>v5.11.2</h2> <h2>What's Changed</h2> <ul> <li>fix: decode Uint8Array XML input as UTF-8 by <a href="https://github.com/emme1t"><code>@emme1t</code></a> in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/875">NaturalIntelligence/fast-xml-parser#875</a></li> <li>fix: type EntityDecoderOptions.setXmlVersion's version as a number by <a href="https://github.com/YevheniiKotyrlo"><code>@YevheniiKotyrlo< /code></a> in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/880">NaturalIntelligence/fast-xml-parser#880</a></li> </ul> <h2>New Contributors</h2> <ul> <li><a href="https://github.com/emme1t"><code>@emme1t</code></a> made their first contribution in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/875">NaturalIntelligence/fast-xml-parser#875</a></li> <li><a href="https://github.com/YevheniiKotyrlo"><code>@YevheniiKotyrlo</code> </a> made their first contribution in <a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/pull/880">NaturalIntelligence/fast-xml-parser#880</a></li> </ul> <p><strong>Full Changelog</strong>: <a href="https://github.com/NaturalIntelligence/fast-xml-parser/compare/v5. 11.1...v5.11.2">https://github.com/NaturalIntelligence/fast-xml- parser/compare/v5.11.1...v5.11.2</a></p> </blockquote> </details> <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/NaturalIntelligence/fast-xml- parser/blob/master/CHANGELOG.md">fast-xml-parser's changelog</a>.</em></p> <blockquote> <p><!-- raw HTML omitted -->Note: If you find missing information about particular minor version, that version must have been changed without any functional change in this library.<!-- raw HTML omitted --></p> <p>Note: Due to some last quick changes on v4, detail of v4.5.3 & v4.5.4 are not updated here. v4.5.4x is the last tag of v4 in github repository. I'm extremely sorry for the confusion</p> <p><strong>5.12.1 / 2026-11-13</strong></p> <ul> <li>deps: fast-xml-builder v1.3.2</li> <li>perf: skip quoted attribute values in one step (long SVG path data 4-5x faster) (<a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/issues/919">#919</a>) (By Afonso Ribeiro)</li> <li>perf: validator; attr scan</li> </ul> <p><strong>5.12.0 / 2026-11-03</strong></p> <ul> <li>perf improvement for stop node: After the first failure in a given stop node, the function stops using readTagExp and switches to a cheap fallback.</li> <li>devdep:jasmine 7.0</li> <li>deps: <ul> <li><code>@nodable/entities</code> v3.1.0</li> <li>fast-xml-builder v1.3.1</li> <li>is-unsafe v2.0.3</li> <li>strnum v2.5.1</li> </ul> </li> <li>fix cjs typing</li> <li>fix: preserve original metadata offsets for CRLF input (<a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/issues/911">#911</a>) (By <a href="https://github.com/sskift">sskift</a>)</li> </ul> <p><strong>5.11.2 / 2026-09-29</strong></p> <ul> <li>fix (<a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/issues/875">#875</a>): decode Uint8Array XML input as UTF-8 (By emme1t)</li> <li>fix (<a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/issues/880">#880</a>) :type EntityDecoderOptions.setXmlVersion's version as a number (By Yevhenii Kotyrlo)</li> </ul> <p><strong>5.11.1 / 2026-08-27</strong></p> <ul> <li>fix: validator; Replace regex with a single-pass scanner for attribute tokens, eliminating quadratic behavior on long whitespace runs.</li> </ul> <p><strong>5.11.0 / 2026-08-16</strong></p> <ul> <li>feat: support for endIndex in node metadata (<a href="https://redirect.github.com/NaturalIntelligence/fast- xml-parser/issues/850">#850</a>) [By <a href="https://github.com/Wain- PC">Pavel Dranichnikov</a>]</li> <li>fix: don't crash on a closing tag with no matching opening tag (<a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/issues/861">#861</a>) [By <a href="https://github.com/hdimer">Haïm Dimer</a>]</li> <li>fix: DOCTYPE to read SYSTEM/PUBLIC</li> <li>deps: strnum v2.4.2</li> </ul> <p><strong>5.10.1 / 2026-07-17</strong></p> <ul> <li>fix: multiple DOCTYPE declarations.</li> <li>deps: <code>@nodable/entities</code> for treeshaking</li> </ul> <p><strong>5.10.0 / 2026-07-11</strong></p> <ul> <li>upgrade: <ul> <li>xml-naming v0.3.0: cache support</li> <li>PEM v1.6.2: sibling bug fix</li> <li>is-unsafe v2.0.0: tree shaking</li> </ul> </li> </ul> <p>*<em>5.9.3 / 2026-06-19</em></p> <ul> <li>update strnum</li> </ul> <p>*<em>5.9.2 / 2026-06-17</em></p> <ul> <li>dummy release to test changes in github action</li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="NaturalIntelligence/fast-xml-parser@88b8 16b30d8d41fd276c35afa267e84f2bf4ffb5"><code>88b816b</code></a> 5.12.1</li> <li><a href="https://github.com/NaturalIntelligence/fast- xml-parser/commit/292d189993e0eae705597fe524fbb534b3a424c6"><code>292d18 9</code></a> update for release</li> <li><a href="NaturalIntelligence/fast-xml-parser@7016 813d0679d1bbdfecacd4b57529397ff9ad0b"><code>7016813</code></a> deps: fxb</li> <li><a href="https://github.com/NaturalIntelligence/fast-xml-pa rser/commit/4a1623bc23c011fd5ea0b72c21b00f3109688e6c"><code>4a1623b</cod e></a> perf: validator; attr scan</li> <li><a href="NaturalIntelligence/fast-xml-parser@339e aba32aee955a16ce277ae3f56137cf2f2c56"><code>339eaba</code></a> perf: skip quoted attribute values in one step (long SVG path data 4-5x faste...</li> <li><a href="https://github.com/NaturalIntelligence/fast- xml-parser/commit/d81af6066e27d65ab500d05c09e63ee9121aeb90"><code>d81af6 0</code></a> Bump github/codeql-action/analyze from 4.36.2 to 4.39.1 (<a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/issues/905">#905</a>)</li> <li><a href="NaturalIntelligence/fast-xml-parser@21ee 0c3c79c389562c8305cd9cd4ff051817fced"><code>21ee0c3</code></a> Bump github/codeql-action/init from 4.36.2 to 4.39.1 (<a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/issues/907">#907</a>)</li> <li><a href="NaturalIntelligence/fast-xml-parser@2460 b41927ad94d352c44297a3aa2fa22fe2d65d"><code>2460b41</code></a> fix: correct demo parser and builder options (<a href="https://redirect.github.com/NaturalIntelligence/fast-xml- parser/issues/897">#897</a>)</li> <li><a href="NaturalIntelligence/fast-xml-parser@d33f c7da4a5e73fae518134fa72c6725fd4698da"><code>d33fc7d</code></a> Enhance pull request template with project links</li> <li><a href="NaturalIntelligence/fast-xml-parser@9764 70f6100eac10304d80507bbd76fb739ba7f5"><code>976470f</code></a> 5.12.0</li> <li>Additional commits viewable in <a href="https://github.com/NaturalIntelligence/fast-xml- parser/compare/v5.11.1...v5.12.1">compare view</a></li> </ul> </details> <br /> [](https://docs.github.com/en/github/managing-security- vulnerabilities/about-dependabot-security-updates#about-compatibility- scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/tursodatabase/turso/network/alerts). </details> Closes #12464

This PR adds support for
DROP TABLEand 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:
DropTableAST instruction via a method calledtranslate_drop_tableDestroyandDropTable. The former is to modify physical b-tree pages and the latter is to modify in-memory structures like the schema hash table.btree_destroyonBTreeCursorto walk the tree of pages for this table and place it in free list.btree_destroyandclear_overflow_pagesto ensure performant, correct code.Nullinstruction 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_schematable and then re-inserting them back into thesqlite_schematable.This is because
OpenEphemeralis still a WIP and is being tracked at #768