Class: Arel::Visitors::MySQL
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
Arel::Visitors::ToSql
|
Defined in: | activerecord/lib/arel/visitors/mysql.rb |
Constant Summary
ToSql
- Inherited
Class Method Summary
Instance Attribute Summary
Instance Method Summary
-
#build_subselect(key, o)
private
MySQL
doesn’t automatically create a temporary table for use subquery, so we have to give it some prompting in the form of a subsubquery. -
#prepare_delete_statement(o)
private
Alias for #prepare_update_statement.
-
#prepare_update_statement(o)
(also: #prepare_delete_statement)
private
In the simple case,
MySQL
allows us to place JOINs directly into the UPDATE query. - #visit_Arel_Nodes_Bin(o, collector) private
- #visit_Arel_Nodes_Concat(o, collector) private
- #visit_Arel_Nodes_Cte(o, collector) private
- #visit_Arel_Nodes_IsDistinctFrom(o, collector) private
- #visit_Arel_Nodes_IsNotDistinctFrom(o, collector) private
- #visit_Arel_Nodes_NotRegexp(o, collector) private
- #visit_Arel_Nodes_NullsFirst(o, collector) private
- #visit_Arel_Nodes_NullsLast(o, collector) private
- #visit_Arel_Nodes_Regexp(o, collector) private
- #visit_Arel_Nodes_SelectCore(o, collector) private
-
#visit_Arel_Nodes_SelectStatement(o, collector)
private
:‘( To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter.
- #visit_Arel_Nodes_UnqualifiedColumn(o, collector) private
ToSql
- Inherited
Visitor
- Inherited
Constructor Details
This class inherits a constructor from Arel::Visitors::ToSql
Instance Method Details
#build_subselect(key, o) (private)
MySQL
doesn’t automatically create a temporary table for use subquery, so we have to give it some prompting in the form of a subsubquery.
# File 'activerecord/lib/arel/visitors/mysql.rb', line 93
def build_subselect(key, o) subselect = super # Materialize subquery by adding distinct # to work with MySQL 5.7.6 which sets optimizer_switch='derived_merge=on' unless has_limit_or_offset_or_orders?(subselect) core = subselect.cores.last core.set_quantifier = Arel::Nodes::Distinct.new end Nodes::SelectStatement.new.tap do |stmt| core = stmt.cores.last core.froms = Nodes::Grouping.new(subselect).as("__active_record_temp") core.projections = [Arel.sql(quote_column_name(key.name), retryable: true)] end end
#prepare_delete_statement(o) (private)
Alias for #prepare_update_statement.
# File 'activerecord/lib/arel/visitors/mysql.rb', line 89
alias :prepare_delete_statement :prepare_update_statement
#prepare_update_statement(o) (private) Also known as: #prepare_delete_statement
In the simple case, MySQL
allows us to place JOINs directly into the UPDATE query. However, this does not allow for LIMIT, OFFSET and ORDER. To support these, we must use a subquery.
# File 'activerecord/lib/arel/visitors/mysql.rb', line 81
def prepare_update_statement(o) if o.offset || has_group_by_and_having?(o) || has_join_sources?(o) && has_limit_or_offset_or_orders?(o) super else o end end
#visit_Arel_Nodes_Bin(o, collector) (private)
[ GitHub ]# File 'activerecord/lib/arel/visitors/mysql.rb', line 7
def visit_Arel_Nodes_Bin(o, collector) collector << "CAST(" visit o.expr, collector collector << " AS BINARY)" end
#visit_Arel_Nodes_Concat(o, collector) (private)
[ GitHub ]# File 'activerecord/lib/arel/visitors/mysql.rb', line 34
def visit_Arel_Nodes_Concat(o, collector) collector << " CONCAT(" visit o.left, collector collector << ", " visit o.right, collector collector << ") " collector end
#visit_Arel_Nodes_Cte(o, collector) (private)
[ GitHub ]# File 'activerecord/lib/arel/visitors/mysql.rb', line 72
def visit_Arel_Nodes_Cte(o, collector) collector << quote_table_name(o.name) collector << " AS " visit o.relation, collector end
#visit_Arel_Nodes_IsDistinctFrom(o, collector) (private)
[ GitHub ]# File 'activerecord/lib/arel/visitors/mysql.rb', line 49
def visit_Arel_Nodes_IsDistinctFrom(o, collector) collector << "NOT " visit_Arel_Nodes_IsNotDistinctFrom o, collector end
#visit_Arel_Nodes_IsNotDistinctFrom(o, collector) (private)
[ GitHub ]# File 'activerecord/lib/arel/visitors/mysql.rb', line 43
def visit_Arel_Nodes_IsNotDistinctFrom(o, collector) collector = visit o.left, collector collector << " <=> " visit o.right, collector end
#visit_Arel_Nodes_NotRegexp(o, collector) (private)
[ GitHub ]# File 'activerecord/lib/arel/visitors/mysql.rb', line 58
def visit_Arel_Nodes_NotRegexp(o, collector) infix_value o, collector, " NOT REGEXP " end
#visit_Arel_Nodes_NullsFirst(o, collector) (private)
[ GitHub ]# File 'activerecord/lib/arel/visitors/mysql.rb', line 62
def visit_Arel_Nodes_NullsFirst(o, collector) visit(o.expr.expr, collector) << " IS NOT NULL, " visit(o.expr, collector) end
#visit_Arel_Nodes_NullsLast(o, collector) (private)
[ GitHub ]# File 'activerecord/lib/arel/visitors/mysql.rb', line 67
def visit_Arel_Nodes_NullsLast(o, collector) visit(o.expr.expr, collector) << " IS NULL, " visit(o.expr, collector) end
#visit_Arel_Nodes_Regexp(o, collector) (private)
[ GitHub ]# File 'activerecord/lib/arel/visitors/mysql.rb', line 54
def visit_Arel_Nodes_Regexp(o, collector) infix_value o, collector, " REGEXP " end
#visit_Arel_Nodes_SelectCore(o, collector) (private)
[ GitHub ]#visit_Arel_Nodes_SelectStatement(o, collector) (private)
:‘( To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. dev.mysql.com/doc/refman/en/select.html
#visit_Arel_Nodes_UnqualifiedColumn(o, collector) (private)
[ GitHub ]# File 'activerecord/lib/arel/visitors/mysql.rb', line 13
def visit_Arel_Nodes_UnqualifiedColumn(o, collector) visit o.expr, collector end