sql-parser icon indicating copy to clipboard operation
sql-parser copied to clipboard

Fix #592 - desc index

Open predictor2718 opened this issue 1 month ago • 1 comments

Description

This PR fixes incorrect parsing of DESC inside index definitions in ALTER TABLE statements.

Example:

ALTER TABLE `t`
  ADD UNIQUE KEY `idx` (`a`, `b` DESC);

This change updates AlterOperation::parse() so that ASC and DESC are not interpreted as new statements within index definitions.

Fixes #592.

predictor2718 avatar Nov 24 '25 22:11 predictor2718

Thank you for the review!

Regarding the question about whether DeSC (or other mixed-case variants) would still trigger the check:

The parser normalizes keywords during lexing.
Lexer::parseKeyword() internally calls Context::isKeyword(), which performs a strtoupper() on the token value.
Because of this, any case variation like DESC, Desc, DeSC, etc. is always mapped to the uppercase keyword DESC.

So the condition is case-insensitive and mixed-case inputs won’t cause issues.

To be safe, I also added additional tests covering:

  • ASC
  • DESC
  • lowercase desc
  • two DESC columns

All tests pass with the current implementation.

predictor2718 avatar Nov 26 '25 22:11 predictor2718