Insert or update ??
Posted in 1999
Topics: Performance & Tuning
Hi all, I need some inputs on performance in following scenarios : Scenario 1 I have a table say t1. This table has 11 fields and 4 indexes (Record size : 180 bytes). I read records from this table and depending on some condition I have to set a expired flag for that record. Currently this table does not have a expired flag field. I have another table say t2 which stores the expired flag. This table has 2 indexes (Record Size : 15). Whenever the condition for expiry has matched, the process INSERTs the record in table t2. Scenario 2 Add a expired flags field to table t1 above. Now, whenever the expiry condition is matched the process will set the expired flag as TRUE for the record currently read and UPDATE the record in the database. In this case I no longer need the table t2. Which scenario will give better performance ? Thanks, Sanjay.
>Scenario 1 >I have a table say t1. This table has 11 fields and 4 indexes (Record size : >180 bytes). >I read records from this table and depending on some condition I have to set >a expired flag for that record. Currently this table does not have a expired >flag field. >I have another table say t2 which stores the expired flag. This table has 2 >indexes (Record Size : 15). > >Whenever the condition for expiry has matched, the process INSERTs the >record in table t2. > >Scenario 2 >Add a expired flags field to table t1 above. Now, whenever the expiry >condition is matched the process will set the expired flag as TRUE for the >record currently read and UPDATE the record in the database. >In this case I no longer need the table t2. > >Which scenario will give better performance ? As with all things, gather the data from the real environment. Aside from that, assuming that you use RI to control data, and assuming that as you read the records from t1 that you are using an update cursor to do so, and assuming that you prepare your sql, and (just one more) assuming that you are using an update where current of syntax in scenario 2, the update will be more efficient. If you examine all that is being done in both scenarios all of the select overhead is present regardless of which is used. At that point it takes less additional work to update a non-indexed row which has already been selected than to insert a row and manipulate at least one index.