-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Indexes to candles and orders to optimize queries #1060
Conversation
WalkthroughThis update introduces new indexing capabilities to the PostgreSQL database, enhancing query performance for specific tables. By adding indexes on the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- indexer/packages/postgres/src/db/migrations/migration_files/20240208153050_add_candles_ticket_resolution_index.ts (1 hunks)
- indexer/packages/postgres/src/db/migrations/migration_files/20240208161948_add_orders_clobpairid_subaccountid_index.ts (1 hunks)
Additional comments: 6
indexer/packages/postgres/src/db/migrations/migration_files/20240208153050_add_candles_ticket_resolution_index.ts (3)
- 6-6: Ensure the column names
ticker
andresolution
are correctly spelled and exist in thecandles
table schema.- 12-12: Confirm that the index name
candles_ticker_resolution_index
matches the one created in theup
function to ensure proper rollback.- 16-18: The configuration
transaction: false
is correctly set for operations that cannot run inside a transaction, such asCREATE INDEX CONCURRENTLY
.indexer/packages/postgres/src/db/migrations/migration_files/20240208161948_add_orders_clobpairid_subaccountid_index.ts (3)
- 6-6: Ensure the column names
clobPairId
andsubaccountId
are correctly spelled and exist in theorders
table schema.- 12-12: Confirm that the index name
orders_clobpairid_subaccountid_index
matches the one created in theup
function to ensure proper rollback.- 16-18: The configuration
transaction: false
is correctly set for operations that cannot run inside a transaction, such asCREATE INDEX CONCURRENTLY
.
export async function up(knex: Knex): Promise<void> { | ||
// eslint-disable-next-line @typescript-eslint/quotes | ||
await knex.raw(` | ||
CREATE INDEX CONCURRENTLY IF NOT EXISTS orders_clobpairid_subaccountid_index ON orders("clobPairId", "subaccountId"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we are inconsistent with our indices where in some we don't include id
(e.g. perpetual_positions_subaccount_perpetual_created_at_index
) and in others we use the exact same case and use quotes (e.g. fills_clobPairId_createdAtHeight_partial
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will go with camel case for consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- indexer/packages/postgres/src/db/migrations/migration_files/20240208161948_add_orders_clobpairid_subaccountid_index.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- indexer/packages/postgres/src/db/migrations/migration_files/20240208161948_add_orders_clobpairid_subaccountid_index.ts
Changelist
Add Indexes to candles and orders to optimize queries:
select "candles".* from "candles" where "ticker" in ($1) and "resolution" = $2 order by "ticker" DESC, "resolution" DESC, "startedAt" DESC limit $3
select distinct on ("perpetualId") "funding_index_updates".* from "funding_index_updates" where "effectiveAtHeight" <= $1 order by "perpetualId" asc, "effectiveAtHeight" DESC
Test Plan
Tested in database directly that this reduced latency
Author/Reviewer Checklist
state-breaking
label.indexer-postgres-breaking
label.PrepareProposal
orProcessProposal
, manually add the labelproposal-breaking
.feature:[feature-name]
.backport/[branch-name]
.refactor
,chore
,bug
.