From 6123f10cdf8d0d1dd6c544f407b16a0e7fb0fad5 Mon Sep 17 00:00:00 2001 From: gbrodman Date: Wed, 12 Aug 2026 17:05:06 +0000 Subject: [PATCH] Add history table indexes for RDE generation (#3206) We can make the "select the correct most recent history object" query much more efficient + simple but we'll want to have these indexes so we can select the most recently modified entry for a given repo ID (at least, one before a particular watermark). --- .../sql/er_diagram/brief_er_diagram.html | 6 +-- .../sql/er_diagram/full_er_diagram.html | 40 +++++++++++++++++-- db/src/main/resources/sql/flyway.txt | 2 + ...27__domainhistory_repo_id_mod_time_idx.sql | 16 ++++++++ ...V228__hosthistory_repo_id_mod_time_idx.sql | 16 ++++++++ .../resources/sql/schema/nomulus.golden.sql | 14 +++++++ 6 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 db/src/main/resources/sql/flyway/V227__domainhistory_repo_id_mod_time_idx.sql create mode 100644 db/src/main/resources/sql/flyway/V228__hosthistory_repo_id_mod_time_idx.sql 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 fe218f7d3..14990bd7a 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 - 2026-08-05 12:44:04 + 2026-08-12 15:34:00 last flyway file - V226__tld_domain_name_index.sql + V228__hosthistory_repo_id_mod_time_idx.sql @@ -273,7 +273,7 @@ td.section {

 

- SchemaCrawler_Diagram generated by SchemaCrawler 17.12.2 generated on 2026-08-05 12:44:04 + SchemaCrawler_Diagram generated by SchemaCrawler 17.12.2 generated on 2026-08-12 15:34:00 allocationtoken_a08ccbef public."AllocationToken" [table] token text not null domain_name text redemption_domain_repo_id text token_type text 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 67d9fcd1b..4d6e2f15c 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 - 2026-08-05 12:44:03 + 2026-08-12 15:33:59
last flyway file - V226__tld_domain_name_index.sql + V228__hosthistory_repo_id_mod_time_idx.sql
@@ -273,7 +273,7 @@ td.section {

 

- SchemaCrawler_Diagram generated by SchemaCrawler 17.12.2 generated on 2026-08-05 12:44:03 + SchemaCrawler_Diagram generated by SchemaCrawler 17.12.2 generated on 2026-08-12 15:33:59 allocationtoken_a08ccbef public."AllocationToken" [table] token text not null update_timestamp timestamptz allowed_registrar_ids _text allowed_tlds _text creation_time timestamptz not null discount_fraction float8(17, 17) not null discount_premiums bool not null discount_years int4 not null domain_name text redemption_domain_repo_id text token_status_transitions hstore token_type text redemption_domain_history_id int8 renewal_price_behavior text not null registration_behavior text not null allowed_epp_actions _text renewal_price_amount numeric(19, 2) renewal_price_currency text discount_price_amount numeric(19, 2) discount_price_currency text @@ -4362,6 +4362,23 @@ td.section { history_revision_id ascending +
+ +
+
+ domainhistory_repo_id_modification_time + [non-unique index] +
+
+ + domain_repo_id + ascending +
+
+ + history_modification_time + ascending +

 

@@ -5710,6 +5727,23 @@ td.section { history_revision_id ascending + + + + + hosthistory_repo_id_modification_time + [non-unique index] + + + + host_repo_id + ascending + + + + history_modification_time + ascending +

 

diff --git a/db/src/main/resources/sql/flyway.txt b/db/src/main/resources/sql/flyway.txt index f2dadff5b..880a57c13 100644 --- a/db/src/main/resources/sql/flyway.txt +++ b/db/src/main/resources/sql/flyway.txt @@ -224,3 +224,5 @@ V223__tld_change_xap_enabled_to_transitions.sql V224__add_registrar_expiry_access_period_enabled.sql V225__user_registry_lock_email_address_index.sql V226__tld_domain_name_index.sql +V227__domainhistory_repo_id_mod_time_idx.sql +V228__hosthistory_repo_id_mod_time_idx.sql diff --git a/db/src/main/resources/sql/flyway/V227__domainhistory_repo_id_mod_time_idx.sql b/db/src/main/resources/sql/flyway/V227__domainhistory_repo_id_mod_time_idx.sql new file mode 100644 index 000000000..0975debc0 --- /dev/null +++ b/db/src/main/resources/sql/flyway/V227__domainhistory_repo_id_mod_time_idx.sql @@ -0,0 +1,16 @@ +-- Copyright 2026 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. + +CREATE INDEX CONCURRENTLY IF NOT EXISTS domainhistory_repo_id_modification_time + ON "DomainHistory" (domain_repo_id, history_modification_time); diff --git a/db/src/main/resources/sql/flyway/V228__hosthistory_repo_id_mod_time_idx.sql b/db/src/main/resources/sql/flyway/V228__hosthistory_repo_id_mod_time_idx.sql new file mode 100644 index 000000000..017415519 --- /dev/null +++ b/db/src/main/resources/sql/flyway/V228__hosthistory_repo_id_mod_time_idx.sql @@ -0,0 +1,16 @@ +-- Copyright 2026 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. + +CREATE INDEX CONCURRENTLY IF NOT EXISTS hosthistory_repo_id_modification_time + ON "HostHistory" (host_repo_id, history_modification_time); diff --git a/db/src/main/resources/sql/schema/nomulus.golden.sql b/db/src/main/resources/sql/schema/nomulus.golden.sql index d041fef59..b953ac976 100644 --- a/db/src/main/resources/sql/schema/nomulus.golden.sql +++ b/db/src/main/resources/sql/schema/nomulus.golden.sql @@ -1876,6 +1876,13 @@ CREATE INDEX domainhistory_domain_repo_id_hash ON public."DomainHistory" USING h CREATE INDEX domainhistory_history_revision_id_hash ON public."DomainHistory" USING hash (history_revision_id); +-- +-- Name: domainhistory_repo_id_modification_time; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX domainhistory_repo_id_modification_time ON public."DomainHistory" USING btree (domain_repo_id, history_modification_time); + + -- -- Name: domainhistoryhost_domain_history_history_revision_id_hash; Type: INDEX; Schema: public; Owner: - -- @@ -1946,6 +1953,13 @@ CREATE INDEX host_host_name_hash ON public."Host" USING hash (host_name); CREATE INDEX host_repo_id_hash ON public."Host" USING hash (repo_id); +-- +-- Name: hosthistory_repo_id_modification_time; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX hosthistory_repo_id_modification_time ON public."HostHistory" USING btree (host_repo_id, history_modification_time); + + -- -- Name: idx1dyqmqb61xbnj7mt7bk27ds25; Type: INDEX; Schema: public; Owner: - --