您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

自动生成索引的脚本

2025/1/9 10:47:08发布15次查看
本文内容遵从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-laptop:~/dropbox/mysqlscript$ ./autocreateindex.pl -e 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.col1alter table foo1 add index idx (col1,col3);alter table foo2 add index idx (col2,col3,col1);plx@plinux-laptop:~/dropbox/mysqlscript$ ./autocreateindex.pl -e select * from t1 where t1 =1 and t2=2alter table t1 add index idx (t2,t1);plx@plinux-laptop:~/dropbox/mysqlscript$ ./autocreateindex.pl -e select * from t1 where col1=1 and col2=4alter table t1 add index idx (col1,col2);plx@plinux-laptop:~/dropbox/mysqlscript$ ./autocreateindex.pl -e select * from t1 where col1>1 and col2=4alter table t1 add index idx (col2,col1);
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product