Skip to content

Commit 2c6a2b6

Browse files
iifawziwilliamdes
authored andcommitted
Improving the parser routing when ANALYZE is used
Signed-off-by: iifawzi <[email protected]>
1 parent 8d88dc7 commit 2c6a2b6

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

src/Parser.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -467,21 +467,25 @@ 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') {
481-
$list->idx = $lastIdx;
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 - ANALYZE 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 case 2 to use the EXPLAIN Parser.
482482
$statementName = 'EXPLAIN';
483-
} else {
483+
if ($first->keyword === 'TABLE' || $second->keyword === 'TABLE') {
484+
$statementName = 'ANALYZE';
485+
}
486+
484487
$list->idx = $lastIdx;
488+
} else {
485489
// Checking if it is a known statement that can be parsed.
486490
if (empty(static::$STATEMENT_PARSERS[$token->keyword])) {
487491
if (! isset(static::$STATEMENT_PARSERS[$token->keyword])) {
@@ -503,7 +507,7 @@ public function parse()
503507
*
504508
* @var string
505509
*/
506-
$class = static::$STATEMENT_PARSERS[$statementName ? $statementName : $token->keyword];
510+
$class = static::$STATEMENT_PARSERS[$statementName ?? $token->keyword];
507511

508512
/**
509513
* Processed statement.

0 commit comments

Comments
 (0)