-
-
Notifications
You must be signed in to change notification settings - Fork 273
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
perf(Postgres): Remove unused indexes #10590
base: main
Are you sure you want to change the base?
Conversation
'transactions__collective_id_createdAt', // Table: Transactions. Size: 351 MB | ||
'transactions__host_collective_id_createdAt', // Table: Transactions. Size: 246 MB | ||
'transactions__hostCollective_clearedAt', // Table: Transactions. Size: 127 MB | ||
'activities__from_collective_id', // Table: Activities. Size: 100 MB. Replaced by activities__from_collective_id_simple, which skips the transactions activities. | ||
'activities__host_collective_id', // Table: Activities. Size: 88 MB. Replaced by activities__host_collective_id_simple, which skips the transactions activities. | ||
'orders__req_ip', // Table: Orders. Size: 21 MB. The fraud detection uses redis, not the DB. | ||
'payment_methods__fingerprint', // Table: PaymentMethods. Size: 16 MB | ||
// 'UploadedFiles_s3_hash', // Table: UploadedFiles. Size: 16 MB. This one is unused because we've disabled Klippa, but we want to keep it in case we re-enable the feature. | ||
'transaction_wise_transfer_id', // Table: Transactions. Size: 8144 kB | ||
'expense_tag_stats_tag', // View: ExpenseTagStats. Size: 6864 kB. We're seemingly never fetching BY tag. | ||
// 'uploaded_files__created_by_user_id', // Table: UploadedFiles. Size: 5792 kB. For Klippa rate-limiting, keeping in case we re-enable an AI feature. | ||
'expenses_data_stripe_virtual_card_transaction_id', // Table: Expenses. Size: 1104 kB | ||
'expenses_data_paypal_transaction_id', // Table: Expenses. Size: 1048 kB | ||
'wise_batchgroup_status', // Table: Expenses. Size: 648 kB | ||
'privacy_transfer_id', // Table: Transactions. Size: 16 kB | ||
'Subscriptions_lastChargedAt', // Table: Subscriptions. Size: 16 kB | ||
'virtual_card_requests__host_collective_id__collective_id', // Table: VirtualCardRequests. Size: 16 kB |
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.
cc @znarf for the following indexes:
transactions__collective_id_createdAt
(Transaction indexes #9743)transactions__host_collective_id_createdAt
(Optimize transactions query for hosts with a new index #9742)transactions__hostCollective_clearedAt
(Implement Transaction.clearedAt #9829)
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.
That looks pretty dangerous to me, I think this has the potential to break production. transactions__collective_id_createdAt
and transactions__host_collective_id_createdAt
were carefully created for the generic GraphQL transactions resolver.
'transactions__collective_id_createdAt', // Table: Transactions. Size: 351 MB | ||
'transactions__host_collective_id_createdAt', // Table: Transactions. Size: 246 MB | ||
'transactions__hostCollective_clearedAt', // Table: Transactions. Size: 127 MB | ||
'activities__from_collective_id', // Table: Activities. Size: 100 MB. Replaced by activities__from_collective_id_simple, which skips the transactions activities. | ||
'activities__host_collective_id', // Table: Activities. Size: 88 MB. Replaced by activities__host_collective_id_simple, which skips the transactions activities. | ||
'orders__req_ip', // Table: Orders. Size: 21 MB. The fraud detection uses redis, not the DB. | ||
'payment_methods__fingerprint', // Table: PaymentMethods. Size: 16 MB | ||
// 'UploadedFiles_s3_hash', // Table: UploadedFiles. Size: 16 MB. This one is unused because we've disabled Klippa, but we want to keep it in case we re-enable the feature. | ||
'transaction_wise_transfer_id', // Table: Transactions. Size: 8144 kB | ||
'expense_tag_stats_tag', // View: ExpenseTagStats. Size: 6864 kB. We're seemingly never fetching BY tag. | ||
// 'uploaded_files__created_by_user_id', // Table: UploadedFiles. Size: 5792 kB. For Klippa rate-limiting, keeping in case we re-enable an AI feature. | ||
'expenses_data_stripe_virtual_card_transaction_id', // Table: Expenses. Size: 1104 kB | ||
'expenses_data_paypal_transaction_id', // Table: Expenses. Size: 1048 kB | ||
'wise_batchgroup_status', // Table: Expenses. Size: 648 kB | ||
'privacy_transfer_id', // Table: Transactions. Size: 16 kB | ||
'Subscriptions_lastChargedAt', // Table: Subscriptions. Size: 16 kB | ||
'virtual_card_requests__host_collective_id__collective_id', // Table: VirtualCardRequests. Size: 16 kB |
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.
cc @kewitz for the following indexes:
orders__req_ip
(Optimize security/order queries #8151)transaction_wise_transfer_id
wise_batchgroup_status
Subscriptions_lastChargedAt
payment_methods__fingerprint
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.
Everything seems safe to delete, but I'm surprised payment_methods__fingerprint is not being used. I'll investigate this further.
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.
Everything is safe to delete.
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.
We'll keep the fingerprint for now, see https://oficonsortium.slack.com/archives/C06K5J91675/p1735902404908739
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.
'transactions__collective_id_createdAt', // Table: Transactions. Size: 351 MB | ||
'transactions__host_collective_id_createdAt', // Table: Transactions. Size: 246 MB | ||
'transactions__hostCollective_clearedAt', // Table: Transactions. Size: 127 MB | ||
'activities__from_collective_id', // Table: Activities. Size: 100 MB. Replaced by activities__from_collective_id_simple, which skips the transactions activities. | ||
'activities__host_collective_id', // Table: Activities. Size: 88 MB. Replaced by activities__host_collective_id_simple, which skips the transactions activities. | ||
'orders__req_ip', // Table: Orders. Size: 21 MB. The fraud detection uses redis, not the DB. | ||
'payment_methods__fingerprint', // Table: PaymentMethods. Size: 16 MB | ||
// 'UploadedFiles_s3_hash', // Table: UploadedFiles. Size: 16 MB. This one is unused because we've disabled Klippa, but we want to keep it in case we re-enable the feature. | ||
'transaction_wise_transfer_id', // Table: Transactions. Size: 8144 kB | ||
'expense_tag_stats_tag', // View: ExpenseTagStats. Size: 6864 kB. We're seemingly never fetching BY tag. | ||
// 'uploaded_files__created_by_user_id', // Table: UploadedFiles. Size: 5792 kB. For Klippa rate-limiting, keeping in case we re-enable an AI feature. | ||
'expenses_data_stripe_virtual_card_transaction_id', // Table: Expenses. Size: 1104 kB | ||
'expenses_data_paypal_transaction_id', // Table: Expenses. Size: 1048 kB | ||
'wise_batchgroup_status', // Table: Expenses. Size: 648 kB | ||
'privacy_transfer_id', // Table: Transactions. Size: 16 kB | ||
'Subscriptions_lastChargedAt', // Table: Subscriptions. Size: 16 kB | ||
'virtual_card_requests__host_collective_id__collective_id', // Table: VirtualCardRequests. Size: 16 kB |
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.
cc @gustavlrsn for the following indexes:
expense_tag_stats_tag
d82e407
to
f4c5087
Compare
Moving this back to draft as:
|
7df3778
to
73f46c5
Compare
Considering that indexes add overhead to SQL write queries and can make the query planner slower, this migration drops indexes that are seemingly no longer used in the codebase. They were identified by running the following
query in the database:
Methodology:
SELECT stats_reset FROM pg_stat_database WHERE datname = current_database()
)