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.
This commit is contained in:
Weimin Yu 2022-03-08 14:22:01 -05:00 committed by GitHub
parent 30c3a51b8d
commit c1ba725d3d
4 changed files with 298 additions and 331 deletions

File diff suppressed because it is too large Load diff

View file

@ -261,7 +261,7 @@ td.section {
</tr>
<tr>
<td class="property_name">generated on</td>
<td class="property_value">2022-03-07 19:59:39.894792</td>
<td class="property_value">2022-03-08 17:12:35.997985</td>
</tr>
<tr>
<td class="property_name">last flyway file</td>
@ -284,7 +284,7 @@ td.section {
generated on
</text>
<text text-anchor="start" x="4755.52" y="-10.8" font-family="Helvetica,sans-Serif" font-size="14.00">
2022-03-07 19:59:39.894792
2022-03-08 17:12:35.997985
</text>
<polygon fill="none" stroke="#888888" points="4668.02,-4 4668.02,-44 4933.02,-44 4933.02,-4 4668.02,-4" /> <!-- allocationtoken_a08ccbef -->
<g id="node1" class="node">
@ -11318,7 +11318,7 @@ td.section {
<tr>
<td class="spacer"></td>
<td class="minwidth">inet_addresses</td>
<td class="minwidth">ascending</td>
<td class="minwidth">unknown</td>
</tr>
<tr>
<td colspan="3"></td>
@ -11344,18 +11344,6 @@ td.section {
<td class="minwidth">repo_id</td>
<td class="minwidth">ascending</td>
</tr>
<tr>
<td colspan="3"></td>
</tr>
<tr>
<td colspan="2" class="name">idxovmntef6l45tw2bsfl56tcugx</td>
<td class="description right">[non-unique index]</td>
</tr>
<tr>
<td class="spacer"></td>
<td class="minwidth">deletion_time</td>
<td class="minwidth">ascending</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>

View file

@ -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);

View file

@ -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);
--