[TYPO3-core] RFC: Bug 4581: Duplicate entry on cache_pagesection on reloading twice

Dmitry Dulepov dmitry at typo3.org
Tue Jan 23 16:47:47 CET 2007


Hi!

Oliver Hader wrote:
> Situation:
> When more visitory come to a page in Frontend at nearly the same time
> and caching is disabled (config.no_cache=1) SQL errors occur. As single
> user it can be reproduced on fast reloading the same page.
> 
> Problem:
> SQL error "duplicate entry" for query "INSERT INTO cache_pagesection".
> First an UPDATE query is sent to the database in hope that a
> corresponding record exists. Afterwards mysql_affected_rows is used to
> determine if the previous query was successful. If the UPDATE failed, a
> INSERT query is sent.
> mysql_affected_rows [1] also fails (returns zero) if the records exists
> but wasn't updated because old values were equal to new values. And then
> also an INSERT is sent. And this produces the "duplicate entry" error.
> 
> Solution:
> Replace mysql_affected_rows by mysql_info [2] which returns some more
> information and can tell, what happened on database.

I doubt it is possible to solve without using transactions. When two 
users may come to the site, the following sequence may happen (number is 
user number):

(1) UPDATE -> fail
(2) UPDATE -> fail
(2) INSERT -> ok
(1) INSERT -> fail

For mysql there is a non-transactional solution:
http://dev.mysql.com/doc/refman/5.1/en/replace.html

But I do not know what to do for other databases.

Personally I would do it this way:
- check if DB is mysql
	- yes: use REPLACE
	- no: use transaction syntax and hope for the best

I would not give +1 because I believe that this solution does not solve 
the problem :(

-- 
Dmitry Dulepov

Web: http://typo3bloke.net/
Skype: callto:liels_bugs

"It is our choices, that show what we truly are,
far more than our abilities." (A.P.W.B.D.)


More information about the TYPO3-team-core mailing list