3

First up: I'm not looking for a way to fix the dreaded tablespace exists InnoDB error found here, rather I'm looking for a way to prevent it! Over the past few weeks we've had a table dissapear from our database at random, with no way to re-create it (because it gives a tablespace exists error). We've narrowed it down to the following table:

CREATE TABLE product_localised (
  id INT (10) UNSIGNED NOT NULL AUTO_INCREMENT,
  product_id INT (10) UNSIGNED NOT NULL,
  language_id INT (10) UNSIGNED NOT NULL,
  slug VARCHAR (255) COLLATE utf8_unicode_ci NOT NULL,
  title TEXT COLLATE utf8_unicode_ci,
  description TEXT COLLATE utf8_unicode_ci,
  description_short TEXT COLLATE utf8_unicode_ci,
  custom_startselect_content TEXT COLLATE utf8_unicode_ci,
  created_at TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
  updated_at TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
  deleted_at TIMESTAMP NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY product_localised_product_id_language_id_unique (`product_id`, `language_id`),
  KEY product_localised_language_id_foreign (`language_id`),
  CONSTRAINT product_localised_language_id_foreign FOREIGN KEY (`language_id`) REFERENCES languages (`id`),
  CONSTRAINT product_localised_product_id_foreign FOREIGN KEY (`product_id`) REFERENCES products (`id`)
) ENGINE = INNODB AUTO_INCREMENT = 46727 DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci;

The question: can someone look at the table's structure and keys and tell if there's anything wrong with it?!

We're hosting our database on Amazon's RDS and tried MySQL 5.5 and 5.6, with innodb_file_per_table enabled.

We also tried MySQL 5.5 on Ubuntu Server 14.04 LTS (using Vagrant) and MySQL 5.6 on Windows using xampp.

In response to questions asked below:

Consider removing id and using (product_id, language_id) as the PK. And surely you don't need 2 billion languages, so consider shrinking language_id to SMALLINT UNSIGNED:

  1. We prefer single column primary keys as it makes using our ORM a lot easier
  2. We don't have a million languages, but it's simply our auto increment setup we use throughout our project, surely this shouldn't cause any problems?
Community
  • 1
  • 1
Kevin Op den Kamp
  • 565
  • 1
  • 8
  • 22
  • Where is the `TABLESPACE` clause? What version of MySQL are you running? – Rick James Mar 20 '16 at 17:25
  • Consider removing `id` and using `(product_id, language_id)` as the PK. And surely you don't need 2 billion languages, so consider shrinking `language_id` to `SMALLINT UNSIGNED`. – Rick James Mar 20 '16 at 17:27
  • Are you using `innodb_file_per_table`? `Barracuda`? – Rick James Mar 20 '16 at 17:27
  • Absolutely right guys, I was convinced it had something with the table structure. Just updated my question with versions and configurations – Kevin Op den Kamp Mar 21 '16 at 07:55
  • Please show us the full text of the error, together with the statements that elicited it. (If it is that `CREATE`, then say so.) Was the statement manually entered, or did it come in as a reload, or as an `IMPORT`? – Rick James Mar 27 '16 at 05:20
  • When trying to query the table we get a "TABLE 'product_localised' doesn't exist" error, when trying to import it or re-create it we get this error: "Tablespace for table 'roduct_localised' exists. Please DISCARD the tablespace before IMPORT." – Kevin Op den Kamp Mar 29 '16 at 07:15

2 Answers2

0

According to this

Error: Tablespace for table xxx exists. Please DISCARD the tablespace before IMPORT

There can be multiple reasons for this.

1) Either your query is timing out
2) Either someone has removed foreign key check by running set foreign_key_checks=0

Community
  • 1
  • 1
Naruto
  • 4,221
  • 1
  • 21
  • 32
  • 1) Highly unlikely seeing as none of our queries take longer than a second 2) The only time we disable foreign key checks is when we run our migration script (we use Laravel 5's migrations), which disabled foreign key checks, does some database operations, and turns it back on. – Kevin Op den Kamp Mar 29 '16 at 07:16
0

See if any of these apply:

----- 2015-08-03 5.7.8 -- Bugs Fixed -- -----

A failing ALTER TABLE ( http://dev.mysql.com/doc/refman/5.7/en/alter-table.html ) tablespace operation (DISCARD TABLESPACE or IMPORT TABLESPACE could produce an incorrect internal tablespace state, causing a succeeding statement to fail. (Bug #76424, Bug #20748660)

----- 2015-03-09 5.7.6 Milestone 16 -- Bugs Fixed -- InnoDB -----

The fil_space_t::tablespace_version field, introduced to keep track of ALTER TABLE...DISCARD TABLESPACE ( http://dev.mysql.com/doc/refman/5.7/en/alter-table.html ) followed by ALTER TABLE IMPORT TABLESPACE ( http://dev.mysql.com/doc/refman/5.7/en/alter-table.html ) operations, was removed. The tablespace_version field ensured that a change buffer merge would not occur for old buffered entries while a tablespace with the same space_id was imported. The field was redundant and no longer required. (Bug #19710564)

----- 2014-03-31 5.7.4 Milestone 14 & 2014-01-31 5.6.16 -- Bugs Fixed -- InnoDB -----

Manipulating a table after discarding its tablespace using ALTER TABLE ... DISCARD TABLESPACE ( http://dev.mysql.com/doc/refman/5.7/en/alter-table.html ) could result in a serious error. (Bug #17700280)

----- 2012-12-11 5.6.9 -- Bugs Fixed -- InnoDB -----

A timeout error could occur on Windows systems when doing ALTER TABLE ( http://dev.mysql.com/doc/refman/5.6/en/alter-table.html ) statements with the DISCARD TABLESPACE or IMPORT TABLESPACE clauses, due to a temporary tablespace file remaining in the file system. (Bug #14776799)

----- 2012-12-11 5.6.9 -- Bugs Fixed -- -----

After issuing ALTER TABLE ... DISCARD TABLESPACE, an online DDL operation for the same table could fail on Windows systems with an error: Got error 11 from storage engine. An ALTER TABLE ( http://dev.mysql.com/doc/refman/5.6/en/alter-table.html ) statement with the ALGORITHM=INPLACE clause could also create an empty .ibd file ( http://dev.mysql.com/doc/refman/5.6/en/glossary.html#glos_ibd_file ), making the tablespace no longer “discarded”. (Bug #14735917)

http://forums.mysql.com/read.php?22,633145 (table does not exist)
http://forums.mysql.com/read.php?20,615512 (MySQL/innodb database malfunctioning)
http://forums.mysql.com/read.php?22,603093 (Database keeps crashing - Assertion Failure?)
http://forums.mysql.com/read.php?22,601100 (Help needed with DISCARD TABLESPACE)
http://forums.mysql.com/read.php?10,591035 (what should do after some tables' .ibd file were deleted ?)
http://forums.mysql.com/read.php?22,444342 (database crash and procesor overload)
http://forums.mysql.com/read.php?22,355932 (InnoDB can't find "the path" specified)
http://forums.mysql.com/read.php?22,290138 (After deleting database, tables "already exist")
http://forums.mysql.com/read.php?22,270607 (*.frm files and reducing ibdata file)

Rick James
  • 135,179
  • 13
  • 127
  • 222