Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty tables in different TABLESPACE might have large data_free on creation #19

Closed
xsist10 opened this issue Sep 5, 2021 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@xsist10
Copy link
Owner

xsist10 commented Sep 5, 2021

When a table is created normally like this:

CREATE TABLE `user` (
  `id` int NOT NULL AUTO_INCREMENT,
  `name` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB

it will have an information_schema.TABLES entry with data_free that equals 0.

> select TABLE_NAME, DATA_FREE from information_schema.TABLES WHERE TABLE_SCHEMA="test" AND TABLE_NAME LIKE "user";
+------------+-----------+
| TABLE_NAME | DATA_FREE |
+------------+-----------+
| user       |         0 |
+------------+-----------+

However if you create it in a tablespace:

CREATE TABLE `user` (
  `id` int NOT NULL AUTO_INCREMENT,
  `name` int NOT NULL,
  PRIMARY KEY (`id`)
) /*!50100 TABLESPACE `innodb_system` */ ENGINE=InnoDB

it might have a completely different data_free value which currently will confuse Cadfael into reporting that it is an empty file but has had records previously:

> select TABLE_NAME, DATA_FREE from information_schema.TABLES WHERE TABLE_SCHEMA="test" AND TABLE_NAME LIKE "user";
+------------+-----------+
| TABLE_NAME | DATA_FREE |
+------------+-----------+
| user       |   5242880 |
+------------+-----------+

This data_free value is determined by:

> SELECT TABLESPACE_NAME, DATA_FREE FROM INFORMATION_SCHEMA.FILES WHERE TABLESPACE_NAME LIKE 'innodb_system';
+-----------------+-----------+
| TABLESPACE_NAME | DATA_FREE |
+-----------------+-----------+
| innodb_system   |   5242880 |
+-----------------+-----------+
@xsist10 xsist10 added the bug Something isn't working label Sep 5, 2021
@xsist10
Copy link
Owner Author

xsist10 commented Sep 5, 2021

Can't seem to find how to query which tablespace a table is in without resorting to parsing the SHOW CREATE TABLE result statement.

@xsist10
Copy link
Owner Author

xsist10 commented Sep 17, 2021

Thanks to Isotopp for pointing this out:

MySQL 8.0

SELECT * FROM information_schema.innodb_tables AS ita
JOIN information_schema.innodb_tablespaces AS its ON (ita.space = its.space)
WHERE ita.name = "mysql/component";

MySQL 5.6/5.7

SELECT * FROM information_schema.innodb_sys_tables AS ita
JOIN information_schema.innodb_sys_tablespaces AS its ON (ita.space = its.space)
WHERE ita.name = "mysql/component";

This was referenced Sep 25, 2021
@xsist10 xsist10 closed this as completed Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant