mysql information_schema查询大小写

mysql> select table_schema,table_name from information_schema.tables where table_name = 'test1' ;
+-----------------+------------+
| table_schema    | table_name |
+-----------------+------------+
| workoperations1 | test1      |
| workoperations2 | test1      |
| workoperations3 | test1      |
| workoperations4 | test1      |
+-----------------+------------+
4 rows in set

mysql> select table_schema,table_name from information_schema.tables where table_name = 'TEST1' ;
Empty set


若改为

select * from information_schema.tables where table_name = 'test1' ;
select * from information_schema.tables where table_name = 'TEST1' ;

都能查出4条记录。

 

原因在于

mysql> explain select table_schema,table_name from information_schema.tables where table_name = 'TEST1' ;
+----+-------------+--------+------+---------------+------------+---------+------+------+--------------------------------------------------+
| id | select_type | table  | type | possible_keys | key        | key_len | ref  | rows | Extra                                            |
+----+-------------+--------+------+---------------+------------+---------+------+------+--------------------------------------------------+
|  1 | SIMPLE      | tables | ALL  | NULL          | TABLE_NAME | NULL    | NULL | NULL | Using where; Skip_open_table; Scanned 1 database |
+----+-------------+--------+------+---------------+------------+---------+------+------+--------------------------------------------------+
1 row in set

mysql> explain select * from information_schema.tables where table_name = 'TEST1' ;
+----+-------------+--------+------+---------------+------------+---------+------+------+--------------------------------------------------+
| id | select_type | table  | type | possible_keys | key        | key_len | ref  | rows | Extra                                            |
+----+-------------+--------+------+---------------+------------+---------+------+------+--------------------------------------------------+
|  1 | SIMPLE      | tables | ALL  | NULL          | TABLE_NAME | NULL    | NULL | NULL | Using where; Open_full_table; Scanned 1 database |
+----+-------------+--------+------+---------------+------------+---------+------+------+--------------------------------------------------+
1 row in set

两条语句的执行计划不同。
要避免出现大小写导致查不到数据字典的情况还是用*代替table_name。

http://dev.mysql.com/doc/refman/5.1/en/information-schema-optimization.html

TABLE_CATALOGSKIP_OPEN_TABLE
TABLE_SCHEMASKIP_OPEN_TABLE
TABLE_NAMESKIP_OPEN_TABLE
TABLE_TYPEOPEN_FRM_ONLY
ENGINEOPEN_FRM_ONLY
VERSIONOPEN_FRM_ONLY
ROW_FORMATOPEN_FULL_TABLE
TABLE_ROWSOPEN_FULL_TABLE
AVG_ROW_LENGTHOPEN_FULL_TABLE
DATA_LENGTHOPEN_FULL_TABLE
MAX_DATA_LENGTHOPEN_FULL_TABLE
INDEX_LENGTHOPEN_FULL_TABLE
DATA_FREEOPEN_FULL_TABLE
AUTO_INCREMENTOPEN_FULL_TABLE
CREATE_TIMEOPEN_FULL_TABLE
UPDATE_TIMEOPEN_FULL_TABLE
CHECK_TIMEOPEN_FULL_TABLE
TABLE_COLLATIONOPEN_FRM_ONLY
CHECKSUMOPEN_FULL_TABLE
CREATE_OPTIONSOPEN_FRM_ONLY
TABLE_COMMENTOPEN_FRM_ONLY


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值