Cache Hit Ratio Optimization

infoProactive Health

Poor cache utilization causing repeated expensive data scans and query compilation overhead when cached results could be reused.

Prompt: I'm seeing the same Snowflake queries run multiple times per day but they're always scanning from remote storage instead of using cached results. Help me understand why the result cache isn't being used and how to optimize warehouse cache retention.

Agent Playbook

When an agent encounters this scenario, Schema provides these diagnostic steps automatically.

When investigating Snowflake cache hit ratio issues, start by confirming result cache is enabled, then measure your actual cache hit rates to quantify the problem. Focus on identifying query text variations that prevent cache reuse—even whitespace differences break the cache—then analyze whether underlying data changes are invalidating results prematurely.

1Verify result cache is enabled at session and account level
The first thing to check is whether USE_CACHED_RESULT is actually enabled. Run `SHOW PARAMETERS LIKE 'USE_CACHED_RESULT'` at both session and account level—applications or BI tools may be explicitly disabling it without you realizing. If disabled, enable it with `ALTER SESSION SET USE_CACHED_RESULT = TRUE` to allow Snowflake to return cached results for identical queries within the 24-hour cache window. This is the most common oversight and the easiest fix.
2Measure your actual cache hit rate and identify high-cost repeat queries
Check `snowflake-query-data-scanned-cache-avg` to see what percentage of data is being served from cache versus remote storage—if this is consistently low (<30%), you have a real problem. Cross-reference with `snowflake-billing-warehouse-credits-used` to quantify the cost impact of cache misses. Look for patterns where the same expensive queries run multiple times per day but show zero cache hits—these are your biggest credit-wasting offenders and should be your optimization targets.
3Query QUERY_HISTORY to find identical queries with different text formatting
Use `SELECT QUERY_TEXT, COUNT(*), SUM(TOTAL_ELAPSED_TIME) FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY GROUP BY QUERY_TEXT` to identify queries that appear similar but have minor text variations preventing cache hits. Even a single extra space or different capitalization breaks the cache. Focus on queries with high `snowflake-query-executed` counts and elevated `snowflake-query-compilation-time-avg`—these are being recompiled and re-executed when they should be returning instant cached results.
4Analyze application query generation patterns for consistency
Review your application code, BI dashboards, and ETL scripts to see if they're generating dynamic SQL with varying text instead of using parameterized queries or consistent formatting. Common culprits include timestamp literals embedded in WHERE clauses, random ordering of columns or JOINs, or different comment blocks. Refactor to use identical query text wherever possible—this is especially critical for BI dashboards where multiple users view the same report and should all benefit from a single cache entry.
5Check if frequent data updates are invalidating the cache prematurely
The result cache is automatically invalidated when underlying tables change, so frequent micro-batch updates can prevent cache hits even with identical queries. Query SNOWFLAKE.ACCOUNT_USAGE.TABLE_STORAGE_METRICS or QUERY_HISTORY filtered by query type (INSERT/UPDATE/DELETE/MERGE) to see if your tables are being modified more often than you realize. If data changes every few minutes but your queries run every hour, consider batching updates or using separate reporting tables that refresh less frequently to maximize the 24-hour cache window.

Technologies

Related Insights

Result cache disabled degrades query performance
info
Repeated expensive queries waste credits when result cache is not leveraged
warning
Result cache underutilization increases duplicate compute
info
Query result cache not leveraged for 24-hour reuse window
info
Result Cache provides zero-cost query responses for repeated queries
info
High Eviction Rate Indicates Memory Pressure
warning
When redis.keys.evicted rate increases significantly, Redis is evicting keys to stay within maxmemory limits, potentially causing cache miss storms and degraded application performance as hot data is prematurely evicted.
Expiring Keys Without TTL Monitoring Causes Memory Leaks
warning
When redis.persist count is high relative to redis.db.expires, many keys lack TTLs and will accumulate indefinitely, causing memory growth. redis.keyspace.avg_ttl can indicate if TTL values are too long for workload patterns.
Missing cache for frequently accessed data increases database load
warning
Missing cache invalidation causes stale data to be served to users
warning

Relevant Metrics

Monitoring Interfaces

Snowflake Datadog
Snowflake Native
Snowflake Prometheus
Snowflake OpenTelemetry
Redis Datadog
Redis Prometheus
Redis Native Metrics