-
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.
[1+2/n][gql-performance][pg] Update tx lookup tables-related schema f…
…iles for pg-backed indexer per transactions benchmark findings (#18231) Apply findings from latest transactions benchmarking. Instead of keeping indexes on `transactions`, we offload all filtering work to the lookup tables. Additionally, we add `tx_calls_pkg` and `tx_calls_mod` and dedicate `tx_calls_fun` to solely handle filters on `package`, `package` and `module`, and `package`, `module`, and `func` respectively. This is because it's possible to invoke the same package, mod, and even func in a transaction. Finally, the new setup drops `cp_sequence_number` from the lookup tables and adds `sender` to them to support `sender` + specialized filter. The Rust structs and code to index data to the lookup tables are also updated. The full stack of changes are listed below, but each can stand independently, and will be individually merged into `idx-breaking-change-park` 1. #18224 - handling tables partitioned on epoch's worth of tx_sequence_number 2. #18244 - storing a mapping of checkpoint -> tx_sequence_number range --- Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK:
- Loading branch information
Showing
11 changed files
with
295 additions
and
103 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
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
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,54 +1,67 @@ | ||
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_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_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, module, func, tx_sequence_number, cp_sequence_number) | ||
sender BYTEA NOT NULL, | ||
PRIMARY KEY(package, module, func, tx_sequence_number) | ||
); | ||
CREATE INDEX tx_calls_package ON tx_calls (package, tx_sequence_number, cp_sequence_number); | ||
CREATE INDEX tx_calls_module ON tx_calls (package, module, 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 TABLE tx_kinds ( | ||
tx_sequence_number BIGINT NOT NULL, | ||
tx_kind SMALLINT NOT NULL, | ||
PRIMARY KEY(tx_kind, tx_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
Oops, something went wrong.