▲ | ericHosick 4 days ago | |||||||||||||
To help understand why a complex query with many joins comes back empty, I like to provide helper debug functions that builds the query step by step. Each block checks one prerequisite and tells the user what’s missing: ```sql FUNCTION debug_user(user_id):
```because when you have a query that involves 6 relations, and you don't get results, it is nice to know why. | ||||||||||||||
▲ | FrancoisBosun 4 days ago | parent | next [-] | |||||||||||||
I do the "same thing", but using PostgreSQL `EXPLAIN ANALYZE`. EXPLAIN ANALYZE has information about the number of rows returned, which means I know exactly which node in the query plan failed to return expected values. | ||||||||||||||
| ||||||||||||||
▲ | iTokio 4 days ago | parent | prev [-] | |||||||||||||
You can can also run a detailed explain plan and with a suitable visualizer it’s trivial to see where the query fell apart. You get to see the actual data distribution this way. |