This issue has been created
There is 1 update.
 
 
XWiki Platform / cid:jira-generated-image-avatar-bb279727-c7a6-46b0-be36-2ce96e2156b2 XWIKI-25053 Open

Avoid creating a new thread each time JSqlParser parses a HQL query

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-63141f9b-7682-4428-bfaf-af1e9b0f305d Thomas Mortagne created this issue on 29/Sep/26 18:53
 
Summary: Avoid creating a new thread each time JSqlParser parses a HQL query
Issue Type: cid:jira-generated-image-avatar-bb279727-c7a6-46b0-be36-2ce96e2156b2 Improvement
Assignee: Unassigned
Components: Query
Created: 29/Sep/26 18:53
Priority: cid:jira-generated-image-static-major-de5a6a01-a453-48ab-b4df-e15a212a4fdb Major
Reporter: Thomas Mortagne
Description:

Every time JSqlParser parses a query through its default entry points, it creates a new single-thread ExecutorService (so a new thread), runs the parse in it to enforce its timeout (8s by default), and then shuts the executor down. This applies to:

  • CCJSqlParserUtil.parse(String), used by EscapeLikeParametersQuery (the escapeLikeParameters filter), which is applied to every HQL query executed through the Query Manager, and re-parses the statement each time getStatement() is called
  • Validation#validate() (through ParseCapability), used by StandardHQLCompleteStatementValidator each time an HQL query reaches that validator

This has been the case at least since JSqlParser 4.6 (there, it happens inside parseStatement(CCJSqlParser) / parseStatements(CCJSqlParser)), but JSqlParser 4.6 did not offer any way to avoid it. Since JSqlParser 5.x, it is possible to provide the ExecutorService to use: CCJSqlParserUtil.parse(String, ExecutorService, Consumer), CCJSqlParserUtil.parseStatements(CCJSqlParser, ExecutorService), etc.

Possible improvements:

  • parse the statement with a shared (reused) ExecutorService in both places
  • for StandardHQLCompleteStatementValidator, parse the statement itself (with CCJSqlParserUtil.newParser(statement).withConfiguration(...) and the shared executor) and then call the static Validation.validate(Statement, ValidationContext), which only checks the features without parsing again
  • use the same parser configuration in both places
  • avoid parsing the same statement several times in EscapeLikeParametersQuery (e.g. by caching the modified statement)

The actual cost has not been measured yet.

 
 

1 update

 
cid:jira-generated-image-avatar-63141f9b-7682-4428-bfaf-af1e9b0f305d Changes by Thomas Mortagne on 29/Sep/26 18:53
 
Labels: performance