From b78d9fd77c3cfb30239f32aadf0306ef09f073a1 Mon Sep 17 00:00:00 2001 From: Dusan Stanivukovic Date: Fri, 9 Feb 2024 09:41:18 +0100 Subject: [PATCH] Add index on auction id (#2386) # Description @fhenneke [reported](https://github.com/cowprotocol/solver-rewards/pull/337) that the batch rewards query takes forever once we removed the `auction_transaction` table. https://github.com/cowprotocol/solver-rewards/pull/334 This should be fixed by adding the index on `auction_id` on `settlements` table. ## How to test Execute batch rewards on staging db to verify the speed. --- database/README.md | 1 + database/sql/V062__settlements_auction_id_index.sql | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 database/sql/V062__settlements_auction_id_index.sql diff --git a/database/README.md b/database/README.md index d49518963a..5a9e2c336c 100644 --- a/database/README.md +++ b/database/README.md @@ -318,6 +318,7 @@ During the solver competition solvers promise a solution of a certain quality. I Indexes: - PRIMARY KEY: btree(`block_number`, `log_index`) +- settlements\_auction\_id: btree(`auction_id`) ### settlement\_scores diff --git a/database/sql/V062__settlements_auction_id_index.sql b/database/sql/V062__settlements_auction_id_index.sql new file mode 100644 index 0000000000..2fd41a1fec --- /dev/null +++ b/database/sql/V062__settlements_auction_id_index.sql @@ -0,0 +1,2 @@ +-- Optimization for when we JOIN settlements on auction_id. +CREATE INDEX settlements_auction_id ON settlements USING BTREE (auction_id);