What is Nostr?
AreWeThereYet /
npub1pr2…fkep
2024-05-27 15:47:49

AreWeThereYet on Nostr: Check out these 2 queries: Query 1: SELECT ... FROM t1 JOIN t2 ON t1.id IN (t2.id1, ...

Check out these 2 queries:

Query 1:

SELECT ...
FROM t1
JOIN t2 ON t1.id IN (t2.id1, t2.id2);

Query 2:

SELECT ...
FROM t1
JOIN t2 ON t1.id = t2.id1
UNION
SELECT ...
FROM t1
JOIN t2 ON t1.id = t2.id2;

They both return the same data but since most database engines struggle with OR joins, the latter will outperform the former by at least an order of magnitude.

#SQLTips #DatabaseOptimization #PerformanceTuning
Author Public Key
npub1pr2d8yya0f0ejktzhjkqlphapekqy0ucuyvtfeh7xnz39zwzp42s9ufkep