Paw Index Advisor是PawSQL团队开发的面向数据库应用开发人员和DBA等数据库运维人员的自动化、智能化、基于代价的索引推荐工具。Paw Index Advisor IntelliJ插件帮助应用开发人员一键优化应用性能。
日前已支持基于IntelliJ的多个开发工具, 包括IntelliJ IDEA , PhpStorm, DataGrip , PyCharm , WebStorm等。
下面小编为大家介绍一下工具的使用方法。
-
启动IntelliJ集成开发环境,打开项目Setting, 选择Plugins;
-
在Marketplace输入"Paw Index Advisor",点击安装;
-
配置索引推荐相关信息,点击确定;
-
右键点击需要进行分析的SQL文件或是文件夹,点击“Run Index Advisor”;
-
查看推荐出来的索引以及推荐索引对于SQL的收益分析。
使用截图:
1. 运行配置
2.一键执行
3. 结果输出
输出分为两个部分,一是输出的可执行的索引创建SQL文件。二是what-if analysis的详细信息,标注了哪些查询会使用哪些推荐的索引,使用后的性能提升比等信息。
3.1 推荐索引:
-
现有的索引信息
-
推荐的索引信息
-
What-if 验证后的推荐索引信息
-- Existing indexes
/*
CREATE INDEX CUSTOMER_C_NATIONKEY_FKEY ON CUSTOMER(C_NATIONKEY);
CREATE INDEX CUSTOMER_PKEY ON CUSTOMER(C_CUSTKEY);
CREATE INDEX MYINDEX ON CUSTOMER(C_NAME,C_PHONE);
...
*/
-- Recommended indexes (After deduplication with existing indexes above)
/*
CREATE INDEX SQLLAB_IDX1496549982 ON NATION(N_NATIONKEY,N_NAME);
CREATE INDEX SQLLAB_IDX1049412868 ON NATION(N_NAME,N_NATIONKEY,N_REGIONKEY);
CREATE INDEX SQLLAB_IDX1640274034 ON NATION(N_NATIONKEY,N_REGIONKEY,N_NAME);
CREATE INDEX SQLLAB_IDX1968327707 ON PARTSUPP(PS_SUPPKEY,PS_PARTKEY,PS_SUPPLYCOST);
CREATE INDEX SQLLAB_IDX1794855777 ON PARTSUPP(PS_SUPPLYCOST,PS_SUPPKEY,PS_PARTKEY);
CREATE INDEX SQLLAB_IDX1797601124 ON PARTSUPP(PS_PARTKEY,PS_SUPPKEY,PS_SUPPLYCOST,PS_AVAILQTY);
CREATE INDEX SQLLAB_IDX1400713053 ON PARTSUPP(PS_SUPPKEY,PS_SUPPLYCOST,PS_AVAILQTY,PS_PARTKEY);
...
*/
-- After what-if analaysis validation
CREATE INDEX SQLLAB_IDX1640274034 ON NATION(N_NATIONKEY,N_REGIONKEY,N_NAME);
CREATE INDEX SQLLAB_IDX1120442220 ON LINEITEM(L_RETURNFLAG,L_ORDERKEY,L_DISCOUNT,L_EXTENDEDPRICE);
CREATE INDEX SQLLAB_IDX1003493942 ON SUPPLIER(S_NATIONKEY,S_SUPPKEY,S_NAME,S_ADDRESS);
CREATE INDEX SQLLAB_IDX1852359742 ON ORDERS(O_ORDERDATE,O_ORDERKEY,O_CUSTKEY,O_SHIPPRIORITY);
...
3.2 What-if 验证信息
对于每一个作为输入的SQL,列出会使用的推荐索引,以及使用推荐索引前后的代价以及提升的比率。
-
-- 17.sql1 -输入的SQL编号
-
performance improves by 4318.409090909091% -性能提升百分比
-
[cost_before=583.23,after_cost=13.2]-索引应用前后的代价估计
-
Contributing indice:[SQLLAB_IDX1352615704, SQLLAB_IDX0607681583, SQLLAB_IDX1285498835] -该SQL使用的索引名称
-
SELECT SUM(L_EXTENDEDPRICE) / 7.0 AS AVG_YEARLY FROM ...-输入的SQL原文
-- Validation details
-- 17.sql1, performance improves by 4318.409090909091%[cost_before=583.23,after_cost=13.2]
Contributing indice:[SQLLAB_IDX1352615704, SQLLAB_IDX0607681583, SQLLAB_IDX1285498835]
SELECT SUM(L_EXTENDEDPRICE) / 7.0 AS AVG_YEARLY FROM LINEITEM, PART WHERE P_PARTKEY = L_PARTKEY AND P_BRAND = 'BRAND#44' AND P_CONTAINER = 'WRAP PKG' AND L_QUANTITY < ( SELECT 0.2 * AVG(L_QUANTITY) FROM LINEITEM WHERE L_PARTKEY = P_PARTKEY );
-- 21.sql1, performance improves by 1173.2289478709183%[cost_before=1333.58,after_cost=104.74]
Contributing indice:[SQLLAB_IDX1621082330, SQLLAB_IDX1003493942, SQLLAB_IDX1416165687, IDX_LINEITEM_ORDERKEY, SQLLAB_IDX0538538531]
SELECT S_NAME, COUNT(*) AS NUMWAIT FROM SUPPLIER, LINEITEM L1, ORDERS, NATION WHERE S_SUPPKEY = L1.L_SUPPKEY AND O_ORDERKEY = L1.L_ORDERKEY AND O_ORDERSTATUS = 'F' AND L1.L_RECEIPTDATE > L1.L_COMMITDATE AND EXISTS ( SELECT * FROM LINEITEM L2 WHERE L2.L_ORDERKEY = L1.L_ORDERKEY AND L2.L_SUPPKEY <> L1.L_SUPPKEY ) AND NOT EXISTS ( SELECT * FROM LINEITEM L3 WHERE L3.L_ORDERKEY = L1.L_ORDERKEY AND L3.L_SUPPKEY <> L1.L_SUPPKEY AND L3.L_RECEIPTDATE > L3.L_COMMITDATE ) AND S_NATIONKEY = N_NATIONKEY AND N_NAME = 'EGYPT' GROUP BY S_NAME ORDER BY NUMWAIT DESC, S_NAME LIMIT 100;
-- 7.sql1, performance improves by 3877.8084714548804%[cost_before=863.98,after_cost=21.72]
Contributing indice:[SQLLAB_IDX1264424863, SQLLAB_IDX1409884827, SQLLAB_IDX1017563074, CUSTOMER_PKEY, SQLLAB_IDX1640274034, SQLLAB_IDX1640274034]
SELECT SUPP_NATION, CUST_NATION, L_YEAR, SUM(VOLUME) AS REVENUE FROM ( SELECT N1.N_NAME AS SUPP_NATION, N2.N_NAME AS CUST_NATION, EXTRACT(YEAR FROM L_SHIPDATE) AS L_YEAR, L_EXTENDEDPRICE * (1 - L_DISCOUNT) AS VOLUME FROM SUPPLIER, LINEITEM, ORDERS, CUSTOMER, NATION N1, NATION N2 WHERE S_SUPPKEY = L_SUPPKEY AND O_ORDERKEY = L_ORDERKEY AND C_CUSTKEY = O_CUSTKEY AND S_NATIONKEY = N1.N_NATIONKEY AND C_NATIONKEY = N2.N_NATIONKEY AND ( (N1.N_NAME = 'JAPAN' AND N2.N_NAME = 'INDIA') OR (N1.N_NAME = 'INDIA' AND N2.N_NAME = 'JAPAN') ) AND L_SHIPDATE BETWEEN DATE '1995-01-01' AND DATE '1996-12-31' ) AS SHIPPING GROUP BY SUPP_NATION, CUST_NATION, L_YEAR ORDER BY SUPP_NATION, CUST_NATION, L_YEAR;
...
怎么样?大家赶紧用起来吧。PawSQL专注数据库性能优化,后续将陆续介绍Paw Index Advisor的内部实现原理,有兴趣的小伙伴请扫描下面的二维码关注PawSQL公众号, 或是查看Paw Index Advisor的主页https://ia.pawsql.com.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)