Skip to content

Commit

Permalink
Merge pull request #5268 from morozov/optimize-list-tables
Browse files Browse the repository at this point in the history
Optimize schema managers' ::listTables() methods
  • Loading branch information
morozov committed Feb 15, 2022
2 parents 6283869 + 194c6eb commit 1135a79
Show file tree
Hide file tree
Showing 17 changed files with 1,305 additions and 85 deletions.
11 changes: 11 additions & 0 deletions UPGRADE.md
Expand Up @@ -8,6 +8,17 @@ awareness about deprecated code.

# Upgrade to 3.4

# Deprecated `AbstractPlatform` schema introspection methods

The following schema introspection methods have been deprecated:

- `AbstractPlatform::getListTablesSQL()`,
- `AbstractPlatform::getListTableColumnsSQL()`,
- `AbstractPlatform::getListTableIndexesSQL()`,
- `AbstractPlatform::getListTableForeignKeysSQL()`.

The queries used for schema introspection are an internal implementation detail of the DBAL.

# Deprecated `collate` option for MySQL

This undocumented option is deprecated in favor of `collation`.
Expand Down
26 changes: 26 additions & 0 deletions psalm.xml.dist
Expand Up @@ -212,6 +212,32 @@
<referencedMethod name="Doctrine\DBAL\Connection::getWrappedConnection"/>
<!--
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractMySQLPlatform::getListTableColumnsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractMySQLPlatform::getListTableForeignKeysSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractMySQLPlatform::getListTableIndexesSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getListTableColumnsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getListTableForeignKeysSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getListTableIndexesSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\DB2Platform::getListTableColumnsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\DB2Platform::getListTableCommentsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\DB2Platform::getListTableForeignKeysSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\DB2Platform::getListTableIndexesSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\OraclePlatform::getListTableColumnsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\OraclePlatform::getListTableForeignKeysSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\OraclePlatform::getListTableIndexesSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\PostgreSQLPlatform::getListTableColumnsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\PostgreSQLPlatform::getListTableForeignKeysSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\PostgreSQLPlatform::getListTableIndexesSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\PostgreSQLPlatform::getListTableMetadataSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SQLServerPlatform::getListTableColumnsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SQLServerPlatform::getListTableForeignKeysSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SQLServerPlatform::getListTableIndexesSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SQLServerPlatform::getListTableMetadataSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SqlitePlatform::getListTableColumnsSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SqlitePlatform::getListTableForeignKeysSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\SqlitePlatform::getListTableIndexesSQL"/>
<!--
See https://github.com/doctrine/dbal/pull/1519
-->
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractMySQLPlatform::prefersIdentityColumns"/>
Expand Down
20 changes: 20 additions & 0 deletions src/Exception/DatabaseRequired.php
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Exception;

use Doctrine\DBAL\Exception;

use function sprintf;

/**
* @psalm-immutable
*/
class DatabaseRequired extends Exception
{
public static function new(string $methodName): self
{
return new self(sprintf('A database is required for the method: %s.', $methodName));
}
}
11 changes: 11 additions & 0 deletions src/Platforms/AbstractMySQLPlatform.php
Expand Up @@ -147,6 +147,8 @@ public function getListTableConstraintsSQL($table)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* {@inheritDoc}
*
* Two approaches to listing the table indexes. The information_schema is
Expand Down Expand Up @@ -174,6 +176,8 @@ public function getListViewsSQL($database)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* @param string $table
* @param string|null $database
*
Expand Down Expand Up @@ -327,6 +331,8 @@ public function supportsColumnCollation()
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* {@inheritDoc}
*/
public function getListTablesSQL()
Expand All @@ -335,6 +341,8 @@ public function getListTablesSQL()
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* {@inheritDoc}
*/
public function getListTableColumnsSQL($table, $database = null)
Expand All @@ -347,6 +355,9 @@ public function getListTableColumnsSQL($table, $database = null)
' ORDER BY ORDINAL_POSITION ASC';
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*/
public function getListTableMetadataSQL(string $table, ?string $database = null): string
{
return sprintf(
Expand Down
8 changes: 8 additions & 0 deletions src/Platforms/AbstractPlatform.php
Expand Up @@ -3125,6 +3125,8 @@ public function getListTableConstraintsSQL($table)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* @param string $table
* @param string $database
*
Expand All @@ -3138,6 +3140,8 @@ public function getListTableColumnsSQL($table, $database = null)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* @return string
*
* @throws Exception If not supported on this platform.
Expand Down Expand Up @@ -3180,6 +3184,8 @@ public function getListViewsSQL($database)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* Returns the list of indexes for the current database.
*
* The current database parameter is optional but will always be passed
Expand All @@ -3202,6 +3208,8 @@ public function getListTableIndexesSQL($table, $database = null)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* @param string $table
*
* @return string
Expand Down
9 changes: 9 additions & 0 deletions src/Platforms/DB2Platform.php
Expand Up @@ -279,6 +279,8 @@ public function getTruncateTableSQL($tableName, $cascade = false)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* This code fragment is originally from the Zend_Db_Adapter_Db2 class, but has been edited.
*
* @param string $table
Expand Down Expand Up @@ -352,6 +354,8 @@ public function getListViewsSQL($database)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* {@inheritDoc}
*/
public function getListTableIndexesSQL($table, $database = null)
Expand All @@ -376,6 +380,8 @@ public function getListTableIndexesSQL($table, $database = null)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* {@inheritDoc}
*/
public function getListTableForeignKeysSQL($table)
Expand Down Expand Up @@ -900,6 +906,9 @@ protected function getReservedKeywordsClass()
return Keywords\DB2Keywords::class;
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*/
public function getListTableCommentsSQL(string $table): string
{
return sprintf(
Expand Down
9 changes: 9 additions & 0 deletions src/Platforms/OraclePlatform.php
Expand Up @@ -430,6 +430,8 @@ protected function _getCreateTableSQL($name, array $columns, array $options = []
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* {@inheritDoc}
*
* @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaOracleReader.html
Expand Down Expand Up @@ -626,6 +628,8 @@ private function getAutoincrementIdentifierName(Identifier $table): string
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* {@inheritDoc}
*/
public function getListTableForeignKeysSQL($table)
Expand Down Expand Up @@ -671,6 +675,8 @@ public function getListTableConstraintsSQL($table)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* {@inheritDoc}
*/
public function getListTableColumnsSQL($table, $database = null)
Expand Down Expand Up @@ -1192,6 +1198,9 @@ public function getBlobTypeDeclarationSQL(array $column)
return 'BLOB';
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*/
public function getListTableCommentsSQL(string $table, ?string $database = null): string
{
$tableCommentsName = 'user_tab_comments';
Expand Down
9 changes: 9 additions & 0 deletions src/Platforms/PostgreSQLPlatform.php
Expand Up @@ -297,6 +297,8 @@ public function getListViewsSQL($database)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* @param string $table
* @param string|null $database
*
Expand Down Expand Up @@ -345,6 +347,8 @@ public function getListTableConstraintsSQL($table)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* {@inheritDoc}
*
* @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html
Expand Down Expand Up @@ -391,6 +395,8 @@ private function getTableWhereClause($table, $classAlias = 'c', $namespaceAlias
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* {@inheritDoc}
*/
public function getListTableColumnsSQL($table, $database = null)
Expand Down Expand Up @@ -1265,6 +1271,9 @@ private function getOldColumnComment(ColumnDiff $columnDiff): ?string
return $columnDiff->fromColumn !== null ? $this->getColumnComment($columnDiff->fromColumn) : null;
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*/
public function getListTableMetadataSQL(string $table, ?string $schema = null): string
{
if ($schema !== null) {
Expand Down
9 changes: 9 additions & 0 deletions src/Platforms/SQLServerPlatform.php
Expand Up @@ -904,6 +904,8 @@ public function getListTablesSQL()
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* {@inheritDoc}
*/
public function getListTableColumnsSQL($table, $database = null)
Expand Down Expand Up @@ -937,6 +939,8 @@ public function getListTableColumnsSQL($table, $database = null)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* @param string $table
* @param string|null $database
*
Expand All @@ -963,6 +967,8 @@ public function getListTableForeignKeysSQL($table, $database = null)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* {@inheritDoc}
*/
public function getListTableIndexesSQL($table, $database = null)
Expand Down Expand Up @@ -1610,6 +1616,9 @@ protected function getCommentOnTableSQL(string $tableName, ?string $comment): st
);
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*/
public function getListTableMetadataSQL(string $table): string
{
return sprintf(
Expand Down
6 changes: 6 additions & 0 deletions src/Platforms/SqlitePlatform.php
Expand Up @@ -472,6 +472,8 @@ public function getListTableConstraintsSQL($table)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* {@inheritDoc}
*/
public function getListTableColumnsSQL($table, $database = null)
Expand All @@ -482,6 +484,8 @@ public function getListTableColumnsSQL($table, $database = null)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* {@inheritDoc}
*/
public function getListTableIndexesSQL($table, $database = null)
Expand Down Expand Up @@ -876,6 +880,8 @@ public function getCreateTableSQL(Table $table, $createFlags = null)
}

/**
* @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon.
*
* @param string $table
* @param string|null $database
*
Expand Down

0 comments on commit 1135a79

Please sign in to comment.