我正在创建一个具有一些复杂的底层关联的网络应用程序。为了解决我创建了一个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是否新建?
发布评论