自动生成索引的脚本
本文内容遵从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很多,欢迎提供意见。
下面是一些例子
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;">(</span>col1<span style="color: #66cc66;">,</span>col3<span style="color: #66cc66;">)</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;">(</span>col2<span style="color: #66cc66;">,</span>col3<span style="color: #66cc66;">,</span>col1<span style="color: #66cc66;">)</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;">(</span>t2<span style="color: #66cc66;">,</span>t1<span style="color: #66cc66;">)</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;">(</span>col1<span style="color: #66cc66;">,</span>col2<span style="color: #66cc66;">)</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;">(</span>col2<span style="color: #66cc66;">,</span>col1<span style="color: #66cc66;">)</span>;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Cutting is a video editing tool with comprehensive editing functions, support for variable speed, various filters and beauty effects, and rich music library resources. In this software, you can edit videos directly or create editing scripts, but how to do it? In this tutorial, the editor will introduce the method of editing and making scripts. Production method: 1. Click to open the editing software on your computer, then find the "Creation Script" option and click to open. 2. In the creation script page, enter the "script title", and then enter a brief introduction to the shooting content in the outline. 3. How can I see the "Storyboard Description" option in the outline?

How to execute .sh file in Linux system? In Linux systems, a .sh file is a file called a Shell script, which is used to execute a series of commands. Executing .sh files is a very common operation. This article will introduce how to execute .sh files in Linux systems and provide specific code examples. Method 1: Use an absolute path to execute a .sh file. To execute a .sh file in a Linux system, you can use an absolute path to specify the location of the file. The following are the specific steps: Open the terminal

How to change the page that opens the Microsoft Edge browser to 360 navigation? It is actually very simple, so now I will share with you the method of changing the page that opens the Microsoft Edge browser to 360 navigation. Friends in need can take a look. I hope Can help everyone. Open the Microsoft Edge browser. We see a page like the one below. Click the three-dot icon in the upper right corner. Click "Settings." Click "On startup" in the left column of the settings page. Click on the three points shown in the picture in the right column (do not click "Open New Tab"), then click Edit and change the URL to "0" (or other meaningless numbers). Then click "Save". Next, select "

We've designed this Windows PowerShell scripting tutorial for beginners, whether you're a tech enthusiast or a professional looking to improve your scripting skills. If you have no prior knowledge of PowerShell scripting, this article will start with the basics and be tailored for you. We'll help you master the installation steps for a PowerShell environment and walk you through the main concepts and features of PowerShell scripts. If you're ready to learn more about PowerShell scripting, let's embark on this exciting learning journey together! What is WindowsPowerShell? PowerShell is a hybrid command system developed by Microsoft

Can downloads be deleted? In recent years, with the advent of the digital age, more and more digital products and services have appeared in our lives. What follows is that our demand for digital content is increasing day by day. In our daily life and work, we often need to download a variety of files, such as documents, pictures, audios, videos, etc. These downloaded files are usually saved in a folder called "downloads". However, over time we often find that,"

What games can be played with i34150 with 1G independent graphics? Can it play small games such as LoL? GTX750 and GTX750TI are very suitable graphics card choices. If you just play some small games or not play games, it is recommended to use the i34150 integrated graphics card. Generally speaking, the price difference between graphics cards and processors is not very big, so it is important to choose a reasonable combination. If you need 2G of video memory, it is recommended to choose GTX750TI; if you only need 1G of video memory, just choose GTX750. GTX750TI can be seen as an enhanced version of GTX750, with overclocking capabilities. Which graphics card can be paired with i34150 depends on your needs. If you plan to play stand-alone games, it is recommended that you consider changing the graphics card. you can choose

CheatEngine is a game editor that can edit and modify the game's memory. However, its default language is non-Chinese, which is inconvenient for many friends. So how to set Chinese in CheatEngine? Today, the editor will give you a detailed introduction to how to set up Chinese in CheatEngine. I hope it can help you. Setting method one: 1. Double-click to open the software and click "edit" in the upper left corner. 2. Then click “settings” in the option list below. 3. In the opened window interface, click "languages" in the left column

Do you know where to set the download button to display in Microsoft Edge? Below, the editor will bring you the method to set the download button to display in Microsoft Edge. I hope it will be helpful to you. Let’s follow the editor to learn it! Step 1: First open Microsoft Edge Browser, click the [...] logo in the upper right corner, as shown in the figure below. Step 2: Then click [Settings] in the pop-up menu, as shown in the figure below. Step 3: Then click [Appearance] on the left side of the interface, as shown in the figure below. Step 4: Finally, click the button on the right side of [Show Download Button] and it will change from gray to blue, as shown in the figure below. The above is where the editor brings you how to set up the download button in Microsoft Edge.
