instance method
fetch_indexes
Ruby on Rails edge
Since edge Private — implementation detail, not part of the public APISignature
fetch_indexes(tables)
No documentation comment.
Parameters
-
tablesreq
Source
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 947
def fetch_indexes(tables)
fetch_by_schema(tables) do |schema, group|
# t.relname comes last so #build_indexes can keep reading columns by position.
rows = query_rows(<<~SQL)
SELECT distinct i.relname, d.indisunique, d.indkey, pg_get_indexdef(d.indexrelid),
pg_catalog.obj_description(i.oid, 'pg_class') AS comment, d.indisvalid,
ARRAY(
SELECT pg_get_indexdef(d.indexrelid, k + 1, true)
FROM generate_subscripts(d.indkey, 1) AS k
ORDER BY k
) AS columns, t.relname
FROM pg_class t
INNER JOIN pg_index d ON t.oid = d.indrelid
INNER JOIN pg_class i ON d.indexrelid = i.oid
LEFT JOIN pg_namespace n ON n.oid = t.relnamespace
WHERE i.relkind IN ('i', 'I')
AND d.indisprimary = 'f'
AND n.nspname = #{schema} AND t.relname IN (#{quoted_table_names(group)})
ORDER BY i.relname
SQL
by_name = rows.group_by(&:last)
group.index_with { |table| build_indexes(table, rows_for(by_name, table)) }
end
end
Defined in activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb line 947
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaStatements