Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions prisma/rsk-explorer-database.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
-- RSK Explorer Database Schema V1.2.3
-- RSK Explorer Database Schema V1.2.4
/*

V1.2.4 Notes:
- Added indexes for NFT support in event table

V1.2.3 Notes:
- Normalized SQL schema across environments

Expand Down Expand Up @@ -483,6 +486,13 @@ CREATE INDEX idx_event_transaction_hash_log_index ON event(transaction_hash, log
CREATE INDEX idx_event_address_event_event_id ON event(address, event, event_id DESC);
CREATE INDEX idx_event_event ON event(event);
CREATE INDEX idx_event_lowercase_event ON event(lower((event)::text));
CREATE INDEX idx_event_addr_t0_t3 ON event(address, topic0, topic3, block_number DESC, transaction_index DESC, log_index DESC);
CREATE INDEX idx_event_addr_t0_block_log_desc ON event(address, topic0, block_number DESC, transaction_index DESC, log_index DESC);
Comment on lines +489 to +490

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please take a look for alternatives to adding 7 indexes, that in total take 30G of disk space, plus the increase in write times.

On the other hand, the indexes don't reduce the response time of the endpoints, that take around 8 seconds with and without the indexes.

CREATE INDEX idx_event_t0_t1 ON event(topic0, topic1);
CREATE INDEX idx_event_t0_t2 ON event(topic0, topic2);
CREATE INDEX idx_event_t0_t3 ON event(topic0, topic3);
CREATE INDEX idx_event_addr_t0_t1_block_log ON event(address, topic0, topic1, block_number DESC, transaction_index DESC, log_index DESC);
CREATE INDEX idx_event_addr_t0_t2_block_log ON event(address, topic0, topic2, block_number DESC, transaction_index DESC, log_index DESC);

CREATE TABLE address_in_event (
event_id VARCHAR,
Expand Down Expand Up @@ -652,4 +662,4 @@ CREATE TABLE bo_active_addresses_daily_aggregated (
CREATE TABLE bo_number_transactions_daily_aggregated (
date_1 DATE PRIMARY KEY,
number_of_transactions INT
);
);
7 changes: 7 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ model event {
@@index([transactionHash, logIndex], map: "idx_event_transaction_hash_log_index")
@@index([address, event, eventId(sort: Desc)], map: "idx_event_address_event_event_id")
@@index([event], map: "idx_event_event")
@@index([address, topic0, topic3, blockNumber(sort: Desc), transactionIndex(sort: Desc), logIndex(sort: Desc)], map: "idx_event_addr_t0_t3")
@@index([topic0, topic1], map: "idx_event_t0_t1")
@@index([topic0, topic2], map: "idx_event_t0_t2")
@@index([address, topic0, blockNumber(sort: Desc), transactionIndex(sort: Desc), logIndex(sort: Desc)], map: "idx_event_addr_t0_block_log_desc")
@@index([address, topic0, topic1, blockNumber(sort: Desc), transactionIndex(sort: Desc), logIndex(sort: Desc)], map: "idx_event_addr_t0_t1_block_log")
@@index([address, topic0, topic2, blockNumber(sort: Desc), transactionIndex(sort: Desc), logIndex(sort: Desc)], map: "idx_event_addr_t0_t2_block_log")
@@index([topic0, topic3], map: "idx_event_t0_t3")
}

model internal_transaction {
Expand Down
Loading