Comment

Comment by bob1029

I think my #1 rule for SQL these days is to abuse common table expressions as much as possible. No amount of whitespace cleanliness can compensate for a poorly organized problem. There is (in my mind) no longer an excuse for trying to join 10+ tables all at once in a single heroic attempt. Decompose the problem and let the query planner figure that shit out for you, just as you would with a compiler and code.

With CTEs you can offload sophisticated joins and constraints in such a way that less experienced developers can follow behind more easily.

Once you find multiple queries using the same WITH clauses, you can create more permanent views that further centralize and optimize these concerns.

parent bob1029 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton