@@ -466,27 +466,44 @@ public function parse()
466
466
continue ;
467
467
}
468
468
469
- // Checking if it is a known statement that can be parsed.
470
- if (empty (static ::$ STATEMENT_PARSERS [$ token ->keyword ])) {
471
- if (! isset (static ::$ STATEMENT_PARSERS [$ token ->keyword ])) {
472
- // A statement is considered recognized if the parser
473
- // is aware that it is a statement, but it does not have
474
- // a parser for it yet.
475
- $ this ->error ('Unrecognized statement type. ' , $ token );
476
- }
469
+ $ lastIdx = $ list ->idx ;
470
+
471
+ ++$ list ->idx ; // Skip ANALYZE
472
+ $ first = $ list ->getNextOfType (Token::TYPE_KEYWORD );
473
+ $ second = $ list ->getNextOfType (Token::TYPE_KEYWORD );
474
+ $ statementName = null ;
475
+
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 ;
482
+ $ statementName = 'EXPLAIN ' ;
483
+ } else {
484
+ $ list ->idx = $ lastIdx ;
485
+ // Checking if it is a known statement that can be parsed.
486
+ if (empty (static ::$ STATEMENT_PARSERS [$ token ->keyword ])) {
487
+ if (! isset (static ::$ STATEMENT_PARSERS [$ token ->keyword ])) {
488
+ // A statement is considered recognized if the parser
489
+ // is aware that it is a statement, but it does not have
490
+ // a parser for it yet.
491
+ $ this ->error ('Unrecognized statement type. ' , $ token );
492
+ }
477
493
478
- // Skipping to the end of this statement.
479
- $ list ->getNextOfType (Token::TYPE_DELIMITER );
480
- $ prevLastIdx = $ list ->idx ;
481
- continue ;
494
+ // Skipping to the end of this statement.
495
+ $ list ->getNextOfType (Token::TYPE_DELIMITER );
496
+ $ prevLastIdx = $ list ->idx ;
497
+ continue ;
498
+ }
482
499
}
483
500
484
501
/**
485
502
* The name of the class that is used for parsing.
486
503
*
487
504
* @var string
488
505
*/
489
- $ class = static ::$ STATEMENT_PARSERS [$ token ->keyword ];
506
+ $ class = static ::$ STATEMENT_PARSERS [$ statementName ? $ statementName : $ token ->keyword ];
490
507
491
508
/**
492
509
* Processed statement.
0 commit comments