1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL>
SQL> alter session set nls_date_format='DD/MM/YYYY';
Session modifiee.
SQL>
SQL> drop table t2;
Table supprimee.
SQL> drop table t1;
Table supprimee.
SQL>
SQL> create table t1
2 as select level x, to_char(rownum) c, level*2 x2, level*3 x3,
3 case when level <= 1600 then to_date('01/01/2007')
4 else to_date('01/01/2006') end d1,
5 case when level <= 1600 then to_date('01/01/2007')
6 else to_date('01/01/2006') end d2
7 from dual connect by level <= 150000;
Table creee.
SQL>
SQL> alter table t1 add primary key(x);
Table modifiee.
SQL>
SQL> create table t2 as select * from t1 where 1=0;
Table creee.
SQL> alter table t2 add primary key(x);
Table modifiee.
SQL>
SQL> select count(*) from
2 (
3 select *
4 from t1, t2
5 where t1.x = t2.x(+)
6 and nvl(t2.d2, t1.d1) >= '01/01/2007'
7 and nvl(t2.d2, t1.d1) < '01/02/2007'
8 );
COUNT(*)
----------
1600
SQL>
SQL>
SQL> exec dbms_stats.gather_table_stats(ownname => 'O', tabname=> 'T1', cascade => TRUE);
Procedure PL/SQL terminee avec succes.
SQL> exec dbms_stats.gather_table_stats(ownname => 'O', tabname=> 'T2', cascade => TRUE);
Procedure PL/SQL terminee avec succes.
SQL>
SQL> create or replace function f(p number) return number
2 as
3 begin
4 dbms_application_info.set_client_info( userenv('client_info')+1 );
5 if (p <=1600 )
6 then
7 return 0;
8 else
9 return 1;
10 end if;
11 end;
12 /
Fonction creee.
SQL>
SQL>
SQL> exec dbms_application_info.set_client_info(0);
Procedure PL/SQL terminee avec succes.
SQL> select count(*) from
2 (
3 select *
4 from t1, t2
5 where t1.x = t2.x(+)
6 and nvl(t2.d2, t1.d1) >= '01/01/2007'
7 and nvl(t2.d2, t1.d1) < '01/02/2007'
8 and f(t1.x) = 0
9 );
COUNT(*)
----------
1600
SQL> select userenv('client_info' ) from dual;
USERENV('CLIENT_INFO')
----------------------------------------------------------------
150000
SQL>
SQL> exec dbms_application_info.set_client_info(0);
Procedure PL/SQL terminee avec succes.
SQL> select count(*) from
2 (
3 select /*+ materialize */ t1.x x1, t2.x x2
4 from t1, t2
5 where t1.x = t2.x(+)
6 and nvl(t2.d2, t1.d1) >= '01/01/2007'
7 and nvl(t2.d2, t1.d1) < '01/02/2007'
8 ) t3
9 where f(t3.x1) = 0
10 ;
COUNT(*)
----------
1600
SQL> select userenv('client_info' ) from dual;
USERENV('CLIENT_INFO')
----------------------------------------------------------------
150000
SQL>
SQL> exec dbms_application_info.set_client_info(0);
Procedure PL/SQL terminee avec succes.
SQL> select count(*) from
2 (
3 select /*+ no_merge */ t1.x x1, t2.x x2
4 from t1, t2
5 where t1.x = t2.x(+)
6 and nvl(t2.d2, t1.d1) >= '01/01/2007'
7 and nvl(t2.d2, t1.d1) < '01/02/2007'
8 ) t3
9 where f(t3.x1) = 0
10 ;
COUNT(*)
----------
1600
SQL> select userenv('client_info' ) from dual;
USERENV('CLIENT_INFO')
----------------------------------------------------------------
1600 |
Partager