Re: MySQL and table locking
| From: | Manuel Lemos | Date: | Fri, 19 May 2000 17:38:56 +0000 |
| Subject: | Re: MySQL and table locking | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-53@lists.php.net to get a copy of this message | ||
Hello Jack,
On 19-May-00 12:30:20, you wrote:
> A better solution is this:
>CREATE TABLE counters
> (
> u int unsigned NOT NULL,
> c int unsigned NOT NULL,
> UNIQUE(u)
> );
> Then, the individual counter could be implmented this way:
>UPDATE counters SET c=c+1 WHERE u=236;
>SELECT c FROM counters WHERE u=236;
I don't see why this is a better solution. Locking tables is always a
risky thing to do and should be avoided if possible. Not only you may risk
to deadlock database connections but you will be also will be slowing them
down.
You'd better stick to auto-increment tables because AFAIK that's the only
atomic incrementing and read operation that MySQL can perform. If only it
supported transactions or stored procedures, things could be much
different.
FYI, auto-increment tables are used to emulate sequences (that MySQL
doesn't support natively as well) under Metabase - a PHP database
abstraction package. Look here for more information:
http://phpclasses.UpperDesign.com/browse.html/package/20
Regards,
Manuel Lemos
Web Programming Components using PHP Classes.
Look at: http://phpclasses.UpperDesign.com/?user=mlemos@acm.org
--
E-mail: mlemos@acm.org
URL: http://www.mlemos.e-na.net/
PGP key: http://www.mlemos.e-na.net/ManuelLemos.pgp
--