@@ -7,33 +7,24 @@ arrayFilter(x -> x != '', {to_address:Array(String)}) AS to_addresses,
77(length(tx_ids) > 0 ) AS has_tx_hash,
88(length(from_addresses) > 0 ) AS has_from,
99(length(to_addresses) > 0 ) AS has_to,
10- {start_time:UInt64} = 1420070400 AS no_start_time,
11- {end_time:UInt64} = 2524608000 AS no_end_time,
12- {start_block:UInt64} = 0 AS no_start_block,
13- {end_block:UInt64} = 9999999999 AS no_end_block,
1410
1511tx_hash_timestamps AS (
1612 SELECT (minute, timestamp )
1713 FROM native_transfer
1814 WHERE has_tx_hash AND tx_hash IN {transaction_id:Array(String)}
1915 GROUP BY minute, timestamp
2016),
17+ /* minute filters */
2118from_minutes AS (
2219 SELECT minute
2320 FROM native_transfer
24- WHERE
25- has_from
26- AND ` from` IN {from_address:Array(String)}
27- AND (no_start_time OR minute >= toRelativeMinuteNum(toDateTime({start_time:UInt64})))
21+ WHERE has_from AND ` from` IN {from_address:Array(String)}
2822 GROUP BY minute
2923),
3024to_minutes AS (
3125 SELECT minute
3226 FROM native_transfer
33- WHERE
34- has_to
35- AND ` to` IN {to_address:Array(String)}
36- AND (no_start_time OR minute >= toRelativeMinuteNum(toDateTime({start_time:UInt64})))
27+ WHERE has_to AND ` to` IN {to_address:Array(String)}
3728 GROUP BY minute
3829)
3930SELECT
@@ -62,18 +53,19 @@ SELECT
6253FROM native_transfer AS t
6354WHERE
6455 /* filter by timestamp and block_num early to reduce data scanned */
65- (no_start_time OR timestamp >= toDateTime({start_time:UInt64}))
66- AND (no_end_time OR timestamp <= toDateTime({end_time:UInt64}))
67- AND (no_start_block OR block_num >= {start_block:UInt64})
68- AND (no_end_block OR block_num <= {end_block:UInt64})
56+ ({start_time:UInt64} = 1420070400 OR timestamp >= toDateTime({start_time:UInt64}))
57+ AND ({end_time:UInt64} = 2524608000 OR timestamp <= toDateTime({end_time:UInt64}))
58+ AND ({start_block:UInt64} = 0 OR block_num >= {start_block:UInt64})
59+ AND ({end_block:UInt64} = 9999999999 OR block_num <= {end_block:UInt64})
60+
61+ /* transaction ID filter */
62+ AND ( NOT has_tx_hash OR (minute, timestamp ) IN tx_hash_timestamps AND tx_hash IN {transaction_id:Array(String)} )
6963
7064 /* timestamp filters */
71- AND (NOT has_tx_hash OR (minute, timestamp ) IN tx_hash_timestamps)
7265 AND (NOT has_from OR minute IN from_minutes)
7366 AND (NOT has_to OR minute IN to_minutes)
7467
7568 /* direct filters */
76- AND (NOT has_tx_hash OR tx_hash IN {transaction_id:Array(String)})
7769 AND (NOT has_from OR ` from` IN {from_address:Array(String)})
7870 AND (NOT has_to OR ` to` IN {to_address:Array(String)})
7971ORDER BY minute DESC , timestamp DESC , block_num DESC , tx_index DESC
0 commit comments