Skip to content

Commit 586046e

Browse files
authored
Add queries that are expected to fail to the MySQL parser corpus (#618)
This PR adds the queries that MySQL tests expect to fail to the `mysql-parser` query corpus, and fixes four extractor bugs that lost queries. The corpus test now checks both directions: **the parser must reject a query marked as a syntax error, and accept any other row.** | | Trunk | This PR | |---|---:|---:| | Corpus rows | 69,370 | 78,156 | | Rows marked as syntax errors | 0 | 848 | | Pinned failures | 43 | 145 | ## Queries that are expected to fail The extractor now keeps the queries after `--error` and `error X;`. Most of them parse, because errors like a missing table come after parsing. A third CSV column holds `syntax_error` for the queries that the parser should reject: - **Marked by their tests:** Every occurrence of the query allows only a syntax error (`ER_PARSE_ERROR` or `1064`). - **Marked by name:** The extractor lists 18 queries whose tests don't show their syntax error, because MySQL reports a semantic error first or the test also allows another error. These queries stay regular rows, without the marker: - **`ER_SYNTAX_ERROR` (1149):** MySQL raises this from semantic checks on queries that parse. - **`PREPARE` with text or a variable:** The error is in the text, which isn't in the corpus. - **Three test files:** In `ctype_latin1.test`, `debug_sync.test`, and `trigger-compat-debug.test`, the error doesn't come from the query's syntax. - **`--error` lists with `0` or `S00000`:** The query may succeed. The benchmark skips marked rows, because it measures queries that should parse. ## Extractor fixes Four older bugs in the extractor lost 837 rows: - **`--delimiter |` (481 rows):** The extractor read the next statement as part of the delimiter and lost the rest of the file. - **Indented commands and comments (347 rows):** An indented `--echo` or `# comment` took in the next statement, and both were dropped. - **A delimiter that starts with a quote (6 rows):** The extractor never found `'abcd'` in `multi_statement.test`, so it lost the rest of that file. - **`--query` lines (3 rows):** The extractor skipped these like any other `--` command. Two of them expect a syntax error and have an unterminated quote, which no other marked row has. ## Remaining failures `tests/data/corpus-failures.csv` pins the 145 rows that fail the test: - **46 regular rows that the parser rejects:** These have several statements in one string, which MySQL also rejects without its multi-statement client flag. Parsing them needs a new parser API. - **97 marked rows that the parser accepts:** MySQL rejects these with checks that run while parsing, like the one for `COMMIT AND CHAIN RELEASE`. Rejecting them here would need a separate pass over the AST. - **2 marked rows that the parser accepts:** `select ?` and `select ? from t1` use `?`, which MySQL allows only when preparing. Every row was also compared with MySQL 8.4.10, using `mysqli::prepare` so that nothing runs. The only other differences are 28 `SHOW PARSE_TREE` rows that only debug builds accept, and the 15 marked rows where MySQL reports a semantic error first. Follow-up to #613. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Tests** * Expanded MySQL parser coverage for query delimiters, indented test commands, and comments. * Updated corpus checks to account for expected syntax errors and SQL-mode differences. Benchmark runs now exclude queries marked as expected syntax errors. * **Documentation** * Updated the documented MySQL query corpus size to approximately 78,000 queries and clarified how syntax-error cases are represented. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent f42d501 commit 586046e

6 files changed

Lines changed: 15854 additions & 574 deletions

File tree

‎packages/mysql-parser/README.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ This requires `bash`, `curl`, `docker`, and `php` and executes the following ste
8080
3. Extract and compact the grammar and tokens, and save them in `src`.
8181

8282
### Building the query corpus
83-
This package includes a testing corpus of about 70,000 MySQL queries extracted
83+
This package includes a testing corpus of about 78,000 MySQL queries extracted
8484
from the MySQL release that corresponds to the generated MySQL grammar version.
8585
To regenerate it, use:
8686

@@ -94,6 +94,11 @@ This requires `bash`, `git`, and `php`. It performs the following steps:
9494
3. Store the queries under `data/mysql-server-query-corpus/mysql-latest.csv`.
9595

9696
A query that runs in SQL modes that affect the lexer has them in a second column.
97+
A query that the MySQL tests only ever expect to fail with a syntax error has
98+
`syntax_error` in a third column, unless the error comes from outside its own
99+
syntax, such as the text of a `PREPARE` statement. A few queries with syntax
100+
errors that the tests don't expect alone have it too, and the extractor lists
101+
them by name.
97102

98103
## Tests and benchmarks
99104
To run lexer and parser tests and benchmarks, use:

0 commit comments

Comments
 (0)