473,659 Members | 3,592 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BETWEEN operation on TIMESTAMP fileds

The following function is called repeatedly from a stored proc.

CREATE FUNCTION GetTaxRate
(
v_AsOfDate TIMESTAMP,
v_FilingStatusI d INT)
RETURNS DOUBLE
BEGIN ATOMIC
DECLARE v_retVal DOUBLE;
SET v_retVal =(select min(taxrate) FROM Tax_Table
WHERE (v_AsOfDate BETWEEN TaxYearStart AND TaxYearEnd) );

RETURN v_retVal;
END

The stored proc takes about 2 minutes to run (expected response time : 1
sec)
If I comment out the WHERE clause in the above function (just for testing),
the proc runs under 1 second.
If I run the function directly, it is quite fast (fraction of a second).

Tax_table has got just 70 rows in it. TaxYearStart & TaxYearEnd or timestamp
fields.
Not able to figure out what is going on with 'BETWEEN' operation on
timestamp filelds.

Ver : DB2 V8.1 FP3 (WIN)
Nov 12 '05 #1
4 21762
Hi,

This should be fixed in FP4. The problem is that access to local
variables/arguments was not (always) considered to be eligible as
index-start-stop key.

Sidenote: You don't need BEGIN..END for this trivial function.
There is a fat chance that:

CREATE FUNCTION GetTaxRate
(
v_AsOfDate TIMESTAMP,
v_FilingStatusI d INT)
RETURNS DOUBLE
RETURN (select min(taxrate) FROM Tax_Table
WHERE (v_AsOfDate BETWEEN TaxYearStart AND TaxYearEnd));

will work fine in FP3 (and get nicely optimized along the way :-)

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

Nov 12 '05 #2
Serge, thanks for your reply.
I tried installing FP4 but it didn't make any difference.
Tax_Table is too small a table (just < 70 rows) and even if the optimizer
chooses to do tablescans, it shouldn't make any difference.
What is puzzling me is that if I replace v_AsOfDate by a constant (eg.
timestamp('2003-10-10-00.00.00')) in the WHERE clause,
it is very fast.

Thanks
"Serge Rielau" <sr*****@ca.e ye-bee-m.com> wrote in message
news:bt******** **@hanover.toro lab.ibm.com...
Hi,

This should be fixed in FP4. The problem is that access to local
variables/arguments was not (always) considered to be eligible as
index-start-stop key.

Sidenote: You don't need BEGIN..END for this trivial function.
There is a fat chance that:

CREATE FUNCTION GetTaxRate
(
v_AsOfDate TIMESTAMP,
v_FilingStatusI d INT)
RETURNS DOUBLE
RETURN (select min(taxrate) FROM Tax_Table
WHERE (v_AsOfDate BETWEEN TaxYearStart AND TaxYearEnd));

will work fine in FP3 (and get nicely optimized along the way :-)

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

Nov 12 '05 #3
Ian
Dave wrote:
Serge, thanks for your reply.
I tried installing FP4 but it didn't make any difference.
Tax_Table is too small a table (just < 70 rows) and even if the optimizer
chooses to do tablescans, it shouldn't make any difference.
What is puzzling me is that if I replace v_AsOfDate by a constant (eg.
timestamp('2003-10-10-00.00.00')) in the WHERE clause,
it is very fast.


This is probably a dumb question, but do you have accurate statistics
on your table TAX_TABLE?

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 12 '05 #4
That is odd.
General comment:
Is this an Oracle migration/port? I'm asking because your names suggest
DATE, but you chosen datatype is TIMESTAMP which is the default MTK
mapping. If you have a chance you should use DATE and remove all this
funny code required in Oracle to normalize the time component.
DB2 will thank you for it is decent performance :-)

W.r.t. you specific problem we need more context. Hwo is thsi fucntion
used? Can you provide an explain?
To get an explain of all statements (save SESSION referencing ones):
db2set DB2_SQLROUTINE_ PREPOPTS="EXPLA IN ALL"
(restart DB2)
db2 connect to ....
db2 -tvf sqllib/misc/EXPLAIN.DDL
re-CREATE PROCEDURE

db2exfmt -d <dbname>
chose default for all input except for "output file"

Find the bad statement in the generated file and we'll take a peek.

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2449
by: Doug Reese | last post by:
hello, i have what seems to me a very common operation i'm performing. i need to find the balance on an invoice. i was not having any problems until the production server was upgraded to mysql v4.0.13-standard for pc-linux. there must be a better way to query for this information than the method i'm using, since the result with v4.0 is not what i expected, nor what i received with v3.23. i'm including sample data and queries with my...
1
2984
by: fnord | last post by:
I'm in a bit of a mess here, trying to deal with some timestamp issues. I need to select items from a database with a datetime timestamp: 0000-00-00 00:00:00 I need to select these items based on several different criteria, for which I will use separate select statements, but some of them are a bit confusing.
2
16357
by: amos_s12 | last post by:
Hello everybody Is there a possibility to make a delay between two sql statements, namely one sql statement is performed, then there is a delay of some seconds and then rhe next statement is performed. In sybase database, there is a possibility to do such thing by using the statement waitfor delay 'hh:mm:dd' for example: while(...)
4
31202
by: iamonthisboat | last post by:
I have a data set like so: UTC_TIME Timestamp NodeID Message Flag Line Station 11/19/2005 10:45:07 1132397107.91 1 3 5 1028 1034 11/3/2005 21:05:35 1131051935.20 2 3 5 1009 1043
2
2039
by: Chris | last post by:
Hi, I seem to be having some problems connecting to webservices. I'm running a C# client connected to a Java webservice using GLUE. The difference between the two request and response pairs below is the first contains one item in the request and the second contains two. From what I can see, the only real difference between the two involves the following:
2
1502
by: mukeshhtrivedi | last post by:
I have Cost Analysis form created where there are three fileds and I want to have total of all the fileds at the end. I have created text box which has Control Source as =++. It shows me total of three text boxes when there are some values in all three text boxes but if there are values in only one or two text boxes it is not dislpaying total. Can anyone please help me to solve the problem. I am new to access database. Thanks, Mukesh
1
6502
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to java class which creates a xml file based on values entered in dynamic jsp page. Now i want to read all those values entered to xml in my other jsp page. I am able to call values from file in my jsp page. But as dynamic values can be any in no...
3
3455
by: Kush | last post by:
Hi. I was just wondering if someone could help me understand the relationship between the recv_hist_retention value and archive logs (and pruning of history file). My understanding is that the history file will be automatically pruned at the number of days specified in the recv_hist_retentn parameter. First of all, is that correct? Secondly, does the archive logs, that are older than the value in recv_hist_retentn value, also get...
1
4398
by: Yas | last post by:
Hello, I currently have Table1 and View1. View1 is a query from 2 or 3 tables that works fine on its own. However in my current query if I try to use it...something like... SELECT a.col1, a.col2, a.col3, b.col1, b.col2, b.col3 FROM View1 a JOIN Table1 b on a.col1 = b.col1
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8531
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8628
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.