Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / February 2007

Tip: Looking for answers? Try searching our database.

SELECTIVITY clause with BETWEEN predicate

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
4.spam@mail.ru - 07 Feb 2007 09:58 GMT
Hello.

v8.2.7

This procedure is not working (SQL20046N):
---
create procedure tst(nm1 varchar(20), nm2 varchar(20))
language sql
dynamic result sets 1
begin
 declare stmt varchar(4096);
 declare c1 cursor with return for s1;
 set stmt=
   'select tabname, colname '
 ||'from syscat.columns '
 ||'where tabschema=''SYSCAT'' '
 ||'and tabname between ? and ? '
 ||'selectivity 0.01 '
 ;
 prepare s1 from stmt;
 open c1 using nm1, nm2;
end
@
---
But if I do
---
...
 ||'and tabname=? '
 ||'selectivity 0.01 '
 ;
 prepare s1 from stmt;
 open c1 using nm1;
...
---
it works.

Q:
SELECTIVITY clause with BETWEEN predicate is not allowed?
Why?
It would be very useful...

Sincerely,
Mark B.
Knut Stolze - 07 Feb 2007 10:07 GMT
> Hello.
>
[quoted text clipped - 26 lines]
>   ||'selectivity 0.01 '
>   ;

It shouldn't work here either.  Looks like a defect to me.

>   prepare s1 from stmt;
>   open c1 using nm1;
[quoted text clipped - 6 lines]
> Why?
> It would be very useful...

No, it is not useful.  It is the optimizer's job to figure out the correct
selectivity.

The SELECTIVITY clause is a way to tell the DB2 optimizer what to expect for
extended indexes (see CREATE INDEX EXTENSION).

Signature

Knut Stolze
DB2 z/OS Utilities Development
IBM Germany

4.spam@mail.ru - 07 Feb 2007 10:30 GMT
> It shouldn't work here either.  Looks like a defect to me.

How about this article:
http://www-128.ibm.com/developerworks/db2/library/tips/dm-0312yip/
?

> No, it is not useful.  It is the optimizer's job to figure out the correct
> selectivity.

How would you figure out the correct selectivity for this dynamically
prepared statement:
select * from tab where dt between ? and ?;
for table:
create table tab (dt date primary key);
?
Knut Stolze - 07 Feb 2007 10:53 GMT
>> It shouldn't work here either.  Looks like a defect to me.
>
> How about this article:
> http://www-128.ibm.com/developerworks/db2/library/tips/dm-0312yip/
> ?

I wasn't aware that you set the DB2 registry variable DB2_SELECTIVITY to
YES.  If you don't do that, then SELECTIVITY is applicable to user-defined
predicates as the error message says.

>> No, it is not useful.  It is the optimizer's job to figure out the
>> correct selectivity.
>
> How would you figure out the correct selectivity for this dynamically
> prepared statement:
> select * from tab where dt between ? and ?;

Ok, you are right on that.  The optimizer can only guess/use defaults there
or rely on some sort of statistics and information about previous queries.

Signature

Knut Stolze
DB2 z/OS Utilities Development
IBM Germany

Serge Rielau - 07 Feb 2007 13:03 GMT
>> How about this article:
>> http://www-128.ibm.com/developerworks/db2/library/tips/dm-0312yip/
[quoted text clipped - 3 lines]
> YES.  If you don't do that, then SELECTIVITY is applicable to user-defined
> predicates as the error message says.
You can also set it to ALL. In that case there are virtually no
restrictions on where it can be used. However obedience by the optimizer
is also limited to "best effort".

If there are "typical" scenarios for the BETWEEN with parameter markers
I would recommend looking into REOPT(ONCE) re-optimization. That way the
optimizer is trained using the very set of actual values.

Cheers
Serge
Signature

Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

4.spam@mail.ru - 07 Feb 2007 13:29 GMT
> If there are "typical" scenarios for the BETWEEN with parameter markers
> I would recommend looking into REOPT(ONCE) re-optimization. That way the
> optimizer is trained using the very set of actual values.

But what shall I do in cli application?
AFAIK REOPT applicable only to packages. Is it true?
I don't want to rebind cli packages with this option.
And I couldn't find any "online" command to change optimizator's
behaviour (to use or not to use re-optimization) in cli
applications...
Serge Rielau - 07 Feb 2007 13:45 GMT
>> If there are "typical" scenarios for the BETWEEN with parameter markers
>> I would recommend looking into REOPT(ONCE) re-optimization. That way the
[quoted text clipped - 6 lines]
> behaviour (to use or not to use re-optimization) in cli
> applications...

I'm not sure how it works with CLI..

Cheers
Serge
Signature

Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.