matanper commented on issue #69916:
URL: https://github.com/apache/doris/issues/69916#issuecomment-6555423780

   **Update.** We have run a fix in production. Two additions to the proposal 
above.
   
   **1. Share compiled databases across queries, not only across clones.** Even 
after compiling once per fragment, every fragment instance of every query still 
compiles its constant LIKE/REGEXP pattern again. Some patterns take seconds to 
compile, and scheduled queries repeat the same patterns. A per-BE cache of 
compiled Hyperscan databases, keyed by expression, removes that:
   - Flags and mode are fixed, so the expression alone is the key.
   - A compiled database is read-only, so all users share it and each allocates 
only its own scratch.
   - Concurrent misses on one expression wait for a single compile.
   - Eviction is LRU, with a mutable byte cap.
   - `regexp_fn`, used when the pattern is constant within a block, uses the 
cache too.
   - RE2 and Boost fallbacks stay per state, uncached, because RE2 locks its 
DFA cache on every search.
   
   The cache complements #66788. #66788 routes quantifiers above 50 to RE2; 
everything that stays on Hyperscan, including other compile-heavy shapes, now 
compiles once per BE.
   
   **2. A trap when caching failed compiles.** A cache that keeps patterns 
Hyperscan rejects, so they go straight to the RE2 fallback, has to tell 
rejections apart from transient failures. hyperscan 5.4.2 and vectorscan 5.4.11 
report "Unable to allocate memory.", "Internal error." and "Allocator returned 
misaligned memory." with `expression == 0`, despite `hs_compile.h` saying they 
are negative. So `expression >= 0` is not enough on its own; those three 
messages have to be retried, not cached.
   
   **Result:** a bounded-repeat `(?i)` pattern that takes ~14.8 s to compile 
drops to ~30 ms on every later run on the same BE. Happy to open a PR with both 
parts.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to