From 41de83e1c729b80f32155a99d064f29ca390c803 Mon Sep 17 00:00:00 2001 From: dydxwill <119354122+dydxwill@users.noreply.github.com> Date: Mon, 4 Mar 2024 12:22:16 -0500 Subject: [PATCH] add index to address read replica lag (#1137) Signed-off-by: Eric --- ...r_id_created_at_height_created_at_index.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 indexer/packages/postgres/src/db/migrations/migration_files/20240304115004_create_fills_clob_pair_id_created_at_height_created_at_index.ts diff --git a/indexer/packages/postgres/src/db/migrations/migration_files/20240304115004_create_fills_clob_pair_id_created_at_height_created_at_index.ts b/indexer/packages/postgres/src/db/migrations/migration_files/20240304115004_create_fills_clob_pair_id_created_at_height_created_at_index.ts new file mode 100644 index 0000000000..b90bffb90d --- /dev/null +++ b/indexer/packages/postgres/src/db/migrations/migration_files/20240304115004_create_fills_clob_pair_id_created_at_height_created_at_index.ts @@ -0,0 +1,21 @@ +import * as Knex from 'knex'; + +export async function up(knex: Knex): Promise { + // Partial index only when `liquidity` is 'TAKER' as this index is meant to speed up the query to + // fetch all trades from the database, and we arbitrarily only use 'TAKER' fills for trades to + // avoid double counting. + // eslint-disable-next-line @typescript-eslint/quotes + await knex.raw(` + CREATE INDEX CONCURRENTLY IF NOT EXISTS "fills_clobPairId_createdAtHeight_createdAt_partial" ON "fills" ("clobPairId", "createdAtHeight", "createdAt") WHERE "liquidity" = 'TAKER'; + `); +} + +export async function down(knex: Knex): Promise { + await knex.raw(` + DROP INDEX CONCURRENTLY IF EXISTS "fills_clobPairId_createdAtHeight_createdAt_partial"; + `); +} + +export const config = { + transaction: false, +};