Skip to content

Commit

Permalink
db_verify::getIndex(): Support index_col_name optional parts
Browse files Browse the repository at this point in the history
In the MariaDB `CREATE TABLE` [`index_definition`](https://mariadb.com/kb/en/create-table/#index-definitions),
 the `index_col_name` could have an optional length and a sort order:

```
index_definition:
    {INDEX|KEY} [index_name] [index_type] (index_col_name,...) [index_option] ...
  {{{|}}} {FULLTEXT|SPATIAL} [INDEX|KEY] [index_name] (index_col_name,...) [index_option] ...
  {{{|}}} [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_col_name,...) [index_option] ...
  {{{|}}} [CONSTRAINT [symbol]] UNIQUE [INDEX|KEY] [index_name] [index_type] (index_col_name,...) [index_option] ...
  {{{|}}} [CONSTRAINT [symbol]] FOREIGN KEY [index_name] (index_col_name,...) reference_definition

index_col_name:
    col_name [(length)] [ASC | DESC]

index_type:
    USING {BTREE | HASH | RTREE}

index_option:
    [ KEY_BLOCK_SIZE [=] value
  {{{|}}} index_type
  {{{|}}} WITH PARSER parser_name
  {{{|}}} COMMENT 'string'
  {{{|}}} CLUSTERING={YES| NO} ]
  [ IGNORED | NOT IGNORED ]

reference_definition:
    REFERENCES tbl_name (index_col_name,...)
      [MATCH FULL | MATCH PARTIAL | MATCH SIMPLE]
      [ON DELETE reference_option]
      [ON UPDATE reference_option]

reference_option:
    RESTRICT | CASCADE | SET NULL | NO ACTION
```

`db_verify::getIndex()` didn't handle this possibility, leading to a
database validity check failure despite the index actually existing.

Fixes: #5054
  • Loading branch information
Deltik committed Aug 2, 2023
1 parent 95296d1 commit ceddd79
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions e107_handlers/db_verify_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1065,9 +1065,7 @@ function getFields($data, $print = false)
*/
function getIndex($data, $print = false)
{
// $regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?`?([\w,]*[\s]?)`?\))?,?/i";
// $regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT|FOREIGN))?[\s]*?KEY (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?([\w\s,`]*[\s]?)`?\))?,?/i";
$regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT|FOREIGN))?[\s]*?(INDEX|KEY) (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?([\w\s,`]*[\s]?)`?\))?,?/i";
$regex = "/(?:(PRIMARY|UNIQUE|FULLTEXT|FOREIGN))?[\s]*?(INDEX|KEY) (?: ?`?([\w]*)`?)[\s]* ?(?:\([\s]?([\w\s,`]*)\(?[\d]*\)?\s*(ASC|DESC)?[\s]?`?\))?,?/i";
preg_match_all($regex,$data,$m);
if (count($m) > 0)
Expand Down

0 comments on commit ceddd79

Please sign in to comment.