There is a table dept
and it has 100 rows, all nicely tucked in 1 block, as seen in the mysql.innodb_index_stats
table.
table_name | index_name | stat_name | stat_value | sample_size | stat_description |
---|---|---|---|---|---|
dept | PRIMARY | size | 1 | NULL | Number of pages in the index |
After running the following query...
select * from dept;
..and looking at its optimizer trace, I see that in the row estimation phase, it says cost = 1 (reading 1 block), but in the planning phase, it says 21. I do not know why and what is the calculation there.
The same happens for all tables. Another Example:
There is a table student
and it has 100000 rows, tucked in 609 blocks, as seen in the mysql.innodb_index_stats
table.
table_name | index_name | stat_name | stat_value | sample_size | stat_description |
---|---|---|---|---|---|
student | PRIMARY | size | 609 | NULL | Number of pages in the index |
After running the following query...
select * from student;
..and looking at its optimizer trace, I see that in the row estimation phase, it says cost = 609 (reading 609 blocks), but in the planning phase, it says 20504.