since upgrading to mysql Ver 14.14 Distrib 5.1.39, my log is reporting numerous errors like those below. I've tried resetting the index, with no change. MySQL tables have been analyized, optimized, and repaired, too.
Duplicate entry '268' for key 'PRIMARY' query: INSERT INTO search_total (word, count) VALUES ('268', 0.30102999566398) in /var/www/www.sterndata.com/drupal-6.14/modules/search/search.module on line 290.
Duplicate entry 'palmrest' for key 'PRIMARY' query: INSERT INTO search_total (word, count) VALUES ('palmrest', 0.30102999566398) in /var/www/www.sterndata.com/drupal-6.14/modules/search/search.module on line 290.
Comment | File | Size | Author |
---|---|---|---|
#6 | 638702.patch | 1.6 KB | jhodgdon |
Comments
Comment #1
kribby CreditAttribution: kribby commentedSubscribing
Comment #2
jhodgdonCan you try going to the Search settings page and clicking on the link that rebuilds the search index, and then running cron from the Status Report page until Search reports that everything is indexed?
Comment #3
sterndata CreditAttribution: sterndata commentedNope. Still get errors when a page is updated after the index is rebuilt.
Comment #4
jhodgdonThat's very interesting. I'm looking at those lines in the search module code:
In other words, it is first doing an UPDATE query to try to update an existing row in the search total table. And then if the UPDATE says "No rows were affected", it's assuming that the word was not in the database table, and trying to use an INSERT query instead.
So it looks like the db_affected_rows() function is not working correctly for you: it should be reporting that it updated that row, and instead it is reporting that it updated nothing.
Very interesting....
So we need to investigate why db_affected_rows() isn't doing the right thing, but in the meantime I think you can probably ignore those errors, because the UPDATE probably worked.
Comment #5
jhodgdonHah! I think I have possibly found the answer. From the documentation of the PHP function mysql_affected_rows():
So possibly this is the issue. If the index is being rebuilt and the count is the same as it was before, it's possible that the affected row count will be zero.
Comment #6
jhodgdonLooking at the code base for Drupal 6, I see that in most cases, when db_affected_rows() is used to figure out if an update took place, the next INSERT statement is preceded by @ to suppress the error that could result when the insert figures out the row actually did exist. This was not done in two places: the search module being one of them. Here's a patch to remedy that.
Comment #7
jhodgdonComment #8
jhodgdonExample of another place it's done this way in Drupal 6:
Comment #10
jhodgdonHuh, I didn't know we had testing now for D6 patches. This patch applies fine for me. I'll try changing the version.
Comment #11
jhodgdon#6: 638702.patch queued for re-testing.
Comment #12
jhodgdonI just filed a related issue about what the return value should be for D7 update queries (because the same problem exists there):
#718540: Better documentation in query.inc
Comment #13
ti2m CreditAttribution: ti2m commentedEhm,
so the solution to this is to supress the warning??? Then we could just skip the whole if clause in general. Other option would be to do something like
(could probably be done in a nicer way)
to replace
Comment #14
jhodgdonPeterP - Right, it bothers me too, but it's definitely the pattern elsewhere in Drupal 6 core. What you're suggesting would be better, but less efficient, as it would require another query.
Comment #15
francisconi.org CreditAttribution: francisconi.org commentedSubscribing..
Comment #16
brianmercer CreditAttribution: brianmercer commentedI just started getting the same error as the op since upgrading to Ubuntu 10.04 lucid with mysql Ver 14.14 Distrib 5.1.41.
The patch at #6 applied fine to Pressflow 6.16.77 and stopped the error messages.
Thanks.
Comment #17
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis makes sense, even if I cannot explain why this shows up so late in the game.
Comment #18
cdale CreditAttribution: cdale commentedI too am getting this since my lucid upgrade, but only with mysqli. mysql seems to work as before. Perhaps the flags passed to mysqli_real_connect() are not respected anymore?
Comment #19
simg CreditAttribution: simg commentedI'm pretty sure this problem is caused by a bug in the db_affected_rows() function.
I've reported the bug and post a suggested fix (that works) here.
http://drupal.org/node/805858
I don't have "commit" access to fix the CVS version.
This bug seems to be the cause of a number of errors in the issue queue ?
Incidently, suppressing the warning is not a good solution at all (sorry)!
Comment #20
jhodgdon#798626: Cron produces duplicate entry error in search.module just marked as a duplicate of this issue.
Comment #21
Gábor Hojtsy@PeterP: that would run at least two queries: a SELECT and an INSERT/UPDATE, while our current code only runs one UPDATE query if possible or an INSERT if the update failed.
@simg: the db_affected_rows() function works as named and documented. It returns 0 when the row was updated to be the same and we pay a little performance penalty in that case, however your suggested patch in the linked issue makes us pay a penalty at all invocations of the function.
Committed, thank you.
Comment #22
AlexisWilke CreditAttribution: AlexisWilke commentedGábor Hojtsy,
Note that you are making improper use of the db_affacted_rows() function:
As you can see here: http://api.drupal.org/api/function/db_affected_rows/6 the function may return -1 which means TRUE in your situation. You ought to use > 0 instead.
Or have the Core people change the code and check for the return value, if -1, return 0.
Thank you.
Alexis Wilke
Comment #23
Gábor Hojtsy@AlexisWilke: this seems like both a documentation omission and a code problem if that is the case. Where did you open an issue for these?