public function listSpatialIndexes($table)
{
if (false !== strpos($table, '.')) {
list(, $table) = explode('.', $table);
}
$sql = "SELECT distinct i.relname, d.indkey, pg_get_indexdef(d.indexrelid) AS inddef, t.oid\n FROM pg_class t\n INNER JOIN pg_index d ON t.oid = d.indrelid\n INNER JOIN pg_class i ON d.indexrelid = i.oid\n WHERE i.relkind = 'i'\n AND d.indisprimary = 'f'\n AND t.relname = ?\n AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = ANY (current_schemas(false)) )\n ORDER BY i.relname";
$tableIndexes = $this->connection->fetchAll($sql, array($this->trimQuotes($table)));
$indexes = array();
foreach ($tableIndexes as $row) {
if (!preg_match('/using\\s+gist/i', $row['inddef'])) {
continue;
}
$sql = "SELECT a.attname, t.typname\n FROM pg_attribute a, pg_type t\n WHERE a.attrelid = {$row['oid']}\n AND a.attnum IN (" . implode(',', explode(' ', $row['indkey'])) . ')
AND a.atttypid = t.oid';
$stmt = $this->connection->executeQuery($sql);
$indexColumns = $stmt->fetchAll();
foreach ($indexColumns as $indexRow) {
if ('geometry' !== $indexRow['typname'] && 'geography' !== $indexRow['typname']) {
continue;
}
if (!isset($indexes[$row['relname']])) {
$indexes[$row['relname']] = array();
}
$indexes[$row['relname']][] = trim($indexRow['attname']);
}
}
return $indexes;
}