-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MySQL support for expression indexes
- Loading branch information
Ioannis Igoumenos
committed
Oct 22, 2023
1 parent
c2b637c
commit 3492096
Showing
4 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace App\Lib\Util; | ||
|
||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\Result; | ||
use Doctrine\DBAL\Schema\AbstractSchemaManager; | ||
use Doctrine\DBAL\Schema\Identifier; | ||
use Doctrine\DBAL\Schema\MySQLSchemaManager; | ||
|
||
class CmgMySQLSchemaManager extends MySQLSchemaManager { | ||
/** | ||
* Aggregates and groups the index results according to the required data result. | ||
* Parameters: \mixed[][] $tableIndexes | ||
* null|string $tableName | ||
*/ | ||
|
||
protected function _getPortableTableIndexesList($tableIndexes, $tableName = null) | ||
{ | ||
foreach ($tableIndexes as $k => $v) { | ||
$v = array_change_key_case($v, CASE_LOWER); | ||
if ($v['key_name'] === 'PRIMARY') { | ||
$v['primary'] = true; | ||
} else { | ||
$v['primary'] = false; | ||
} | ||
|
||
if (strpos($v['index_type'], 'FULLTEXT') !== false) { | ||
$v['flags'] = ['FULLTEXT']; | ||
} elseif (strpos($v['index_type'], 'SPATIAL') !== false) { | ||
$v['flags'] = ['SPATIAL']; | ||
} | ||
|
||
// Ignore prohibited prefix `length` for spatial index | ||
if (strpos($v['index_type'], 'SPATIAL') === false) { | ||
$v['length'] = isset($v['sub_part']) ? (int) $v['sub_part'] : null; | ||
} | ||
|
||
$tableIndexes[$k] = $v; | ||
} | ||
|
||
return AbstractSchemaManager::_getPortableTableIndexesList($tableIndexes, $tableName); | ||
} | ||
|
||
protected function selectIndexColumns(string $databaseName, ?string $tableName = null): Result | ||
{ | ||
$sql = 'SELECT'; | ||
|
||
if ($tableName === null) { | ||
$sql .= ' TABLE_NAME,'; | ||
} | ||
|
||
$sql .= <<<'SQL' | ||
NON_UNIQUE AS Non_Unique, | ||
INDEX_NAME AS Key_name, | ||
CONCAT(COALESCE(COLUMN_NAME, ''), COALESCE(EXPRESSION, '')) AS Column_Name, | ||
SUB_PART AS Sub_Part, | ||
INDEX_TYPE AS Index_Type, | ||
EXPRESSION AS Expression | ||
FROM information_schema.STATISTICS | ||
SQL; | ||
|
||
$conditions = ['TABLE_SCHEMA = ?']; | ||
$params = [$databaseName]; | ||
|
||
if ($tableName !== null) { | ||
$conditions[] = 'TABLE_NAME = ?'; | ||
$params[] = $tableName; | ||
} | ||
|
||
$sql .= ' WHERE ' . implode(' AND ', $conditions) . ' ORDER BY SEQ_IN_INDEX'; | ||
|
||
return $this->_conn->executeQuery($sql, $params); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters