Details
-
Bug
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.6, 10.11, 11.4, 11.6(EOL), 11.7(EOL)
-
None
Description
InnoDB persistent statistics behaves quite unexpectedly upon ALTER .. COPY (and differently non-copying ALTER).
Below is an original report demonstrating it via a vector key on 11.7. See comments for a generic test case without vectors, applicable to older versions
With vector key:
7fce19bd215ac0671855044520092aa4210049d1 |
MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null, vector(v)) engine=InnoDB; |
Query OK, 0 rows affected (0.110 sec) |
|
MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; |
+------------+ |
| table_name |
|
+------------+ |
| t |
|
| t#i#01 |
|
+------------+ |
2 rows in set (0.001 sec) |
|
MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; |
+------------+-----------------+--------------+ |
| table_name | index_name | stat_name |
|
+------------+-----------------+--------------+ |
| t | PRIMARY | n_diff_pfx01 | |
| t | PRIMARY | n_leaf_pages | |
| t | PRIMARY | size | |
| t#i#01 | GEN_CLUST_INDEX | n_diff_pfx01 |
|
| t#i#01 | GEN_CLUST_INDEX | n_leaf_pages |
|
| t#i#01 | GEN_CLUST_INDEX | size | |
| t#i#01 | layer | n_diff_pfx01 |
|
| t#i#01 | layer | n_diff_pfx02 |
|
| t#i#01 | layer | n_leaf_pages |
|
| t#i#01 | layer | size | |
| t#i#01 | tref | n_diff_pfx01 |
|
| t#i#01 | tref | n_leaf_pages |
|
| t#i#01 | tref | size | |
+------------+-----------------+--------------+ |
13 rows in set (0.001 sec) |
MariaDB [test]> alter table t add index (a); |
Query OK, 0 rows affected (0.140 sec) |
Records: 0 Duplicates: 0 Warnings: 0
|
|
MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; |
Empty set (0.001 sec) |
|
MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; |
Empty set (0.001 sec) |
I suppose it is expected that separate records are created for the index pseudo-table t#i#01; however, it is unclear why an innocent operation on the table (in this case an addition of another index, but also removal of any of the indexes) clears all table/index statistics.
It doesn't happen without vector key in otherwise identical circumstances; instead, statistical records for the new index are added, as would be reasonable to expect:
MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null) engine=InnoDB; |
Query OK, 0 rows affected (0.080 sec) |
|
MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; |
+------------+ |
| table_name |
|
+------------+ |
| t |
|
+------------+ |
1 row in set (0.001 sec) |
|
MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; |
+------------+------------+--------------+ |
| table_name | index_name | stat_name |
|
+------------+------------+--------------+ |
| t | PRIMARY | n_diff_pfx01 | |
| t | PRIMARY | n_leaf_pages | |
| t | PRIMARY | size | |
+------------+------------+--------------+ |
3 rows in set (0.001 sec) |
MariaDB [test]> alter table t add index (a); |
Query OK, 0 rows affected (0.043 sec) |
Records: 0 Duplicates: 0 Warnings: 0
|
|
MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; |
+------------+ |
| table_name |
|
+------------+ |
| t |
|
+------------+ |
1 row in set (0.001 sec) |
|
MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; |
+------------+------------+--------------+ |
| table_name | index_name | stat_name |
|
+------------+------------+--------------+ |
| t | PRIMARY | n_diff_pfx01 | |
| t | PRIMARY | n_leaf_pages | |
| t | PRIMARY | size | |
| t | a | n_diff_pfx01 |
|
| t | a | n_diff_pfx02 |
|
| t | a | n_leaf_pages |
|
| t | a | size | |
+------------+------------+--------------+ |
7 rows in set (0.001 sec) |
Attachments
Activity
Field | Original Value | New Value |
---|---|---|
Link |
This issue is caused by |
Description |
InnoDB persistent statistics on a table with a vector key behaves quite unexpectedly (and differently from tables without a vector key). Compare:
With vector key: {code:sql|title=7fce19bd215ac0671855044520092aa4210049d1} MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null, vector(v)) engine=InnoDB; Query OK, 0 rows affected (0.110 sec) MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | | t#i#01 | +------------+ 2 rows in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+-----------------+--------------+ | table_name | index_name | stat_name | +------------+-----------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | | t#i#01 | GEN_CLUST_INDEX | n_diff_pfx01 | | t#i#01 | GEN_CLUST_INDEX | n_leaf_pages | | t#i#01 | GEN_CLUST_INDEX | size | | t#i#01 | layer | n_diff_pfx01 | | t#i#01 | layer | n_diff_pfx02 | | t#i#01 | layer | n_leaf_pages | | t#i#01 | layer | size | | t#i#01 | tref | n_diff_pfx01 | | t#i#01 | tref | n_leaf_pages | | t#i#01 | tref | size | +------------+-----------------+--------------+ 13 rows in set (0.001 sec) {code} {code:sql} MariaDB [test]> alter table t add index (a); Query OK, 0 rows affected (0.140 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; Empty set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; Empty set (0.001 sec) {code} I suppose it is expected that separate records are created for the index pseudo-table {{t#i#01}}; however, it is unclear why an innocent operation on the table (in this case an addition of another index, but also removal of any of the indexes) clears all table/index statistics. It doesn't happen without vector key in otherwise identical circumstances; instead, upon ALTER statistical records for the new index are added, as would be reasonable to expect: {code:sql} MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null) engine=InnoDB; Query OK, 0 rows affected (0.080 sec) MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | +------------+ 1 row in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+------------+--------------+ | table_name | index_name | stat_name | +------------+------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | +------------+------------+--------------+ 3 rows in set (0.001 sec) {code} {code:sql} MariaDB [test]> alter table t add index (a); Query OK, 0 rows affected (0.043 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | +------------+ 1 row in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+------------+--------------+ | table_name | index_name | stat_name | +------------+------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | | t | a | n_diff_pfx01 | | t | a | n_diff_pfx02 | | t | a | n_leaf_pages | | t | a | size | +------------+------------+--------------+ 7 rows in set (0.001 sec) {code} |
InnoDB persistent statistics on a table with a vector key behaves quite unexpectedly (and differently from tables without a vector key). Compare:
With vector key: {code:sql|title=7fce19bd215ac0671855044520092aa4210049d1} MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null, vector(v)) engine=InnoDB; Query OK, 0 rows affected (0.110 sec) MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | | t#i#01 | +------------+ 2 rows in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+-----------------+--------------+ | table_name | index_name | stat_name | +------------+-----------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | | t#i#01 | GEN_CLUST_INDEX | n_diff_pfx01 | | t#i#01 | GEN_CLUST_INDEX | n_leaf_pages | | t#i#01 | GEN_CLUST_INDEX | size | | t#i#01 | layer | n_diff_pfx01 | | t#i#01 | layer | n_diff_pfx02 | | t#i#01 | layer | n_leaf_pages | | t#i#01 | layer | size | | t#i#01 | tref | n_diff_pfx01 | | t#i#01 | tref | n_leaf_pages | | t#i#01 | tref | size | +------------+-----------------+--------------+ 13 rows in set (0.001 sec) {code} {code:sql} MariaDB [test]> alter table t add index (a); Query OK, 0 rows affected (0.140 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; Empty set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; Empty set (0.001 sec) {code} I suppose it is expected that separate records are created for the index pseudo-table {{t#i#01}}; however, it is unclear why an innocent operation on the table (in this case an addition of another index, but also removal of any of the indexes) clears all table/index statistics. It doesn't happen without vector key in otherwise identical circumstances; instead, statistical records for the new index are added, as would be reasonable to expect: {code:sql} MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null) engine=InnoDB; Query OK, 0 rows affected (0.080 sec) MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | +------------+ 1 row in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+------------+--------------+ | table_name | index_name | stat_name | +------------+------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | +------------+------------+--------------+ 3 rows in set (0.001 sec) {code} {code:sql} MariaDB [test]> alter table t add index (a); Query OK, 0 rows affected (0.043 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | +------------+ 1 row in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+------------+--------------+ | table_name | index_name | stat_name | +------------+------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | | t | a | n_diff_pfx01 | | t | a | n_diff_pfx02 | | t | a | n_leaf_pages | | t | a | size | +------------+------------+--------------+ 7 rows in set (0.001 sec) {code} |
Component/s | Data Definition - Alter Table [ 10114 ] | |
Component/s | Vector search [ 20205 ] | |
Fix Version/s | 10.6 [ 24028 ] | |
Fix Version/s | 10.11 [ 27614 ] | |
Fix Version/s | 11.4 [ 29301 ] | |
Fix Version/s | 11.6 [ 29515 ] | |
Affects Version/s | 10.6 [ 24028 ] | |
Affects Version/s | 10.11 [ 27614 ] | |
Affects Version/s | 11.4 [ 29301 ] | |
Affects Version/s | 11.6 [ 29515 ] | |
Affects Version/s | 11.7 [ 29815 ] | |
Affects Version/s | N/A [ 14700 ] | |
Summary | Operations on table with vector key remove InnoDB table/index statistics | ALTER .. COPY removes and doesn't re-create InnoDB table/index statistics |
Assignee | Sergei Golubchik [ serg ] | Marko Mäkelä [ marko ] |
Description |
InnoDB persistent statistics on a table with a vector key behaves quite unexpectedly (and differently from tables without a vector key). Compare:
With vector key: {code:sql|title=7fce19bd215ac0671855044520092aa4210049d1} MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null, vector(v)) engine=InnoDB; Query OK, 0 rows affected (0.110 sec) MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | | t#i#01 | +------------+ 2 rows in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+-----------------+--------------+ | table_name | index_name | stat_name | +------------+-----------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | | t#i#01 | GEN_CLUST_INDEX | n_diff_pfx01 | | t#i#01 | GEN_CLUST_INDEX | n_leaf_pages | | t#i#01 | GEN_CLUST_INDEX | size | | t#i#01 | layer | n_diff_pfx01 | | t#i#01 | layer | n_diff_pfx02 | | t#i#01 | layer | n_leaf_pages | | t#i#01 | layer | size | | t#i#01 | tref | n_diff_pfx01 | | t#i#01 | tref | n_leaf_pages | | t#i#01 | tref | size | +------------+-----------------+--------------+ 13 rows in set (0.001 sec) {code} {code:sql} MariaDB [test]> alter table t add index (a); Query OK, 0 rows affected (0.140 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; Empty set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; Empty set (0.001 sec) {code} I suppose it is expected that separate records are created for the index pseudo-table {{t#i#01}}; however, it is unclear why an innocent operation on the table (in this case an addition of another index, but also removal of any of the indexes) clears all table/index statistics. It doesn't happen without vector key in otherwise identical circumstances; instead, statistical records for the new index are added, as would be reasonable to expect: {code:sql} MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null) engine=InnoDB; Query OK, 0 rows affected (0.080 sec) MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | +------------+ 1 row in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+------------+--------------+ | table_name | index_name | stat_name | +------------+------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | +------------+------------+--------------+ 3 rows in set (0.001 sec) {code} {code:sql} MariaDB [test]> alter table t add index (a); Query OK, 0 rows affected (0.043 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | +------------+ 1 row in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+------------+--------------+ | table_name | index_name | stat_name | +------------+------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | | t | a | n_diff_pfx01 | | t | a | n_diff_pfx02 | | t | a | n_leaf_pages | | t | a | size | +------------+------------+--------------+ 7 rows in set (0.001 sec) {code} |
InnoDB persistent statistics behaves quite unexpectedly upon ALTER .. COPY (and differently non-copying ALTER). Compare:
With vector key: {code:sql|title=7fce19bd215ac0671855044520092aa4210049d1} MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null, vector(v)) engine=InnoDB; Query OK, 0 rows affected (0.110 sec) MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | | t#i#01 | +------------+ 2 rows in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+-----------------+--------------+ | table_name | index_name | stat_name | +------------+-----------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | | t#i#01 | GEN_CLUST_INDEX | n_diff_pfx01 | | t#i#01 | GEN_CLUST_INDEX | n_leaf_pages | | t#i#01 | GEN_CLUST_INDEX | size | | t#i#01 | layer | n_diff_pfx01 | | t#i#01 | layer | n_diff_pfx02 | | t#i#01 | layer | n_leaf_pages | | t#i#01 | layer | size | | t#i#01 | tref | n_diff_pfx01 | | t#i#01 | tref | n_leaf_pages | | t#i#01 | tref | size | +------------+-----------------+--------------+ 13 rows in set (0.001 sec) {code} {code:sql} MariaDB [test]> alter table t add index (a); Query OK, 0 rows affected (0.140 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; Empty set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; Empty set (0.001 sec) {code} I suppose it is expected that separate records are created for the index pseudo-table {{t#i#01}}; however, it is unclear why an innocent operation on the table (in this case an addition of another index, but also removal of any of the indexes) clears all table/index statistics. It doesn't happen without vector key in otherwise identical circumstances; instead, statistical records for the new index are added, as would be reasonable to expect: {code:sql} MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null) engine=InnoDB; Query OK, 0 rows affected (0.080 sec) MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | +------------+ 1 row in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+------------+--------------+ | table_name | index_name | stat_name | +------------+------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | +------------+------------+--------------+ 3 rows in set (0.001 sec) {code} {code:sql} MariaDB [test]> alter table t add index (a); Query OK, 0 rows affected (0.043 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | +------------+ 1 row in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+------------+--------------+ | table_name | index_name | stat_name | +------------+------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | | t | a | n_diff_pfx01 | | t | a | n_diff_pfx02 | | t | a | n_leaf_pages | | t | a | size | +------------+------------+--------------+ 7 rows in set (0.001 sec) {code} |
Description |
InnoDB persistent statistics behaves quite unexpectedly upon ALTER .. COPY (and differently non-copying ALTER). Compare:
With vector key: {code:sql|title=7fce19bd215ac0671855044520092aa4210049d1} MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null, vector(v)) engine=InnoDB; Query OK, 0 rows affected (0.110 sec) MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | | t#i#01 | +------------+ 2 rows in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+-----------------+--------------+ | table_name | index_name | stat_name | +------------+-----------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | | t#i#01 | GEN_CLUST_INDEX | n_diff_pfx01 | | t#i#01 | GEN_CLUST_INDEX | n_leaf_pages | | t#i#01 | GEN_CLUST_INDEX | size | | t#i#01 | layer | n_diff_pfx01 | | t#i#01 | layer | n_diff_pfx02 | | t#i#01 | layer | n_leaf_pages | | t#i#01 | layer | size | | t#i#01 | tref | n_diff_pfx01 | | t#i#01 | tref | n_leaf_pages | | t#i#01 | tref | size | +------------+-----------------+--------------+ 13 rows in set (0.001 sec) {code} {code:sql} MariaDB [test]> alter table t add index (a); Query OK, 0 rows affected (0.140 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; Empty set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; Empty set (0.001 sec) {code} I suppose it is expected that separate records are created for the index pseudo-table {{t#i#01}}; however, it is unclear why an innocent operation on the table (in this case an addition of another index, but also removal of any of the indexes) clears all table/index statistics. It doesn't happen without vector key in otherwise identical circumstances; instead, statistical records for the new index are added, as would be reasonable to expect: {code:sql} MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null) engine=InnoDB; Query OK, 0 rows affected (0.080 sec) MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | +------------+ 1 row in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+------------+--------------+ | table_name | index_name | stat_name | +------------+------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | +------------+------------+--------------+ 3 rows in set (0.001 sec) {code} {code:sql} MariaDB [test]> alter table t add index (a); Query OK, 0 rows affected (0.043 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | +------------+ 1 row in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+------------+--------------+ | table_name | index_name | stat_name | +------------+------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | | t | a | n_diff_pfx01 | | t | a | n_diff_pfx02 | | t | a | n_leaf_pages | | t | a | size | +------------+------------+--------------+ 7 rows in set (0.001 sec) {code} |
InnoDB persistent statistics behaves quite unexpectedly upon ALTER .. COPY (and differently non-copying ALTER).
Below is an original test case demonstrating it via a vector key on 11.7. See comments for a generic test case without vectors, applicable to older versions With vector key: {code:sql|title=7fce19bd215ac0671855044520092aa4210049d1} MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null, vector(v)) engine=InnoDB; Query OK, 0 rows affected (0.110 sec) MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | | t#i#01 | +------------+ 2 rows in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+-----------------+--------------+ | table_name | index_name | stat_name | +------------+-----------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | | t#i#01 | GEN_CLUST_INDEX | n_diff_pfx01 | | t#i#01 | GEN_CLUST_INDEX | n_leaf_pages | | t#i#01 | GEN_CLUST_INDEX | size | | t#i#01 | layer | n_diff_pfx01 | | t#i#01 | layer | n_diff_pfx02 | | t#i#01 | layer | n_leaf_pages | | t#i#01 | layer | size | | t#i#01 | tref | n_diff_pfx01 | | t#i#01 | tref | n_leaf_pages | | t#i#01 | tref | size | +------------+-----------------+--------------+ 13 rows in set (0.001 sec) {code} {code:sql} MariaDB [test]> alter table t add index (a); Query OK, 0 rows affected (0.140 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; Empty set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; Empty set (0.001 sec) {code} I suppose it is expected that separate records are created for the index pseudo-table {{t#i#01}}; however, it is unclear why an innocent operation on the table (in this case an addition of another index, but also removal of any of the indexes) clears all table/index statistics. It doesn't happen without vector key in otherwise identical circumstances; instead, statistical records for the new index are added, as would be reasonable to expect: {code:sql} MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null) engine=InnoDB; Query OK, 0 rows affected (0.080 sec) MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | +------------+ 1 row in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+------------+--------------+ | table_name | index_name | stat_name | +------------+------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | +------------+------------+--------------+ 3 rows in set (0.001 sec) {code} {code:sql} MariaDB [test]> alter table t add index (a); Query OK, 0 rows affected (0.043 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | +------------+ 1 row in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+------------+--------------+ | table_name | index_name | stat_name | +------------+------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | | t | a | n_diff_pfx01 | | t | a | n_diff_pfx02 | | t | a | n_leaf_pages | | t | a | size | +------------+------------+--------------+ 7 rows in set (0.001 sec) {code} |
Description |
InnoDB persistent statistics behaves quite unexpectedly upon ALTER .. COPY (and differently non-copying ALTER).
Below is an original test case demonstrating it via a vector key on 11.7. See comments for a generic test case without vectors, applicable to older versions With vector key: {code:sql|title=7fce19bd215ac0671855044520092aa4210049d1} MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null, vector(v)) engine=InnoDB; Query OK, 0 rows affected (0.110 sec) MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | | t#i#01 | +------------+ 2 rows in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+-----------------+--------------+ | table_name | index_name | stat_name | +------------+-----------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | | t#i#01 | GEN_CLUST_INDEX | n_diff_pfx01 | | t#i#01 | GEN_CLUST_INDEX | n_leaf_pages | | t#i#01 | GEN_CLUST_INDEX | size | | t#i#01 | layer | n_diff_pfx01 | | t#i#01 | layer | n_diff_pfx02 | | t#i#01 | layer | n_leaf_pages | | t#i#01 | layer | size | | t#i#01 | tref | n_diff_pfx01 | | t#i#01 | tref | n_leaf_pages | | t#i#01 | tref | size | +------------+-----------------+--------------+ 13 rows in set (0.001 sec) {code} {code:sql} MariaDB [test]> alter table t add index (a); Query OK, 0 rows affected (0.140 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; Empty set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; Empty set (0.001 sec) {code} I suppose it is expected that separate records are created for the index pseudo-table {{t#i#01}}; however, it is unclear why an innocent operation on the table (in this case an addition of another index, but also removal of any of the indexes) clears all table/index statistics. It doesn't happen without vector key in otherwise identical circumstances; instead, statistical records for the new index are added, as would be reasonable to expect: {code:sql} MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null) engine=InnoDB; Query OK, 0 rows affected (0.080 sec) MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | +------------+ 1 row in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+------------+--------------+ | table_name | index_name | stat_name | +------------+------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | +------------+------------+--------------+ 3 rows in set (0.001 sec) {code} {code:sql} MariaDB [test]> alter table t add index (a); Query OK, 0 rows affected (0.043 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | +------------+ 1 row in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+------------+--------------+ | table_name | index_name | stat_name | +------------+------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | | t | a | n_diff_pfx01 | | t | a | n_diff_pfx02 | | t | a | n_leaf_pages | | t | a | size | +------------+------------+--------------+ 7 rows in set (0.001 sec) {code} |
InnoDB persistent statistics behaves quite unexpectedly upon ALTER .. COPY (and differently non-copying ALTER).
Below is an original report demonstrating it via a vector key on 11.7. See comments for a generic test case without vectors, applicable to older versions With vector key: {code:sql|title=7fce19bd215ac0671855044520092aa4210049d1} MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null, vector(v)) engine=InnoDB; Query OK, 0 rows affected (0.110 sec) MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | | t#i#01 | +------------+ 2 rows in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+-----------------+--------------+ | table_name | index_name | stat_name | +------------+-----------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | | t#i#01 | GEN_CLUST_INDEX | n_diff_pfx01 | | t#i#01 | GEN_CLUST_INDEX | n_leaf_pages | | t#i#01 | GEN_CLUST_INDEX | size | | t#i#01 | layer | n_diff_pfx01 | | t#i#01 | layer | n_diff_pfx02 | | t#i#01 | layer | n_leaf_pages | | t#i#01 | layer | size | | t#i#01 | tref | n_diff_pfx01 | | t#i#01 | tref | n_leaf_pages | | t#i#01 | tref | size | +------------+-----------------+--------------+ 13 rows in set (0.001 sec) {code} {code:sql} MariaDB [test]> alter table t add index (a); Query OK, 0 rows affected (0.140 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; Empty set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; Empty set (0.001 sec) {code} I suppose it is expected that separate records are created for the index pseudo-table {{t#i#01}}; however, it is unclear why an innocent operation on the table (in this case an addition of another index, but also removal of any of the indexes) clears all table/index statistics. It doesn't happen without vector key in otherwise identical circumstances; instead, statistical records for the new index are added, as would be reasonable to expect: {code:sql} MariaDB [test]> create or replace table t (pk int primary key, a int, v vector(1) not null) engine=InnoDB; Query OK, 0 rows affected (0.080 sec) MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | +------------+ 1 row in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+------------+--------------+ | table_name | index_name | stat_name | +------------+------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | +------------+------------+--------------+ 3 rows in set (0.001 sec) {code} {code:sql} MariaDB [test]> alter table t add index (a); Query OK, 0 rows affected (0.043 sec) Records: 0 Duplicates: 0 Warnings: 0 MariaDB [test]> select table_name from mysql.innodb_table_stats where database_name = 'test'; +------------+ | table_name | +------------+ | t | +------------+ 1 row in set (0.001 sec) MariaDB [test]> select table_name, index_name, stat_name from mysql.innodb_index_stats where database_name = 'test'; +------------+------------+--------------+ | table_name | index_name | stat_name | +------------+------------+--------------+ | t | PRIMARY | n_diff_pfx01 | | t | PRIMARY | n_leaf_pages | | t | PRIMARY | size | | t | a | n_diff_pfx01 | | t | a | n_diff_pfx02 | | t | a | n_leaf_pages | | t | a | size | +------------+------------+--------------+ 7 rows in set (0.001 sec) {code} |
Link |
This issue is caused by |
Fix Version/s | 11.6(EOL) [ 29515 ] |
Fix Version/s | 11.7(EOL) [ 29815 ] |
It doesn't seem to be related to vector, alter table ... algorithm=copy loses stats as well.