You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "Utkarsh Vashishtha (Jira)" <ji...@apache.org> on 2026/09/22 21:31:00 UTC

[jira] [Commented] (FLINK-40776) PARSE_URL compiles the query-parameter pattern on every row

    [ https://issues.apache.org/jira/browse/FLINK-40776?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18118163#comment-18118163 ] 

Utkarsh Vashishtha commented on FLINK-40776:
--------------------------------------------

The fix is small and committed in the fork we run, I'll create a PR upstream if the ticket can be assigned.

> PARSE_URL compiles the query-parameter pattern on every row
> -----------------------------------------------------------
>
>                 Key: FLINK-40776
>                 URL: https://issues.apache.org/jira/browse/FLINK-40776
>             Project: Flink
>          Issue Type: Improvement
>          Components: Table SQL / Runtime
>            Reporter: Utkarsh Vashishtha
>            Priority: Major
>
> {{SqlFunctionUtils.parseUrl(urlStr, partToExtract, key)}} compiles a new {{Pattern}} on every invocation:
> {code:java}
> Pattern p = Pattern.compile("(&|^)" + Pattern.quote(key) + "=([^&]*)");
> {code}
> The pattern depends only on {{{}key{}}}. The URL parse immediately above already goes through {{{}URL_CACHE{}}}.
> h3. Fix
> Route the pattern through a {{ThreadLocalCache}} keyed on {{{}key{}}}, matching {{URL_CACHE}} in the same class:
> {code:java}
> private static final ThreadLocalCache<String, Pattern> QUERY_PARAM_PATTERN_CACHE =
>         ThreadLocalCache.of(k -> Pattern.compile("(&|^)" + Pattern.quote(k) + "=([^&]*)"));
> {code}
>  
> This fix already runs in our Flink fork and performance benchmarks show an improvement ranging till 4x, depending on key being static (most common / highest improvement) v/s dynamic (dependent on cardinality). 
> Found while investigating per-row regex costs in a production Flink SQL deployment.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)