Overview
Follow these best practices to build secure, production-ready applications with the SQL API.Prioritize indexed fields for filtering
To maximize query speed, always filter your data using indexed fields. Filtering on non-indexed fields forces full table scans, which are resource-intensive. Key indexed fields for filtering (use these in your WHERE clauses):- Base:
event_signature(prefer overevent_name),address,block_timestamp - Solana transfers:
mint,block_time(andsource_owner/destination_ownerfor wallet filters) - Solana instructions:
executing_account,instruction_name,block_time
Select only necessary fields
Avoid usingSELECT *. Selecting unnecessary fields consumes more RAM and accesses more disk space, which increases the likelihood of your query reaching resource limits.
Leverage caching with maxAgeMs
Developers should take advantage of SQL API’s cache controls when executing high frequency queries. Ensure you’re using the maximum maxAgeMs that your queries can reasonably tolerate. This allows the API to return a cached response, which limits direct database calls.
Separate dev and prod project IDs
Always use a different project ID for your development (dev) and production (prod) integrations. Clear separation ensures that testing and debugging activities do not impact the performance or rate limits of your live production environment.Account for Solana token accounts vs wallets
On Solana, SPL transfers move balances between token accounts, not directly between owner wallets. When you need holder-level activity:- Prefer
source_owner/destination_owneronsolana.transfers - Or resolve owners via
account_ownersonsolana.instructions
mint when tracking a specific token—mint is the leading index for solana.transfers. See Query Solana tokens.