Page MenuHomePhabricator

Error 1050: Table 'user_watch_scores' already exists
Closed, ResolvedPublic

Description

With MediaWiki 1.43 and Extension Version 4.5, I have seen "Error 1050: Table 'user_watch_scores' already exists" as part of Function: PageWatchesQuery::createUserWatchScoresTempTable. While this might be a transient error, it would be better to ensure the php handles cases where this could occur.

If the intent is to create it only when it doesn't exist, then could change line 139 of PageWatchesQuery.php
from

CREATE TEMPORARY TABLE user_watch_scores

to

CREATE TEMPORARY TABLE IF NOT EXISTS user_watch_scores

Otherwise, if the intent is to always create it each time, then you could modify to drop table if it exists, then create it. Lines 135 to 139
from:

private function createUserWatchScoresTempTable() {
		$dbw = WatchAnalyticsUtils::getWriteDB();

		$sql = <<<END
			CREATE TEMPORARY TABLE user_watch_scores

to:

private function createUserWatchScoresTempTable() {
		$dbw = WatchAnalyticsUtils::getWriteDB();
		$dbw->query( 'DROP TEMPORARY TABLE IF EXISTS user_watch_scores;', __METHOD__ );
		$sql = <<<END
			CREATE TEMPORARY TABLE user_watch_scores

Event Timeline

@MichaelLyle That is a fair fix. Do you wish to submit a patch or do you want me to create one ?

@Techwizzie I'll let you submit the patch (whichever path is best)

Change #1185949 had a related patch set uploaded (by Yaron Koren; author: Yaron Koren):

[mediawiki/extensions/WatchAnalytics@master] Drop temp table user_watch_scores before (re-)creating it

https://gerrit.wikimedia.org/r/1185949

Change #1185949 merged by jenkins-bot:

[mediawiki/extensions/WatchAnalytics@master] Drop temp table user_watch_scores before (re-)creating it

https://gerrit.wikimedia.org/r/1185949

Yaron_Koren claimed this task.
Yaron_Koren subscribed.

@MichaelLyle - thanks for the code fix! I decided to go with deleting the old temporary table each time - it seems "safer", if any of the data changed in the meantime.