Repository navigation
Commit 586046e
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
- data/mysql-server-query-corpus
- tests
- data
- tools
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
97 | 102 | | |
98 | 103 | | |
99 | 104 | | |
| |||
0 commit comments