自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

MySQL關(guān)于數(shù)據(jù)字典的一個(gè)疑問

數(shù)據(jù)庫 MySQL
今天看著MySQL的數(shù)據(jù)字典,突然想到一個(gè)問題:為什么MySQL數(shù)據(jù)字典 information_schema中的表名是大寫,而performance_schema和其他庫中的是小寫?帶著這個(gè)問題,我開始了一些猜測和自我論證。

MySQL關(guān)于數(shù)據(jù)字典的一個(gè)疑問

今天看著MySQL的數(shù)據(jù)字典,突然想到一個(gè)問題:為什么MySQL數(shù)據(jù)字典 information_schema中的表名是大寫,而performance_schema和其他庫中的是小寫?

帶著這個(gè)問題,我開始了一些猜測和自我論證。

首先大小寫的這個(gè)情況是相對不兼容的。

比如在performance_schema中,根據(jù)關(guān)鍵字user可以找到兩個(gè)相關(guān)的表。 

  1. mysql> show tables  like 'user%' 
  2. +--------------------------------------+  
  3. | Tables_in_performance_schema (user%) |  
  4. +--------------------------------------+  
  5. | user_variables_by_thread             |  
  6. | users                                |  
  7. +--------------------------------------+  
  8. rows in set (0.00 sec)  

但是如果我改做大寫,是不能識別的,這在其他的數(shù)據(jù)庫里也是類似的處理方式。 

  1. mysql> desc USERS;  
  2. ERROR 1146 (42S02): Table 'performance_schema.USERS' doesn't exist  
  3. mysql> select database();  
  4. +--------------------+  
  5. database()         |  
  6. +--------------------+  
  7. | performance_schema |  
  8. +--------------------+  
  9. 1 row in set (0.00 sec) 

而在information_schema中,則是相對兼容的。 

  1. mysql> select count(*)from tables; select count(*)from TABLES;  
  2. +----------+  
  3. count(*) |  
  4. +----------+  
  5. |      383 |  
  6. +----------+  
  7. 1 row in set (0.01 sec)  
  8. +----------+  
  9. count(*) |  
  10. +----------+  
  11. |      383 |  
  12. +----------+  
  13. 1 row in set (0.00 sec) 

如果從物理文件的角度來看,你會(huì)發(fā)現(xiàn)在MySQL中information_schema這個(gè)數(shù)據(jù)庫和其他數(shù)據(jù)庫不同,沒有一個(gè)指定的目錄存在。 

  1. [root@dev01 mysql]# ll  
  2. total 188796  
  3. -rw-r----- 1 mysql mysql       56 Jan  2 12:37 auto.cnf  
  4. -rw-r----- 1 mysql mysql        5 Mar 13 14:26 dev01.pid  
  5. drwxr-x--- 2 mysql mysql    12288 Mar  9 10:44 devopsdb  
  6. drwxr-x--- 2 mysql mysql     4096 Jan  2 12:38 dms_metadata  
  7. -rw-r----- 1 mysql mysql     1292 Jan 26 19:44 ib_buffer_pool  
  8. -rw-r----- 1 mysql mysql 79691776 Mar 13 23:27 ibdata1  
  9. -rw-r----- 1 mysql mysql 50331648 Mar 13 23:27 ib_logfile0  
  10. -rw-r----- 1 mysql mysql 50331648 Mar 13 23:27 ib_logfile1  
  11. -rw-r----- 1 mysql mysql 12582912 Mar 13 23:36 ibtmp1  
  12. drwxr-x--- 2 mysql mysql     4096 Jan 24 19:04 kmp  
  13. drwxr-x--- 2 mysql mysql     4096 Jan  2 12:37 mysql  
  14. -rw-r----- 1 mysql mysql   324407 Mar 13 21:54 mysqld.log  
  15. drwxr-x--- 2 mysql mysql     4096 Jan  2 12:37 performance_schema  
  16. drwxr-x--- 2 mysql mysql    12288 Jan  2 12:37 sys  
  17. drwxr-x--- 2 mysql mysql     4096 Mar 13 23:27 test  

這個(gè)數(shù)據(jù)的存儲(chǔ)就好比Oracle里面的系統(tǒng)表空間,所以information_schema是名副其實(shí)的數(shù)據(jù)字典庫。

而performance_schema則是一個(gè)內(nèi)存庫,它的存儲(chǔ)引擎是特別的一種,不是InnoDB也不是MyISAM,Memory,而是performance_schema

帶著疑問我繼續(xù)切換到了information_schema中,可以很明顯的發(fā)現(xiàn)information_schema中的數(shù)據(jù)字典大多是Memory存儲(chǔ)引擎。 

  1. mysql> show create table tables \G  
  2. *************************** 1. row ***************************  
  3.        Table: TABLES  
  4. Create TableCREATE TEMPORARY TABLE `TABLES` (  
  5.   `TABLE_CATALOG` varchar(512) NOT NULL DEFAULT '' 
  6.  。。。  
  7.   `TABLE_COMMENT` varchar(2048) NOT NULL DEFAULT ''  
  8. ) ENGINE=MEMORY DEFAULT CHARSET=utf8  
  9. 1 row in set (0.00 sec) 

還要一些是InnoDB的。 

  1. mysql>  show create table PLUGINS\G  
  2. *************************** 1. row ***************************  
  3.        Table: PLUGINS 
  4.  Create TableCREATE TEMPORARY TABLE `PLUGINS` (  
  5.   `PLUGIN_NAME` varchar(64) NOT NULL DEFAULT '' 
  6.   `PLUGIN_VERSION` varchar(20) NOT NULL DEFAULT '' 
  7.   `PLUGIN_STATUS` varchar(10) NOT NULL DEFAULT '' 
  8. 。。。  
  9.   `LOAD_OPTION` varchar(64) NOT NULL DEFAULT ''  
  10. ) ENGINE=InnoDB DEFAULT CHARSET=utf8  
  11. 1 row in set (0.00 sec)  

所以數(shù)據(jù)字典的結(jié)構(gòu)其實(shí)還算是比價(jià)繁雜,涉及多個(gè)存儲(chǔ)引擎,涉及多中規(guī)則和處理方式。

如果我們仔細(xì)查看上面的語句,就會(huì)發(fā)現(xiàn),這些數(shù)據(jù)字典都是temporary table.

明白了這些,對我們分析問題的方向就很有利了。

所以我的初步設(shè)想就是通過這種命名方式能夠標(biāo)識出來它就是臨時(shí)表,避免混淆。

怎么理解呢。

如果一個(gè)數(shù)據(jù)庫中存在一個(gè)臨時(shí)表,一個(gè)普通表,名字都是test,可不可行?

不要猜行不行,而是快速驗(yàn)證一下。 

  1. mysql> create table tmp (id int,name varchar(30));  
  2. Query OK, 0 rows affected (0.09 sec)  
  3. mysql> create temporary table tmp(id int,name varchar(30));  
  4. Query OK, 0 rows affected (0.00 sec) 

這個(gè)時(shí)候插入一條記錄,顯示成功,但是我們卻沒有辦法判斷到底是插入到了哪個(gè)表里。 

  1. mysql> insert into tmp values(1,'aa');  
  2. Query OK, 1 row affected (0.00 sec)  

所以我們可以用排除的方式來驗(yàn)證,我們刪掉tmp,然后查看剩下的數(shù)據(jù)到底在哪里?

刪除成功,但是這個(gè)時(shí)候我們還需要其他的信息來佐證。 

  1. mysql> drop table tmp ;  
  2. Query OK, 0 rows affected (0.00 sec)  

查看tmp的定義信息,很明顯drop的tmp是臨時(shí)表。 

  1. mysql> show create table tmp ;  
  2. +-------+---------------------------------------------+  
  3. Table | Create Table     
  4. +-------+--------------------------------------------+  
  5. | tmp   | CREATE TABLE `tmp` (  
  6.   `id` int(11) DEFAULT NULL 
  7.   `namevarchar(30) DEFAULT NULL  
  8. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |  
  9. +-------+-----------------------------------------+  
  10. 1 row in set (0.00 sec)  

那么插入的數(shù)據(jù)到了哪里呢,一查便知,顯示為0,則很顯然數(shù)據(jù)是插入到了臨時(shí)表tmp中。 

  1. mysql> select count(*)from tmp ;  
  2. +----------+  
  3. count(*) |  
  4. +----------+  
  5. |        0 |  
  6. +----------+  
  7. 1 row in set (0.00 sec)  

而如果我們繼續(xù)換個(gè)思路,定義兩個(gè)表,一個(gè)是大寫的TABLES,一個(gè)是小寫的tables

則默認(rèn)的情況下也是不會(huì)沖突的,盡管tables是在數(shù)據(jù)字典層面的一個(gè)表,但是在其他數(shù)據(jù)庫中依舊可以正常處理,命名還是不會(huì)沖突。 

  1. mysql> create table TABLES  (id INT );  
  2. Query OK, 0 rows affected (0.12 sec)  
  3.  
  4.  
  5. mysql> create table tables  (id INT );  
  6. Query OK, 0 rows affected (0.11 sec)  

所以這個(gè)問題的初步理解就是為了在數(shù)據(jù)字典層面作為一種清晰的標(biāo)識,而如果想得到更多的信息,還是得翻翻代碼的實(shí)現(xiàn)了。 

責(zé)任編輯:龐桂玉 來源: 楊建榮的學(xué)習(xí)筆記
相關(guān)推薦

2015-07-22 17:21:34

Oracle數(shù)據(jù)字典

2022-10-10 08:01:08

MySQL字典表

2023-03-04 20:50:19

MySQL字典InnoDB

2021-01-28 19:31:59

MySQL手冊方法

2010-04-09 10:13:13

Oracle數(shù)據(jù)字典

2010-04-28 17:49:41

Oracle數(shù)據(jù)字典

2010-03-31 16:38:02

Oracle數(shù)據(jù)字典

2010-04-06 17:17:16

Oracle數(shù)據(jù)字典

2010-04-27 16:18:26

Oracle數(shù)據(jù)字典

2010-07-14 13:50:48

SQL Server數(shù)

2010-04-22 09:36:56

Oracle數(shù)據(jù)字典

2023-05-03 09:18:24

RedisDB數(shù)據(jù)字典Dict

2010-04-22 10:00:41

Oracle數(shù)據(jù)字典

2010-04-14 14:09:38

Oracle管理腳本

2023-03-06 07:48:01

數(shù)據(jù)字典Spring

2014-10-20 16:29:04

屏蔽布線

2010-05-10 15:22:34

Oracle數(shù)據(jù)字典

2010-11-15 16:08:15

ORACLE系統(tǒng)表

2019-10-17 13:57:38

戴爾

2010-04-06 17:36:15

Oracle數(shù)據(jù)字典
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號