MySQLSchema设计(四)一个MySQL里的JQuery:common_schema_MySQL
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'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='innodb_index_stats'/G;*************************** 1. row ***************************help_message:NAMEinnodb_index_stats: Estimated InnoDB depth & split factor of key'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
mysql> select * from data_size_per_schema where table_schema='sakila'/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 * from candidate_keys_recommended where table_schema='sakila'; +--------------+---------------+------------------------+--------------+------------+-----------------------+---------------------+ | 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('sakila','actor_info'); +-------------+---------------+-------------+--------+ | 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 eval('select concat(/'create table test./', table_name,/' as select * from sakila./', table_name) '> from information_schema.tables '> where table_schema = /'sakila/''); 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('select concat(/'drop table test./', table_name) from information_schema.tables '> where table_schema = /'test/''); Query OK, 0 rows affected (0.92 sec) mysql> show tables in test; Empty set (0.00 sec)
mysql> call help('foreach'); +--------------------------------------------------------------------------------+ | 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 $('1:3', 'create table test.${1}(id int,name varchar(20))'); 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 $('1:3', 'drop table test.`${1}`'); Query OK, 0 rows affected, 1 warning (0.40 sec) mysql> show tables in test; Empty set (0.00 sec)

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

这个AI辅助编程工具在这个AI迅速发展的阶段,挖掘出了一大批好用的AI辅助编程工具。AI辅助编程工具能够提高开发效率、改善代码质量、降低bug率,是现代软件开发过程中的重要助手。今天大姚给大家分享4款AI辅助编程工具(并且都支持C#语言),希望对大家有所帮助。https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot是一款AI编码助手,可帮助你更快、更省力地编写代码,从而将更多精力集中在问题解决和协作上。Git

Go语言开发移动应用程序教程随着移动应用市场的不断蓬勃发展,越来越多的开发者开始探索如何利用Go语言开发移动应用程序。作为一种简洁高效的编程语言,Go语言在移动应用开发中也展现出了强大的潜力。本文将详细介绍如何利用Go语言开发移动应用程序,并附上具体的代码示例,帮助读者快速入门并开始开发自己的移动应用。一、准备工作在开始之前,我们需要准备好开发环境和工具。首

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语言自从诞生以来,受到了广泛的关注和应用。作为一门新兴的高效、简洁的编程语言,Go的快速发展离不开丰富的开源库的支持。本文将介绍五大热门的Go语言库,这些库在Go开发中扮演了至关重要的角色,为开发者提供了强大的功能和便捷的开发体验。同时,为了更好地理解这些库的用途和功能,我们会结合具体的代码示例进行讲

PHP在Web开发中是属于后端。PHP是一种服务器端脚本语言,主要用于处理服务器端的逻辑,生成动态网页内容。与前端技术相比,PHP更多地用于与数据库交互、处理用户请求以及生成页面内容等后端操作。接下来通过具体的代码示例来说明PHP在后端开发中的应用。首先,我们来看一个简单的PHP代码示例,用于连接数据库并查询数据:

Java开发必备:详细解读Java虚拟机安装步骤,需要具体代码示例随着计算机科学和技术的发展,Java语言已成为广泛使用的编程语言之一。它具有跨平台、面向对象等优点,逐渐成为开发人员的首选语言。在使用Java进行开发之前,首先需要安装Java虚拟机(JavaVirtualMachine,JVM)。本文将详细解读Java虚拟机的安装步骤,并提供具体的代码示

《了解VSCode:这款工具到底是用来干什么的?》作为一个程序员,无论是初学者还是资深开发者,都离不开代码编辑工具的使用。在众多编辑工具中,VisualStudioCode(简称VSCode)作为一款开源、轻量级、强大的代码编辑器备受开发者欢迎。那么,VSCode到底是用来干什么的?本文将深入探讨VSCode的功能和用途,并提供具体的代码示例,以帮助读者

Android开发是一项繁忙而又令人兴奋的工作,而选择一个适合的Linux发行版来进行开发则显得尤为重要。在众多的Linux发行版中,究竟哪一个最适合Android开发呢?本文将从几个方面来探讨这一问题,并给出具体的代码示例。首先,我们来看一下目前流行的几个Linux发行版:Ubuntu、Fedora、Debian、CentOS等,它们都有各自的优点和特点。
