Upgrade ParserSQL to v1.1.0, fix SET LOCAL tracking, and preserve digest fallback
Upgrade vendored ParserSQL to v1.1.0, fix MySQL SET LOCAL session tracking, and preserve query digests when ParserSQL cannot fully parse a statement. This PR incorporates all changes from #6403; review and CI continue here as a single PR.
Behavior
- Treat MySQL
LOCALasSESSIONfor supported tracked-variable assignments in the dispatch path and legacy SET parsers.SET LOCAL innodb_lock_wait_timeout=5no longer unnecessarily locks the frontend to a hostgroup and causes error 9006 after routing elsewhere. - Validate every assignment scope before ParserSQL session tracking changes state. Mixed GLOBAL/PERSIST/user-variable targets, malformed assignments and conflicting scopes forward the complete original statement instead of being accepted as local state.
- Use complete successful ASTs for digest normalization. Failed/incomplete parsing, missing ASTs and unavailable emitter output fall back to ProxySQL's existing dialect tokenizer on the original SQL, independently of ParserSQL's AST arena limits. Preserve tokenizer settings, length limits and first-comment metadata.
- Require actual digest metadata for digest-constrained query rules, including negated regexes. Unsupported ALTER statements cannot accidentally match SELECT-only digest rules because their digest is absent.
- Exclude PostgreSQL's final wire NUL from digest normalization. For PostgreSQL SET extraction, also reject embedded/multiple NULs while preserving the existing single-trailing-comma compatibility.
- Fix standalone digest-test ownership for inline buffers and align user-variable rejection expectations with v1.1.0's charset/COLLATE grammar support.
ParserSQL v1.1.0 adds broader PostgreSQL/MySQL grammar, structured transaction starts, AST traversal/transformation/parameterization APIs, large IN-list improvements, and source-span/canonicalization fixes. It includes the PostgreSQL SET regression fix.
Dependency provenance
- Exact upstream tag: v1.1.0, commit
a123f6e94dff79f0823909401cc7a3ef4eff9e56. - Archive:
git archive --format=tar.gz --prefix=ParserSQL-1.1.0/ v1.1.0. - SHA-256:
2d14704f15f94ce707e6349e77a1f34dc99349c83831d7038dc4adda3ca29c66. - Archive and symlink replace v1.0.11 with no local patches to the vendored parser.
Validation of the combined changes
- Full
PROXYSQL31=1 make -j8 debugbuild passed. - Full isolated unit group: 104/104 test programs passed, including 232 parser assertions and 110 digest fallback/rule assertions.
- Standalone SET suites: 236, 234, and 517 assertions passed.
- Isolated MySQL 8.4 regressions: 261/261 SET LOCAL assertions across four parser configurations, and 5/5 digest-rule assertions with tokenizer and ParserSQL modes.
groups.jsonformat lint andgit diff --checkpassed.- CI, including sanitizer and platform jobs, must validate the consolidated head. MariaDB was not run locally.
Compatibility
Complete-AST digest normalization remains as implemented by ParserSQL; fallback formatting follows the legacy tokenizer. AST-based digest text/hashes can change as grammar and canonicalization improve, so persisted digest-based rules should be reviewed during adoption. Parsing support does not imply query-engine execution support or complete dialect coverage. PostgreSQL SET scope semantics are unchanged. No benchmark artifacts are included.
Fixes #6397.
Summary by cubic
Upgrades the vendored ParserSQL from v1.0.11 to the unmodified upstream v1.1.0 and merges the SET LOCAL session‑tracking fix (#6403) and the digest‑fallback fix (#6405) into a single release.
AST‑based digests now use complete‑AST normalization only; on grammar errors, partial parses, missing ASTs, or arena exhaustion they fall back to ProxySQL’s dialect tokenizer on the original SQL, preserving configured options, length/hash limits, and first‑comment metadata. Digest‑constrained rules no longer match when their digest metadata is absent — including negated regexes — and the PostgreSQL wire terminator is stripped from digest normalization and SET parsing.
MySQL SET LOCAL is now treated as a session‑scope assignment for tracked variables; mixed GLOBAL/PERSIST/user‑variable targets are forwarded whole instead of partially staged. The upgrade also rejects expression‑valued PostgreSQL generic SET assignments and excludes charset introducer/COLLATE expressions from user‑variable replay.
Migration
- AST‑based digest text and hashes can change as grammar and canonicalization improve; review persisted digest‑based rules during adoption.
- Parsing support doesn’t imply query‑engine execution support or complete dialect coverage.
Validation: full unit group (104 programs, 232 parser and 110 digest‑fallback assertions), live MySQL 8.4 regressions (261 SET LOCAL, 5 digest‑rule), and isolated parser suites (236/234/517 assertions) all pass.
Summary by CodeRabbit
- New Features
- Expanded PostgreSQL and MySQL SQL parsing support, including syntax-tree traversal, cloning, replacement, and parameterization.
- Improved handling of large
INlists and preservation of source positions during SQL canonicalization. - Supports MySQL
SET LOCALas a session-scope assignment. - Uses tokenizer-based normalization when SQL cannot be fully parsed, where tokens are present.
- Bug Fixes
- Rejects expression-valued PostgreSQL
SETassignments, including malformedsearch_pathvalues. - Handles a single trailing PostgreSQL protocol NUL while rejecting embedded or repeated NUL bytes.
- Digest-based query rules no longer match when required digest information is missing.
- Rejects expression-valued PostgreSQL
- Documentation
- Notes potential digest changes and the limits of parsing support. Persisted digest-based rules should be reviewed.