Re: Performance of ON DUPLICATE KEY and other options?
Jay Pipes wrote:
> I'm not sure I understand you. What is the
> purpose of updating the inputTable at all?
>
Well, all tables start empty when you create them. In the process of filling up a table like inputTable, where there may be multiple occurrences of the data you're putting in that you don't want duplicated (where you want a unique identifier to stand in for the value in normalized tables), you have to have some way of knowing if the value you want to put in is new or a duplicate of a value loaded prior.
When you're running through your raw input, you don't know if the value's already in there. You could try
SELECT qid from inputTable where input='?in'
first and then do an INSERT if you get no response.
Or you could use the ON DUPLICATE KEY UPDATE qid=LAST_INSERT_ID(qid) mechanism on your INSERT to try both with one statement. My question was whether the former approach performed better than ON DUPLICATE KEY UPDATE.
If the above is long winded and/or missing your point, the other thing I think you might mean is that there are/were other columns in inputTable that also track other aspects about the rows in inputTable. I left those out to simplify the example and discussion. In my case those things involve booleans indicating whether the input was as is or changed by a normalization process. I can also imagine a case where inputTable might have an integer column counting the number of different users who used the same value, etc.
So to flesh out the original example with the other boolean columns, the non-ON DUP logic would look
SELECT qid FROM inputTable where input='?in'
if (qid not null)
UPDATE inputTable SET rawInput=true where qid=?qid
else
INSERT INTO inputTable (input, rawInput) VALUES (?in, ?raw);
Thanks
_mark
Subject
Views
Written By
Posted
2242
September 23, 2005 09:20AM
1352
September 23, 2005 10:48AM
1428
September 23, 2005 10:56AM
1354
September 23, 2005 11:20AM
Re: Performance of ON DUPLICATE KEY and other options?
1493
September 23, 2005 11:38AM
1363
September 23, 2005 03:33PM
1361
September 23, 2005 04:25PM
1294
September 23, 2005 04:59PM
1512
September 26, 2005 02:30PM
1378
November 10, 2005 10:12AM
1414
November 10, 2005 10:26AM
1335
November 10, 2005 02:19PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.