Page MenuHomePhabricator

Database::upsert: weird behaviour after upgrading to 1.29.x or installing a fresh 1.29.x
Closed, DuplicatePublic

Description

On seemingly every single page access MediaWiki 1.29 and 1.29.1 issue UPDATE followed by INSERT on module_deps with the exact same data in both statements. The INSERT statement is wrapped in a transaction and fails with

Sep 29 22:49:31 db postgres[90132]: [11-3] azurlane_wiki STATEMENT:  INSERT /* Wikimedia\Rdbms\Database::upsert  */ INTO "module_deps" (md_module,md_skin,md_deps) VALUES
[skipping the entire statement here]
Sep 29 22:49:32 db postgres[90135]: [9-1] ERROR:  duplicate key value violates unique constraint "md_module_skin"
Sep 29 22:49:32 db postgres[90135]: [9-2] DETAIL:  Key (md_module, md_skin)=(mediawiki.action.view.postEdit, vector|en-gb) already exists.

Judging by DBQuery debug logs, MediaWiki 1.28 (and 1.26 as well? unsure at the moment, but no errors are logged for these) only issues an UPDATE statement for the same table without INSERT following (provided the data is already in the table).

This floods the PostgreSQL server log files with unnecessary messages. Is there a reason this behaviour was introduced in 1.29?

Event Timeline

ERROR: duplicate key value violates unique constraint "md_module_skin"

This seems similar to T167942, see the repsonse from @Krinkle on that matter.

Thank you. I guess this won't ever be fixed, then.

I'll look into hacking an ON CONFLICT IGNORE (PostgreSQL's native UPSERT since 9.5) into the INSERT statement as this query is performed on almost every HTTP request to the wiki so the log file writes are introducing a slight performance hit (not to mention it makes it harder to find actual errors in them)

the log file writes are introducing a slight performance hit (not to mention it makes it harder to find actual errors in them)

I raised that point to but given the response no one seems to care enough to actually fix the issue. @Krinkle, setting the log to evade exception traces doens't make it go away, outright declining T167942 doesn't resolve anything, it just hides the issue.