FW: [PHP-WIN] SQL SELECT while INSERTING
| From: | Svensson, B.A.T. | Date: | Sat, 09 Dec 2000 08:48:04 +0000 |
| Subject: | FW: [PHP-WIN] SQL SELECT while INSERTING | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-4389@lists.php.net to get a copy of this message | ||
BE VERY CAREFUL HERE!
If your query is running in an environment with concurrency
(which is highly likely in a database environment) you need
to perform this either as an atomic action or to implement
an voting mechanism to be sure that you really retrieve the
max value from the tuple you just inserted.
With the atomic action approach, you can simply make a lock
in the database, and then not release the lock until you made
your max() select. But this can cause a performance hit in
the database if you are going to make a lot of inserts, since
the lock will prevent other applications to manipulate the
table you are working with.
The voting mechanism on the other hand is nicer to the database
performance, but on the other hand you can never be 100% sure
of the result - just 99.999...% or something... :)
The naive approach to just perform a max() select can only
be guaranteed to return the correct result if you run as a
single user in the database - in other case you can never
be sure of weather the result actually is correct or not.
Of course in most case it will be correct even in an
environment with concurrency - but what will happen with
your data when it isn't?
Regards,
Anders
>-----Original Message-----
>From: Asendorf, John [mailto:JAsendorf@lcounty.com]
>Sent: Thursday, December 07, 2000 2:57 PM
>To: Michael Rudel; Php-Windows (E-mail)
>Subject: RE: [PHP-WIN] SQL SELECT while INSERTING
>
>
>That's what I'm looking for SELECT MAX, that should do it!
>Thanks everyone!
>
>---------------------
>John Asendorf - jasendorf@lcounty.com
>Web Applications Developer
>http://www.lcounty.com - NEW FEATURES ADDED DAILY!
>Licking County, Ohio, USA
>740-349-3631