forked from dydxprotocol/v4-chain
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add index to address read replica lag (dydxprotocol#1137)
- Loading branch information
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...tion_files/20240304115004_create_fills_clob_pair_id_created_at_height_created_at_index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as Knex from 'knex'; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
// 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<void> { | ||
await knex.raw(` | ||
DROP INDEX CONCURRENTLY IF EXISTS "fills_clobPairId_createdAtHeight_createdAt_partial"; | ||
`); | ||
} | ||
|
||
export const config = { | ||
transaction: false, | ||
}; |