首頁 資料庫 mysql教程 MySQLSchema设计(四)一个MySQL里的JQuery:common_schema_MySQL

MySQLSchema设计(四)一个MySQL里的JQuery:common_schema_MySQL

May 27, 2016 pm 02:12 PM
開發 法律

jQuery

bitsCN.com

我们总要在一定的框架中活着,框架的构成有来自法律,有来自道德的,还有来自潜规则的。大部分人只求安生的活着,玩命的人毕竟是少数,有人打破框架平度青云,也有人打破框却架坠落深渊。每每跟开发人员讨论业务,就会听到一大滩框架名称,觉得很是高上大的样子。但他山之石可以攻玉,在MySQL当中也是有框架,这便是我们要介绍的common_schema。高性能MySQL一书作者 Baron Schwartz曾如是说:The common_schema is to MySQL as JQuery is to JavaScript。本节仅仅简单介绍Schema相关部分,毕竟common_schema实在太强悍太广博。

软件主页:code.google.com/p/common-schema软件安装

[mysql@DataHacker ~]$ mysql -uroot -p < common_schema-2.2.sqlEnter password:complete- Base components: installed- InnoDB Plugin components: installed- Percona Server components: not installed- TokuDB components: partial install: 1/2Installation complete. Thank you for using common_schema!
登入後複製
软件信息:
mysql> select attribute_name,substr(attribute_value,1,50) from metadata;+-------------------------------------+----------------------------------------------------+| attribute_name                      | substr(attribute_value,1,50)                       |+-------------------------------------+----------------------------------------------------+| author                              | Shlomi Noach                                       || author_url                          | http://code.openark.org/blog/shlomi-noach          || base_components_installed           | 1                                                  || innodb_plugin_components_installed  | 1                                                  || install_mysql_version               | 5.6.12-log                                         || install_sql_mode                    | NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES,NO_ENGIN || install_success                     | 1                                                  || install_time                        | 2014-02-05 21:53:55                                || license                             |common_schema - DBA&#39;s Framework for MySQLCopyri || license_type                        | GPL                                                || percona_server_components_installed | 0                                                  || project_home                        | http://code.google.com/p/common-schema/            || project_name                        | common_schema                                      || project_repository                  | https://common-schema.googlecode.com/svn/trunk/    || project_repository_type             | svn                                                || revision                            | 523                                                || version                             | 2.2                                                |+-------------------------------------+----------------------------------------------------+17 rows in set (0.00 sec)
登入後複製
内建帮助系统:
mysql> desc help_content;+--------------+-------------+------+-----+---------+-------+| Field        | Type        | Null | Key | Default | Extra |+--------------+-------------+------+-----+---------+-------+| topic        | varchar(32) | NO   | PRI | NULL    |       || help_message | text        | NO   |     | NULL    |       |+--------------+-------------+------+-----+---------+-------+2 rows in set (0.00 sec)mysql> select topic from help_content;+--------------------------------+| topic                          |+--------------------------------+| auto_increment_columns         || candidate_keys                 || candidate_keys_recommended     |mysql> select help_message from help_content where topic=&#39;innodb_index_stats&#39;/G;*************************** 1. row ***************************help_message:NAMEinnodb_index_stats: Estimated InnoDB depth & split factor of key&#39;s B+ TreeTYPEViewDESCRIPTIONinnodb_index_stats extends the INNODB_INDEX_STATS patch in Percona Server, andpresents with estimated depth & split factor of InnoDB keys.Estimations are optimistic, in that they assume condensed trees. It ispossible that the depth is larger than estimated, and that split factor islower than estimated.Estimated values are presented as floating point values, although in realitythese are integer types.This view is experimental and in BETA stage.This view depends upon the INNODB_INDEX_STATS patch in Percona Server.Note that Percona Server 5.5.8-20.0 version introduced changes to theINNODB_INDEX_STATS schema. This view is compatible with the new schema, and isincompatible with older releases................<此处省略输出>.............
登入後複製

FROM _flattened_keys AS redundant_keys INNER JOIN _flattened_keys AS dominant_keys USING (TABLE_SCHEMA, TABLE_NAME)
再以 _flattened_keys 为基表查看:
登入後複製
  FROM INFORMATION_SCHEMA.STATISTICS
登入後複製
作者Shlomi Noach便是认为"INFORMATION_SCHEMAprovides with complete info, it is ofter difficult to aggregate. It is sometimes too normalized, and at other times too de-normalized",他的诞生和Perl有些类似,系统管理员沃尔曾想用awk来完成,但其并不能满足他的需求,结果就是一门新的编程语言要诞生了。
mysql> select * from data_size_per_schema where table_schema=&#39;sakila&#39;/G;*************************** 1. row ***************************      TABLE_SCHEMA: sakila      count_tables: 16       count_views: 7  distinct_engines: 2         data_size: 4297536        index_size: 2581504        total_size: 6879040     largest_table: rentallargest_table_size: 27852801 row in set (0.16 sec)
登入後複製

DDL scripts
mysql> select table_name,sql_add_keys from sql_alter_table where table_schema='sakila'/G; *************************** 1. row *************************** table_name: actor sql_add_keys: ADD KEY `idx_actor_last_name`(`last_name`), ADD KEY `idx_actor_last_name_duplicate`(`last_name`), ADD PRIMARY KEY (`actor_id`) *************************** 2. row *************************** table_name: address sql_add_keys: ADD KEY `idx_fk_city_id`(`city_id`), ADD PRIMARY KEY (`address_id`) .................<此处省略输出>................. mysql> select * from sql_foreign_keys where table_schema='sakila'/G; *************************** 1. row *************************** TABLE_SCHEMA: sakila TABLE_NAME: address CONSTRAINT_NAME: fk_address_city drop_statement: ALTER TABLE `sakila`.`address` DROP FOREIGN KEY `fk_address_city` create_statement: ALTER TABLE `sakila`.`address` ADD CONSTRAINT `fk_address_city` FOREIGN KEY (`city_id`) REFERENCES `sakila`.`city` (`city_id`) ON DELETE RESTRICT ON UPDATE CASCADE ........................<此处省略输出>.........................

mysql> select table_name,column_name,data_type,max_value,auto_increment value,auto_increment_ratio ratio -> from auto_increment_columns -> where table_schema='sakila'; +------------+--------------+-----------+------------+-------+--------+ | TABLE_NAME | COLUMN_NAME | DATA_TYPE | max_value | value | ratio | +------------+--------------+-----------+------------+-------+--------+ | actor | actor_id | smallint | 65535 | 201 | 0.0031 | | address | address_id | smallint | 65535 | 606 | 0.0092 | | category | category_id | tinyint | 255 | 17 | 0.0667 | | city | city_id | smallint | 65535 | 601 | 0.0092 | | country | country_id | smallint | 65535 | 110 | 0.0017 | | customer | customer_id | smallint | 65535 | 600 | 0.0092 | | film | film_id | smallint | 65535 | 1001 | 0.0153 | | inventory | inventory_id | mediumint | 16777215 | 4582 | 0.0003 | | language | language_id | tinyint | 255 | 7 | 0.0275 | | payment | payment_id | smallint | 65535 | 16050 | 0.2449 | | rental | rental_id | int | 2147483647 | 16050 | 0.0000 | | staff | staff_id | tinyint | 255 | 3 | 0.0118 | | store | store_id | tinyint | 255 | 3 | 0.0118 | +------------+--------------+-----------+------------+-------+--------+ 13 rows in set (0.90 sec)
mysql> select * from candidate_keys_recommended where table_schema=&#39;sakila&#39;; +--------------+---------------+------------------------+--------------+------------+-----------------------+---------------------+ | table_schema | table_name | recommended_index_name | has_nullable | is_primary | count_column_in_index | column_names | +--------------+---------------+------------------------+--------------+------------+-----------------------+---------------------+ | sakila | language | PRIMARY | 0 | 1 | 1 | language_id | | sakila | customer | PRIMARY | 0 | 1 | 1 | customer_id | | sakila | film_category | PRIMARY | 0 | 1 | 2 | film_id,category_id | | sakila | category | PRIMARY | 0 | 1 | 1 | category_id | | sakila | rental | PRIMARY | 0 | 1 | 1 | rental_id | | sakila | film_actor | PRIMARY | 0 | 1 | 2 | actor_id,film_id | | sakila | inventory | PRIMARY | 0 | 1 | 1 | inventory_id | | sakila | country | PRIMARY | 0 | 1 | 1 | country_id | | sakila | store | PRIMARY | 0 | 1 | 1 | store_id | | sakila | address | PRIMARY | 0 | 1 | 1 | address_id | | sakila | payment | PRIMARY | 0 | 1 | 1 | payment_id | | sakila | film | PRIMARY | 0 | 1 | 1 | film_id | | sakila | film_text | PRIMARY | 0 | 1 | 1 | film_id | | sakila | city | PRIMARY | 0 | 1 | 1 | city_id | | sakila | staff | PRIMARY | 0 | 1 | 1 | staff_id | | sakila | actor | PRIMARY | 0 | 1 | 1 | actor_id | +--------------+---------------+------------------------+--------------+------------+-----------------------+---------------------+ 16 rows in set (0.39 sec)
登入後複製
mysql> call get_view_dependencies(&#39;sakila&#39;,&#39;actor_info&#39;); +-------------+---------------+-------------+--------+ | schema_name | object_name | object_type | action | +-------------+---------------+-------------+--------+ | sakila | actor | table | select | | sakila | category | table | select | | sakila | film | table | select | | sakila | film_actor | table | select | | sakila | film_category | table | select | +-------------+---------------+-------------+--------+ 5 rows in set (0.32 sec) Query OK, 0 rows affected (0.32 sec)
登入後複製
mysql> call help('eval'); +--------------------------------------------------------------------------------+ | help | +--------------------------------------------------------------------------------+ | | | NAME | | | | eval(): Evaluates the queries generated by a given query. | | | | TYPE | ..............<此处省略输出>...............
mysql> call eval(&#39;select concat(/&#39;create table test./&#39;, table_name,/&#39; as select * from sakila./&#39;, table_name) &#39;> from information_schema.tables &#39;> where table_schema = /&#39;sakila/&#39;&#39;); Query OK, 0 rows affected (11.30 sec) mysql> show tables in test; +----------------------------+ | Tables_in_test | +----------------------------+ | actor | | actor_info | | address | ...... <此处省略输出>....... | staff_list | | store | +----------------------------+ 23 rows in set (0.00 sec) mysql> call eval(&#39;select concat(/&#39;drop table test./&#39;, table_name) from information_schema.tables &#39;> where table_schema = /&#39;test/&#39;&#39;); Query OK, 0 rows affected (0.92 sec) mysql> show tables in test; Empty set (0.00 sec)
登入後複製
mysql> call help(&#39;foreach&#39;); +--------------------------------------------------------------------------------+ | help | +--------------------------------------------------------------------------------+ | | | NAME | | | | foreach(): Invoke a script on each element of given collection. $() is a | | synonym of this routine. | | | | TYPE | | | | Procedure | | | | DESCRIPTION | | | | This procedure accepts collections of varying types, including result sets, | | and invokes a QueryScript code per element. | ...............<此处省略N个输出>.................
登入後複製
mysql> call $(&#39;1:3&#39;, &#39;create table test.${1}(id int,name varchar(20))&#39;); Query OK, 0 rows affected, 1 warning (0.59 sec) mysql> show tables in test; +----------------+ | Tables_in_test | +----------------+ | 1 | | 2 | | 3 | +----------------+ 3 rows in set (0.00 sec) mysql> call $(&#39;1:3&#39;, &#39;drop table test.`${1}`&#39;); Query OK, 0 rows affected, 1 warning (0.40 sec) mysql> show tables in test; Empty set (0.00 sec)
登入後複製
bitsCN.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

四款值得推薦的AI輔助程式工具 四款值得推薦的AI輔助程式工具 Apr 22, 2024 pm 05:34 PM

這個AI輔助程式工具在這個AI快速發展的階段,挖掘出了一大批好用的AI輔助程式工具。 AI輔助程式設計工具能夠提升開發效率、提升程式碼品質、降低bug率,是現代軟體開發過程中的重要助手。今天大姚給大家分享4款AI輔助程式工具(而且都支援C#語言),希望對大家有幫助。 https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot是一款AI編碼助手,可幫助你更快、更省力地編寫程式碼,從而將更多精力集中在問題解決和協作上。 Git

AI程式設計師哪家強?探索Devin、通靈靈碼和SWE-agent的潛力 AI程式設計師哪家強?探索Devin、通靈靈碼和SWE-agent的潛力 Apr 07, 2024 am 09:10 AM

2022年3月3日,距離世界首個AI程式設計師Devin誕生不足一個月,普林斯頓大學的NLP團隊開發了一個開源AI程式設計師SWE-agent。它利用GPT-4模型在GitHub儲存庫中自動解決問題。 SWE-agent在SWE-bench測試集上的表現與Devin相似,平均耗時93秒,解決了12.29%的問題。 SWE-agent透過與專用終端交互,可以開啟、搜尋文件內容,使用自動語法檢查、編輯特定行,以及編寫和執行測試。 (註:以上內容為原始內容微調,但保留了原文中的關鍵訊息,未超過指定字數限制。)SWE-A

學習如何利用Go語言開發行動應用程式 學習如何利用Go語言開發行動應用程式 Mar 28, 2024 pm 10:00 PM

Go語言開發行動應用程式教學隨著行動應用程式市場的不斷蓬勃發展,越來越多的開發者開始探索如何利用Go語言開發行動應用程式。作為一種簡潔高效的程式語言,Go語言在行動應用開發中也展現了強大的潛力。本文將詳細介紹如何利用Go語言開發行動應用程序,並附上具體的程式碼範例,幫助讀者快速入門並開始開發自己的行動應用程式。一、準備工作在開始之前,我們需要準備好開發環境和工具。首

五大熱門Go語言庫總表:開發必備利器 五大熱門Go語言庫總表:開發必備利器 Feb 22, 2024 pm 02:33 PM

五大熱門Go語言庫總結:開發必備利器,需要具體程式碼範例Go語言自從誕生以來,受到了廣泛的關注和應用。作為一門新興的高效、簡潔的程式語言,Go的快速發展離不開豐富的開源程式庫的支援。本文將介紹五大熱門的Go語言庫,這些庫在Go開發中扮演了至關重要的角色,為開發者提供了強大的功能和便利的開發體驗。同時,為了更好地理解這些庫的用途和功能,我們會結合具體的程式碼範例進行講

了解VSCode:這款工具到底是用來做什麼的? 了解VSCode:這款工具到底是用來做什麼的? Mar 25, 2024 pm 03:06 PM

《了解VSCode:這款工具到底是用來做什麼的? 》身為程式設計師,無論是初學者或資深開發者,都離不開程式碼編輯工具的使用。在眾多編輯工具中,VisualStudioCode(簡稱VSCode)作為一款開源、輕量級、強大的程式碼編輯器備受開發者歡迎。那麼,VSCode到底是用來做什麼的呢?本文將深入探討VSCode的功能和用途,並提供具體的程式碼範例,以幫助讀者

Android開發最適合的Linux發行版是哪一個? Android開發最適合的Linux發行版是哪一個? Mar 14, 2024 pm 12:30 PM

Android開發是一項繁忙而又令人興奮的工作,而選擇適合的Linux發行版來進行開發則顯得尤為重要。在眾多的Linux發行版中,究竟哪一個最適合Android開發呢?本文將從幾個方面來探討這個問題,並給出具體的程式碼範例。首先,我們來看看目前流行的幾個Linux發行版:Ubuntu、Fedora、Debian、CentOS等,它們都有各自的優點和特點。

PHP在Web開發中是屬於前端還是後端? PHP在Web開發中是屬於前端還是後端? Mar 24, 2024 pm 02:18 PM

PHP在Web開發中是屬於後端。 PHP是一種伺服器端腳本語言,主要用於處理伺服器端的邏輯,產生動態網頁內容。與前端技術相比,PHP更多地用於與資料庫互動、處理使用者請求以及生成頁面內容等後端操作。接下來透過具體的程式碼範例來說明PHP在後端開發中的應用。首先,我們來看一個簡單的PHP程式碼範例,用於連接資料庫並查詢資料:

全面指南:詳解Java虛擬機器安裝過程 全面指南:詳解Java虛擬機器安裝過程 Jan 24, 2024 am 09:02 AM

Java開發必備:詳細解讀Java虛擬機器安裝步驟,需要具體程式碼範例隨著電腦科學和技術的發展,Java語言已成為廣泛使用的程式語言之一。它具有跨平台、物件導向等優點,逐漸成為開發人員的首選語言。在使用Java進行開發之前,首先需要安裝Java虛擬機器(JavaVirtualMachine,JVM)。本文將詳細解讀Java虛擬機器的安裝步驟,並提供具體的程式碼示

See all articles