Problem Statement
Which is often faster when deduplicating before a join inflates rows?
Explanation
De-duplicating early on the side that causes multiplicity prevents row explosion and shrinks the join inputs. That reduces memory, sorts, and downstream aggregation cost.
This pattern is especially useful when joining many-to-many relationships or dimension tables with duplicated keys.
Code Solution
SolutionRead Only
WITH d AS ( SELECT DISTINCT customer_id FROM clicks WHERE dt=:d ) SELECT ... FROM d JOIN customers c ON c.id=d.customer_id;
