Skip to content

Commit

Permalink
Drop FKs referencing DomainHistory
Browse files Browse the repository at this point in the history
- We never delete rows from DomainHistory (and even if we do in the
  future, they'll be old / the references won't matter)
- This is likely creating lock contention when lots of requests come
  through at once for domains with many DomainHistory entries
  • Loading branch information
gbrodman committed Dec 9, 2024
1 parent cb3738d commit b6b39f4
Show file tree
Hide file tree
Showing 17 changed files with 220 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
@Index(columnList = "domainRepoId"),
@Index(columnList = "billingTime"),
@Index(columnList = "billing_event_id"),
@Index(columnList = "billing_recurrence_id")
@Index(columnList = "billing_recurrence_id"),
@Index(columnList = "domainRepoId,domainHistoryRevisionId")
})
@AttributeOverride(name = "id", column = @Column(name = "billing_cancellation_id"))
@WithVKey(Long.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
@Index(columnList = "syntheticCreationTime"),
@Index(columnList = "domainRepoId"),
@Index(columnList = "allocationToken"),
@Index(columnList = "cancellation_matching_billing_recurrence_id")
@Index(columnList = "cancellation_matching_billing_recurrence_id"),
@Index(columnList = "domainRepoId,domainHistoryRevisionId"),
@Index(columnList = "domainRepoId,recurrenceHistoryRevisionId")
})
@AttributeOverride(name = "id", column = @Column(name = "billing_event_id"))
@WithVKey(Long.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
@Index(columnList = "domainRepoId"),
@Index(columnList = "recurrenceEndTime"),
@Index(columnList = "recurrenceLastExpansion"),
@Index(columnList = "recurrence_time_of_year")
@Index(columnList = "recurrenceTimeOfYear"),
@Index(columnList = "domainRepoId,domainHistoryRevisionId")
})
@AttributeOverride(name = "id", column = @Column(name = "billing_recurrence_id"))
@WithVKey(Long.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public static GracePeriod forBillingEvent(

/** Entity class to represent a historic {@link GracePeriod}. */
@Entity(name = "GracePeriodHistory")
@Table(indexes = @Index(columnList = "domainRepoId"))
@Table(indexes = {@Index(columnList = "domainRepoId"), @Index(columnList = "domainRepoId,domainHistoryRevisionId")})
public static class GracePeriodHistory extends GracePeriodBase {
@Id Long gracePeriodHistoryRevisionId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Index;
import jakarta.persistence.Table;

/** Entity class to represent a historic {@link DomainDsData}. */
@Entity
@Table(indexes = @Index(columnList = "domainRepoId,domainHistoryRevisionId"))
public class DomainDsDataHistory extends DomainDsDataBase {

@Id Long dsDataHistoryRevisionId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@
@Table(
indexes = {
@Index(columnList = "domainRepoId"),
@Index(columnList = "registrar_id"),
@Index(columnList = "eventTime")
@Index(columnList = "registrarId"),
@Index(columnList = "eventTime"),
@Index(columnList = "domainRepoId,domainHistoryRevisionId")
})
public abstract class PollMessage extends ImmutableObject
implements Buildable, TransferServerApproveEntity, UnsafeSerializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Index;
import jakarta.persistence.Table;
import org.joda.time.DateTime;

/**
Expand All @@ -42,6 +44,7 @@
* uses HistoryEntry.otherClientId because the losing party in a transfer is always the otherClient.
*/
@Entity
@Table(indexes = @Index(columnList = "domainRepoId,historyRevisionId"))
public class DomainTransactionRecord extends ImmutableObject
implements Buildable, UnsafeSerializable {

Expand Down
7 changes: 7 additions & 0 deletions db/src/main/resources/sql/flyway.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,10 @@ V176__drop_login_email_address_column_from_registrar_poc.sql
V177__drop_user_id.sql
V178__drop_user_id_history.sql
V179__add_discount_price_allocation_token.sql
V180__remove_fk_graceperiodhistory_domainhistory.sql
V181__remove_fk_billingcancellation_domainhistory.sql
V182__remove_fk_billingevent_domainhistory.sql
V183__remove_fk_billingrecurrence_domainhistory.sql
V184__remove_fk_pollmessage_domainhistory.sql
V185__remove_fk_domaintransactionrecord_domainhistory.sql
V186__remove_fk_domaindsdatahistory_domainhistory.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Copyright 2024 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

ALTER TABLE "GracePeriodHistory" DROP CONSTRAINT fk7w3cx8d55q8bln80e716tr7b8;
CREATE INDEX IDXl67y6wclc2uaupepnvkoo81fl on "GracePeriodHistory" (domain_repo_id, domain_history_revision_id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Copyright 2024 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

ALTER TABLE "BillingCancellation" DROP CONSTRAINT fk_billing_cancellation_domain_history;
CREATE INDEX IDX7v75e535c47mxfb2rk9o843bn ON"BillingCancellation" (domain_repo_id, domain_history_revision_id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Copyright 2024 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

ALTER TABLE "BillingEvent" DROP CONSTRAINT fk_billing_event_domain_history;
ALTER TABLE "BillingEvent" DROP CONSTRAINT fk_billing_event_recurrence_history;
CREATE INDEX IDX77ceolnf7rok8ui957msmo6en ON "BillingEvent" (domain_repo_id, domain_history_revision_id);
CREATE INDEX IDXehp8ejwpbsooar0e8k32847m3 ON "BillingEvent" (domain_repo_id, recurrence_history_revision_id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Copyright 2024 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

ALTER TABLE "BillingRecurrence" DROP CONSTRAINT fk_billing_recurrence_domain_history;
CREATE INDEX IDXlh9lvmxb2dj3ti83buauwvbil ON "BillingRecurrence" (domain_repo_id, domain_history_revision_id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Copyright 2024 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

ALTER TABLE "PollMessage" DROP CONSTRAINT fk_poll_message_domain_history;
CREATE INDEX IDXfkg5lrxr5yg54jpii25a17v53 ON "PollMessage" (domain_repo_id, domain_history_revision_id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Copyright 2024 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

ALTER TABLE "DomainTransactionRecord" DROP CONSTRAINT "fkcjqe54u72kha71vkibvxhjye7";
CREATE INDEX IDX1dyqmqb61xbnj7mt7bk27ds25 ON "DomainTransactionRecord" (domain_repo_id, history_revision_id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Copyright 2024 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

ALTER TABLE "DomainDsDataHistory" DROP CONSTRAINT fko4ilgyyfnvppbpuivus565i0j;
CREATE INDEX IDXmk1d2ngdtfkg6odmw7l5ejisw ON "DomainDsDataHistory" (domain_repo_id, domain_history_revision_id);
28 changes: 26 additions & 2 deletions db/src/main/resources/sql/schema/db-schema.sql.generated
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,9 @@
create index IDXku0fopwyvd57ebo8bf0jg9xo2
on "BillingCancellation" (billing_recurrence_id);

create index IDX7v75e535c47mxfb2rk9o843bn
on "BillingCancellation" (domain_repo_id, domain_history_revision_id);

create index IDXqspv57gj2led8ly42fq01t7m7
on "BillingEvent" (registrar_id);

Expand All @@ -968,6 +971,12 @@
create index IDX6ebt3nwk5ocvnremnhnlkl6ff
on "BillingEvent" (cancellation_matching_billing_recurrence_id);

create index IDX77ceolnf7rok8ui957msmo6en
on "BillingEvent" (domain_repo_id, domain_history_revision_id);

create index IDXehp8ejwpbsooar0e8k32847m3
on "BillingEvent" (domain_repo_id, recurrence_history_revision_id);

create index IDXd3gxhkh0jk694pjvh9pyn7wjc
on "BillingRecurrence" (registrar_id);

Expand All @@ -983,9 +992,12 @@
create index IDXp0pxi708hlu4n40qhbtihge8x
on "BillingRecurrence" (recurrence_last_expansion);

create index IDXjny8wuot75b5e6p38r47wdawu
create index IDXbix949l2kfn9r03l6omyhi36f
on "BillingRecurrence" (recurrence_time_of_year);

create index IDXlh9lvmxb2dj3ti83buauwvbil
on "BillingRecurrence" (domain_repo_id, domain_history_revision_id);

create index IDXj874kw19bgdnkxo1rue45jwlw
on "BsaDownload" (creation_time);

Expand Down Expand Up @@ -1079,6 +1091,9 @@
create index IDXhteajcrxmq4o8rsys8kevyiqr
on "Domain" (transfer_billing_cancellation_id);

create index IDXmk1d2ngdtfkg6odmw7l5ejisw
on "DomainDsDataHistory" (domain_repo_id, domain_history_revision_id);

create index IDXrh4xmrot9bd63o382ow9ltfig
on "DomainHistory" (creation_time);

Expand All @@ -1097,6 +1112,9 @@
create index IDXjw3rwtfrexyq53x9vu7qghrdt
on "DomainHost" (host_repo_id);

create index IDX1dyqmqb61xbnj7mt7bk27ds25
on "DomainTransactionRecord" (domain_repo_id, history_revision_id);

create index IDXj1mtx98ndgbtb1bkekahms18w
on "GracePeriod" (domain_repo_id);

Expand All @@ -1109,6 +1127,9 @@
create index IDXd01j17vrpjxaerxdmn8bwxs7s
on "GracePeriodHistory" (domain_repo_id);

create index IDXl67y6wclc2uaupepnvkoo81fl
on "GracePeriodHistory" (domain_repo_id, domain_history_revision_id);

create index IDXkpkh68n6dy5v51047yr6b0e9l
on "Host" (host_name);

Expand Down Expand Up @@ -1145,12 +1166,15 @@
create index IDXf2q9dqj899h1q8lah5y719nxd
on "PollMessage" (domain_repo_id);

create index IDXe7wu46c7wpvfmfnj4565abibp
create index IDXb75725p8js6987ubi8a7nhdqs
on "PollMessage" (registrar_id);

create index IDXaydgox62uno9qx8cjlj5lauye
on "PollMessage" (event_time);

create index IDXfkg5lrxr5yg54jpii25a17v53
on "PollMessage" (domain_repo_id, domain_history_revision_id);

create index premiumlist_name_idx
on "PremiumList" (name);

Expand Down
Loading

0 comments on commit b6b39f4

Please sign in to comment.