Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old September 4th, 2008, 05:05 PM
Henry J.
Guest
 
Posts: n/a
Default default timestamp value and performance

I know this could be a dumb question, I just want to confirm that it
is faster to execute inserts, if a timestamp field is set to have a
default value, like DEFAULT CURRENT TIMESTAMP, and skip that column in
inserts, than to include explicit timestamps in the inserts and let
the DB insert them.

Thanks!



  #2  
Old September 4th, 2008, 06:15 PM
Serge Rielau
Guest
 
Posts: n/a
Default Re: default timestamp value and performance

Henry J. wrote:
Quote:
I know this could be a dumb question, I just want to confirm that it
is faster to execute inserts, if a timestamp field is set to have a
default value, like DEFAULT CURRENT TIMESTAMP, and skip that column in
inserts, than to include explicit timestamps in the inserts and let
the DB insert them.
Matter of fact the DEFAULT will be ever so slightly more expensive.
Now before anyone gets excited here the difference is minuscule.
Essentially DB2 needs to "enrich" the INSERT. So it needs to root around
for the default value and plug it in.
This is a compile time cost only. At runtime there is no difference
whatsoever

Cheers
Serge


--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
  #3  
Old September 4th, 2008, 10:15 PM
Henry J.
Guest
 
Posts: n/a
Default Re: default timestamp value and performance

On Sep 4, 1:14*pm, Serge Rielau <srie...@ca.ibm.comwrote:
Quote:
Henry J. wrote:
Quote:
I know this could be a dumb question, I just want to confirm that it
is faster to execute inserts, if a timestamp field is set to have a
default value, like DEFAULT CURRENT TIMESTAMP, and skip that column in
inserts, than to include explicit timestamps in the inserts and let
the DB insert them.
>
Matter of fact the DEFAULT will be ever so slightly more expensive.
Now before anyone gets excited here the difference is minuscule.
Essentially DB2 needs to "enrich" the INSERT. So it needs to root around
for the default value and plug it in.
This is a compile time cost only. At runtime there is no difference
whatsoever
>
If I have a query that inserts 1 million rows. One way is to bind the
timestamp field to the current time in the app; the other is to let DB
insert the current time. For the latter, the current time will
increase during the course of the huge insertion, the timestamp for
the last row inserted would be bigger than that for the first row
inserted. When the app passes the timestamp, it just passes one
value. In light of this, if the DB implments the default timestamp by
"enrich" the insert statement, it appears to me it would be more
expensive in run-time as well.

I thought the DB would implement the default timestamp by some low
level writes, making it faster than the timestamp from the app.
Surprised to know it could be other way around. Is it the same in
other databases?
  #4  
Old September 4th, 2008, 10:25 PM
Henry J.
Guest
 
Posts: n/a
Default Re: default timestamp value and performance

On Sep 4, 1:14*pm, Serge Rielau <srie...@ca.ibm.comwrote:
Quote:
Henry J. wrote:
Quote:
I know this could be a dumb question, I just want to confirm that it
is faster to execute inserts, if a timestamp field is set to have a
default value, like DEFAULT CURRENT TIMESTAMP, and skip that column in
inserts, than to include explicit timestamps in the inserts and let
the DB insert them.
>
Matter of fact the DEFAULT will be ever so slightly more expensive.
Now before anyone gets excited here the difference is minuscule.
Essentially DB2 needs to "enrich" the INSERT. So it needs to root around
for the default value and plug it in.
This is a compile time cost only. At runtime there is no difference
whatsoever
Another one. If a timestamp column has a default value (current
timestamp), will the inserts with expliclit timestamps be even more
expensive?
  #5  
Old September 5th, 2008, 12:25 AM
Serge Rielau
Guest
 
Posts: n/a
Default Re: default timestamp value and performance

Henry J. wrote:
Quote:
On Sep 4, 1:14 pm, Serge Rielau <srie...@ca.ibm.comwrote:
Quote:
>Henry J. wrote:
Quote:
>>I know this could be a dumb question, I just want to confirm that it
>>is faster to execute inserts, if a timestamp field is set to have a
>>default value, like DEFAULT CURRENT TIMESTAMP, and skip that column in
>>inserts, than to include explicit timestamps in the inserts and let
>>the DB insert them.
>Matter of fact the DEFAULT will be ever so slightly more expensive.
>Now before anyone gets excited here the difference is minuscule.
>Essentially DB2 needs to "enrich" the INSERT. So it needs to root around
>for the default value and plug it in.
>This is a compile time cost only. At runtime there is no difference
>whatsoever
>>
>
If I have a query that inserts 1 million rows. One way is to bind the
timestamp field to the current time in the app; the other is to let DB
insert the current time. For the latter, the current time will
increase during the course of the huge insertion, the timestamp for
the last row inserted would be bigger than that for the first row
inserted. When the app passes the timestamp, it just passes one
value. In light of this, if the DB implments the default timestamp by
"enrich" the insert statement, it appears to me it would be more
expensive in run-time as well.
>
I thought the DB would implement the default timestamp by some low
level writes, making it faster than the timestamp from the app.
Surprised to know it could be other way around. Is it the same in
other databases?
CURRENT TIMESTAMP has the same value for the entire statement.
If you want different numbers per row you need to do
TIMESTAMP(generate_unique())

I do not know about other DBMS by design - or ignorance in the case of IDS

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
  #6  
Old September 5th, 2008, 12:25 AM
Serge Rielau
Guest
 
Posts: n/a
Default Re: default timestamp value and performance

Henry J. wrote:
Quote:
On Sep 4, 1:14 pm, Serge Rielau <srie...@ca.ibm.comwrote:
Quote:
>Henry J. wrote:
Quote:
>>I know this could be a dumb question, I just want to confirm that it
>>is faster to execute inserts, if a timestamp field is set to have a
>>default value, like DEFAULT CURRENT TIMESTAMP, and skip that column in
>>inserts, than to include explicit timestamps in the inserts and let
>>the DB insert them.
>Matter of fact the DEFAULT will be ever so slightly more expensive.
>Now before anyone gets excited here the difference is minuscule.
>Essentially DB2 needs to "enrich" the INSERT. So it needs to root around
>for the default value and plug it in.
>This is a compile time cost only. At runtime there is no difference
>whatsoever
>
Another one. If a timestamp column has a default value (current
timestamp), will the inserts with expliclit timestamps be even more
expensive?
No. Keep in mind that we are talking about some 100 cycles in a GHz CPU.
So "even more" is a really funny phrase even if that were the case

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.