Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

explaining postgres's EXPLAIN output

Tags:

sql

postgresql

I've read the documentation but I'd like to ask a more specific question in trying to understanding the EXPLAIN output.

The final step of a query is a nested loop left join and it says the cost is 0.01 ... 3108.35 rows=1 width=185. This step has a big grey arrow to an aggregate call which says cost 3044.87 ... 3044.89 rows=1 width=16.

enter image description here

Can someone breakdown what this is telling me? This is a relatively slow query that I am trying to optimize, and I'm trying to understand the cost aspect of the postgres explain output.

like image 319
Wells Avatar asked Jun 22 '26 12:06

Wells


1 Answers

I'll answer the question you specifically asked, but you probably need to post more information to get the answer you actually want:

What the graph is telling you is that the aggregate is what is taking up the vast majority of the query time. I would guess that the input to that aggregate is a sequential scan (based on the icon), and that sequential scan is the biggest contributor in its own right to the final output.

But, as someone commented above, go to explain.depesz.com and post a link to it for more thorough information

like image 74
Christophe Avatar answered Jun 25 '26 00:06

Christophe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!