diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-03-30 14:11:40 -0300 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-03-30 14:11:43 -0300 |
commit | 7860bf11d862a6eb1bd9ada85bcd97f17a2cb536 (patch) | |
tree | 22824f19b47eacbfea1f13b16d173895b38f8902 | |
parent | cbfa91a216384489e66f5e70eecebc455d334908 (diff) | |
download | rails-7860bf11d862a6eb1bd9ada85bcd97f17a2cb536.tar.gz rails-7860bf11d862a6eb1bd9ada85bcd97f17a2cb536.tar.bz2 rails-7860bf11d862a6eb1bd9ada85bcd97f17a2cb536.zip |
Do not calculate values if they are not going to be used
When building the indexes list in PostgreSQL, IndexDefinition objects
are only created if the query for the related attributes really returns
something matching the attributes.
In case it does not, the variables for building the definition objects were
being created but not used.
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index 0168c36abc..d9b807bba4 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -156,13 +156,15 @@ module ActiveRecord column_names = columns.values_at(*indkey).compact - # add info on sort order for columns (only desc order is explicitly specified, asc is the default) - desc_order_columns = inddef.scan(/(\w+) DESC/).flatten - orders = desc_order_columns.any? ? Hash[desc_order_columns.map {|order_column| [order_column, :desc]}] : {} - where = inddef.scan(/WHERE (.+)$/).flatten[0] - using = inddef.scan(/USING (.+?) /).flatten[0].to_sym - - column_names.empty? ? nil : IndexDefinition.new(table_name, index_name, unique, column_names, [], orders, where, nil, using) + unless column_names.empty? + # add info on sort order for columns (only desc order is explicitly specified, asc is the default) + desc_order_columns = inddef.scan(/(\w+) DESC/).flatten + orders = desc_order_columns.any? ? Hash[desc_order_columns.map {|order_column| [order_column, :desc]}] : {} + where = inddef.scan(/WHERE (.+)$/).flatten[0] + using = inddef.scan(/USING (.+?) /).flatten[0].to_sym + + IndexDefinition.new(table_name, index_name, unique, column_names, [], orders, where, nil, using) + end end.compact end |