Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Check Constraint and Query optimisation

Richard LeggeJun 26 2020 — edited Jun 29 2020

Hi All,

SE 12.1

For some reason I was under the impression that if you have a check constraint on a column,that stops particular entries being inserted, when you query that column with a value that isn't allowed by the constraint, the optimiser would check the constraint first before continuing with the query, and not actually search for it..

i.e.

alter table TAB1 add constraint

not_a check ( COL_1  != 'A')

select * from TAB1 where COL_1 = 'A'

This query would not actually search the table TAB1.  Looking at the explain plan, its still doing a search for A via its index..

I'm asking, because Im looking at putting together a manual partitioning solution by creating multiple tables with different partition data, adding constraints on what data is allowed in each table. Then creating a view on them with a union of the tables. When testing however, the plan is still showing than its accessing each table and searching..

Many Thanks

Richard

This post has been answered by Jonathan Lewis on Jun 26 2020
Jump to Answer
Comments
Post Details
Added on Jun 26 2020
15 comments
946 views