-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(sqlite): use null parent and root TX ID for optimistic data …
…items PE-6284 For expedience, the initial optimistic indexing code used placeholder values for root TX ID and parent. While this mostly works, it's confusing and produces inaccurate GQL results without extra post processing (optimistic data item parents are wrong). This change modifies the DB to allow null parent, root transaction ids, and offsets. It also adjusts types to allow for this and introduces extra conditionals to ensure that bundle imports and data indexing for optimistically indexed data items are not attempted. This prevents errant optimistic data items from making their way into the stable indexes.
- Loading branch information
Showing
11 changed files
with
261 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
migrations/2024.06.13T13.52.01.bundles.nullable-parent-and-root.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
DROP TABLE new_data_items; | ||
|
||
CREATE TABLE new_data_items ( | ||
-- Identity | ||
id BLOB NOT NULL, | ||
parent_id BLOB, | ||
root_transaction_id BLOB, | ||
height INTEGER, | ||
signature BLOB NOT NULL, | ||
anchor BLOB NOT NULL, | ||
|
||
-- Ownership | ||
owner_address BLOB NOT NULL, | ||
target BLOB, | ||
|
||
-- Data | ||
data_offset INTEGER, | ||
data_size INTEGER NOT NULL, | ||
content_type TEXT, | ||
|
||
-- Metadata | ||
tag_count INTEGER NOT NULL, | ||
indexed_at INTEGER NOT NULL, | ||
PRIMARY KEY (id) | ||
); | ||
|
||
CREATE INDEX new_data_items_parent_id_id_idx ON new_data_items (parent_id, id); | ||
CREATE INDEX new_data_items_root_transaction_id_id_idx ON new_data_items (root_transaction_id, id); | ||
CREATE INDEX new_data_items_target_id_idx ON new_data_items (target, id); | ||
CREATE INDEX new_data_items_owner_address_id_idx ON new_data_items (owner_address, id); | ||
CREATE INDEX new_data_items_height_indexed_at_idx ON new_data_items (height, indexed_at); | ||
|
||
DROP TABLE new_data_item_tags; | ||
|
||
CREATE TABLE new_data_item_tags ( | ||
tag_name_hash BLOB NOT NULL, | ||
tag_value_hash BLOB NOT NULL, | ||
root_transaction_id BLOB, | ||
data_item_id BLOB NOT NULL, | ||
data_item_tag_index INTEGER NOT NULL, | ||
height INTEGER, | ||
indexed_at INTEGER NOT NULL, | ||
PRIMARY KEY (tag_name_hash, tag_value_hash, root_transaction_id, data_item_id, data_item_tag_index) | ||
); | ||
|
||
CREATE INDEX new_data_item_tags_height_indexed_at_idx ON new_data_item_tags (height, indexed_at); | ||
CREATE INDEX new_data_item_tags_data_item_id_idx ON new_data_item_tags (data_item_id); |
48 changes: 48 additions & 0 deletions
48
migrations/down/2024.06.13T13.52.01.bundles.nullable-parent-and-root.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
-- down migration | ||
DROP TABLE new_data_item_tags; | ||
|
||
CREATE TABLE new_data_item_tags ( | ||
tag_name_hash BLOB NOT NULL, | ||
tag_value_hash BLOB NOT NULL, | ||
root_transaction_id BLOB NOT NULL, | ||
data_item_id BLOB NOT NULL, | ||
data_item_tag_index INTEGER NOT NULL, | ||
height INTEGER, | ||
indexed_at INTEGER NOT NULL, | ||
PRIMARY KEY (tag_name_hash, tag_value_hash, root_transaction_id, data_item_id, data_item_tag_index) | ||
); | ||
|
||
CREATE INDEX new_data_item_tags_height_indexed_at_idx ON new_data_item_tags (height, indexed_at); | ||
CREATE INDEX new_data_item_tags_data_item_id_idx ON new_data_item_tags (data_item_id); | ||
|
||
DROP TABLE new_data_items; | ||
|
||
CREATE TABLE new_data_items ( | ||
-- Identity | ||
id BLOB NOT NULL, | ||
parent_id BLOB NOT NULL, | ||
root_transaction_id BLOB NOT NULL, | ||
height INTEGER, | ||
signature BLOB NOT NULL, | ||
anchor BLOB NOT NULL, | ||
|
||
-- Ownership | ||
owner_address BLOB NOT NULL, | ||
target BLOB, | ||
|
||
-- Data | ||
data_offset INTEGER NOT NULL, | ||
data_size INTEGER NOT NULL, | ||
content_type TEXT, | ||
|
||
-- Metadata | ||
tag_count INTEGER NOT NULL, | ||
indexed_at INTEGER NOT NULL, | ||
PRIMARY KEY (id) | ||
); | ||
|
||
CREATE INDEX new_data_items_parent_id_id_idx ON new_data_items (parent_id, id); | ||
CREATE INDEX new_data_items_root_transaction_id_id_idx ON new_data_items (root_transaction_id, id); | ||
CREATE INDEX new_data_items_target_id_idx ON new_data_items (target, id); | ||
CREATE INDEX new_data_items_owner_address_id_idx ON new_data_items (owner_address, id); | ||
CREATE INDEX new_data_items_height_indexed_at_idx ON new_data_items (height, indexed_at); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.