Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine the InnoDB index length only once per schema #4853

Merged
merged 1 commit into from Jun 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 17 additions & 6 deletions core-bundle/src/Doctrine/Schema/DcaSchemaProvider.php
Expand Up @@ -36,6 +36,11 @@ class DcaSchemaProvider
*/
private $doctrine;

/**
* @var int|null
*/
private $defaultIndexLength;

/**
* @internal Do not inherit from this class; decorate the "contao.doctrine.schema_provider" service instead
*/
Expand All @@ -59,6 +64,8 @@ public function createSchema(): Schema
*/
public function appendToSchema(Schema $schema): void
{
$this->defaultIndexLength = null;

$config = $this->getSqlDefinitions();

foreach ($config as $tableName => $definitions) {
Expand Down Expand Up @@ -444,6 +451,10 @@ private function getDefaultIndexLength(Table $table): int
return 1000;
}

if (null !== $this->defaultIndexLength) {
return $this->defaultIndexLength;
}

$largePrefix = $this->doctrine
->getConnection()
->query("SHOW VARIABLES LIKE 'innodb_large_prefix'")
Expand All @@ -452,7 +463,7 @@ private function getDefaultIndexLength(Table $table): int

// The variable no longer exists as of MySQL 8 and MariaDB 10.3
if (false === $largePrefix || '' === $largePrefix->Value) {
return 3072;
return $this->defaultIndexLength = 3072;
}

$version = $this->doctrine
Expand All @@ -470,12 +481,12 @@ private function getDefaultIndexLength(Table $table): int

// Large prefixes are always enabled as of MySQL 5.7.7 and MariaDB 10.2.2
if (version_compare($ver, $vok, '>=')) {
return 3072;
return $this->defaultIndexLength = 3072;
}

// The innodb_large_prefix option is disabled
if (!\in_array(strtolower((string) $largePrefix->Value), ['1', 'on'], true)) {
return 767;
return $this->defaultIndexLength = 767;
}

$filePerTable = $this->doctrine
Expand All @@ -486,7 +497,7 @@ private function getDefaultIndexLength(Table $table): int

// The innodb_file_per_table option is disabled
if (!\in_array(strtolower((string) $filePerTable->Value), ['1', 'on'], true)) {
return 767;
return $this->defaultIndexLength = 767;
}

$fileFormat = $this->doctrine
Expand All @@ -497,10 +508,10 @@ private function getDefaultIndexLength(Table $table): int

// The InnoDB file format is not Barracuda
if ('' !== $fileFormat->Value && 'barracuda' !== strtolower((string) $fileFormat->Value)) {
return 767;
return $this->defaultIndexLength = 767;
}

return 3072;
return $this->defaultIndexLength = 3072;
}

private function isCaseSensitive(array $config): bool
Expand Down