473,468 Members | 1,479 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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!
Sep 4 '08 #1
5 4820
Henry J. wrote:
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
Sep 4 '08 #2
On Sep 4, 1:14*pm, Serge Rielau <srie...@ca.ibm.comwrote:
Henry J. wrote:
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?
Sep 4 '08 #3
On Sep 4, 1:14*pm, Serge Rielau <srie...@ca.ibm.comwrote:
Henry J. wrote:
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?
Sep 4 '08 #4
Henry J. wrote:
On Sep 4, 1:14 pm, Serge Rielau <srie...@ca.ibm.comwrote:
>Henry J. wrote:
>>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
Sep 4 '08 #5
Henry J. wrote:
On Sep 4, 1:14 pm, Serge Rielau <srie...@ca.ibm.comwrote:
>Henry J. wrote:
>>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
Sep 4 '08 #6

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

Similar topics

49
by: Mark Hahn | last post by:
As we are addressing the "warts" in Python to be fixed in Prothon, we have come upon the mutable default parameter problem. For those unfamiliar with the problem, it can be seen in this Prothon...
6
by: My Deja | last post by:
what is the syntax for specifying the default values for timestamps in MySQL in the CREATE TABLE command? I have 2 timestamps, one for when the record was entered, the other for any subsequent...
0
by: matthew | last post by:
I am using: mysql Ver 12.22 Distrib 4.0.18, for sun-solaris2.9 (sparc) And I do this: mysql> create table test (a timestamp default null, b timestamp default null); Query OK, 0 rows...
2
by: Rob | last post by:
Hello all I have a field (called active) of type DATE and I want to add a default value. The default value must be the current date. Is this possible to do this in the table create statement? ...
12
by: Emi Lu | last post by:
Hello all, I have a question about "date" & "timestamp" types in PostgreSQL. I want to setup the default value '0000-00-00' and "0000-00-00 00:00:00" for them. However, it seems that PostgreSQL...
1
by: Frans | last post by:
Hello All, I have just upgrade my postgresql to 7.4.5-2, but I have problem with default value in postgresql 7.4.5-2, everytime I set default value for varchar or timestamp fields, the result...
22
by: Mal Ball | last post by:
I hope I have the right forum for this question. I have an existing Windows application which uses a SQL Server database and stored procedures. I am now developing a web application to use the same...
2
by: syntego | last post by:
We commonly use triggers to log changes to our main tables to historical log tables. In the trigger, we create a concatenated string of the old values by casting them as follows: ...
8
by: kanwal | last post by:
Hi, I have millions of records in my xxxxx table in mysql. And I have a column of time in which I have stored the timestamp using php time() function. Now I wanna write an SQL query to fetch...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.