You'll not like the consequences if somehow you'll force rails to run this in single query.
Because of the DISTINCT "posts"."id"
, rails manages to avoid
DISTINCT "posts"."*"
. Having the last one condition will force DB to compare records in full, instead of just the primary keys!
And I'm 100% sure that in case:
SELECT DISTINCT "posts"."id" FROM "posts"
LEFT OUTER JOIN "post_translations"
ON "post_translations"."post_id" = "posts"."id" LIMIT $1 [["LIMIT", 3]]
under the hood, this request happens to be Index Only Scan, unless of course you skipped corresponding indexes.
Here the difference between distincts, on a small size dataset: