I am new to using Postgres and I have a question concerning Materialized views. I am currently using Postgres 9.6.0 and 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. 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.....
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? Or is there a setting within Postgres that needs to be set perhaps for data to be persistent in the materialized view?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With