From 469cf3d7ba3865efdb48ddd76e6a5b16a4d58a17 Mon Sep 17 00:00:00 2001 From: Warren He Date: Fri, 23 Jun 2023 17:05:20 -0700 Subject: [PATCH 1/2] storage: add chain.evm_tokens name indexes --- storage/migrations/08_evm_tokens_name_index.up.sql | 10 ++++++++++ storage/postgres/client.go | 2 ++ 2 files changed, 12 insertions(+) create mode 100644 storage/migrations/08_evm_tokens_name_index.up.sql diff --git a/storage/migrations/08_evm_tokens_name_index.up.sql b/storage/migrations/08_evm_tokens_name_index.up.sql new file mode 100644 index 000000000..3fb9c1503 --- /dev/null +++ b/storage/migrations/08_evm_tokens_name_index.up.sql @@ -0,0 +1,10 @@ +-- Add indexes for evm_tokens token names and symbols for search. + +BEGIN; + +CREATE EXTENSION pg_trgm; + +CREATE INDEX ix_evm_tokens_name ON chain.evm_tokens USING GIST (token_name gist_trgm_ops); +CREATE INDEX ix_evm_tokens_symbol ON chain.evm_tokens USING GIST (symbol gist_trgm_ops); + +COMMIT; diff --git a/storage/postgres/client.go b/storage/postgres/client.go index 8a51dded6..efdc9aa03 100644 --- a/storage/postgres/client.go +++ b/storage/postgres/client.go @@ -322,6 +322,7 @@ func (c *Client) Wipe(ctx context.Context) error { // List, then drop all custom types. // Query from https://stackoverflow.com/questions/3660787/how-to-list-custom-types-using-postgres-information-schema + // TODO: Don't delete extensions' types. types, err := c.listNexusTypes(ctx) if err != nil { return err @@ -334,6 +335,7 @@ func (c *Client) Wipe(ctx context.Context) error { } // List, then drop all custom functions. + // TODO: Don't delete extensions' functions. functions, err := c.listNexusFunctions(ctx) if err != nil { return err From 239435670c2639eef603088f9ca34849a191dcd6 Mon Sep 17 00:00:00 2001 From: Warren He Date: Tue, 27 Jun 2023 14:28:27 -0700 Subject: [PATCH 2/2] storage: drop pg_trgm on wipe --- storage/postgres/client.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/storage/postgres/client.go b/storage/postgres/client.go index efdc9aa03..3a251ef2b 100644 --- a/storage/postgres/client.go +++ b/storage/postgres/client.go @@ -309,6 +309,10 @@ func (c *Client) listNexusMaterializedViews(ctx context.Context) ([]string, erro // Wipe removes all contents of the database. func (c *Client) Wipe(ctx context.Context) error { + if _, err := c.pool.Exec(ctx, "DROP EXTENSION IF EXISTS pg_trgm CASCADE;"); err != nil { + return err + } + tables, err := c.listNexusTables(ctx) if err != nil { return err