Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve DB indexes for better worst case accounting time #760

Merged
merged 3 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions idb/postgres/internal/schema/setup_postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a non-partial index on addr - the primary key.


-- Optional, to make queries of all asset balances fast /v2/assets/<assetid>/balances
-- CREATE INDEX CONCURRENTLY IF NOT EXISTS account_asset_asset ON account_asset (assetid, addr ASC);
Expand All @@ -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.
Expand All @@ -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 (
Expand All @@ -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;
12 changes: 6 additions & 6 deletions idb/postgres/internal/schema/setup_postgres_sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.