1. 10 2月, 2017 1 次提交
    • J
      Simplify and speed up Postgres query for primary_keys · d6529af2
      Jordan Lewis 提交于
      primary_keys(table) needs to query various metadata tables in Postgres to
      determine the primary key for the table. Previously, it did so using a
      complex common table expression against pg_constraint and pg_attribute.
      
      This patch simplifies the query by joining pg_index against pg_attribute
      instead of going through pg_constraint. This avoids an expensive unnest,
      window function query, and common table expression.
      
      EXPLAINing these queries in Postgres against a database with a single
      table with a composite primary key shows a 66% reduction in the plan and
      execute latencies. This is significant during application startup time,
      especially against very large schemas, where these queries would be even
      slower and more numerous.
      
      Closes #27949
      d6529af2
  2. 09 2月, 2017 1 次提交
  3. 07 2月, 2017 2 次提交
  4. 04 2月, 2017 2 次提交
    • R
      Restore the behaviour of the compatibility layer for integer-like PKs · 4db72741
      Ryuta Kamizono 提交于
      The PR #27384 changed migration compatibility behaviour.
      
      ```ruby
      class CreateMasterData < ActiveRecord::Migration[5.0]
        def change
          create_table :master_data, id: :integer do |t|
            t.string :name
          end
        end
      end
      
      ```
      
      Previously this migration created non-autoincremental primary key
      expected. But after the PR, the primary key changed to autoincremental,
      it is unexpected.
      
      This change restores the behaviour of the compatibility layer.
      4db72741
    • R
      Correctly dump integer-like primary key with default nil · 605837a6
      Ryuta Kamizono 提交于
      The PR #27384 changed integer-like primary key to be autoincrement
      unless an explicit default. This means that integer-like primary key is
      restored as autoincrement unless dumping the default nil explicitly.
      We should dump integer-like primary key with default nil correctly.
      605837a6
  5. 02 2月, 2017 1 次提交
  6. 31 1月, 2017 1 次提交
    • J
      Simplify Postgres query for column_definitions() · f9c6cbd5
      Jordan Lewis 提交于
      column_definitions() needs to fetch the collation for every column, if
      present. Previously, it did so using a correlated subquery - a subquery
      that references results from the outer scope.
      
      This patch updates the query to remove the subquery in favor of a
      simpler and more efficient JOIN clause.
      
      Running the two queries through EXPLAIN against Postgres additionally
      shows that the original form with a correlated subquery requires a
      Nested Loop Left Join, while the new form with a simple JOIN can use a
      more efficient Merge Left Join.
      f9c6cbd5
  7. 27 1月, 2017 1 次提交
  8. 22 1月, 2017 1 次提交
  9. 20 1月, 2017 1 次提交
  10. 19 1月, 2017 2 次提交
  11. 18 1月, 2017 2 次提交
  12. 17 1月, 2017 1 次提交
  13. 16 1月, 2017 1 次提交
  14. 14 1月, 2017 1 次提交
    • E
      Fix pool_from_any_process to use most recent spec · e15a23fa
      eileencodes 提交于
      If a process is forked more than once, the pool was grabbing the oldest
      spec, not the most recent spec. This wasn't noticed before because most
      folks are lilely forking the process only once.
      
      If you're forking the process multiple times however the wrong spec name
      will be returned and an incorrect connection will be used for the
      process.
      
      This fixes the issue by reversing the list of spec names so we can grab
      the most recent spec rather than the oldest spec.
      e15a23fa
  15. 13 1月, 2017 1 次提交
  16. 12 1月, 2017 1 次提交
  17. 05 1月, 2017 1 次提交
    • R
      Optimizing information_schema query for `foreign_keys` · 801a21e6
      Ryuta Kamizono 提交于
      Need `table_name` to avoid all databases scan.
      See https://dev.mysql.com/doc/refman/5.7/en/information-schema-optimization.html.
      
      ```
      > EXPLAIN SELECT fk.referenced_table_name AS 'to_table', fk.referenced_column_name AS 'primary_key', fk.column_name AS 'column', fk.constraint_name AS 'name', rc.update_rule AS 'on_update', rc.delete_rule AS 'on_delete' FROM information_schema.key_column_usage fk JOIN information_schema.referential_constraints rc USING (constraint_schema, constraint_name) WHERE fk.referenced_column_name IS NOT NULL AND fk.table_schema = 'activerecord_unittest' AND fk.table_name = 'fk_test_has_pk' AND rc.table_name = 'fk_test_has_pk'\G
      *************************** 1. row ***************************
                 id: 1
        select_type: SIMPLE
              table: fk
         partitions: NULL
               type: ALL
      possible_keys: NULL
                key: TABLE_SCHEMA,TABLE_NAME
            key_len: NULL
                ref: NULL
               rows: NULL
           filtered: NULL
              Extra: Using where; Open_full_table; Scanned 0 databases
      *************************** 2. row ***************************
                 id: 1
        select_type: SIMPLE
              table: rc
         partitions: NULL
               type: ALL
      possible_keys: NULL
                key: TABLE_NAME
            key_len: NULL
                ref: NULL
               rows: NULL
           filtered: NULL
              Extra: Using where; Open_full_table; Scanned 1 database; Using join buffer (Block Nested Loop)
      2 rows in set, 1 warning (0.00 sec)
      ```
      
      Fixes #27579.
      801a21e6
  18. 04 1月, 2017 6 次提交
    • R
      Revert "Merge pull request #21233 from... · 127509c0
      Rafael Mendonça França 提交于
      Revert "Merge pull request #21233 from mtsmfm/disable-referential-integrity-without-superuser-privileges"
      
      This reverts commit eeac6151, reversing
      changes made to 5c40239d.
      
      Reason: Broke the isolated tests.
      https://travis-ci.org/rails/rails/builds/188721346
      127509c0
    • R
      61b5f5d2
    • R
      Deprecate passing `name` to `indexes` like `tables` · 457e6c77
      Ryuta Kamizono 提交于
      Passing `name` to `tables` is already deprecated at #21601.
      Passing `name` to `indexes` is also unused.
      457e6c77
    • R
      Fix `select_rows` method signature for consistency · cb180359
      Ryuta Kamizono 提交于
      Related #22973, #24708.
      
      `select_all`, `select_one`, `select_value`, and `select_values` method
      signature is `(arel, name = nil, binds = [])`.
      But `select_rows` is `(sql, name = nil, binds = [])`.
      cb180359
    • J
      Compare deserialized values for `PostgreSQL::OID::Hstore` types · 8ded825b
      Jon Moss 提交于
      Per the regression commit below, the commit changes the behavior of
      `#changed?`to consult the `#changed_in_place?` method on `Type::Value` classes.
      Per this change, `PostgreSQL::OID::Hstore` needs to override this method
      in order to compare the deserialized forms of the two arguments. In
      Ruby, two hashes are considered equal even if their key order is
      different. This commit helps to bring that behavior to `Hstore` values.
      
      Fixes regression introduced by 8e633e50
      
      Fixes #27502
      8ded825b
    • S
      Consistently apply adapter behavior when serializing arrays · 0f1d0b1b
      Sean Griffin 提交于
      In f1a0fa9e we moved backend specific timestamp behavior out of the type
      and into the adapter. This was in line with our general attempt to
      reduce the number of adapter specific type subclasses. However, on PG,
      the array type performs all serialization, including database encoding
      in its serialize method.
      
      This means that we have converted the value into a string before
      reaching the database, so no adapter specific logic can be applied (and
      this also means that timestamp arrays were using the default `.to_s`
      method on the given object, which likely meant timestamps were being
      ignored in certain cases as well)
      
      Ultimately I want to do a more in depth refactoring which separates
      database serializer objects from the active model type objects, to give
      us a less awkward API for introducing the attributes API onto Active
      Model.
      
      However, in the short term, we follow the solution we've applied
      elsewhere for this. Move behavior off of the type and into the adapter,
      and use a data object to allow the type to communicate information up
      the stack.
      
      Fixes #27514.
      0f1d0b1b
  19. 01 1月, 2017 3 次提交
  20. 30 12月, 2016 5 次提交
  21. 29 12月, 2016 2 次提交
  22. 25 12月, 2016 2 次提交
  23. 24 12月, 2016 1 次提交