Skip to content

MySQL: Add support for SELECT modifiers#2172

Merged
iffyio merged 2 commits intoapache:mainfrom
mvzink:push-syxoqlsrvqux
Feb 5, 2026
Merged

MySQL: Add support for SELECT modifiers#2172
iffyio merged 2 commits intoapache:mainfrom
mvzink:push-syxoqlsrvqux

Conversation

@mvzink
Copy link
Contributor

@mvzink mvzink commented Jan 23, 2026

Adds support for MySQL-specific SELECT modifiers that appear after the SELECT keyword. Grammar from the docs:

SELECT
    [ALL | DISTINCT | DISTINCTROW ]
    [HIGH_PRIORITY]
    [STRAIGHT_JOIN]
    [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
    [SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
    select_expr [, select_expr] ...

Manual testing shows that these options can appear in any order relative to each other, so for the sake of fidelity, we parse this separately from how we parse distinct and other options for other dialects, in a new Parser::parse_select_modifiers method.

DISTINCTROW is a legacy (but not deprecated) synonym for DISTINCT, so it just gets canonicalized as DISTINCT.

@mvzink mvzink force-pushed the push-syxoqlsrvqux branch from 460f829 to a437a32 Compare January 23, 2026 01:08
Comment on lines 14060 to 14061
let mut distinct: Option<Distinct> = None;
let mut has_all = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we instead introduce a proper enum to represent the three states? the current impl I think is harder to follow which combinations are valid and if/when the specified option is ignored in the output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sure. Is this what you have in mind?

enum Distinct {
    All,
    Distinct,
    On(Vec<Expr),
}

I'll go ahead and implement that, but let me know if you had something else in mind that I'll be happy to update it..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lmk what you think. I also reworked it a bit so that DISTINCTROW aliasing only happens here and not in the main parse_all_or_distinct which I believe addresses your other comment.

mvzink and others added 2 commits February 4, 2026 15:49
Previously, `SELECT ALL` was parsed but the ALL keyword was discarded,
with `one_statement_parses_to` tests verifying it normalized away. Now
the parser returns `Distinct::All` so the AST represents the original
SQL.

Also improves error messages for conflicting ALL/DISTINCT to indicate
which keyword came first.
Adds support for MySQL-specific `SELECT` modifiers that appear after the
`SELECT` keyword. Grammar from the [docs]:

```sql
SELECT
    [ALL | DISTINCT | DISTINCTROW ]
    [HIGH_PRIORITY]
    [STRAIGHT_JOIN]
    [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
    [SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
    select_expr [, select_expr] ...
```

Manual testing shows that these options can appear in any order relative
to each other, so for the sake of fidelity, we parse this separately
from how we parse distinct and other options for other dialects, in a
new `Parser::parse_select_modifiers` method.

`DISTINCTROW` is a legacy (but not deprecated) synonym for `DISTINCT`,
so it just gets canonicalized as `DISTINCT`.

[docs]: https://dev.mysql.com/doc/refman/8.4/en/select.html
@mvzink mvzink force-pushed the push-syxoqlsrvqux branch from a437a32 to a2459ae Compare February 5, 2026 00:10
Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @mvzink!

@iffyio iffyio added this pull request to the merge queue Feb 5, 2026
Merged via the queue into apache:main with commit 5e5c16c Feb 5, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants