1. 22 5月, 2019 1 次提交
  2. 08 4月, 2019 1 次提交
  3. 04 4月, 2019 1 次提交
    • R
      Fix `count(:all)` with eager loading and explicit select and order · 060e09df
      Ryuta Kamizono 提交于
      This follows up ebc09ed9.
      
      We've still experienced a regression for `size` (`count(:all)`) with
      eager loading and explicit select and order when upgrading Rails to 5.1.
      
      In that case, the eager loading enforces `distinct` to subselect but
      still keep the custom select, it would cause the ORDER BY with DISTINCT
      issue.
      
      ```
      % ARCONN=postgresql bundle exec ruby -w -Itest test/cases/relations_test.rb -n test_size_with_eager_loading_and_custom_select_and_order
      Using postgresql
      Run options: -n test_size_with_eager_loading_and_custom_select_and_order --seed 8356
      
      # Running:
      
      E
      
      Error:
      RelationTest#test_size_with_eager_loading_and_custom_select_and_order:
      ActiveRecord::StatementInvalid: PG::InvalidColumnReference: ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select list
      LINE 1: ..." ON "comments"."post_id" = "posts"."id" ORDER BY comments.i...
                                                                   ^
      ```
      
      As another problem on `distinct` is enforced, the result of `count`
      becomes fewer than expected if `select` is given explicitly.
      
      e.g.
      
      ```ruby
      Post.select(:type).count
      # => 11
      
      Post.select(:type).distinct.count
      # => 3
      ```
      
      As long as `distinct` is enforced, we need to care to keep the result of
      `count`.
      
      This fixes both the `count` with eager loading problems.
      060e09df
  4. 26 2月, 2019 1 次提交
  5. 24 2月, 2019 2 次提交
  6. 13 2月, 2019 1 次提交
    • R
      Fix `pluck` and `select` with custom attributes · 0ee96d13
      Ryuta Kamizono 提交于
      Currently custom attributes are always qualified by the table name in
      the generated SQL wrongly even if the table doesn't have the named
      column, it would cause an invalid SQL error.
      
      Custom attributes should only be qualified if the table has the same
      named column.
      0ee96d13
  7. 18 1月, 2019 3 次提交
  8. 04 1月, 2019 1 次提交
  9. 02 1月, 2019 1 次提交
  10. 06 12月, 2018 1 次提交
  11. 03 12月, 2018 1 次提交
  12. 23 11月, 2018 1 次提交
    • G
      Redact SQL in errors · 192b7bcf
      Gannon McGibbon 提交于
      Move `ActiveRecord::StatementInvalid` SQL to error property.
      Also add bindings as an error property.
      192b7bcf
  13. 19 6月, 2018 1 次提交
  14. 07 6月, 2018 1 次提交
    • R
      Fix GROUP BY queries to apply LIMIT/OFFSET after aggregations · 63e35a13
      Ryuta Kamizono 提交于
      If `eager_loading` is true, `apply_join_dependency` force applies
      LIMIT/OFFSET before JOINs by `limited_ids_for` to keep parent records
      count. But for aggregation queries, LIMIT/OFFSET should be applied after
      aggregations the same as SQL semantics.
      
      And also, we could not replace SELECT list by `limited_ids_for` when a
      query has a GROUP BY clause. It had never been worked since it will
      causes generating invalid SQL for MySQL, PostgreSQL, and probably most
      backends.
      
      ```
      % ARCONN=postgresql be ruby -w -Itest test/cases/calculations_test.rb -n test_group_by_with_limit
      Using postgresql
      Run options: -n test_group_by_with_limit --seed 20925
      
      # Running:
      
      E
      
      Error:
      CalculationsTest#test_group_by_with_limit:
      ActiveRecord::StatementInvalid: PG::GroupingError: ERROR:  column "posts.id" must appear in the GROUP BY clause or be used in an aggregate function
      LINE 1: SELECT  DISTINCT "posts"."id", "posts"."type" AS alias_0 FRO...                         ^
      : SELECT  DISTINCT "posts"."id", "posts"."type" AS alias_0 FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id" GROUP BY "posts"."type" ORDER BY "posts"."type" ASC LIMIT $1
      ```
      
      Fixes #8103.
      Closes #27249.
      63e35a13
  15. 09 3月, 2018 1 次提交
  16. 26 2月, 2018 1 次提交
  17. 13 2月, 2018 1 次提交
  18. 10 2月, 2018 1 次提交
  19. 25 1月, 2018 1 次提交
    • R
      Fix `count(:all)` with eager loading and having an order other than the driving table · ebc09ed9
      Ryuta Kamizono 提交于
      This is a regression caused by 6beb4de7.
      
      In PostgreSQL, ORDER BY expressions must appear in SELECT list when
      using DISTINCT.
      
      When using `count(:all)` with eager loading, Active Record enforces
      DISTINCT to count the driving table records only. 6beb4de7 was caused the
      regression because `count(:all)` with DISTINCT path no longer removes
      ORDER BY.
      
      We need to ignore ORDER BY when DISTINCT is enforced, otherwise not
      always generated valid SQL for PostgreSQL.
      
      Fixes #31783.
      ebc09ed9
  20. 07 1月, 2018 1 次提交
  21. 20 12月, 2017 1 次提交
    • R
      Fix `count(:all)` to correctly work `distinct` with custom SELECT list · c6cd9a59
      Ryuta Kamizono 提交于
      Currently `count(:all)` with `distinct` doesn't work correctly because
      SELECT list is always replaced to `*` or primary key in that case even
      if having custom SELECT list.
      
      And also, PostgreSQL has a limitation that ORDER BY expressions must
      appear in select list for SELECT DISTINCT.
      
      Therefore, we should not replace custom SELECT list when using
      `count(:all)` with `distinct`.
      
      Closes #31277.
      c6cd9a59
  22. 09 11月, 2017 2 次提交
  23. 14 10月, 2017 1 次提交
  24. 01 9月, 2017 1 次提交
  25. 22 7月, 2017 2 次提交
  26. 20 7月, 2017 1 次提交
  27. 06 7月, 2017 1 次提交
    • E
      Skip query cache for in_batches and friends · 6658e374
      Eugene Kenny 提交于
      The `find_each`, `find_in_batches` and `in_batches` APIs usually operate
      on large numbers of records, where it's preferable not to load them all
      into memory at once.
      
      If the query cache is enabled, it will hold onto the query results until
      the end of the execution context (request/job), which means the memory
      used is still proportional to the total number of records. These queries
      are typically not repeated, so the query cache isn't desirable here.
      6658e374
  28. 02 7月, 2017 1 次提交
  29. 01 7月, 2017 1 次提交
  30. 06 6月, 2017 2 次提交
    • K
      b8dea23c
    • Y
      Load schema before assertion · c40502f9
      yuuji.yaginuma 提交于
      Without this, test fails because the load schema when pluck is executed.
      
      Steps to reproduce:
      
      ```
      bin/test -a postgresql -w --seed 61689 test/cases/*test.rb -n "/^(?:InheritanceComputeTypeTest#(?:test_inheritance_new_with_subclass_as_default)|CalculationsTest#(?:test_pluck_loaded_relation))$/"
      
      # Running:
      
      .F
      
      Failure:
      CalculationsTest#test_pluck_loaded_relation [/home/yaginuma/program/rails/master_y_yagi/rails/activerecord/test/cases/calculations_test.rb:722]:
      1 instead of 0 queries were executed.
      Queries:
      SELECT c.relname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE n.nspname = ANY (current_schemas(false)) AND c.relname = 'companies' AND c.relkind IN ('r','v','m').
      Expected: 0
        Actual: 1
      
      bin/test test/cases/calculations_test.rb:7
      ```
      c40502f9
  31. 29 5月, 2017 1 次提交
  32. 01 3月, 2017 1 次提交
  33. 28 2月, 2017 1 次提交
  34. 27 2月, 2017 1 次提交