- 最后登录
- 2013-11-14
- 在线时间
- 104 小时
- 威望
- 999
- 金钱
- 271
- 注册时间
- 2013-1-9
- 阅读权限
- 70
- 帖子
- 63
- 精华
- 0
- 积分
- 999
- UID
- 855
|
4#
发表于 2013-2-18 23:03:37
本帖最后由 Stone 于 2013-2-18 23:07 编辑
经过测试的结果才是正确的 :),我们经常说“眼见为实,耳听为虚”,不过很多时候,即使看见纸面上写的东东,也不要轻易相信,记得jonathan lewis有一句类似的话,忘记了原话咋说啦,找到了再分享过来 ;)- SQL> select * from v$version where rownum < 3;
- BANNER
- --------------------------------------------------------------------------------
- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
- PL/SQL Release 11.2.0.3.0 - Production
- SQL> select * from tab;
- TNAME TABTYPE CLUSTERID
- ------------------------------ ------- ----------
- T1 TABLE
- SQL>
- SQL> desc t1
- Name Null? Type
- ----------------------------------------- -------- ----------------------------
- OWNER VARCHAR2(30)
- OBJECT_NAME VARCHAR2(128)
- SUBOBJECT_NAME VARCHAR2(30)
- OBJECT_ID NUMBER
- DATA_OBJECT_ID NUMBER
- OBJECT_TYPE VARCHAR2(19)
- CREATED DATE
- LAST_DDL_TIME DATE
- TIMESTAMP VARCHAR2(19)
- STATUS VARCHAR2(7)
- TEMPORARY VARCHAR2(1)
- GENERATED VARCHAR2(1)
- SECONDARY VARCHAR2(1)
- NAMESPACE NUMBER
- EDITION_NAME VARCHAR2(30)
- SQL> create index idx_t1 on t1(OWNER);
- Index created.
- SQL> create view v_t1 as select * from t1;
- View created.
- SQL> set lines 130
- col OWNER for a20
- col OBJECT_NAME for a35
- select OWNER,OBJECT_NAME,OBJECT_TYPE,STATUS from dba_objects
- where OBJECT_NAME='&obj_name';SQL> SQL> SQL> 2
- Enter value for obj_name: V_T1
- old 2: where OBJECT_NAME='&obj_name'
- new 2: where OBJECT_NAME='V_T1'
- OWNER OBJECT_NAME OBJECT_TYPE STATUS
- -------------------- ----------------------------------- ------------------- -------
- STONE V_T1 VIEW VALID
- SQL> drop index idx_t1;
- Index dropped.
- SQL> select OWNER,OBJECT_NAME,OBJECT_TYPE,STATUS from dba_objects
- where OBJECT_NAME='&obj_name'; 2
- Enter value for obj_name: V_T1
- old 2: where OBJECT_NAME='&obj_name'
- new 2: where OBJECT_NAME='V_T1'
- OWNER OBJECT_NAME OBJECT_TYPE STATUS
- -------------------- ----------------------------------- ------------------- -------
- STONE V_T1 VIEW VALID
复制代码 其实这个问题很可能是10g早期或者以前的一些版本可能碰到的问题,但是Oracle10.2的这个文档(http://docs.oracle.com/cd/B19306_01/server.102/b14220/depend.htm)似乎并没有修正这个说法,11g肯定就没有这个问题啦 :)
不过来自wordpress的这篇文章也正是对这个问题的一个探究,看完后应该就清楚点儿啦。当然为了方便大家,就顺便贴过来啦。
http://srivenukadiyala.wordpress.com/2010/09/25/does-dropping-an-index-invalidate-all-objects-that-depend-on-the-underlying-table-including-views-packages-package-bodies-functions-and-procedures/
Invalidation of dependent code objects for dropping an index on the base table?
Filed under: Uncategorized — srivenu @ 10:21 am
“When you drop an index, Oracle invalidates all objects that depend on the underlying table, including views, packages, package bodies, functions, and procedures.”
This statement has been part of Oracle documentation since 9i doc (At least it wasn’t there in the same section in 8i doc)
I never thought for a minute that dropping an index would invalidate the code objects dependant on the underlying base table. That was till a couple of days back !
As part of tuning some sql, i was creating new indexes ones and dropping some old ones. All the index changes were on look-up tables. Even though it was on a production system, I thought that it wouldn’t impact anyone as the tables were small & static. How wrong & ignorant i was !
Next day i had been told that the end-users experienced an application freeze for around 6 minutes. On analysis it was found that the database faced several latch free events on shared pool & library cache and library cache pins. It was also noted that several code objects got invalid during that time and had undergone implicit recompilation. We had a DDL trigger at database level to capture all DDL changes. And the only DDL’s that we saw prior to the impact was the INDEX DROP. Some of my colleagues suggested that the INDEX drop has invalidated the procedures. I immediately rubbished their claim that an index drop would cause object invalidations.
To find the culprit, i decided to do some log mining. I was searching for the details of the session which invalidated the procs. I looked for SQL_REDO where the STATUS column in the OBJ$ table for the PROC object (OBJ#) was updated to a status of 5(invalid). I found out the session and after further analysis, i found that it was my session! I looked at all the SQL_REDO’s of my session and found that it had first updated the status of all the dependent procedures to an INVALID STATUS before executing the DROP INDEX statement. I immediately ran a quick test.
Create table X(a number);
Create index ix on X(a);
Create or replace procedure PX as
begin
delete from X where a=10;
end;
/
I dropped the index IX and checked for the status of PX. It was still VALID
On close observation i found out that the index i dropped during the issue was a FUNCTION-BASED index. So i repeated the test with a function-based index
Create table X(a number);
Create index ix on X(to_char(a));
Create or replace procedure PX as
begin
delete from X where a=10;
end;
/
I dropped the index IX and checked for the status of PX. It was now INVALID
So dependent code objects on a base table are only invalidated if you drop a Function-Based index on that table. (I did not check for other types). I raised an SR for fixing the documentation.
But this left me pondering the reason for this invalidation !
As a commentor has pointed out, the invalidation is no longer happening in 11g. I had infact raised a SR to get the Oracle documentation fixed
(SR 3-2143692451) |
|