function Schema::introspectIndexSchema
Finds the columns for the primary key, unique keys and indexes of a table.
Parameters
string $table: The name of the table.
Return value
array A schema array with the following keys: 'primary key', 'unique keys' and 'indexes', and values as arrays of database columns.
Overrides Schema::introspectIndexSchema
File
- 
              core/modules/ mysql/ src/ Driver/ Database/ mysql/ Schema.php, line 600 
Class
- Schema
- MySQL implementation of \Drupal\Core\Database\Schema.
Namespace
Drupal\mysql\Driver\Database\mysqlCode
protected function introspectIndexSchema($table) {
  if (!$this->tableExists($table)) {
    throw new SchemaObjectDoesNotExistException("The table {$table} doesn't exist.");
  }
  $index_schema = [
    'primary key' => [],
    'unique keys' => [],
    'indexes' => [],
  ];
  $result = $this->connection
    ->query('SHOW INDEX FROM {' . $table . '}')
    ->fetchAll();
  foreach ($result as $row) {
    if ($row->Key_name === 'PRIMARY') {
      $index_schema['primary key'][] = $row->Column_name;
    }
    elseif ($row->Non_unique == 0) {
      $index_schema['unique keys'][$row->Key_name][] = $row->Column_name;
    }
    else {
      $index_schema['indexes'][$row->Key_name][] = $row->Column_name;
    }
  }
  return $index_schema;
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
