Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: SQL
Expertise: Advanced
Apr 20, 2007



Application Security Testing: An Integral Part of DevOps

Predicate Pushing

Oracle supports the pushing of predicates into a given view. Suppose you have a set of layered views:

--View One
CREATE VIEW vw_layer_one
-- View Two
CREATE VIEW vw_layer_two_dept_100
AS SELECT * FROM vw_layer_one
WHERE deptno=100;
Then assume you issued this query:

SELECT * FROM vw_layer_two_dept_100
WHERE empid=100;
The predicate in this statement is WHERE empid=100;. You may have one of tens or even hundreds of predicates (if you have hundreds, you don't want to be supporting your SQL code!). In many cases, Oracle will push those predicates down into the views being called. Thus, Oracle will transform the vw_layer_one view into a SQL statement that looks like this:

CREATE VIEW vw_layer_one
WHERE deptno=100
AND empid=100;
Note that both the predicate from vw_layer_two (where deptno=100) and the predicate from the SQL statement being executed (where empid=100) are pushed down into the final view that is executed. This can have significant performance benefits, because now the bottom view can possibly use an index if one exists on deptno and/or empid.

Predicate pushing has a number of restrictions that are beyond the scope of this tip, but you can find them in the Oracle documentation. Also, any predicate pushing may result in a hard parse of the underlying SQL that is executed. Hence, it is important to make sure you use bind variables instead of literals in SQL code calling views. Your SQL should look something like this, for best performance:

SELECT * FROM vw_layer_two_dept_100
WHERE empid=:b100;
Shraddha Pandya
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date