summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/path_alias/src/PathAliasStorageSchema.php
blob: d2bc87de1672251354dd523295ebe34f9e1d5de9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

namespace Drupal\path_alias;

use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;

/**
 * Defines the path_alias schema handler.
 */
class PathAliasStorageSchema extends SqlContentEntityStorageSchema {

  /**
   * {@inheritdoc}
   */
  protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
    $schema = parent::getEntitySchema($entity_type, $reset);
    $base_table = $this->storage->getBaseTable();
    $revision_table = $this->storage->getRevisionTable();

    $schema[$base_table]['indexes'] += [
      'path_alias__alias_langcode_id_status' => ['alias', 'langcode', 'id', 'status'],
      'path_alias__path_langcode_id_status' => ['path', 'langcode', 'id', 'status'],
    ];
    $schema[$revision_table]['indexes'] += [
      'path_alias_revision__alias_langcode_id_status' => ['alias', 'langcode', 'id', 'status'],
      'path_alias_revision__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;
  }

}