[20180625]10g下查询条件rownum = 0.txt

简介: [20180625]10g下查询条件rownum = 0.txt SCOTT@test> @ &r/ver1 PORT_STRING                    VERSION        BANNER --------------------...

[20180625]10g下查询条件rownum = 0.txt

SCOTT@test> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- ----------------------------------------------------------------
x86_64/Linux 2.4.xx            10.2.0.4.0     Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

SCOTT@test> alter session set statistics_level=all;
Session altered.

SCOTT@test> select * from emp where rownum = 0;
no rows selected

SCOTT@test> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  9cqutphfzqcdr, child number 1
-------------------------------------
select * from emp where rownum = 0
Plan hash value: 2063368778
----------------------------------------------------------------------------------------------------------------------
| Id  | Operation           | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time   | A-Rows |   A-Time   | Buffers |
----------------------------------------------------------------------------------------------------------------------
|   1 |  COUNT              |      |      1 |        |       |            |          |      0 |00:00:00.01 |       7 |
|*  2 |   FILTER            |      |      1 |        |       |            |          |      0 |00:00:00.01 |       7 |
|   3 |    TABLE ACCESS FULL| EMP  |      1 |     14 |   518 |     3   (0)| 00:00:01 |     14 |00:00:00.01 |       7 |
----------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1
   3 - SEL$1 / EMP@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
   2 - filter(ROWNUM=0)
25 rows selected.

--//可以发现实际上真实做的是全表扫描,逻辑读7,采用的是filter.
--//可以发现这个是一个bug,结果大量的逻辑读.可以在11g重复测试:

SCOTT@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

SCOTT@book> alter session set statistics_level=all;
Session altered.

SCOTT@book> select * from emp where rownum = 0;
no rows selected

SCOTT@book> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  9cqutphfzqcdr, child number 0
-------------------------------------
select * from emp where rownum = 0
Plan hash value: 1973284518
-----------------------------------------------------------------------------------------------------------
| Id  | Operation          | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time   | A-Rows |   A-Time   |
-----------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      |      1 |        |       |     2 (100)|          |      0 |00:00:00.01 |
|*  1 |  COUNT STOPKEY     |      |      1 |        |       |            |          |      0 |00:00:00.01 |
|   2 |   TABLE ACCESS FULL| EMP  |      1 |      1 |    38 |     2   (0)| 00:00:01 |      0 |00:00:00.01 |
-----------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1
   2 - SEL$1 / EMP@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter(ROWNUM=0)
25 rows selected.

--//这里逻辑读是0,A-rows=0(id=2),也说明没有做全表扫描.

目录
相关文章
|
SQL 关系型数据库 MySQL
第3章_基本select语句
第3章_基本select语句
67 0
|
SQL
在sql 里嵌套查询时,查询条件带有instr时报错
在sql 里嵌套查询时,查询条件带有instr时报错
120 1
|
SQL 存储 前端开发
第03章_基本的SELECT语句
第03章_基本的SELECT语句
219 1
|
存储 SQL 缓存
SQL优化实战-0002:select查询不建议使用星号(select *),最好指定具体查询字段
SQL优化实战-0002:select查询不建议使用星号(select *),最好指定具体查询字段
303 0
|
SQL 存储 关系型数据库
03_基本的SELECT语句
03_基本的SELECT语句
97 0
|
SQL Java 数据库连接
SELECT操作
SELECT操作
77 0
Select 查询数据语句
Select 查询数据语句
186 0
SELECT 语句中的 子查询(Sub Query)
SELECT 语句中的子查询 子查询(Sub Query)或者说内查询(Inner Query),也可以称作嵌套查询(Nested Query),是一种嵌套在其他 SQL 查询的 WHERE 子句中的查询。
1274 0
|
关系型数据库 MySQL 数据库
select distinct去掉重复查询结果|学习笔记
快速学习select distinct去掉重复查询结果
265 0