1. 29 4月, 2020 1 次提交
    • R
      PERF: Improve performance of where when using an array of values · c3a2b54b
      Ryuta Kamizono 提交于
      This is a smaller alternative of performance improvement, without
      refactoring type casting mechanism #39009.
      
      This is relatively a smaller change (but about 40% faster than before),
      so I think this could be easier reviewed without discuss about
      refactoring type casting mechanism.
      
      This just makes `attribute.in(values)` less allocation from an array of
      casted nodes to one casted array node.
      
      ```ruby
      ids = (1..1000).each.map do |n|
        Post.create!.id
      end
      
      Benchmark.ips do |x|
        x.report("where with ids") do
          Post.where(id: ids).to_a
        end
      
        x.report("where with sanitize") do
          Post.where(ActiveRecord::Base.sanitize_sql(["id IN (?)", ids])).to_a
        end
      
        x.compare!
      end
      ```
      
      Before:
      
      ```
      Warming up --------------------------------------
            where with ids     7.000  i/100ms
       where with sanitize    13.000  i/100ms
      
      Calculating -------------------------------------
            where with ids     70.661  (± 5.7%) i/s -    357.000  in   5.072771s
       where with sanitize    130.993  (± 7.6%) i/s -    663.000  in   5.096085s
      
      Comparison:
       where with sanitize:      131.0 i/s
            where with ids:       70.7 i/s - 1.85x  slower
      ```
      
      After:
      
      ```
      Warming up --------------------------------------
            where with ids    10.000  i/100ms
       where with sanitize    13.000  i/100ms
      
      Calculating -------------------------------------
            where with ids     98.174  (± 7.1%) i/s -    490.000  in   5.012851s
       where with sanitize    132.289  (± 8.3%) i/s -    663.000  in   5.052728s
      
      Comparison:
       where with sanitize:      132.3 i/s
            where with ids:       98.2 i/s - 1.35x  slower
      ```
      c3a2b54b
  2. 07 1月, 2020 1 次提交
  3. 17 7月, 2019 1 次提交
    • J
      Support beginless ranges in hash conditions. · b1915044
      Josh Goodall 提交于
      Ruby 2.7 introduces beginless ranges (..value and ...value) and as with
      endless ranges we can turn these into inequalities, enabling expressions
      such as
      
          Order.where(created_at: ..1.year.ago)
          User.where(karma: ...0)
      b1915044
  4. 13 6月, 2019 1 次提交
  5. 18 1月, 2019 1 次提交
    • R
      All of queries should return correct result even if including large number · 31ffbf8d
      Ryuta Kamizono 提交于
      Currently several queries cannot return correct result due to incorrect
      `RangeError` handling.
      
      First example:
      
      ```ruby
      assert_equal true, Topic.where(id: [1, 9223372036854775808]).exists?
      assert_equal true, Topic.where.not(id: 9223372036854775808).exists?
      ```
      
      The first example is obviously to be true, but currently it returns
      false.
      
      Second example:
      
      ```ruby
      assert_equal topics(:first), Topic.where(id: 1..9223372036854775808).find(1)
      ```
      
      The second example also should return the object, but currently it
      raises `RecordNotFound`.
      
      It can be seen from the examples, the queries including large number
      assuming empty result is not always correct.
      
      Therefore, This change handles `RangeError` to generate executable SQL
      instead of raising `RangeError` to users to always return correct
      result. By this change, it is no longer raised `RangeError` to users.
      31ffbf8d
  6. 12 1月, 2019 1 次提交
  7. 11 1月, 2019 1 次提交
    • G
      Support endless ranges in where · 7110dbea
      Greg Navis 提交于
      This commit adds support for endless ranges, e.g. (1..), that were added
      in Ruby 2.6. They're functionally equivalent to explicitly specifying
      Float::INFINITY as the end of the range.
      7110dbea
  8. 08 1月, 2019 1 次提交
  9. 16 11月, 2018 1 次提交
    • D
      Arel: Implemented DB-aware NULL-safe comparison (#34451) · b5302d5a
      Dmytro Shteflyuk 提交于
      * Arel: Implemented DB-aware NULL-safe comparison
      
      * Fixed where clause inversion for NULL-safe comparison
      
      * Renaming "null_safe_eq" to "is_not_distinct_from", "null_safe_not_eq" to "is_distinct_from"
      
      [Dmytro Shteflyuk + Rafael Mendonça França]
      b5302d5a
  10. 24 2月, 2018 2 次提交