I have table data1 with 2 field: user_id and data_id. I have 2 indexes on user_id and data_id. They are a non unique indexed.
a function:
FUNCTION user_filter(p_schema IN VARCHAR2,
p_object IN VARCHAR2) RETURN VARCHAR2 IS
BEGIN
RETURN 'user_id='||session_pkg.user_id;
END;
I register this function as rls policy on data1:
DBMS_RLS.ADD_POLICY(OBJECT_SCHEMA => '',
OBJECT_NAME => 'data1',
POLICY_NAME => 'user_filter',
POLICY_FUNCTION => 'user_filter');
To have best performance, do I have to create 1 more Index like following?
create index data3_idx on data (user_ID, data_id);
Thanks,
In general it would be wasteful to have three indexes for two columns
(data_id),(user_id,data_id)and(user_id)since Oracle can use the compound index for queries that filter onuser_idand queries that filter on both columns.In your case the
DBMS_RLS.ADD_POLICYprocedure will add the filteruser_id=XXto all requests on this object. This means that you could replace the index ondata_idwith a more efficient compound index.