Skip to content

Commit f66f782

Browse files
authored
Partition token_balances (#291)
* Partition token_balances * Index block number * Update schema
1 parent f711248 commit f66f782

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

internal/tools/clickhouse/0002_clickhouse_create_logs_table.sql

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,23 @@ CREATE TABLE IF NOT EXISTS logs (
3737
transaction_index,
3838
log_index
3939
),
40-
PROJECTION chain_topic0_projection
40+
PROJECTION chain_address_block_number_full_projection
41+
(
42+
SELECT
43+
*
44+
ORDER BY
45+
chain_id,
46+
address,
47+
block_number
48+
),
49+
PROJECTION chain_topic0_full_projection
4150
(
4251
SELECT
43-
_part_offset
52+
*
4453
ORDER BY
4554
chain_id,
4655
topic_0,
4756
block_number,
48-
transaction_index,
49-
log_index,
5057
address
5158
),
5259
PROJECTION address_topic0_state_projection

internal/tools/clickhouse/0006_clickhouse_create_token_transfers.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CREATE TABLE IF NOT EXISTS token_transfers
1717
`insert_timestamp` DateTime DEFAULT now(),
1818
`is_deleted` UInt8 DEFAULT 0,
1919

20+
INDEX idx_block_number block_number TYPE minmax GRANULARITY 1,
2021
INDEX idx_block_timestamp block_timestamp TYPE minmax GRANULARITY 1,
2122
INDEX idx_from_address from_address TYPE bloom_filter GRANULARITY 3,
2223
INDEX idx_to_address to_address TYPE bloom_filter GRANULARITY 3,

internal/tools/clickhouse/0008_clickhouse_create_token_balances.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ CREATE TABLE IF NOT EXISTS token_balances
2020
`insert_timestamp` DateTime DEFAULT now(),
2121
`is_deleted` UInt8 DEFAULT 0,
2222

23+
INDEX idx_block_number block_number TYPE minmax GRANULARITY 1,
2324
INDEX idx_block_timestamp block_timestamp TYPE minmax GRANULARITY 1,
2425
INDEX idx_token_address token_address TYPE bloom_filter GRANULARITY 3,
2526
INDEX idx_owner_address owner_address TYPE bloom_filter GRANULARITY 3,
@@ -62,6 +63,6 @@ CREATE TABLE IF NOT EXISTS token_balances
6263
)
6364
)
6465
ENGINE = ReplacingMergeTree(insert_timestamp, is_deleted)
65-
PARTITION BY chain_id
66+
PARTITION BY (chain_id, toStartOfQuarter(block_timestamp))
6667
ORDER BY (chain_id, owner_address, token_address, token_id, block_number, transaction_index, log_index, direction)
6768
SETTINGS index_granularity = 8192, lightweight_mutation_projection_mode = 'rebuild', deduplicate_merge_projection_mode = 'rebuild', allow_part_offset_column_in_projections=1;

0 commit comments

Comments
 (0)