From 8b81028b5fc8d4446c33ba0517c40d1e9b9ecc2b Mon Sep 17 00:00:00 2001 From: jeff <113397187+cyberhorsey@users.noreply.github.com> Date: Thu, 11 Jan 2024 17:46:25 -0800 Subject: [PATCH] fix(eventindexer): add indexes for struggling queries (#15483) --- packages/eventindexer/.l2.env | 5 +++-- packages/eventindexer/generator/generator.go | 8 ++++---- ...08839_alter_transactions_table_add_indexes.sql | 11 +++++++++++ ...60906208839_alter_events_table_add_indexes.sql | 15 +++++++++++++++ ...906208839_alter_accounts_table_add_indexes.sql | 9 +++++++++ ...80906208839_alter_blocks_table_add_indexes.sql | 9 +++++++++ 6 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 packages/eventindexer/migrations/20250906208839_alter_transactions_table_add_indexes.sql create mode 100644 packages/eventindexer/migrations/20260906208839_alter_events_table_add_indexes.sql create mode 100644 packages/eventindexer/migrations/20270906208839_alter_accounts_table_add_indexes.sql create mode 100644 packages/eventindexer/migrations/20280906208839_alter_blocks_table_add_indexes.sql diff --git a/packages/eventindexer/.l2.env b/packages/eventindexer/.l2.env index 7950ff835cd..77bb8409fff 100644 --- a/packages/eventindexer/.l2.env +++ b/packages/eventindexer/.l2.env @@ -7,8 +7,9 @@ DATABASE_HOST=localhost:3306 DATABASE_MAX_IDLE_CONNS=50 DATABASE_MAX_OPEN_CONNS=3000 DATABASE_CONN_MAX_LIFETIME_IN_MS=100000 -RPC_URL=wss://ws.internal.taiko.xyz +RPC_URL=wss://ws.katla.taiko.xyz CORS_ORIGINS=* -BLOCK_BATCH_SIZE=100 +BLOCK_BATCH_SIZE=50 CACHE_INTERVAL_IN_SECONDS=60 LAYER=l2 +INDEX_NFTS=true diff --git a/packages/eventindexer/generator/generator.go b/packages/eventindexer/generator/generator.go index d5519b6bcf0..822aca79091 100644 --- a/packages/eventindexer/generator/generator.go +++ b/packages/eventindexer/generator/generator.go @@ -196,7 +196,7 @@ func (g *Generator) queryByTask(task string, date time.Time) error { case tasks.TotalTransitionProvedByTier: var tiers []uint16 = make([]uint16, 0) - query := "SELECT DISTINCT tier FROM events WHERE name = ? AND tier IS NOT NULL;" + query := "SELECT DISTINCT tier FROM events WHERE event = ? AND tier IS NOT NULL;" err = g.db.GormDB(). Raw(query, eventindexer.EventNameTransitionProved). @@ -252,7 +252,7 @@ func (g *Generator) queryByTask(task string, date time.Time) error { case tasks.TransitionProvedByTierPerDay: var tiers []uint16 = make([]uint16, 0) - query := "SELECT DISTINCT tier FROM events WHERE name = ? AND tier IS NOT NULL;" + query := "SELECT DISTINCT tier FROM events WHERE event = ? AND tier IS NOT NULL;" err = g.db.GormDB(). Raw(query, eventindexer.EventNameTransitionProved). @@ -301,7 +301,7 @@ func (g *Generator) queryByTask(task string, date time.Time) error { case tasks.TransitionContestedByTierPerDay: var tiers []uint16 = make([]uint16, 0) - query := "SELECT DISTINCT tier FROM events WHERE name = ? AND tier IS NOT NULL;" + query := "SELECT DISTINCT tier FROM events WHERE event = ? AND tier IS NOT NULL;" err = g.db.GormDB(). Raw(query, eventindexer.EventNameTransitionContested). @@ -350,7 +350,7 @@ func (g *Generator) queryByTask(task string, date time.Time) error { case tasks.TotalTransitionContestedByTier: var tiers []uint16 = make([]uint16, 0) - query := "SELECT DISTINCT tier FROM events WHERE name = ? AND tier IS NOT NULL;" + query := "SELECT DISTINCT tier FROM events WHERE event = ? AND tier IS NOT NULL;" err = g.db.GormDB(). Raw(query, eventindexer.EventNameTransitionContested). diff --git a/packages/eventindexer/migrations/20250906208839_alter_transactions_table_add_indexes.sql b/packages/eventindexer/migrations/20250906208839_alter_transactions_table_add_indexes.sql new file mode 100644 index 00000000000..ed2c0fe0733 --- /dev/null +++ b/packages/eventindexer/migrations/20250906208839_alter_transactions_table_add_indexes.sql @@ -0,0 +1,11 @@ +-- +goose Up +-- +goose StatementBegin +ALTER TABLE `transactions` ADD INDEX transacted_at_index(`transacted_at`), +ADD INDEX transacted_at_contract_address_index(`transacted_at`, `contract_address`); + +-- +goose StatementEnd +-- +goose Down +-- +goose StatementBegin +DROP INDEX transacted_at_index on transactions; +DROP INDEX transacted_at_contract_address_index on transactions; +-- +goose StatementEnd diff --git a/packages/eventindexer/migrations/20260906208839_alter_events_table_add_indexes.sql b/packages/eventindexer/migrations/20260906208839_alter_events_table_add_indexes.sql new file mode 100644 index 00000000000..3333fe638cf --- /dev/null +++ b/packages/eventindexer/migrations/20260906208839_alter_events_table_add_indexes.sql @@ -0,0 +1,15 @@ +-- +goose Up +-- +goose StatementBegin +ALTER TABLE `events` ADD INDEX `event_transacted_at_tier_index` (`transacted_at`, `event`, `tier`), +ADD INDEX `event_transacted_at_index` (`transacted_at`, `event`), +ADD INDEX `event_block_id_index` (`event`, `block_id`), +ADD INDEX `event_tier_index` (`event`, `tier`); + +-- +goose StatementEnd +-- +goose Down +-- +goose StatementBegin +DROP INDEX event_transacted_at_tier_index on events, +event_transacted_at_index on events, +event_block_id_index on events, +event_tier_index on events; +-- +goose StatementEnd diff --git a/packages/eventindexer/migrations/20270906208839_alter_accounts_table_add_indexes.sql b/packages/eventindexer/migrations/20270906208839_alter_accounts_table_add_indexes.sql new file mode 100644 index 00000000000..a0bd1d2c652 --- /dev/null +++ b/packages/eventindexer/migrations/20270906208839_alter_accounts_table_add_indexes.sql @@ -0,0 +1,9 @@ +-- +goose Up +-- +goose StatementBegin +ALTER TABLE `accounts` ADD INDEX `transacted_at_index` (`transacted_at`); + +-- +goose StatementEnd +-- +goose Down +-- +goose StatementBegin +DROP INDEX transacted_at_index on accounts; +-- +goose StatementEnd diff --git a/packages/eventindexer/migrations/20280906208839_alter_blocks_table_add_indexes.sql b/packages/eventindexer/migrations/20280906208839_alter_blocks_table_add_indexes.sql new file mode 100644 index 00000000000..6a00b34f461 --- /dev/null +++ b/packages/eventindexer/migrations/20280906208839_alter_blocks_table_add_indexes.sql @@ -0,0 +1,9 @@ +-- +goose Up +-- +goose StatementBegin +ALTER TABLE `blocks` ADD INDEX `transacted_at_index` (`transacted_at`); + +-- +goose StatementEnd +-- +goose Down +-- +goose StatementBegin +DROP INDEX transacted_at_index on blocks; +-- +goose StatementEnd