Skip to content

[BUG] JSQLParser 4.6 : PostgreSQL : CPU burn when parsing certain queries #1792

Closed
@llehtinen

Description

@llehtinen

Always check against the Latest SNAPSHOT of JSQLParser and the Syntax Diagram

Failing SQL Feature:

  • Parenthesis in a query lead to CPU burn - my example has ((( ... ))), add more parenthesis to see significant increase in the time it takes to fail

SQL Example:

  • Valid PostgreSQL query (heavily reduced from a large query with many nested cases):
    -- Simple query which fails fast
    SELECT ('{"obj":{"field": "value"}}'::JSON -> 'obj'::TEXT ->> 'field'::TEXT)
    
    -- Same query nested in a case statement, takes the CPU for a spin
    SELECT
     CASE
        WHEN true
        THEN (SELECT ((('{"obj":{"field": "value"}}'::JSON -> 'obj'::TEXT ->> 'field'::TEXT))))
     END

My notes:

I was trying to narrow down the issue by testing the case statement query like this:

CCJSqlParserUtil.newParser(sql).withAllowComplexParsing(allowComplexParsing).statements();
JSql allowComplexParsing outcome
4.5 false Fails fast
4.5 true Fails after ~10 seconds of 100% CPU
4.6 false Fails after ~20 seconds of 100% CPU
4.6 true Doesn't finish in 3 minutes, CPU stays at 100%

Software Information:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions