Main Page | Report this Page
Computers Forum Index  »  Computer - Databases - Oracle (Server)  »  performance issue after upgrade to oracle 11.2.0.1...
Page 1 of 3    Goto page 1, 2, 3  Next

performance issue after upgrade to oracle 11.2.0.1...

Author Message
lsllcm...
Posted: Tue Nov 03, 2009 3:29 pm
Guest
Hi All,

I have one performance issue after upgrade to oracle 11.2.0.1 linux 32
bit.

The optimizer always choose index of "order by column", not use index
of "where clause columns". Any comments are appreciated.

Below are three test cases:

Case 1: TEST on 11.2.0.1 DBs with ORDER BY ORDER BY gf_fee_apply_date
Result: Choose incorrect execution plan.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

SQL> set autotrace trace
SQL> set timing on
SQL>
SQL> variable spc varchar2(15);
SQL> variable bfd varchar2(40);
SQL> variable efd varchar2(40);
SQL> variable p1 varchar2(60);
SQL> exec :spc:='SACRAMENTO';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :bfd:='2005-12-05';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.01
SQL> exec :efd:='2008-12-04 23:59:59';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :p1:='SET07%'

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL>
SQL> SELECT xfi.serv_prov_code,
2 xfi.b1_per_id1,
3 xfi.b1_per_id2,
4 xfi.b1_per_id3,
5 xfi.feeitem_seq_nbr,
6 xfi.invoice_nbr,
7 xfi.gf_fee_period,
8 xfi.gf_fee,
9 xfi.gf_des,
10 xfi.gf_unit,
11 xfi.gf_udes,
12 finv.invoice_date AS gf_fee_apply_date,
13 xfi.feeitem_invoice_status,
14 xfi.gf_l1,
15 xfi.gf_l2,
16 xfi.gf_l3,
17 xfi.x4feeitem_invoice_udf1,
18 xfi.x4feeitem_invoice_udf2,
19 xfi.x4feeitem_invoice_udf3,
20 xfi.x4feeitem_invoice_udf4,
21 xfi.gf_fee_schedule,
22 xfi.fee_schedule_version,
23 xfi.rec_date,
24 xfi.rec_ful_nam,
25 xfi.rec_status,
26 f4.GF_COD,
27 f4.GF_PRIORITY
28 FROM x4feeitem_invoice xfi, setdetails sd, f4invoice finv,
F4FEEITEM f4
29 WHERE sd.serv_prov_code = xfi.serv_prov_code
30 AND sd.b1_per_id1 = xfi.b1_per_id1
31 AND sd.b1_per_id2 = xfi.b1_per_id2
32 AND sd.b1_per_id3 = xfi.b1_per_id3
33 AND xfi.serv_prov_code = f4.serv_prov_code
34 AND xfi.b1_per_id1 = f4.b1_per_id1
35 AND xfi.b1_per_id2 = f4.b1_per_id2
36 AND xfi.b1_per_id3 = f4.b1_per_id3
37 And xfi.feeitem_seq_nbr = f4.feeitem_seq_nbr
38 AND finv.serv_prov_code = xfi.serv_prov_code
39 AND finv.invoice_nbr = xfi.invoice_nbr
40 AND sd.serv_prov_code = :spc
41 AND upper(sd.set_id) = :p1
42 AND xfi.rec_status = 'A'
43 AND xfi.feeitem_invoice_status = 'INVOICED'
44 ORDER BY gf_fee_apply_date
45 /

no rows selected

Elapsed: 00:02:15.28

Execution Plan
----------------------------------------------------------
Plan hash value: 3748720781

--------------------------------------------------------------------------------
----------------------------

| Id | Operation | Name |
Rows | Byt
es | Cost (%CPU)| Time |

--------------------------------------------------------------------------------
----------------------------

| 0 | SELECT STATEMENT | |
103 | 242
05 | 9 (0)| 00:00:01 |

| 1 | NESTED LOOPS |
| |
| | |

| 2 | NESTED LOOPS | |
103 | 242
05 | 9 (0)| 00:00:01 |

| 3 | NESTED LOOPS |
| 3 | 5
79 | 8 (0)| 00:00:01 |

| 4 | NESTED LOOPS |
| 39 | 60
45 | 4 (0)| 00:00:01 |

| 5 | TABLE ACCESS BY INDEX ROWID| F4INVOICE |
60771 | 14
24K| 1 (0)| 00:00:01 |

|* 6 | INDEX RANGE SCAN | F4INVOICE_DATE_IX
| 27 |
| 1 (0)| 00:00:01 |

|* 7 | TABLE ACCESS BY INDEX ROWID| X4FEEITEM_INVOICE
| 1 | 1
31 | 1 (0)| 00:00:01 |

|* 8 | INDEX RANGE SCAN | X4FEEITEM_INVOICE_NBR_IX
| 1 |
| 1 (0)| 00:00:01 |

|* 9 | TABLE ACCESS BY INDEX ROWID | SETDETAILS
| 1 |
38 | 1 (0)| 00:00:01 |

|* 10 | INDEX RANGE SCAN | SETDETAILS_PID_IX
| 1 |
| 1 (0)| 00:00:01 |

|* 11 | INDEX UNIQUE SCAN | F4FEEITEM_PK
| 1 |
| 1 (0)| 00:00:01 |

| 12 | TABLE ACCESS BY INDEX ROWID | F4FEEITEM
| 34 | 14
28 | 1 (0)| 00:00:01 |

--------------------------------------------------------------------------------
----------------------------


Predicate Information (identified by operation id):
---------------------------------------------------

6 - access("FINV"."SERV_PROV_CODE"=:SPC)
7 - filter("XFI"."FEEITEM_INVOICE_STATUS"='INVOICED' AND
"XFI"."REC_STATUS"='
A')

8 - access("XFI"."SERV_PROV_CODE"=:SPC AND
"FINV"."INVOICE_NBR"="XFI"."INVOIC
E_NBR")

9 - filter(UPPER("SET_ID")=Razz1)
10 - access("SD"."SERV_PROV_CODE"=:SPC AND
"SD"."B1_PER_ID1"="XFI"."B1_PER_ID1
" AND

"SD"."B1_PER_ID2"="XFI"."B1_PER_ID2" AND
"SD"."B1_PER_ID3"="XFI"."
B1_PER_ID3")

11 - access("F4"."SERV_PROV_CODE"=:SPC AND
"XFI"."B1_PER_ID1"="F4"."B1_PER_ID1
" AND

"XFI"."B1_PER_ID2"="F4"."B1_PER_ID2" AND
"XFI"."B1_PER_ID3"="F4"."
B1_PER_ID3" AND

"XFI"."FEEITEM_SEQ_NBR"="F4"."FEEITEM_SEQ_NBR")


Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
2891740 consistent gets
25708 physical reads
0 redo size
1763 bytes sent via SQL*Net to client
380 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release
11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

2. Case 2: test on 11.2.0.1 without ORDER BY ORDER BY
gf_fee_apply_date
Result: Choose correct execution plan.

C:\>sqlplus accela/dbs at (no spam) dbs26 at (no spam) e:\tools\sql\test.sql

SQL*Plus: Release 10.2.0.4.0 - Production on Sat Oct 31 13:40:08 2009

Copyright (c) 1982, 2007, Oracle. All Rights Reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

SQL> set autotrace trace
SQL> set timing on
SQL>
SQL> variable spc varchar2(15);
SQL> variable bfd varchar2(40);
SQL> variable efd varchar2(40);
SQL> variable p1 varchar2(60);
SQL> exec :spc:='SACRAMENTO';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :bfd:='2005-12-05';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :efd:='2008-12-04 23:59:59';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :p1:='SET07%'

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL>
SQL> SELECT xfi.serv_prov_code,
2 xfi.b1_per_id1,
3 xfi.b1_per_id2,
4 xfi.b1_per_id3,
5 xfi.feeitem_seq_nbr,
6 xfi.invoice_nbr,
7 xfi.gf_fee_period,
8 xfi.gf_fee,
9 xfi.gf_des,
10 xfi.gf_unit,
11 xfi.gf_udes,
12 finv.invoice_date AS gf_fee_apply_date,
13 xfi.feeitem_invoice_status,
14 xfi.gf_l1,
15 xfi.gf_l2,
16 xfi.gf_l3,
17 xfi.x4feeitem_invoice_udf1,
18 xfi.x4feeitem_invoice_udf2,
19 xfi.x4feeitem_invoice_udf3,
20 xfi.x4feeitem_invoice_udf4,
21 xfi.gf_fee_schedule,
22 xfi.fee_schedule_version,
23 xfi.rec_date,
24 xfi.rec_ful_nam,
25 xfi.rec_status,
26 f4.GF_COD,
27 f4.GF_PRIORITY
28 FROM x4feeitem_invoice xfi, setdetails sd, f4invoice finv,
F4FEEITEM f4
29 WHERE sd.serv_prov_code = xfi.serv_prov_code
30 AND sd.b1_per_id1 = xfi.b1_per_id1
31 AND sd.b1_per_id2 = xfi.b1_per_id2
32 AND sd.b1_per_id3 = xfi.b1_per_id3
33 AND xfi.serv_prov_code = f4.serv_prov_code
34 AND xfi.b1_per_id1 = f4.b1_per_id1
35 AND xfi.b1_per_id2 = f4.b1_per_id2
36 AND xfi.b1_per_id3 = f4.b1_per_id3
37 And xfi.feeitem_seq_nbr = f4.feeitem_seq_nbr
38 AND finv.serv_prov_code = xfi.serv_prov_code
39 AND finv.invoice_nbr = xfi.invoice_nbr
40 AND sd.serv_prov_code = :spc
41 AND upper(sd.set_id) = :p1
42 AND xfi.rec_status = 'A'
43 AND xfi.feeitem_invoice_status = 'INVOICED'
44 -- ORDER BY gf_fee_apply_date
45 /

no rows selected

Elapsed: 00:00:00.06

Execution Plan
----------------------------------------------------------
Plan hash value: 1421766072

--------------------------------------------------------------------------------
----------------------------

| Id | Operation | Name |
Rows | Byt
es | Cost (%CPU)| Time |

--------------------------------------------------------------------------------
----------------------------

| 0 | SELECT STATEMENT | |
101 | 369
66 | 5 (20)| 00:00:01 |

| 1 | NESTED LOOPS |
| |
| | |

| 2 | NESTED LOOPS | |
101 | 369
66 | 5 (20)| 00:00:01 |

| 3 | NESTED LOOPS |
| 3 | 9
72 | 4 (25)| 00:00:01 |

|* 4 | HASH JOIN |
| 3 | 9
00 | 3 (34)| 00:00:01 |

| 5 | TABLE ACCESS BY INDEX ROWID| SETDETAILS |
107 | 40
66 | 1 (0)| 00:00:01 |

|* 6 | INDEX RANGE SCAN | SETDETAILS_SETID_IX |
107 |
| 1 (0)| 00:00:01 |

|* 7 | TABLE ACCESS BY INDEX ROWID| X4FEEITEM_INVOICE |
2680 | 3
42K| 1 (0)| 00:00:01 |

|* 8 | INDEX RANGE SCAN | X4FEEITEM_INVOICE_NBR_IX |
255K|
| 1 (0)| 00:00:01 |

| 9 | TABLE ACCESS BY INDEX ROWID | F4INVOICE
| 1 |
24 | 1 (0)| 00:00:01 |

|* 10 | INDEX UNIQUE SCAN | F4INVOICE_PK
| 1 |
| 1 (0)| 00:00:01 |

|* 11 | INDEX UNIQUE SCAN | F4FEEITEM_PK
| 1 |
| 1 (0)| 00:00:01 |

| 12 | TABLE ACCESS BY INDEX ROWID | F4FEEITEM
| 34 | 14
28 | 1 (0)| 00:00:01 |

--------------------------------------------------------------------------------
----------------------------


Predicate Information (identified by operation id):
---------------------------------------------------

4 - access("SD"."SERV_PROV_CODE"="XFI"."SERV_PROV_CODE" AND
"SD"."B1_PER_ID1"
="XFI"."B1_PER_ID1"

AND "SD"."B1_PER_ID2"="XFI"."B1_PER_ID2" AND
"SD"."B1_PER_ID3"="XF
I"."B1_PER_ID3")

6 - access("SD"."SERV_PROV_CODE"=:SPC AND UPPER("SET_ID")=Razz1)
7 - filter("XFI"."FEEITEM_INVOICE_STATUS"='INVOICED' AND
"XFI"."REC_STATUS"='
A')

8 - access("XFI"."SERV_PROV_CODE"=:SPC)
10 - access("FINV"."SERV_PROV_CODE"=:SPC AND
"FINV"."INVOICE_NBR"="XFI"."INVOI
CE_NBR")

11 - access("F4"."SERV_PROV_CODE"=:SPC AND
"XFI"."B1_PER_ID1"="F4"."B1_PER_ID1
" AND

"XFI"."B1_PER_ID2"="F4"."B1_PER_ID2" AND
"XFI"."B1_PER_ID3"="F4"."
B1_PER_ID3" AND

"XFI"."FEEITEM_SEQ_NBR"="F4"."FEEITEM_SEQ_NBR")


Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
3 physical reads
0 redo size
1763 bytes sent via SQL*Net to client
380 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release
11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

C:\>


3. Case 3: TEST on 11.1.0.6/10.2.0.4 DBs
Result: Choose correct execution plan.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

SQL> set autotrace trace
SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is
enabled
SP2-0611: Error enabling STATISTICS report
SQL> set timing on
SQL>
SQL> variable spc varchar2(15);
SQL> variable bfd varchar2(40);
SQL> variable efd varchar2(40);
SQL> variable p1 varchar2(60);
SQL> exec :spc:='SACRAMENTO';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.01
SQL> exec :bfd:='2005-12-05';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :efd:='2008-12-04 23:59:59';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.01
SQL> exec :p1:='SET07%'

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL>
SQL> SELECT xfi.serv_prov_code,
2 xfi.b1_per_id1,
3 xfi.b1_per_id2,
4 xfi.b1_per_id3,
5 xfi.feeitem_seq_nbr,
6 xfi.invoice_nbr,
7 xfi.gf_fee_period,
8 xfi.gf_fee,
9 xfi.gf_des,
10 xfi.gf_unit,
11 xfi.gf_udes,
12 finv.invoice_date AS gf_fee_apply_date,
13 xfi.feeitem_invoice_status,
14 xfi.gf_l1,
15 xfi.gf_l2,
16 xfi.gf_l3,
17 xfi.x4feeitem_invoice_udf1,
18 xfi.x4feeitem_invoice_udf2,
19 xfi.x4feeitem_invoice_udf3,
20 xfi.x4feeitem_invoice_udf4,
21 xfi.gf_fee_schedule,
22 xfi.fee_schedule_version,
23 xfi.rec_date,
24 xfi.rec_ful_nam,
25 xfi.rec_status,
26 f4.GF_COD,
27 f4.GF_PRIORITY
28 FROM x4feeitem_invoice xfi, setdetails sd, f4invoice finv,
F4FEEITEM f4
29 WHERE sd.serv_prov_code = xfi.serv_prov_code
30 AND sd.b1_per_id1 = xfi.b1_per_id1
31 AND sd.b1_per_id2 = xfi.b1_per_id2
32 AND sd.b1_per_id3 = xfi.b1_per_id3
33 AND xfi.serv_prov_code = f4.serv_prov_code
34 AND xfi.b1_per_id1 = f4.b1_per_id1
35 AND xfi.b1_per_id2 = f4.b1_per_id2
36 AND xfi.b1_per_id3 = f4.b1_per_id3
37 And xfi.feeitem_seq_nbr = f4.feeitem_seq_nbr
38 AND finv.serv_prov_code = xfi.serv_prov_code
39 AND finv.invoice_nbr = xfi.invoice_nbr
40 AND sd.serv_prov_code = :spc
41 AND upper(sd.set_id) = :p1
42 AND xfi.rec_status = 'A'
43 AND xfi.feeitem_invoice_status = 'INVOICED'
44 ORDER BY gf_fee_apply_date
45 /
Elapsed: 00:00:00.51

Execution Plan
----------------------------------------------------------
Plan hash value: 2996231674

--------------------------------------------------------------------------------
-------------------------

| Id | Operation | Name |
Rows | Bytes
| Cost (%CPU)| Time |

--------------------------------------------------------------------------------
-------------------------

| 0 | SELECT STATEMENT | |
417 | 90072
| 16 (13)| 00:00:01 |

| 1 | SORT ORDER BY | |
417 | 90072
| 16 (13)| 00:00:01 |

|* 2 | HASH JOIN | |
417 | 90072
| 15 (7)| 00:00:01 |

| 3 | NESTED LOOPS |
| |
| | |

| 4 | NESTED LOOPS | |
29 | 5626
| 11 (0)| 00:00:01 |

| 5 | NESTED LOOPS | |
3 | 441
| 8 (0)| 00:00:01 |

| 6 | TABLE ACCESS BY INDEX ROWID| SETDETAILS |
3 | 105
| 2 (0)| 00:00:01 |

|* 7 | INDEX RANGE SCAN | SETDETAILS_SETID_IX |
3 |
| 1 (0)| 00:00:01 |

|* 8 | TABLE ACCESS BY INDEX ROWID| X4FEEITEM_INVOICE |
1 | 112
| 2 (0)| 00:00:01 |

|* 9 | INDEX RANGE SCAN | X4FEEITEM_INVOICE_PK |
1 |
| 1 (0)| 00:00:01 |

|* 10 | INDEX UNIQUE SCAN | F4FEEITEM_PK |
1 |
| 0 (0)| 00:00:01 |

| 11 | TABLE ACCESS BY INDEX ROWID | F4FEEITEM |
10 | 470
| 1 (0)| 00:00:01 |

| 12 | TABLE ACCESS BY INDEX ROWID | F4INVOICE |
9453 | 203K
| 3 (0)| 00:00:01 |

|* 13 | INDEX RANGE SCAN | F4INVOICE_DATE_IX |
9453 |
| 2 (0)| 00:00:01 |

--------------------------------------------------------------------------------
-------------------------


Predicate Information (identified by operation id):
---------------------------------------------------

2 - access("FINV"."SERV_PROV_CODE"="XFI"."SERV_PROV_CODE" AND
"FINV"."INVOICE_NBR"="XFI"."INVOICE_NBR")
7 - access("SD"."SERV_PROV_CODE"=:SPC AND UPPER("SET_ID")=Razz1)
8 - filter("XFI"."FEEITEM_INVOICE_STATUS"='INVOICED' AND
"XFI"."REC_STATUS"='
A')

9 - access("XFI"."SERV_PROV_CODE"=:SPC AND
"SD"."B1_PER_ID1"="XFI"."B1_PER_ID
1" AND

"SD"."B1_PER_ID2"="XFI"."B1_PER_ID2" AND
"SD"."B1_PER_ID3"="XFI"."
B1_PER_ID3")

10 - access("F4"."SERV_PROV_CODE"=:SPC AND
"XFI"."B1_PER_ID1"="F4"."B1_PER_ID1
" AND

"XFI"."B1_PER_ID2"="F4"."B1_PER_ID2" AND
"XFI"."B1_PER_ID3"="F4"."
B1_PER_ID3" AND

"XFI"."FEEITEM_SEQ_NBR"="F4"."FEEITEM_SEQ_NBR")
13 - access("FINV"."SERV_PROV_CODE"=:SPC)

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options
 
ddf...
Posted: Tue Nov 03, 2009 3:58 pm
Guest
On Nov 3, 9:29 am, lsllcm <lsl... at (no spam) gmail.com> wrote:
Quote:
Hi All,

I have one performance issue after upgrade to oracle 11.2.0.1 linux 32
bit.

The optimizer always choose index of "order by column", not use index
of "where clause columns". Any comments are appreciated.

Below are three test cases:

Case 1: TEST on 11.2.0.1 DBs with ORDER BY ORDER BY gf_fee_apply_date
Result: Choose incorrect execution plan.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

SQL> set autotrace trace
SQL> set timing on
SQL
SQL> variable spc varchar2(15);
SQL> variable bfd varchar2(40);
SQL> variable efd varchar2(40);
SQL> variable p1 varchar2(60);
SQL> exec :spc:='SACRAMENTO';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :bfd:='2005-12-05';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.01
SQL> exec :efd:='2008-12-04 23:59:59';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :p1:='SET07%'

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL
SQL> SELECT xfi.serv_prov_code,
  2         xfi.b1_per_id1,
  3         xfi.b1_per_id2,
  4         xfi.b1_per_id3,
  5         xfi.feeitem_seq_nbr,
  6         xfi.invoice_nbr,
  7         xfi.gf_fee_period,
  8         xfi.gf_fee,
  9         xfi.gf_des,
 10         xfi.gf_unit,
 11         xfi.gf_udes,
 12         finv.invoice_date AS gf_fee_apply_date,
 13         xfi.feeitem_invoice_status,
 14         xfi.gf_l1,
 15         xfi.gf_l2,
 16         xfi.gf_l3,
 17         xfi.x4feeitem_invoice_udf1,
 18         xfi.x4feeitem_invoice_udf2,
 19         xfi.x4feeitem_invoice_udf3,
 20         xfi.x4feeitem_invoice_udf4,
 21         xfi.gf_fee_schedule,
 22         xfi.fee_schedule_version,
 23         xfi.rec_date,
 24         xfi.rec_ful_nam,
 25         xfi.rec_status,
 26         f4.GF_COD,
 27         f4.GF_PRIORITY
 28    FROM x4feeitem_invoice xfi, setdetails sd, f4invoice finv,
F4FEEITEM f4
 29   WHERE sd.serv_prov_code = xfi.serv_prov_code
 30     AND sd.b1_per_id1 = xfi.b1_per_id1
 31     AND sd.b1_per_id2 = xfi.b1_per_id2
 32     AND sd.b1_per_id3 = xfi.b1_per_id3
 33     AND xfi.serv_prov_code = f4.serv_prov_code
 34     AND xfi.b1_per_id1 = f4.b1_per_id1
 35     AND xfi.b1_per_id2 = f4.b1_per_id2
 36     AND xfi.b1_per_id3 = f4.b1_per_id3
 37     And xfi.feeitem_seq_nbr = f4.feeitem_seq_nbr
 38     AND finv.serv_prov_code = xfi.serv_prov_code
 39     AND finv.invoice_nbr = xfi.invoice_nbr
 40     AND sd.serv_prov_code = :spc
 41     AND upper(sd.set_id) = :p1
 42     AND xfi.rec_status = 'A'
 43     AND xfi.feeitem_invoice_status = 'INVOICED'
 44   ORDER BY gf_fee_apply_date
 45  /

no rows selected

Elapsed: 00:02:15.28

Execution Plan
----------------------------------------------------------
Plan hash value: 3748720781

---------------------------------------------------------------------------­-----
----------------------------

| Id  | Operation                       | Name                     |
Rows  | Byt
es | Cost (%CPU)| Time     |

---------------------------------------------------------------------------­-----
----------------------------

|   0 | SELECT STATEMENT                |                          |
103 | 242
05 |     9   (0)| 00:00:01 |

|   1 |  NESTED LOOPS                   |
|       |
   |            |          |

|   2 |   NESTED LOOPS                  |                          |
103 | 242
05 |     9   (0)| 00:00:01 |

|   3 |    NESTED LOOPS                 |
|     3 |   5
79 |     8   (0)| 00:00:01 |

|   4 |     NESTED LOOPS                |
|    39 |  60
45 |     4   (0)| 00:00:01 |

|   5 |      TABLE ACCESS BY INDEX ROWID| F4INVOICE                |
60771 |  14
24K|     1   (0)| 00:00:01 |

|*  6 |       INDEX RANGE SCAN          | F4INVOICE_DATE_IX
|    27 |
   |     1   (0)| 00:00:01 |

|*  7 |      TABLE ACCESS BY INDEX ROWID| X4FEEITEM_INVOICE
|     1 |   1
31 |     1   (0)| 00:00:01 |

|*  8 |       INDEX RANGE SCAN          | X4FEEITEM_INVOICE_NBR_IX
|     1 |
   |     1   (0)| 00:00:01 |

|*  9 |     TABLE ACCESS BY INDEX ROWID | SETDETAILS
|     1 |
38 |     1   (0)| 00:00:01 |

|* 10 |      INDEX RANGE SCAN           | SETDETAILS_PID_IX
|     1 |
   |     1   (0)| 00:00:01 |

|* 11 |    INDEX UNIQUE SCAN            | F4FEEITEM_PK
|     1 |
   |     1   (0)| 00:00:01 |

|  12 |   TABLE ACCESS BY INDEX ROWID   | F4FEEITEM
|    34 |  14
28 |     1   (0)| 00:00:01 |

---------------------------------------------------------------------------­-----
----------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   6 - access("FINV"."SERV_PROV_CODE"=:SPC)
   7 - filter("XFI"."FEEITEM_INVOICE_STATUS"='INVOICED' AND
"XFI"."REC_STATUS"='
A')

   8 - access("XFI"."SERV_PROV_CODE"=:SPC AND
"FINV"."INVOICE_NBR"="XFI"."INVOIC
E_NBR")

   9 - filter(UPPER("SET_ID")=Razz1)
  10 - access("SD"."SERV_PROV_CODE"=:SPC AND
"SD"."B1_PER_ID1"="XFI"."B1_PER_ID1
" AND

              "SD"."B1_PER_ID2"="XFI"."B1_PER_ID2" AND
"SD"."B1_PER_ID3"="XFI"."
B1_PER_ID3")

  11 - access("F4"."SERV_PROV_CODE"=:SPC AND
"XFI"."B1_PER_ID1"="F4"."B1_PER_ID1
" AND

              "XFI"."B1_PER_ID2"="F4"."B1_PER_ID2" AND
"XFI"."B1_PER_ID3"="F4"."
B1_PER_ID3" AND

              "XFI"."FEEITEM_SEQ_NBR"="F4"."FEEITEM_SEQ_NBR")

Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
    2891740  consistent gets
      25708  physical reads
          0  redo size
       1763  bytes sent via SQL*Net to client
        380  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
0       rows processed
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release
11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

2.      Case 2: test on 11.2.0.1 without ORDER BY ORDER BY
gf_fee_apply_date
Result: Choose correct execution plan.

C:\>sqlplus accela/dbs at (no spam) dbs26 at (no spam) e:\tools\sql\test.sql

SQL*Plus: Release 10.2.0.4.0 - Production on Sat Oct 31 13:40:08 2009

Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

SQL> set autotrace trace
SQL> set timing on
SQL
SQL> variable spc varchar2(15);
SQL> variable bfd varchar2(40);
SQL> variable efd varchar2(40);
SQL> variable p1 varchar2(60);
SQL> exec :spc:='SACRAMENTO';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :bfd:='2005-12-05';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :efd:='2008-12-04 23:59:59';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :p1:='SET07%'

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL
SQL> SELECT xfi.serv_prov_code,
  2         xfi.b1_per_id1,
  3         xfi.b1_per_id2,
  4         xfi.b1_per_id3,
  5         xfi.feeitem_seq_nbr,
  6         xfi.invoice_nbr,
  7         xfi.gf_fee_period,
  8         xfi.gf_fee,
  9         xfi.gf_des,
 10         xfi.gf_unit,
 11         xfi.gf_udes,
 12         finv.invoice_date AS gf_fee_apply_date,
 13         xfi.feeitem_invoice_status,
 14         xfi.gf_l1,
 15         xfi.gf_l2,
 16         xfi.gf_l3,
 17         xfi.x4feeitem_invoice_udf1,
 18         xfi.x4feeitem_invoice_udf2,
 19         xfi.x4feeitem_invoice_udf3,
 20         xfi.x4feeitem_invoice_udf4,
 21         xfi.gf_fee_schedule,
 22         xfi.fee_schedule_version,
 23         xfi.rec_date,
 24         xfi.rec_ful_nam,
 25         xfi.rec_status,
 26         f4.GF_COD,
 27         f4.GF_PRIORITY
 28    FROM x4feeitem_invoice xfi, setdetails sd, f4invoice finv,
F4FEEITEM f4
 29   WHERE sd.serv_prov_code = xfi.serv_prov_code
 30     AND sd.b1_per_id1 = xfi.b1_per_id1
 31     AND sd.b1_per_id2 = xfi.b1_per_id2
 32     AND sd.b1_per_id3 = xfi.b1_per_id3
 33     AND xfi.serv_prov_code = f4.serv_prov_code
 34     AND xfi.b1_per_id1 = f4.b1_per_id1
 35     AND xfi.b1_per_id2 = f4.b1_per_id2
 36     AND xfi.b1_per_id3 = f4.b1_per_id3
 37     And xfi.feeitem_seq_nbr = f4.feeitem_seq_nbr
 38     AND finv.serv_prov_code = xfi.serv_prov_code
 39     AND finv.invoice_nbr = xfi.invoice_nbr
 40     AND sd.serv_prov_code = :spc
 41     AND upper(sd.set_id) = :p1
 42     AND xfi.rec_status = 'A'
 43     AND xfi.feeitem_invoice_status = 'INVOICED'
 44  -- ORDER BY gf_fee_apply_date
 45  /

no rows selected

Elapsed: 00:00:00.06

Execution Plan
----------------------------------------------------------
Plan hash value: 1421766072

---------------------------------------------------------------------------­-----
----------------------------

| Id  | Operation                       | Name                     |
Rows  | Byt
es | Cost (%CPU)| Time     |

---------------------------------------------------------------------------­-----
----------------------------

|   0 | SELECT STATEMENT                |                          |
101 | 369
66 |     5  (20)| 00:00:01 |

|   1 |  NESTED LOOPS                   |
|       |
   |            |          |

|   2 |   NESTED LOOPS                  |                          |
101 | 369
66 |     5  (20)| 00:00:01 |

|   3 |    NESTED LOOPS                 |
|     3 |   9
72 |     4  (25)| 00:00:01 |

|*  4 |     HASH JOIN                   |
|     3 |   9
00 |     3  (34)| 00:00:01 |

|   5 |      TABLE ACCESS BY INDEX ROWID| SETDETAILS               |
107 |  40
66 |     1   (0)| 00:00:01 |

|*  6 |       INDEX RANGE SCAN          | SETDETAILS_SETID_IX      |
107 |
   |     1   (0)| 00:00:01 |

|*  7 |      TABLE ACCESS BY INDEX ROWID| X4FEEITEM_INVOICE        |
2680 |   3
42K|     1   (0)| 00:00:01 |

|*  8 |       INDEX RANGE SCAN          | X4FEEITEM_INVOICE_NBR_IX |
255K|
   |     1   (0)| 00:00:01 |

|   9 |     TABLE ACCESS BY INDEX ROWID | F4INVOICE
|     1 |
24 |     1   (0)| 00:00:01 |

|* 10 |      INDEX UNIQUE SCAN          | F4INVOICE_PK
|     1 |
   |     1   (0)| 00:00:01 |

|* 11 |    INDEX UNIQUE SCAN            | F4FEEITEM_PK
|     1 |
   |     1   (0)| 00:00:01 |

|  12 |   TABLE ACCESS BY INDEX ROWID   | F4FEEITEM
|    34 |  14
28 |     1   (0)| 00:00:01 |

---------------------------------------------------------------------------­-----
----------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   4 - access("SD"."SERV_PROV_CODE"="XFI"."SERV_PROV_CODE" AND
"SD"."B1_PER_ID1"
="XFI"."B1_PER_ID1"

              AND "SD"."B1_PER_ID2"="XFI"."B1_PER_ID2" AND
"SD"."B1_PER_ID3"="XF
I"."B1_PER_ID3")

   6 - access("SD"."SERV_PROV_CODE"=:SPC AND UPPER("SET_ID")=Razz1)
   7 - filter("XFI"."FEEITEM_INVOICE_STATUS"='INVOICED' AND
"XFI"."REC_STATUS"='
A')

   8 - access("XFI"."SERV_PROV_CODE"=:SPC)
  10 - access("FINV"."SERV_PROV_CODE"=:SPC AND
"FINV"."INVOICE_NBR"="XFI"."INVOI
CE_NBR")

  11 - access("F4"."SERV_PROV_CODE"=:SPC AND
"XFI"."B1_PER_ID1"="F4"."B1_PER_ID1
" AND

              "XFI"."B1_PER_ID2"="F4"."B1_PER_ID2" AND
"XFI"."B1_PER_ID3"="F4"."
B1_PER_ID3" AND

              "XFI"."FEEITEM_SEQ_NBR"="F4"."FEEITEM_SEQ_NBR")

Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
          3  consistent gets
          3  physical reads
          0  redo size
       1763  bytes sent via SQL*Net to client
        380  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          0  rows processed

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release
11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

C:\

3.      Case 3: TEST on 11.1.0.6/10.2.0.4 DBs
Result: Choose correct execution plan.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

SQL> set autotrace trace
SP2-0618: Cannot find the Session Identifier.  Check PLUSTRACE role is
enabled
SP2-0611: Error enabling STATISTICS report
SQL> set timing on
SQL
SQL> variable spc varchar2(15);
SQL> variable bfd varchar2(40);
SQL> variable efd varchar2(40);
SQL> variable p1 varchar2(60);
SQL> exec :spc:='SACRAMENTO';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.01
SQL> exec :bfd:='2005-12-05';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :efd:='2008-12-04 23:59:59';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.01
SQL> exec :p1:='SET07%'

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL
SQL> SELECT xfi.serv_prov_code,
  2         xfi.b1_per_id1,
  3         xfi.b1_per_id2,
  4         xfi.b1_per_id3,
  5         xfi.feeitem_seq_nbr,
  6         xfi.invoice_nbr,
  7         xfi.gf_fee_period,
  8         xfi.gf_fee,
  9         xfi.gf_des,
 10         xfi.gf_unit,
 11         xfi.gf_udes,
 12         finv.invoice_date AS gf_fee_apply_date,
 13         xfi.feeitem_invoice_status,
 14         xfi.gf_l1,
 15         xfi.gf_l2,
 16         xfi.gf_l3,
 17         xfi.x4feeitem_invoice_udf1,
 18         xfi.x4feeitem_invoice_udf2,
 19         xfi.x4feeitem_invoice_udf3,
 20         xfi.x4feeitem_invoice_udf4,
 21         xfi.gf_fee_schedule,
 22         xfi.fee_schedule_version,
 23         xfi.rec_date,
 24         xfi.rec_ful_nam,
 25         xfi.rec_status,
 26         f4.GF_COD,
 27         f4.GF_PRIORITY
 28    FROM x4feeitem_invoice xfi, setdetails sd, f4invoice finv,
F4FEEITEM f4
 29   WHERE sd.serv_prov_code = xfi.serv_prov_code
 30     AND sd.b1_per_id1 = xfi.b1_per_id1
 31     AND sd.b1_per_id2 = xfi.b1_per_id2
 32     AND sd.b1_per_id3 = xfi.b1_per_id3
 33     AND xfi.serv_prov_code = f4.serv_prov_code
 34     AND xfi.b1_per_id1 = f4.b1_per_id1
 35     AND xfi.b1_per_id2 = f4.b1_per_id2
 36     AND xfi.b1_per_id3 = f4.b1_per_id3
 37     And xfi.feeitem_seq_nbr = f4.feeitem_seq_nbr
 38     AND finv.serv_prov_code = xfi.serv_prov_code
 39     AND finv.invoice_nbr = xfi.invoice_nbr
 40     AND sd.serv_prov_code = :spc
 41     AND upper(sd.set_id) = :p1
 42     AND xfi.rec_status = 'A'
 43     AND xfi.feeitem_invoice_status = 'INVOICED'
 44   ORDER BY gf_fee_apply_date
 45  /
Elapsed: 00:00:00.51

Execution Plan
----------------------------------------------------------
Plan hash value: 2996231674

---------------------------------------------------------------------------­-----
-------------------------

| Id  | Operation                        | Name                 |
Rows  | Bytes
| Cost (%CPU)| Time     |

---------------------------------------------------------------------------­-----
-------------------------

|   0 | SELECT STATEMENT                 |                      |
417 | 90072
|    16  (13)| 00:00:01 |

|   1 |  SORT ORDER BY                   |                      |
417 | 90072
|    16  (13)| 00:00:01 |

|*  2 |   HASH JOIN                      |                      |
417 | 90072
|    15   (7)| 00:00:01 |

|   3 |    NESTED LOOPS                  |
|       |
|            |          |

|   4 |     NESTED LOOPS                 |                      |
29 |  5626
|    11   (0)| 00:00:01 |

|   5 |      NESTED LOOPS                |                      |
3 |   441
|     8   (0)| 00:00:01 |

|   6 |       TABLE ACCESS BY INDEX ROWID| SETDETAILS           |
3 |   105
|     2   (0)| 00:00:01 |

|*  7 |        INDEX RANGE SCAN          | SETDETAILS_SETID_IX  |
3 |
|     1   (0)| 00:00:01 |

|*  8 |       TABLE ACCESS BY INDEX ROWID| X4FEEITEM_INVOICE    |
1 |   112
|     2   (0)| 00:00:01 |

|*  9 |        INDEX RANGE SCAN          | X4FEEITEM_INVOICE_PK |
1 |
|     1   (0)| 00:00:01 |

|* 10 |      INDEX UNIQUE SCAN           | F4FEEITEM_PK         |
1 |
|     0   (0)| 00:00:01 |

|  11 |     TABLE ACCESS BY INDEX ROWID  | F4FEEITEM            |
10 |   470
|     1   (0)| 00:00:01 |

|  12 |    TABLE ACCESS BY INDEX ROWID   | F4INVOICE            |
9453 |   203K
|     3   (0)| 00:00:01 |

|* 13 |     INDEX RANGE SCAN             | F4INVOICE_DATE_IX    |
9453 |
|     2   (0)| 00:00:01 |

---------------------------------------------------------------------------­-----
-------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("FINV"."SERV_PROV_CODE"="XFI"."SERV_PROV_CODE" AND
              "FINV"."INVOICE_NBR"="XFI"."INVOICE_NBR")
   7 - access("SD"."SERV_PROV_CODE"=:SPC AND UPPER("SET_ID")=Razz1)
   8 - filter("XFI"."FEEITEM_INVOICE_STATUS"='INVOICED' AND
"XFI"."REC_STATUS"='
A')

   9 - access("XFI"."SERV_PROV_CODE"=:SPC AND
"SD"."B1_PER_ID1"="XFI"."B1_PER_ID
1" AND

              "SD"."B1_PER_ID2"="XFI"."B1_PER_ID2" AND
"SD"."B1_PER_ID3"="XFI"."
B1_PER_ID3")

  10 - access("F4"."SERV_PROV_CODE"=:SPC AND
"XFI"."B1_PER_ID1"="F4"."B1_PER_ID1
" AND

              "XFI"."B1_PER_ID2"="F4"."B1_PER_ID2" AND
"XFI"."B1_PER_ID3"="F4"."
B1_PER_ID3" AND

              "XFI"."FEEITEM_SEQ_NBR"="F4"."FEEITEM_SEQ_NBR")
  13 - access("FINV"."SERV_PROV_CODE"=:SPC)

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

Have you run an event 10053 trace to see what information the
optimizer is using to arrive at that decision?


David Fitzjarrell
 
Charles Hooper...
Posted: Tue Nov 03, 2009 4:22 pm
Guest
On Nov 3, 10:29 am, lsllcm <lsl... at (no spam) gmail.com> wrote:
Quote:
Hi All,

I have one performance issue after upgrade to oracle 11.2.0.1 linux 32
bit.

The optimizer always choose index of "order by column", not use index
of "where clause columns". Any comments are appreciated.

Below are three test cases:

Case 1: TEST on 11.2.0.1 DBs with ORDER BY ORDER BY gf_fee_apply_date
Result: Choose incorrect execution plan.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

SQL> set autotrace trace
SQL> set timing on
SQL
SQL> variable spc varchar2(15);
SQL> variable bfd varchar2(40);
SQL> variable efd varchar2(40);
SQL> variable p1 varchar2(60);
SQL> exec :spc:='SACRAMENTO';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :bfd:='2005-12-05';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.01
SQL> exec :efd:='2008-12-04 23:59:59';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :p1:='SET07%'

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL
SQL> SELECT xfi.serv_prov_code,
  2         xfi.b1_per_id1,
  3         xfi.b1_per_id2,
  4         xfi.b1_per_id3,
  5         xfi.feeitem_seq_nbr,
  6         xfi.invoice_nbr,
  7         xfi.gf_fee_period,
  8         xfi.gf_fee,
  9         xfi.gf_des,
 10         xfi.gf_unit,
 11         xfi.gf_udes,
 12         finv.invoice_date AS gf_fee_apply_date,
 13         xfi.feeitem_invoice_status,
 14         xfi.gf_l1,
 15         xfi.gf_l2,
 16         xfi.gf_l3,
 17         xfi.x4feeitem_invoice_udf1,
 18         xfi.x4feeitem_invoice_udf2,
 19         xfi.x4feeitem_invoice_udf3,
 20         xfi.x4feeitem_invoice_udf4,
 21         xfi.gf_fee_schedule,
 22         xfi.fee_schedule_version,
 23         xfi.rec_date,
 24         xfi.rec_ful_nam,
 25         xfi.rec_status,
 26         f4.GF_COD,
 27         f4.GF_PRIORITY
 28    FROM x4feeitem_invoice xfi, setdetails sd, f4invoice finv,
F4FEEITEM f4
 29   WHERE sd.serv_prov_code = xfi.serv_prov_code
 30     AND sd.b1_per_id1 = xfi.b1_per_id1
 31     AND sd.b1_per_id2 = xfi.b1_per_id2
 32     AND sd.b1_per_id3 = xfi.b1_per_id3
 33     AND xfi.serv_prov_code = f4.serv_prov_code
 34     AND xfi.b1_per_id1 = f4.b1_per_id1
 35     AND xfi.b1_per_id2 = f4.b1_per_id2
 36     AND xfi.b1_per_id3 = f4.b1_per_id3
 37     And xfi.feeitem_seq_nbr = f4.feeitem_seq_nbr
 38     AND finv.serv_prov_code = xfi.serv_prov_code
 39     AND finv.invoice_nbr = xfi.invoice_nbr
 40     AND sd.serv_prov_code = :spc
 41     AND upper(sd.set_id) = :p1
 42     AND xfi.rec_status = 'A'
 43     AND xfi.feeitem_invoice_status = 'INVOICED'
 44   ORDER BY gf_fee_apply_date
 45  /

no rows selected

Elapsed: 00:02:15.28

Execution Plan
----------------------------------------------------------
Plan hash value: 3748720781

---------------------------------------------------------------------------­-----
----------------------------

| Id  | Operation                       | Name                     |
Rows  | Byt
es | Cost (%CPU)| Time     |

---------------------------------------------------------------------------­-----
----------------------------

|   0 | SELECT STATEMENT                |                          |
103 | 242
05 |     9   (0)| 00:00:01 |

|   1 |  NESTED LOOPS                   |
|       |
   |            |          |

|   2 |   NESTED LOOPS                  |                          |
103 | 242
05 |     9   (0)| 00:00:01 |

|   3 |    NESTED LOOPS                 |
|     3 |   5
79 |     8   (0)| 00:00:01 |

|   4 |     NESTED LOOPS                |
|    39 |  60
45 |     4   (0)| 00:00:01 |

|   5 |      TABLE ACCESS BY INDEX ROWID| F4INVOICE                |
60771 |  14
24K|     1   (0)| 00:00:01 |

|*  6 |       INDEX RANGE SCAN          | F4INVOICE_DATE_IX
|    27 |
   |     1   (0)| 00:00:01 |

|*  7 |      TABLE ACCESS BY INDEX ROWID| X4FEEITEM_INVOICE
|     1 |   1
31 |     1   (0)| 00:00:01 |

|*  8 |       INDEX RANGE SCAN          | X4FEEITEM_INVOICE_NBR_IX
|     1 |
   |     1   (0)| 00:00:01 |

|*  9 |     TABLE ACCESS BY INDEX ROWID | SETDETAILS
|     1 |
38 |     1   (0)| 00:00:01 |

|* 10 |      INDEX RANGE SCAN           | SETDETAILS_PID_IX
|     1 |
   |     1   (0)| 00:00:01 |

|* 11 |    INDEX UNIQUE SCAN            | F4FEEITEM_PK
|     1 |
   |     1   (0)| 00:00:01 |

|  12 |   TABLE ACCESS BY INDEX ROWID   | F4FEEITEM
|    34 |  14
28 |     1   (0)| 00:00:01 |

---------------------------------------------------------------------------­-----
----------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   6 - access("FINV"."SERV_PROV_CODE"=:SPC)
   7 - filter("XFI"."FEEITEM_INVOICE_STATUS"='INVOICED' AND
"XFI"."REC_STATUS"='
A')

   8 - access("XFI"."SERV_PROV_CODE"=:SPC AND
"FINV"."INVOICE_NBR"="XFI"."INVOIC
E_NBR")

   9 - filter(UPPER("SET_ID")=Razz1)
  10 - access("SD"."SERV_PROV_CODE"=:SPC AND
"SD"."B1_PER_ID1"="XFI"."B1_PER_ID1
" AND

              "SD"."B1_PER_ID2"="XFI"."B1_PER_ID2" AND
"SD"."B1_PER_ID3"="XFI"."
B1_PER_ID3")

  11 - access("F4"."SERV_PROV_CODE"=:SPC AND
"XFI"."B1_PER_ID1"="F4"."B1_PER_ID1
" AND

              "XFI"."B1_PER_ID2"="F4"."B1_PER_ID2" AND
"XFI"."B1_PER_ID3"="F4"."
B1_PER_ID3" AND

              "XFI"."FEEITEM_SEQ_NBR"="F4"."FEEITEM_SEQ_NBR")

Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
    2891740  consistent gets
      25708  physical reads
          0  redo size
       1763  bytes sent via SQL*Net to client
        380  bytes received via SQL*Net from client
          1  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
0       rows processed
SQL> exit
(snip)


Autotrace may lie - it does not necessarily show the actual execution
plan. This is especially a problem when bind variables are used as
bind variable peeking does not happen, and all bind variables are
treated as VARCHAR2 type columns. To see the actual execution plan,
disable autotrace and include the hint /*+ GATHER_PLAN_STATISTICS
*/ immediately after the SELECT keyword. Then use the following to
display the actual execution plan with estimated and actual rows:
SELECT
*
FROM
TABLE (DBMS_XPLAN.DISPLAY_CURSOR(NULL,NULL,'ALLSTATS LAST'));

(If you do not use the hint, it is possible to specify NULL for the
last parameter to return the actual execution plan with just the
estimated cardinality and costs.)

Note the 2,891,740 consistent gets for the slow execution compared to
the 3 consistent gets with the "fast" execution without the ORDER BY
clause. It *could* very well be the case in the slow execution that a
previous execution used different bind variable values which were
"peeked" at, creating an appropriate execution plan for a query with a
large number of rows to be processed. By removing the ORDER BY
clause, you forced a hard parse of the SQL statement, which caused the
optimizer again to peek at the bind variables to determine a good
execution plan.

You will probably find on Oracle 11.1.0.6 and above that the optimizer
will eventually re-hard parse the SQL statement when it recognizes
that the execution plan should be bind variable sensitive - it might
take a couple executions of the SQL statement before the optimizer
switches to bind aware versions of the execution plans.

Note also that it is possible that the object statistics and optimizer
parameters (FIRST_ROWS_n, for example) differ between the Oracle
versions.

David's suggestion of a 10053 trace is a good one - just keep in mind
that such traces only appear during a hard parse.

Charles Hooper
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc.
 
joel garry...
Posted: Tue Nov 03, 2009 5:44 pm
Guest
On Nov 3, 8:22 am, Charles Hooper <hooperc2... at (no spam) yahoo.com> wrote:
Quote:
On Nov 3, 10:29 am, lsllcm <lsl... at (no spam) gmail.com> wrote:


Note also that it is possible that the object statistics and optimizer
parameters (FIRST_ROWS_n, for example) differ between the Oracle
versions.

David's suggestion of a 10053 trace is a good one - just keep in mind
that such traces only appear during a hard parse.

A bit of a stretch, but consider this: rownum is assigned after the
predicate is processed, but before sorting is done. "Bug 6438892 :
Suboptimal plan with ROWNUM predicate and NESTED LOOPS." is in the
11.1.0.6 patch set, bug not published. So maybe there is some
mysterious optimizer bug here, set off by the order by even though
rownum is not originally a predicate. Try patching beyond the base
release and see if the problem is still there.

jg
--
at (no spam) home.com is bogus.
Do not fart next to a cellphone. http://www.signonsandiego.com/news/2009/nov/02/wwwxconomycom48394/
 
Charles Hooper...
Posted: Tue Nov 03, 2009 6:11 pm
Guest
On Nov 3, 12:44 pm, joel garry <joel-ga... at (no spam) home.com> wrote:
Quote:
On Nov 3, 8:22 am, Charles Hooper <hooperc2... at (no spam) yahoo.com> wrote:

On Nov 3, 10:29 am, lsllcm <lsl... at (no spam) gmail.com> wrote:

Note also that it is possible that the object statistics and optimizer
parameters (FIRST_ROWS_n, for example) differ between the Oracle
versions.

David's suggestion of a 10053 trace is a good one - just keep in mind
that such traces only appear during a hard parse.

A bit of a stretch, but consider this:  rownum is assigned after the
predicate is processed, but before sorting is done.  "Bug 6438892 :
Suboptimal plan with ROWNUM predicate and NESTED LOOPS." is in the
11.1.0.6 patch set, bug not published.  So maybe there is some
mysterious optimizer bug here, set off by the order by even though
rownum is not originally a predicate.  Try patching beyond the base
release and see if the problem is still there.

jg
--

The OP is experiencing problems in 11.2.0.1, which does not exhibit
the ROWNUM bug that you mentioned, based on my testing. You might be
suggesting - what if the fix of that bug caused another bug?
Interesting, quite possible.

I noticed the large number of NESTED LOOPS in his posted plan also,
which is one of the reasons why I mentioned FIRST_ROWS_n
(OPTIMIZER_MODE). It might even be the case that the OPTIMIZER_MODE
is set to FIRST_ROWS (or maybe even CHOOSE), rather than FIRST_ROWS_1,
FIRST_ROWS_10, FIRST_ROWS_100, ALL_ROWS, etc.

lsllcm, please try setting OPTIMIZER_FEATURES_ENABLE to 11.1.0.6 in
Oracle 11.2.0.1 and re-execute the SQL statement - note that this will
force a hard parse. How does the performance compare? If the
performance is better, set OPTIMIZER_FEATURES_ENABLE to 11.2.0.1, add
a couple extra spaces in the SQL statement, and try your test again.
Is the performance the same as it was on 11.1.0.6 and 10.2.0.4?

Charles Hooper
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc.
 
Robert Klemme...
Posted: Tue Nov 03, 2009 9:07 pm
Guest
On 11/03/2009 04:58 PM, ddf wrote:

Quote:
Have you run an event 10053 trace to see what information the
optimizer is using to arrive at that decision?

And: are statistics (table, index and system) current?

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Mladen Gogala...
Posted: Tue Nov 03, 2009 11:19 pm
Guest
On Tue, 03 Nov 2009 07:29:46 -0800, lsllcm wrote:

Quote:
Hi All,

I have one performance issue after upgrade to oracle 11.2.0.1 linux 32
bit.

The optimizer always choose index of "order by column", not use index of
"where clause columns". Any comments are appreciated.

Below are three test cases:

Case 1: TEST on 11.2.0.1 DBs with ORDER BY ORDER BY gf_fee_apply_date
Result: Choose incorrect execution plan.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

SQL> set autotrace trace
SQL> set timing on
SQL
SQL> variable spc varchar2(15);
SQL> variable bfd varchar2(40);
SQL> variable efd varchar2(40);
SQL> variable p1 varchar2(60);
SQL> exec :spc:='SACRAMENTO';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :bfd:='2005-12-05';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.01
SQL> exec :efd:='2008-12-04 23:59:59';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :p1:='SET07%'

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL
SQL> SELECT xfi.serv_prov_code,
2 xfi.b1_per_id1,
3 xfi.b1_per_id2,
4 xfi.b1_per_id3,
5 xfi.feeitem_seq_nbr,
6 xfi.invoice_nbr,
7 xfi.gf_fee_period,
8 xfi.gf_fee,
9 xfi.gf_des,
10 xfi.gf_unit,
11 xfi.gf_udes,
12 finv.invoice_date AS gf_fee_apply_date, 13
xfi.feeitem_invoice_status, 14 xfi.gf_l1,
15 xfi.gf_l2,
16 xfi.gf_l3,
17 xfi.x4feeitem_invoice_udf1, 18
xfi.x4feeitem_invoice_udf2, 19 xfi.x4feeitem_invoice_udf3, 20
xfi.x4feeitem_invoice_udf4, 21 xfi.gf_fee_schedule,
22 xfi.fee_schedule_version,
23 xfi.rec_date,
24 xfi.rec_ful_nam,
25 xfi.rec_status,
26 f4.GF_COD,
27 f4.GF_PRIORITY
28 FROM x4feeitem_invoice xfi, setdetails sd, f4invoice finv,
F4FEEITEM f4
29 WHERE sd.serv_prov_code = xfi.serv_prov_code 30 AND
sd.b1_per_id1 = xfi.b1_per_id1 31 AND sd.b1_per_id2 =
xfi.b1_per_id2 32 AND sd.b1_per_id3 = xfi.b1_per_id3 33 AND
xfi.serv_prov_code = f4.serv_prov_code 34 AND xfi.b1_per_id1 =
f4.b1_per_id1 35 AND xfi.b1_per_id2 = f4.b1_per_id2 36 AND
xfi.b1_per_id3 = f4.b1_per_id3 37 And xfi.feeitem_seq_nbr =
f4.feeitem_seq_nbr 38 AND finv.serv_prov_code = xfi.serv_prov_code
39 AND finv.invoice_nbr = xfi.invoice_nbr 40 AND
sd.serv_prov_code = :spc
41 AND upper(sd.set_id) = :p1
42 AND xfi.rec_status = 'A'
43 AND xfi.feeitem_invoice_status = 'INVOICED' 44 ORDER BY
gf_fee_apply_date
45 /

no rows selected

Elapsed: 00:02:15.28

Execution Plan
---------------------------------------------------------- Plan hash
value: 3748720781


--------------------------------------------------------------------------------
----------------------------

| Id | Operation | Name |
Rows | Byt
es | Cost (%CPU)| Time |


--------------------------------------------------------------------------------
----------------------------

| 0 | SELECT STATEMENT | | 103
| 242
05 | 9 (0)| 00:00:01 |

| 1 | NESTED LOOPS | | |
| | |

| 2 | NESTED LOOPS | | 103
| 242
05 | 9 (0)| 00:00:01 |

| 3 | NESTED LOOPS | | 3 | 5
79 | 8 (0)| 00:00:01 |

| 4 | NESTED LOOPS | | 39 | 60
45 | 4 (0)| 00:00:01 |

| 5 | TABLE ACCESS BY INDEX ROWID| F4INVOICE |
60771 | 14
24K| 1 (0)| 00:00:01 |

|* 6 | INDEX RANGE SCAN | F4INVOICE_DATE_IX | 27 |
| 1 (0)| 00:00:01 |

|* 7 | TABLE ACCESS BY INDEX ROWID| X4FEEITEM_INVOICE | 1 |
1
31 | 1 (0)| 00:00:01 |

|* 8 | INDEX RANGE SCAN | X4FEEITEM_INVOICE_NBR_IX |
1 |
| 1 (0)| 00:00:01 |

|* 9 | TABLE ACCESS BY INDEX ROWID | SETDETAILS | 1 |
38 | 1 (0)| 00:00:01 |

|* 10 | INDEX RANGE SCAN | SETDETAILS_PID_IX | 1 |
| 1 (0)| 00:00:01 |

|* 11 | INDEX UNIQUE SCAN | F4FEEITEM_PK | 1 |
| 1 (0)| 00:00:01 |

| 12 | TABLE ACCESS BY INDEX ROWID | F4FEEITEM | 34 | 14
28 | 1 (0)| 00:00:01 |


--------------------------------------------------------------------------------
----------------------------


Predicate Information (identified by operation id):
---------------------------------------------------

6 - access("FINV"."SERV_PROV_CODE"=:SPC) 7 -
filter("XFI"."FEEITEM_INVOICE_STATUS"='INVOICED' AND
"XFI"."REC_STATUS"='
A')

8 - access("XFI"."SERV_PROV_CODE"=:SPC AND
"FINV"."INVOICE_NBR"="XFI"."INVOIC
E_NBR")

9 - filter(UPPER("SET_ID")=Razz1)
10 - access("SD"."SERV_PROV_CODE"=:SPC AND
"SD"."B1_PER_ID1"="XFI"."B1_PER_ID1
" AND

"SD"."B1_PER_ID2"="XFI"."B1_PER_ID2" AND
"SD"."B1_PER_ID3"="XFI"."
B1_PER_ID3")

11 - access("F4"."SERV_PROV_CODE"=:SPC AND
"XFI"."B1_PER_ID1"="F4"."B1_PER_ID1
" AND

"XFI"."B1_PER_ID2"="F4"."B1_PER_ID2" AND
"XFI"."B1_PER_ID3"="F4"."
B1_PER_ID3" AND

"XFI"."FEEITEM_SEQ_NBR"="F4"."FEEITEM_SEQ_NBR")


Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
2891740 consistent gets
25708 physical reads
0 redo size
1763 bytes sent via SQL*Net to client
380 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release
11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

2. Case 2: test on 11.2.0.1 without ORDER BY ORDER BY
gf_fee_apply_date
Result: Choose correct execution plan.

C:\>sqlplus accela/dbs at (no spam) dbs26 at (no spam) e:\tools\sql\test.sql

SQL*Plus: Release 10.2.0.4.0 - Production on Sat Oct 31 13:40:08 2009

Copyright (c) 1982, 2007, Oracle. All Rights Reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

SQL> set autotrace trace
SQL> set timing on
SQL
SQL> variable spc varchar2(15);
SQL> variable bfd varchar2(40);
SQL> variable efd varchar2(40);
SQL> variable p1 varchar2(60);
SQL> exec :spc:='SACRAMENTO';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :bfd:='2005-12-05';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :efd:='2008-12-04 23:59:59';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :p1:='SET07%'

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL
SQL> SELECT xfi.serv_prov_code,
2 xfi.b1_per_id1,
3 xfi.b1_per_id2,
4 xfi.b1_per_id3,
5 xfi.feeitem_seq_nbr,
6 xfi.invoice_nbr,
7 xfi.gf_fee_period,
8 xfi.gf_fee,
9 xfi.gf_des,
10 xfi.gf_unit,
11 xfi.gf_udes,
12 finv.invoice_date AS gf_fee_apply_date, 13
xfi.feeitem_invoice_status, 14 xfi.gf_l1,
15 xfi.gf_l2,
16 xfi.gf_l3,
17 xfi.x4feeitem_invoice_udf1, 18
xfi.x4feeitem_invoice_udf2, 19 xfi.x4feeitem_invoice_udf3, 20
xfi.x4feeitem_invoice_udf4, 21 xfi.gf_fee_schedule,
22 xfi.fee_schedule_version,
23 xfi.rec_date,
24 xfi.rec_ful_nam,
25 xfi.rec_status,
26 f4.GF_COD,
27 f4.GF_PRIORITY
28 FROM x4feeitem_invoice xfi, setdetails sd, f4invoice finv,
F4FEEITEM f4
29 WHERE sd.serv_prov_code = xfi.serv_prov_code 30 AND
sd.b1_per_id1 = xfi.b1_per_id1 31 AND sd.b1_per_id2 =
xfi.b1_per_id2 32 AND sd.b1_per_id3 = xfi.b1_per_id3 33 AND
xfi.serv_prov_code = f4.serv_prov_code 34 AND xfi.b1_per_id1 =
f4.b1_per_id1 35 AND xfi.b1_per_id2 = f4.b1_per_id2 36 AND
xfi.b1_per_id3 = f4.b1_per_id3 37 And xfi.feeitem_seq_nbr =
f4.feeitem_seq_nbr 38 AND finv.serv_prov_code = xfi.serv_prov_code
39 AND finv.invoice_nbr = xfi.invoice_nbr 40 AND
sd.serv_prov_code = :spc
41 AND upper(sd.set_id) = :p1
42 AND xfi.rec_status = 'A'
43 AND xfi.feeitem_invoice_status = 'INVOICED' 44 -- ORDER BY
gf_fee_apply_date
45 /

no rows selected

Elapsed: 00:00:00.06

Execution Plan
---------------------------------------------------------- Plan hash
value: 1421766072


--------------------------------------------------------------------------------
----------------------------

| Id | Operation | Name |
Rows | Byt
es | Cost (%CPU)| Time |


--------------------------------------------------------------------------------
----------------------------

| 0 | SELECT STATEMENT | | 101
| 369
66 | 5 (20)| 00:00:01 |

| 1 | NESTED LOOPS | | |
| | |

| 2 | NESTED LOOPS | | 101
| 369
66 | 5 (20)| 00:00:01 |

| 3 | NESTED LOOPS | | 3 | 9
72 | 4 (25)| 00:00:01 |

|* 4 | HASH JOIN | | 3 | 9
00 | 3 (34)| 00:00:01 |

| 5 | TABLE ACCESS BY INDEX ROWID| SETDETAILS | 107
| 40
66 | 1 (0)| 00:00:01 |

|* 6 | INDEX RANGE SCAN | SETDETAILS_SETID_IX | 107
|
| 1 (0)| 00:00:01 |

|* 7 | TABLE ACCESS BY INDEX ROWID| X4FEEITEM_INVOICE |
2680 | 3
42K| 1 (0)| 00:00:01 |

|* 8 | INDEX RANGE SCAN | X4FEEITEM_INVOICE_NBR_IX |
255K|
| 1 (0)| 00:00:01 |

| 9 | TABLE ACCESS BY INDEX ROWID | F4INVOICE | 1 |
24 | 1 (0)| 00:00:01 |

|* 10 | INDEX UNIQUE SCAN | F4INVOICE_PK | 1 |
| 1 (0)| 00:00:01 |

|* 11 | INDEX UNIQUE SCAN | F4FEEITEM_PK | 1 |
| 1 (0)| 00:00:01 |

| 12 | TABLE ACCESS BY INDEX ROWID | F4FEEITEM | 34 | 14
28 | 1 (0)| 00:00:01 |


--------------------------------------------------------------------------------
----------------------------


Predicate Information (identified by operation id):
---------------------------------------------------

4 - access("SD"."SERV_PROV_CODE"="XFI"."SERV_PROV_CODE" AND
"SD"."B1_PER_ID1"
="XFI"."B1_PER_ID1"

AND "SD"."B1_PER_ID2"="XFI"."B1_PER_ID2" AND
"SD"."B1_PER_ID3"="XF
I"."B1_PER_ID3")

6 - access("SD"."SERV_PROV_CODE"=:SPC AND UPPER("SET_ID")=Razz1) 7 -
filter("XFI"."FEEITEM_INVOICE_STATUS"='INVOICED' AND
"XFI"."REC_STATUS"='
A')

8 - access("XFI"."SERV_PROV_CODE"=:SPC)
10 - access("FINV"."SERV_PROV_CODE"=:SPC AND
"FINV"."INVOICE_NBR"="XFI"."INVOI
CE_NBR")

11 - access("F4"."SERV_PROV_CODE"=:SPC AND
"XFI"."B1_PER_ID1"="F4"."B1_PER_ID1
" AND

"XFI"."B1_PER_ID2"="F4"."B1_PER_ID2" AND
"XFI"."B1_PER_ID3"="F4"."
B1_PER_ID3" AND

"XFI"."FEEITEM_SEQ_NBR"="F4"."FEEITEM_SEQ_NBR")


Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3 consistent gets
3 physical reads
0 redo size
1763 bytes sent via SQL*Net to client
380 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release
11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

C:\


3. Case 3: TEST on 11.1.0.6/10.2.0.4 DBs Result: Choose correct
execution plan.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

SQL> set autotrace trace
SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is
enabled
SP2-0611: Error enabling STATISTICS report SQL> set timing on
SQL
SQL> variable spc varchar2(15);
SQL> variable bfd varchar2(40);
SQL> variable efd varchar2(40);
SQL> variable p1 varchar2(60);
SQL> exec :spc:='SACRAMENTO';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.01
SQL> exec :bfd:='2005-12-05';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :efd:='2008-12-04 23:59:59';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.01
SQL> exec :p1:='SET07%'

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL
SQL> SELECT xfi.serv_prov_code,
2 xfi.b1_per_id1,
3 xfi.b1_per_id2,
4 xfi.b1_per_id3,
5 xfi.feeitem_seq_nbr,
6 xfi.invoice_nbr,
7 xfi.gf_fee_period,
8 xfi.gf_fee,
9 xfi.gf_des,
10 xfi.gf_unit,
11 xfi.gf_udes,
12 finv.invoice_date AS gf_fee_apply_date, 13
xfi.feeitem_invoice_status, 14 xfi.gf_l1,
15 xfi.gf_l2,
16 xfi.gf_l3,
17 xfi.x4feeitem_invoice_udf1, 18
xfi.x4feeitem_invoice_udf2, 19 xfi.x4feeitem_invoice_udf3, 20
xfi.x4feeitem_invoice_udf4, 21 xfi.gf_fee_schedule,
22 xfi.fee_schedule_version,
23 xfi.rec_date,
24 xfi.rec_ful_nam,
25 xfi.rec_status,
26 f4.GF_COD,
27 f4.GF_PRIORITY
28 FROM x4feeitem_invoice xfi, setdetails sd, f4invoice finv,
F4FEEITEM f4
29 WHERE sd.serv_prov_code = xfi.serv_prov_code 30 AND
sd.b1_per_id1 = xfi.b1_per_id1 31 AND sd.b1_per_id2 =
xfi.b1_per_id2 32 AND sd.b1_per_id3 = xfi.b1_per_id3 33 AND
xfi.serv_prov_code = f4.serv_prov_code 34 AND xfi.b1_per_id1 =
f4.b1_per_id1 35 AND xfi.b1_per_id2 = f4.b1_per_id2 36 AND
xfi.b1_per_id3 = f4.b1_per_id3 37 And xfi.feeitem_seq_nbr =
f4.feeitem_seq_nbr 38 AND finv.serv_prov_code = xfi.serv_prov_code
39 AND finv.invoice_nbr = xfi.invoice_nbr 40 AND
sd.serv_prov_code = :spc
41 AND upper(sd.set_id) = :p1
42 AND xfi.rec_status = 'A'
43 AND xfi.feeitem_invoice_status = 'INVOICED' 44 ORDER BY
gf_fee_apply_date
45 /
Elapsed: 00:00:00.51

Execution Plan
---------------------------------------------------------- Plan hash
value: 2996231674


--------------------------------------------------------------------------------
-------------------------

| Id | Operation | Name | Rows
| Bytes
| Cost (%CPU)| Time |


--------------------------------------------------------------------------------
-------------------------

| 0 | SELECT STATEMENT | | 417 |
90072
| 16 (13)| 00:00:01 |

| 1 | SORT ORDER BY | | 417 |
90072
| 16 (13)| 00:00:01 |

|* 2 | HASH JOIN | | 417 |
90072
| 15 (7)| 00:00:01 |

| 3 | NESTED LOOPS | | |
| | |

| 4 | NESTED LOOPS | | 29 |
5626
| 11 (0)| 00:00:01 |

| 5 | NESTED LOOPS | | 3 |
441
| 8 (0)| 00:00:01 |

| 6 | TABLE ACCESS BY INDEX ROWID| SETDETAILS | 3 |
105
| 2 (0)| 00:00:01 |

|* 7 | INDEX RANGE SCAN | SETDETAILS_SETID_IX | 3 |
| 1 (0)| 00:00:01 |

|* 8 | TABLE ACCESS BY INDEX ROWID| X4FEEITEM_INVOICE | 1 |
112
| 2 (0)| 00:00:01 |

|* 9 | INDEX RANGE SCAN | X4FEEITEM_INVOICE_PK | 1 |
| 1 (0)| 00:00:01 |

|* 10 | INDEX UNIQUE SCAN | F4FEEITEM_PK | 1 |
| 0 (0)| 00:00:01 |

| 11 | TABLE ACCESS BY INDEX ROWID | F4FEEITEM | 10 |
470
| 1 (0)| 00:00:01 |

| 12 | TABLE ACCESS BY INDEX ROWID | F4INVOICE | 9453 |
203K
| 3 (0)| 00:00:01 |

|* 13 | INDEX RANGE SCAN | F4INVOICE_DATE_IX | 9453 |
| 2 (0)| 00:00:01 |


--------------------------------------------------------------------------------
-------------------------


Predicate Information (identified by operation id):
---------------------------------------------------

2 - access("FINV"."SERV_PROV_CODE"="XFI"."SERV_PROV_CODE" AND
"FINV"."INVOICE_NBR"="XFI"."INVOICE_NBR")
7 - access("SD"."SERV_PROV_CODE"=:SPC AND UPPER("SET_ID")=Razz1) 8 -
filter("XFI"."FEEITEM_INVOICE_STATUS"='INVOICED' AND
"XFI"."REC_STATUS"='
A')

9 - access("XFI"."SERV_PROV_CODE"=:SPC AND
"SD"."B1_PER_ID1"="XFI"."B1_PER_ID
1" AND

"SD"."B1_PER_ID2"="XFI"."B1_PER_ID2" AND
"SD"."B1_PER_ID3"="XFI"."
B1_PER_ID3")

10 - access("F4"."SERV_PROV_CODE"=:SPC AND
"XFI"."B1_PER_ID1"="F4"."B1_PER_ID1
" AND

"XFI"."B1_PER_ID2"="F4"."B1_PER_ID2" AND
"XFI"."B1_PER_ID3"="F4"."
B1_PER_ID3" AND

"XFI"."FEEITEM_SEQ_NBR"="F4"."FEEITEM_SEQ_NBR")
13 - access("FINV"."SERV_PROV_CODE"=:SPC)

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release
11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options


Do you happen to have a SQL trace? I don't see whether the CPU costing is
on and whether the tables are analyzed. If the analysis job is running
nightly, tables are probably analyzed with the system default options.




--
http://mgogala.freehostia.com
 
joel garry...
Posted: Wed Nov 04, 2009 12:38 am
Guest
On Nov 3, 10:11 am, Charles Hooper <hooperc2... at (no spam) yahoo.com> wrote:
Quote:
On Nov 3, 12:44 pm, joel garry <joel-ga... at (no spam) home.com> wrote:



On Nov 3, 8:22 am, Charles Hooper <hooperc2... at (no spam) yahoo.com> wrote:

On Nov 3, 10:29 am, lsllcm <lsl... at (no spam) gmail.com> wrote:

Note also that it is possible that the object statistics and optimizer
parameters (FIRST_ROWS_n, for example) differ between the Oracle
versions.

David's suggestion of a 10053 trace is a good one - just keep in mind
that such traces only appear during a hard parse.

A bit of a stretch, but consider this:  rownum is assigned after the
predicate is processed, but before sorting is done.  "Bug 6438892 :
Suboptimal plan with ROWNUM predicate and NESTED LOOPS." is in the
11.1.0.6 patch set, bug not published.  So maybe there is some
mysterious optimizer bug here, set off by the order by even though
rownum is not originally a predicate.  Try patching beyond the base
release and see if the problem is still there.

jg
--

The OP is experiencing problems in 11.2.0.1, which does not exhibit
the ROWNUM bug that you mentioned, based on my testing.  You might be
suggesting - what if the fix of that bug caused another bug?
Interesting, quite possible.

Uh yeah, that's the ticket. (OK, I admit, somewhere along the line I
bugeyed the 11.2.0.1 to 11.1...)

Quote:

I noticed the large number of NESTED LOOPS in his posted plan also,
which is one of the reasons why I mentioned FIRST_ROWS_n
(OPTIMIZER_MODE).  It might even be the case that the OPTIMIZER_MODE
is set to FIRST_ROWS (or maybe even CHOOSE), rather than FIRST_ROWS_1,
FIRST_ROWS_10, FIRST_ROWS_100, ALL_ROWS, etc.

lsllcm, please try setting OPTIMIZER_FEATURES_ENABLE to 11.1.0.6 in
Oracle 11.2.0.1 and re-execute the SQL statement - note that this will
force a hard parse.  How does the performance compare?  If the
performance is better, set OPTIMIZER_FEATURES_ENABLE to 11.2.0.1, add
a couple extra spaces in the SQL statement, and try your test again.
Is the performance the same as it was on 11.1.0.6 and 10.2.0.4?

That may be informative.

jg
--
at (no spam) home.com is bogus.
http://users.rcn.com/eslowry/inexcus.htm
 
lsllcm...
Posted: Wed Nov 04, 2009 1:46 am
Guest
On Nov 4, 2:11 am, Charles Hooper <hooperc2... at (no spam) yahoo.com> wrote:
Quote:
On Nov 3, 12:44 pm, joel garry <joel-ga... at (no spam) home.com> wrote:





On Nov 3, 8:22 am, Charles Hooper <hooperc2... at (no spam) yahoo.com> wrote:

On Nov 3, 10:29 am, lsllcm <lsl... at (no spam) gmail.com> wrote:

Note also that it is possible that the object statistics and optimizer
parameters (FIRST_ROWS_n, for example) differ between the Oracle
versions.

David's suggestion of a 10053 trace is a good one - just keep in mind
that such traces only appear during a hard parse.

A bit of a stretch, but consider this:  rownum is assigned after the
predicate is processed, but before sorting is done.  "Bug 6438892 :
Suboptimal plan with ROWNUM predicate and NESTED LOOPS." is in the
11.1.0.6 patch set, bug not published.  So maybe there is some
mysterious optimizer bug here, set off by the order by even though
rownum is not originally a predicate.  Try patching beyond the base
release and see if the problem is still there.

jg
--

The OP is experiencing problems in 11.2.0.1, which does not exhibit
the ROWNUM bug that you mentioned, based on my testing.  You might be
suggesting - what if the fix of that bug caused another bug?
Interesting, quite possible.

I noticed the large number of NESTED LOOPS in his posted plan also,
which is one of the reasons why I mentioned FIRST_ROWS_n
(OPTIMIZER_MODE).  It might even be the case that the OPTIMIZER_MODE
is set to FIRST_ROWS (or maybe even CHOOSE), rather than FIRST_ROWS_1,
FIRST_ROWS_10, FIRST_ROWS_100, ALL_ROWS, etc.

lsllcm, please try setting OPTIMIZER_FEATURES_ENABLE to 11.1.0.6 in
Oracle 11.2.0.1 and re-execute the SQL statement - note that this will
force a hard parse.  How does the performance compare?  If the
performance is better, set OPTIMIZER_FEATURES_ENABLE to 11.2.0.1, add
a couple extra spaces in the SQL statement, and try your test again.
Is the performance the same as it was on 11.1.0.6 and 10.2.0.4?

Charles Hooper
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc.- Hide quoted text -

- Show quoted text -

Thank you All at first.

I have done one quick test after set OPTIMIZER_FEATURES_ENABLE to
11.1.0.6 again, the performance is same as the value to 11.2.0.1.

I will double test it again and get 10053 trace file.

Thanks
 
Randolf Geist...
Posted: Wed Nov 04, 2009 4:11 pm
Guest
On Nov 3, 4:29 pm, lsllcm <lsl... at (no spam) gmail.com> wrote:
Quote:
I have one performance issue after upgrade to oracle 11.2.0.1 linux 32
bit.

The optimizer always choose index of "order by column", not use index
of "where clause columns". Any comments are appreciated.

This might be caused by some code change / bug introduced in 11.2.0.1,
but since Charles already asked you to run the same with the optimizer
features reverted to 11.1.0.6 and you confirmed that the problem still
persists with this setting, there are some other possibilities:

1. Looking at the 10053 optimizer trace file, we can see that the
optimizer actually estimates that this statement is going to generate
millions of rows, so this is already way off from the 0 rows that it
actually produces. So the starting point of the whole calculation is
already totally wrong, since otherwise the optimizer would recognize
that using the FIRST_ROWS_n mode won't change the outcome of the
query. Looking at the 3 consistent gets with the good plan, it looks
like the whole execution already stops after the first index / table
access to SD, otherwise we probably would see more consistent gets. So
the runtime engine can take a shortcut here with the NESTED LOOP joins
if one the driving row sources generates 0 rows.

2. You're using the FIRST_ROWS_100 optimizer mode together with very
aggressive OPTIMIZER_INDEX_COST_ADJ and OPTIMIZER_INDEX_CACHING
settings which will lower cost of index access paths dramatically, in
particular when performing NESTED LOOP joins. This might lead to
multiple optimizer choices with similar costs, due to the lowering of
the cost. Using the FIRST_ROWS_n modes will introduce additional re-
costing steps by the optimizer for ORDER BY access. This is very
likely the reason why you don't see the effect when omitting the ORDER
BY.

3. You say that you've migrated to 11.2.0.1, but we don't know if the
remaining environment in terms of optimizer settings and object
statistics is the same as in the 10.2 and 11.1 databases you've used
to show the "correct" plan chosen. May be the 11.2 database has re-
gathered table/index statistics and with those modified statistics the
11.1 and 10.2 database might come to the same "bad" execution plan

4. As pointed out by Charles already, you need to be very careful with
testing when bind variables are involved, in order to make sure that
you don't share an execution plan from previous executions available
in the Shared Pool. This is obviously a general issue, and only
partially addressed by the new Adaptive Cursor Sharing introduced with
11.1

What you could try:

1. What cost / plan do you get if you request to use the index
SETDETAILS_SETID_IX?

SELECT /*+ INDEX(SD, SETDETAILS_SETID_IX) */ ...

2. What plan do you get in 11.2 if you're setting
OPTIMIZER_INDEX_COST_ADJ and OPTIMIZER_INDEX_CACHING to default
values:

ALTER SESSION SET OPTIMIZER_INDEX_COST_ADJ = 100;
ALTER SESSION SET OPTIMIZER_INDEX_CACHING = 0;

3. What plan do you get in your 10.2 and 11.1 databases if you use the
same environment as in 11.2? In particular the optimizer settings and
object statistics should be the same. You can either try to export /
import the object statistics manually or (I'm not sure if it requires
an additional license cost, but if your license allows for it) you can
very simply create a test case using the SQL Test Case Builder in 11.2
and try to import this into the 11.1 and 10.2 databases to create a
similar environment, however I'm not sure if this will work due to
potential compatibility issues in the lower version environments.

Use the DBMS_SQLDIAG.EXPORT_SQL_TESTCASE / IMPORT_SQL_TESTCASE to do
so.

See the manuals or e.g. http://optimizermagic.blogspot.com/2008/03/oracle-support-keeps-closing-my-tar.html
for more information.

4. A general question: Is your application actually using the
FIRST_ROWS_100 optimizer mode properly? Which means, do you always
fetch only a few rows from a larger result set? Does your application
show only the top N ordered results of a search result in "pagination"
style like Google search? Only then the FIRST_ROWS_100 mode is
reasonable, otherwise you should actually use the ALL_ROWS mode. Given
your aggressive OPTIMIZER_INDEX_COST_ADJ and OPTIMIZER_INDEX_CACHING
the optimizer would still favor index access / nested loop operations
quite a lot even in ALL_ROWS mode.

Regards,
Randolf

Oracle related stuff blog:
http://oracle-randolf.blogspot.com/

SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/
 
Charles Hooper...
Posted: Wed Nov 04, 2009 10:26 pm
Guest
On Nov 4, 7:01 am, lsllcm <lsl... at (no spam) gmail.com> wrote:
Quote:
The trace file is too long, I use three parts.
(Snip)
***************************************
PARAMETERS USED BY THE OPTIMIZER
********************************
*************************************
PARAMETERS WITH ALTERED VALUES
******************************
Compilation Environment Dump
optimizer_features_enable = 11.1.0.6
optimizer_mode = first_rows_100
optimizer_index_cost_adj = 10
optimizer_index_caching = 90
_optimizer_cost_based_transformation = off
Bug Fix Control Environment

I agree with Randolf's points.

I attempted to run through the trace file, but I believe that there
are sections of the trace file that are missing - at least from what I
am able to see.

Just a couple questions:
Why is "_optimizer_cost_based_transformation = off" specified?
Why is "optimizer_mode = first_rows_100" specified?
Why is "optimizer_index_cost_adj = 10" specified?
Why is "optimizer_index_caching = 90" specified?

The system statistics show the following:
-----------------------------
SYSTEM STATISTICS INFORMATION
-----------------------------
Using NOWORKLOAD Stats
CPUSPEEDNW: 2696 millions instructions/sec (default is 100)
IOTFRSPEED: 4096 bytes per millisecond (default is 4096)
IOSEEKTIM: 10 milliseconds (default is 10)
MBRC: -1 blocks (default is 8)

You might try collecting system statistics during a busy time period.
To collect the system statistics with a 60 minute monitoring period,
enter the following in SQL*Plus (the SQL*Plus command prompt will
return immediately):
EXEC DBMS_STATS.GATHER_SYSTEM_STATS('interval',interval=>60)

The SETDETAILS table should probably be one of the first tables
accessed, if not the first. There are a couple interesting statistics
showing up in the calculations:

SINGLE TABLE ACCESS PATH
Single Table Cardinality Estimation for SETDETAILS[SD]
Column (#17):
NewDensity:0.000065, OldDensity:0.002105 BktCnt:254, PopBktCnt:
194, PopValCnt:19, NDV:3664
Column (#3):
NewDensity:0.000063, OldDensity:0.001961 BktCnt:254, PopBktCnt:
196, PopValCnt:20, NDV:3665
ColGroup (#8, Index) SETDETAILS_IX
Col#: 1 3 4 5 6 CorStregth: 11963.23
ColGroup (#2, Index) SETDETAILS_PID_IX
Col#: 1 4 5 6 CorStregth: 7.07
ColGroup (#1, Index) SETDETAILS_SETID1_IX
Col#: 1 3 CorStregth: 1.00
ColGroup (#3, Index) SETDETAILS_SETID_IX
Col#: 1 17 CorStregth: 1.00
ColGroup (#5, Index) SETDETAILS_STAT_IX
Col#: 1 15 CorStregth: -1.00
ColGroup (#7, Index) SETDETAILS_PK
Col#: 1 2 CorStregth: -1.00
ColGroup (#6, Index) SETDETAILS_PAR_IX
Col#: 12 13 CorStregth: -1.00
ColGroup (#4, Index) SETDETAILS_ADDR_IX
Col#: 1 14 CorStregth: -1.00
ColGroup Usage:: PredCnt: 2 Matches Full: Partial:
***** Virtual column Adjustment ******
Column name SYS_NC00017$
cost_cpu 150.00
cost_io
179769313486231570814527423731704356798070567525844996598917476803157260780­
028538760589558632766878171540458953514382464234321326889464182768467546703­
537516986049910576551282076245490090389328944075868508455133942304583236903­
222948165808559332123348274797826204144723168738177180919299881250404026184­
124858368.00

Is SYS_NC00017$ the virtual column for a function based index, maybe
on UPPER("SET_ID")? I wonder if Oracle was able to calculate positive
infinity correctly? :-)

--

Oracle only tried 19 join orders, ending with this:
(newjo-stop-1) k:0, spcnt:0, perm:19, maxperm:1000
*********************************
Number of join permutations tried: 19

With 4 tables involved, there are 4! (24) possible join orders for the
tables, so I am not sure if Oracle aborted the join orders early?

--

Oracle found that the join order 9 was the lowest cost per this output
in the trace file:
Final cost for query block SEL$1 (#0) - First K Rows Plan:
Best join order: 9
Cost: 4.5006 Degree: 1 Card: 117.0000 Bytes: 27495
Resc: 4.5006 Resc_io: 4.5000 Resc_cpu: 20442
Resp: 4.5006 Resp_io: 4.5000 Resc_cpu: 20442

That join order is:
Join order[9]: F4INVOICE[FINV]#1 X4FEEITEM_INVOICE[XFI]#2
SETDETAILS
[SD]#0 F4FEEITEM[F4]#3
....
SM Join
SM cost: 32953.73
resc: 32953.73 resc_io: 32880.40 resc_cpu: 2372333225
resp: 32953.73 resp_io: 32880.40 resp_cpu: 2372333225
Outer table: SETDETAILS Alias: SD
resc: 11877.47 card 90789.89 bytes: 193 deg: 1 resp: 11877.47
Inner table: F4FEEITEM Alias: F4
resc: 1107.45 card: 344923.77 bytes: 42 deg: 1 resp: 1107.45
using dmeth: 2 #groups: 1
Cost per ptn: 1763.63 #ptns: 1
hash_area: 124 (max=10240) buildfrag: 2272 probefrag: 2274
ppasses: 1
Hash join: Resc: 14748.55 Resp: 14748.55 [multiMatchCost=0.00]
HA Join
HA cost: 14748.55
resc: 14748.55 resc_io: 14722.80 resc_cpu: 833107904
resp: 14748.55 resp_io: 14722.80 resp_cpu: 833107904
Join order aborted: cost > best plan cost

Without the FIRST_ROWS_100 optimizer mode, Oracle should have selected
a different plan (if I am not missing sections of the 10053 trace
between the join order start and the rejection of the join order due
to the cost of the join order before applying the adjustment for the
FIRST_ROWS_100 optimizer mode to avoid the sort).

--

Suggestions (initially just at the session level):
Gather statistics on all objects in the schema, including virtual
columns (also specify NO_INVALIDATE=>FALSE)
At the session level, Set optimizer_mode = ALL_ROWS
At the session level, Set optimizer_index_cost_adj = 90
At the session level, Set optimizer_index_caching = 10
At the session level, Set _optimizer_cost_based_transformation = on
Run the SQL statement - did the plan change, and did the execution
time change? If not, are you able to modify the query to add a
LEADING hint?

If the plan is better, wait until the database instance is very busy,
then start the system statistics gathering process (with
DBMS_STATS.GATHER_SYSTEM_STATS). Consider setting the
_optimizer_cost_based_transformation, optimizer_index_caching,
optimizer_index_cost_adj, and optimizer_mode back to the default
values at the system level:
Set optimizer_mode = ALL_ROWS
Set optimizer_index_cost_adj = 100
Set optimizer_index_caching = 0
Set _optimizer_cost_based_transformation = on

-

Randolf is better at reading 10053 trace files than I am, so he might
see something else that I missed in the file.

-

Randolf: regarding the optimizer bug that was fixed in 11.2.0.1 which
was related to ROWNUM and incorrect cardinality estimates, I was
unable to force 11.2.0.1 to reproduce the incorrect cardinality
estimates by changing the OPTIMIZER_FEATURES_ENABLE parameter to match
a lower release number. So, I guess that some fixes are buried deep
in the code. I even tried disabling some of the bug fixes without
success. This seems to imply that changing the
OPTIMIZER_FEATURES_ENABLE to an older version may not always reproduce
the old optimizer behavior, which is a bit unfortunate.

Charles Hooper
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc.
 
joel garry...
Posted: Thu Nov 05, 2009 12:56 am
Guest
On Nov 4, 2:26 pm, Charles Hooper <hooperc2... at (no spam) yahoo.com> wrote:

Quote:
-

Randolf: regarding the optimizer bug that was fixed in 11.2.0.1 which
was related to ROWNUM and incorrect cardinality estimates, I was
unable to force 11.2.0.1 to reproduce the incorrect cardinality
estimates by changing the OPTIMIZER_FEATURES_ENABLE parameter to match
a lower release number.  So, I guess that some fixes are buried deep
in the code.  I even tried disabling some of the bug fixes without
success.  This seems to imply that changing the
OPTIMIZER_FEATURES_ENABLE to an older version may not always reproduce
the old optimizer behavior, which is a bit unfortunate.


Yes, Jonathan blogged about an example of this in "FBI
problem" ( http://jonathanlewis.wordpress.com/2007/11/18/fbi-problem/
) But it's still usually worth a try, if just to narrow
possibilities.

Also, just to clearly emphasize to the OP, it is recommended in a lot
of places not to set OPTIMIZER_INDEX_COST_ADJ and
OPTIMIZER_INDEX_CACHING, at least until testing shows they help - it's
likely a mistake to keep the settings from earlier versions. See
http://richardfoote.wordpress.com/2009/09/01/optimizer_index_caching-parameter/
for some idea of what to look for.

jg
--
at (no spam) home.com is bogus.
http://www.newscientist.com/article/mg20427321.000-clever-fools-why-a-high-iq-doesnt-mean-youre-smart.html?full=true
 
Charles Hooper...
Posted: Thu Nov 05, 2009 12:27 pm
Guest
On Nov 4, 7:56 pm, joel garry <joel-ga... at (no spam) home.com> wrote:
Quote:
Yes, Jonathan blogged about an example of this in "FBI
problem" (http://jonathanlewis.wordpress.com/2007/11/18/fbi-problem/
) But it's still usually worth a try, if just to narrow
possibilities.

Also, just to clearly emphasize to the OP, it is recommended in a lot
of places not to set OPTIMIZER_INDEX_COST_ADJ and
OPTIMIZER_INDEX_CACHING, at least until testing shows they help - it's
likely a mistake to keep the settings from earlier versions. Seehttp://richardfoote.wordpress.com/2009/09/01/optimizer_index_caching-...
for some idea of what to look for.

jg
--

Joel,

Thanks for providing the links. It looks like Jonathan's blog post
describes what I saw while trying to un-fix 11.2.0.1.

Richard Foote also has at least a 3 part series on the effects of
OPTIMIZER_INDEX_COST_ADJ. This example shows a query requiring
00:01:49.75 (just under 2 minutes) with the default value of
OPTIMIZER_INDEX_COST_ADJ, and 02:16:44.42 (just over 2.25 hours) with
a very small value for the parameter:
http://richardfoote.wordpress.com/2009/07/22/the-cbo-and-indexes-optimizer_index_cost_adj-part-ii/

Of course there is also one of my test cases here:
http://groups.google.com/group/comp.databases.oracle.server/browse_thread/thread/6c436cee329326ec/65f7487bd653d0df

"What about the performance results?
* Oracle 11.1.0.7 on 64 bit Windows finished the full tablescan
access
path for the query in 35.38 seconds and the index access path in 1
hour, 38 minutes and 7 seconds.
* Oracle 11.1.0.6 on 64 bit Oracle Enterprise Linux 5 required 41.98
seconds for the full tablescan access path and one hour, 14 minutes
and 40 seconds for the index access path.
* Oracle 11.2.0.1 required 13.13 seconds (a significant drop from the
41.98 seconds received on the same server with the same operating
system and disk subsystem) and 22.13 seconds for the index access
path
(an unbelievable drop from the one hour, 14 minutes and 40 seconds on
the same server, operating system, and I/O subsystem)."

35.38 seconds with the default value compared to 1:38:07 (just over an
hour and a half) with a value of 5 (10 might have also worked, but not
tested).
41.98 seconds with the default value compared to 1:14:40 (just under
1.25 hours) with a value of 5.
13.13 seconds with the default value compared to 22.13 seconds with a
value of 5.

I guess the message is to test to see why the performance is
different.

Charles Hooper
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc.
 
lsllcm...
Posted: Thu Nov 05, 2009 4:37 pm
Guest
Thank for your good suggestions and comments:

I have done some test based on your good suggestions: below are some
test cases

--------------------case 1--------------------------------------------
1. What cost / plan do you get if you request to use the index
SETDETAILS_SETID_IX?

Result: as same as no index hint

--------------------case 2--------------------------------------------
2. What plan do you get in 11.2 if you're setting
OPTIMIZER_INDEX_COST_ADJ and OPTIMIZER_INDEX_CACHING to default
values:

Result: get below execution plan. The consistent read is 3656.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

SQL> set autotrace trace
SQL> set timing on
SQL>
SQL> variable spc varchar2(15);
SQL> variable bfd varchar2(40);
SQL> variable efd varchar2(40);
SQL> variable p1 varchar2(60);
SQL> variable p2 varchar2(60);
SQL> exec :spc:='SACRAMENTO';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :bfd:='2005-12-05';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :efd:='2008-12-04 23:59:59';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :p1:='254413'

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :p2:='Contractor'

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.01
SQL>
SQL> --alter session set optimizer_features_enable = "11.1.0.6";
SQL> alter session set optimizer_index_caching = 0;

Session altered.

Elapsed: 00:00:00.00
SQL> alter session set optimizer_index_cost_adj = 100;

Session altered.

Elapsed: 00:00:00.01
SQL> alter session set optimizer_mode = ALL_ROWS;

Session altered.

Elapsed: 00:00:00.00
SQL> --alter session set optimizer_mode = FIRST_ROWS_100;
SQL>
SQL>
SQL> --SELECT
SQL> SELECT /*+ index(SD SETDETAILS_SETID_IX) */
2 xfi.serv_prov_code,
3 xfi.b1_per_id1,
4 xfi.b1_per_id2,
5 xfi.b1_per_id3,
6 xfi.feeitem_seq_nbr,
7 xfi.invoice_nbr,
8 xfi.gf_fee_period,
9 xfi.gf_fee,
10 xfi.gf_des,
11 xfi.gf_unit,
12 xfi.gf_udes,
13 finv.invoice_date AS gf_fee_apply_date,
14 xfi.feeitem_invoice_status,
15 xfi.gf_l1,
16 xfi.gf_l2,
17 xfi.gf_l3,
18 xfi.x4feeitem_invoice_udf1,
19 xfi.x4feeitem_invoice_udf2,
20 xfi.x4feeitem_invoice_udf3,
21 xfi.x4feeitem_invoice_udf4,
22 xfi.gf_fee_schedule,
23 xfi.fee_schedule_version,
24 xfi.rec_date,
25 xfi.rec_ful_nam,
26 xfi.rec_status,
27 f4.GF_COD,
28 f4.GF_PRIORITY
29 FROM x4feeitem_invoice xfi, setdetails sd, f4invoice finv,
F4FEEITEM f4
30 WHERE sd.serv_prov_code = xfi.serv_prov_code
31 AND sd.b1_per_id1 = xfi.b1_per_id1
32 AND sd.b1_per_id2 = xfi.b1_per_id2
33 AND sd.b1_per_id3 = xfi.b1_per_id3
34 AND xfi.serv_prov_code = f4.serv_prov_code
35 AND xfi.b1_per_id1 = f4.b1_per_id1
36 AND xfi.b1_per_id2 = f4.b1_per_id2
37 AND xfi.b1_per_id3 = f4.b1_per_id3
38 And xfi.feeitem_seq_nbr = f4.feeitem_seq_nbr
39 AND finv.serv_prov_code = xfi.serv_prov_code
40 AND finv.invoice_nbr = xfi.invoice_nbr
41 AND sd.serv_prov_code = :spc
42 AND upper(sd.set_id) = :p1
43 AND xfi.rec_status = 'A'
44 AND xfi.feeitem_invoice_status = 'INVOICED'
45 ORDER BY gf_fee_apply_date
46 /

no rows selected

Elapsed: 00:00:00.53

Execution Plan
----------------------------------------------------------
Plan hash value: 3678138156

--------------------------------------------------------------------------------
-----------------------------------

| Id | Operation | Name |
Rows | Byte
s |TempSpc| Cost (%CPU)| Time |

--------------------------------------------------------------------------------
-----------------------------------

| 0 | SELECT STATEMENT | |
20239 | 464
4K| | 6832 (1)| 00:01:22 |

| 1 | SORT ORDER BY | |
20239 | 464
4K| 5072K| 6832 (1)| 00:01:22 |

|* 2 | HASH JOIN | |
20239 | 464
4K| 2152K| 5801 (1)| 00:01:10 |

| 3 | TABLE ACCESS BY INDEX ROWID | F4INVOICE |
61172 | 143
3K| | 924 (1)| 00:00:12 |

|* 4 | INDEX RANGE SCAN | F4INVOICE_BATCH_NBR_IX |
61172 |
| | 193 (0)| 00:00:03 |

|* 5 | HASH JOIN | |
19441 | 400
5K| 3440K| 4566 (1)| 00:00:55 |

| 6 | NESTED LOOPS |
| |
| | | |

| 7 | NESTED LOOPS | |
19441 | 320
8K| | 327 (0)| 00:00:04 |

| 8 | TABLE ACCESS BY INDEX ROWID| SETDETAILS |
107 | 406
6 | | 6 (0)| 00:00:01 |

|* 9 | INDEX RANGE SCAN | SETDETAILS_SETID_IX |
107 |
| | 3 (0)| 00:00:01 |

|* 10 | INDEX RANGE SCAN | X4FEEITEM_INVOICE_PK
| 1 |
| | 2 (0)| 00:00:01 |

|* 11 | TABLE ACCESS BY INDEX ROWID | X4FEEITEM_INVOICE |
182 | 2384
2 | | 3 (0)| 00:00:01 |

| 12 | TABLE ACCESS BY INDEX ROWID | F4FEEITEM |
117K| 481
4K| | 3770 (1)| 00:00:46 |

|* 13 | INDEX RANGE SCAN | F4FEEITEM_POS_IX |
117K|
| | 577 (1)| 00:00:07 |

--------------------------------------------------------------------------------
-----------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------

2 - access("FINV"."SERV_PROV_CODE"="XFI"."SERV_PROV_CODE" AND
"FINV"."INVOICE
_NBR"="XFI"."INVOICE_NBR")

4 - access("FINV"."SERV_PROV_CODE"=:SPC)
5 - access("XFI"."SERV_PROV_CODE"="F4"."SERV_PROV_CODE" AND
"XFI"."B1_PER_ID1
"="F4"."B1_PER_ID1" AND

"XFI"."B1_PER_ID2"="F4"."B1_PER_ID2" AND
"XFI"."B1_PER_ID3"="F4"."
B1_PER_ID3" AND

"XFI"."FEEITEM_SEQ_NBR"="F4"."FEEITEM_SEQ_NBR")
9 - access("SD"."SERV_PROV_CODE"=:SPC AND UPPER("SET_ID")=Razz1)
10 - access("XFI"."SERV_PROV_CODE"=:SPC AND
"SD"."B1_PER_ID1"="XFI"."B1_PER_ID
1" AND

"SD"."B1_PER_ID2"="XFI"."B1_PER_ID2" AND
"SD"."B1_PER_ID3"="XFI"."
B1_PER_ID3")

11 - filter("XFI"."FEEITEM_INVOICE_STATUS"='INVOICED' AND
"XFI"."REC_STATUS"='
A')

13 - access("F4"."SERV_PROV_CODE"=:SPC)


Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3656 consistent gets
0 physical reads
0 redo size
1763 bytes sent via SQL*Net to client
381 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
0 rows processed

SQL> rem SELECT * FROM TABLE (DBMS_XPLAN.DISPLAY_CURSOR
(NULL,NULL,'ALLSTATS LAST')) ;
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release
11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

E:\tools\syncdb>

--------------------case 3--------------------------------------------
3. import statistics: not ready, will do test
When I try to import sql test case dmp from 11.2.0.1 to 11.1.0.6. It
prompts message as below:
ORA-20006: ORA-39001: invalid argument value
ORA-39000: bad dump file specification
ORA-39142: incompatible version number 3.1 in dump file
"oratcb1_00C201740001dpexp.dmp"

I will try import sql test case dmp from 11.1.0.6 to 11.2.0.1
tomorrow.

--------------------item 4--------------------------------------------
4. A general question: Is your application actually using the
FIRST_ROWS_100 optimizer mode properly?
Yes, most of applications are oltp type and return first of rows. So
we choose aggressive OPTIMIZER_INDEX_COST_ADJ and
OPTIMIZER_INDEX_CACHING


--------------------item 5--------------------------------------------
5. question
Why is "_optimizer_cost_based_transformation = off" specified?
Why is "optimizer_mode = first_rows_100" specified?
Why is "optimizer_index_cost_adj = 10" specified?
Why is "optimizer_index_caching = 90" specified?
[lsllcm] The _optimizer_cost_based_transformation parameter is set
useless, I remove the setting
About other three parameters, please see item 4

--------------------item 6--------------------------------------------
6. system statistics: There are about 10 scheduled jobs. I stop them
at first.

Thank you again
lsllcm
 
Charles Hooper...
Posted: Thu Nov 05, 2009 8:14 pm
Guest
On Nov 5, 11:37 am, lsllcm <lsl... at (no spam) gmail.com> wrote:
Quote:
Thank for your good suggestions and comments:

I have done some test based on your good suggestions: below are some
test cases

--------------------case 2--------------------------------------------
2. What plan do you get in 11.2 if you're setting
OPTIMIZER_INDEX_COST_ADJ and OPTIMIZER_INDEX_CACHING to default
values:

Result: get below execution plan. The consistent read is 3656.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing
options

SQL> set autotrace trace
SQL> set timing on
SQL
SQL> variable spc varchar2(15);
SQL> variable bfd varchar2(40);
SQL> variable efd varchar2(40);
SQL> variable p1 varchar2(60);
SQL> variable p2 varchar2(60);
SQL> exec :spc:='SACRAMENTO';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :bfd:='2005-12-05';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :efd:='2008-12-04 23:59:59';

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :p1:='254413'

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00
SQL> exec :p2:='Contractor'

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.01
SQL
SQL> --alter session set optimizer_features_enable = "11.1.0.6";
SQL> alter session set optimizer_index_caching = 0;

Session altered.

Elapsed: 00:00:00.00
SQL> alter session set optimizer_index_cost_adj = 100;

Session altered.

Elapsed: 00:00:00.01
SQL> alter session set optimizer_mode = ALL_ROWS;

Session altered.

Elapsed: 00:00:00.00
SQL> --alter session set optimizer_mode = FIRST_ROWS_100;
SQL
SQL
SQL> --SELECT
SQL> SELECT /*+ index(SD SETDETAILS_SETID_IX) */
2 xfi.serv_prov_code,
3 xfi.b1_per_id1,
(snip)

no rows selected

Elapsed: 00:00:00.53

Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
3656 consistent gets
0 physical reads
0 redo size
1763 bytes sent via SQL*Net to client
381 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
0 rows processed


The performance of the above is about 0.02 seconds slower than on the
older release of Oracle. Please try the test again without the index
hint. Also, you might need to force the join order with SETDETAILS as
the leading table (I am not sure why this is not happening
automatically based on the old 10053 trace):
/*+ LEADING(SD) */

Quote:
--------------------item 4--------------------------------------------
4. A general question: Is your application actually using the
FIRST_ROWS_100 optimizer mode properly?
Yes, most of applications are oltp type and return first of rows. So
we choose aggressive OPTIMIZER_INDEX_COST_ADJ and
OPTIMIZER_INDEX_CACHING

Even in OLTP type applications an OPTIMIZER_MODE of ALL_ROWS may be
appropriate. I believe that Randolf's comment was along the lines of:
your query is expected to retrieve 100,000 rows, but the application
front-end will ONLY read just the first 100 rows and then throw away
the rest of the query results without bother fetching the remaining
rows. That is probably not happening in your environment, and I
believe that is the intention of the FIRST_ROWS_100 optimizer mode.

A case in point where FIRST_ROWS_n may lead to problems (at least with
Oracle 10.2.0.x) is poor performance resulting when querying certain
data dictionary views when the OPTIMIZER_MODE is not set to ALL_ROWS -
I believe that this situation is most severe when fixed object
statistics have not been collected.

Take a look at the following links:
http://jonathanlewis.wordpress.com/2008/11/11/first_rows_n/

Likewise, it is generally not advised to modify
OPTIMIZER_INDEX_COST_ADJ due to the index costing problem mentioned by
Randolf (also covered in detail in the book "Troubleshooting Oracle
Performance"), but to instead verify that suitable system statistics
are present - see below.

Quote:
--------------------item 5--------------------------------------------
5. question
Why is "_optimizer_cost_based_transformation = off" specified?
Why is "optimizer_mode = first_rows_100" specified?
Why is "optimizer_index_cost_adj = 10" specified?
Why is "optimizer_index_caching = 90" specified?
[lsllcm] The _optimizer_cost_based_transformation parameter is set
useless, I remove the setting
About other three parameters, please see item 4

Does the above comment mean that you removed the
_optimizer_cost_based_transformation parameter?

Quote:
--------------------item 6--------------------------------------------
6. system statistics: There are about 10 scheduled jobs. I stop them
at first.

Thank you again
lsllcm

I think that there is a misunderstanding about the system statistics
comment that I made. That comment was related to this showing up in
the 10053 trace file:
SYSTEM STATISTICS INFORMATION
-----------------------------
Using NOWORKLOAD Stats
CPUSPEEDNW: 2696 millions instructions/sec (default is 100)
IOTFRSPEED: 4096 bytes per millisecond (default is 4096)
IOSEEKTIM: 10 milliseconds (default is 10)
MBRC: -1 blocks (default is 8)

That information is also viewed by executing this query:
SELECT
*
FROM
SYS.AUX_STATS$;

Charles Hooper
IT Manager/Oracle DBA
K&M Machine-Fabricating, Inc.
 
 
Page 1 of 3    Goto page 1, 2, 3  Next
All times are GMT
The time now is Tue Dec 01, 2009 9:44 am