From 359df4e9ba517af0cd8d4a423b6ba8be836f9a00 Mon Sep 17 00:00:00 2001 From: "elessar.eth" Date: Tue, 10 Sep 2024 02:20:08 +0200 Subject: [PATCH] perf(db): add rollup indexes (#558) * perf(db): remove rendundant block number index * perf(db): add rollup index keys * perf(db): add transaction sender/receiver indexes --- .../migration.sql | 2 ++ .../20240909234808_add_rollup_index/migration.sql | 5 +++++ .../migration.sql | 11 +++++++++++ packages/db/prisma/schema.prisma | 7 ++++--- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 packages/db/prisma/migrations/20240909234614_remove_redundant_block_number_index/migration.sql create mode 100644 packages/db/prisma/migrations/20240909234808_add_rollup_index/migration.sql create mode 100644 packages/db/prisma/migrations/20240910000321_add_tx_sender_receiver_indexes/migration.sql diff --git a/packages/db/prisma/migrations/20240909234614_remove_redundant_block_number_index/migration.sql b/packages/db/prisma/migrations/20240909234614_remove_redundant_block_number_index/migration.sql new file mode 100644 index 000000000..24e7699bf --- /dev/null +++ b/packages/db/prisma/migrations/20240909234614_remove_redundant_block_number_index/migration.sql @@ -0,0 +1,2 @@ +-- DropIndex +DROP INDEX "transaction_block_number_idx"; diff --git a/packages/db/prisma/migrations/20240909234808_add_rollup_index/migration.sql b/packages/db/prisma/migrations/20240909234808_add_rollup_index/migration.sql new file mode 100644 index 000000000..186494da1 --- /dev/null +++ b/packages/db/prisma/migrations/20240909234808_add_rollup_index/migration.sql @@ -0,0 +1,5 @@ +-- DropIndex +DROP INDEX "transaction_category_idx"; + +-- CreateIndex +CREATE INDEX "transaction_category_rollup_block_number_index_idx" ON "transaction"("category", "rollup", "block_number", "index"); diff --git a/packages/db/prisma/migrations/20240910000321_add_tx_sender_receiver_indexes/migration.sql b/packages/db/prisma/migrations/20240910000321_add_tx_sender_receiver_indexes/migration.sql new file mode 100644 index 000000000..49cf05181 --- /dev/null +++ b/packages/db/prisma/migrations/20240910000321_add_tx_sender_receiver_indexes/migration.sql @@ -0,0 +1,11 @@ +-- DropIndex +DROP INDEX "transaction_block_timestamp_idx"; + +-- CreateIndex +CREATE INDEX "transaction_block_timestamp_category_rollup_block_number_in_idx" ON "transaction"("block_timestamp", "category", "rollup", "block_number", "index"); + +-- CreateIndex +CREATE INDEX "transaction_from_id_block_number_index_idx" ON "transaction"("from_id", "block_number", "index"); + +-- CreateIndex +CREATE INDEX "transaction_to_id_block_number_index_idx" ON "transaction"("to_id", "block_number", "index"); diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index 58ebf26d2..cec4fad7d 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -168,10 +168,11 @@ model Transaction { @@index([insertedAt]) @@index([blockHash]) - @@index([blockNumber]) @@index([blockNumber, index]) - @@index([blockTimestamp]) - @@index([category]) + @@index([blockTimestamp, category, rollup, blockNumber, index]) + @@index([category, rollup, blockNumber, index]) + @@index([fromId, blockNumber, index]) + @@index([toId, blockNumber, index]) @@map("transaction") }