From f0597eb8015ccc5a3cdf14f78d3a86f90750cf57 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:48:51 +0000 Subject: [PATCH 1/2] Index trade_executed_view.order_book_id for GET /query/executed-trades/{orderBookId} Co-Authored-By: taylor.curran --- .../trader/app/query/orders/transaction/TradeExecutedView.java | 3 +++ .../migration/V2__index_trade_executed_view_order_book_id.sql | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 trader-app/src/main/resources/db/migration/V2__index_trade_executed_view_order_book_id.sql diff --git a/trader-app/src/main/java/io/pivotal/refarch/cqrs/trader/app/query/orders/transaction/TradeExecutedView.java b/trader-app/src/main/java/io/pivotal/refarch/cqrs/trader/app/query/orders/transaction/TradeExecutedView.java index ae8f1599..6564ed91 100644 --- a/trader-app/src/main/java/io/pivotal/refarch/cqrs/trader/app/query/orders/transaction/TradeExecutedView.java +++ b/trader-app/src/main/java/io/pivotal/refarch/cqrs/trader/app/query/orders/transaction/TradeExecutedView.java @@ -18,8 +18,11 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; +import javax.persistence.Index; +import javax.persistence.Table; @Entity +@Table(indexes = @Index(name = "idx_trade_executed_view_order_book_id", columnList = "orderBookId")) public class TradeExecutedView { @javax.persistence.Id diff --git a/trader-app/src/main/resources/db/migration/V2__index_trade_executed_view_order_book_id.sql b/trader-app/src/main/resources/db/migration/V2__index_trade_executed_view_order_book_id.sql new file mode 100644 index 00000000..5a8ea620 --- /dev/null +++ b/trader-app/src/main/resources/db/migration/V2__index_trade_executed_view_order_book_id.sql @@ -0,0 +1,3 @@ +-- GET /query/executed-trades/{orderBookId} filters trade_executed_view by order_book_id, which had no index, so every +-- call scanned the whole append-only table. Same index as @Table(indexes) on TradeExecutedView (local ddl-auto=update). +CREATE INDEX `idx_trade_executed_view_order_book_id` ON `trade_executed_view` (`order_book_id`); From db9a55333acae8555c2ff7f15846accd18ea5976 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:53:35 +0000 Subject: [PATCH 2/2] Make V2 index migration skip an index Hibernate already created Co-Authored-By: taylor.curran --- .../V2__index_trade_executed_view_order_book_id.sql | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/trader-app/src/main/resources/db/migration/V2__index_trade_executed_view_order_book_id.sql b/trader-app/src/main/resources/db/migration/V2__index_trade_executed_view_order_book_id.sql index 5a8ea620..09508eeb 100644 --- a/trader-app/src/main/resources/db/migration/V2__index_trade_executed_view_order_book_id.sql +++ b/trader-app/src/main/resources/db/migration/V2__index_trade_executed_view_order_book_id.sql @@ -1,3 +1,13 @@ -- GET /query/executed-trades/{orderBookId} filters trade_executed_view by order_book_id, which had no index, so every -- call scanned the whole append-only table. Same index as @Table(indexes) on TradeExecutedView (local ddl-auto=update). -CREATE INDEX `idx_trade_executed_view_order_book_id` ON `trade_executed_view` (`order_book_id`); +-- Conditional because a database Hibernate already updated (local profile) and then baselined at V1 already has it; +-- MySQL 5.7 has no CREATE INDEX IF NOT EXISTS. +SET @idx_exists := (SELECT COUNT(*) FROM information_schema.statistics + WHERE table_schema = DATABASE() AND table_name = 'trade_executed_view' + AND index_name = 'idx_trade_executed_view_order_book_id'); +SET @ddl := IF(@idx_exists = 0, + 'CREATE INDEX `idx_trade_executed_view_order_book_id` ON `trade_executed_view` (`order_book_id`)', + 'DO 0'); +PREPARE stmt FROM @ddl; +EXECUTE stmt; +DEALLOCATE PREPARE stmt;