Query editor
withstatic as (select'{{timebox}}' as timebox, date_trunc('{{timebox}}', timestamp '{{period from}}') as period_from, depth['{{timebox}}'] as depth_back_seconds, to_unixtime(next['{{timebox}}']) - to_unixtime(now()) as seconds_left_in_timebox, split('{{blockchain}}', ',') as blockchainsfrom query_3298581)-- fusion txs of the period: dex.trades is read only for these txs, fusion_txs as (select distinctblockchain, tx_hashfrom oneinch.swapswhere trueand tx_success and call_successand mode = 'fusion'and block_time > date_trunc('{{timebox}}', timestamp '{{period from}}')and if(array_position(split('{{blockchain}}', ','), '= all =') > 0, true, array_position(split('{{blockchain}}', ','), blockchain) > 0)), dexes as (selectblockchain, tx_hash, max(amount_usd) as dexes_amount_usdfrom (selectblockchain, tx_hash, token_sold_address, sum(amount_usd) as amount_usdfrom dex.tradesjoin fusion_txs using(blockchain, tx_hash)wheretrue-- use literals, not static: static reads query_3298581, so its values are not known at plan time and the partitions are not prunedand block_month >= cast(date_trunc('month', date_trunc('{{timebox}}', timestamp '{{period from}}')) as date)and block_time > date_trunc('{{timebox}}', timestamp '{{period from}}')and if(array_position(split('{{blockchain}}', ','), '= all =') > 0, true, array_position(split('{{blockchain}}', ','), blockchain) > 0)group by 1, 2, 3)group by 1, 2), fusion as (selectdate_trunc(timebox, block_time) as time, count(*) as fills, count(*) filter(where amount_usd is null) as fills_without_prices, count(distinct order_hash) as orders, count(distinct order_hash) filter(where amount_usd is null) as orders_without_prices, count(distinct order_hash) filter(where order_fills > 1) as orders_filled_in_parts, count(distinct tx_hash) as txs, count(distinct user) as users, count(distinct user) filter(where account_rn = 1) as users_new