SQL解释计划:什么是Materialize?
我要求 PostgreSQL 解释我的查询。部分解释是:
table_name --> Materialize
Materialize 有什么作用?我正在连接两个表,而不是视图或类似的东西。
I asked PostgreSQL to explain my query. Part of the explanation was:
table_name --> Materialize
What does materialize do? I'm joining two tables, not views or anything like that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
物化节点意味着树中它下面的任何内容的输出(可以是扫描,或全套连接或类似的东西)在执行上层节点之前被物化到内存中。这通常是在外部节点因某种原因需要可以重新扫描的源时完成的。
因此,在您的情况下,规划器正在确定对您的一个表的扫描结果将适合内存,并且它直到可以选择需要重新扫描的上连接操作,同时仍然更便宜。
A materialize node means the output of whatever is below it in the tree (which can be a scan, or a full set of joins or something like that) is materalized into memory before the upper node is executed. This is usually done when the outer node needs a source that it can re-scan for some reason or other.
So in your case, the planner is determining that the result of a scan on one of your tables will fit in memory, and it till make it possible to choose an upper join operation that requires rescans while still being cheaper.
这意味着它不能使用任何索引(或类似的方法)来提高连接效率,因此最后的手段是将其中一个表的结果具体化,以便在连接另一个表时使用较小的集合来处理。
It means that it can't use any index (or similar method) to make the join efficient, so as a last resort is materializes the result from one of the tables to have a smaller set to work with when joining against the other table.
在合并连接和嵌套循环连接中,数据库将“重新扫描”内循环。
基本上就像:
规划器将具体化内部循环表,这意味着将整个表加载到内存缓冲区中以避免昂贵的磁盘 IO 成本。
有用的链接。
In merge join and nested loop join, the database will "rescan" the inner loop.
Basically like:
The planner will materializes the inner loop table which means load the whole table in an in-memory buffer to avoid the expensive disk IO cost.
A useful link.
从更实证的角度来看,您可以执行
EXPLAIN ANALYZE
并保留这些结果,然后更改标志:再次运行相同的
EXPLAIN ANALYZE
来比较结果一行一行,您将确切地看到发生了什么变化,查询时间是好还是坏,等等。修改一长串查询配置标志并观察效果。https://www.postgresql.org/docs/current/runtime-配置查询.html
From a more empirical point of view, you can do your
EXPLAIN ANALYZE
and keep those results, then change the flag:Go and run the same
EXPLAIN ANALYZE
again to compare the results line by line and you will see exactly what changes, whether the query time is better or worse, etc. Tinker around with the long list of query config flags and observe the effects.https://www.postgresql.org/docs/current/runtime-config-query.html
可以说Materialize命令将创建一个表的视图(就像内存中的虚拟表或表的快照)
我们 用于通过在信息更丰富的上下文中呈现数据来增强数据的可见性,并通过向不需要查看数据/或我们不希望向其显示数据的用户隐藏关键或敏感数据来控制对数据的访问。
使用 Materialize/Snap-Shot 的主要好处是减少事后查询该表的成本。
在执行计划中同样指出,如果我们使用具体化,与不使用它时相比,我们可以获得多少好处!
解释检查执行计划
我忽略了这个
- ->
因为据我所知没有这样的运算符,加上 -- 之后会注释该表达式,我假设您只是指这个->
。我希望这有帮助..
We can say the
Materialize
command will create aView of a table
(just like a virtual table OR aSnapShot
of table in Memory)It is used to enhance visibility of the data by presenting it in a more informational context and to control access to the data by hiding critical or sensitive data from users who don't need to see it/or to whom we don't what to show it.
The main benefit of using Materialize/Snap-Shot is to reduce the cost of query on that table afterwards.
In execution plan the same states that how much benefit we may fetch if we use materialize compare to when it is not used!
Explain to check execution plan
I have ignored this
-->
as there is not such operator in my knowledge, plus the -- will comment the expression afterwards, I have assumed you meant this->
only.I hope this helps..