Skip to content

Commit c63ec2f

Browse files
feat(solana): add executing_account_prefix predicates for instruction_calls partition pruning (#9674)
* feat(solana): add executing_account_prefix predicates for instruction_calls partition pruning solana.instruction_calls is partitioned by (year, month, executing_account_prefix) where executing_account_prefix = substring(executing_account, 1, 2). With Base58, that's 12 * 58^2 = ~40k partitions/year. Trino 479 cannot derive prefix predicates from full-address predicates (trinodb/trino#19455), so the partition column is not used unless we filter on it explicitly. Spellbook models all filter on the full executing_account, never on the prefix, so partition enumeration dominates planning time and pushes complex models over the 600s query.max-planning-time ceiling. Adding 'AND executing_account_prefix = ''XX''' alongside the existing executing_account literal predicate gives Trino a constant partition predicate at plan time, cutting splits-generation by ~60%. Mirrors the account_activity fix in #9670. Towards DWH-642 * feat(solana): extend executing_account_prefix predicate to amm staging macro and opensea Adds the prefix predicate to: - solana_amm_stg_raw_swaps macro -- one line that propagates to 14 DEX staging callers (alphaq, aquifer, aquifer_v2, bisonfi, byreal, goonfi, goonfi_v2, manifest, obric, scorch, solfi_v2, tessera, whalestreet, zerofi). The macro takes program_id as an argument so '{{ program_id[:2] }}' derives the prefix at compile time from each caller's literal. - opensea_solana_token_trades (daily_spellbook) -- MemoSq4gqA... program with prefix 'Me'. Same Jinja slice pattern as the per-model fixes in e2c5371 and the account_activity fix in #9670. With the prior commit this covers all literal-predicate readers of solana.instruction_calls in the spellbook project. Towards DWH-642 --------- Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com>
1 parent ccc96b6 commit c63ec2f

13 files changed

Lines changed: 18 additions & 0 deletions

File tree

dbt_subprojects/daily_spellbook/models/_projects/opensea/solana/opensea_solana_token_trades.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ WITH opensea_tx_ids AS (
1414
SELECT DISTINCT(tx_id) AS tx_id
1515
FROM {{ source('solana', 'instruction_calls') }}
1616
WHERE CONTAINS(log_messages, 'Program log: Memo (len 8): "865d8597"')
17+
AND executing_account_prefix = 'Me'
1718
AND executing_account = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'
1819
AND block_time > TRY_CAST('2025-05-26 00:00' AS TIMESTAMP)
1920
{% if is_incremental() %}

dbt_subprojects/solana/macros/_sector/dex/solana_amm_stg_raw_swaps.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ WITH swaps AS (
2727
) }} AS surrogate_key
2828
FROM {{ source('solana', 'instruction_calls') }}
2929
WHERE 1=1
30+
AND executing_account_prefix = '{{ program_id[:2] }}'
3031
AND executing_account = '{{ program_id }}'
3132
AND tx_success = true
3233
AND {{ discriminator_filter }}

dbt_subprojects/solana/models/_sector/dex/humidifi/humidifi_solana_stg_raw_swaps.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ WITH swaps AS (
3636
FROM {{ source('solana', 'instruction_calls') }}
3737
WHERE 1=1
3838
AND executing_account = '9H6tua7jkLhdm3w8BvgpTn5LZNU7g4ZynDmCiNN3q6Rp'
39+
AND executing_account_prefix = '9H'
3940
AND tx_success = true
4041
AND cardinality(account_arguments) > 8
4142
{% if is_incremental() -%}

dbt_subprojects/solana/models/_sector/dex/orca_whirlpool/orca_whirlpool_v2_stg_swaps.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ FROM (
273273
AND ((sp.call_is_inner = false AND memo.inner_instruction_index = 1)
274274
OR (sp.call_is_inner = true AND memo.inner_instruction_index = sp.call_inner_instruction_index + 1))
275275
AND memo.executing_account = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'
276+
AND memo.executing_account_prefix = 'Me'
276277
{% if is_incremental() -%}
277278
AND {{ incremental_predicate('memo.block_time') }}
278279
{% else -%}

dbt_subprojects/solana/models/_sector/dex/phantom_swapper/phantom_swapper_solana_fee_addresses.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ FROM (
2727
, account_arguments[4] AS referraltokenaccount
2828
FROM {{ source('solana','instruction_calls') }}
2929
WHERE executing_account = 'REFER4ZgmyYx9c6He5XfaTMiGfdLwRnkV4RPp9t9iF3'
30+
AND executing_account_prefix = 'RE'
3031
AND account_arguments[2] = '45ruCyfdRkWpRNGEqWzjCiXRHkZs8WXCLQ67Pnpye7Hp'
3132
AND TRY_CAST(data AS VARCHAR) like '%7d12465f%'
3233
AND block_time >= TIMESTAMP '2023-11-30' -- First date phantom ReferralTokenAccount created

dbt_subprojects/solana/models/_sector/dex/pumpdotfun/solana/pumpdotfun_solana_base_trades.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ with
2222
, account_arguments[4] as bonding_curve_vault
2323
FROM {{ source('solana','instruction_calls') }}
2424
WHERE executing_account = '6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P'
25+
AND executing_account_prefix = '6E'
2526
AND bytearray_substring(data,1,8) = 0x181ec828051c0777 --Create https://solscan.io/tx/2Vfq4gS9nq2jvpmZSxVXJ3uHGeheENXetwUus6KnhBzFu23Brqbt5EoNiTLds6jr72yZYGJ9YbMDG1BYKMRe3hSQ
2627
and tx_success = true
2728
{% if is_incremental() %}
@@ -52,6 +53,7 @@ with
5253
, outer_executing_account
5354
FROM {{ source('solana','instruction_calls') }}
5455
WHERE executing_account = '6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P'
56+
AND executing_account_prefix = '6E'
5557
AND bytearray_substring(data,1,16) = 0xe445a52e51cb9a1dbddb7fd34ee661ee --SwapEvent
5658
and tx_success = true
5759
{% if is_incremental() %}

dbt_subprojects/solana/models/_sector/dex/pumpswap/pumpswap_solana_pools.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ WITH pool_creation AS (
2626
FROM {{ source('solana','instruction_calls') }}
2727
WHERE varbinary_starts_with(data, 0xe445a52e51cb9a1db1310cd2a076a774)
2828
AND executing_account = 'pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA'
29+
AND executing_account_prefix = 'pA'
2930
AND tx_success = true
3031
{% if is_incremental() %}
3132
AND {{incremental_predicate('block_time')}}

dbt_subprojects/solana/models/_sector/dex/sanctum_router/sanctum_router_base_trades.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ token_amounts AS (
163163
AND ic.block_slot = b.block_slot
164164
WHERE 1=1
165165
AND ic.executing_account = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
166+
AND ic.executing_account_prefix = 'To'
166167
AND (
167168
(b.amount_type = 'mintTo' AND bytearray_substring(ic.data, 1, 1) = 0x07 AND ELEMENT_AT(ic.account_arguments, 1) = b.token_bought_mint_address)
168169
OR

dbt_subprojects/solana/models/_sector/gas/gas_solana_compute_limit.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ SELECT
2424
) as compute_limit
2525
FROM {{ source('solana', 'instruction_calls') }}
2626
WHERE executing_account = 'ComputeBudget111111111111111111111111111111'
27+
AND executing_account_prefix = 'Co'
2728
AND bytearray_substring(data,1,1) = 0x02
2829
AND inner_instruction_index is null
2930
{% if is_incremental() %}

dbt_subprojects/solana/models/_sector/gas/gas_solana_compute_unit_price.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ SELECT
2424
) AS compute_unit_price
2525
FROM {{ source('solana', 'instruction_calls') }}
2626
WHERE executing_account = 'ComputeBudget111111111111111111111111111111'
27+
AND executing_account_prefix = 'Co'
2728
AND bytearray_substring(data,1,1) = 0x03
2829
AND inner_instruction_index is null
2930
{% if is_incremental() %}

0 commit comments

Comments
 (0)