一、
上午的时候看到oracle逻辑存储结构,有一句话说:system sysaux表空间和临时表空间中
块大小必须为DB_BLOCK_SIZE。然后就先以为从数据字典中查,-_-|||
select *
from dba_tab_columns d
where d.COLUMN_NAME='DB_BLOCK_SIZE'
然后想到参数 就用show parameters在sqlplus中试了下。
还有spfile,我之前一直不知道在哪= =
show parameters db_block_size
show parameters spfile
------块大小应该是不好改,原因在于块是最小的存储单位,如果改,那么底层存储可能会存在某些块不可用。
一般的情况下块大小和操作系统块的几倍大小。不过,单位DB都是8K,默认的大小。
二、
下午时候公司一个小盆友问:
select *
from tablename
where id+0=221
-------中的+0是什么意思?
只记得和索引有关,之前看过,但是忘记了。所以就记下来吧。
强制不走字段ID上的索引。
然后查了下具体:
强制索引失效以及更有效的使用索引
http://space.itpub.net/13177610/viewspace-676346
那么自己简单测试一下 加强记忆。。。
SET AUTOTRACE OFF ---------------- 不生成AUTOTRACE 报告,这是缺省模式
SET AUTOTRACE ON EXPLAIN ------ AUTOTRACE只显示优化器执行路径报告
SET AUTOTRACE ON STATISTICS -- 只显示执行统计信息
SET AUTOTRACE ON ----------------- 包含执行计划和统计信息
SET AUTOTRACE TRACEONLY ------ 同set autotrace on,但是不显示查询输出
下次还是换pl/sql吧
①避免在索引列上使用计算(确实会导致索引失效)
SQL> SELECT *
2 FROM JOBS
3 WHERE
JOB_ID='WOR'
4
/
Plan hash value:
3348418524
|
Id |
Operation
| Name |
Rows | Bytes | Cost (%CPU)|
Time
|
---------------------------------------------------------------------------------------
| 0 | SELECT
STATEMENT
|
|
1 | 13
|
1 (0)| 00:00:01
|
| 1 | TABLE
ACCESS BY INDEX ROWID|
JOBS
|
1 | 13
|
1 (0)| 00:00:01
|
|* 2 |
INDEX UNIQUE
SCAN
| JOBS_PK
|
1
|
|
0 (0)| 00:00:01
|
---------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
1 SELECT *
2 FROM JOBS
3* WHERE
JOB_ID||''='WOR'
执行计划
----------------------------------------------------------
Plan hash value:
944056911
--------------------------------------------------------------------------
| Id |
Operation
| Name | Rows | Bytes | Cost (%CPU)|
Time
|
--------------------------------------------------------------------------
| 0 | SELECT
STATEMENT
|
|
1 | 13
|
3 (0)| 00:00:01
|
|* 1 | TABLE ACCESS
FULL| JOBS
|
1 | 13
|
3 (0)| 00:00:01
|
--------------------------------------------------------------------------
1 select count(*)
2 from test_case
3* where id1+0=0
--------------------------------------------------------------------------------
| Id |
Operation
|
Name
| Rows | Bytes | Cost (%CPU)|
Time
|
--------------------------------------------------------------------------------
| 0 | SELECT
STATEMENT
|
|
1
|
3
|
3 (0)| 00:00:01
|
| 1 | SORT
AGGREGATE
|
|
1
|
3
|
|
|
|* 2 |
TABLE ACCESS FULL| TEST_CASE
|
1
|
3
|
3 (0)| 00:00:01
| --------------------------------------------------------------------------------
1 select count(*)
2 from test_case
3* where id1=0+0
----------------------------------------------------------------------------------
| Id |
Operation
|
Name
| Rows | Bytes | Cost (%CPU)|
Time
|
----------------------------------------------------------------------------------
| 0 | SELECT
STATEMENT
|
|
1
|
3
|
1 (0)| 00:00:01
|
| 1 | SORT
AGGREGATE
|
|
1
|
3
|
|
|
|* 2
| INDEX RANGE
SCAN| IDX_INTERGER
|
1
|
3
|
1 (0)| 00:00:01
|
----------------------------------------------------------------------------------
②避免在索引列上使用not(测试结果与文中描述不符)
SQL> select count(*)
2 from test_case
3 where id1 is not
null
4 /
执行计划
----------------------------------------------------------
Plan hash value:
594955771
---------------------------------------------------------------------------------
| Id |
Operation
|
Name
| Rows | Bytes | Cost (%CPU)|
Time
|
---------------------------------------------------------------------------------
| 0 | SELECT STATEMENT
|
|
1
|
3
|
1 (0)| 00:00:01
|
| 1 | SORT
AGGREGATE
|
|
1
|
3
|
|
|
|* 2 |
INDEX FULL SCAN| IDX_INTERGER
|
8 | 24
|
1 (0)| 00:00:01
|
---------------------------------------------------------------------------------
SQL>
select count(*)
2 from test_case
3 where id1 not
in(0,1,2)
4
/
执行计划
----------------------------------------------------------
Plan hash value:
594955771
---------------------------------------------------------------------------------
| Id |
Operation
|
Name
| Rows | Bytes | Cost (%CPU)|
Time
|
---------------------------------------------------------------------------------
| 0 | SELECT STATEMENT
|
|
1
|
3
|
1 (0)| 00:00:01
|
| 1 | SORT
AGGREGATE
|
|
1
|
3
|
|
|
|* 2
| INDEX FULL SCAN|
IDX_INTERGER
|
5 | 15
|
1 (0)| 00:00:01
|
---------------------------------------------------------------------------------
SQL> select count(*)
2 from test_case
3 where
id1<>0
4 /
执行计划
----------------------------------------------------------
Plan hash value:
594955771
---------------------------------------------------------------------------------
| Id |
Operation
|
Name
| Rows | Bytes | Cost (%CPU)|
Time
|
---------------------------------------------------------------------------------
| 0 | SELECT STATEMENT
|
|
1
|
3
|
1 (0)| 00:00:01
|
| 1 | SORT
AGGREGATE
|
|
1
|
3
|
|
|
|* 2
| INDEX FULL SCAN|
IDX_INTERGER
|
7 | 21
|
1 (0)| 00:00:01
|
---------------------------------------------------------------------------------
③用>=替代>(有待考证)
1 select count(*)
2 from test_case
3* where
id1>4
----------------------------------------------------------------------------------
| Id |
Operation
|
Name
| Rows | Bytes | Cost (%CPU)|
Time
|
----------------------------------------------------------------------------------
| 0 | SELECT
STATEMENT
|
|
1
|
3
|
1 (0)| 00:00:01
|
| 1 | SORT
AGGREGATE
|
|
1
|
3
|
|
|
|* 2 | INDEX
RANGE SCAN| IDX_INTERGER
|
5
|
15
|
1 (0)| 00:00:01
|
----------------------------------------------------------------------------------
1 select count(*)
2 from test_case
3* where
id1>=5
----------------------------------------------------------------------------------
| Id |
Operation
|
Name
| Rows | Bytes | Cost (%CPU)|
Time
|
----------------------------------------------------------------------------------
| 0 | SELECT
STATEMENT
|
|
1
|
3
|
1 (0)| 00:00:01
|
| 1 | SORT
AGGREGATE
|
|
1
|
3
|
|
|
|* 2 | INDEX
RANGE SCAN| IDX_INTERGER
|
6 |
18
|
1 (0)| 00:00:01
|
----------------------------------------------------------------------------------
不知道是测试错了 还是 有问题。。。
三、强制使用索引
有别名就要使用别名。
SELECT ......