Skip to content

Commit

Permalink
Merge pull request #3683 from christos/schema_introspection_speedup
Browse files Browse the repository at this point in the history
Only used detailed schema introspection when doing a schema dump.
Conflicts:

	activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
  • Loading branch information
tenderlove committed Nov 18, 2011
1 parent 1b527d7 commit a31a805
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Expand Up @@ -572,6 +572,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) #:nodoc:
keys = []
sql = <<-SQL
SELECT t.constraint_type, k.column_name
Expand Down
Expand Up @@ -755,6 +755,13 @@ def show_variable(name)

# Returns a table's primary key and belonging sequence.
def pk_and_sequence_for(table) #:nodoc:
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) #:nodoc:
keys = []
sql = <<-SQL
SELECT t.constraint_type, k.column_name
Expand Down
4 changes: 3 additions & 1 deletion activerecord/lib/active_record/schema_dumper.rb
Expand Up @@ -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)
Expand Down

0 comments on commit a31a805

Please sign in to comment.