Skip to content

SET parser: stops after SET NAMES when comma-separated assignments follow #34

@renecannao

Description

@renecannao

Problem

When a SET statement contains SET NAMES charset followed by comma-separated variable assignments (e.g., SET NAMES utf8, sql_mode = 'TRADITIONAL'), the parser stops after SET NAMES and does not parse the remaining assignments.

Failing test cases

SET sql_mode = 'TRADITIONAL', NAMES 'utf8' COLLATE 'unicode_ci'
  Expected: {"sql_mode": ["TRADITIONAL"], "names": ["utf8", "unicode_ci"]}
  Got:      {"sql_mode": ["TRADITIONAL"]}  (names missing)

SET NAMES utf8, @@SESSION.sql_mode = CONCAT(...), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 3600
  Expected: 4 entries (names + 3 assignments)
  Got:      1 entry (names only)

SET NAMES utf8, @@LOCAL.sql_mode = CONCAT(...), @@LOCAL.sql_auto_is_null = 0, @@LOCAL.wait_timeout = 3600
  Expected: 4 entries
  Got:      1 entry (names only)

SET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(REPLACE(...))), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 3600
  Expected: 4 entries
  Got:      1 entry (names only)

Root cause

In set_parser.h, after parsing NODE_SET_NAMES, the parser does not continue to check for comma-separated NODE_VAR_ASSIGNMENT siblings. The SetParser returns after the NAMES clause.

Expected behavior

SET NAMES charset [, var = expr, ...] should produce both a NODE_SET_NAMES child and NODE_VAR_ASSIGNMENT children under the NODE_SET_STMT root.

Context

Discovered during integration testing of ParserSQL into ProxySQL. Test suite: setparser_test_common.h, test arrays multiple[2], multiple[6], multiple[7], Set1_v2[1].

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