Re: A Question of design.



Chung Leong wrote:
Create an array of what to add, capture all existing items in
another array , then it's a simple question of array_diff() for
items that are invalid.

Then create an array of already owned items, array_intersect() will
tell you what to update, the rest will have to be added.
Then you end up with a race condition, I think even if a transaction
is used. If there are two threads trying to insert the same data
running simultaneously, a transaction would not block the second
thread from fetching the same result set as the first. Thus both
threads could
think that a particular record doesn't exist and both would insert it.
You would need to lock the table for the duration of the entire
operation, which is pretty lousy.

My solution was purely to give him back the information he wants (he not
only wants to reject invalids, update already existing, and insert new, but
he wants to know which ones they are).

The actual updating can still be done with the previous simple replace
into, avoiding race condition.
--
Grtz,

Rik Wasmus


.



Relevant Pages

  • Re: Q: Checking the size of a non-allocated array?
    ... an actual argument is already invalid ... First note that you don't have an unallocated array in the subroutine. ... it is comparable to disassociated or undefined pointers. ... Obviously the compiler has ...
    (comp.lang.fortran)
  • Re: Transferring related records from table to table in one transaction: Two cursors? [Mac FMP 9 Adv
    ... I should then begin inserting each row in this virtual two-dimensional ... array into new related rows in Postings. ... After having inserted all rows into the Postings table, I can commit the ... You need to create importing routines that may store total record numbers in fields to confirm the entire transaction has taken place, in case of a crash or interruption during the import, but this also applies to other methodologies. ...
    (comp.databases.filemaker)
  • Re: [PATCH 2/2] improve ext3 fsync batching
    ... fsync when a commit is currently in progress, ... The average transaction commit time is a direct measurement of the past behaviour, ... Against an array, we saw a 2.5x speedup with the new code. ... many other tasks are joining this task's transaction. ...
    (Linux-Kernel)
  • Re: Transferring related records from table to table in one transaction: Two cursors? [Mac FMP 9 Adv
    ... I should then begin inserting each row in this virtual two-dimensional ... array into new related rows in Postings. ... After having inserted all rows into the Postings table, ... newly created Transaction record - thus committing all of the insertions ...
    (comp.databases.filemaker)
  • Re: [PATCH 2/2] improve ext3 fsync batching
    ... but we currently sleep 3-4 times longer waiting to batch for an array than it takes to complete the transaction. ... when commit times go up to seconds? ... Transactions on that busier drive would take longer, we would sleep longer which would allow us to batch up more into one transaction. ...
    (Linux-Kernel)

Loading