Re: [Patch] DB_DataObject and Postgres INSERT race condition obtaining last key
| From: | Alexey Borzov | Date: | Fri, 13 Oct 2006 18:33:59 +0000 |
| Subject: | Re: [Patch] DB_DataObject and Postgres INSERT race condition obtaining last key | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-44507@lists.php.net to get a copy of this message | ||
Hi,
Matt Craig wrote:
Even if you do connection pooling, each script still gets its own connection (=session).Much better fix. I will test this. A question remains in my mind about connection pooling. currval() says in the documentation "Notice that because this is returning a session-local value, it gives a predictable answer even if other sessions are executing nextval meanwhile." on http://www.postgresql.org/docs/7.4/static/functions-sequence.html With pooled connections through the web server are these pooled connections considered the same session?I've had a brief look, the bug is in DB_DO, it incorrectly gets the last value of the sequence: $pgsql_key = $DB->getOne("SELECT last_value FROM ".$seq); Should be instead: $pgsql_key = $DB->getOne("SELECT currval('".$seq . "')"); PostgreSQL's built-in currval() function automatically takes care of giving the proper value. Of course, this fix is also a bit shorter than the proposed patch. :-DI knew there has to be a way to get the connection's last sequence value. ;-) Nice find. Matt: could you try this instead of your patch and see if it fixes your problem?