diff --git a/core/modules/path_alias/path_alias.post_update.php b/core/modules/path_alias/path_alias.post_update.php new file mode 100644 index 0000000000000000000000000000000000000000..2675142e62246dde04106f3cf28f51f0805f09e5 --- /dev/null +++ b/core/modules/path_alias/path_alias.post_update.php @@ -0,0 +1,16 @@ +<?php + +/** + * @file + * Post update functions for Path Alias. + */ + +/** + * Remove the path_alias__status index. + */ +function path_alias_post_update_drop_path_alias_status_index(): void { + /** @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface $update_manager */ + $update_manager = \Drupal::service('entity.definition_update_manager'); + $entity_type = $update_manager->getEntityType('path_alias'); + $update_manager->updateEntityType($entity_type); +} diff --git a/core/modules/path_alias/src/PathAliasStorageSchema.php b/core/modules/path_alias/src/PathAliasStorageSchema.php index 53acc85c72383caa384d57200e196a6506c42d69..7db7519dbf5bf606e9c187af4175cbc90e1926e5 100644 --- a/core/modules/path_alias/src/PathAliasStorageSchema.php +++ b/core/modules/path_alias/src/PathAliasStorageSchema.php @@ -15,12 +15,17 @@ class PathAliasStorageSchema extends SqlContentEntityStorageSchema { */ protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) { $schema = parent::getEntitySchema($entity_type, $reset); + $base_table = $this->storage->getBaseTable(); - $schema[$this->storage->getBaseTable()]['indexes'] += [ + $schema[$base_table]['indexes'] += [ 'path_alias__alias_langcode_id_status' => ['alias', 'langcode', 'id', 'status'], 'path_alias__path_langcode_id_status' => ['path', 'langcode', 'id', 'status'], ]; + // Unset the path_alias__status index as it is slower than the above + // indexes and MySQL 5.7 chooses to use it even though it is suboptimal. + unset($schema[$base_table]['indexes']['path_alias__status']); + return $schema; } diff --git a/core/modules/path_alias/tests/src/Functional/PathAliasUpdateTest.php b/core/modules/path_alias/tests/src/Functional/PathAliasUpdateTest.php new file mode 100644 index 0000000000000000000000000000000000000000..d7db9a4b3d039687983fc79252541fa864610901 --- /dev/null +++ b/core/modules/path_alias/tests/src/Functional/PathAliasUpdateTest.php @@ -0,0 +1,33 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\Tests\path_alias\Functional; + +use Drupal\FunctionalTests\Update\UpdatePathTestBase; + +/** + * Tests update hooks the path_alias module. + * + * @group path_alias + */ +class PathAliasUpdateTest extends UpdatePathTestBase { + + /** + * {@inheritdoc} + */ + protected function setDatabaseDumpFiles() { + $this->databaseDumpFiles[] = __DIR__ . '/../../../../system/tests/fixtures/update/drupal-9.4.0.bare.standard.php.gz'; + } + + /** + * Tests path_alias_post_update_drop_path_alias_status_index. + */ + public function testPathAliasStatusIndexRemoved(): void { + $schema = \Drupal::database()->schema(); + $this->assertTrue($schema->indexExists('path_alias', 'path_alias__status')); + $this->runUpdates(); + $this->assertFalse($schema->indexExists('path_alias', 'path_alias__status')); + } + +} diff --git a/core/modules/path_alias/tests/src/Kernel/PathAliasStorageSchemaTest.php b/core/modules/path_alias/tests/src/Kernel/PathAliasStorageSchemaTest.php new file mode 100644 index 0000000000000000000000000000000000000000..61496b0b04f72b5ff8f0bdb709c77c53fc15e34c --- /dev/null +++ b/core/modules/path_alias/tests/src/Kernel/PathAliasStorageSchemaTest.php @@ -0,0 +1,44 @@ +<?php + +declare(strict_types=1); + +namespace Drupal\Tests\path_alias\Kernel; + +use Drupal\KernelTests\KernelTestBase; + +/** + * Tests the path_alias storage schema. + * + * @coversDefaultClass \Drupal\path_alias\PathAliasStorageSchema + * + * @group path_alias + */ +class PathAliasStorageSchemaTest extends KernelTestBase { + + /** + * {@inheritdoc} + */ + protected static $modules = ['path_alias']; + + /** + * {@inheritdoc} + */ + protected function setUp(): void { + parent::setUp(); + $this->installEntitySchema('path_alias'); + } + + /** + * Tests that the path_alias__status index is removed. + * + * @covers ::getEntitySchema + */ + public function testPathAliasStatusIndexRemoved(): void { + $schema = \Drupal::database()->schema(); + $table_name = 'path_alias'; + $this->assertTrue($schema->indexExists($table_name, 'path_alias__alias_langcode_id_status')); + $this->assertTrue($schema->indexExists($table_name, 'path_alias__path_langcode_id_status')); + $this->assertFalse($schema->indexExists($table_name, 'path_alias__status')); + } + +}