From 6baac297c595561e0452ce49f55d11b3a64fd0fd Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sun, 27 Apr 2025 20:47:35 +0300 Subject: [PATCH] Add GIN indexes for attributes which used to search. --- .../metadata/author.ex | 4 + lib/decentralised_book_index/metadata/book.ex | 4 + .../metadata/book_id.ex | 5 + .../metadata/dbi_server.ex | 4 + .../metadata/publisher.ex | 4 + .../20250427175337_add_gin_indexes.exs | 42 ++++ .../repo/authors/20250427175338.json | 158 ++++++++++++ .../repo/book_ids/20250427175338.json | 178 ++++++++++++++ .../repo/books/20250427175338.json | 227 ++++++++++++++++++ .../repo/dbi_servers/20250427175338.json | 90 +++++++ .../repo/publishers/20250427175338.json | 109 +++++++++ 11 files changed, 825 insertions(+) create mode 100644 priv/repo/migrations/20250427175337_add_gin_indexes.exs create mode 100644 priv/resource_snapshots/repo/authors/20250427175338.json create mode 100644 priv/resource_snapshots/repo/book_ids/20250427175338.json create mode 100644 priv/resource_snapshots/repo/books/20250427175338.json create mode 100644 priv/resource_snapshots/repo/dbi_servers/20250427175338.json create mode 100644 priv/resource_snapshots/repo/publishers/20250427175338.json diff --git a/lib/decentralised_book_index/metadata/author.ex b/lib/decentralised_book_index/metadata/author.ex index 8de4973..dc40677 100644 --- a/lib/decentralised_book_index/metadata/author.ex +++ b/lib/decentralised_book_index/metadata/author.ex @@ -16,6 +16,10 @@ defmodule DecentralisedBookIndex.Metadata.Author do postgres do table "authors" repo DecentralisedBookIndex.Repo + + custom_indexes do + index "name gin_trgm_ops", name: "author_name_gin_index", using: "GIN" + end end actions do diff --git a/lib/decentralised_book_index/metadata/book.ex b/lib/decentralised_book_index/metadata/book.ex index 48c25ff..ad72b07 100644 --- a/lib/decentralised_book_index/metadata/book.ex +++ b/lib/decentralised_book_index/metadata/book.ex @@ -16,6 +16,10 @@ defmodule DecentralisedBookIndex.Metadata.Book do postgres do table "books" repo DecentralisedBookIndex.Repo + + custom_indexes do + index "title gin_trgm_ops", name: "book_title_gin_index", using: "GIN" + end end actions do diff --git a/lib/decentralised_book_index/metadata/book_id.ex b/lib/decentralised_book_index/metadata/book_id.ex index 62402f7..e872ee3 100644 --- a/lib/decentralised_book_index/metadata/book_id.ex +++ b/lib/decentralised_book_index/metadata/book_id.ex @@ -19,6 +19,11 @@ defmodule DecentralisedBookIndex.Metadata.BookId do references do reference :book, index?: true, on_delete: :delete end + + custom_indexes do + index "type gin_trgm_ops", name: "book_id_type_gin_index", using: "GIN" + index "bid gin_trgm_ops", name: "book_id_bid_gin_index", using: "GIN" + end end actions do diff --git a/lib/decentralised_book_index/metadata/dbi_server.ex b/lib/decentralised_book_index/metadata/dbi_server.ex index 213b53f..3a2ddb0 100644 --- a/lib/decentralised_book_index/metadata/dbi_server.ex +++ b/lib/decentralised_book_index/metadata/dbi_server.ex @@ -10,6 +10,10 @@ defmodule DecentralisedBookIndex.Metadata.DBIServer do postgres do table "dbi_servers" repo DecentralisedBookIndex.Repo + + custom_indexes do + index "name gin_trgm_ops", name: "server_name_gin_index", using: "GIN" + end end actions do diff --git a/lib/decentralised_book_index/metadata/publisher.ex b/lib/decentralised_book_index/metadata/publisher.ex index bd0f910..aaffc43 100644 --- a/lib/decentralised_book_index/metadata/publisher.ex +++ b/lib/decentralised_book_index/metadata/publisher.ex @@ -16,6 +16,10 @@ defmodule DecentralisedBookIndex.Metadata.Publisher do postgres do table "publishers" repo DecentralisedBookIndex.Repo + + custom_indexes do + index "name gin_trgm_ops", name: "publisher_name_gin_index", using: "GIN" + end end actions do diff --git a/priv/repo/migrations/20250427175337_add_gin_indexes.exs b/priv/repo/migrations/20250427175337_add_gin_indexes.exs new file mode 100644 index 0000000..c6c69b5 --- /dev/null +++ b/priv/repo/migrations/20250427175337_add_gin_indexes.exs @@ -0,0 +1,42 @@ +defmodule DecentralisedBookIndex.Repo.Migrations.AddGinIndexes do + @moduledoc """ + Updates resources based on their most recent snapshots. + + This file was autogenerated with `mix ash_postgres.generate_migrations` + """ + + use Ecto.Migration + + def up do + execute("CREATE EXTENSION IF NOT EXISTS \"pg_trgm\"") + + create index(:publishers, ["name gin_trgm_ops"], + name: "publisher_name_gin_index", + using: "GIN" + ) + + create index(:dbi_servers, ["name gin_trgm_ops"], name: "server_name_gin_index", using: "GIN") + + create index(:books, ["title gin_trgm_ops"], name: "book_title_gin_index", using: "GIN") + + create index(:book_ids, ["bid gin_trgm_ops"], name: "book_id_bid_gin_index", using: "GIN") + + create index(:book_ids, ["type gin_trgm_ops"], name: "book_id_type_gin_index", using: "GIN") + + create index(:authors, ["name gin_trgm_ops"], name: "author_name_gin_index", using: "GIN") + end + + def down do + drop_if_exists index(:authors, ["name gin_trgm_ops"], name: "author_name_gin_index") + + drop_if_exists index(:book_ids, ["type gin_trgm_ops"], name: "book_id_type_gin_index") + + drop_if_exists index(:book_ids, ["bid gin_trgm_ops"], name: "book_id_bid_gin_index") + + drop_if_exists index(:books, ["title gin_trgm_ops"], name: "book_title_gin_index") + + drop_if_exists index(:dbi_servers, ["name gin_trgm_ops"], name: "server_name_gin_index") + + drop_if_exists index(:publishers, ["name gin_trgm_ops"], name: "publisher_name_gin_index") + end +end diff --git a/priv/resource_snapshots/repo/authors/20250427175338.json b/priv/resource_snapshots/repo/authors/20250427175338.json new file mode 100644 index 0000000..1bc7067 --- /dev/null +++ b/priv/resource_snapshots/repo/authors/20250427175338.json @@ -0,0 +1,158 @@ +{ + "attributes": [ + { + "allow_nil?": false, + "default": "fragment(\"gen_random_uuid()\")", + "generated?": false, + "primary_key?": true, + "references": null, + "size": null, + "source": "id", + "type": "uuid" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "name", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "description", + "type": "text" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "avatar_url", + "type": "text" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "inserted_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "updated_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": false, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "name": "authors_dbi_server_id_fkey", + "on_delete": null, + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "dbi_servers" + }, + "size": null, + "source": "dbi_server_id", + "type": "uuid" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": false, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "name": "authors_author_alias_registry_id_fkey", + "on_delete": null, + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "author_alias_registries" + }, + "size": null, + "source": "author_alias_registry_id", + "type": "uuid" + } + ], + "base_filter": null, + "check_constraints": [], + "custom_indexes": [ + { + "all_tenants?": false, + "concurrently": false, + "error_fields": [], + "fields": [ + { + "type": "string", + "value": "name gin_trgm_ops" + } + ], + "include": null, + "message": null, + "name": "author_name_gin_index", + "nulls_distinct": true, + "prefix": null, + "table": null, + "unique": false, + "using": "GIN", + "where": null + } + ], + "custom_statements": [], + "has_create_action": true, + "hash": "0311CECE8C742961C5FE2E08EAA6134CCA256C216369E4FCC6FC520EDC0DBC58", + "identities": [], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.DecentralisedBookIndex.Repo", + "schema": null, + "table": "authors" +} \ No newline at end of file diff --git a/priv/resource_snapshots/repo/book_ids/20250427175338.json b/priv/resource_snapshots/repo/book_ids/20250427175338.json new file mode 100644 index 0000000..2b9cfce --- /dev/null +++ b/priv/resource_snapshots/repo/book_ids/20250427175338.json @@ -0,0 +1,178 @@ +{ + "attributes": [ + { + "allow_nil?": false, + "default": "fragment(\"gen_random_uuid()\")", + "generated?": false, + "primary_key?": true, + "references": null, + "size": null, + "source": "id", + "type": "uuid" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "type", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "bid", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "order", + "type": "bigint" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "inserted_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "updated_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": false, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "name": "book_ids_dbi_server_id_fkey", + "on_delete": null, + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "dbi_servers" + }, + "size": null, + "source": "dbi_server_id", + "type": "uuid" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": true, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "name": "book_ids_book_id_fkey", + "on_delete": "delete", + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "books" + }, + "size": null, + "source": "book_id", + "type": "uuid" + } + ], + "base_filter": null, + "check_constraints": [], + "custom_indexes": [ + { + "all_tenants?": false, + "concurrently": false, + "error_fields": [], + "fields": [ + { + "type": "string", + "value": "type gin_trgm_ops" + } + ], + "include": null, + "message": null, + "name": "book_id_type_gin_index", + "nulls_distinct": true, + "prefix": null, + "table": null, + "unique": false, + "using": "GIN", + "where": null + }, + { + "all_tenants?": false, + "concurrently": false, + "error_fields": [], + "fields": [ + { + "type": "string", + "value": "bid gin_trgm_ops" + } + ], + "include": null, + "message": null, + "name": "book_id_bid_gin_index", + "nulls_distinct": true, + "prefix": null, + "table": null, + "unique": false, + "using": "GIN", + "where": null + } + ], + "custom_statements": [], + "has_create_action": true, + "hash": "7FFBC69CD3871701196C9A4178BB47E64D91BB18BE2652BFBE38FA3F74E53685", + "identities": [], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.DecentralisedBookIndex.Repo", + "schema": null, + "table": "book_ids" +} \ No newline at end of file diff --git a/priv/resource_snapshots/repo/books/20250427175338.json b/priv/resource_snapshots/repo/books/20250427175338.json new file mode 100644 index 0000000..37434a7 --- /dev/null +++ b/priv/resource_snapshots/repo/books/20250427175338.json @@ -0,0 +1,227 @@ +{ + "attributes": [ + { + "allow_nil?": false, + "default": "fragment(\"gen_random_uuid()\")", + "generated?": false, + "primary_key?": true, + "references": null, + "size": null, + "source": "id", + "type": "uuid" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "title", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "description", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "published", + "type": "date" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "language", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "format", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "page_count", + "type": "bigint" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "cover_image_url", + "type": "text" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "inserted_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "updated_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": false, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "name": "books_dbi_server_id_fkey", + "on_delete": null, + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "dbi_servers" + }, + "size": null, + "source": "dbi_server_id", + "type": "uuid" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": false, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "name": "books_book_editions_registry_id_fkey", + "on_delete": null, + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "book_editions_registries" + }, + "size": null, + "source": "book_editions_registry_id", + "type": "uuid" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": false, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "name": "books_publisher_id_fkey", + "on_delete": null, + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "publishers" + }, + "size": null, + "source": "publisher_id", + "type": "uuid" + } + ], + "base_filter": null, + "check_constraints": [], + "custom_indexes": [ + { + "all_tenants?": false, + "concurrently": false, + "error_fields": [], + "fields": [ + { + "type": "string", + "value": "title gin_trgm_ops" + } + ], + "include": null, + "message": null, + "name": "book_title_gin_index", + "nulls_distinct": true, + "prefix": null, + "table": null, + "unique": false, + "using": "GIN", + "where": null + } + ], + "custom_statements": [], + "has_create_action": true, + "hash": "AA67DC03E5D78606517F268BD28B58521F2000DE3BA531FA48363CCD08CE4475", + "identities": [], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.DecentralisedBookIndex.Repo", + "schema": null, + "table": "books" +} \ No newline at end of file diff --git a/priv/resource_snapshots/repo/dbi_servers/20250427175338.json b/priv/resource_snapshots/repo/dbi_servers/20250427175338.json new file mode 100644 index 0000000..14449e8 --- /dev/null +++ b/priv/resource_snapshots/repo/dbi_servers/20250427175338.json @@ -0,0 +1,90 @@ +{ + "attributes": [ + { + "allow_nil?": false, + "default": "fragment(\"gen_random_uuid()\")", + "generated?": false, + "primary_key?": true, + "references": null, + "size": null, + "source": "id", + "type": "uuid" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "name", + "type": "text" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "url", + "type": "text" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "inserted_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "updated_at", + "type": "utc_datetime_usec" + } + ], + "base_filter": null, + "check_constraints": [], + "custom_indexes": [ + { + "all_tenants?": false, + "concurrently": false, + "error_fields": [], + "fields": [ + { + "type": "string", + "value": "name gin_trgm_ops" + } + ], + "include": null, + "message": null, + "name": "server_name_gin_index", + "nulls_distinct": true, + "prefix": null, + "table": null, + "unique": false, + "using": "GIN", + "where": null + } + ], + "custom_statements": [], + "has_create_action": true, + "hash": "A95880DE071D85C4FB7DB67F97B8BAC964D5CE68D2CC06BB52C4C94520B201C5", + "identities": [], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.DecentralisedBookIndex.Repo", + "schema": null, + "table": "dbi_servers" +} \ No newline at end of file diff --git a/priv/resource_snapshots/repo/publishers/20250427175338.json b/priv/resource_snapshots/repo/publishers/20250427175338.json new file mode 100644 index 0000000..27b7f6c --- /dev/null +++ b/priv/resource_snapshots/repo/publishers/20250427175338.json @@ -0,0 +1,109 @@ +{ + "attributes": [ + { + "allow_nil?": false, + "default": "fragment(\"gen_random_uuid()\")", + "generated?": false, + "primary_key?": true, + "references": null, + "size": null, + "source": "id", + "type": "uuid" + }, + { + "allow_nil?": false, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "name", + "type": "text" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "inserted_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": false, + "default": "fragment(\"(now() AT TIME ZONE 'utc')\")", + "generated?": false, + "primary_key?": false, + "references": null, + "size": null, + "source": "updated_at", + "type": "utc_datetime_usec" + }, + { + "allow_nil?": true, + "default": "nil", + "generated?": false, + "primary_key?": false, + "references": { + "deferrable": false, + "destination_attribute": "id", + "destination_attribute_default": null, + "destination_attribute_generated": null, + "index?": false, + "match_type": null, + "match_with": null, + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "name": "publishers_dbi_server_id_fkey", + "on_delete": null, + "on_update": null, + "primary_key?": true, + "schema": "public", + "table": "dbi_servers" + }, + "size": null, + "source": "dbi_server_id", + "type": "uuid" + } + ], + "base_filter": null, + "check_constraints": [], + "custom_indexes": [ + { + "all_tenants?": false, + "concurrently": false, + "error_fields": [], + "fields": [ + { + "type": "string", + "value": "name gin_trgm_ops" + } + ], + "include": null, + "message": null, + "name": "publisher_name_gin_index", + "nulls_distinct": true, + "prefix": null, + "table": null, + "unique": false, + "using": "GIN", + "where": null + } + ], + "custom_statements": [], + "has_create_action": true, + "hash": "750C2F417E5794699546DF9C8734168FE4BB6B062E627CE4C7692F72B54E2A0C", + "identities": [], + "multitenancy": { + "attribute": null, + "global": null, + "strategy": null + }, + "repo": "Elixir.DecentralisedBookIndex.Repo", + "schema": null, + "table": "publishers" +} \ No newline at end of file