From ea3c6b947852afac2c3eaed025841aa281a059cc Mon Sep 17 00:00:00 2001 From: Ragot Geoffrey Date: Thu, 19 Dec 2024 16:37:35 +0100 Subject: [PATCH] fix: too many indexes and missing indexes (#621) --- docker-compose.yml | 2 +- internal/storage/bucket/default_bucket.go | 56 ------------------- .../24-accounts-metadata-index/notes.yaml | 1 + .../24-accounts-metadata-index/up.sql | 1 + 4 files changed, 3 insertions(+), 57 deletions(-) create mode 100644 internal/storage/bucket/migrations/24-accounts-metadata-index/notes.yaml create mode 100644 internal/storage/bucket/migrations/24-accounts-metadata-index/up.sql diff --git a/docker-compose.yml b/docker-compose.yml index 40a521713..ab044c1c0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -43,7 +43,7 @@ services: - "16686:16686/tcp" ledger: - image: golang:1.22-alpine + image: golang:1.23-alpine entrypoint: go run main.go serve volumes: - .:/src diff --git a/internal/storage/bucket/default_bucket.go b/internal/storage/bucket/default_bucket.go index 1b9fb8233..13e3ca8af 100644 --- a/internal/storage/bucket/default_bucket.go +++ b/internal/storage/bucket/default_bucket.go @@ -117,12 +117,6 @@ var ledgerSetups = []ledgerSetup{ ), 1)::bigint, false); `, }, - { - requireFeatures: features.FeatureSet{ - features.FeatureMovesHistoryPostCommitEffectiveVolumes: "SYNC", - }, - script: `create index "pcev_{{.ID}}" on "{{.Bucket}}".moves (accounts_address, asset, effective_date desc) where ledger = '{{.Name}}';`, - }, { requireFeatures: features.FeatureSet{ features.FeatureMovesHistoryPostCommitEffectiveVolumes: "SYNC", @@ -228,22 +222,6 @@ var ledgerSetups = []ledgerSetup{ execute procedure "{{.Bucket}}".insert_transaction_metadata_history(); `, }, - { - requireFeatures: features.FeatureSet{ - features.FeatureIndexTransactionAccounts: "SYNC", - }, - script: ` - create index "transactions_sources_{{.ID}}" on "{{.Bucket}}".transactions using gin (sources jsonb_path_ops) where ledger = '{{.Name}}'; - `, - }, - { - requireFeatures: features.FeatureSet{ - features.FeatureIndexTransactionAccounts: "ON", - }, - script: ` - create index "transactions_destinations_{{.ID}}" on "{{.Bucket}}".transactions using gin (destinations jsonb_path_ops) where ledger = '{{.Name}}'; - `, - }, { requireFeatures: features.FeatureSet{ features.FeatureIndexTransactionAccounts: "ON", @@ -259,22 +237,6 @@ var ledgerSetups = []ledgerSetup{ execute procedure "{{.Bucket}}".set_transaction_addresses(); `, }, - { - requireFeatures: features.FeatureSet{ - features.FeatureIndexAddressSegments: "ON", - }, - script: ` - create index "accounts_address_array_{{.ID}}" on "{{.Bucket}}".accounts using gin (address_array jsonb_ops) where ledger = '{{.Name}}'; - `, - }, - { - requireFeatures: features.FeatureSet{ - features.FeatureIndexAddressSegments: "ON", - }, - script: ` - create index "accounts_address_array_length_{{.ID}}" on "{{.Bucket}}".accounts (jsonb_array_length(address_array)) where ledger = '{{.Name}}'; - `, - }, { requireFeatures: features.FeatureSet{ features.FeatureIndexAddressSegments: "ON", @@ -290,24 +252,6 @@ var ledgerSetups = []ledgerSetup{ execute procedure "{{.Bucket}}".set_address_array_for_account(); `, }, - { - requireFeatures: features.FeatureSet{ - features.FeatureIndexAddressSegments: "ON", - features.FeatureIndexTransactionAccounts: "ON", - }, - script: ` - create index "transactions_sources_arrays_{{.ID}}" on "{{.Bucket}}".transactions using gin (sources_arrays jsonb_path_ops) where ledger = '{{.Name}}'; - `, - }, - { - requireFeatures: features.FeatureSet{ - features.FeatureIndexAddressSegments: "ON", - features.FeatureIndexTransactionAccounts: "ON", - }, - script: ` - create index "transactions_destinations_arrays_{{.ID}}" on "{{.Bucket}}".transactions using gin (destinations_arrays jsonb_path_ops) where ledger = '{{.Name}}'; - `, - }, { requireFeatures: features.FeatureSet{ features.FeatureIndexAddressSegments: "ON", diff --git a/internal/storage/bucket/migrations/24-accounts-metadata-index/notes.yaml b/internal/storage/bucket/migrations/24-accounts-metadata-index/notes.yaml new file mode 100644 index 000000000..621ded983 --- /dev/null +++ b/internal/storage/bucket/migrations/24-accounts-metadata-index/notes.yaml @@ -0,0 +1 @@ +name: Create accounts metadata index concurrently diff --git a/internal/storage/bucket/migrations/24-accounts-metadata-index/up.sql b/internal/storage/bucket/migrations/24-accounts-metadata-index/up.sql new file mode 100644 index 000000000..a8fa79bb1 --- /dev/null +++ b/internal/storage/bucket/migrations/24-accounts-metadata-index/up.sql @@ -0,0 +1 @@ +create index concurrently accounts_metadata_idx on "{{.Schema}}".accounts using gin(metadata JSONB_PATH_OPS); \ No newline at end of file