473,714 Members | 2,500 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

update transmogrifies to insert/delete

been ruminating on the question (mostly in a 390/v7 context) of
whether, and if so when, a row update becomes an insert/delete.

i assume that there is a threshold on the number of columns of
the table, or perhaps bytes, being updated where the engine just
decides, screw it, i'll just make a new one.

surfed this group and google, but couldn't find anything.

the context: we have some java folk who like to parametize/
generalize/exersize into what they call Data Access Objects, and
end up looping through a database result set based on column
metadata (thus not having to write any table specific code),
resetting all columns. makes for generatable code, but i for one
don't like it.

seems to be the worst possible performance scenario??
Nov 12 '05 #1
16 3871

"robert" <gn*****@rcn.co m> wrote in message
news:da******** *************** ***@posting.goo gle.com...
been ruminating on the question (mostly in a 390/v7 context) of
whether, and if so when, a row update becomes an insert/delete.

i assume that there is a threshold on the number of columns of
the table, or perhaps bytes, being updated where the engine just
decides, screw it, i'll just make a new one.

surfed this group and google, but couldn't find anything.

the context: we have some java folk who like to parametize/
generalize/exersize into what they call Data Access Objects, and
end up looping through a database result set based on column
metadata (thus not having to write any table specific code),
resetting all columns. makes for generatable code, but i for one
don't like it.

seems to be the worst possible performance scenario??


I'm a Java developer but I've never used Data Access Objects so I may not be
qualified to comment on this question.

However, I would be quite astonished if "the engine" _EVER_ "just decides,
screw it, I'll just make a new one". (I assume that when you say "the
engine" you mean the DB2 code itself, as opposed to some third party add-on
to DB2.)

Frankly, I've never heard so much as a whisper of a hint of a rumour of a
suggestion that DB2 could transform an SQL Update statement to an Insert
and/or a Delete and I've been working with DB2 in one capacity or another
for 20 years.

As far as I know, an Update is always an Update, a Delete is always a
Delete, and an Insert is always an Insert and none of these can change from
one to the other.

Of course, I *could* be wrong....

Having said that, an *application* which uses DB2 should be able to turn an
update statement into a delete/insert. For instance, if a user submitted a
query like this through an interface that I wrote:
update Employee
set salary = salary * 1.1
where empno = '000010'

I could imagine converting that to:
1) a delete that removed the current row for employee 000010
2) an insert to create a new row for employee 000010 but with a 10% raise in
salary.

Of course, the code to do this would also need a select to determine the
current values of all of the other columns in the original row so that they
could be copied to the new row during the insert.

However, there could easily be important side-issues with respect to related
data. For instance, if the Employee table in the example had dependent
tables, such as Employee_Health _Claims, doing the delete in the Employee
table could cause all rows of Employee_Health _Claims that relate to that
Employee to be deleted if a DELETE CASCADE rule was in effect. (And rows in
tables dependent on Employee_Health _Claims might also be deleted if the
DELETE CASCADE rule was in effect on this foreign keys.)

By the same token, the delete in the Employee table would fail if there was
a DELETE RESTRICT rule between Employee and Employee_Health _Claims. You
would have to consider Referential Integrity issues very carefully if you
chose to convert an Update into a Delete/Insert combination.

After all, you wouldn't want an update in one table to cause all sorts of
data to be deleted just because you thought you might get a slight advantage
by turning one Update into a Delete followed by an Insert.

Since I'm not sure if I really understood the intent of your question, I
don't know if this answers it. If not, perhaps you can clarify what you are
after. Then I - or others on this newsgroup - could try again.

Rhino
Nov 12 '05 #2
I'd beg to differ just a little bit here.
IN DB2 UDB for LUW:
Multi Dimension Clusterd tables.
If one updates one of the columns chosen as a dimension, the only way
DB2 can deal with this to maintain clustering is to delete the row where
it lived in its block and insert the row with the new dimension in its
proper block.
Apart from this I'd totally agree with Rhino.

Rhino wrote:
"robert" <gn*****@rcn.co m> wrote in message
news:da******** *************** ***@posting.goo gle.com...
been ruminating on the question (mostly in a 390/v7 context) of
whether, and if so when, a row update becomes an insert/delete.

i assume that there is a threshold on the number of columns of
the table, or perhaps bytes, being updated where the engine just
decides, screw it, i'll just make a new one.

surfed this group and google, but couldn't find anything.

the context: we have some java folk who like to parametize/
generalize/exersize into what they call Data Access Objects, and
end up looping through a database result set based on column
metadata (thus not having to write any table specific code),
resetting all columns. makes for generatable code, but i for one
don't like it.

seems to be the worst possible performance scenario??

I'm a Java developer but I've never used Data Access Objects so I may not be
qualified to comment on this question.

However, I would be quite astonished if "the engine" _EVER_ "just decides,
screw it, I'll just make a new one". (I assume that when you say "the
engine" you mean the DB2 code itself, as opposed to some third party add-on
to DB2.)

Frankly, I've never heard so much as a whisper of a hint of a rumour of a
suggestion that DB2 could transform an SQL Update statement to an Insert
and/or a Delete and I've been working with DB2 in one capacity or another
for 20 years.

As far as I know, an Update is always an Update, a Delete is always a
Delete, and an Insert is always an Insert and none of these can change from
one to the other.

Of course, I *could* be wrong....

Having said that, an *application* which uses DB2 should be able to turn an
update statement into a delete/insert. For instance, if a user submitted a
query like this through an interface that I wrote:
update Employee
set salary = salary * 1.1
where empno = '000010'

I could imagine converting that to:
1) a delete that removed the current row for employee 000010
2) an insert to create a new row for employee 000010 but with a 10% raise in
salary.

Of course, the code to do this would also need a select to determine the
current values of all of the other columns in the original row so that they
could be copied to the new row during the insert.

However, there could easily be important side-issues with respect to related
data. For instance, if the Employee table in the example had dependent
tables, such as Employee_Health _Claims, doing the delete in the Employee
table could cause all rows of Employee_Health _Claims that relate to that
Employee to be deleted if a DELETE CASCADE rule was in effect. (And rows in
tables dependent on Employee_Health _Claims might also be deleted if the
DELETE CASCADE rule was in effect on this foreign keys.)

By the same token, the delete in the Employee table would fail if there was
a DELETE RESTRICT rule between Employee and Employee_Health _Claims. You
would have to consider Referential Integrity issues very carefully if you
chose to convert an Update into a Delete/Insert combination.

After all, you wouldn't want an update in one table to cause all sorts of
data to be deleted just because you thought you might get a slight advantage
by turning one Update into a Delete followed by an Insert.

Since I'm not sure if I really understood the intent of your question, I
don't know if this answers it. If not, perhaps you can clarify what you are
after. Then I - or others on this newsgroup - could try again.

Rhino


--
Pierre Saint-Jacques - Reply to: sesconsjunk at attglobaljunk dot com
Reconstruct address: Remove the two junk and replace at and dot by
their symbols.
IBM DB2 Cerified Solutions Expert - Administration
SES Consultants Inc.
Nov 12 '05 #3
I'd beg to differ just a little bit here.
IN DB2 UDB for LUW:
Multi Dimension Clusterd tables.
If one updates one of the columns chosen as a dimension, the only way
DB2 can deal with this to maintain clustering is to delete the row where
it lived in its block and insert the row with the new dimension in its
proper block.
Apart from this I'd totally agree with Rhino.

Rhino wrote:
"robert" <gn*****@rcn.co m> wrote in message
news:da******** *************** ***@posting.goo gle.com...
been ruminating on the question (mostly in a 390/v7 context) of
whether, and if so when, a row update becomes an insert/delete.

i assume that there is a threshold on the number of columns of
the table, or perhaps bytes, being updated where the engine just
decides, screw it, i'll just make a new one.

surfed this group and google, but couldn't find anything.

the context: we have some java folk who like to parametize/
generalize/exersize into what they call Data Access Objects, and
end up looping through a database result set based on column
metadata (thus not having to write any table specific code),
resetting all columns. makes for generatable code, but i for one
don't like it.

seems to be the worst possible performance scenario??

I'm a Java developer but I've never used Data Access Objects so I may not be
qualified to comment on this question.

However, I would be quite astonished if "the engine" _EVER_ "just decides,
screw it, I'll just make a new one". (I assume that when you say "the
engine" you mean the DB2 code itself, as opposed to some third party add-on
to DB2.)

Frankly, I've never heard so much as a whisper of a hint of a rumour of a
suggestion that DB2 could transform an SQL Update statement to an Insert
and/or a Delete and I've been working with DB2 in one capacity or another
for 20 years.

As far as I know, an Update is always an Update, a Delete is always a
Delete, and an Insert is always an Insert and none of these can change from
one to the other.

Of course, I *could* be wrong....

Having said that, an *application* which uses DB2 should be able to turn an
update statement into a delete/insert. For instance, if a user submitted a
query like this through an interface that I wrote:
update Employee
set salary = salary * 1.1
where empno = '000010'

I could imagine converting that to:
1) a delete that removed the current row for employee 000010
2) an insert to create a new row for employee 000010 but with a 10% raise in
salary.

Of course, the code to do this would also need a select to determine the
current values of all of the other columns in the original row so that they
could be copied to the new row during the insert.

However, there could easily be important side-issues with respect to related
data. For instance, if the Employee table in the example had dependent
tables, such as Employee_Health _Claims, doing the delete in the Employee
table could cause all rows of Employee_Health _Claims that relate to that
Employee to be deleted if a DELETE CASCADE rule was in effect. (And rows in
tables dependent on Employee_Health _Claims might also be deleted if the
DELETE CASCADE rule was in effect on this foreign keys.)

By the same token, the delete in the Employee table would fail if there was
a DELETE RESTRICT rule between Employee and Employee_Health _Claims. You
would have to consider Referential Integrity issues very carefully if you
chose to convert an Update into a Delete/Insert combination.

After all, you wouldn't want an update in one table to cause all sorts of
data to be deleted just because you thought you might get a slight advantage
by turning one Update into a Delete followed by an Insert.

Since I'm not sure if I really understood the intent of your question, I
don't know if this answers it. If not, perhaps you can clarify what you are
after. Then I - or others on this newsgroup - could try again.

Rhino


--
Pierre Saint-Jacques - Reply to: sesconsjunk at attglobaljunk dot com
Reconstruct address: Remove the two junk and replace at and dot by
their symbols.
IBM DB2 Cerified Solutions Expert - Administration
SES Consultants Inc.
Nov 12 '05 #4
"Rhino" <rh****@NOSPAM. sympatico.ca> wrote in message news:<Yc******* *************@n ews20.bellgloba l.com>...
"robert" <gn*****@rcn.co m> wrote in message
news:da******** *************** ***@posting.goo gle.com...
been ruminating on the question (mostly in a 390/v7 context) of
whether, and if so when, a row update becomes an insert/delete.

i assume that there is a threshold on the number of columns of
the table, or perhaps bytes, being updated where the engine just
decides, screw it, i'll just make a new one.

surfed this group and google, but couldn't find anything.

the context: we have some java folk who like to parametize/
generalize/exersize into what they call Data Access Objects, and
end up looping through a database result set based on column
metadata (thus not having to write any table specific code),
resetting all columns. makes for generatable code, but i for one
don't like it.

seems to be the worst possible performance scenario??
I'm a Java developer but I've never used Data Access Objects so I may not be
qualified to comment on this question.

However, I would be quite astonished if "the engine" _EVER_ "just decides,
screw it, I'll just make a new one". (I assume that when you say "the
engine" you mean the DB2 code itself, as opposed to some third party add-on
to DB2.)


i have this irrepressible lower brain stem memory that some databases
(not for certain db2, hence the question), do just that.

Frankly, I've never heard so much as a whisper of a hint of a rumour of a
suggestion that DB2 could transform an SQL Update statement to an Insert
and/or a Delete and I've been working with DB2 in one capacity or another
for 20 years.

As far as I know, an Update is always an Update, a Delete is always a
Delete, and an Insert is always an Insert and none of these can change from
one to the other.

Of course, I *could* be wrong....

Having said that, an *application* which uses DB2 should be able to turn an
update statement into a delete/insert. For instance, if a user submitted a
query like this through an interface that I wrote:
update Employee
set salary = salary * 1.1
where empno = '000010'

I could imagine converting that to:
1) a delete that removed the current row for employee 000010
2) an insert to create a new row for employee 000010 but with a 10% raise in
salary.

Of course, the code to do this would also need a select to determine the
current values of all of the other columns in the original row so that they
could be copied to the new row during the insert.
thus handing over the responsibility for data concurrency to the application.
just the sort of thing that irritates my piles. see following.
and preceding.

However, there could easily be important side-issues with respect to related
data. For instance, if the Employee table in the example had dependent
tables, such as Employee_Health _Claims, doing the delete in the Employee
table could cause all rows of Employee_Health _Claims that relate to that
Employee to be deleted if a DELETE CASCADE rule was in effect. (And rows in
tables dependent on Employee_Health _Claims might also be deleted if the
DELETE CASCADE rule was in effect on this foreign keys.)

By the same token, the delete in the Employee table would fail if there was
a DELETE RESTRICT rule between Employee and Employee_Health _Claims. You
would have to consider Referential Integrity issues very carefully if you
chose to convert an Update into a Delete/Insert combination.

After all, you wouldn't want an update in one table to cause all sorts of
data to be deleted just because you thought you might get a slight advantage
by turning one Update into a Delete followed by an Insert.

Since I'm not sure if I really understood the intent of your question, I
don't know if this answers it. If not, perhaps you can clarify what you are
after. Then I - or others on this newsgroup - could try again.
two, related concerns (sorry if my OP was obtuse):

- updating every column of each updated row has *got* to be too expensive
for words; far more (if it's ever been quantified) than the 1 or 2 or 3
columns actually changed. are there published stats on the performance
impact?? that is: at what point, either number/type of columns, or
average byte count, etc. is the penalty so large that whatever (coder)
time saved in development by relying on a code generation tool is
overwhelmed by the run-time penalty of updating all columns?? OR, is
DB2 smart enough to see that the incoming column data matches in
table data, and says, "screw it. it ain't different. i ain't
touching it"???? in this scenario, using code generating tools is
not a bad thing, beyond the fact that folks soon forget what their
data looks like.

- if DB2 sees that the row is being nuked, does it escalate (as it does do
with locks) to insert/delete (or vice versa, of course). and, another
if, so is this more or less expensive than doing the in-place insert?
an optimizer might consider "all aspects", and thus, basically, make
a mistake from a performance point of view??

clearer? somewhat existential and theoretical. antidote for RNC
blathering.

Rhino

Nov 12 '05 #5

"robert" <gn*****@rcn.co m> wrote in message
news:da******** *************** ***@posting.goo gle.com...
"Rhino" <rh****@NOSPAM. sympatico.ca> wrote in message news:<Yc******* *************@n ews20.bellgloba l.com>...
"robert" <gn*****@rcn.co m> wrote in message
news:da******** *************** ***@posting.goo gle.com...
been ruminating on the question (mostly in a 390/v7 context) of
whether, and if so when, a row update becomes an insert/delete.

i assume that there is a threshold on the number of columns of
the table, or perhaps bytes, being updated where the engine just
decides, screw it, i'll just make a new one.

surfed this group and google, but couldn't find anything.

the context: we have some java folk who like to parametize/
generalize/exersize into what they call Data Access Objects, and
end up looping through a database result set based on column
metadata (thus not having to write any table specific code),
resetting all columns. makes for generatable code, but i for one
don't like it.

seems to be the worst possible performance scenario??


I'm a Java developer but I've never used Data Access Objects so I may not be qualified to comment on this question.

However, I would be quite astonished if "the engine" _EVER_ "just decides, screw it, I'll just make a new one". (I assume that when you say "the
engine" you mean the DB2 code itself, as opposed to some third party add-on to DB2.)


i have this irrepressible lower brain stem memory that some databases
(not for certain db2, hence the question), do just that.

That's quite possible but I don't know the other databases well enough to
say yes or no with any certainty.

Frankly, I've never heard so much as a whisper of a hint of a rumour of a suggestion that DB2 could transform an SQL Update statement to an Insert
and/or a Delete and I've been working with DB2 in one capacity or another for 20 years.

As far as I know, an Update is always an Update, a Delete is always a
Delete, and an Insert is always an Insert and none of these can change from one to the other.

Of course, I *could* be wrong....

Having said that, an *application* which uses DB2 should be able to turn an update statement into a delete/insert. For instance, if a user submitted a query like this through an interface that I wrote:
update Employee
set salary = salary * 1.1
where empno = '000010'

I could imagine converting that to:
1) a delete that removed the current row for employee 000010
2) an insert to create a new row for employee 000010 but with a 10% raise in salary.

Of course, the code to do this would also need a select to determine the
current values of all of the other columns in the original row so that they could be copied to the new row during the insert.


thus handing over the responsibility for data concurrency to the

application. just the sort of thing that irritates my piles. see following.
and preceding.

However, there could easily be important side-issues with respect to related data. For instance, if the Employee table in the example had dependent
tables, such as Employee_Health _Claims, doing the delete in the Employee
table could cause all rows of Employee_Health _Claims that relate to that
Employee to be deleted if a DELETE CASCADE rule was in effect. (And rows in tables dependent on Employee_Health _Claims might also be deleted if the
DELETE CASCADE rule was in effect on this foreign keys.)

By the same token, the delete in the Employee table would fail if there was a DELETE RESTRICT rule between Employee and Employee_Health _Claims. You
would have to consider Referential Integrity issues very carefully if you chose to convert an Update into a Delete/Insert combination.

After all, you wouldn't want an update in one table to cause all sorts of data to be deleted just because you thought you might get a slight advantage by turning one Update into a Delete followed by an Insert.

Since I'm not sure if I really understood the intent of your question, I
don't know if this answers it. If not, perhaps you can clarify what you are after. Then I - or others on this newsgroup - could try again.
two, related concerns (sorry if my OP was obtuse):

- updating every column of each updated row has *got* to be too expensive
for words; far more (if it's ever been quantified) than the 1 or 2 or 3
columns actually changed. are there published stats on the performance
impact?? that is: at what point, either number/type of columns, or
average byte count, etc. is the penalty so large that whatever (coder)
time saved in development by relying on a code generation tool is
overwhelmed by the run-time penalty of updating all columns?? OR, is
DB2 smart enough to see that the incoming column data matches in
table data, and says, "screw it. it ain't different. i ain't
touching it"???? in this scenario, using code generating tools is
not a bad thing, beyond the fact that folks soon forget what their
data looks like.

I don't know precisely what happens in DB2 with respect to updates; after
all, IBM doesn't publish the source code so I wouldn't know.

However, I have always understood that DB2 stores data as rows, that rows
are stored in pages, and DB2 works with pages of data in its bufferpools. In
other words, DB2 isn't doing separate I/Os to get each value on a row.
Furthermore, I've always believed that DB2 only updates the columns that are
in the SET clause of the Update statement and doesn't attempt to rewrite
columns that aren't changed. Again, that is just my *belief*; I can't say
that with certainty without looking at the source code. If anyone who is
absolutely certain can confirm or deny that belief, I'd appreciate it.

So I think the actual behaviour of an application depends on the Update
statement that it generates. If an application - or application generator -
puts every column of the table in the SET clause of its Update statements,
even if the column value isn't being changed, I'd expect that to be slower.
But that would be the fault of the application or generator, not DB2.
- if DB2 sees that the row is being nuked, does it escalate (as it does do
with locks) to insert/delete (or vice versa, of course). and, another
if, so is this more or less expensive than doing the in-place insert?
an optimizer might consider "all aspects", and thus, basically, make
a mistake from a performance point of view??

DB2's Lock Manager can certainly escalate locks and does that when that is
required. However, you should understand that the Lock Manager works at the
row (or page, or table, or tablespace, or database level), not at the level
of individual fields. I'm not aware of any circumstances where it can lock
less than a full row. Lock escalation is always about locking more rows (or
pages), never about locking more fields on one row.

Again, I don't think it is possible for DB2 to convert an Update to a
Delete/Insert, except in that one special case that Pierre noted.

As always, I assume that others on this newsgroup will correct me if I've
inadvertently said anything wrong.

Rhino
Nov 12 '05 #6
Ian
Pierre Saint-Jacques wrote:
I'd beg to differ just a little bit here.
IN DB2 UDB for LUW:
Multi Dimension Clusterd tables.
If one updates one of the columns chosen as a dimension, the only way
DB2 can deal with this to maintain clustering is to delete the row where
it lived in its block and insert the row with the new dimension in its
proper block.


The same applies for updating the partitioning key for a table in
a partitioned database -- this may result in a delete/insert if the
row would need to be migrated to a different database partition.

-----= 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 #7
Things may have changed but I've always understood DB2's update to deal
with the undo/redo info required and only that for an update.
I used to know(?), things may have changed, that DB2 would pick up the
first column of a row to be changed and all columns from there to the
last column mentioned in the set. Not to deal with the whole row.

As Rhino mentions, in DB2 UDB for LUW, for updates, tables get locked
and rows may get locked. If rows do get locked, locklist and maxlocks
(cfg parms) will govern whether or not there is escalation. Escalation
is always to a strict table lock.
HTH, Pierre.

Rhino wrote:
"robert" <gn*****@rcn.co m> wrote in message
news:da******** *************** ***@posting.goo gle.com...
"Rhino" <rh****@NOSPAM. sympatico.ca> wrote in message


news:<Yc******* *************@n ews20.bellgloba l.com>...
"robert" <gn*****@rcn.co m> wrote in message
news:da***** *************** ******@posting. google.com...

been ruminating on the question (mostly in a 390/v7 context) of
whether, and if so when, a row update becomes an insert/delete.

i assume that there is a threshold on the number of columns of
the table, or perhaps bytes, being updated where the engine just
decides, screw it, i'll just make a new one.

surfed this group and google, but couldn't find anything.

the context: we have some java folk who like to parametize/
generaliz e/exersize into what they call Data Access Objects, and
end up looping through a database result set based on column
metadata (thus not having to write any table specific code),
resetting all columns. makes for generatable code, but i for one
don't like it.

seems to be the worst possible performance scenario??

I'm a Java developer but I've never used Data Access Objects so I may
not be
qualified to comment on this question.

However, I would be quite astonished if "the engine" _EVER_ "just
decides,
screw it, I'll just make a new one". (I assume that when you say "the
engine" you mean the DB2 code itself, as opposed to some third party
add-on
to DB2.)


i have this irrepressible lower brain stem memory that some databases
(not for certain db2, hence the question), do just that.


That's quite possible but I don't know the other databases well enough to
say yes or no with any certainty.
Frankly, I've never heard so much as a whisper of a hint of a rumour of
a
suggestion that DB2 could transform an SQL Update statement to an Insert
and/or a Delete and I've been working with DB2 in one capacity or
another
for 20 years.

As far as I know, an Update is always an Update, a Delete is always a
Delete, and an Insert is always an Insert and none of these can change
from
one to the other.

Of course, I *could* be wrong....

Having said that, an *application* which uses DB2 should be able to turn
an
update statement into a delete/insert. For instance, if a user submitted
a
query like this through an interface that I wrote:
update Employee
set salary = salary * 1.1
where empno = '000010'

I could imagine converting that to:
1) a delete that removed the current row for employee 000010
2) an insert to create a new row for employee 000010 but with a 10%
raise in
salary.

Of course, the code to do this would also need a select to determine the
current values of all of the other columns in the original row so that
they
could be copied to the new row during the insert.


thus handing over the responsibility for data concurrency to the


application.
just the sort of thing that irritates my piles. see following.
and preceding.

However, there could easily be important side-issues with respect to
related
data. For instance, if the Employee table in the example had dependent
tables, such as Employee_Health _Claims, doing the delete in the Employee
table could cause all rows of Employee_Health _Claims that relate to that
Employee to be deleted if a DELETE CASCADE rule was in effect. (And rows
in
tables dependent on Employee_Health _Claims might also be deleted if the
DELETE CASCADE rule was in effect on this foreign keys.)

By the same token, the delete in the Employee table would fail if there
was
a DELETE RESTRICT rule between Employee and Employee_Health _Claims. You
would have to consider Referential Integrity issues very carefully if
you
chose to convert an Update into a Delete/Insert combination.

After all, you wouldn't want an update in one table to cause all sorts
of
data to be deleted just because you thought you might get a slight
advantage
by turning one Update into a Delete followed by an Insert.

Since I'm not sure if I really understood the intent of your question, I
don't know if this answers it. If not, perhaps you can clarify what you
are
after. Then I - or others on this newsgroup - could try again.


two, related concerns (sorry if my OP was obtuse):

- updating every column of each updated row has *got* to be too expensive
for words; far more (if it's ever been quantified) than the 1 or 2 or 3
columns actually changed. are there published stats on the performance
impact?? that is: at what point, either number/type of columns, or
average byte count, etc. is the penalty so large that whatever (coder)
time saved in development by relying on a code generation tool is
overwhelmed by the run-time penalty of updating all columns?? OR, is
DB2 smart enough to see that the incoming column data matches in
table data, and says, "screw it. it ain't different. i ain't
touching it"???? in this scenario, using code generating tools is
not a bad thing, beyond the fact that folks soon forget what their
data looks like.


I don't know precisely what happens in DB2 with respect to updates; after
all, IBM doesn't publish the source code so I wouldn't know.

However, I have always understood that DB2 stores data as rows, that rows
are stored in pages, and DB2 works with pages of data in its bufferpools. In
other words, DB2 isn't doing separate I/Os to get each value on a row.
Furthermore, I've always believed that DB2 only updates the columns that are
in the SET clause of the Update statement and doesn't attempt to rewrite
columns that aren't changed. Again, that is just my *belief*; I can't say
that with certainty without looking at the source code. If anyone who is
absolutely certain can confirm or deny that belief, I'd appreciate it.

So I think the actual behaviour of an application depends on the Update
statement that it generates. If an application - or application generator -
puts every column of the table in the SET clause of its Update statements,
even if the column value isn't being changed, I'd expect that to be slower.
But that would be the fault of the application or generator, not DB2.

- if DB2 sees that the row is being nuked, does it escalate (as it does do
with locks) to insert/delete (or vice versa, of course). and, another
if, so is this more or less expensive than doing the in-place insert?
an optimizer might consider "all aspects", and thus, basically, make
a mistake from a performance point of view??


DB2's Lock Manager can certainly escalate locks and does that when that is
required. However, you should understand that the Lock Manager works at the
row (or page, or table, or tablespace, or database level), not at the level
of individual fields. I'm not aware of any circumstances where it can lock
less than a full row. Lock escalation is always about locking more rows (or
pages), never about locking more fields on one row.

Again, I don't think it is possible for DB2 to convert an Update to a
Delete/Insert, except in that one special case that Pierre noted.

As always, I assume that others on this newsgroup will correct me if I've
inadvertently said anything wrong.

Rhino


--
Pierre Saint-Jacques - Reply to: sesconsjunk at attglobaljunk dot com
Reconstruct address: Remove the two junk and replace at and dot by
their symbols.
IBM DB2 Cerified Solutions Expert - Administration
SES Consultants Inc.
Nov 12 '05 #8
I think an update on a Union ALL view WITH ROW MOVEMENT can also do that.

PM
Nov 12 '05 #9
Correct and also update to a range-clustered table.
When range partitioning become availbale, that too will have the same
behaviour.

To comment on the question what DB2 really updates in a "real" update.
DB2 actually ahndles teh fact that more elements are mentioned in the
SET clause (or before trigger) than ar eactually changed (SET c1 = c1).
By default these smarts are ON. There is a Db2 registry variable called
ASSUMEUPDATED (or something like that) which can be set to disable the
smarts (to shave some codepath in well behaved high performance
environments).
The requirement to be that smart indeed coems from teh fact that many
Apps don't bother to find out what was updated. They simply update all
the columns.
The savings, btw is not in the writing of the page. It's in the logging.
And DB2 indeed logs the stripe from the first changed column to the last
changed column.

Cheers
Serge
Nov 12 '05 #10

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

Similar topics

8
8606
by: Jason | last post by:
I have a table that matches up Securities and Exchanges. Individual securities can belong on multiple exchanges. One of the columns, named PrimaryExchangeFlag, indicates if a particular exchange is the primary exchange for that symbol. Each symbol can only have one primary exchange. I am trying to write a insert/update/delete trigger that enforces this rule. The rules I have thought of are as follows: Insert If new row has flag...
1
3680
by: Google Mike | last post by:
I have one table of new records (tableA) that may already exist in tableB. I want to insert these records into tableB with insert if they don't already exist, or update any existing ones with new data if they do already exist. A column (Action) in tableA already tells me whether this is an INSERT, UPDATE, or DELETE. I'm able to derive that I can do an insert with select * into tableB from tableA where Action = 'INSERT' ....and I think...
16
17011
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then IF FOUND UPDATE <TABLE> SET .... <Values entered here> ELSE INSERT INTO <TABLE> VALUES <Values...
2
21377
by: Tinius | last post by:
I am trying to update a field of type IMAGE. I am able to do this by deleting the record and then INSERTing a new record as shown below in the commented section. But I really want to do this with an UPDATE command as shown below in the un-commented code. I assume this is possible. The image is passed as a byte array called 'content'. I then want to update the column STREAM with the new 'CONTENT'.
25
4065
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
3
3447
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all the necessary records in it when testing it. I get the error "No value given for one or more required parameters." when I try to update the database. Can you tell me what am I doing wrong?
1
6208
by: abhi81 | last post by:
Hello All, I have a table on which I have created a insert,Update and a Delete trigger. All these triggers write a entry to another audit table with the unique key for each table and the timestamp. Insert and Update trigger work fine when i have only one of them defined. However when I have all the 3 triggers in place and when i try to fire a insert query on the statement. It triggers both insert and update trigger at the same time and...
13
1880
by: =?Utf-8?B?VmVybm9uIFBlcHBlcnM=?= | last post by:
I am using VS2005. I created a Windows Appication project. Inside the Server Explorer, I created a new SQLExpress database, and then created a new table. I added the rows, making my first row an integer, and setting the identity property to true. I set that row to be my primary key. I then added a dataset, and added my table to the dataset. When I configure the table, I have no Update or Delete commands, even though the wizard has the...
0
2288
by: magnolia | last post by:
i created a trigger that will record the changes made to a table .everything works fine except the insert query.whenerever i try to insert a record it fires insert and update triger at the same time which means i hav 2 record for every insert operation. any help appreciated. thank u herez teh code i tried. ALTER TRIGGER trg_ContactAddress_Audit ON Address FOR DELETE, INSERT, UPDATE AS
0
8707
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9174
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9074
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
7953
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5947
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
4725
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3158
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2520
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2110
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.