简体   繁体   中英

How does `desc <table>` command works internally inside innodb?

Does it scans the entire information_schema? Or it simply shows data from some header in table file?

Documentations on mysql ( https://dev.mysql.com/doc/refman/8.0/en/show-columns.html ) and mariadb ( https://mariadb.com/kb/en/show-columns/ ) give information about outputs, but do not reveal how the data is fetched internally.

Requirement of this answer branches by the curiosity to understand following

  1. Effect of increasing number of tables on performance to database, due to impact on information schema.
  2. Whether table metadata is used instead of information schema for describe.
  3. Is information schema stored in a different tablespace, or is it rendered via table metadata.

I think MySQL 8.0 has all that info in the "Data Dictionary", which is the big change for 8.0. It is in InnoDB table(s), so it should be fast.

Before 8.0, the .frm was the main source for the information, but I think there was other information buried in unindexed pseudo tables in RAM and/or ibdata1. The more tables you had, the slower things were.

If you go past, say, 1K tables in your system, you may have a poor schema design.

In a survey of a lot of servers, running DESCRIBE or SHOW CREATE TABLE is, on most machines, done less than once an hour. If you are doing such queries more than once a second, I would again question the architecture.

Note: MariaDB has not implemented the Data Dictionary.

DESCRIBE does not incur the performance cost of querying INFORMATION_SCHEMA.

Years ago, I implemented code in Zend Framework 1.0 to discover columns for a table. First implementation for Beta was to use INFORMATION_SCHEMA. But users complained that it ruined their performance.

So I changed it to query DESCRIBE, which has less detailed information, but it had enough for the purpose I had. This was much better for performance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM