{@inheritDoc}

Two approaches to listing the table indexes. The information_schema is
preferred, because it doesn't cause problems with SQL keywords such as "order" or "table".
978426
public function getListTableIndexesSQL($table, $currentDatabase = null)
    {
        if ($currentDatabase) {
            $currentDatabase = $this->quoteStringLiteral($currentDatabase);
            $table           = $this->quoteStringLiteral($table);

            return 'SELECT NON_UNIQUE AS Non_Unique, INDEX_NAME AS Key_name, COLUMN_NAME AS Column_Name,' .
                   ' SUB_PART AS Sub_Part, INDEX_TYPE AS Index_Type' .
                   ' FROM information_schema.STATISTICS WHERE TABLE_NAME = ' . $table .
                   ' AND TABLE_SCHEMA = ' . $currentDatabase .
                   ' ORDER BY SEQ_IN_INDEX ASC';
        }

        return 'SHOW INDEX FROM ' . $table;
    }
88200
protected function _updateIndexes ($table_name) {
		$seq_in_index = [];

		$this->_indexes[$table_name] = [];

		foreach ($this->getColumns($table_name, true) as $column) {
			if ($column['primary_key']) {
				if (!isset($seq_in_index['PRIMARY'])) {
					$seq_in_index['PRIMARY'] = 1;
				}
				$this->_indexes[$table_name]['PRIMARY'][] = [
					'table_name'		=> $table_name,
					'temporary'			=> null,
					'unique'			=> true,
					'if_not_exists'		=> null,
					'key_name'			=> 'PRIMARY',
					'column_name'		=> $column['column_name'],
					'seq_in_index'		=> $seq_in_index['PRIMARY']++,
					'collation'			=> null,
					'cardinality'		=> null,
					'comment'			=> null,
					'index_comment'		=> null,
					'order'				=> null,
					'index_type'		=> null,
					'sub_part'			=> null,
					'raw_data'			=> null,
				];
			}
		}

		$stmt = $this->prepare('SELECT pis.tablename AS table_name, pis.indexname AS index_name, pa.attname AS column_name, pi.indisunique AS unique, pi.indisprimary AS primary, pis.indexdef AS sql, pam.amname AS hash_type FROM pg_indexes pis, pg_class pc_i, pg_index pi, pg_class pc_t, pg_attribute pa, pg_am pam WHERE pis.schemaname = current_schema() AND pis.tablename = ? AND pc_i.relname IN (pis.indexname) AND pi.indexrelid IN (pc_i.oid) AND pc_t.relname = ? AND pa.attrelid = pc_t.oid AND pa.attnum = ANY(pi.indkey) AND pc_i.relam = pam.oid');
		$stmt->execute([$table_name, $table_name]);
		$stmt->setFetchMode(\PDO::FETCH_ASSOC);
		foreach ($stmt as $index) {
			$name = $index['primary'] ? 'PRIMARY' : $index['index_name'];
			if (!isset($seq_in_index[$name])) {
				$seq_in_index[$name] = 1;
			}
			$this->_indexes[$table_name][$name][] = [
				'table_name'		=> $table_name,
				'temporary'			=> null,
				'unique'			=> $index['unique'],
				'if_not_exists'		=> null,
				'key_name'			=> $name,
				'column_name'		=> $index['column_name'],
				'seq_in_index'		=> $seq_in_index[$name]++,
				'collation'			=> null,
				'cardinality'		=> null,
				'comment'			=> null,
				'index_comment'		=> null,
				'order'				=> null,
				'index_type'		=> null,
				'sub_part'			=> null,
				'raw_data'			=> $index,
			];
		}
	}
135022
public function actionIndex()
    {
        $this->getSearchCriteria();
        $this->layout = static::TABLE_LAYOUT;
        return $this->render('index', [
            'searchModel' => $this->searchModel,
            'dataProvider' => $this->dataProvider,
        ]);
    }
464298
public function getIndexes($table, $schema = null)
    {
        $select = [
            'columns.column_name',
            'pg_class2.relname AS index_type'
        ];
        
        $where = [
            "pg_attribute.attrelid = pg_class1.oid AND pg_class1.relname='".$table."'",
            'columns.column_name = pg_attribute.attname AND columns.table_name=pg_class1.relname',
            'pg_class1.oid = pg_index.indrelid AND pg_attribute.attnum = ANY(pg_index.indkey)',
            'pg_class2.oid = pg_index.indexrelid'
        ];
        
        if ($schema) {
            $where[1] .= ' AND columns.table_schema="'.$schema.'"';
        }
        
        $query = $this
            ->getSelectQuery($select)
            ->from('pg_attribute')
            ->innerJoin('pg_class AS pg_class1', $where[0], false)
            ->innerJoin('information_schema.COLUMNS    AS columns', $where[1], false)
            ->innerJoin('pg_index', $where[2], false)
            ->innerJoin('pg_class AS pg_class2', $where[3], false)
            ->getQuery();
            
        return $this->query($query);
    }
687240
function generateDropIndexSql( $table, $index_name, $removed_index, $params )
    {
        return $this->OtherSchema->generateDropIndexSql( $table, $index_name, $removed_index, $params );
    }
487116
public function showTables()
	{
		$query = $this->getQuery(true)
			->select('table_name')
			->from('information_schema.tables')
			->where('table_type=' . $this->quote('BASE TABLE'))
			->where('table_schema NOT IN (' . $this->quote('pg_catalog') . ', ' . $this->quote('information_schema') . ' )');

		$this->setQuery($query);

		return $this->loadColumn();
	}
1287323
protected Index getIndexExample(final Database database, final Schema schema,
         final String tableName) {
      final Index example = new Index();
      if (tableName != null) {
         example.setTable((Table) new Table().setName(
               database.correctObjectName(getTableName(), Table.class)).setSchema(schema));
      }
      example.setName(database.correctObjectName(getIndexName(), Index.class));
      if (StringUtils.trimToNull(getColumnNames()) != null) {
         for (final String columnName : getColumnNames().split("\\s*,\\s*")) {
            final Column column = new Column(database.correctObjectName(columnName, Column.class));
            example.getColumns().add(column);
         }
      }
      return example;
   }
274476
public function addIndex(Index $index)
    {
        if ($this->hasIndex($index->getName())) {
            throw SchemaException::tableIndexAlreadyExists($this->getName(), $index->getName());
        }

        foreach ($index->getColumnNames() as $columnName) {
            if (!$this->hasColumn($columnName)) {
                throw SchemaException::tableColumnDoesNotExist($this->getName(), $columnName);
            }
        }

        foreach ($this->getIndexes() as $indexCandidate) {
            if ($indexCandidate->isBetterThan($index)) {
                return;
            }
        }

        foreach ($this->getIndexes() as $indexCandidate) {
            if ($index->isBetterThan($indexCandidate)) {
                $this->dropIndex($indexCandidate->getName());
            }
        }

        $this->indexes[$index->getName()] = $index;
    }
727450
public function showSchemaInList()
    {
        //change connection if provide
        if ($this->option('c')) {
            $this->schema->setConnection($this->option('c'));
            $this->schema->switchWrapper();
        }

        $tables = $this->schema->databaseWrapper->getTables();
        if (!count($tables)) {
            $this->warn('Database does not contain any table');
        }

        $tableName = $this->option('t');
        if (!empty($tableName)) {
            if ($this->isNamespaceModel($tableName)) {
                $tableName = $this->tableNameFromModel($tableName);
            }
            if (!in_array($tableName, $tables)) {
                $this->warn('Table name is not correct!');
                return false;
            }

            $attributes = $this->schema->databaseWrapper->getColumns($tableName);
            $rowsCount = $this->schema->getTableRowCount($tableName);
            $this->info($tableName . ' (rows: ' . $rowsCount . ')');
            foreach ($attributes as $attribute) {
                $this->line('  ' . $attribute['Field'] . '  ' . $attribute['Type']);
            }
            return true;
        }

        foreach ($this->schema->databaseWrapper->getSchema() as $key => $value) {
            $this->info($key . ' (rows: ' . $value['rowsCount'] . ')');
            foreach ($value['attributes'] as $attribute) {
                $this->line('  ' . $attribute['Field'] . '  ' . $attribute['Type']);
            }
            $this->line('');
        }
    }
895253
public function index() {
		$currentType = $this->request->getQuery('type');

		if (DatabaseLogsTable::isSearchEnabled()) {
			$query = $this->DatabaseLogs->find('search', ['search' => $this->request->getQuery()]);
		} else {
			$conditions = $this->DatabaseLogs->textSearch();
			if ($currentType) {
				$conditions['type'] = $currentType;
			}
			$query = $this->DatabaseLogs->find()->where($conditions);
		}
		$query = $query->select(['id', 'created', 'type', 'summary', 'count']);

		$logs = $this->paginate($query);
		$types = $this->DatabaseLogs->getTypes();

		$this->set(compact('logs', 'types', 'currentType'));
	}
139180
public function listTables()
    {
        $result = array();
        // Use mysqli extension API, because SHOW doesn't work
        // well as a prepared statement on MySQL 4.1.
        $sql = 'SHOW TABLES';
        if ($queryResult = $this->getConnection()->query($sql)) {
            while ($row = $queryResult->fetch_row()) {
                $result[] = $row[0];
            }
            $queryResult->close();
        } else {
            /**
             * @see Zend_Db_Adapter_Mysqli_Exception
             */
            // require_once 'Zend/Db/Adapter/Mysqli/Exception.php';
            throw new Zend_Db_Adapter_Mysqli_Exception($this->getConnection()->error);
        }
        return $result;
    }
817677
public function describeIndexes($conn, $table, $schema = null)
    {
        $dialect = $conn->getDialectType();
        $method = 'describeIndexes' . $dialect;
        if (!method_exists($this, $method)) {
            throw new Exception("Describe index for $dialect is not implemented yet");
        }
        return $this->$method($conn, $table, $schema);
    }
999274
protected function getIdsInfo($table, $fields_info = null, &$requested_fields = null, $requested_types = null)
    {
        $idsInfo = [];
        if (empty($requested_fields)) {
            $requested_fields = [];
            /** @type ColumnSchema[] $idsInfo */
            $idsInfo = static::getPrimaryKeys($fields_info);
            foreach ($idsInfo as $info) {
                $requested_fields[] = $info->getName(true);
            }
        } else {
            if (false !== $requested_fields = static::validateAsArray($requested_fields, ',')) {
                foreach ($requested_fields as $field) {
                    $ndx = strtolower($field);
                    if (isset($fields_info[$ndx])) {
                        $idsInfo[] = $fields_info[$ndx];
                    }
                }
            }
        }

        return $idsInfo;
    }
90105
public function getTableList()
	{
		$this->connect();

		$query = $this->getQuery(true);
		$query->select('table_name')
			->from('information_schema.tables')
			->where('table_type=' . $this->quote('BASE TABLE'))
			->where(
				'table_schema NOT IN (' . $this->quote('pg_catalog') . ', ' . $this->quote('information_schema') . ')'
			)
			->order('table_name ASC');

		$this->setQuery($query);

		return $this->loadColumn();
	}
1141030
public function getTables()
    {
        $objResult = $this->query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = current_schema() AND TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME ASC");
        $strToReturn = array();
        while ($strRowArray = $objResult->fetchRow()) {
            array_push($strToReturn, $strRowArray[0]);
        }
        return $strToReturn;
    }
437039
public function indexList($table)
    {
        $indexes = $this->query("EXEC sp_helpindex '$table';");
        $indexList = array();

        // Enumerate all basic indexes
        foreach ($indexes as $index) {
            if (strpos($index['index_description'], 'unique') !== false) {
                $indexType = 'unique ';
            } else {
                $indexType = 'index ';
            }

            // Extract name from index
            $baseIndexName = $this->buildMSSQLIndexName($table, '');
            $indexName = substr($index['index_name'], strlen($baseIndexName));

            // Extract columns
            $columns = $this->quoteColumnSpecString($index['index_keys']);
            $indexList[$indexName] = $this->parseIndexSpec($indexName, array(
                'name' => $indexName,
                'value' => $columns,
                'type' => $indexType
            ));
        }

        // Now we need to check to see if we have any fulltext indexes attached to this table:
        if ($this->database->fullTextEnabled()) {
            $result = $this->query('EXEC sp_help_fulltext_columns;');

            // Extract columns from this fulltext definition
            $columns = array();
            foreach ($result as $row) {
                if ($row['TABLE_NAME'] == $table) {
                    $columns[] = $row['FULLTEXT_COLUMN_NAME'];
                }
            }

            if (!empty($columns)) {
                $indexList['SearchFields'] = $this->parseIndexSpec('SearchFields', array(
                    'name' => 'SearchFields',
                    'value' => $this->implodeColumnList($columns),
                    'type' => 'fulltext'
                ));
            }
        }

        return $indexList;
    }
691795
public List<String> listIndexDefinitions(boolean used, List<String> tables)
  {
    String scansOp = used ? "!=" : "=";
    String sql
      = "SELECT pg_get_indexdef(x.indexrelid) AS indexdef "
      + "FROM pg_index x, pg_class c "
      + "WHERE x.indexrelid = c.oid "
      + "AND c.relname IN ( " + StringUtils.repeat("?", ",", tables.size())
      + ") "
      + "AND pg_stat_get_numscans(x.indexrelid) " + scansOp + " 0";
    return getJdbcTemplate().query(sql, tables.toArray(), stringRowMapper());
  }