From c1ba725d3d5d4c532b5821804e76f51846d6c329 Mon Sep 17 00:00:00 2001 From: Weimin Yu Date: Tue, 8 Mar 2022 14:22:01 -0500 Subject: [PATCH] Revise Host index on inet_addresses (#1549) * Revise Host index on inet_addresses The index on the 'inet_addresses array column should be of gin or gist type, which index individual array elements. We use gin for now since host updates are not often, and gin has better accuracy. Since flyway script V108__... has not been deployed, we edit the file in place instead of adding a new script. This will be followed up with a modified query that can take advantage of the gin index. Until then we don't expect to see performance improvement. The suspected bottlenect query in the whois path is: select * from "Host" where 'non-ip-string' = any(inet_address) and deletion_time < now(); It needs to be revised into: select * from "Host" where array['non-ip-string'] <@ inet_address and deletion_time < now(); The combined change reduces the query time from 90ms to 30ms in Sandbox, and from 150ms to 40ms in production. It is unclear if this solves all problem with whois latency. --- .../sql/er_diagram/brief_er_diagram.html | 597 +++++++++--------- .../sql/er_diagram/full_er_diagram.html | 18 +- .../V108__add_host_indexes_for_whois.sql | 5 +- .../resources/sql/schema/nomulus.golden.sql | 9 +- 4 files changed, 298 insertions(+), 331 deletions(-) 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 fdee13b9a..0eac7462f 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,7 +261,7 @@ td.section { generated on - 2022-03-07 19:59:41.272148 + 2022-03-08 17:12:37.970348 last flyway file @@ -284,7 +284,7 @@ td.section { generated on - 2022-03-07 19:59:41.272148 + 2022-03-08 17:12:37.970348 @@ -651,7 +651,7 @@ td.section { billingevent_a57d1815:w->registrar_6e1503e3:e - + @@ -664,98 +664,98 @@ td.section { billingcancellation_6eedf614 - - + + public.BillingCancellation - - + + [table] - + billing_cancellation_id - + - + int8 not null - + registrar_id - + - + text not null - + domain_history_revision_id - + - + int8 not null - + domain_repo_id - + - + text not null - + event_time - + - + timestamptz not null - + billing_time - + - + timestamptz - + billing_event_id - + - + int8 - + billing_recurrence_id - + - + int8 - + billingcancellation_6eedf614:w->billingevent_a57d1815:e - - - + + + - + fk_billing_cancellation_billing_event_id billingcancellation_6eedf614:w->billingrecurrence_5fa2cb01:e - - - + + + @@ -766,39 +766,39 @@ td.section { billingcancellation_6eedf614:w->domainhistory_a54cc226:e - - - - + + + + - - - + + + fk_billing_cancellation_domain_history billingcancellation_6eedf614:w->domainhistory_a54cc226:e - - - + + + - + fk_billing_cancellation_domain_history billingcancellation_6eedf614:w->registrar_6e1503e3:e - - - - - - - + + + + + + + fk_billing_cancellation_registrar_id @@ -977,10 +977,10 @@ td.section { domain_6c51cffa:w->billingevent_a57d1815:e - + - + @@ -990,21 +990,21 @@ td.section { domain_6c51cffa:w->billingcancellation_6eedf614:e - - - - - - - - + + + + + + + + fk_domain_transfer_billing_cancellation_id domain_6c51cffa:w->billingrecurrence_5fa2cb01:e - - + + @@ -1016,7 +1016,7 @@ td.section { domain_6c51cffa:w->billingrecurrence_5fa2cb01:e - + @@ -1121,53 +1121,53 @@ td.section { domain_6c51cffa:w->contact_8de8cb16:e - - - - - - - - + + + + + + + + fk_domain_admin_contact domain_6c51cffa:w->contact_8de8cb16:e - - - - - - - - + + + + + + + + fk_domain_billing_contact domain_6c51cffa:w->contact_8de8cb16:e - - - - - - - - + + + + + + + + fk_domain_registrant_contact domain_6c51cffa:w->contact_8de8cb16:e - - - + + + - + fk_domain_tech_contact @@ -1199,14 +1199,14 @@ td.section { domain_6c51cffa:w->registrar_6e1503e3:e - - - + + + - + fkjc0r9r5y1lfbt4gpbqw4wsuvq @@ -1271,100 +1271,100 @@ td.section { graceperiod_cd3b2e8f - - + + public.GracePeriod - - + + [table] - + grace_period_id - + - + int8 not null - + billing_event_id - + - + int8 - + billing_recurrence_id - + - + int8 - + registrar_id - + - + text not null - + domain_repo_id - + - + text not null - + graceperiod_cd3b2e8f:w->billingevent_a57d1815:e - - - - + + + + - - - + + + fk_grace_period_billing_event_id graceperiod_cd3b2e8f:w->domain_6c51cffa:e - - - + + + - + fk_grace_period_domain_repo_id graceperiod_cd3b2e8f:w->billingrecurrence_5fa2cb01:e - - - + + + - - - + + + fk_grace_period_billing_recurrence_id graceperiod_cd3b2e8f:w->registrar_6e1503e3:e - - - + + + @@ -1401,13 +1401,13 @@ td.section { billingrecurrence_5fa2cb01:w->registrar_6e1503e3:e - - - - - - - + + + + + + + fk_billing_recurrence_registrar_id @@ -1545,87 +1545,87 @@ td.section { contacthistory_d2964f8a - - + + public.ContactHistory - - + + [table] - + history_revision_id - + - + int8 not null - + history_registrar_id - + - + text - + history_modification_time - + - + timestamptz not null - + history_type - + - + text not null - + creation_time - + - + timestamptz - + contact_repo_id - + - + text not null - + contacthistory_d2964f8a:w->contact_8de8cb16:e - - - + + + - + fk_contact_history_contact_repo_id contacthistory_d2964f8a:w->registrar_6e1503e3:e - - - - - - - - + + + + + + + + fk_contact_history_registrar_id @@ -1744,48 +1744,48 @@ td.section { pollmessage_614a523e:w->contact_8de8cb16:e - + - - - - + + + + fk_poll_message_contact_repo_id pollmessage_614a523e:w->contacthistory_d2964f8a:e - + - - - - - + + + + + fk_poll_message_contact_history pollmessage_614a523e:w->contacthistory_d2964f8a:e - + - - - - - + + + + + fk_poll_message_contact_history pollmessage_614a523e:w->domainhistory_a54cc226:e - - - + + + @@ -1809,90 +1809,82 @@ td.section { host_f21b78de - - + + public.Host - - + + [table] - + repo_id - + - + text not null - + creation_registrar_id - + - + text - + current_sponsor_registrar_id - + - + text - - deletion_time - - - - - timestamptz - - + last_epp_update_registrar_id - + - + text - + host_name - + - + text - + superordinate_domain - + - + text - + inet_addresses - + - + _text - + pollmessage_614a523e:w->host_f21b78de:e - + - - - - - + + + + + fk_poll_message_host_repo_id @@ -1992,22 +1984,22 @@ td.section { pollmessage_614a523e:w->registrar_6e1503e3:e - - - - - - - - + + + + + + + + fk_poll_message_registrar_id pollmessage_614a523e:w->registrar_6e1503e3:e - - - + + + @@ -2018,12 +2010,12 @@ td.section { pollmessage_614a523e:w->registrar_6e1503e3:e - - - - + + + + - + fk_poll_message_transfer_response_losing_registrar_id @@ -2157,9 +2149,9 @@ td.section { domainhistory_a54cc226:w->registrar_6e1503e3:e - - - + + + @@ -2211,22 +2203,22 @@ td.section { domainhost_1ea127c2:w->host_f21b78de:e - - - - - - - - + + + + + + + + fk_domainhost_host_valid host_f21b78de:w->domain_6c51cffa:e - - - + + + @@ -2237,40 +2229,40 @@ td.section { host_f21b78de:w->registrar_6e1503e3:e - - - + + + - + - + fk_host_creation_registrar_id host_f21b78de:w->registrar_6e1503e3:e - - - + + + - - - + + + fk_host_current_sponsor_registrar_id host_f21b78de:w->registrar_6e1503e3:e - - - + + + - + fk_host_last_epp_update_registrar_id @@ -2475,14 +2467,14 @@ td.section { domaintransactionrecord_6e77ff61:w->tld_f1fa57e2:e - - - + + + - + fk_domain_transaction_record_tld @@ -2550,14 +2542,14 @@ td.section { hosthistory_56210c2:w->host_f21b78de:e - - + + - - - - - + + + + + fk_hosthistory_host @@ -5268,11 +5260,6 @@ td.section { current_sponsor_registrar_id text - - - deletion_time - timestamptz - last_epp_update_registrar_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 26c80c5f8..67bcc3e4b 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,7 +261,7 @@ td.section { generated on - 2022-03-07 19:59:39.894792 + 2022-03-08 17:12:35.997985 last flyway file @@ -284,7 +284,7 @@ td.section { generated on - 2022-03-07 19:59:39.894792 + 2022-03-08 17:12:35.997985 @@ -11318,7 +11318,7 @@ td.section { inet_addresses - ascending + unknown @@ -11344,18 +11344,6 @@ td.section { repo_id ascending - - - - - idxovmntef6l45tw2bsfl56tcugx - [non-unique index] - - - - deletion_time - ascending -

 

diff --git a/db/src/main/resources/sql/flyway/V108__add_host_indexes_for_whois.sql b/db/src/main/resources/sql/flyway/V108__add_host_indexes_for_whois.sql index ea6b11f64..8e64a661f 100644 --- a/db/src/main/resources/sql/flyway/V108__add_host_indexes_for_whois.sql +++ b/db/src/main/resources/sql/flyway/V108__add_host_indexes_for_whois.sql @@ -12,6 +12,5 @@ -- See the License for the specific language governing permissions and -- limitations under the License. - -CREATE INDEX IDXovmntef6l45tw2bsfl56tcugx ON "Host" (deletion_time); -CREATE INDEX IDXrc77s1ndiemi2vwwudchye214 ON "Host" (inet_addresses); +CREATE INDEX IF NOT EXISTS IDXrc77s1ndiemi2vwwudchye214 + ON "Host" USING GIN (inet_addresses); diff --git a/db/src/main/resources/sql/schema/nomulus.golden.sql b/db/src/main/resources/sql/schema/nomulus.golden.sql index cabce7686..570f6e536 100644 --- a/db/src/main/resources/sql/schema/nomulus.golden.sql +++ b/db/src/main/resources/sql/schema/nomulus.golden.sql @@ -1854,13 +1854,6 @@ CREATE INDEX idxoqd7n4hbx86hvlgkilq75olas ON public."Contact" USING btree (conta CREATE INDEX idxoqttafcywwdn41um6kwlt0n8b ON public."BillingRecurrence" USING btree (domain_repo_id); --- --- Name: idxovmntef6l45tw2bsfl56tcugx; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX idxovmntef6l45tw2bsfl56tcugx ON public."Host" USING btree (deletion_time); - - -- -- Name: idxp3usbtvk0v1m14i5tdp4xnxgc; Type: INDEX; Schema: public; Owner: - -- @@ -1900,7 +1893,7 @@ CREATE INDEX idxr22ciyccwi9rrqmt1ro0s59qf ON public."Domain" USING btree (tech_c -- Name: idxrc77s1ndiemi2vwwudchye214; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX idxrc77s1ndiemi2vwwudchye214 ON public."Host" USING btree (inet_addresses); +CREATE INDEX idxrc77s1ndiemi2vwwudchye214 ON public."Host" USING gin (inet_addresses); --