在 postgresql 中解释(缓冲区、分析)

Explain (buffers, analyse) in postgresql

我是 postgresql 的新手,我试图理解 explain(缓冲区、分析)指令。我有一个查询,我使用解释(缓冲区、分析)执行它。

我第一次执行它的性能比第二次差。此外,第一次我在 'hit' 旁边得到一个 'read' 参数,而第二次 'read' 不存在。

谁能帮我理解一下?

你第一次 select,页面变暖 - 它们被加载到缓存,一旦它们在 RAM 中 - 所有接下来的 selects 将更快(RAM 速度更高)。

相应地buffers显示读取,当页面不在缓存中时,cos postgres 读取它们,而当它们是热的时候没有读取,所以缓存被命中...

更新 docs:

BUFFERS

Include information on buffer usage. Specifically, include the number of shared blocks hit, read, dirtied, and written, the number of local blocks hit, read, dirtied, and written, and the number of temp blocks read and written. A hit means that a read was avoided because the block was found already in cache when needed. Shared blocks contain data from regular tables and indexes; local blocks contain data from temporary tables and indexes; while temp blocks contain short-term working data used in sorts, hashes, Materialize plan nodes, and similar cases. The number of blocks dirtied indicates the number of previously unmodified blocks that were changed by this query; while the number of blocks written indicates the number of previously-dirtied blocks evicted from cache by this backend during query processing. The number of blocks shown for an upper-level node includes those used by all its child nodes. In text format, only non-zero values are printed. This parameter may only be used when ANALYZE is also enabled. It defaults to FALSE.

令人惊讶的是,关于缓冲区的内容并不多 here