diff --git a/core/src/main/java/google/registry/model/domain/DomainBase.java b/core/src/main/java/google/registry/model/domain/DomainBase.java index aa1d77a70..37fa0e2e5 100644 --- a/core/src/main/java/google/registry/model/domain/DomainBase.java +++ b/core/src/main/java/google/registry/model/domain/DomainBase.java @@ -75,7 +75,9 @@ public class DomainBase extends DomainContent } @ElementCollection - @JoinTable(name = "DomainHost") + @JoinTable( + name = "DomainHost", + indexes = {@Index(columnList = "domain_repo_id,host_repo_id", unique = true)}) @Access(AccessType.PROPERTY) @Column(name = "host_repo_id") public Set> getNsHosts() { diff --git a/core/src/main/java/google/registry/model/domain/DomainHistory.java b/core/src/main/java/google/registry/model/domain/DomainHistory.java index 64f2bc7c2..00d207ec9 100644 --- a/core/src/main/java/google/registry/model/domain/DomainHistory.java +++ b/core/src/main/java/google/registry/model/domain/DomainHistory.java @@ -96,7 +96,14 @@ public class DomainHistory extends HistoryEntry implements SqlEntity { // TODO(b/166776754): Investigate if we can reuse domainContent.nsHosts for storing host keys. @Ignore @ElementCollection - @JoinTable(name = "DomainHistoryHost") + @JoinTable( + name = "DomainHistoryHost", + indexes = { + @Index( + columnList = + "domain_history_history_revision_id,domain_history_domain_repo_id,host_repo_id", + unique = true), + }) @Column(name = "host_repo_id") Set> nsHosts; diff --git a/db/src/main/resources/sql/er_diagram/brief_er_diagram.html b/db/src/main/resources/sql/er_diagram/brief_er_diagram.html index 6015cbdd8..672b07563 100644 --- a/db/src/main/resources/sql/er_diagram/brief_er_diagram.html +++ b/db/src/main/resources/sql/er_diagram/brief_er_diagram.html @@ -261,11 +261,11 @@ td.section { generated on - 2020-12-16 16:26:55.279224 + 2020-12-21 17:41:59.495189 last flyway file - V82__add_columns_to_restore_symmetric_billing_vkey.sql + V83__add_indexes_on_domainhost.sql @@ -284,7 +284,7 @@ td.section { generated on - 2020-12-16 16:26:55.279224 + 2020-12-21 17:41:59.495189 @@ -568,14 +568,14 @@ td.section { billingevent_a57d1815:w->domainhistory_a54cc226:e - + - - - - - + + + + + fk_billing_event_domain_history @@ -617,14 +617,14 @@ td.section { billingevent_a57d1815:w->registrar_6e1503e3:e - - - - - - - - + + + + + + + + fk_billing_event_registrar_id @@ -1754,14 +1754,14 @@ td.section { pollmessage_614a523e:w->domainhistory_a54cc226:e - + - - - - - + + + + + fk_poll_message_domain_history @@ -2252,21 +2252,29 @@ td.section { domainhistoryhost_9f3f23ee - - + + public.DomainHistoryHost - - + + [table] - + domain_history_history_revision_id + + + + int8 not null + + + host_repo_id + - int8 not null + text domain_history_domain_repo_id @@ -2276,31 +2284,31 @@ td.section { text not null - + domainhistoryhost_9f3f23ee:w->domainhistory_a54cc226:e - - - - - - - - + + + + + + + + fka9woh3hu8gx5x0vly6bai327n domainhistoryhost_9f3f23ee:w->domainhistory_a54cc226:e - - - - - - - - + + + + + + + + fka9woh3hu8gx5x0vly6bai327n @@ -2430,14 +2438,14 @@ td.section { graceperiodhistory_40ccc1f1:w->domainhistory_a54cc226:e - - - + + + - + fk7w3cx8d55q8bln80e716tr7b8 @@ -4790,6 +4798,11 @@ td.section { domain_history_history_revision_id int8 not null + + + host_repo_id + text + domain_history_domain_repo_id diff --git a/db/src/main/resources/sql/er_diagram/full_er_diagram.html b/db/src/main/resources/sql/er_diagram/full_er_diagram.html index 93a85397f..4072ca681 100644 --- a/db/src/main/resources/sql/er_diagram/full_er_diagram.html +++ b/db/src/main/resources/sql/er_diagram/full_er_diagram.html @@ -261,11 +261,11 @@ td.section { generated on - 2020-12-16 16:26:53.180789 + 2020-12-21 17:41:57.553769 last flyway file - V82__add_columns_to_restore_symmetric_billing_vkey.sql + V83__add_indexes_on_domainhost.sql @@ -284,7 +284,7 @@ td.section { generated on - 2020-12-16 16:26:53.180789 + 2020-12-21 17:41:57.553769 @@ -9921,6 +9921,34 @@ td.section { domain_history_history_revision_id (0..many)→ public.DomainHistory.history_revision_id + + + + + Indexes + + + + + + ukt2e7ae3t8gcsxd13wjx2ka7ij + [unique index] + + + + domain_history_history_revision_id + ascending + + + + domain_history_domain_repo_id + ascending + + + + host_repo_id + ascending +

 

@@ -9968,6 +9996,29 @@ td.section { host_repo_id (0..many)→ public.Host.repo_id + + + + + Indexes + + + + + + ukat9erbh52e4lg3jw6ai9wkjj9 + [unique index] + + + + domain_repo_id + ascending + + + + host_repo_id + ascending +

 

diff --git a/db/src/main/resources/sql/flyway.txt b/db/src/main/resources/sql/flyway.txt index 3bc5cc50f..5fb661992 100644 --- a/db/src/main/resources/sql/flyway.txt +++ b/db/src/main/resources/sql/flyway.txt @@ -80,3 +80,4 @@ V79__drop_foreign_keys_on_pollmessage.sql V80__defer_bill_event_key.sql V81__drop_spec11_fkeys.sql V82__add_columns_to_restore_symmetric_billing_vkey.sql +V83__add_indexes_on_domainhost.sql diff --git a/db/src/main/resources/sql/flyway/V83__add_indexes_on_domainhost.sql b/db/src/main/resources/sql/flyway/V83__add_indexes_on_domainhost.sql new file mode 100644 index 000000000..97f026d61 --- /dev/null +++ b/db/src/main/resources/sql/flyway/V83__add_indexes_on_domainhost.sql @@ -0,0 +1,23 @@ +-- Copyright 2020 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 if exists "DomainHistoryHost" + add constraint UKt2e7ae3t8gcsxd13wjx2ka7ij unique ( + domain_history_history_revision_id, + domain_history_domain_repo_id, + host_repo_id); + +alter table if exists "DomainHost" + add constraint UKat9erbh52e4lg3jw6ai9wkjj9 unique ( + domain_repo_id, host_repo_id); diff --git a/db/src/main/resources/sql/schema/db-schema.sql.generated b/db/src/main/resources/sql/schema/db-schema.sql.generated index 7b2fbaaae..d2f7e642d 100644 --- a/db/src/main/resources/sql/schema/db-schema.sql.generated +++ b/db/src/main/resources/sql/schema/db-schema.sql.generated @@ -768,6 +768,12 @@ create index IDXrh4xmrot9bd63o382ow9ltfig on "DomainHistory" (creation_time); create index IDXaro1omfuaxjwmotk3vo00trwm on "DomainHistory" (history_registrar_id); create index IDXsu1nam10cjes9keobapn5jvxj on "DomainHistory" (history_type); create index IDX6w3qbtgce93cal2orjg1tw7b7 on "DomainHistory" (history_modification_time); + + alter table if exists "DomainHistoryHost" + add constraint UKt2e7ae3t8gcsxd13wjx2ka7ij unique (domain_history_history_revision_id, domain_history_domain_repo_id, host_repo_id); + + alter table if exists "DomainHost" + add constraint UKat9erbh52e4lg3jw6ai9wkjj9 unique (domain_repo_id, host_repo_id); create index IDXj1mtx98ndgbtb1bkekahms18w on "GracePeriod" (domain_repo_id); create index IDXd01j17vrpjxaerxdmn8bwxs7s on "GracePeriodHistory" (domain_repo_id); create index IDXfg2nnjlujxo6cb9fha971bq2n on "HostHistory" (creation_time); diff --git a/db/src/main/resources/sql/schema/nomulus.golden.sql b/db/src/main/resources/sql/schema/nomulus.golden.sql index 26afb03dd..f80c02c15 100644 --- a/db/src/main/resources/sql/schema/nomulus.golden.sql +++ b/db/src/main/resources/sql/schema/nomulus.golden.sql @@ -1428,6 +1428,22 @@ ALTER TABLE ONLY public."RegistryLock" ADD CONSTRAINT idx_registry_lock_repo_id_revision_id UNIQUE (repo_id, revision_id); +-- +-- Name: DomainHost ukat9erbh52e4lg3jw6ai9wkjj9; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."DomainHost" + ADD CONSTRAINT ukat9erbh52e4lg3jw6ai9wkjj9 UNIQUE (domain_repo_id, host_repo_id); + + +-- +-- Name: DomainHistoryHost ukt2e7ae3t8gcsxd13wjx2ka7ij; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."DomainHistoryHost" + ADD CONSTRAINT ukt2e7ae3t8gcsxd13wjx2ka7ij UNIQUE (domain_history_history_revision_id, domain_history_domain_repo_id, host_repo_id); + + -- -- Name: allocation_token_domain_name_idx; Type: INDEX; Schema: public; Owner: - --