Skip to content

Commit

Permalink
add skip indexes and date partitions
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Feb 27, 2025
1 parent 3fa1ead commit 2229cfa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
33 changes: 31 additions & 2 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ CREATE TABLE IF NOT EXISTS balance_changes (
-- debug --
balance_change_type Int32
)
ENGINE = ReplacingMergeTree PRIMARY KEY (block_num, storage_ordinal)
ENGINE = ReplacingMergeTree
PARTITION BY date
PRIMARY KEY (block_num, storage_ordinal)
ORDER BY (block_num, storage_ordinal);

-- create a bloom-filter index for these high-cardinality string columns
CREATE INDEX idx_balance_changes_contract ON balance_changes (contract) TYPE bloom_filter GRANULARITY 4;
CREATE INDEX idx_balance_changes_owner ON balance_changes (owner) TYPE bloom_filter GRANULARITY 4;

-------------------------------------------------
-- Transfer events --
-------------------------------------------------
Expand Down Expand Up @@ -88,5 +94,28 @@ CREATE TABLE IF NOT EXISTS transfers (
-- debug --
transfer_type Int32
)
ENGINE = ReplacingMergeTree PRIMARY KEY (block_num, log_block_index)
ENGINE = ReplacingMergeTree
PARTITION BY date
PRIMARY KEY (block_num, log_block_index)
ORDER BY (block_num, log_block_index);

-- create a bloom-filter index for these high-cardinality string columns
CREATE INDEX idx_transfers_contract ON transfers (contract) TYPE bloom_filter GRANULARITY 4;
CREATE INDEX idx_transfers_from ON transfers (`from`) TYPE bloom_filter GRANULARITY 4;
CREATE INDEX idx_transfers_to ON transfers (`to`) TYPE bloom_filter GRANULARITY 4;

-- latest balances by account --
CREATE MATERIALIZED VIEW balances
ENGINE = ReplacingMergeTree(version)
ORDER BY (owner, contract)
POPULATE
AS
SELECT * FROM balance_changes;

-- latest balances by account & by date --
CREATE MATERIALIZED VIEW balances_by_date
ENGINE = ReplacingMergeTree(version)
ORDER BY (owner, contract, date)
POPULATE
AS
SELECT * FROM balance_changes;
9 changes: 9 additions & 0 deletions schema.views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ ORDER BY (owner, contract, date)
POPULATE
AS
SELECT * FROM balance_changes;

-- create a bloom-filter index for these high-cardinality string columns
CREATE INDEX idx_balance_changes_contract ON balance_changes (contract) TYPE bloom_filter GRANULARITY 4;
CREATE INDEX idx_balance_changes_owner ON balance_changes (owner) TYPE bloom_filter GRANULARITY 4;

-- create a bloom-filter index for these high-cardinality string columns
CREATE INDEX idx_transfers_contract ON transfers (contract) TYPE bloom_filter GRANULARITY 4;
CREATE INDEX idx_transfers_from ON transfers (`from`) TYPE bloom_filter GRANULARITY 4;
CREATE INDEX idx_transfers_to ON transfers (`to`) TYPE bloom_filter GRANULARITY 4;

0 comments on commit 2229cfa

Please sign in to comment.