Skip to content

Conversation

@JanJakes
Copy link
Member

@JanJakes JanJakes commented Jan 30, 2026

Fixes SELECT queries that have string literals with NULL bytes in them and no column alias.

E.g.:

SELECT `a<null-byte>b`;

-- result column name should be: 'a'

This is because in MySQL:

  • There can’t be \0 bytes in identifiers (like column names). The lexer will reject that.
  • But string literals can have them.
  • And there is a way to make a string literal “identifier-like” (implicit alias = the result “column name”): SELECT 'abc\0xyz' The result column name will be: abc

@JanJakes JanJakes requested a review from a team January 30, 2026 16:30
@JanJakes JanJakes marked this pull request as ready for review January 30, 2026 16:30

// When the literal value contains a NULL byte, MySQL truncates the
// resulting identifier at the position of the first one of them.
$fist_null_byte_pos = strpos( $alias, "\0" );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this matter in more places than just translate_select_item?

Copy link
Member Author

@JanJakes JanJakes Jan 30, 2026

Choose a reason for hiding this comment

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

@adamziel I will check that a bit deeper in a follow-up PR. There is the case where you type this explicitly (SELECT 1 AS 'a\0b'), and we need a follow-up to tackle that. Then, I think there is no other way where a string literal gets "converted" to an alias, but—I found some inconsistencies in how we process string literals vs. quoted identifiers and want to improve that too. We seem to treat them the same, but they shouldn't. It might be an interesting edge case bug going down to the lexer.

Copy link
Collaborator

@adamziel adamziel left a comment

Choose a reason for hiding this comment

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

LGTM and solves a problem so looks good for merging. We may want to follow up with a more general solution if that matters beyond the SELECT columns list.

@JanJakes JanJakes merged commit 64468b7 into trunk Jan 30, 2026
16 checks passed
@JanJakes JanJakes deleted the fix-select-literal-with-null branch January 30, 2026 16:48
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.

3 participants