简体   繁体   English

Postgres:物化视图查询需要更长的时间来执行

[英]Postgres: Materialized Views query taking longer to execute

I am new to using Postgres and I have a question concerning Materialized views. 我是使用Postgres的新手,但是我对物化视图有疑问。 I am currently using Postgres 9.6.0 and PGAdmin 4. 我目前正在使用Postgres 9.6.0和PGAdmin 4。

I have a query that is composed of a number of joins and when it's executed in PGAdmin, it takes approximately 13 seconds. 我有一个由许多联接组成的查询,当它在PGAdmin中执行时,大约需要13秒钟。 This is true, considering the correct indices are set. 考虑到设置了正确的索引,这是正确的。

The next approach is to use Materialized Views. 下一种方法是使用实​​例化视图。 By using Materialized Views and setting the appropriate indices, I would have assumed that running a query would be a lot faster given that the data would be cached/ temporarily stored. 通过使用物化视图并设置适当的索引,我假设运行查询会更快,因为数据将被缓存/临时存储。 However after running the query, it looks like it still takes 13 seconds..... 但是,运行查询后,看起来仍然需要13秒.....

Unless my understanding of Materialized Views is not correct, can someone please explain why executing the materialized view would take as long as running the query. 除非我对物化视图的理解不正确,否则有人可以解释为什么执行物化视图需要花很长时间才能运行查询。 Could it be PGAdmin causing this issue? 可能是PGAdmin导致此问题吗? Or is there a setting within Postgres that needs to be set perhaps for data to be persistent in the materialized view? 还是在Postgres中是否需要设置某个设置,以使数据在实例化视图中持久存在?

Any advice is appreciated. 任何建议表示赞赏。 Thanks. 谢谢。

This is expected behavior for the simple case. 这是简单情况下的预期行为。 This means that the materialized view, which is a result of a query against indexes, performs exactly like the indexes from which it was derived. 这意味着,物化视图是对索引进行查询的结果,其性能与从其派生的索引完全相同。 This makes a lot of sense if you think about it. 如果您考虑一下,这很有意义。

Materialized views don't necessarily have better performance than the underlying query for the first access. 物化视图不一定具有比首次访问的基础查询更好的性能。 The complexity of assembly of the data may be trivial. 数据组装的复杂性可能很小。 A number of joins that use indices would be much less intensive than a complex set of criteria, or something that requires functional processing or sorting for example. 使用索引的许多联接的强度要比一组复杂的标准或需要功能处理或排序的强度低得多。

What you have found in this instance, is that the underlying query is just as good as a materialized view for the same dataset. 在此实例中发现的是,基础查询与同一数据集的物化视图一样好。 You might want to consider a simple view for this case. 您可能需要考虑这种情况的简单视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM