-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathclickhouse-schema.sql
More file actions
83 lines (78 loc) · 2.35 KB
/
clickhouse-schema.sql
File metadata and controls
83 lines (78 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
-- Solana Validator Performance History
CREATE TABLE IF NOT EXISTS default.validator_performance (
timestamp DateTime DEFAULT now(),
vote_pubkey String,
node_pubkey String,
activated_stake UInt64,
commission UInt8,
epoch_credits UInt64,
last_vote UInt64,
root_slot UInt64,
skip_rate Float32,
is_delinquent UInt8,
version String DEFAULT ''
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(timestamp)
ORDER BY (timestamp, vote_pubkey);
-- TPS and Network Metrics
CREATE TABLE IF NOT EXISTS default.network_metrics (
timestamp DateTime DEFAULT now(),
slot UInt64,
block_height UInt64,
tps UInt32,
transaction_count UInt64,
total_validators UInt32,
active_validators UInt32,
delinquent_validators UInt32,
total_stake UInt64
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(timestamp)
ORDER BY timestamp;
-- Transaction Activity by Program
CREATE TABLE IF NOT EXISTS default.program_activity (
timestamp DateTime DEFAULT now(),
program_id String,
transaction_count UInt64,
success_rate Float32,
avg_compute_units UInt64
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(timestamp)
ORDER BY (timestamp, program_id);
-- Token Analytics (Pump.fun, etc)
CREATE TABLE IF NOT EXISTS default.token_analytics (
timestamp DateTime DEFAULT now(),
token_mint String,
holder_count UInt32,
market_cap Float64,
liquidity Float64,
volume_24h Float64,
price_change_24h Float32
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(timestamp)
ORDER BY (timestamp, token_mint);
-- Materialized views for fast queries
CREATE MATERIALIZED VIEW IF NOT EXISTS default.validator_performance_hourly
ENGINE = SummingMergeTree()
PARTITION BY toYYYYMM(hour)
ORDER BY (hour, vote_pubkey)
AS SELECT
toStartOfHour(timestamp) as hour,
vote_pubkey,
avg(skip_rate) as avg_skip_rate,
avg(activated_stake) as avg_stake,
avg(commission) as avg_commission,
sum(is_delinquent) as delinquent_count
FROM default.validator_performance
GROUP BY hour, vote_pubkey;
CREATE MATERIALIZED VIEW IF NOT EXISTS default.network_metrics_hourly
ENGINE = SummingMergeTree()
PARTITION BY toYYYYMM(hour)
ORDER BY hour
AS SELECT
toStartOfHour(timestamp) as hour,
avg(tps) as avg_tps,
max(tps) as max_tps,
min(tps) as min_tps,
avg(active_validators) as avg_active_validators
FROM default.network_metrics
GROUP BY hour;