Skip to content

Commit 30e8281

Browse files
committed
Improving the parser routing when ANALYZE is used
Signed-off-by: iifawzi <[email protected]>
1 parent 8d88dc7 commit 30e8281

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/Parser.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -467,21 +467,26 @@ public function parse()
467467
}
468468

469469
$lastIdx = $list->idx;
470-
471-
++$list->idx; // Skip ANALYZE
472-
$first = $list->getNextOfType(Token::TYPE_KEYWORD);
473-
$second = $list->getNextOfType(Token::TYPE_KEYWORD);
474470
$statementName = null;
475471

476-
// ANALYZE keyword can be an indication of two cases:
477-
// 1- ANALAYZE TABLE statements, in both mariaDB and MySQL
478-
// 2- Explain statement, in case of mariaDB https://mariadb.com/kb/en/explain-analyze/
479-
// We need to point case 2 to use the EXPLAIN Parser.
480-
if ($token->keyword === 'ANALYZE' && $first->keyword !== 'TABLE' && $second->keyword !== 'TABLE') {
472+
if ($token->keyword === 'ANALYZE') {
473+
++$list->idx; // Skip ANALYZE
474+
475+
$first = $list->getNextOfType(Token::TYPE_KEYWORD);
476+
$second = $list->getNextOfType(Token::TYPE_KEYWORD);
477+
478+
// ANALYZE keyword can be an indication of two cases:
479+
// 1- ANALAYZE TABLE statements, in both mariaDB and MySQL
480+
// 2- Explain statement, in case of mariaDB https://mariadb.com/kb/en/explain-analyze/
481+
// We need to point each case to the correct parser
482+
if ($first->keyword === 'TABLE' || $second->keyword === 'TABLE') {
483+
$statementName = 'ANALYZE';
484+
} else {
485+
$statementName = 'EXPLAIN';
486+
}
487+
481488
$list->idx = $lastIdx;
482-
$statementName = 'EXPLAIN';
483489
} else {
484-
$list->idx = $lastIdx;
485490
// Checking if it is a known statement that can be parsed.
486491
if (empty(static::$STATEMENT_PARSERS[$token->keyword])) {
487492
if (! isset(static::$STATEMENT_PARSERS[$token->keyword])) {

0 commit comments

Comments
 (0)