473,545 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating columns w/ same value - will DB2 optimize for me?

DB2 UDB 7.2 WSE
Fixpak 9
Linux Red Hat 7.3

I have some library code (written in Java, if that matters) that
processes maintenance screens that are presented to the end-users
as forms in a browser.

Because the code is generic, working against any table, I am
dynamically generating UPDATE statements that update
every column in a row, regardless of whether the value in
a column has actually changed. ie - I might be updating columns
w/ the same value that they already have.

I have though about optimizing this - checking to see what the value
is before I update, and generating a shorter, smarter UPDATE statement
that references only columns whose values have actually changed.

But do I need to be overly concerned about this? Will the DB2 engine
notice that I am updating columns w/ the same value they already have,
and optimize things for me?

Any thoughts appreciated...

aj
Nov 12 '05 #1
9 4168
<al****@ndr.com > wrote in message
news:40******** *********@news. supernews.com.. .
DB2 UDB 7.2 WSE
Fixpak 9
Linux Red Hat 7.3

I have some library code (written in Java, if that matters) that
processes maintenance screens that are presented to the end-users
as forms in a browser.

Because the code is generic, working against any table, I am
dynamically generating UPDATE statements that update
every column in a row, regardless of whether the value in
a column has actually changed. ie - I might be updating columns
w/ the same value that they already have.

I have though about optimizing this - checking to see what the value
is before I update, and generating a shorter, smarter UPDATE statement
that references only columns whose values have actually changed.

But do I need to be overly concerned about this? Will the DB2 engine
notice that I am updating columns w/ the same value they already have,
and optimize things for me?

Any thoughts appreciated...

aj


I don't think DB2 will optimize it for you. If you use one update statement
per row, the CPU usage will be a bit more, but physical I/O for the table
should be the same if you update columns that haven't changed. But, there
will be extra I/O (I assume) to update the index columns. Also, DB2 will
need to log the whole row, instead of maybe just logging part of the row.

I think it depends on the volume of the transaction as to whether it is
worth optimizing the SQL dynamically in the program.
Nov 12 '05 #2
Actually DB2 does detect this at runtime by default.
DB2 logs everything between the first columns changed and the last
column changed.
I can't confirm off hand whether this optimization includes the indexes
or not.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #3
Hi Serge. Thanks for replying.

So you are saying that optimizing my updates will not get me anything?
DB2 is already doing it?
Does this apply to v7? v8? Both?

thanks

aj

On Thu, 05 Feb 2004 13:13:23 -0500, Serge Rielau
<sr*****@ca.e ye-be-em.com> wrote:
Actually DB2 does detect this at runtime by default.
DB2 logs everything between the first columns changed and the last
column changed.
I can't confirm off hand whether this optimization includes the indexes
or not.

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


Nov 12 '05 #4
For sure for V8. I don't have the impression it's new either.
Again I don't know of hands whether that optimization includes index
updates or only the logs.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #5
"Serge Rielau" <sr*****@ca.e ye-be-em.com> wrote in message
news:bv******** **@hanover.toro lab.ibm.com...
For sure for V8. I don't have the impression it's new either.
Again I don't know of hands whether that optimization includes index
updates or only the logs.

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


So you are saying that DB2 does not log columns which are not actually
changed even if they are in the "set" clause of the update statement? I am
not talking about columns which are in between the first and last column
changed, which get logged anyway.
Nov 12 '05 #6
Found it.. google my newest favorite toy :-)
http://www.db2.jp/db2manual/en_US/in...e/c0011223.htm
DB2ASSUMEUPDATE Default=OFF
Values: ON, OFF

When enabled, allows DB2 to assume that all fixed length columns
provided in an UPDATE statement are in fact being changed. This
eliminates the need for DB2 to compare the existing column values to the
new values provided to determine if the column is actually changing.
Using this registry variable when columns are provided for update (for
example, in a SET clause) but are not actually being modified can result
in additional logging and index maintenance.
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #7
"Serge Rielau" <sr*****@ca.e ye-be-em.com> wrote in message
news:bv******** **@hanover.toro lab.ibm.com...
Found it.. google my newest favorite toy :-)
http://www.db2.jp/db2manual/en_US/in...e/c0011223.htm
DB2ASSUMEUPDATE Default=OFF
Values: ON, OFF

When enabled, allows DB2 to assume that all fixed length columns
provided in an UPDATE statement are in fact being changed. This
eliminates the need for DB2 to compare the existing column values to the
new values provided to determine if the column is actually changing.
Using this registry variable when columns are provided for update (for
example, in a SET clause) but are not actually being modified can result
in additional logging and index maintenance.
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab


What about varchar? Are they always logged if in the set statement?
Nov 12 '05 #8
The way I disect this text is that by default will always verify for ALL
columns whether they have in fact changed. This is the default and what
OP hopes for.
In V8.1.4 the dial was added to assume a well written app and save that
codepath. Presumably there is only a savings for fixed columns (since
they are at fixed locations in the row (?)).

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #9
al****@ndr.com wrote:
So you are saying that optimizing my updates will not get me anything?


One aspect to consider is how many update statements you are
preparing. If the answer is 1 and you're using placeholders for all
the values, then it is easier to just use that one statement. If,
instead, you write a new statement for each operation, then things are
dramatically slower. If you create one statement for each combination
of N updated columns out of M columns in the table, you end up with a
lot of statements.

And if everything is pre-bound - which DB2 tends to do, but Informix
(my main area of expertise) does not - then the issue may be the size
of your package.

I don't know where the trade-offs occur, nor the relative costings.
However, I'd guess that you're better off using one or a few prepared
statements and living with identity updates on some columns than with
managing hundreds of statements (and C(N,M) gets quite big quite
quickly, if you remember your Pascal's Triangle from maths classes).
--
Jonathan Leffler #include <disclaimer.h >
Email: jl******@earthl ink.net, jl******@us.ibm .com
Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/

Nov 12 '05 #10

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

Similar topics

11
16098
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? 1) simply UPDATING the values for all fields in the table, whether or not any particular field has actually changed 2) running a second SELECT...
1
5933
by: Srinadh | last post by:
Hi all, We have files with about 20 to 30 fields per row. We are trying to update such files with about 60 rows as contiguous data in a CLOB field. It passes through. But when we try updating files with about 60 to 200 rows, we get the
14
2108
by: Lars Netzel | last post by:
A little background: I use three Datagrids that are in a child parent relation. I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these grid and write to the database and I set the new Primary Keys and related Fields to the new asigned atuonumbers in the Access.
2
2841
by: Alexey.Murin | last post by:
The application we are developing uses MS Access 2003 database (with help of ADO). We have noticed that during massive records updating the size of the mdb file increases dramatically (from 3-4 to 200-300 Mb). After compacting the file shrinks back to 3-4 Mb. I have performed the following experiment. I created a test database containing...
4
2364
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has two fields: a primary key and another holding a string. In table B there are three fields: a primary key, a foreign key (which links to the primary...
1
19741
by: Lars E | last post by:
Hi all I have a small problem. I have a datatable with 8 columns. But it is only data in 5 of the columns. Data for the remaing 3 columns is in another dataset. I Want to run trough the datatable and fill out the remaining data. My code so far: if (this.fetch("custinfo", "fetchCustInfo", out customers, parameters))
5
1968
by: JimmyKoolPantz | last post by:
Situation: I am writing a program that opens up a data file (file ext .dbf), imports the information into a dataset. The program also, searches through the dataset for key words ("company names") and then displays all records with company names in a datagridview. Once the information has been binded to the datagridview control, I allow...
33
3261
by: bill | last post by:
In an application I am writing the user can define a series of steps to be followed. I save them in a sql database using the field "order" (a smallint) as the primary key. (there are in the range of 20 steps) On the admin page the steps are listed, in "order" order and the user can create new steps and assign an order and all is well. ...
3
1486
by: AshishMishra16 | last post by:
Hi Friends, What is the way to iterate the Table and Make all the input types editable on the click of a checkbox. Here is what My Requirement is : <table id="adSearchTable" cellspacing="3"> <thead> <tr class="tableheader" style="height: 15px;">
0
7405
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7659
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. ...
0
7811
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7760
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...
1
5334
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4949
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...
0
3455
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...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
709
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...

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.