[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Page MenuHomePhabricator

Test fails with "Can't reopen table" error.
Closed, ResolvedPublic

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 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

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

Not Tracking-Neverending per definition. Also, all related Gerrit patches are merged or abandoned.

I ran into this problem when writing a big integration test, and I used the workaround number 2 (force the use of real tables instead of temporary tables). There doesn't seem to be a supported way to do it in MediaWikiIntegrationTestCase, so I hacked it like this: https://gerrit.wikimedia.org/r/c/mediawiki/extensions/DiscussionTools/+/771974/17/tests/phpunit/ThreadItemStoreTest.php#20

	public function getCliArg( $offset ) {
		// Work around MySQL bug (T256006)
		if ( $offset === 'use-normal-tables' ) {
			return true;
		}
		return parent::getCliArg( $offset );
	}

The test seems to work fine now, but let me know if this is a bad idea.

FWIW, the version of mariadb that this is fixed is 10.2 and we all are already on 10.4 and partially 10.6 so it should be okay to drop the workaround for testing mariadb (if the version of mariadb in CI is old, we should bump it anyway) but I don't know how would I feel about breaking it for everyone who is testing under mysql (and there seems to be no plan by mysql to fix this). There are way to skip a test if it's mysql (and not mariadb). Let me give this a try.

Change 928685 had a related patch set uploaded (by Ladsgroup; author: Amir Sarabadani):

[mediawiki/core@master] Tests: Only skip tests related to the temp table reopen issue in MySQL

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

Tests pass ^ CI is on MariaDB 10.3 which has the fix.

Tests pass ^ CI is on MariaDB 10.3 which has the fix.

Yay!

Tests pass ^ CI is on MariaDB 10.3 which has the fix.

And MW requires 10.3+, so we can merge it.

Change 928685 merged by jenkins-bot:

[mediawiki/core@master] Tests: Only skip tests related to the temp table reopen issue in MySQL

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

Ladsgroup claimed this task.

Change 935467 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/extensions/DiscussionTools@master] ThreadItemStoreTest: Update workaround for T256006

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

Change 935467 merged by jenkins-bot:

[mediawiki/extensions/DiscussionTools@master] ThreadItemStoreTest: Update workaround for T256006

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