开发者

Postgres EXPLAIN ANALYZE is much faster than running the query normally

开发者 https://www.devze.com 2023-01-10 05:43 出处:网络
I\'m trying to optimise a PostgreSQL 8.4 query. After greatly simplifying the original query, trying to figure out what\'s making it choose a bad query plan, I got to the point where runni开发者_Pytho

I'm trying to optimise a PostgreSQL 8.4 query. After greatly simplifying the original query, trying to figure out what's making it choose a bad query plan, I got to the point where runni开发者_Python百科ng the query under EXPLAIN ANALYZE takes only 0.5s, while running it normally takes 2.8s. It seems obvious then, that what EXPLAIN ANALYZE is showing me is not what it normally does, so whatever it's showing me is useless, isn't it? What is going on here and how do I see what it's really doing?


Most likely, the data pages are in the OS disk cache when you are manually running with EXPLAIN ANALYZE in order to try and optimize the query. When run in a normal environment, the pages probably aren't in the cache already and have to be fetched from disk, increasing the runtime.


It shows less time because:

1) The Total runtime shown by EXPLAIN ANALYZE includes executor start-up and shut-down time, as well as the time to run any triggers that are fired, but it does not include parsing, rewriting, or planning time.

2)Since no output rows are delivered to the client, network transmission costs and I/O conversion costs are not included.

Warning!

The measurement overhead added by EXPLAIN ANALYZE can be significant, especially on machines with slow gettimeofday() operating-system calls. So, it's advisable to use EXPLAIN (ANALYZE TRUE, TIMING FALSE).

0

精彩评论

暂无评论...
验证码 换一张
取 消