by twic · 8y ago · 0 comments
It's only O(n^2) if your DBMS uses nested loops to do this join. If it uses a merge join it's O(n log n) (plus you get an order by for 'free'), and if it uses a hash join it's O(n).
MySQL, last I checked, only supported various forms of nested loops, but first-class databases like PostgreSQL support the others.
http://www.postgresonline.com/journal/archives/27-Reading-Pg... (example pictures if anyone reading this hasn't seen it before), it is pretty cool.