You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# frozen_string_literal: truerequire"bundler/inline"gemfile(true)dosource"https://rubygems.org"git_source(:github){ |repo| "https://github.com/#{repo}.git"}# Activate the gem you are reporting the issue against.gem"activerecord","5.2.2"gem"sqlite3","~> 1.3.6"endrequire"active_record"require"minitest/autorun"require"logger"# This connection will do for database-independent bug reports.ActiveRecord::Base.establish_connection(adapter: "sqlite3",database: ":memory:")ActiveRecord::Base.logger=Logger.new(STDOUT)ActiveRecord::Schema.definedocreate_table:points,force: truedo |t|
t.integer:xt.integer:yendendclassPoint < ActiveRecord::BaseendclassBugTest < Minitest::Testdeftest_association_stuffPoint.create!(x: 1,y: 1)Point.create!(x: 1,y: 2)relation=Point.select(:x).distinct.offset(1)assert_equal[true,false,0,[]],[relation.empty?,# Actual: falserelation.exists?,# Actual: truerelation.count,relation.to_a]endend
Expected behavior
The test should pass.
Actual behavior
The test fails with empty? and exists?, due to the way Relation#exists? is implemented. It runs a query that looks like SELECT 1 AS one … LIMIT 1 to check for the existence of records, but DISTINCT is the crucial part of the original query because there is also OFFSET specified; the question is how many distinct records are there.
System configuration
Rails version: 5.2.2, 5.1.6.1, 6.0.0.beta1
Older versions may also be affected.
Ruby version: 2.6.1, 2.6.0, 2.5.3
The text was updated successfully, but these errors were encountered:
The `distinct` affects (reduces) rows of the result, so it is important
part when both `distinct` and `offset` are given.
Replacing SELECT clause to `1 AS one` and removing `distinct` and
`order` is just optimization for the `exists?`, we should not apply the
optimization for that case.
Fixesrails#35191.
Steps to reproduce
Expected behavior
The test should pass.
Actual behavior
The test fails with
empty?
andexists?
, due to the wayRelation#exists?
is implemented. It runs a query that looks likeSELECT 1 AS one … LIMIT 1
to check for the existence of records, but DISTINCT is the crucial part of the original query because there is also OFFSET specified; the question is how many distinct records are there.System configuration
Rails version: 5.2.2, 5.1.6.1, 6.0.0.beta1
Older versions may also be affected.
Ruby version: 2.6.1, 2.6.0, 2.5.3
The text was updated successfully, but these errors were encountered: