MySQL NDB cluster fails to add key

54 Views Asked by At

Here is a simple demo of creating two tables and trying to add a key on a MySQL NDB cluster database. Pretty basic:

CREATE TABLE `child` (
  `id` int NOT NULL,
  `id_parent` int NOT NULL
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

CREATE TABLE `parent` (
  `id` int NOT NULL
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;


ALTER TABLE `child`
  ADD PRIMARY KEY (`id`),
  ADD KEY `id_parent` (`id_parent`);

But MySQL gives me:

ERROR 1005 (HY000): Can't create destination table for copying alter table (use SHOW WARNINGS for more info).

SHOW WARNINGS shows:

+---------+------+-------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                   |
+---------+------+-------------------------------------------------------------------------------------------+
| Warning | 1296 | The temporary named table #sql-398_3d9.test2 already exists, it will be removed           |
| Warning | 1296 | Got error 917 'Invalid index stats sys tables data' from NDB                              |
| Warning | 1296 | Failed to commit NDB schema transaction                                                   |
| Error   | 1005 | Can't create destination table for copying alter table (use SHOW WARNINGS for more info). |
+---------+------+-------------------------------------------------------------------------------------------+

So it looks like "Invalid index stats sys tables data" is something bad. What does it mean?

1

There are 1 best solutions below

0
Hokascha On

To recreate the index stats sys tables use this:

ndb_index_stat --sys-create-if-not-valid

after that, keys could be added successfully.