Postgres: Add an index to account write tables

This index matches exactly the most frequent query type of
SELECT DISTINCT(pubkey) ...
    ORDER BY pubkey, slot DESC, write_version DESC
This commit is contained in:
Christian Kamm 2022-01-20 11:23:02 +01:00
parent cf26557f7d
commit 08b99875c2
2 changed files with 5 additions and 0 deletions

View File

@ -72,6 +72,7 @@ CREATE TABLE account_write (
data BYTEA, data BYTEA,
PRIMARY KEY (pubkey_id, slot, write_version) PRIMARY KEY (pubkey_id, slot, write_version)
); );
CREATE UNIQUE INDEX account_write_searchkey on account_write(pubkey_id, slot DESC, write_version DESC);
-- The table storing slot information -- The table storing slot information
CREATE TABLE slot ( CREATE TABLE slot (
@ -121,6 +122,7 @@ CREATE TABLE mango_account_write (
padding BYTEA, padding BYTEA,
PRIMARY KEY (pubkey_id, slot, write_version) PRIMARY KEY (pubkey_id, slot, write_version)
); );
CREATE UNIQUE INDEX mango_account_write_searchkey on mango_account_write(pubkey_id, slot DESC, write_version DESC);
CREATE TYPE "TokenInfo" AS ( CREATE TYPE "TokenInfo" AS (
@ -177,6 +179,7 @@ CREATE TABLE mango_group_write (
padding BYTEA, padding BYTEA,
PRIMARY KEY (pubkey_id, slot, write_version) PRIMARY KEY (pubkey_id, slot, write_version)
); );
CREATE UNIQUE INDEX mango_group_write_searchkey on mango_group_write(pubkey_id, slot DESC, write_version DESC);
CREATE TYPE "PriceCache" AS ( CREATE TYPE "PriceCache" AS (
price NUMERIC, -- I80F48 price NUMERIC, -- I80F48
@ -207,3 +210,4 @@ CREATE TABLE mango_cache_write (
perp_market_cache "PerpMarketCache"[], perp_market_cache "PerpMarketCache"[],
PRIMARY KEY (pubkey_id, slot, write_version) PRIMARY KEY (pubkey_id, slot, write_version)
); );
CREATE UNIQUE INDEX mango_cache_write_searchkey on mango_cache_write(pubkey_id, slot DESC, write_version DESC);

View File

@ -61,6 +61,7 @@ CREATE TABLE account_write (
data BYTEA, data BYTEA,
PRIMARY KEY (pubkey_id, slot, write_version) PRIMARY KEY (pubkey_id, slot, write_version)
); );
CREATE UNIQUE INDEX account_write_searchkey on account_write(pubkey_id, slot DESC, write_version DESC);
-- The table storing slot information -- The table storing slot information
CREATE TABLE slot ( CREATE TABLE slot (