I think there's small misunderstanding of yours. I try to describe shortly what's going on when you run a query:
- 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 only.
- 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".
So there's no reason why planning time and execution time difference should be smaller. PostgreSQL want to keep planning time short to minimize it's impact on whole execution time.
All is written here in manual.
Note that the execution time does not include the planning time. If you want a clear example where the planning time alone is longer than the execution time, you can try query explain analyse select 1
.