Skip to content

Commit

Permalink
Use explicit inner joins to add tables in the postgres indexes lookup…
Browse files Browse the repository at this point in the history
…, as is done in the rails 3.1 codebase
  • Loading branch information
Empact committed Aug 16, 2011
1 parent d04ea0d commit 868b609
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/spatial_adapter/postgresql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ def indexes(table_name, name = nil)
# Changed from upstread: link to pg_am to grab the index type (e.g. "gist")
result = query(<<-SQL, name)
SELECT distinct i.relname, d.indisunique, d.indkey, t.oid, am.amname
FROM pg_class t, pg_class i, pg_index d, pg_attribute a, pg_am am
FROM pg_class t
INNER JOIN pg_index d ON t.oid = d.indrelid
INNER JOIN pg_class i ON d.indexrelid = i.oid
INNER JOIN pg_attribute a ON a.attrelid = t.oid
INNER JOIN pg_am am ON i.relam = am.oid
WHERE i.relkind = 'i'
AND d.indexrelid = i.oid
AND d.indisprimary = 'f'
AND t.oid = d.indrelid
AND t.relname = '#{table_name}'
AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname IN (#{schemas}) )
AND i.relam = am.oid
AND a.attrelid = t.oid
ORDER BY i.relname
SQL

Expand All @@ -184,10 +184,10 @@ def indexes(table_name, name = nil)
# Changed from upstream: need to get the column types to test for spatial indexes
columns = query(<<-SQL, "Columns for index #{row[0]} on #{table_name}").inject({}) {|attlist, r| attlist[r[1]] = [r[0], r[2]]; attlist}
SELECT a.attname, a.attnum, t.typname
FROM pg_attribute a, pg_type t
FROM pg_attribute a
INNER JOIN pg_type t ON a.atttypid = t.oid
WHERE a.attrelid = #{oid}
AND a.attnum IN (#{indkey.join(",")})
AND a.atttypid = t.oid
SQL

# Only GiST indexes on spatial columns denote a spatial index
Expand Down

0 comments on commit 868b609

Please sign in to comment.