当前位置:网站首页>Jincang database kingbasees plug-in force_ view

Jincang database kingbasees plug-in force_ view

2022-06-25 11:07:00 Thousands of sails pass by the side of the sunken boat_

Catalog

1. force_view Introduce

2. force_view The birth of

3. force_view Is still invalid after recompiling :

4. Generation of effective view creates an effective view :

5. Use of valid views

6. Maintenance of view state maintenance of view state


1. force_view Introduce


force_view Is the invalid state of the view , The view is based on SQL Visual table of statement result set , Its content is defined by query . Views have invalid and valid states . Use an invalid view (force_view) When , If the invalid view is recompiled, it is still invalid , Then an error message will be thrown .


2. force_view The birth of


Create an invalid view :

Use create force view Create an invalid view . establish force view If the dependency check is successful , Create a valid view , Otherwise, it will be created as an invalid view . Here dependency checking is view compilation , The check in the view compilation phase mainly includes : Whether the dependent object exists 、 Whether the creator has a dependency on the object select Authority, etc .
create force view vtab as select * from tab; --tab non-existent
WARNING: View created with compilation errors
CREATE VIEW
select reloptions from sys_class where relname = 'vtab';
reloptions
----------------
{status=false}

A valid view becomes an invalid view :

Delete view dependency , Changing the view dependent column will make the dependent view invalid .
create or replace You may also replace a valid view with an invalid view .
create table tab(a int);
CREATE TABLE
create force view vtab as select * from tab;
CREATE VIEW
select reloptions from sys_class where relname = 'vtab';
reloptions
------------

drop table tab;
NOTICE: view vtab depends on table tab
DROP TABLE
select reloptions from sys_class where relname = 'vtab';
reloptions
----------------
{status=false}

3. force_view Use Recompile is still invalid :

Use ( Inquire about , Insert , Update, etc. ) When an invalid view , The view is recompiled . If compilation fails, the view is still invalid , Throw an error .
create force view vtab as select * from tab; --tab non-existent
WARNING: View created with compilation errors
CREATE VIEW
select reloptions from sys_class where relname = 'vtab';
reloptions
----------------
{status=false}
select * from vtab;
ERROR: view "vtab" is still invalid after recompiling

Valid after recompilation :

When using an invalid view , The view is recompiled . If compilation is successful , The view is valid , Operate the view according to user instructions .
create force view vtab as select * from tab; --tab non-existent
WARNING: View created with compilation errors
CREATE VIEW select reloptions from sys_class where relname = 'vtab';
reloptions
----------------
{status=false}
create table tab(a int);
CREATE TABLE
select * from vtab;
a
---
(0 rows)
select reloptions from sys_class where relname = 'vtab';
reloptions
---------------
{status=true}


4. Generation of effective views Create a valid view :

When creating a view, if the dependency check succeeds, it will be created as a valid view . Create view ( No force ), Dependency check failed , View creation will fail .
create table tab(a int);
CREATE TABLE
create force view vtab as select * from tab;
CREATE VIEW
select reloptions from sys_class where relname = 'vtab';
reloptions
------------

create view vtab1 as select * from tab1;
ERROR: relation "tab1" does not exist
LINE 1: create view vtab1 as select * from tab1;

Invalid view becomes valid view :

Use an invalid view , If view recompile succeeds , View becomes a valid view .
create force view vtab as select * from tab;
CREATE VIEW
select reloptions from sys_class where relname = 'vtab';
reloptions
----------------
{status=false}
create table tab(a int);
CREATE TABLE
select * from vtab;
a
---
(0 rows)
select reloptions from sys_class where relname = 'vtab';
reloptions
------------


5. Use of valid views

create table tab(a int);
CREATE TABLE
insert into tab values(3);
INSERT 0 1
create view vtab as select * from tab;
CREATE VIEW
select reloptions from sys_class where relname = 'vtab';
reloptions
------------

select * from vtab;
a
---
3


6. Maintenance of view state Maintenance of view state

1、 Delete or change view dependencies ( Column 、 Table, etc ), This change will affect the dependent views , Then all dependent views will be updated to invalid status
create table tab(a int);
CREATE TABLE
create view vtab as select * from tab;
CREATE VIEW
create view vvtab as select * from vtab;
CREATE VIEW
select relname, reloptions from sys_class where relname in ('vtab', 'vvtab');
relname | reloptions
---------+------------
vtab |
vvtab |
(2 rows)
drop table tab;
NOTICE: there are(is) 2 objects that depend(s) on it
DETAIL: view vtab depends on table tab
view vvtab depends on view vtab
DROP TABLE
select relname, reloptions from sys_class where relname in ('vtab', 'vvtab');
relname | reloptions
---------+----------------
vtab | {status=false}
vvtab | {status=false}
(2 rows)
2、 When using an invalid view , Will recompile the view . If the view is valid after compilation , Execute user instructions ; If the view is still invalid after compilation , Throw an error .
原网站

版权声明
本文为[Thousands of sails pass by the side of the sunken boat_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251044549906.html