From f3ce3ed8a65160d0cb847b8fcffc7ca8649af0c7 Mon Sep 17 00:00:00 2001 From: MartinquaXD Date: Fri, 2 Jan 2026 14:40:03 +0000 Subject: [PATCH 1/4] Add index for cancellation timestamp --- database/sql/V095__update_order_timestamp_indexes.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 database/sql/V095__update_order_timestamp_indexes.sql diff --git a/database/sql/V095__update_order_timestamp_indexes.sql b/database/sql/V095__update_order_timestamp_indexes.sql new file mode 100644 index 0000000000..f8043e78dd --- /dev/null +++ b/database/sql/V095__update_order_timestamp_indexes.sql @@ -0,0 +1,10 @@ +-- drop index over (creation_timestamp, cancellation timestamp) +-- since it can only be used optimally for queries on the creation_timestamp. +IF EXISTS DROP INDEX order_creation_cancellation; + +-- create a separate index for cancellation_timestamp to improve queries +-- filtering based on the cancellation_timestamp +CREATE INDEX order_cancellation_timestamp ON orders USING BTREE(cancellation_timestamp); + +-- no extra index with only the creation_timestamp needs to be created +-- since that already exists. From c88a9ab133fdda794b76a9e887955f04b6110c07 Mon Sep 17 00:00:00 2001 From: MartinquaXD Date: Fri, 2 Jan 2026 14:42:12 +0000 Subject: [PATCH 2/4] switch order of operations --- .../sql/V095__update_order_timestamp_indexes.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/database/sql/V095__update_order_timestamp_indexes.sql b/database/sql/V095__update_order_timestamp_indexes.sql index f8043e78dd..387536b67e 100644 --- a/database/sql/V095__update_order_timestamp_indexes.sql +++ b/database/sql/V095__update_order_timestamp_indexes.sql @@ -1,10 +1,10 @@ --- drop index over (creation_timestamp, cancellation timestamp) --- since it can only be used optimally for queries on the creation_timestamp. -IF EXISTS DROP INDEX order_creation_cancellation; - -- create a separate index for cancellation_timestamp to improve queries -- filtering based on the cancellation_timestamp -CREATE INDEX order_cancellation_timestamp ON orders USING BTREE(cancellation_timestamp); - -- no extra index with only the creation_timestamp needs to be created -- since that already exists. +CREATE INDEX CONCURRENTLY order_cancellation_timestamp ON orders USING BTREE(cancellation_timestamp); + +-- drop index over (creation_timestamp, cancellation timestamp) +-- since it can only be used optimally for queries on the creation_timestamp. +IF EXISTS DROP INDEX order_creation_cancellation; + From d6341f10b8fb67f86a3af19ff25e8c282ece1533 Mon Sep 17 00:00:00 2001 From: MartinquaXD Date: Fri, 2 Jan 2026 14:48:32 +0000 Subject: [PATCH 3/4] document indexes on orders table --- database/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/database/README.md b/database/README.md index d62b9bda99..734002c82a 100644 --- a/database/README.md +++ b/database/README.md @@ -265,6 +265,13 @@ Column | Type | Nullable | Details Indexes: - PRIMARY KEY: btree(`uid`) +- order_cancellation_timestamp: btree(`cancellation_timestamp`) +- order_creation_timestamp: btree(`creation_timestamp`) +- order_owner: hash(`owner`) +- order_quoting_parameters: btree(`sell_token`, `buy_token`, `sell_amount`) +- order_sell_buy_tokens: btree(`sell_token`, `buy_token`) +- user_order_creation_timestamp: btree(`owner`, `creation_timestamp`) +- version_idx: btree(`settlement_contract`) ### fee_policies From 777675dc3deecfb4aabb0a3b6e4d7ecbaca99ba7 Mon Sep 17 00:00:00 2001 From: MartinquaXD Date: Fri, 2 Jan 2026 15:12:54 +0000 Subject: [PATCH 4/4] fix errors --- database/sql/V095__update_order_timestamp_indexes.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/sql/V095__update_order_timestamp_indexes.sql b/database/sql/V095__update_order_timestamp_indexes.sql index 387536b67e..93bb687a4c 100644 --- a/database/sql/V095__update_order_timestamp_indexes.sql +++ b/database/sql/V095__update_order_timestamp_indexes.sql @@ -2,9 +2,9 @@ -- filtering based on the cancellation_timestamp -- no extra index with only the creation_timestamp needs to be created -- since that already exists. -CREATE INDEX CONCURRENTLY order_cancellation_timestamp ON orders USING BTREE(cancellation_timestamp); +CREATE INDEX order_cancellation_timestamp ON orders USING BTREE(cancellation_timestamp); -- drop index over (creation_timestamp, cancellation timestamp) -- since it can only be used optimally for queries on the creation_timestamp. -IF EXISTS DROP INDEX order_creation_cancellation; +DROP INDEX IF EXISTS order_creation_cancellation;