I am hardly checking to find the execution speed of two queries, explain analyze and benchmark because i got timeout for one query but i am not sure this query was causing this.
queue_count = purchase.purchase_items.where("queue_id = ?", queue.id).count
same sql query
SELECT COUNT(*) FROM "purchase_items" WHERE "purchase_items"."purchase_id" = 1241422 AND (queue_id = 3479783)
so i have to remove the count then i got one solution to take all record in array and do the count then i got the query like this
queue_count = purchase.purchase_items.where("queue_id = ?", queue.id).all.count
same sql query
SELECT "purchase_items".* FROM "purchase_items" WHERE "purchase_items"."purchase_id" = 1241422 AND (queue_id = 3479783)
finally got some slight variation when i was checking with query analyze and also benchmark, so this was the correct way? or am i doing anything wrong?