Skip to content

Conversation

@sigfawn
Copy link

@sigfawn sigfawn commented Jan 2, 2026

This PR improves the robustness of the Query Optimizer cache.

1. Cache Invalidation Hardening

  • Problem: The regex used to extract table names for cache invalidation failed on quoted identifiers (e.g., "users") or complex spacing. This meant that UPDATE or DELETE operations might not invalidate the cache, leading to stale data.
  • Fix: Updated regex to handle quotes and added a Safety Fallback: if an execute() (write) operation occurs but no tables can be identified (e.g., complex subquery), the entire cache is cleared to guarantee consistency.

2. Stats Memory Leak

  • Problem: The stats map grew indefinitely with every unique query string. Dynamic queries (e.g., variable IN clauses) could cause OOM.
  • Fix: Capped the stats map size to 1000 entries with LRU-style eviction.

Result: More reliable caching and stable memory usage.

@sigfawn sigfawn closed this by deleting the head repository Jan 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant