一、MySQL的dd表介绍
二、代码跟踪
三、知识应用
四、总结
一、MySQL的dd表介绍
MySQL的dd表是用来存放表结构和各种建表信息的,客户端建的表都存在mysql.table和mysql.columns表里,还有一个表mysql.column_type_elements比较特殊,用来存放SET和ENUM类型的字段集合值信息。看一下下面这张表的mysql.columns表和mysql.column_type_elements信息。为了缩短显示长度,这里只展示几个重要的值。
#建表:
CREATE TABLE t1(id int not null auto_increment primary key,col1 number,col2 VARCHAR(100),col3 pls_integer,
col4 enum('x','y') default 'x',col5 set('x1','y1')) partition by hash(id) partitions 3;
SET SESSION debug='+d,skip_dd_table_access_check';
mysql> select name,ordinal_position,type,default_value_utf8,options,column_type_utf8 from mysql.columns where table_id=383;
+-------------+------------------+-----------------------+--------------------+-------------------+------------------+
| name | ordinal_position | type | default_value_utf8 | options | column_type_utf8 |
+-------------+------------------+-----------------------+--------------------+-------------------+------------------+
| col1 | 2 | MYSQL_TYPE_NEWDECIMAL | NULL | interval_count=0; | decimal(65,0) |
| col2 | 3 | MYSQL_TYPE_VARCHAR | NULL | interval_count=0; | varchar(100) |
| col3 | 4 | MYSQL_TYPE_LONG | NULL | interval_count=0; | int |
| col4 | 5 | MYSQL_TYPE_ENUM | x | interval_count=2; | enum('x','y') |
| col5 | 6 | MYSQL_TYPE_SET | NULL | interval_count=2; | set('x1','y1') |
| DB_ROLL_PTR | 8 | MYSQL_TYPE_LONGLONG | NULL | NULL | |
| DB_TRX_ID | 7 | MYSQL_TYPE_INT24 | NULL | NULL | |
| id | 1 | MYSQL_TYPE_LONG | NULL | interval_count=0; | int |
+-------------+------------------+-----------------------+--------------------+-------------------+------------------+
8 rows in set (0.00 sec)
mysql.columns表说明如下:
ordinal_position 是该字段在表里的偏移量,这里多了3个字段, DB_ROLL_PTR 、 DB_TRX_ID 、