VastbaseG100

基于openGauss内核开发的企业级关系型数据库。

Menu

兼容VPD功能

vastbase=# create schema vpd;
CREATE SCHEMA
vastbase=# set search_path to vpd;
SET
vastbase=# create table t1(id1 int, id2 int);
CREATE TABLE
vastbase=# create or replace function f1(schema text, object text) 
vastbase-# returns text as $$
vastbase$# declare                                           
vastbase$# begin                         
vastbase$#   return 'id1 between 1 and 2 and id2 between 3 and 4';
vastbase$# end;
vastbase$# $$
vastbase-# language plpgsql;
CREATE FUNCTION
vastbase=# select dbms_rls.add_policy(
vastbase(#     object_name => 't1',
vastbase(#     policy_name => 'mypolicy1',
vastbase(#     policy_function => 'f1',
vastbase(#     object_schema => 'vpd',
vastbase(#     function_schema => 'vpd',
vastbase(#     enable => true
vastbase(# );
 add_policy 
------------
 
(1 row)

vastbase=# explain (COSTS false) select id1 from t1; 
                             QUERY PLAN                              
---------------------------------------------------------------------
 Seq Scan on t1
   Filter: ((id1 >= 1) AND (id1 <= 2) AND (id2 >= 3) AND (id2 <= 4))
(2 rows)

vastbase=# explain (COSTS false) select id2 from t1;
                             QUERY PLAN                              
---------------------------------------------------------------------
 Seq Scan on t1
   Filter: ((id1 >= 1) AND (id1 <= 2) AND (id2 >= 3) AND (id2 <= 4))
(2 rows)

vastbase=# explain (COSTS false) select * from t1 where id2=10;
                                     QUERY PLAN                                     
------------------------------------------------------------------------------------
 Seq Scan on t1
   Filter: ((id1 >= 1) AND (id1 <= 2) AND (id2 >= 3) AND (id2 <= 4) AND (id2 = 10))
(2 rows)

vastbase=# explain (COSTS false) delete from t1;
                                QUERY PLAN                                 
---------------------------------------------------------------------------
 Delete on t1
   ->  Seq Scan on t1
         Filter: ((id1 >= 1) AND (id1 <= 2) AND (id2 >= 3) AND (id2 <= 4))
(3 rows)

vastbase=# explain (COSTS false) delete from t1 where id1 = 1;
                                       QUERY PLAN                                        
-----------------------------------------------------------------------------------------
 Delete on t1
   ->  Seq Scan on t1
         Filter: ((id1 >= 1) AND (id1 <= 2) AND (id2 >= 3) AND (id2 <= 4) AND (id1 = 1))
(3 rows)

vastbase=# explain (COSTS false) update t1 set id1=1;
                                QUERY PLAN                                 
---------------------------------------------------------------------------
 Update on t1
   ->  Seq Scan on t1
         Filter: ((id1 >= 1) AND (id1 <= 2) AND (id2 >= 3) AND (id2 <= 4))
(3 rows)