{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/35214","repository_url":"https://api.github.com/repos/rails/rails","labels_url":"https://api.github.com/repos/rails/rails/issues/35214/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/35214/comments","events_url":"https://api.github.com/repos/rails/rails/issues/35214/events","html_url":"https://github.com/rails/rails/issues/35214","id":408553467,"node_id":"MDU6SXNzdWU0MDg1NTM0Njc=","number":35214,"title":"[activerecord] DISTINCT in select being dropped when using size on the relation","user":{"login":"cwardata","id":47308085,"node_id":"MDQ6VXNlcjQ3MzA4MDg1","avatar_url":"https://avatars3.githubusercontent.com/u/47308085?v=4","gravatar_id":"","url":"https://api.github.com/users/cwardata","html_url":"https://github.com/cwardata","followers_url":"https://api.github.com/users/cwardata/followers","following_url":"https://api.github.com/users/cwardata/following{/other_user}","gists_url":"https://api.github.com/users/cwardata/gists{/gist_id}","starred_url":"https://api.github.com/users/cwardata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cwardata/subscriptions","organizations_url":"https://api.github.com/users/cwardata/orgs","repos_url":"https://api.github.com/users/cwardata/repos","events_url":"https://api.github.com/users/cwardata/events{/privacy}","received_events_url":"https://api.github.com/users/cwardata/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2019-02-10T16:44:55Z","updated_at":"2019-02-19T12:01:41Z","closed_at":null,"author_association":"NONE","body":"### Steps to reproduce\r\n\r\n```\r\nSetting.select('DISTINCT key').size # select dropped\r\nSetting.select('DISTINCT key').to_a.size # returns correct result\r\n```\r\n\r\nSame with `DISTINCT ON`:\r\n\r\n```\r\nSetting.select('DISTINCT ON (key) *').size\r\nSetting.select('DISTINCT ON (key) *').to_a.size\r\n```\r\n\r\nFull test case: https://gist.github.com/cwardata/2db2f7364fb827d9906834a4182a873b\r\n\r\n### Expected behavior\r\n\r\n```\r\nSetting.select('DISTINCT key').size\r\n2\r\nSetting.select('DISTINCT key').to_a.size\r\n2\r\nSetting.select('DISTINCT ON (key) *').size\r\n2\r\nSetting.select('DISTINCT ON(key) *').to_a.size\r\n2\r\n```\r\n\r\n### Actual behavior\r\n\r\n```\r\nSetting.select('DISTINCT key').size\r\n3\r\nSetting.select('DISTINCT key').to_a.size\r\n2\r\nSetting.select('DISTINCT ON (key) *').size\r\n3\r\nSetting.select('DISTINCT ON(key) *').to_a.size\r\n2\r\n```\r\n\r\n### System configuration\r\n\r\n**Rails version**: latest from Github.\r\n\r\n**Ruby version**: `ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin14]`"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/465102721","html_url":"https://github.com/rails/rails/issues/35214#issuecomment-465102721","issue_url":"https://api.github.com/repos/rails/rails/issues/35214","id":465102721,"node_id":"MDEyOklzc3VlQ29tbWVudDQ2NTEwMjcyMQ==","user":{"login":"cwardata","id":47308085,"node_id":"MDQ6VXNlcjQ3MzA4MDg1","avatar_url":"https://avatars3.githubusercontent.com/u/47308085?v=4","gravatar_id":"","url":"https://api.github.com/users/cwardata","html_url":"https://github.com/cwardata","followers_url":"https://api.github.com/users/cwardata/followers","following_url":"https://api.github.com/users/cwardata/following{/other_user}","gists_url":"https://api.github.com/users/cwardata/gists{/gist_id}","starred_url":"https://api.github.com/users/cwardata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cwardata/subscriptions","organizations_url":"https://api.github.com/users/cwardata/orgs","repos_url":"https://api.github.com/users/cwardata/repos","events_url":"https://api.github.com/users/cwardata/events{/privacy}","received_events_url":"https://api.github.com/users/cwardata/received_events","type":"User","site_admin":false},"created_at":"2019-02-19T12:01:41Z","updated_at":"2019-02-19T12:01:41Z","author_association":"NONE","body":"I'm getting:\r\n\r\n```\r\nSetting.distinct.select('key').size\r\n2\r\nSetting.distinct.select('key').to_a.size\r\n2\r\n```\r\n\r\nSo using `.distinct` returns correct result at least, still using `DISTINCT` in a select seems to be supported, e.g. I get `SELECT DISTINCT key FROM \"settings\"` from `Setting.select('DISTINCT key').to_sql`"}}
{"actor":{"display_login":"cwardata"}}