Details
diff --git a/account/src/main/resources/com/ning/billing/account/ddl.sql b/account/src/main/resources/com/ning/billing/account/ddl.sql
index fe9ec44..47f2138 100644
--- a/account/src/main/resources/com/ning/billing/account/ddl.sql
+++ b/account/src/main/resources/com/ning/billing/account/ddl.sql
@@ -31,6 +31,7 @@ CREATE TABLE accounts (
) ENGINE=innodb;
CREATE UNIQUE INDEX accounts_id ON accounts(id);
CREATE UNIQUE INDEX accounts_external_key ON accounts(external_key);
+CREATE INDEX accounts_tenant_record_id ON accounts(tenant_record_id);
DROP TABLE IF EXISTS account_history;
CREATE TABLE account_history (
@@ -64,6 +65,7 @@ CREATE TABLE account_history (
PRIMARY KEY(history_record_id)
) ENGINE=innodb;
CREATE INDEX account_history_record_id ON account_history(record_id);
+CREATE INDEX account_history_tenant_record_id ON account_history(tenant_record_id);
DROP TABLE IF EXISTS account_emails;
CREATE TABLE account_emails (
@@ -81,6 +83,7 @@ CREATE TABLE account_emails (
) ENGINE=innodb;
CREATE UNIQUE INDEX account_email_id ON account_emails(id);
CREATE UNIQUE INDEX account_email_account_id_email ON account_emails(account_id, email);
+CREATE INDEX account_emails_tenant_account_record_id ON account_emails(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS account_email_history;
CREATE TABLE account_email_history (
@@ -97,3 +100,4 @@ CREATE TABLE account_email_history (
PRIMARY KEY(history_record_id)
) ENGINE=innodb;
CREATE INDEX account_email_record_id ON account_email_history(record_id);
+CREATE INDEX account_email_history_tenant_account_record_id ON account_email_history(tenant_record_id, account_record_id);
diff --git a/analytics/src/main/resources/com/ning/billing/analytics/ddl.sql b/analytics/src/main/resources/com/ning/billing/analytics/ddl.sql
index fa6bfab..b223a80 100644
--- a/analytics/src/main/resources/com/ning/billing/analytics/ddl.sql
+++ b/analytics/src/main/resources/com/ning/billing/analytics/ddl.sql
@@ -38,6 +38,7 @@ create table bst (
, primary key(record_id)
) engine=innodb comment 'Business Subscription Transitions, track bundles lifecycle';
create index bst_key_index on bst (external_key, requested_timestamp asc);
+create index bst_tenant_account_record_id on bst(tenant_record_id, account_record_id);
drop table if exists bac;
create table bac (
@@ -60,6 +61,7 @@ create table bac (
, primary key(record_id)
) engine=innodb comment 'Business ACcounts, keep a record of all accounts';
create unique index bac_key_index on bac (account_key);
+create index bac_tenant_account_record_id on bac(tenant_record_id, account_record_id);
drop table if exists bin;
create table bin (
@@ -82,6 +84,7 @@ create table bin (
, primary key(record_id)
) engine=innodb comment 'Business INvoices, keep a record of generated invoices';
create unique index bin_key_index on bin (invoice_id);
+create index bin_tenant_account_record_id on bin(tenant_record_id, account_record_id);
drop table if exists bii;
create table bii (
@@ -108,6 +111,7 @@ create table bii (
, primary key(record_id)
) engine=innodb comment 'Business Invoice Items, keep a record of all invoice items';
create unique index bii_key_index on bii (item_id);
+create index bii_tenant_account_record_id on bii(tenant_record_id, account_record_id);
drop table if exists bip;
create table bip (
@@ -137,6 +141,7 @@ create table bip (
, primary key(record_id)
) engine=innodb comment 'Business Invoice Payments, track all payments';
create unique index bip_key_index on bip (payment_id);
+create index bip_tenant_account_record_id on bip(tenant_record_id, account_record_id);
drop table if exists bos;
create table bos (
@@ -151,6 +156,7 @@ create table bos (
, tenant_record_id int(11) unsigned default null
, primary key(record_id)
) engine=innodb comment 'Business Overdue Status, historical bundles overdue status';
+create index bos_tenant_account_record_id on bos(tenant_record_id, account_record_id);
drop table if exists bac_tags;
create table bac_tags (
@@ -162,6 +168,7 @@ create table bac_tags (
, tenant_record_id int(11) unsigned default null
, primary key(record_id)
) engine=innodb comment 'Tags associated to accounts';
+create index bac_tags_tenant_account_record_id on bac_tags(tenant_record_id, account_record_id);
drop table if exists bac_fields;
create table bac_fields (
@@ -174,6 +181,7 @@ create table bac_fields (
, tenant_record_id int(11) unsigned default null
, primary key(record_id)
) engine=innodb comment 'Custom fields associated to accounts';
+create index bac_fields_tenant_account_record_id on bac_fields(tenant_record_id, account_record_id);
drop table if exists bst_tags;
create table bst_tags (
@@ -186,6 +194,7 @@ create table bst_tags (
, tenant_record_id int(11) unsigned default null
, primary key(record_id)
) engine=innodb comment 'Tags associated to bundles';
+create index bst_tags_tenant_account_record_id on bst_tags(tenant_record_id, account_record_id);
drop table if exists bst_fields;
create table bst_fields (
@@ -199,6 +208,7 @@ create table bst_fields (
, tenant_record_id int(11) unsigned default null
, primary key(record_id)
) engine=innodb comment 'Custom fields associated to bundles';
+create index bst_fields_tenant_account_record_id on bst_fields(tenant_record_id, account_record_id);
drop table if exists bin_tags;
create table bin_tags (
@@ -209,6 +219,7 @@ create table bin_tags (
, tenant_record_id int(11) unsigned default null
, primary key(record_id)
) engine=innodb comment 'Tags associated to invoices';
+create index bin_tags_tenant_account_record_id on bin_tags(tenant_record_id, account_record_id);
drop table if exists bin_fields;
create table bin_fields (
@@ -220,6 +231,7 @@ create table bin_fields (
, tenant_record_id int(11) unsigned default null
, primary key(record_id)
) engine=innodb comment 'Custom fields associated to invoices';
+create index bin_fields_tenant_account_record_id on bin_fields(tenant_record_id, account_record_id);
drop table if exists bip_tags;
create table bip_tags (
@@ -230,6 +242,7 @@ create table bip_tags (
, tenant_record_id int(11) unsigned default null
, primary key(record_id)
) engine=innodb comment 'Tags associated to payments';
+create index bip_tags_tenant_account_record_id on bip_tags(tenant_record_id, account_record_id);
drop table if exists bip_fields;
create table bip_fields (
@@ -241,3 +254,4 @@ create table bip_fields (
, tenant_record_id int(11) unsigned default null
, primary key(record_id)
) engine=innodb comment 'Custom fields associated to payments';
+create index bip_fields_tenant_account_record_id on bip_fields(tenant_record_id, account_record_id);
diff --git a/entitlement/src/main/resources/com/ning/billing/entitlement/ddl.sql b/entitlement/src/main/resources/com/ning/billing/entitlement/ddl.sql
index 2b604e7..ee822a9 100644
--- a/entitlement/src/main/resources/com/ning/billing/entitlement/ddl.sql
+++ b/entitlement/src/main/resources/com/ning/billing/entitlement/ddl.sql
@@ -26,8 +26,7 @@ CREATE TABLE subscription_events (
CREATE UNIQUE INDEX subscription_events_id ON subscription_events(id);
CREATE INDEX idx_ent_1 ON subscription_events(subscription_id, is_active, effective_date);
CREATE INDEX idx_ent_2 ON subscription_events(subscription_id, effective_date, created_date, requested_date,id);
-
-
+CREATE INDEX subscription_events_tenant_account_record_id ON subscription_events(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS subscriptions;
CREATE TABLE subscriptions (
@@ -50,6 +49,7 @@ CREATE TABLE subscriptions (
) ENGINE=innodb;
CREATE UNIQUE INDEX subscriptions_id ON subscriptions(id);
CREATE INDEX subscriptions_bundle_id ON subscriptions(bundle_id);
+CREATE INDEX subscriptions_tenant_account_record_id ON subscriptions(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS bundles;
CREATE TABLE bundles (
@@ -65,4 +65,5 @@ CREATE TABLE bundles (
CREATE UNIQUE INDEX bundles_id ON bundles(id);
CREATE INDEX bundles_key ON bundles(external_key);
CREATE INDEX bundles_account ON bundles(account_id);
+CREATE INDEX bundles_tenant_account_record_id ON bundles(tenant_record_id, account_record_id);
diff --git a/invoice/src/main/resources/com/ning/billing/invoice/ddl.sql b/invoice/src/main/resources/com/ning/billing/invoice/ddl.sql
index 5a6c063..2052006 100644
--- a/invoice/src/main/resources/com/ning/billing/invoice/ddl.sql
+++ b/invoice/src/main/resources/com/ning/billing/invoice/ddl.sql
@@ -1,4 +1,3 @@
-
DROP TABLE IF EXISTS invoice_items;
CREATE TABLE invoice_items (
record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
@@ -22,11 +21,11 @@ CREATE TABLE invoice_items (
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
) ENGINE=innodb;
-
CREATE UNIQUE INDEX invoice_items_id ON invoice_items(id);
CREATE INDEX invoice_items_subscription_id ON invoice_items(subscription_id ASC);
CREATE INDEX invoice_items_invoice_id ON invoice_items(invoice_id ASC);
CREATE INDEX invoice_items_account_id ON invoice_items(account_id ASC);
+CREATE INDEX invoice_items_tenant_account_record_id ON invoice_items(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS invoices;
CREATE TABLE invoices (
@@ -45,6 +44,7 @@ CREATE TABLE invoices (
) ENGINE=innodb;
CREATE UNIQUE INDEX invoices_id ON invoices(id);
CREATE INDEX invoices_account_target ON invoices(account_id ASC, target_date);
+CREATE INDEX invoices_tenant_account_record_id ON invoices(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS invoice_payments;
CREATE TABLE invoice_payments (
@@ -67,3 +67,4 @@ CREATE TABLE invoice_payments (
CREATE UNIQUE INDEX invoice_payments_id ON invoice_payments(id);
CREATE INDEX invoice_payments ON invoice_payments(payment_id);
CREATE INDEX invoice_payments_reversals ON invoice_payments(linked_invoice_payment_id);
+CREATE INDEX invoice_payments_tenant_account_record_id ON invoice_payments(tenant_record_id, account_record_id);
diff --git a/junction/src/main/resources/com/ning/billing/junction/ddl.sql b/junction/src/main/resources/com/ning/billing/junction/ddl.sql
index d7c595b..90b8158 100644
--- a/junction/src/main/resources/com/ning/billing/junction/ddl.sql
+++ b/junction/src/main/resources/com/ning/billing/junction/ddl.sql
@@ -1,4 +1,3 @@
-
DROP TABLE IF EXISTS blocking_states;
CREATE TABLE blocking_states (
record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
@@ -14,4 +13,5 @@ CREATE TABLE blocking_states (
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
) ENGINE=innodb;
-CREATE INDEX blocking_states_id ON blocking_states(id);
\ No newline at end of file
+CREATE INDEX blocking_states_id ON blocking_states(id);
+CREATE INDEX blocking_states_tenant_account_record_id ON blocking_states(tenant_record_id, account_record_id);
diff --git a/payment/src/main/resources/com/ning/billing/payment/ddl.sql b/payment/src/main/resources/com/ning/billing/payment/ddl.sql
index c63b519..dc71838 100644
--- a/payment/src/main/resources/com/ning/billing/payment/ddl.sql
+++ b/payment/src/main/resources/com/ning/billing/payment/ddl.sql
@@ -1,6 +1,4 @@
-
-
-DROP TABLE IF EXISTS payments;
+DROP TABLE IF EXISTS payments;
CREATE TABLE payments (
record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
id char(36) NOT NULL,
@@ -24,6 +22,7 @@ CREATE TABLE payments (
CREATE UNIQUE INDEX payments_id ON payments(id);
CREATE INDEX payments_inv ON payments(invoice_id);
CREATE INDEX payments_accnt ON payments(account_id);
+CREATE INDEX payments_tenant_account_record_id ON payments(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS payment_history;
CREATE TABLE payment_history (
@@ -48,7 +47,7 @@ CREATE TABLE payment_history (
PRIMARY KEY (history_record_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE INDEX payment_history_record_id ON payment_history(record_id);
-
+CREATE INDEX payment_history_tenant_account_record_id ON payment_history(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS payment_attempts;
CREATE TABLE payment_attempts (
@@ -69,7 +68,7 @@ CREATE TABLE payment_attempts (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE UNIQUE INDEX payment_attempts_id ON payment_attempts(id);
CREATE INDEX payment_attempts_payment ON payment_attempts(payment_id);
-
+CREATE INDEX payment_attempts_tenant_account_record_id ON payment_attempts(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS payment_attempt_history;
CREATE TABLE payment_attempt_history (
@@ -90,7 +89,7 @@ CREATE TABLE payment_attempt_history (
PRIMARY KEY (history_record_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE INDEX payment_attempt_history_record_id ON payment_attempt_history(record_id);
-
+CREATE INDEX payment_attempt_history_tenant_account_record_id ON payment_attempt_history(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS payment_methods;
CREATE TABLE payment_methods (
@@ -110,7 +109,7 @@ CREATE TABLE payment_methods (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE UNIQUE INDEX payment_methods_id ON payment_methods(id);
CREATE INDEX payment_methods_active_accnt ON payment_methods(is_active, account_id);
-
+CREATE INDEX payment_methods_tenant_account_record_id ON payment_methods(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS payment_method_history;
CREATE TABLE payment_method_history (
@@ -130,6 +129,7 @@ CREATE TABLE payment_method_history (
PRIMARY KEY (history_record_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE UNIQUE INDEX payment_method_history_record_id ON payment_method_history(record_id);
+CREATE INDEX payment_method_history_tenant_account_record_id ON payment_method_history(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS refunds;
CREATE TABLE refunds (
@@ -152,6 +152,7 @@ CREATE TABLE refunds (
CREATE UNIQUE INDEX refunds_id ON refunds(id);
CREATE INDEX refunds_pay ON refunds(payment_id);
CREATE INDEX refunds_accnt ON refunds(account_id);
+CREATE INDEX refunds_tenant_account_record_id ON refunds(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS refund_history;
CREATE TABLE refund_history (
@@ -173,7 +174,7 @@ CREATE TABLE refund_history (
PRIMARY KEY (history_record_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE INDEX refund_history_record_id ON refund_history(record_id);
-
+CREATE INDEX refund_history_tenant_account_record_id ON refund_history(tenant_record_id, account_record_id);
diff --git a/usage/src/main/resources/com/ning/billing/usage/ddl.sql b/usage/src/main/resources/com/ning/billing/usage/ddl.sql
index b424075..23f046d 100644
--- a/usage/src/main/resources/com/ning/billing/usage/ddl.sql
+++ b/usage/src/main/resources/com/ning/billing/usage/ddl.sql
@@ -11,6 +11,7 @@ create table sources (
, primary key(record_id)
, index created_date_record_id_dx (created_date, record_id)
) engine = innodb default charset = latin1;
+create index sources_tenant_account_record_id on sources(tenant_record_id, account_record_id);
create table event_categories (
record_id integer not null auto_increment
@@ -19,6 +20,7 @@ create table event_categories (
, primary key(record_id)
, unique index event_category_unq (event_category)
) engine = innodb default charset = latin1;
+create index event_categories_tenant_record_id on event_categories(tenant_record_id);
create table metrics (
record_id int(11) unsigned not null auto_increment
@@ -28,6 +30,7 @@ create table metrics (
, primary key(record_id)
, unique index metric_unq (event_category_id, metric)
) engine = innodb default charset = latin1;
+create index metrics_tenant_record_id on metrics(tenant_record_id);
create table timeline_chunks (
record_id bigint not null auto_increment
@@ -65,3 +68,4 @@ create table timeline_rolled_up_chunk (
, tenant_record_id int(11) unsigned default null
, primary key(record_id)
) engine = innodb default charset = latin1;
+create index timeline_rolled_up_chunk_tenant_account_record_id on timeline_rolled_up_chunk(tenant_record_id, account_record_id);
diff --git a/util/src/main/resources/com/ning/billing/util/ddl.sql b/util/src/main/resources/com/ning/billing/util/ddl.sql
index 374b49f..980d9c9 100644
--- a/util/src/main/resources/com/ning/billing/util/ddl.sql
+++ b/util/src/main/resources/com/ning/billing/util/ddl.sql
@@ -17,6 +17,7 @@ CREATE TABLE custom_fields (
CREATE UNIQUE INDEX custom_fields_id ON custom_fields(id);
CREATE INDEX custom_fields_object_id_object_type ON custom_fields(object_id, object_type);
CREATE UNIQUE INDEX custom_fields_unique ON custom_fields(object_id, object_type, field_name);
+CREATE INDEX custom_fields_tenant_account_record_id ON custom_fields(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS custom_field_history;
CREATE TABLE custom_field_history (
@@ -36,6 +37,7 @@ CREATE TABLE custom_field_history (
) ENGINE=innodb;
CREATE INDEX custom_field_history_record_id ON custom_field_history(record_id);
CREATE INDEX custom_field_history_object_id_object_type ON custom_fields(object_id, object_type);
+CREATE INDEX custom_field_history_tenant_account_record_id ON custom_field_history(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS tag_definitions;
CREATE TABLE tag_definitions (
@@ -52,6 +54,7 @@ CREATE TABLE tag_definitions (
) ENGINE=innodb;
CREATE UNIQUE INDEX tag_definitions_id ON tag_definitions(id);
CREATE UNIQUE INDEX tag_definitions_name ON tag_definitions(name);
+CREATE INDEX tag_definitions_tenant_record_id ON tag_definitions(tenant_record_id);
DROP TABLE IF EXISTS tag_definition_history;
CREATE TABLE tag_definition_history (
@@ -70,6 +73,7 @@ CREATE TABLE tag_definition_history (
CREATE INDEX tag_definition_history_id ON tag_definition_history(id);
CREATE INDEX tag_definition_history_record_id ON tag_definition_history(record_id);
CREATE INDEX tag_definition_history_name ON tag_definition_history(name);
+CREATE INDEX tag_definition_history_tenant_record_id ON tag_definition_history(tenant_record_id);
DROP TABLE IF EXISTS tags;
CREATE TABLE tags (
@@ -87,6 +91,7 @@ CREATE TABLE tags (
CREATE UNIQUE INDEX tags_id ON tags(id);
CREATE INDEX tags_by_object ON tags(object_id);
CREATE UNIQUE INDEX tags_unique ON tags(tag_definition_id, object_id);
+CREATE INDEX tags_tenant_account_record_id ON tags(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS tag_history;
CREATE TABLE tag_history (
@@ -105,6 +110,7 @@ CREATE TABLE tag_history (
) ENGINE = innodb;
CREATE INDEX tag_history_record_id ON tag_history(record_id);
CREATE INDEX tag_history_by_object ON tags(object_id);
+CREATE INDEX tag_history_tenant_account_record_id ON tag_history(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS notifications;
CREATE TABLE notifications (
@@ -128,6 +134,7 @@ CREATE UNIQUE INDEX notifications_id ON notifications(id);
CREATE INDEX `idx_comp_where` ON notifications (`effective_date`, `queue_name`, `processing_state`,`processing_owner`,`processing_available_date`);
CREATE INDEX `idx_update` ON notifications (`processing_state`,`processing_owner`,`processing_available_date`);
CREATE INDEX `idx_get_ready` ON notifications (`effective_date`,`created_date`,`id`);
+CREATE INDEX notifications_tenant_account_record_id ON notifications(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS claimed_notifications;
CREATE TABLE claimed_notifications (
@@ -139,6 +146,7 @@ CREATE TABLE claimed_notifications (
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
) ENGINE=innodb;
+CREATE INDEX claimed_notifications_tenant_account_record_id ON claimed_notifications(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS audit_log;
CREATE TABLE audit_log (
@@ -157,6 +165,7 @@ CREATE TABLE audit_log (
) ENGINE=innodb;
CREATE INDEX audit_log_fetch_record ON audit_log(table_name, record_id);
CREATE INDEX audit_log_user_name ON audit_log(changed_by);
+CREATE INDEX audit_log_tenant_account_record_id ON audit_log(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS bus_events;
CREATE TABLE bus_events (
@@ -173,6 +182,7 @@ CREATE TABLE bus_events (
PRIMARY KEY(record_id)
) ENGINE=innodb;
CREATE INDEX `idx_bus_where` ON bus_events (`processing_state`,`processing_owner`,`processing_available_date`);
+CREATE INDEX bus_events_tenant_account_record_id ON bus_events(tenant_record_id, account_record_id);
DROP TABLE IF EXISTS claimed_bus_events;
CREATE TABLE claimed_bus_events (
@@ -184,3 +194,4 @@ CREATE TABLE claimed_bus_events (
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
) ENGINE=innodb;
+CREATE INDEX claimed_bus_events_tenant_account_record_id ON claimed_bus_events(tenant_record_id, account_record_id);