当前位置:网站首页>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
边栏推荐
- 【StoneDB Class】Introduction Lesson 2: Analysis of the Overall Architecture of StoneDB
- SQL函数 %SQLUPPER
- AI目标分割能力,无需绿幕即可实现快速视频抠图
- iframe标签属性说明 详解[通俗易懂]
- Visualization of lag correlation of two time series data in R language: use the ccf function of the forecast package to draw the cross-correlation function, and analyze the lag correlation according t
- 批量任务导入到数据库中
- 【StoneDB Class】入门第二课:StoneDB 整体架构解析
- LeetCode_动态规划_中等_377.组合总和 Ⅳ
- markdown常用数学符号cov(markdown求和符号)
- 高仿项目协作工具【Worktile】,从零带你一步步实现组织架构、网盘、消息、项目、审批等功能
猜你喜欢

力扣160题,相交链表

Based on 10 years of experience in stability assurance, what are the three key questions to be answered in failure recovery?|TakinTalks big coffee sharing

芝加哥丰田技术学院 | Leveraging Natural Supervision for Language Representation Learning and Generation(利用自然监督进行语言表示学习和生成)

程序员的自我修养

找出相同属性值的对象 累加数量 汇总

数字孪生北京故宫,元宇宙推进旅游业进程

Data Mining-04

华盛顿大学、Allen AI 等联合 | RealTime QA: What's the Answer Right Now?(实时 QA:现在的答案是什么?)

【StoneDB Class】Introduction Lesson 2: Analysis of the Overall Architecture of StoneDB

让程序员早点下班的效率工具
随机推荐
测试发文
数据湖 delta lake和spark版本对应关系
How to Integrate Your Service Registry with Istio?
态路小课堂丨浅谈优质光模块需要具备的条件!
NebulaGraph v3.2.0 性能报告
观察者模式
安全又省钱,“15岁”老小区用上管道燃气
Istio Meetup China: Full Stack Service Mesh - Aeraki Helps You Manage Any Layer 7 Traffic in an Istio Service Mesh
How do we do full-link grayscale on the database?
STM32 CAN过滤器配置详解
win10系统重装,无法登录进行同步的情况下chrome数据恢复
MySQL调优
postgresql之page分配管理(一)
How to successfully pass the CKA exam?
Envoy source code flow chart
什么是一致性哈希?可以应用在哪些场景?
芝加哥丰田技术学院 | Leveraging Natural Supervision for Language Representation Learning and Generation(利用自然监督进行语言表示学习和生成)
华盛顿大学、Allen AI 等联合 | RealTime QA: What's the Answer Right Now?(实时 QA:现在的答案是什么?)
库函数的模拟实现(strlen)(strcpy)(strcat)(strcmp)(strstr)(memcpy)(memmove)(C语言)(VS)
Aeraki Mesh became CNCF sandbox project