0

I came across this answer for speeding up a query, saying to use

SELECT COUNT(*) FROM (SELECT DISTINCT column_name FROM table_name) AS temp;

instead of

COUNT(DISTINCT column_name)

How would one go about writing this change in activerecord (short of just writing as an sql statement)?

rene
  • 41,474
  • 78
  • 114
  • 152
Ryan Clark
  • 764
  • 1
  • 8
  • 29
  • Well, this answer is 5 years old, optimizer get more sophisticated. You should try first, if it actually returns a different plan (you might also check `SELECT COUNT(*) FROM (SELECT column_name FROM table_name GROUP BY column_name) AS temp;`, which is another rewrite). But a decent optimizer should create the same plan anyway. – dnoeth Nov 19 '18 at 19:44
  • I'd like to compare the plan for both but haven't had time. The timed results are similar though, so you may be correct - it might not matter. – Ryan Clark Nov 19 '18 at 19:56

0 Answers0