A common practice among DBAs and developers is to copy table data and .frm files from the data dictionary. They often set up batch jobs to automate the recovery of these tables. This capability is also utilized in disaster recovery scenarios, where individuals well-versed in .frm files can reconstruct their metadata as needed.

In MySQL 8.0, the information is presented within serialized objects within the dictionary. In the case of InnoDB tablespaces, this information is incorporated into the tablespace itself, creating a fusion of metadata and data primarily to enhance performance. MySQL writes a .sdi file to accommodate the serialized dictionary information for storage engines that lack support for this functionality.

Purpose of .sdi files

Serialized dictionary information (SDI) files store serialized metadata about various database objects, such as tables, indexes, and other schema-related details. This serialized data is typically stored in a compact JSON format.

Storage engine compatibility

Different MySQL storage engines handle .sdi files in various ways.

InnoDB

One of the most widely used storage engines stores .sdi data within its tablespace files. This helps improve the performance of metadata retrieval and management for InnoDB tables.

The existence of SDI data offers redundancy in terms of metadata. For instance, in cases where the data dictionary becomes inaccessible, object metadata can be directly extracted from InnoDB tablespace files using the ibd2sdi tool.

The utility ibd2sdi is compatible with file-per-table tablespace files (.ibd files), general tablespace files (.ibd files), system tablespace files (ibdata* files), and the data dictionary tablespace (mysql.ibd). However, it is not intended for use with temporary or undo tablespaces.

Let’s test it with InnoDB using the ibd2sdi tool. 

Other storage engines

Some other storage engines in MySQL may store .sdi data in separate .sdi files created in the database directory for a specific table. The exact handling can vary depending on the storage engine.

I’ve generated a MyISAM table to illustrate what .sdi files appear like.

We can see that it has.sdi file generated

RocksDb also supports SDI.

Updating .sdi files

.sdi files are typically updated when certain database operations are performed, such as Data Definition Language (DDL) operations on tables or using the “CHECK TABLE FOR UPGRADE” command. These operations can trigger changes to the metadata, and .sdi files are updated to reflect these changes.

SDI data does not receive updates while upgrading the MySQL server to a new release or version.

Whenever you change a table using an engine that requires an SDI file, a new file is created with a distinct OID (Object ID) number, effectively replacing any previous file.

Note: In the case of the InnoDB storage engine, SDI is updated and stored inside the IBD files when certain database operations are performed, such as Data Definition Language (DDL).

Parsed the .sdi using JSON parser (jq parser) 

sdi2ddl – Convert SDI JSON to SHOW CREATE TABLE statement

One of my coworkers has created a tool called sdi2ddl, which enables the conversion of MySQL SDI into a SHOW CREATE TABLE statement. MySQL 8 introduced a shift away from conventional .frm files, opting instead for a transactional data dictionary stored within the mysql.ibd file. There are instances when retrieving the Data Definition Language (DDL) from a .ibd file becomes essential, as this capability facilitates the potential recovery of a table through DISCARD/IMPORT TABLESPACE procedures.

Caution: The sdi2ddl tool/script is not for production and should be handled carefully at your risk.

Another blog post explains how Percona XtraBackup depends on SDI to perform rollback and undo operations during the preparation phase: 20X Faster Backup Preparation With Percona XtraBackup 8.0.33-28.

Percona Distribution for MySQL is the most complete, stable, scalable, and secure open source MySQL solution available, delivering enterprise-grade database environments for your most critical business applications… and it’s free to use!

 

Try Percona Distribution for MySQL today!

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments