每次查询PostgreSQL VIEWS是否新建?

编程入门 行业动态 更新时间:2024-10-26 00:27:03
本文介绍了每次查询PostgreSQL VIEWS是否新建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在创建一个具有一些复杂的底层关联的网络应用程序。为了解决我创建了一个UNION视图的几个问题。可能还有很多其他方法可以解决。

I am creating a web app which has some complex underlying associations. In order to solve several issues I was having I created a UNION View. There are probably a lot of other ways this could be solved.

但是,我正在考虑我的设计效率,我想知道一个VIEW是否新创建每次查询时,或者只创建一次,并保持更新。

But I am now considering the efficiency of my design, and I wanted to know if a VIEW is newly created each time it is queried, or is it only created once, and kept updated.

要详细说明,如果我有table_a(100条记录)和table_b(100条记录)和做一个UNION视图,然后我创建了一个包含200条记录的视图。

To elaborate, if I have table_a (100 records) and table_b (100 records) and make a UNION View, then I have created a view with 200 records.

这个整个过程是否每次对View进行选择?

Does this whole process occur each time I do a select against the View?

再次显示,每次更新底层表格记录时,视图都会更新,但视图是否会更新此记录,或者从头开始重新创建整个视图?

Again, obviously each time I update the underlying table records the view is updated, but does the view update this one record or does it recreate the whole view from scratch?

Dale

推荐答案

视图只不过是一个名称查询。有可能与perf相关的优化,一些DBMS实现比其他人更好(pgSQL似乎在更好的一面),如重用查询计划,缓存访问控制等。

A view is nothing more than a query with a name. There are possible perf-related optimizations, that some DBMS realize better than others (pgSQL seems to be on the better side), like reusing the query plan, cached access control etc.

然而,在他们这一天的结尾,几乎总是,你可以期待一个视图的行为就像直接发出SQL。有区别的是,您可以授予访问此查询的权限,允许访问底层表。

However, at the end of they day, almost always, you can expect a view to behave like issuing the SQL directly. With the difference that you can grant access to this query w/o granting access to the underlying tables.

有优化可以改变行为(使它们一半表格),这可能或可能不存在于pgSQL像物化视图(抱歉不知道关于pgSQL),但这只是nitpicking。

There are optimizations that you could do which change the behavior (make them half table-like) and that might or might not exist in pgSQL like materialized views (sorry no idea about pgSQL), but this is just nitpicking.

更多推荐

每次查询PostgreSQL VIEWS是否新建?

本文发布于:2023-10-22 22:31:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1518925.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PostgreSQL   VIEWS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!