From 4b5b8d9c1a186aff2c2b589b291dd4f04df1d543 Mon Sep 17 00:00:00 2001 From: Tolik Zinovyev Date: Tue, 26 Oct 2021 19:39:14 -0400 Subject: [PATCH 1/2] Improve DB indexes for better worst case accounting time. --- idb/postgres/internal/schema/setup_postgres.sql | 12 ++++++------ idb/postgres/internal/schema/setup_postgres_sql.go | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/idb/postgres/internal/schema/setup_postgres.sql b/idb/postgres/internal/schema/setup_postgres.sql index e2646d437..476a22e4d 100644 --- a/idb/postgres/internal/schema/setup_postgres.sql +++ b/idb/postgres/internal/schema/setup_postgres.sql @@ -65,8 +65,8 @@ CREATE TABLE IF NOT EXISTS account_asset ( PRIMARY KEY (addr, assetid) ); --- For account lookup -CREATE INDEX IF NOT EXISTS account_asset_by_addr ON account_asset ( addr ); +-- For lookup up existing assets by account +CREATE INDEX IF NOT EXISTS account_asset_by_addr_partial ON account_asset(addr) WHERE NOT deleted; -- Optional, to make queries of all asset balances fast /v2/assets//balances -- CREATE INDEX CONCURRENTLY IF NOT EXISTS account_asset_asset ON account_asset (assetid, addr ASC); @@ -82,7 +82,7 @@ CREATE TABLE IF NOT EXISTS asset ( ); -- For account lookup -CREATE INDEX IF NOT EXISTS asset_by_creator_addr ON asset ( creator_addr ); +CREATE INDEX IF NOT EXISTS asset_by_creator_addr_deleted ON asset(creator_addr, deleted); -- Includes indexer import state, migration state, special accounts (fee sink and -- rewards pool) and account totals. @@ -103,7 +103,7 @@ CREATE TABLE IF NOT EXISTS app ( ); -- For account lookup -CREATE INDEX IF NOT EXISTS app_by_creator ON app ( creator ); +CREATE INDEX IF NOT EXISTS app_by_creator_deleted ON app(creator, deleted); -- per-account app local state CREATE TABLE IF NOT EXISTS account_app ( @@ -116,5 +116,5 @@ CREATE TABLE IF NOT EXISTS account_app ( PRIMARY KEY (addr, app) ); --- For account lookup -CREATE INDEX IF NOT EXISTS account_app_by_addr ON account_app ( addr ); +-- For looking up existing app local states by account +CREATE INDEX IF NOT EXISTS account_app_by_addr_partial ON account_app(addr) WHERE NOT deleted; diff --git a/idb/postgres/internal/schema/setup_postgres_sql.go b/idb/postgres/internal/schema/setup_postgres_sql.go index e6cb95675..f3d174d6f 100644 --- a/idb/postgres/internal/schema/setup_postgres_sql.go +++ b/idb/postgres/internal/schema/setup_postgres_sql.go @@ -69,8 +69,8 @@ CREATE TABLE IF NOT EXISTS account_asset ( PRIMARY KEY (addr, assetid) ); --- For account lookup -CREATE INDEX IF NOT EXISTS account_asset_by_addr ON account_asset ( addr ); +-- For lookup up existing assets by account +CREATE INDEX IF NOT EXISTS account_asset_by_addr_partial ON account_asset(addr) WHERE NOT deleted; -- Optional, to make queries of all asset balances fast /v2/assets//balances -- CREATE INDEX CONCURRENTLY IF NOT EXISTS account_asset_asset ON account_asset (assetid, addr ASC); @@ -86,7 +86,7 @@ CREATE TABLE IF NOT EXISTS asset ( ); -- For account lookup -CREATE INDEX IF NOT EXISTS asset_by_creator_addr ON asset ( creator_addr ); +CREATE INDEX IF NOT EXISTS asset_by_creator_addr_deleted ON asset(creator_addr, deleted); -- Includes indexer import state, migration state, special accounts (fee sink and -- rewards pool) and account totals. @@ -107,7 +107,7 @@ CREATE TABLE IF NOT EXISTS app ( ); -- For account lookup -CREATE INDEX IF NOT EXISTS app_by_creator ON app ( creator ); +CREATE INDEX IF NOT EXISTS app_by_creator_deleted ON app(creator, deleted); -- per-account app local state CREATE TABLE IF NOT EXISTS account_app ( @@ -120,6 +120,6 @@ CREATE TABLE IF NOT EXISTS account_app ( PRIMARY KEY (addr, app) ); --- For account lookup -CREATE INDEX IF NOT EXISTS account_app_by_addr ON account_app ( addr ); +-- For looking up existing app local states by account +CREATE INDEX IF NOT EXISTS account_app_by_addr_partial ON account_app(addr) WHERE NOT deleted; ` From 8c4eea1f67977a732a411cba826df3d36e7f85a9 Mon Sep 17 00:00:00 2001 From: Tolik Zinovyev Date: Thu, 28 Oct 2021 14:50:19 -0400 Subject: [PATCH 2/2] Trigger CI.