Problem
ProxySQL's regex-based SET parser (MySQL_Set_Stmt_Parser::parse1v2()) returns an empty map for syntactically invalid SET statements. This signals to ProxySQL that the statement is unparseable, causing it to forward the SET verbatim to the backend.
ParserSQL's SetParser is more lenient — it partially parses invalid statements and produces a non-empty result instead of failing. This causes ProxySQL to attempt to process variables that came from malformed SQL.
Failing test cases
These should all produce an empty map but instead produce partial results:
SET sql_mode='TRADITIONAL' , whatever
Expected: {} (syntax error: trailing "whatever" with no assignment)
Got: {"sql_mode": ["TRADITIONAL"], "whatever": [""]}
SET sql_mode='TRADITIONAL' , whatever =
Expected: {} (syntax error: empty value after =)
Got: {"sql_mode": ["TRADITIONAL"], "whatever": [""]}
SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION')), time_zone = '+00:00', NAMES utf8mb4 COLLATE utf8mb4_unicode_ci
Expected: 3 entries (this one actually works, but mismatched — subquery handling)
SET sql_mode=(SELECT CONCA(@@sql_mode, '...')) -- misspelled function
Expected: {}
Got: {"sql_mode": [...]}
SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT[,NO_ENGINE_SUBSTITUTION')) -- unmatched bracket
Expected: {}
Got: {"sql_mode": [...]}
SET sql_mode=(SELCT CONCAT(@@sql_mode, '...')) -- misspelled SELECT
Expected: {}
Got: {"sql_mode": [...]}
SET sql_mode='TRADITIONAL' , whatever = , autocommit=1 -- empty assignment
Expected: {}
Got: partial results
Suggested approach
The SetParser should validate that the entire input was consumed after parsing. If there are remaining unconsumed tokens after the SET statement, return ParseResult::ERROR or an empty AST. This matches the "parse everything or nothing" contract that the regex parser provides.
Context
Discovered during integration testing into ProxySQL. Test suite: setparser_test_common.h, test arrays Set1_v2[0], syntax_errors[0], syntax_errors[1], sql_mode[21], sql_mode[23-25].
Problem
ProxySQL's regex-based SET parser (
MySQL_Set_Stmt_Parser::parse1v2()) returns an empty map for syntactically invalid SET statements. This signals to ProxySQL that the statement is unparseable, causing it to forward the SET verbatim to the backend.ParserSQL's SetParser is more lenient — it partially parses invalid statements and produces a non-empty result instead of failing. This causes ProxySQL to attempt to process variables that came from malformed SQL.
Failing test cases
These should all produce an empty map but instead produce partial results:
Suggested approach
The SetParser should validate that the entire input was consumed after parsing. If there are remaining unconsumed tokens after the SET statement, return
ParseResult::ERRORor an empty AST. This matches the "parse everything or nothing" contract that the regex parser provides.Context
Discovered during integration testing into ProxySQL. Test suite:
setparser_test_common.h, test arraysSet1_v2[0],syntax_errors[0],syntax_errors[1],sql_mode[21],sql_mode[23-25].