当前位置:文档之家› SQL优化和SQLMap开发规范

SQL优化和SQLMap开发规范

SQLREVIEW工具介绍及调优技 巧
Tips and tools for creating and presenting wide format slides
大纲

SQLReview介绍

工具介绍 流程

数据库调优基础



负载模型 数据的获取方式 执行计划和优化器 OLTP 优化重点


分清压力负载是调优的前提
鱼和熊掌不能兼得

OLTP(Transaction)
面向互联网用户 每笔交易少量数据的改变 每秒多少笔交易,多少并发

数据的获取方式
全表(FULL
TABLE SCAN)
分区(Partition) 分表(Sharding) 并行(Parallel)
索引查找(INDEX)
Widescreen Advantages
Side
by side material fits more naturally. Widescreen adds drama to graphics and images.
Widescreen Graphics
East West North16x9
Widescreen Test Pattern (16:9)
Aspect Ratio Test
(Should appear circular)
4x3 16x9
Widescreen Test Pattern (16:9)
Aspect Ratio Test
3rd Qtr
4th Qtr
Widescreen Pictures
Pictures can also be presented more dramatically in widescreen.
Slide Show Tips




To present in true widescreen, you‟ll need a computer and, optionally, a projector or flat panel that can output widescreen resolutions. Common computer widescreen resolutions are 1280 x 800 and 1440 x 900. (These are 16:10 aspect ratio, but will work well with 16:9 projectors and screens.) Standard high definition televisions resolutions are1280 x 720 and 1920 x 1080. Use the Test Pattern on the next slide to verify your slide show settings.
SQLReview 工具介绍
帮助架构师、DBA、开发
可以做到

快速Review
增量对比 自动分析SQLMAP拼接SQL 执行计划的自动获取 拼接出最准确的SQL 老SQL可能成为漏网之鱼
不能做到

SQLReview 工具介绍

执行计划



如何获取、计算数据 同样的SQL可能有多个执行计划 复杂的SQL不稳定
Even a single graphic, such as a chart, can be presented more dramatically in widescreen.
45.9 38.6 30.6 20.4 27.4
46.9 34.6
45 31.6 20.4
43.9
1st Qtr
2nd Qtr
SQL和SQLMAP

不好的SQL写法 SQLMAP编写注意点
SQLReview 工具介绍
帮助架构师、DBA、开发
可以做到

快速Review
增量对比SQLMAP的变化 自动分析SQLMAP拼接SQL 执行计划的自动获取 拼接出最准确的SQL 老SQL可能成为漏网之鱼
不能做到

SQLReview 流程改变
开发发起SQL
Review申请,DBA、架构师 Review
REVIEW通过才可以发布上线 REVIEW不通过,需要修改后再REVIEW
REG
tag 对应的SQL Review必须完成
JAVA代码可变更、SQLMAP不再变更 所有SQLMAP文件的MD5之和
类型不明确,隐式转换 标量子查询在返回列上


太多的表关联

复杂业务排序 NULL 作为主条件

… … where PARENT_ID is NULL
SQLMAP编写注意点(1)
这不是JAVA,不要切分太多模块相互组合拼接

LIST-APP 的例子
SQLMAP编写注意点(2)
select count from iw_user usr <dynamic prepend="where"> <isNotEmpty prepend="AND" property="userId"> usr.iw_user_id = #userId:varchar# </isNotEmpty> <isNotEmpty prepend="AND" property="email"> usr.email = #email:varchar# </isNotEmpty> <isNotEmpty prepend="AND" property="certType"> usr.cert_type = #certType:varchar# </isNotEmpty> <isNotEmpty prepend="AND" property="certNo"> usr.cert_no = #certNo:varchar# </isNotEmpty> <isEmpty property="userId"> <isEmpty property="email"> <isEmpty property="certNo"> @query not allowed </isEmpty> </isEmpty> </isEmpty> </dynamic>
select * from products where product_status = :P_status ;

优化器

产生执行计划

数据分布 统计信息 参数设置 …….
哪个好?要看数据分布、业务场景
Widescreen Presentation
This template is formatted with a 16:9 “widescreen” aspect ratio. It‟s a great way to take advantage of laptops, televisions and projectors equipped with widescreen displays. Even if you do not have a widescreen display, you can still create and present 16:9 slides. PowerPoint‟s Slide Show always resizes your slides to fit any screen.
select * from products where product_status = :P_status ;

优化器

产生执行计划

数据分布 统计信息 参数设置 …….
哪个好?要看数据分布、业务场景
负载模型

OLAP(Analysis)
数据仓库、ODS 批量JOB 每秒多少处理GB的数据
(Should appear circular)
4x3 16x9
Widescreen Test Pattern (16:9)
Aspect Ratio Test
(Should appear circular)
4x3 16x9
SQLReview 工具介绍

执行计划



如何获取、计算数据 同样的SQL可能有多个执行计划 复杂的SQL不稳定
SQLMAP编写注意点(3)
数据更新必须修改
updated_at
update BD_CONTACTINFO set updated_at= SYSDATE <dynamic> ...... </dynamic> where ID = #id#
绝不使用
dynamic 标签动态拼接需要 join 的table 变量使用#VAL# 而不是 $VAL$
全动态条件拼接,毫无重点
select count from iw_user usr <dynamic prepend="where"> <isNotEmpty prepend="AND" property="userId"> usr.iw_user_id = #userId:varchar# </isNotEmpty> <isNotEmpty prepend="AND" property="email"> usr.email = #email:varchar# </isNotEmpty> <isNotEmpty prepend="AND" property="certType"> usr.cert_type = #certType:varchar# </isNotEmpty> <isNotEmpty prepend="AND" property="certNo"> usr.cert_no = #certNo:varchar# </isNotEmpty> </dynamic>
相关主题