composite-primary-keys / composite_primary_keys

Composite Primary Keys support for Active Record
1.03k stars 350 forks source link

Use original implementation to execute COUNT without subquery. #550

Closed hrysd closed 3 years ago

hrysd commented 3 years ago

When operation like followings, CPK generates subquery always. And I don't think ActiveRecord::Calculations#execute_simple_calculation needs CPK specific implementation. So I stop to overwrite this. And I also don't think overwriting this need on master too. If this PR can merge. I'll create same PR to master

User.count(:id)
SELECT COUNT(count_column) FROM (SELECT `users`.`id` AS count_column FROM `users`) subquery_for_count
hrysd commented 3 years ago

As far as see test result, I think ActiveRecord::Calculation::aggregate_column is also unnecessary. but executed SQL could not resolve dup column. I'll investigate this and recreate PR.

cfis commented 3 years ago

Sounds good.