Planning Time和Execution Time相差很大,其实互相比较没什么意思
因为Planning Time是指定一个执行查询的最快方式(计划)所需的时间,postgres有一个 "query planner" 来实现的
而Execution Time是运行这个最快的查询计划,并且将结果输出的时间
下面国外的文章很好的解释了两者的区别:
- You write a query in SQL which is some kind of "script" that you try to tell the server what you want from him.
- Most of the times there is many ways for server to collect data you ask for by writing query. There is where mechanism called "query planner" comes in to action. It tries to find the quickest way (plan) of execution of your query. It's doing so by estimates execution time of several possible ways (plans).
- Server runs the query using the plan which is thought as the quickest one.
- Server returns you the output.
EXPLAIN
command prints you description of that process. Now:
- Execution time on
EXPLAIN
output is time server spent on steps 3-4. - Planning time on
EXPLAIN
output is time server spent on step 2 only. I believe you think of it as "time planner thinks that query would take", but that can be called "planned [execution] time" or "estimated execution time".