I have this simple query that finds all transactions from accounts belonging to a specific login, with some extra conditions on the transactions.
SELECT t.id, t.date, t.amount, t.description FROM transaction t
INNER JOIN account ac ON t.account = ac.id AND ac.login_id = ${loginId}
WHERE t.processed = false AND t.updated_by_user = false
AND t.category = 'uncategorized' ;
Will this query perform faster with a subquery on accounts
, for example:
SELECT t.id, t.date, t.amount, t.description FROM transaction t
INNER JOIN (SELECT id FROM account WHERE login_id = ${loginId}) ac ON t.account = ac.id
WHERE t.processed = false AND t.updated_by_user = false
AND t.category = 'uncategorized' ;
I'd appreciate some insightful comments on this, thanks in advance!
EXPLAIN
on both? You could also do some timingsexplain (analyze, verbose) select ...
to verify that (but remember to run each statement several times to exclude the caching effects from the timing).