-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[indexer] merge in indexer breaking change park (#18899)
## Description Changes in this uhaul PR includes: - Addition of `objects_version` table - Addition of a number of transaction and event indices tables, with the removal of `tx_calls` table. - Enable pruning for the newly added indices tables and make tx sequence number a valid partition range, in addition to cp sequence number. ## Test plan tested locally --- ## Release notes This PR modifies the indexer db schemas for improving GraphQL query performance. Specifically, an `objects_version` table along with various transaction and events lookup tables are added. `tx_calls` table is removed by more fine-grained tables `tx_calls_pkg`, `tx_calls_mod` and `tx_calls_fun`. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [x] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] REST API: --------- Co-authored-by: Ashok Menon <ashok@mystenlabs.com> Co-authored-by: wlmyng <127570466+wlmyng@users.noreply.github.com>
- Loading branch information
Showing
35 changed files
with
1,448 additions
and
178 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
13 changes: 10 additions & 3 deletions
13
crates/sui-indexer/migrations/mysql/2024-04-24-180249_packages/up.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 |
---|---|---|
@@ -1,7 +1,14 @@ | ||
CREATE TABLE packages | ||
( | ||
package_id blob NOT NULL, | ||
package_id BLOB NOT NULL, | ||
original_id BLOB NOT NULL, | ||
package_version BIGINT NOT NULL, | ||
-- bcs serialized MovePackage | ||
move_package MEDIUMBLOB NOT NULL, | ||
CONSTRAINT packages_pk PRIMARY KEY (package_id(255)) | ||
move_package MEDIUMBLOB NOT NULL, | ||
checkpoint_sequence_number BIGINT NOT NULL, | ||
CONSTRAINT packages_pk PRIMARY KEY (package_id(32), original_id(32), package_version), | ||
CONSTRAINT packages_unique_package_id UNIQUE (package_id(32)) | ||
); | ||
|
||
CREATE INDEX packages_cp_id_version ON packages (checkpoint_sequence_number, original_id(32), package_version); | ||
CREATE INDEX packages_id_version_cp ON packages (original_id(32), package_version, checkpoint_sequence_number); |
1 change: 1 addition & 0 deletions
1
crates/sui-indexer/migrations/mysql/2024-05-05-155158_obj_indices/down.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 @@ | ||
DROP TABLE IF EXISTS objects_version; |
9 changes: 9 additions & 0 deletions
9
crates/sui-indexer/migrations/mysql/2024-05-05-155158_obj_indices/up.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,9 @@ | ||
-- The Postgres version of this table is partitioned by the first byte | ||
-- of object_id, but this kind of partition is not easily supported in | ||
-- MySQL, so this variant is unpartitioned for now. | ||
CREATE TABLE objects_version ( | ||
object_id BLOB NOT NULL, | ||
object_version BIGINT NOT NULL, | ||
cp_sequence_number BIGINT NOT NULL, | ||
PRIMARY KEY (object_id(32), object_version) | ||
) |
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
1 change: 1 addition & 0 deletions
1
crates/sui-indexer/migrations/pg/2023-08-19-044026_transactions/down.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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
-- This file should undo anything in `up.sql` | ||
DROP TABLE IF EXISTS transactions; | ||
DROP TABLE IF EXISTS transactions_partition_0; |
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
20 changes: 11 additions & 9 deletions
20
crates/sui-indexer/migrations/pg/2023-08-19-044044_checkpoints/up.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
14 changes: 11 additions & 3 deletions
14
crates/sui-indexer/migrations/pg/2023-08-19-060729_packages/up.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 |
---|---|---|
@@ -1,6 +1,14 @@ | ||
CREATE TABLE packages | ||
CREATE TABLE packages | ||
( | ||
package_id bytea PRIMARY KEY, | ||
package_id bytea NOT NULL, | ||
original_id bytea NOT NULL, | ||
package_version bigint NOT NULL, | ||
-- bcs serialized MovePackage | ||
move_package bytea NOT NULL | ||
move_package bytea NOT NULL, | ||
checkpoint_sequence_number bigint NOT NULL, | ||
CONSTRAINT packages_pkey PRIMARY KEY (package_id, original_id, package_version), | ||
CONSTRAINT packages_unique_package_id UNIQUE (package_id) | ||
); | ||
|
||
CREATE INDEX packages_cp_id_version ON packages (checkpoint_sequence_number, original_id, package_version); | ||
CREATE INDEX packages_id_version_cp ON packages (original_id, package_version, checkpoint_sequence_number); |
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
61 changes: 37 additions & 24 deletions
61
crates/sui-indexer/migrations/pg/2023-10-06-204335_tx_indices/up.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 |
---|---|---|
@@ -1,57 +1,70 @@ | ||
CREATE TABLE tx_senders ( | ||
cp_sequence_number BIGINT NOT NULL, | ||
tx_sequence_number BIGINT NOT NULL, | ||
-- SuiAddress in bytes. | ||
sender BYTEA NOT NULL, | ||
PRIMARY KEY(sender, tx_sequence_number, cp_sequence_number) | ||
PRIMARY KEY(sender, tx_sequence_number) | ||
); | ||
CREATE INDEX tx_senders_tx_sequence_number_index ON tx_senders (tx_sequence_number, cp_sequence_number); | ||
|
||
CREATE TABLE tx_recipients ( | ||
cp_sequence_number BIGINT NOT NULL, | ||
tx_sequence_number BIGINT NOT NULL, | ||
-- SuiAddress in bytes. | ||
recipient BYTEA NOT NULL, | ||
PRIMARY KEY(recipient, tx_sequence_number, cp_sequence_number) | ||
sender BYTEA NOT NULL, | ||
PRIMARY KEY(recipient, tx_sequence_number) | ||
); | ||
CREATE INDEX tx_recipients_tx_sequence_number_index ON tx_recipients (tx_sequence_number, cp_sequence_number); | ||
CREATE INDEX tx_recipients_sender ON tx_recipients (sender, recipient, tx_sequence_number); | ||
|
||
CREATE TABLE tx_input_objects ( | ||
cp_sequence_number BIGINT NOT NULL, | ||
tx_sequence_number BIGINT NOT NULL, | ||
-- Object ID in bytes. | ||
object_id BYTEA NOT NULL, | ||
PRIMARY KEY(object_id, tx_sequence_number, cp_sequence_number) | ||
sender BYTEA NOT NULL, | ||
PRIMARY KEY(object_id, tx_sequence_number) | ||
); | ||
CREATE INDEX tx_input_objects_tx_sequence_number_index ON tx_input_objects (tx_sequence_number); | ||
CREATE INDEX tx_input_objects_sender ON tx_input_objects (sender, object_id, tx_sequence_number); | ||
|
||
CREATE TABLE tx_changed_objects ( | ||
cp_sequence_number BIGINT NOT NULL, | ||
tx_sequence_number BIGINT NOT NULL, | ||
-- Object Id in bytes. | ||
object_id BYTEA NOT NULL, | ||
PRIMARY KEY(object_id, tx_sequence_number, cp_sequence_number) | ||
sender BYTEA NOT NULL, | ||
PRIMARY KEY(object_id, tx_sequence_number) | ||
); | ||
CREATE INDEX tx_changed_objects_tx_sequence_number_index ON tx_changed_objects (tx_sequence_number); | ||
CREATE INDEX tx_changed_objects_sender ON tx_changed_objects (sender, object_id, tx_sequence_number); | ||
|
||
CREATE TABLE tx_calls_pkg ( | ||
tx_sequence_number BIGINT NOT NULL, | ||
package BYTEA NOT NULL, | ||
sender BYTEA NOT NULL, | ||
PRIMARY KEY(package, tx_sequence_number) | ||
); | ||
CREATE INDEX tx_calls_pkg_sender ON tx_calls_pkg (sender, package, tx_sequence_number); | ||
|
||
CREATE TABLE tx_calls_mod ( | ||
tx_sequence_number BIGINT NOT NULL, | ||
package BYTEA NOT NULL, | ||
module TEXT NOT NULL, | ||
sender BYTEA NOT NULL, | ||
PRIMARY KEY(package, module, tx_sequence_number) | ||
); | ||
CREATE INDEX tx_calls_mod_sender ON tx_calls_mod (sender, package, module, tx_sequence_number); | ||
|
||
CREATE TABLE tx_calls ( | ||
cp_sequence_number BIGINT NOT NULL, | ||
CREATE TABLE tx_calls_fun ( | ||
tx_sequence_number BIGINT NOT NULL, | ||
package BYTEA NOT NULL, | ||
module TEXT NOT NULL, | ||
func TEXT NOT NULL, | ||
-- 1. Using Primary Key as a unique index. | ||
-- 2. Diesel does not like tables with no primary key. | ||
PRIMARY KEY(package, tx_sequence_number, cp_sequence_number) | ||
sender BYTEA NOT NULL, | ||
PRIMARY KEY(package, module, func, tx_sequence_number) | ||
); | ||
CREATE INDEX tx_calls_module ON tx_calls (package, module, tx_sequence_number, cp_sequence_number); | ||
CREATE INDEX tx_calls_func ON tx_calls (package, module, func, tx_sequence_number, cp_sequence_number); | ||
CREATE INDEX tx_calls_tx_sequence_number ON tx_calls (tx_sequence_number, cp_sequence_number); | ||
CREATE INDEX tx_calls_fun_sender ON tx_calls_fun (sender, package, module, func, tx_sequence_number); | ||
|
||
-- un-partitioned table for tx_digest -> (cp_sequence_number, tx_sequence_number) lookup. | ||
CREATE TABLE tx_digests ( | ||
tx_digest BYTEA PRIMARY KEY, | ||
cp_sequence_number BIGINT NOT NULL, | ||
tx_sequence_number BIGINT NOT NULL | ||
); | ||
CREATE INDEX tx_digests_tx_sequence_number ON tx_digests (tx_sequence_number); | ||
|
||
CREATE TABLE tx_kinds ( | ||
tx_sequence_number BIGINT NOT NULL, | ||
tx_kind SMALLINT NOT NULL, | ||
PRIMARY KEY(tx_kind, tx_sequence_number) | ||
); |
6 changes: 3 additions & 3 deletions
6
crates/sui-indexer/migrations/pg/2023-11-29-193859_advance_partition/up.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
1 change: 1 addition & 0 deletions
1
crates/sui-indexer/migrations/pg/2024-05-05-155158_obj_indices/down.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 @@ | ||
DROP TABLE IF EXISTS objects_version; |
31 changes: 31 additions & 0 deletions
31
crates/sui-indexer/migrations/pg/2024-05-05-155158_obj_indices/up.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,31 @@ | ||
-- Indexing table mapping an object's ID and version to its checkpoint | ||
-- sequence number, partitioned by the first byte of its Object ID. | ||
CREATE TABLE objects_version ( | ||
object_id bytea NOT NULL, | ||
object_version bigint NOT NULL, | ||
cp_sequence_number bigint NOT NULL, | ||
PRIMARY KEY (object_id, object_version) | ||
) PARTITION BY RANGE (object_id); | ||
|
||
-- Create a partition for each first byte value. | ||
DO $$ | ||
DECLARE | ||
lo text; | ||
hi text; | ||
BEGIN | ||
FOR i IN 0..254 LOOP | ||
lo := LPAD(TO_HEX(i), 2, '0'); | ||
hi := LPAD(TO_HEX(i + 1), 2, '0'); | ||
EXECUTE FORMAT($F$ | ||
CREATE TABLE objects_version_%1$s PARTITION OF objects_version FOR VALUES | ||
FROM (E'\\x%1$s00000000000000000000000000000000000000000000000000000000000000') | ||
TO (E'\\x%2$s00000000000000000000000000000000000000000000000000000000000000'); | ||
$F$, lo, hi); | ||
END LOOP; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
-- Special case for the last partition, because of the upper bound. | ||
CREATE TABLE objects_version_ff PARTITION OF objects_version FOR VALUES | ||
FROM (E'\\xff00000000000000000000000000000000000000000000000000000000000000') | ||
TO (MAXVALUE); |
7 changes: 7 additions & 0 deletions
7
crates/sui-indexer/migrations/pg/2024-06-14-045801_event_indices/down.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,7 @@ | ||
DROP TABLE IF EXISTS event_emit_package; | ||
DROP TABLE IF EXISTS event_emit_module; | ||
DROP TABLE IF EXISTS event_struct_package; | ||
DROP TABLE IF EXISTS event_struct_module; | ||
DROP TABLE IF EXISTS event_struct_name; | ||
DROP TABLE IF EXISTS event_struct_type; | ||
DROP TABLE IF EXISTS event_senders; |
Oops, something went wrong.