Hi all,
Sorry for some mistakes in early post.
Here is the correct one.
db2 => create table emp(empno int not null primary key, \
db2 (cont.) => sex char(1) not null constraint s_check check \
db2 (cont.) => (sex in ('m','f')) \
db2 (cont.) => not enforced \
db2 (cont.) => enable query optimization)
DB20000I The SQL command completed successfully.
db2 => insert into emp values(1,'m')
DB20000I The SQL command completed successfully.
db2 => insert into emp values(2,'f')
DB20000I The SQL command completed successfully.
db2 => insert into emp values(3,'x')
DB20000I The SQL command completed successfully.
db2 => select * from emp
EMPNO SEX
----------- ---
1 m
2 f
3 x
3 record(s) selected.
db2 => select * from emp where sex = 'x'
EMPNO SEX
----------- ---
0 record(s) selected.
db2 => select * from emp where sex <> 'm'
EMPNO SEX
----------- ---
2 f
3 x
2 record(s) selected.
I have add the enable query optimization clause.. But how come the
last query is showing records with sex x??
My question is "If query optimization is enabled and the query has
been issued, the informational constraint having check values m and f
has to be considered." Am i Right??? Can any one justify for final
query response??
db2level
--------
DB21085I Instance "DB2" uses "32" bits and DB2 code release
"SQL08010" with
level identifier "01010106".
Informational tokens are "DB2 v8.1.0.36", "s021023", "", and FixPak
"0".
Product is installed at "C:\PROGRA~1\IBM\SQLLIB".
Thiru.
WantedToBeDBA.
Gert van der Kooij <ge**@invalid.nl> wrote in message news:<MP************************@news.xs4all.nl>.. .
In article <11*********************@l41g2000cwc.googlegroups. com>,
(ak************@yahoo.com) says... Gert,
I guess that during compilation of
select * from emp where sex = 'q'
the optimizer recognized the check constraint sex in ('m','f') and
eliminated the select altogether. Should the constraint be enforced, no
rows would meet the search criteria sex = 'q'. The optimizer has acted
as if the constraint were enforced, which is exactly as it should.
Regarding
select * from emp where sex <> 'm'
I guess the execution plan was tablespace scan, matching rows against
the search criteria
sex <> 'm'
I don't see any problem here, all worked as it should.
What do you think?
You should read the first post :)
I didn't have a problem, it was Thiru (a.k. WantedToBeDBA) who had a
problem when running the last SQL, it returned an 'x':
db2 => select * from emp where sex <> 'm'
EMPNO SEX
----------- ---
2 f
3 x
2 record(s) selected.