Skip to content

Commit

Permalink
[CT-423] Add missing index (#1039) (#1041)
Browse files Browse the repository at this point in the history
* [CT-423] Add missing index

Fetching SELECT * FROM perpetual_positions WHERE "subaccountId" = subaccount_uuid AND "perpetualId" = perpetual_id ORDER BY "openEventId" DESC LIMIT 1 was very slow on mainnet.
  • Loading branch information
lcwik authored Feb 2, 2024
1 parent 82627db commit 4dd753e
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as Knex from 'knex';

export async function up(knex: Knex): Promise<void> {
// eslint-disable-next-line @typescript-eslint/quotes
await knex.raw(`
CREATE INDEX CONCURRENTLY IF NOT EXISTS "perpetual_positions_subaccountId_perpetualId_openEventId_index" ON "perpetual_positions" ("subaccountId", "perpetualId", "openEventId" DESC);
`);
}

export async function down(knex: Knex): Promise<void> {
await knex.raw(`
DROP INDEX CONCURRENTLY IF EXISTS "perpetual_positions_subaccountId_perpetualId_openEventId_index";
`);
}

export const config = {
transaction: false,
};

0 comments on commit 4dd753e

Please sign in to comment.