Josh SP
02-17-2006, 06:24 AM
Hi, maybe I'm misunderstanding how REPLACE DELAYED works, but I seem to be having some trouble, and I'm wondering if someone can point me in the right direction. Thanks.
THE SITUATION
I have a PHP/MySQL website that needs to update a value in a table upon each page load. The problem is that this table is also accessed by many SELECT statements, a few of which are unavoidably slow. When one of these slow SELECTs is running and an UPDATE is attempted, my understanding is that the UPDATE locks the table and doesn't let any other SELECTs access the table until the original slow SELECT *and* the UPDATE have completed. I'm witness this occuring, so I'm fairly certain I understand this part correctly. Because of this, whenever a slow SELECT occurs, all the pages on the site (the ones that access the table in question, at least) hang for several seconds.
MY ATTEMPTED SOLUTION
I changed the UPDATE to a REPLACE in order to take advantage of the DELAYED option. I figured this would solve my problems because the table would not be locked to the exclusion of other SELECTS. I thought that the DELAYED option would cause the REPLACE to be nice and let other pending SELECTs access the table.
DOESN'T WORK AS INTENDED
This doesn't seem to be working. The DELAYED option seems to *not* allow other SELECTs to access the table. I have verified this via the mysql command line interface.
SOME DETAILS
Here is the REPLACE SQL I'm using:
REPLACE DELAYED `object_scores` (`object_id`, `hits`, `score`, `weighted_num_votes`, `weighted_vote_sum`) VALUES (172582, 68, 88.01, 3.67371, 36.3206);
Here's the table:
> show create table object_scores;
+----------
| object_scores | CREATE TABLE `object_scores` (
`object_id` int(10) unsigned NOT NULL default '0',
`hits` int(10) unsigned NOT NULL default '0',
`score` float NOT NULL default '0',
`weighted_num_votes` float NOT NULL default '0',
`weighted_vote_sum` float NOT NULL default '0',
PRIMARY KEY (`object_id`),
KEY `hits` (`hits`),
KEY `score` (`score`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
+----------
Any advice would be greatly appreciated. Thanks!
THE SITUATION
I have a PHP/MySQL website that needs to update a value in a table upon each page load. The problem is that this table is also accessed by many SELECT statements, a few of which are unavoidably slow. When one of these slow SELECTs is running and an UPDATE is attempted, my understanding is that the UPDATE locks the table and doesn't let any other SELECTs access the table until the original slow SELECT *and* the UPDATE have completed. I'm witness this occuring, so I'm fairly certain I understand this part correctly. Because of this, whenever a slow SELECT occurs, all the pages on the site (the ones that access the table in question, at least) hang for several seconds.
MY ATTEMPTED SOLUTION
I changed the UPDATE to a REPLACE in order to take advantage of the DELAYED option. I figured this would solve my problems because the table would not be locked to the exclusion of other SELECTS. I thought that the DELAYED option would cause the REPLACE to be nice and let other pending SELECTs access the table.
DOESN'T WORK AS INTENDED
This doesn't seem to be working. The DELAYED option seems to *not* allow other SELECTs to access the table. I have verified this via the mysql command line interface.
SOME DETAILS
Here is the REPLACE SQL I'm using:
REPLACE DELAYED `object_scores` (`object_id`, `hits`, `score`, `weighted_num_votes`, `weighted_vote_sum`) VALUES (172582, 68, 88.01, 3.67371, 36.3206);
Here's the table:
> show create table object_scores;
+----------
| object_scores | CREATE TABLE `object_scores` (
`object_id` int(10) unsigned NOT NULL default '0',
`hits` int(10) unsigned NOT NULL default '0',
`score` float NOT NULL default '0',
`weighted_num_votes` float NOT NULL default '0',
`weighted_vote_sum` float NOT NULL default '0',
PRIMARY KEY (`object_id`),
KEY `hits` (`hits`),
KEY `score` (`score`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
+----------
Any advice would be greatly appreciated. Thanks!