Saturday, July 6, 2013

Constraint validation in parallel - seems to be 11g new...

Just learnt something new in Oracle, while testing an application and it seems to be a new behavior introduced with Oracle 11g and not see in previous versions. Here is a demo of it.

I am on 11.2.0.1 and big_table has around 10M record sets.

rajesh@ORA11G> alter table big_table parallel 4;

Table altered.

rajesh@ORA11G> alter session enable parallel dml;

Session altered.

rajesh@ORA11G> exec dbms_application_info.set_client_info('VALIDATE_CONSTRAINT');

PL/SQL procedure successfully completed.

rajesh@ORA11G> alter table big_table
  2  modify id constraint id_not_null
  3  not null novalidate ;

Table altered.

So just preserved the constraint metadata in data dictionary but not validated it.

rajesh@ORA11G> alter table big_table
  2  modify constraint id_not_null
  3  validate;

while this statement runs, monitored this session from different terminal and seems validation happening in parallel.

rajesh@ORA11G> l
  1  select sid,serial#,event,sql_id,
  2    ( select distinct sql_text from v$sql t1 where t1.sql_id = t2.sql_id ) sql_text,t2.last_call_et
  3  from gv$session t2
  4* where client_info='VALIDATE_CONSTRAINT'
rajesh@ORA11G> /
       SID    SERIAL# EVENT                SQL_ID        SQL_TEXT             LAST_CALL_ET
---------- ---------- -------------------- ------------- -------------------- ------------
        18        335 direct path read     dt1u018kpcbpy  select /*+ all_rows           10
        21        890 PX Deq: Execute Repl dt1u018kpcbpy  select /*+ all_rows           10
        22        923 direct path read     dt1u018kpcbpy  select /*+ all_rows           10
       143        814 direct path read     dt1u018kpcbpy  select /*+ all_rows           10

4 rows selected.

but when the same test case repeated on 10.2.0.5 on Linux I don't see any parallel validations.

rajesh@ORA10G> alter table big_table modify id null;

Table altered.

rajesh@ORA10G> alter table big_table noparallel;

Table altered.

rajesh@ORA10G> alter table big_table parallel 4;

Table altered.

rajesh@ORA10G> alter session enable parallel dml;

Session altered.

rajesh@ORA10G> exec dbms_application_info.set_client_info('VALIDATE_CONSTRAINT');

PL/SQL procedure successfully completed.

rajesh@ORA10G> alter table big_table
  2  modify id constraint id_not_null
  3  not null novalidate ;

Table altered.

rajesh@ORA10G> alter table big_table
  2  modify constraint id_not_null
  3  validate;

now, this running gv$session show's me this. (no parallel validation happening)

rajesh@ORA10G> select sid,serial#,event,sql_id,
  2    ( select distinct sql_text from v$sql t1 where t1.sql_id = t2.sql_id ) sql_text,t2.last_call_et
  3  from gv$session t2
  4  where client_info='VALIDATE_CONSTRAINT' ;
       SID    SERIAL# EVENT                SQL_ID        SQL_TEXT             LAST_CALL_ET
---------- ---------- -------------------- ------------- -------------------- ------------
       294      57526 i/o slave wait       dxyabb2qfv82y                                30

1 row selected.

 

No comments:

Post a Comment