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

Use result.rows as fastest alternative

This commit is contained in:
Ryuta Kamizono 2020-06-08 12:00:45 +09:00
parent cfb7c16ac4
commit 2ad2425fd3
3 changed files with 8 additions and 10 deletions

View file

@ -505,12 +505,12 @@ module ActiveRecord
# Result will have following sample string
# CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
# "password_digest" varchar COLLATE "NOCASE");
result = exec_query(sql, "SCHEMA").first
result = query_value(sql, "SCHEMA")
if result
# Splitting with left parentheses and discarding the first part will return all
# columns separated with comma(,).
columns_string = result["sql"].split("(", 2).last
columns_string = result.split("(", 2).last
columns_string.split(",").each do |column_string|
# This regex will match the column name and collation type and will save

View file

@ -367,14 +367,12 @@ module ActiveRecord
arel = query.arel
end
result = connection.select_one(arel, nil)
size, timestamp = connection.select_rows(arel, nil).first
if result
if size
column_type = klass.type_for_attribute(timestamp_column)
timestamp = column_type.deserialize(result["timestamp"])
size = result["size"]
timestamp = column_type.deserialize(timestamp)
else
timestamp = nil
size = 0
end
end

View file

@ -316,7 +316,7 @@ module ActiveRecord
relation = construct_relation_for_exists(conditions)
skip_query_cache_if_necessary { connection.select_one(relation.arel, "#{name} Exists?") } ? true : false
skip_query_cache_if_necessary { connection.select_rows(relation.arel, "#{name} Exists?").size == 1 }
end
# This method is called whenever no records are found with either a single
@ -416,8 +416,8 @@ module ActiveRecord
relation = relation.except(:select).select(values).distinct!
id_rows = skip_query_cache_if_necessary { @klass.connection.select_all(relation.arel, "SQL") }
id_rows.map { |row| row[primary_key] }
id_rows = skip_query_cache_if_necessary { @klass.connection.select_rows(relation.arel, "SQL") }
id_rows.map(&:last)
end
def using_limitable_reflections?(reflections)