当前位置:网站首页>sql is not null 优化(oracle语句索引优化)
sql is not null 优化(oracle语句索引优化)
2022-08-01 12:46:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
IS NULL的优化
优化方法: 通过nvl(字段i,j),将字段i中为空的数据转化为j,从而正常使用索引. 具体则是将条件 i is null 转化为 j = nvl(i,j); 数据量较大时转化is null 在所用oracle版本提升明显, 注意:使用时必须确保字段i的数据不包含j! 缺陷:字段i不能有值为j的数据 另外一种方式是将null包含到索引中
函数介绍: nvl(a,b,c,…) 当a为空时取b,当b为空取c,以此类推.
优化示例
--使用nvl函数的方式(不用添加索引,推荐)
select*from tab_i t where 1=nvl(t.col_x,1);
--当t.col_x不存在等于1的数据时等价于
--select*from tab_i t where t.col_x is null;
--添加索引的方式
create index idx_col_x on tab_i(decode(col_x,null,1));
select*from tab_i t where decode(t.col_x,null,1)=1;IS NOT NULL的优化
优化方法 结果集不包含 j = nvl(i,j)即可,方式多样. 通常情况下可以使用not exists或者比较大小, 这两种效率一般高于比较长度
优化示例
- not exists
select*from tab_i t where not exists
(select 1 form tab_i i where 1=nvl(i.col_x,1));
--11g版本后not in和not exists趋于相似,也可以用not in
--当t.col_x不存在等于1的数据时等价于
--select*from tab_i t where t.col_x is not null;- 比较大小
--当t.col_x为总是大于1的数值时
select*from tab_i t where 1<nvl(t.col_x,1);
--当t.col_x为总是小于1的数值时
select*from tab_i t where 1>nvl(t.col_x,1);
--直接比较大小,暗含了 IS NOT NULL
select*from tab_i t where t.col_x>1;- 比较长度
--当t.col_x的长度总是大于1时
select*from tab_i t where 2<=length(nvl(t.col_x,1));
--因为length函数的参数为空时,其结果为空,因而不能直接使用length函数发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/126517.html原文链接:https://javaforall.cn
边栏推荐
- Do wildcard SSL certificates not support multiple domains?
- Programmer's Romantic Tanabata
- Process sibling data into tree data
- tensorflow2.0 handwritten digit recognition (tensorflow handwriting recognition)
- SQL functions STR
- iframe标签属性说明 详解[通俗易懂]
- 嵌入式开发:创建和使用可移植类型的7个技巧
- Software designer test center summary (interior designer personal summary)
- How does the SAP ABAP OData service support the Create operation trial version
- Six Stones Programming: Problems must be faced, methods must be skillful, and functions that cannot be done well must be solved
猜你喜欢

8. SAP ABAP OData 服务如何支持创建(Create)操作

程序员的自我修养

嵌入式开发:创建和使用可移植类型的7个技巧

windows IDEA + PHP+xdebug 断点调试

《MySQL核心知识》第6章:查询语句

消息中间件解析 | 如何正确理解软件应用系统中关于系统通信的那些事?

leetcode:1201. 丑数 III【二分 + 数学 + 容斥原理】
![leetcode: 1201. Ugly Number III [Dichotomy + Mathematics + Inclusion and Exclusion Principle]](/img/44/bf1d9b9d85939e73bc44be2f9701e1.png)
leetcode: 1201. Ugly Number III [Dichotomy + Mathematics + Inclusion and Exclusion Principle]

shell 中的 分发系统 expect脚本 (传递参数、自动同步文件、指定host和要传输的文件、(构建文件分发系统)(命令批量执行))

Data frame and remote frame of CAN communication
随机推荐
8. SAP ABAP OData 服务如何支持创建(Create)操作
【StoneDB Class】入门第二课:StoneDB 整体架构解析
50W+小程序开发者背后的数据库降本增效实践
小程序插件如何帮助开发者受益?
Feign 从注册到调用原理分析
SQL函数 %SQLSTRING
How to get the address of WeChat video account (link address of WeChat public account)
Detailed explanation of table join
JMP Pro 16.0软件安装包下载及安装教程
What is MNIST (what does plist mean)
MarkDown公式指导手册
并发编程10大坑,你踩过几个?
Why does the maximum plus one equal the minimum
PanGu-Coder:函数级的代码生成模型
NebulaGraph v3.2.0 性能报告
字体反爬之好租
How do we do full-link grayscale on the database?
让程序员早点下班的效率工具
【面试高频题】难度 1.5/5,二分经典运用题
Grafana9.0发布,Prometheus和Loki查询生成器、全新导航、热图面板等新功能!