Such tasks leave behind gaps among the information that remains in the table and that is the true cause of table fragmentation. Moreover, the database doesn’t immediately replace these spaces that non-insert DML commands liberate.
In this blog, we will discuss how the database management system
handles this space for the tables.
MySQL SQL Performance Tuning: Managing Table Fragmentation
In some cases, row storage isn’t contiguous or the rows are divided across multiple blocks. Both of these negatively impact the database, so you will need MySQL SQL performance tuning to reduce the requirement of additional block accesses.
Keep in mind that table fragmentation and file fragmentation are two distinct occurrences. Table fragmentation involves the application of many Data Manipulation Language commands. This is because the resulting free space does not get released by the DML from the table, except if it is under the High-Water Mark (HWM).
High Water Mark is a measure of that DBMSs occupied blocks. Those
that lie under the HWM may or may not have data at the moment but they have
held it at least once. The database is aware that blocks over this indicator
have never contained data. It is why it only reads those that reach up to the
HWM during a complete table scan. This value can be reset by a DDL query.
Why Table Reorganization Can Help MySQL Database and SQL
This particular task helps deal with three major problems with MySQL Database and SQL:
●
Too many
chained or migrated rows
●
Sluggish
table response time
●
Wasted old
space due to non-uniform table growth
There are certain ways to locate a majority of fragmented tables. Look for tables that have a sizable difference in their expected and actual sizes. Such differences usually occur thanks to table fragmentation or old stats that haven’t gone through updates.
If you want to determine and eliminate table fragmentation, you may follow the steps explained briefly below:
- Bring together important table stats,
such as the actual size and stats size. These will help you calculate the
exact difference between the two and help you identify the presence of
fragmentation. You will require updated stats in dba_tables for this
purpose. To verify whether the stats are new, you can go through the
last_analyzed value or try collecting table stats.
- Find out the current table size- if it
is smaller than its older size, you can tell it has undergone table
fragmentation.
- Other signs you can look for in the
table include the overall size of the table (with fragmentation), what
size you may expect in the absence of fragmentation, and the percentage
size the DBA may regain once fragmentation is removed. You will require
the table and schema names for this.
Final Thoughts
You can still gain performance-related advantages from a large number of fragmented tables with the help of the steps mentioned above.
These will enable you to collect all the necessary statistics that will inform the optimizer on how to build the most favorable execution plan. The plan will ensure MySQL SQL performance tuning for better results during statement execution.