Flattening subselects

The next thing is to flatten subselects. By getting rid of subselects, a couple more options to optimize the query will appear.

Here is what the query will look like after flattening the subselects:

SELECT * FROM a, b, c WHERE a.aid = c.cid AND aid = bid AND cid = 4;

It is now a normal join. Note we would have done that on our own but the planner will take care of those transformations for us anyway. The door is open for a key optimization.

Get Mastering PostgreSQL 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.