Page MenuHomePhabricator

Test fails with "Can't reopen table" error.
Open, MediumPublic

Description

This is a tracking ticket for problems and workarounds related to the following issue:

  1. MySQL and older versions of MariaDB (and possibly other database systems) do not allow a temporary table to be used more than once in a query. Any attempt to self-join a temporary table, or to use a temporary table in a join as well as a sub-query, or two sub-queries, will result in "Error 1137: Can't reopen table".
  2. MediaWiki's framework for phpunit tests "shadows" all database tables with temporary tables.
  3. Thus, all query that use any table more than once will fail in phpunit tests.

There is no real fix as long as we support databases that have this problem. This ticket provides a central place for discussing the issue and best practices around it. It exists so people running into this issue will find useful information and can benefit from past experience. This ticket also serves as a marker that relevant code can link to, allowing such code to be easily identified and located.

Workaround for this include:

  • Skip the test under MySQL
  • Force the use of real tables instead of temporary tables
  • Copy the relevant (temporary) table and use the copy for one of the usages in the query

See also:

Event Timeline

daniel created this task.Jun 22 2020, 2:55 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJun 22 2020, 2:55 PM
daniel updated the task description. (Show Details)Jun 22 2020, 2:57 PM
daniel updated the task description. (Show Details)

Change 607070 had a related patch set uploaded (by Daniel Kinzler; owner: Daniel Kinzler):
[mediawiki/core@master] Track worarounds for "can't reopen tables" error

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

BPirkle triaged this task as Medium priority.Jun 24 2020, 8:19 PM

Change 607070 merged by jenkins-bot:
[mediawiki/core@master] Fix "can't reopen tables" test error for Special:BrokenRedirects

https://gerrit.wikimedia.org/r/c/mediawiki/core/ /607070

Change 617134 had a related patch set uploaded (by Reedy; owner: Daniel Kinzler):
[mediawiki/core@REL1_34] Fix "can't reopen tables" test error for Special:BrokenRedirects

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