You'll have much less overhead checking with a select first and then insert if not exists
olinux --- Sebastian Bergmann <[EMAIL PROTECTED]> wrote: > [resent; original posting didn't make it (through > the spam protection)] > > With phpOpenTracker I have for instance the > following table > > CREATE TABLE pot_foo ( > data_id int(11) NOT NULL, > string varchar(255) NOT NULL > > PRIMARY KEY (data_id) > ) DELAY_KEY_WRITE=1; > > For each visitor, I need to make sure that I have > a row for the > current (data_id, string) pair in the table. > > For performance reasons it makes no sense to use a > SELECT query to > determine whether or not the row in question > already exists in the > table. > > So, what is the better / faster way to do this > with MySQL: > > 1) Use "REPLACE INTO" at the cost of deleting > the old row (which > is identical!) every time. > > 2) Use "INSERT INTO" and ignore the failure of > the query if the > row (ie. the PRIMARY KEY) already exists. > > -- > Sebastian Bergmann > http://sebastian-bergmann.de/ > http://phpOpenTracker.de/ > > Did I help you? Consider a gift: > http://wishlist.sebastian-bergmann.de/ > > --------------------------------------------------------------------- > Before posting, please check: > http://www.mysql.com/manual.php (the manual) > http://lists.mysql.com/ (the list > archive) > > To request this thread, e-mail > <[EMAIL PROTECTED]> > To unsubscribe, e-mail > <[EMAIL PROTECTED]> > Trouble unsubscribing? Try: > http://lists.mysql.com/php/unsubscribe.php > __________________________________________________ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php