Heim Datenbank MySQL-Tutorial 自动生成索引的脚本

自动生成索引的脚本

Jun 07, 2016 pm 04:32 PM
内容 协议 Kann 版权 索引 脚本 自动生成

本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/database/autocreateindex_script_release.html 写了个自动建索引的脚本,基本原理是解析SQL 的条件,然后得出每个条件

本文内容遵从CC版权协议, 可以随意转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明网址: http://www.penglixun.com/tech/database/autocreateindex_script_release.html

写了个自动建索引的脚本,基本原理是解析SQL的条件,然后得出每个条件的运算符,最后通过优先级矩阵将可以建索引的列排序求最长的序列,也就是尽可能把更多的列包含进索引。

使用方法:
./AutoCreateIndex.pl -e “你的SQL”

对于多表连接,务必将列名前跟上表名,否则无法处理,因为脚本并不连接数据库,无法判断哪个列属于那个表。
测试版本,Bug很多,欢迎提供意见。

Note: There is a file embedded within this post, please visit this post to download the file.

下面是一些例子

plx@plinux<span style="color: #66cc66;">-</span>Laptop:~<span style="color: #66cc66;">/</span>Dropbox<span style="color: #66cc66;">/</span>MySQLScript$ <span style="color: #66cc66;">./</span>AutoCreateIndex<span style="color: #66cc66;">.</span>pl <span style="color: #66cc66;">-</span>e <span style="color: #ff0000;">"SELECT * FROM foo1 a,foo2 b WHERE 'fdsfsa'=a.col1 AND b.col2 = 'abc' AND a.col1=b.col2 AND a.col3 >1 ORDER BY b.col3,b.col1"</span>
<span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> foo1 <span style="color: #993333; font-weight: bold;">ADD</span> <span style="color: #993333; font-weight: bold;">INDEX</span> idx <span style="color: #66cc66;">&#40;</span>col1<span style="color: #66cc66;">,</span>col3<span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> foo2 <span style="color: #993333; font-weight: bold;">ADD</span> <span style="color: #993333; font-weight: bold;">INDEX</span> idx <span style="color: #66cc66;">&#40;</span>col2<span style="color: #66cc66;">,</span>col3<span style="color: #66cc66;">,</span>col1<span style="color: #66cc66;">&#41;</span>;
plx@plinux<span style="color: #66cc66;">-</span>Laptop:~<span style="color: #66cc66;">/</span>Dropbox<span style="color: #66cc66;">/</span>MySQLScript$ <span style="color: #66cc66;">./</span>AutoCreateIndex<span style="color: #66cc66;">.</span>pl <span style="color: #66cc66;">-</span>e <span style="color: #ff0000;">"SELECT * FROM t1 where t1 =1 and t2=2"</span>
<span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> t1 <span style="color: #993333; font-weight: bold;">ADD</span> <span style="color: #993333; font-weight: bold;">INDEX</span> idx <span style="color: #66cc66;">&#40;</span>t2<span style="color: #66cc66;">,</span>t1<span style="color: #66cc66;">&#41;</span>;
plx@plinux<span style="color: #66cc66;">-</span>Laptop:~<span style="color: #66cc66;">/</span>Dropbox<span style="color: #66cc66;">/</span>MySQLScript$ <span style="color: #66cc66;">./</span>AutoCreateIndex<span style="color: #66cc66;">.</span>pl <span style="color: #66cc66;">-</span>e <span style="color: #ff0000;">"SELECT * FROM t1 where col1=1 and col2=4"</span>
<span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> t1 <span style="color: #993333; font-weight: bold;">ADD</span> <span style="color: #993333; font-weight: bold;">INDEX</span> idx <span style="color: #66cc66;">&#40;</span>col1<span style="color: #66cc66;">,</span>col2<span style="color: #66cc66;">&#41;</span>;
plx@plinux<span style="color: #66cc66;">-</span>Laptop:~<span style="color: #66cc66;">/</span>Dropbox<span style="color: #66cc66;">/</span>MySQLScript$ <span style="color: #66cc66;">./</span>AutoCreateIndex<span style="color: #66cc66;">.</span>pl <span style="color: #66cc66;">-</span>e <span style="color: #ff0000;">"SELECT * FROM t1 where col1>1 and col2=4"</span>
<span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> t1 <span style="color: #993333; font-weight: bold;">ADD</span> <span style="color: #993333; font-weight: bold;">INDEX</span> idx <span style="color: #66cc66;">&#40;</span>col2<span style="color: #66cc66;">,</span>col1<span style="color: #66cc66;">&#41;</span>;
Nach dem Login kopieren
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
2 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
Repo: Wie man Teamkollegen wiederbelebt
4 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Abenteuer: Wie man riesige Samen bekommt
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Wie erstelle ich ein Skript zur Bearbeitung? Tutorial zum Erstellen eines Skripts durch Bearbeitung Wie erstelle ich ein Skript zur Bearbeitung? Tutorial zum Erstellen eines Skripts durch Bearbeitung Mar 13, 2024 pm 12:46 PM

Wie erstelle ich ein Skript zur Bearbeitung? Tutorial zum Erstellen eines Skripts durch Bearbeitung

Wie führe ich eine .sh-Datei im Linux-System aus? Wie führe ich eine .sh-Datei im Linux-System aus? Mar 14, 2024 pm 06:42 PM

Wie führe ich eine .sh-Datei im Linux-System aus?

So ändern Sie den Microsoft Edge-Browser so, dass er mit 360-Navigation geöffnet wird - So ändern Sie die Öffnung mit 360-Navigation So ändern Sie den Microsoft Edge-Browser so, dass er mit 360-Navigation geöffnet wird - So ändern Sie die Öffnung mit 360-Navigation Mar 04, 2024 pm 01:50 PM

So ändern Sie den Microsoft Edge-Browser so, dass er mit 360-Navigation geöffnet wird - So ändern Sie die Öffnung mit 360-Navigation

Windows PowerShell-Skript-Tutorial für Anfänger Windows PowerShell-Skript-Tutorial für Anfänger Mar 13, 2024 pm 10:55 PM

Windows PowerShell-Skript-Tutorial für Anfänger

Kann ich den Download-Ordner löschen? Kann ich den Download-Ordner löschen? Feb 19, 2024 pm 03:38 PM

Kann ich den Download-Ordner löschen?

Wo wird die Download-Schaltfläche in Microsoft Edge festgelegt? – So richten Sie die Download-Schaltfläche in Microsoft Edge ein Wo wird die Download-Schaltfläche in Microsoft Edge festgelegt? – So richten Sie die Download-Schaltfläche in Microsoft Edge ein Mar 06, 2024 am 11:49 AM

Wo wird die Download-Schaltfläche in Microsoft Edge festgelegt? – So richten Sie die Download-Schaltfläche in Microsoft Edge ein

Wie richte ich die Cheat Engine auf Chinesisch ein? Cheat Engine-Einstellung chinesische Methode Wie richte ich die Cheat Engine auf Chinesisch ein? Cheat Engine-Einstellung chinesische Methode Mar 13, 2024 pm 04:49 PM

Wie richte ich die Cheat Engine auf Chinesisch ein? Cheat Engine-Einstellung chinesische Methode

So erstellen Sie automatisch ein Verzeichnis. So legen Sie das Format des automatisch generierten Verzeichnisses fest. So erstellen Sie automatisch ein Verzeichnis. So legen Sie das Format des automatisch generierten Verzeichnisses fest. Feb 22, 2024 pm 03:30 PM

So erstellen Sie automatisch ein Verzeichnis. So legen Sie das Format des automatisch generierten Verzeichnisses fest.

See all articles