1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/lib/arel/nodes.rb

71 lines
1.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-02-24 01:45:50 -05:00
2010-12-15 00:06:16 -05:00
# node
2018-02-24 01:45:50 -05:00
require "arel/nodes/node"
require "arel/nodes/node_expression"
require "arel/nodes/select_statement"
require "arel/nodes/select_core"
require "arel/nodes/insert_statement"
require "arel/nodes/update_statement"
require "arel/nodes/bind_param"
2010-12-14 23:53:19 -05:00
2011-04-21 16:46:24 -04:00
# terminal
2018-02-24 01:45:50 -05:00
require "arel/nodes/terminal"
require "arel/nodes/true"
require "arel/nodes/false"
2011-04-21 16:46:24 -04:00
2010-12-15 00:06:16 -05:00
# unary
2018-02-24 01:45:50 -05:00
require "arel/nodes/unary"
require "arel/nodes/grouping"
Perf: Improve performance of where when using an array of values A coworker at GitHub found a few months back that if we used `santitize_sql` over `where` when we knew the values going into `where` it was a lot faster than `where`. This PR adds a new Arel node type called `HomogenousIn` that will be used when Rails knows the values are all homogenous and can therefore pick a faster codepath. This new codepath skips some of the required processing by `where` to make `wheres` with homogenous arrays faster without requiring the application author to know when to use which query type. Using our benchmark code: ```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 this PR comparing where with a list of IDs to santitize sql: ``` Warming up -------------------------------------- where with ids 11.000 i/100ms where with sanitize 17.000 i/100ms Calculating ------------------------------------- where with ids 115.733 (± 4.3%) i/s - 583.000 in 5.045828s where with sanitize 174.231 (± 4.0%) i/s - 884.000 in 5.081495s Comparison: where with sanitize: 174.2 i/s where with ids: 115.7 i/s - 1.51x slower ``` After this PR comparing where with a list of IDs to santitize sql: ``` Warming up -------------------------------------- where with ids 16.000 i/100ms where with sanitize 19.000 i/100ms Calculating ------------------------------------- where with ids 158.293 (± 6.3%) i/s - 800.000 in 5.072208s where with sanitize 169.141 (± 3.5%) i/s - 855.000 in 5.060878s Comparison: where with sanitize: 169.1 i/s where with ids: 158.3 i/s - same-ish: difference falls within error ``` Co-authored-by: Aaron Patterson <aaron.patterson@gmail.com>
2020-01-14 16:14:39 -05:00
require "arel/nodes/homogeneous_in"
require "arel/nodes/ordering"
2018-02-24 01:45:50 -05:00
require "arel/nodes/ascending"
require "arel/nodes/descending"
require "arel/nodes/unqualified_column"
require "arel/nodes/with"
2010-12-14 23:53:19 -05:00
2010-12-15 00:06:16 -05:00
# binary
2018-02-24 01:45:50 -05:00
require "arel/nodes/binary"
require "arel/nodes/equality"
require "arel/nodes/in"
2018-02-24 01:45:50 -05:00
require "arel/nodes/join_source"
require "arel/nodes/delete_statement"
require "arel/nodes/table_alias"
require "arel/nodes/infix_operation"
require "arel/nodes/unary_operation"
require "arel/nodes/over"
require "arel/nodes/matches"
require "arel/nodes/regexp"
2010-12-15 00:06:16 -05:00
# nary
2018-02-24 01:45:50 -05:00
require "arel/nodes/and"
2010-12-15 00:06:16 -05:00
# function
# FIXME: Function + Alias can be rewritten as a Function and Alias node.
# We should make Function a Unary node and deprecate the use of "aliaz"
2018-02-24 01:45:50 -05:00
require "arel/nodes/function"
require "arel/nodes/count"
require "arel/nodes/extract"
require "arel/nodes/values_list"
require "arel/nodes/named_function"
2010-12-15 00:06:16 -05:00
2012-02-22 09:25:10 -05:00
# windows
2018-02-24 01:45:50 -05:00
require "arel/nodes/window"
2012-02-22 09:25:10 -05:00
2015-12-19 13:40:46 -05:00
# conditional expressions
2018-02-24 01:45:50 -05:00
require "arel/nodes/case"
2015-12-19 13:40:46 -05:00
2010-12-15 00:06:16 -05:00
# joins
2018-02-24 01:45:50 -05:00
require "arel/nodes/full_outer_join"
require "arel/nodes/inner_join"
require "arel/nodes/outer_join"
require "arel/nodes/right_outer_join"
require "arel/nodes/string_join"
2010-12-15 00:06:16 -05:00
require "arel/nodes/comment"
2018-02-24 01:45:50 -05:00
require "arel/nodes/sql_literal"
2018-02-24 01:45:50 -05:00
require "arel/nodes/casted"