组函数会忽略null值

SQL> select distinct id from abc;

ID


1

2

4

SQL> select count( distinct id ) from abc;

COUNT(DISTINCTID)


3

SQL> select count(id) from abc;

COUNT(ID)


3

SQL> select count(*) from abc;

COUNT(*)


5

SQL> select *from abc;

ID NAME


1 asdf

2 sdfa

sdfa

4 fdas

asdf

SQL>

hint被忽略

如果CBO认为使用hint会导致错误的结果时,hint将被忽略,详见下例SQL> select /*+ index(t t_ind) */ count(*) from t;

Execution Plan


Plan hash value: 2966233522


| Id | Operation | Name | Rows | Cost (%CPU)| Time |


| 0 | SELECT STATEMENT | | 1 | 57 (2)| 00:00:01 |

| 1 | SORT AGGREGATE | | 1 | | |

| 2 | TABLE ACCESS FULL| T | 50366 | 57 (2)| 00:00:01 |


因为我们是对记录求总数,且我们并没有在建立索引时指定不能为空,索引如果CBO选择在索引上进行count时,但索引字段上的值为空时,结果将不准确,故CBO没有选择索引。 SQL> select /*+ index(t t_ind) */ count(id) from t;

Execution Plan


Plan hash value: 646498162


| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |


| 0 | SELECT STATEMENT | | 1 | 5 | 285 (1)| 00:00:04 |

| 1 | SORT AGGREGATE | | 1 | 5 | | |

| 2 | INDEX FULL SCAN| T_IND | 50366 | 245K| 285 (1)| 00:00:04 |


因为我们只对id进行count,这个动作相当于count索引上的所有id值,这个操作和对表上的id字段进行count是一样的(组函数会忽略null值)

/*+ INDEX_JOIN(TABLE INDEX_NAME1 INDEX_NAME2) */

当谓词中引用的列都有索引的时候,可以通过指定采用索引关联的方式,来访问数据select /*+ index_join(t t_ind t_bm) */ id from t where id=100 and object_name='EMPLOYEES'

/*+ no_use_nl(table_1,table_2) */在多表关联查询中,指定不使用nest loops方式进行多表关联。

select /*+ no_use_nl(t,t1) */ t.* from t,t1 where t.id=t1.id;

/*+ no_use_hash(table_1,table_2) */在多表关联查询中,指定不使用hash join方式进行多表关联。

select /*+ no_use_hash(t,t1) */ t.* from t,t1 where t.id=t1.id;

/*+ no_use_merge(table_1,table_2) */在多表关联查询中,指定不使用merge join方式进行多表关联。

select /*+ no_use_merge(t,t1) */ t.* from t,t1 where t.id=t1.id;

/*+ dynamic_sampling(table_name n) */

设置sql执行时动态采用的级别,这个级别为0~10select /*+ dynamic_sampling(t 4) */ * from t where id > 1234

NL_AJ

Use an anti-join in a sub-query. (depricated in Oracle 10g)

相关推荐
徐子元竟然被占了!!1 天前
Linux-systemctl
linux·数据库·oracle
Spring AI学习1 天前
Spring AI深度解析(9/50):可观测性与监控体系实战
java·人工智能·spring
java1234_小锋1 天前
Spring IoC的实现机制是什么?
java·后端·spring
YJlio1 天前
Active Directory 工具学习笔记(10.8):AdInsight——保存与导出(证据留存、共享与二次分析)
数据库·笔记·学习
suoyue_zhan1 天前
GBase的管理监控平台GEM实践指南
数据库
xqqxqxxq1 天前
背单词软件技术笔记(V2.0扩展版)
java·笔记·python
消失的旧时光-19431 天前
深入理解 Java 线程池(二):ThreadPoolExecutor 执行流程 + 运行状态 + ctl 原理全解析
java·开发语言
哈哈老师啊1 天前
Springboot学生综合测评系统hxtne(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
java·数据库·spring boot
4311媒体网1 天前
帝国cms调用文章内容 二开基本操作
java·开发语言·php