logoalt Hacker News

dapperdrakeyesterday at 2:22 PM2 repliesview on HN

Other way around. Aggregation is usually faster than a join.


Replies

sgarlandyesterday at 4:02 PM

Disagree, though in practice it depends on the query, cardinality of the various columns across table, indices, and RDBMS implementation (so, everything).

A simple equijoin with high cardinality and indexed columns will usually be extremely fast. The same join in a 1:M might be fast, or it might result in a massive fanout. In the case of the latter, if your RDBMS uses a clustering index, and if you’ve designed your schemata to exploit this fact (e.g. a table called UserPurchase that has a PK of (user_id, purchase_id)) can still be quite fast.

Aggregations often imply large amounts of data being retrieved, though this is not necessarily true.

show 3 replies
zjaffeetoday at 6:40 AM

I'm saying that a smaller amount of data means more compute is required for a join. Sorry if that wasn't clear.