0

I have a data transfer tool that transfers information from one database to another. Every hour it will issue an UPDATE on all the rows in a table. I already have an INSERT trigger to dump the data from that one table into a number of other tables. I added an UPDATE trigger to edit the other tables, but it's making the extra processing is making the entire UPDATE process run slowly.

I'd like to wrap the body of the UPDATE trigger in an IF statement that compares the old and new rows, and skips processing if nothing has changed. Is it possible to compare an entire row against another, like this?

IF new = old THEN ...

Or is there no other option than to check each column individually?

tkooser
  • 125
  • 1
  • 11
  • You can try using workaround from http://stackoverflow.com/questions/6296313/mysql-trigger-after-update-only-if-row-has-changed (timestamp column) – a1ex07 Jan 18 '12 at 21:05

2 Answers2

0

Sadly, no, you're going to need to compare each column individually. Probably not the answer you were hoping for.

davidethell
  • 11,708
  • 6
  • 43
  • 63
0

If speed is the issue here, I would either save a timestamp of when it was last edited or a checksum.

Using the latter approach, if you have a table with three rows A, B and C, I would modify this scheme to also include a new row, cksum.

Whenever you insert something, you would in the cksum insert a value generated using a fast hashing algorithm, for instance MD5. This checksum could be something like

checksum = MD5(A + B + C);

This way, whenever having to insert something, you would only have to compare with the cksum field.

kba
  • 19,333
  • 5
  • 62
  • 89