If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > select current timestamp

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-19-08, 16:50
hickston hickston is offline
Registered User
 
Join Date: Feb 2008
Posts: 2
select current timestamp

quick question hopefully.

we can get the current timestamp using sysibm.sysdummy1 and that works ok, but we were advised that after v8 implementation, this table/option wouldnt be available (presumably the advisor assumed it wouldnt work with unicode or something...the manual sais its still ebcidic). - I know this isnt true!!

anyway, we assumed that using
"select current timestamp" from any DB2 table would return the same result and it worked perfectly. What we didnt notice was that the result seems to be being obtained by doing a full index scan. This is ok in test where there's a low number of rows, but as soon as it went live, it tried to scan 200 million rows and obviously took a while..

so the question is, why is it trying to do an index scan and not just returning the current timestamp as it would from sysdummy?
Reply With Quote
  #2 (permalink)  
Old 02-19-08, 16:54
sundaram sundaram is offline
Registered User
 
Join Date: Mar 2006
Posts: 104
try SQL

"values current timestamp"

Regards

Harikumar
Reply With Quote
  #3 (permalink)  
Old 02-19-08, 17:05
hickston hickston is offline
Registered User
 
Join Date: Feb 2008
Posts: 2
thanks for that Harikumar. I know we can just use sysdummy now, so the SQL isnt really a problem.

What I'm really interested in is the nuts and bolts of why it does a full index scan. I just was just hoping there was a simple explanation.

ie why doesnt DB2 realise the current timestamp on any table is just that, the current timestamp. If I inserted to the table and used default timestamp it wouldnt scan the index first and then decide what the timestamp should be...
Reply With Quote
  #4 (permalink)  
Old 02-19-08, 17:51
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
What you are describing is standard SQL. If you run the following statement:

select 1 from <table-name>

You will get one row for each row of the table (each row with the value 1 being returned). This is what happens when you have no WHERE clause. Anything else would be a violation of the SQL standard.

This is why sysibm.sysdummy1 has only one row in it, percisely so that you can select the current_timestamp and get one value back. Since this table was put in DB2 for LUW for compatibility with DB2 for z/OS, I don't think it is going away. If it does, just create your own table or view with the same name.

BTW, if you don't want to use sysibm.sysdummy1 you can do the following:

select current_timestamp from <table-name> fetch first 1 rows only

This will achieve the objective you want without the full index or table scan.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390

Last edited by Marcus_A; 02-20-08 at 00:10.
Reply With Quote
  #5 (permalink)  
Old 02-19-08, 23:43
nidm nidm is offline
Registered User
 
Join Date: May 2003
Posts: 113
I believe you can still use sysibm.sysdummy1 as before.

In case of difficult encoding(unicode vs. ebcdic), you can use sysibm.sysdummyu, which is in unicode
Reply With Quote
  #6 (permalink)  
Old 02-20-08, 04:51
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Exactly - just use SYSIBM.SYSDUMMY1, that's what it is intended for. It is the way to deal with the situation that DB2 z/OS does not have a VALUES table constructor yet. It won't go away for two primary reasons:
(a) IBM did not mark it as being "deprecated"
(b) it is used in way too many applications to force customers to change those applications
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development

Last edited by stolze; 02-20-08 at 06:54.
Reply With Quote
  #7 (permalink)  
Old 08-25-10, 15:36
AMIKHAILOV AMIKHAILOV is offline
Registered User
 
Join Date: Aug 2010
Posts: 1
set command vs select

Is there a difference performance- or otherwise between set :hv = current timestamp and select current_timestamp from sysdummy1 ?
Does anyone know ?
Reply With Quote
  #8 (permalink)  
Old 08-25-10, 20:20
wilsonfv wilsonfv is offline
Registered User
 
Join Date: Apr 2009
Posts: 42
I believe the performance difference is minor
Reply With Quote
  #9 (permalink)  
Old 08-26-10, 00:19
ericshef ericshef is offline
Registered User
 
Join Date: Aug 2010
Posts: 1
yea i believe the difference is minor as well
Reply With Quote
  #10 (permalink)  
Old 08-26-10, 02:20
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
Some time ago I did some performance checks regarding that issue.

SELECT current date + :n days INTO :host FROM SYSIBM.SYSDUMMY1 versus
SET :host = current date + :n days.

The SET costs about half the CPU time and elapsed time.

( Maybe that changed in V9, as SYSDUMMY1 was moved from tablespace DSNDB06.SYSSTR to DSNDB06.SYSEBCDC. )


If you still use SYSDUMMY1, SELECT WITH UR will save about 10% CPU
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On