JSqlParser
JSqlParser copied to clipboard
Postgres EXPLAIN parsing incorrect and missing new flags
Describe the bug
Hello! Just filing this to let you know of the current issues with the EXPLAIN statement parsing since it looks like it was implemented slightly wrong (brackets missing for all options exception analyze and verbose, parses boolean options when not using brackets) and a few features missing(using 0 and 1 for false and true, new Postgres options, text format)
Queries that should parse and work as expected:
EXPLAIN SELECT 1EXPLAIN ANALYZE SELECT 1EXPLAIN VERBOSE SELECT 1EXPLAIN ANALYZE VERBOSE SELECT 1
Queries that should not parse (that currently do not parse as expected):
EXPLAIN () SELECT 1
Queries that should not parse (that currently parse):
- [ ]
EXPLAIN ANALYZE TRUE SELECT 1 - [ ]
EXPLAIN VERBOSE TRUE SELECT 1 - [ ]
EXPLAIN BUFFERS SELECT 1 - [ ]
EXPLAIN COSTS SELECT 1 - [ ]
EXPLAIN FORMAT XML SELECT 1 - [ ]
EXPLAIN FORMAT JSON SELECT 1 - [ ]
EXPLAIN FORMAT YAML SELECT 1
Queries that should parse and do not currently work (bugs):
- [ ]
-- Postgres 9.1 EXPLAIN (ANALYZE, VERBOSE, COSTS, BUFFERS) SELECT 1 - [ ]
-- Postgres 9.1 with boolean options EXPLAIN (ANALYZE TRUE, VERBOSE ON, COSTS OFF, BUFFERS FALSE) SELECT 1
Queries that should parse and do not currently work (new features):
- [ ]
-- text format EXPLAIN (FORMAT TEXT) SELECT 1 - [ ]
-- using 1 for true EXPLAIN (ANALYZE 1) SELECT 1 - [ ]
-- using 0 for false EXPLAIN (ANALYZE 0) SELECT 1 - [ ]
-- Postgres 9.2 (also has boolean option) EXPLAIN (ANALYZE, TIMING) SELECT 1 - [ ]
-- Postgres 10 (also has boolean option) EXPLAIN (SUMMARY) SELECT 1 - [ ]
-- Postgres 12 (also has boolean option) EXPLAIN (SETTINGS) SELECT 1 - [ ]
-- Postgres 13 (also has boolean option) EXPLAIN (ANALYZE, WAL) SELECT 1
To Reproduce Steps to reproduce the behaviour:
- Try to parse queries above
Expected behaviour The queries to be parsed
System
- Database you are using Postgres
- Java Version 15
- JSqlParser version 4.2
Extra notes:
// JSqlParser has incorrect syntax for PostgreSQL EXPLAIN options.
// Correct behaviour:
// https://www.postgresql.org/docs/current/sql-explain.html
// https://www.postgresql.org/docs/current/using-explain.html#USING-EXPLAIN-ANALYZE
// https://github.com/postgres/postgres/blob/b0f7425ec2445678f32381de8bd3174d3cc2167e/src/backend/parser/gram.y#L10887-L10918
@SerialVelocity Wow. This was included over a year ago. Strange that til now nobody complained. You are right, the implementation is wrong.