Would there be any performance difference between ...
# suiteql
b
Would there be any performance difference between these two queries?
Copy code
SELECT
  table1.column1,
  table2.column1
FROM table1
JOIN table2 ON table2.id = table1.id
WHERE table1.a = 'foo'
  AND table1.b = 'bar'
  AND table2.a = 'foo'
  AND table2.b = 'bar'
Copy code
SELECT
  table1_filtered.column1,
  table2_filtered.column1
FROM (
  SELECT column1
  FROM table1
  WHERE a = 'foo'
    AND b = 'bar'
) table1_filtered
JOIN (
  SELECT column1
  FROM table2
  WHERE a = 'foo'
    AND b = 'bar'
) table2_filtered ON table2_filtered.id = table1_filtered.id
s
With these kind of things, you need to benchmark it with your data. You can also try an
INNER JOIN
, it allows the query optimiser to do some optimisations in some cases.
💯 1
b
Okay thanks. My thinking was maybe filtering the tables before joining them might make the joining quicker. Thanks for the tip!