1. 27 1月, 2020 2 次提交
  2. 14 1月, 2020 1 次提交
  3. 11 10月, 2019 1 次提交
  4. 08 8月, 2019 1 次提交
  5. 07 8月, 2019 1 次提交
    • R
      Fix GROUP BY aggregation alias to not duplicate "_" chars · e62195e2
      Ryuta Kamizono 提交于
      c9e4c848 has one performance optimization for `aggregate_alias` to early
      returning by `aggregate_alias.match?(/\A\w+\z/)`, but it is caused a
      regression that failing deduplication for non word chars #36867.
      
      I've quited the optimization and add a test to prevent a future
      regression.
      
      Fixes #36867.
      e62195e2
  6. 02 8月, 2019 1 次提交
    • G
      Add tests for selecting aggregates · 05300be6
      Godfrey Chan 提交于
      These tests verifies that aggregates like `AVG` can be selected as
      "virtual attributes" on Active Record models and have the correct
      column type.
      05300be6
  7. 08 7月, 2019 1 次提交
  8. 17 6月, 2019 1 次提交
    • R
      PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute · cb0299c9
      Ryuta Kamizono 提交于
      GROUP BY with virtual count attribute is invalid for almost all
      databases, but it is valid for PostgreSQL, and it had worked until Rails
      5.2.2, so it is a regression for Rails 5.2.3 (caused by 311f0011).
      
      I can't find perfectly solution for fixing this for now, but I would not
      like to break existing apps, so I decided to allow referencing virtual
      count attribute in ORDER BY clause when GROUP BY aggrigation (it partly
      revert the effect of 311f0011) to fix the regression #36022.
      
      Fixes #36022.
      cb0299c9
  9. 11 6月, 2019 1 次提交
  10. 02 6月, 2019 1 次提交
    • Y
      Address test_pluck_columns_with_same_name failure due to nondeterministic sort order · 86384ea8
      Yasuo Honda 提交于
      ```ruby
      $ bundle exec rake test_postgresql
      ... snip ...
      Failure:
      CalculationsTest#test_pluck_columns_with_same_name [/home/yahonda/git/rails/activerecord/test/cases/calculations_test.rb:842]:
      --- expected
      +++ actual
      @@ -1 +1 @@
      -[["The First Topic", "The Second Topic of the day"], ["The Third Topic of the day", "The Fourth Topic of the day"]]
      +[["The Third Topic of the day", "The Fourth Topic of the day"], ["The First Topic", "The Second Topic of the day"]]
      ```
      86384ea8
  11. 22 5月, 2019 2 次提交
  12. 08 4月, 2019 1 次提交
  13. 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
  14. 26 2月, 2019 1 次提交
  15. 24 2月, 2019 2 次提交
  16. 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
  17. 18 1月, 2019 3 次提交
  18. 04 1月, 2019 1 次提交
  19. 02 1月, 2019 1 次提交
  20. 06 12月, 2018 1 次提交
  21. 03 12月, 2018 1 次提交
  22. 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
  23. 19 6月, 2018 1 次提交
  24. 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
  25. 09 3月, 2018 1 次提交
  26. 26 2月, 2018 1 次提交
  27. 13 2月, 2018 1 次提交
  28. 10 2月, 2018 1 次提交
  29. 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
  30. 07 1月, 2018 1 次提交
  31. 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
  32. 09 11月, 2017 2 次提交
  33. 14 10月, 2017 1 次提交
  34. 01 9月, 2017 1 次提交