Permalink
Browse files

Merge pull request #3683 from christos/schema_introspection_speedup

Only used detailed schema introspection when doing a schema dump.
  • Loading branch information...
2 parents 581ba1d + 280b2b7 commit 2debbe1581976d4694cb35ea7942c12f9224fb9f @tenderlove tenderlove committed Nov 18, 2011
@@ -576,6 +576,13 @@ def show_variable(name)
# Returns a table's primary key and belonging sequence.
def pk_and_sequence_for(table)
+ execute_and_free("DESCRIBE #{quote_table_name(table)}", 'SCHEMA') do |result|
+ keys = each_hash(result).select { |row| row[:Key] == 'PRI' }.map { |row| row[:Field] }
+ keys.length == 1 ? [keys.first, nil] : nil
+ end
+ end
+
+ def detailed_pk_and_sequence_for(table)
sql = <<-SQL
SELECT t.constraint_type, k.column_name
FROM information_schema.table_constraints t
@@ -86,7 +86,9 @@ def table(table, stream)
tbl = StringIO.new
# first dump primary key column
- if @connection.respond_to?(:pk_and_sequence_for)
+ if @connection.respond_to?(:detailed_pk_and_sequence_for)
+ pk, _ = @connection.detailed_pk_and_sequence_for(table)
+ elsif @connection.respond_to?(:pk_and_sequence_for)
pk, _ = @connection.pk_and_sequence_for(table)
elsif @connection.respond_to?(:primary_key)
pk = @connection.primary_key(table)

0 comments on commit 2debbe1

Please sign in to comment.