Fixed an issue where EXPLAIN and EXPLAIN ANALYZE failed when blank lines separate clauses in the SQL query. (#9875)
getQueryAt now uses the syntax tree as the primary check for whether a blank-line boundary cut through a SQL statement. It is split into two helpers: _findQueryBoundaries (the original scan, parameterized by stopAtBlankLine) and _needsExpansion, which detects when a Statement node straddles the extracted range and re-scans ignoring blank lines. A STATEMENT_STARTERS keyword list guards the case where the parser merges semicolon-less queries into one Statement, and WRAPPER_STARTERS (EXPLAIN, ANALYZE, WITH) force expansion when the Statement extends past the range. Also fixes a Lezer boundary bug (tree.iterate is inclusive at boundaries) with a node.to > startPos check. Adds 21 tests covering EXPLAIN, negative no-merge cases, comments, and boundary edge cases.
A
Ashesh Vashi committed
397be4e70e1a4fa02f1ab853cc00da3e40da9de4
Parent: 0223e8a
Committed by Dave Page <dpage@pgadmin.org>
on 6/9/2026, 2:10:07 PM