From 450ce8b60d65ad302f279c7ce7ea6fdcc31525bb Mon Sep 17 00:00:00 2001 From: Christopher-Li Date: Fri, 9 Feb 2024 13:49:18 -0500 Subject: [PATCH] Add Indexes to candles and orders to optimize queries (#1060) * Add Indexes to candles and orders to optimize queries * update naming --- ...3050_add_candles_ticket_resolution_index.ts | 18 ++++++++++++++++++ ...add_orders_clobpairid_subaccountid_index.ts | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 indexer/packages/postgres/src/db/migrations/migration_files/20240208153050_add_candles_ticket_resolution_index.ts create mode 100644 indexer/packages/postgres/src/db/migrations/migration_files/20240208161948_add_orders_clobpairid_subaccountid_index.ts diff --git a/indexer/packages/postgres/src/db/migrations/migration_files/20240208153050_add_candles_ticket_resolution_index.ts b/indexer/packages/postgres/src/db/migrations/migration_files/20240208153050_add_candles_ticket_resolution_index.ts new file mode 100644 index 0000000000..9a3cc7463a --- /dev/null +++ b/indexer/packages/postgres/src/db/migrations/migration_files/20240208153050_add_candles_ticket_resolution_index.ts @@ -0,0 +1,18 @@ +import * as Knex from 'knex'; + +export async function up(knex: Knex): Promise { + // eslint-disable-next-line @typescript-eslint/quotes + await knex.raw(` + CREATE INDEX CONCURRENTLY IF NOT EXISTS candles_ticker_resolution_index ON candles("ticker", "resolution"); + `); +} + +export async function down(knex: Knex): Promise { + await knex.raw(` + DROP INDEX CONCURRENTLY IF EXISTS "candles_ticker_resolution_index"; + `); +} + +export const config = { + transaction: false, +}; diff --git a/indexer/packages/postgres/src/db/migrations/migration_files/20240208161948_add_orders_clobpairid_subaccountid_index.ts b/indexer/packages/postgres/src/db/migrations/migration_files/20240208161948_add_orders_clobpairid_subaccountid_index.ts new file mode 100644 index 0000000000..8e4f394ba5 --- /dev/null +++ b/indexer/packages/postgres/src/db/migrations/migration_files/20240208161948_add_orders_clobpairid_subaccountid_index.ts @@ -0,0 +1,18 @@ +import * as Knex from 'knex'; + +export async function up(knex: Knex): Promise { + // eslint-disable-next-line @typescript-eslint/quotes + await knex.raw(` + CREATE INDEX CONCURRENTLY IF NOT EXISTS orders_clobPairId_subaccountId_index ON orders("clobPairId", "subaccountId"); + `); +} + +export async function down(knex: Knex): Promise { + await knex.raw(` + DROP INDEX CONCURRENTLY IF EXISTS "orders_clobPairId_subaccountId_index"; + `); +} + +export const config = { + transaction: false, +};