Details
diff --git a/beatrix/src/main/resources/org/killbill/billing/beatrix/ddl.sql b/beatrix/src/main/resources/org/killbill/billing/beatrix/ddl.sql
index 96f32e8..d5ccb71 100644
--- a/beatrix/src/main/resources/org/killbill/billing/beatrix/ddl.sql
+++ b/beatrix/src/main/resources/org/killbill/billing/beatrix/ddl.sql
@@ -37,3 +37,4 @@ CREATE TABLE bus_ext_events_history (
search_key2 bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
+CREATE INDEX bus_ext_events_history_tenant_account_record_id ON bus_ext_events_history(search_key2, search_key1);
diff --git a/util/src/main/resources/org/killbill/billing/util/ddl.sql b/util/src/main/resources/org/killbill/billing/util/ddl.sql
index 8e21ad6..552f8dd 100644
--- a/util/src/main/resources/org/killbill/billing/util/ddl.sql
+++ b/util/src/main/resources/org/killbill/billing/util/ddl.sql
@@ -193,6 +193,7 @@ CREATE TABLE notifications_history (
future_user_token varchar(36),
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
+CREATE INDEX notifications_history_tenant_account_record_id ON notifications_history(search_key2, search_key1);
DROP TABLE IF EXISTS bus_events;
CREATE TABLE bus_events (
@@ -231,6 +232,7 @@ CREATE TABLE bus_events_history (
search_key2 bigint /*! unsigned */ not null default 0,
PRIMARY KEY(record_id)
) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
+CREATE INDEX bus_events_history_tenant_account_record_id ON bus_events_history(search_key2, search_key1);
drop table if exists sessions;
create table sessions (
diff --git a/util/src/main/resources/org/killbill/billing/util/migration/V20170209083747__queues_history_indexes.sql b/util/src/main/resources/org/killbill/billing/util/migration/V20170209083747__queues_history_indexes.sql
new file mode 100644
index 0000000..f873b01
--- /dev/null
+++ b/util/src/main/resources/org/killbill/billing/util/migration/V20170209083747__queues_history_indexes.sql
@@ -0,0 +1,3 @@
+alter table notifications_history add index notifications_history_tenant_account_record_id(search_key2, search_key1);
+alter table bus_events_history add index bus_events_history_tenant_account_record_id(search_key2, search_key1);
+alter table bus_ext_events_history add index bus_ext_events_history_tenant_account_record_id(search_key2, search_key1);