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/unary.rb
Ryuta Kamizono 97347d8c40 Support Optimizer Hints
We as Arm Treasure Data are using Optimizer Hints with a monkey patch
(https://gist.github.com/kamipo/4c8539f0ce4acf85075cf5a6b0d9712e),
especially in order to use `MAX_EXECUTION_TIME` (refer #31129).

Example:

```ruby
class Job < ApplicationRecord
  default_scope { optimizer_hints("MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(jobs)") }
end
```

Optimizer Hints is supported not only for MySQL but also for most
databases (PostgreSQL on RDS, Oracle, SQL Server, etc), it is really
helpful to turn heavy queries for large scale applications.
2019-03-16 18:44:55 +09:00

45 lines
719 B
Ruby

# frozen_string_literal: true
module Arel # :nodoc: all
module Nodes
class Unary < Arel::Nodes::NodeExpression
attr_accessor :expr
alias :value :expr
def initialize(expr)
super()
@expr = expr
end
def hash
@expr.hash
end
def eql?(other)
self.class == other.class &&
self.expr == other.expr
end
alias :== :eql?
end
%w{
Bin
Cube
DistinctOn
Group
GroupingElement
GroupingSet
Lateral
Limit
Lock
Not
Offset
On
OptimizerHints
Ordering
RollUp
}.each do |name|
const_set(name, Class.new(Unary))
end
end
end