Reputation: 4637
Which will perform faster
1.
SELECT *
FROM test
WHERE id IN (1, 2, 3, 4, 5);
Or
2.
FOR s IN (SELECT id FROM ids)
LOOP
SELECT * FROM test where id = s.id;
END LOOP;
I think the first query will perform faster since it will be executed once but looking at second query it just need to fetch data related to one id which is going to be only one row at a time, that is confusing to me.
I just need to know conceptually that which one will perform better and which is correct way?
Upvotes: 2
Views: 1095
Reputation: 8905
Tom Kyte's mantra is:
I find it's a very usefull rule of thumb.
Upvotes: 3