| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
| |
Currently the normalization only exists in `primary_key` shorthand. It
should be moved to `new_column_definition` to also affect to
`add_column` with primary key.
|
|
|
|
|
|
|
| |
Currently implicit legacy primary key is compatible, but adding explicit
legacy primary key is not compatible. It should also be fixed.
Fixes #30664.
|
| |
|
|
|
|
|
|
|
| |
`change_column_{default,null,comment}` in mysql2 adapter are passing
`column.sql_type` as `type` to `change_column` to intend keeping
previous type. But `column_for` requires extra query, so use passing
`nil` to `type` explicitly in the internal for the purpose.
|
| |
|
| |
|
| |
|
|\
| |
| | |
Use algorithm while removing index with db:rollback
|
| |
| |
| |
| | |
Closes #24190
|
|/
|
|
|
|
|
|
|
|
|
|
| |
This fixes following warning:
```
/home/travis/build/rails/rails/activerecord/test/cases/instrumentation_test.rb:11: warning: `*' interpreted as argument prefix
/home/travis/build/rails/rails/activerecord/test/cases/instrumentation_test.rb:23: warning: `*' interpreted as argument prefix
/home/travis/build/rails/rails/activerecord/test/cases/instrumentation_test.rb:35: warning: `*' interpreted as argument prefix
/home/travis/build/rails/rails/activerecord/test/cases/instrumentation_test.rb:48: warning: `*' interpreted as argument prefix
/home/travis/build/rails/rails/activerecord/test/cases/instrumentation_test.rb:61: warning: `*' interpreted as argument prefix
```
|
|\
| |
| |
| |
| | |
jagthedrummer/jeremy/instrumentation-payload-names
Update payload names for `sql.active_record` instrumentation to be more descriptive.
|
| |
| |
| |
| | |
Fixes #30586.
|
| | |
|
|\ \
| | |
| | | |
Add :comment option for add_column [ci skip]
|
| |/ |
|
|\ \
| | |
| | | |
Add test validating that Model.attribute_names cache is busted
|
| | | |
|
| | | |
|
| | |
| | |
| | |
| | | |
`reflection.join_primary_key`
|
| | | |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
Since we have `Preloader#preload`, `Preloader::Association#preload` is a
little confusing. And also, since the `preload` method is an abstract
method, it is hard to read where `associated_records_by_owner` is
called. This refactors `Preloader::Association` to ease to read where
`associated_records_by_owner` is called.
|
| | |
| | |
| | |
| | |
| | |
| | | |
If collided named sequence already exists, newly created serial column
will generate alternative sequence name. Fix sequence name detection to
allow the alternative names.
|
| | |
| | |
| | |
| | | |
`options` is never assigned to `scope` as long as using splat hash.
|
| | | |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
Class level `update` and `destroy` are using `find` in the internal, so
it will raise `RecordNotFound` if given ids cannot find an object even
though the method already affect (update or destroy) to any objects.
These methods should return affected objects even in that case.
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
`Persistence::ClassMethods`
The docs are obviously for class level `update`, `destroy`, and
`delete`. It should be placed in `Persistence::ClassMethods` rather than
`Relation`. And also, these methods are not dependent on relation. So it
is not needed to delegate to `all` (plus, `klass.find` is faster than
`relation.find`).
|
| | | |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
given
Related 2b5f5cdd7c1d95716de6a206b6d09ccbb006dc17.
If `reflection.scope` isn't given, `reflection_scope` is always empty
scope. It is unnecessary to merge it.
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
Related 2b5f5cdd7c1d95716de6a206b6d09ccbb006dc17.
If `through_scope` is empty scope, it is unnecessary to merge it.
And also, comparing relations is a little expensive (will cause
`build_arel`). It is enough to use `empty_scope?` to determine whether
empty scope.
|
| | |
| | |
| | |
| | | |
`through_scope` is not empty scope if `options[:source_type]` is given.
|
| |/
|/|
| |
| |
| |
| |
| | |
* `rails db:migrate STEP = 2` will not rollback the migrations, instead
`rails db:rollback STEP = 2` will do the rollback.
* Also, rewritten `rails db:migrate VERSION` => `rails db:rollback VERSION`
for consistency.
|
| |
| |
| |
| |
| |
| |
| | |
It is only used `primary_key` and `connection` in the internal, so it is
not needed to delegate others to `klass` explicitly.
This doesn't change public behavior because `relation` will delegate
missing method to `klass`.
|
| |
| |
| |
| |
| | |
Because `collection.table_name` doesn't respect table alias.
Use `collection.arel_attribute` instead.
|
| |
| |
| |
| |
| |
| | |
Because `quoted_table_name` doesn't respect table alias. We should use
`arel_attribute` for that, so I added `column_name_from_arel_node` to
generate column name from an arel node.
|
|\ \
| | |
| | | |
Address random `test_or_with_bind_params` failures
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
Reported at https://travis-ci.org/rails/rails/jobs/274370258
- `Post.find([1, 2])` generates this query below:
```sql
SELECT "posts".* FROM "posts" WHERE "posts"."id" IN ($1, $2) [["id", 1], ["id", 2]]
```
- `Post.where(id: 1).or(Post.where(id: 2)).to_a` generates this query below:
```sql
SELECT "posts".* FROM "posts" WHERE ("posts"."id" = $1 OR "posts"."id" = $2) [["id", 1], ["id", 2]]
```
Most of the time these two queries return the same result but the order of records are not guaranteed
from SQL point of view then added `sort` before comparing them.
|
|/ /
| |
| |
| | |
So using `arel_attribute(primary_key).asc` in `batch_order` instead.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Before:
```sql
SELECT "posts".* FROM "posts" ORDER BY "posts"."id" ASC LIMIT ? [["LIMIT", 2]]
SELECT "posts".* FROM "posts" WHERE "posts"."id" > 2 ORDER BY "posts"."id" ASC LIMIT ? [["LIMIT", 2]]
SELECT "posts".* FROM "posts" WHERE "posts"."id" > 4 ORDER BY "posts"."id" ASC LIMIT ? [["LIMIT", 2]]
SELECT "posts".* FROM "posts" WHERE "posts"."id" > 6 ORDER BY "posts"."id" ASC LIMIT ? [["LIMIT", 2]]
SELECT "posts".* FROM "posts" WHERE "posts"."id" > 8 ORDER BY "posts"."id" ASC LIMIT ? [["LIMIT", 2]]
SELECT "posts".* FROM "posts" WHERE "posts"."id" > 10 ORDER BY "posts"."id" ASC LIMIT ? [["LIMIT", 2]]
```
After:
```sql
SELECT "posts".* FROM "posts" ORDER BY "posts"."id" ASC LIMIT ? [["LIMIT", 2]]
SELECT "posts".* FROM "posts" WHERE "posts"."id" > ? ORDER BY "posts"."id" ASC LIMIT ? [["id", 2], ["LIMIT", 2]]
SELECT "posts".* FROM "posts" WHERE "posts"."id" > ? ORDER BY "posts"."id" ASC LIMIT ? [["id", 4], ["LIMIT", 2]]
SELECT "posts".* FROM "posts" WHERE "posts"."id" > ? ORDER BY "posts"."id" ASC LIMIT ? [["id", 6], ["LIMIT", 2]]
SELECT "posts".* FROM "posts" WHERE "posts"."id" > ? ORDER BY "posts"."id" ASC LIMIT ? [["id", 8], ["LIMIT", 2]]
SELECT "posts".* FROM "posts" WHERE "posts"."id" > ? ORDER BY "posts"."id" ASC LIMIT ? [["id", 10], ["LIMIT", 2]]
```
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
`ActiveRecord::Associations::Preloader::Association`.
```
require 'active_record'
require 'benchmark/ips'
ActiveRecord::Base.establish_connection(ENV.fetch('DATABASE_URL'))
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define do
create_table :users, force: true do |t|
t.string :name, :email
t.integer :topic_id
t.timestamps null: false
end
create_table :topics, force: true do |t|
t.string :title
t.timestamps null: false
end
end
attributes = {
name: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
email: 'foobar@email.com'
}
class Topic < ActiveRecord::Base
has_many :users
end
class User < ActiveRecord::Base
belongs_to :topic
end
100.times do
User.create!(attributes)
end
users = User.first(50)
100.times do
Topic.create!(title: 'This is a topic', users: users)
end
Benchmark.ips do |x|
x.config(time: 10, warmup: 5)
x.report("preload") do
User.includes(:topic).all.to_a
end
end
```
```
Calculating -------------------------------------
preload 25.000 i/100ms
-------------------------------------------------
preload 251.772 (± 1.2%) i/s - 2.525k
```
```
Calculating -------------------------------------
preload 26.000 i/100ms
-------------------------------------------------
preload 270.392 (± 1.1%) i/s - 2.704k
```
|
|\ \
| | |
| | | |
PERF: Recover `ActiveRecord::pluck` performance.
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
```ruby
require 'active_record'
require 'benchmark/ips'
ActiveRecord::Base.establish_connection(ENV.fetch('DATABASE_URL'))
ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define do
create_table :users, force: true do |t|
t.string :name, :email
t.timestamps null: false
end
end
attributes = {
name: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
email: 'foobar@email.com'
}
class User < ActiveRecord::Base; end
1000.times do
User.create!(attributes)
end
Benchmark.ips do |x|
x.config(time: 10, warmup: 2)
x.report('pluck 1 column') do
User.pluck(:id)
end
x.report('pluck 2 columns') do
User.pluck(:id, :email)
end
x.report('pluck 1 column with scope') do
User.where(id: 1000).pluck(:id)
end
x.report('pluck 2 columns with scope') do
User.where(id: 1000).pluck(:id, :email)
end
end
```
```
Calculating -------------------------------------
pluck 1 column 122.000 i/100ms
pluck 2 columns 74.000 i/100ms
pluck 1 column with scope
615.000 i/100ms
pluck 2 columns with scope
515.000 i/100ms
-------------------------------------------------
pluck 1 column 1.272k (± 3.9%) i/s - 12.810k
pluck 2 columns 750.096 (± 3.3%) i/s - 7.548k
pluck 1 column with scope
6.074k (± 4.1%) i/s - 60.885k
pluck 2 columns with scope
5.158k (± 2.7%) i/s - 52.015k
```
```
Calculating -------------------------------------
pluck 1 column 126.000 i/100ms
pluck 2 columns 78.000 i/100ms
pluck 1 column with scope
457.000 i/100ms
pluck 2 columns with scope
434.000 i/100ms
-------------------------------------------------
pluck 1 column 1.266k (± 2.1%) i/s - 12.726k
pluck 2 columns 795.061 (± 3.0%) i/s - 7.956k
pluck 1 column with scope
4.660k (± 2.1%) i/s - 46.614k
pluck 2 columns with scope
4.355k (± 2.3%) i/s - 43.834k
```
```
Calculating -------------------------------------
pluck 1 column 126.000 i/100ms
pluck 2 columns 78.000 i/100ms
pluck 1 column with scope
539.000 i/100ms
pluck 2 columns with scope
481.000 i/100ms
-------------------------------------------------
pluck 1 column 1.308k (± 3.4%) i/s - 13.104k
pluck 2 columns 798.604 (± 2.8%) i/s - 8.034k
pluck 1 column with scope
5.530k (± 3.4%) i/s - 55.517k
pluck 2 columns with scope
4.914k (± 2.7%) i/s - 49.543k
```
```
Calculating -------------------------------------
pluck 1 column 139.000 i/100ms
pluck 2 columns 79.000 i/100ms
pluck 1 column with scope
580.000 i/100ms
pluck 2 columns with scope
526.000 i/100ms
-------------------------------------------------
pluck 1 column 1.337k (± 3.0%) i/s - 13.483k
pluck 2 columns 806.776 (± 2.7%) i/s - 8.137k
pluck 1 column with scope
5.924k (± 4.1%) i/s - 59.160k
pluck 2 columns with scope
5.276k (± 3.1%) i/s - 53.126k
```
|
| | |
| | |
| | |
| | |
| | |
| | | |
This method was moved from `JoinHelper` in 0fddc3c1, but it is only used
for `table.create_join` in the internal and `Nodes::InnerJoin` is
default join klass. So it is not needed to pass it explicitly.
|
| | |
| | |
| | |
| | |
| | | |
The superclass (`MacroReflection`) already have the same method
definition.
|
| | |
| | |
| | |
| | |
| | | |
`primary_key_type` is no longer used since #26718.
`quoted_table_name` is no longer used since Rails 3.1.
|
| | | |
|
| | |
| | |
| | |
| | | |
Fixes #30539.
|
| | |
| | |
| | |
| | |
| | |
| | | |
Because `table` is part of `reflection`, don't need to pass it
explicitly. And also, naming `alias_name` to `table` is a little
confusing. `aliased_table` is preferable than `alias_name`.
|
| | |
| | |
| | |
| | |
| | |
| | | |
`PolymorphicReflection` is an internal class that is used in
`ThroughReflection`. But `RuntimeReflection` is used for the head of
chain in `AssociationScope`. These are totally different things.
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
The order of scope evaluation should be from through scope to the
association's own scope. Otherwise the association's scope cannot affect
to through scope.
Fixes #13677.
Closes #28449.
|