当前位置:网站首页>第一篇 热身--隐式类型转换还是其他?
第一篇 热身--隐式类型转换还是其他?
2022-06-22 18:24:00 【老虎刘】
前几天,有个给运营商做维护的DBA小陈问:
刘老师,我这个SQL不能使用索引,你帮我确认一下,是不是遇到了“隐式类型转换”?然后发了一个执行计划的最后部分给我看:
Peeked Binds (identified by position):
--------------------------------------
1 - :V1 (VARCHAR2(30), CSID=852): '4000874'
2 - :V2 (VARCHAR2(30), CSID=852): '4000874'
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter(("RATABLE_RESOURCE_ID"=TO_NUMBER(:V1) OR "TRANSFER_RESOURCE_ID"=TO_NUMBER(:V2)))
我说没错,确实是有隐式类型转换。但是,这个隐式类型转换却是“无害”的,因为如果字段是number类型,绑定变量是varchar2类型,这种隐式类型转换是不会影响SQL执行计划的。而如果字段是varchar2类型,绑定变量是number类型,这种才是最危险的。
小陈接下来发了完整的SQL,并告知第一个谓词条件字段(红色)上有主键:
SELECT
......
FROM hss.tb_bil_ratable_resource
WHERE ratable_resource_id = '4000874' OR transfer_resource_id = '4000874';
我一看SQL,马上就明白是什么原因了:这个SQL如果要想使用索引,必须还要创建另一个谓词条件字段(transfer_resource_id)上的索引。
小陈创建完索引后很快就发消息说搞定了!
解释:
因为两个谓词条件之间的关系是OR,而不是通常见到的AND,如果是AND,不用创建另一个字段上的索引就可以使用已经存在的主键索引。
总结:
这个SQL虽然非常简单,但是如果没有理解OR和AND的区别,还是会比较迷惑。而且客户之前被隐式类型转换折腾过几次,这次发现一个,可惜却不是根因。
边栏推荐
- shell脚本详解(十)——sed编辑器的使用方法
- Follow up course supplement of little turtle teacher "take you to learn C and take you to fly"
- Openpnp使用过程的一些问题记录
- Pat a 1093 count Pat's (25 points)
- shell脚本详解(二)——条件测试、if语句和case分支语句
- 84.(cesium篇)cesium模型在地形上运动
- 给对象赋值
- Take the file name in the zip package
- Digital business cloud: build a digital supply chain system to enable enterprises to optimize and upgrade their logistics supply chain
- About Random Forest
猜你喜欢

NLP-D57-nlp比赛D26&刷题D13&读论文&&找了一个多小时bug

Solution of off grid pin in Altium Designer

K8s deploy MySQL

Focal and global knowledge distillation for detectors
![Programmer's tool encyclopedia [continuous update]](/img/7e/b7fbc030f4bbded3ee6188360d7d54.png)
Programmer's tool encyclopedia [continuous update]

Flutter series - build a flutter development environment

Altium Designer中off grid pin解决方法

Experiment 7 trigger

1.2-----机械设计工具(CAD软件)和硬件设计工具(EDA软件)及对比

shell脚本详解(七)——正则表达式、sort、uniq、tr
随机推荐
canvas给图片画框框
通过base64下载文件(将base64转为blob)
Velocity syntax
antd tree 树状选择器 子类必填
Message Oriented Middleware (I) MQ explanation and comparison of four MQS
Ts as const
C WinForm embedded flash
Chapter I 100 hot questions (1-5)
远程访问及控制——SSH远程管理及TCP Wrappers 访问控制
[dry goods | necessary skills for interface testing common interface protocol analysis]
Problems of different renderers running on the web with flutter2.0
Fault analysis | from data_ Free exception
In the first half of the year, there were 7 new unicorns in this field, and the capital scrambled to enter the market
Human Pose Estimation浅述
YARN笔记
DIV横向布局
下拉刷新及上拉加载更多的ListView
Activereports report practical application tutorial (19) -- multi data source binding
1.3----- simple setting of 3D slicing software
[nfs无法挂载问题] mount.nfs: access denied by server while mounting localhost:/data/dev/mysql