SQL> alter session set nls_sort=GERMAN;
Session altered.
SQL> alter session set nls_comp=ANSI;
Session altered.
SQL> alter session set QUERY_REWRITE_ENABLED=TRUE;
Session altered.
SQL> alter session set QUERY_REWRITE_INTEGRITY=TRUSTED;
Session altered.
SQL> select d.parameter Dparameter,
2 d.value DatabaseVal,
3 i.value InstanceVal,
4 s.value SessionVal
5 from nls_database_parameters d, nls_instance_parameters i,
6 nls_session_parameters s
7 where d.parameter = i.parameter (+)
8 and d.parameter = s.parameter (+)
9 order by DParameter;
DPARAMETER DATABASEVAL INSTANCEVAL SESSIONVAL
------------------------------ ---------------------------------------- ---------------------------------------- ----------------------------------------
NLS_CALENDAR GREGORIAN GREGORIAN
NLS_CHARACTERSET EE8ISO8859P1
NLS_COMP BINARY ANSI
NLS_CURRENCY $ $
NLS_DATE_FORMAT DD-MON-RR DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN AMERICAN
NLS_DUAL_CURRENCY $ $
NLS_ISO_CURRENCY AMERICA AMERICA
NLS_LANGUAGE AMERICAN GERMAN AMERICAN
NLS_LENGTH_SEMANTICS BYTE BYTE BYTE
NLS_NCHAR_CHARACTERSET UTF8
NLS_NCHAR_CONV_EXCP FALSE FALSE FALSE
NLS_NUMERIC_CHARACTERS ., .,
NLS_RDBMS_VERSION 10.2.0.3.0
NLS_SORT BINARY GERMAN
NLS_TERRITORY AMERICA GERMANY AMERICA
NLS_TIME_FORMAT HH.MI.SSXFF AM HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM DD-MON-RR HH.MI.SSXFF AM
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR DD-MON-RR HH.MI.SSXFF AM TZR
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR HH.MI.SSXFF AM TZR
20 rows selected.
SQL> CREATE UNIQUE INDEX IDX_ENAM_FAMI_ID_GEB ON PATIENT (ENAM, FAMILIEN, ID, GEBURT);
Index created.
SQL> CREATE UNIQUE INDEX ENAM_FAMI_IDDE ON PATIENT (NLSSORT("ENAM",'nls_sort=''GERMAN'''), NLSSORT("FAMILIEN",'nls_sort=''GERMAN'''), ID);
Index created.
SQL> set autotrace on;
SQL> SELECT
2 ENAM,FAMILIEN,GEBURT, i
3 FROM (
4 SELECT /*+ INDEX_RS_ASC(PATIENT ENAM_FAMI_IDDE) FIRST_ROWS */
5 row_number() OVER (PARTITION BY NLSSORT("ENAM",'nls_sort=GERMAN'),NLSSORT("FAMILIEN",'nls_sort=GERMAN') ORDER BY NLSSORT("ENAM",'nls_sort=GERMAN'),NLSSORT("FAMILIEN",'nls_sort=GERMAN'),ID) I,
6 ENAM,
7 FAMILIEN,
8 GEBURT
9 FROM PATIENT
10 WHERE NLSSORT("ENAM",'nls_sort=GERMAN')>=NLSSORT('ANNA','nls_sort=GERMAN') AND (NLSSORT("ENAM",'nls_sort=GERMAN')>NLSSORT('ANNA','nls_sort=GERMAN') OR NLSSORT("FAMILIEN",'nls_sort=GERMAN')>=NLSSORT('BANANA','nls_sort=GERMAN'))
11 ORDER BY NLSSORT("ENAM",'nls_sort=GERMAN'),NLSSORT("FAMILIEN",'nls_sort=GERMAN'),ID
12 ) a
13 WHERE rownum<=5 AND (a.I>=3 OR NLSSORT("ENAM",'nls_sort=GERMAN')>NLSSORT('ANNA','nls_sort=GERMAN') OR NLSSORT("FAMILIEN",'nls_sort=GERMAN')>NLSSORT('BANANA','nls_sort=GERMAN'));
ENAM FAMILIEN GEBURT I
-------------------------------------------------- -------------------------------------------------------------------------------- --------- ----------
ANNA BANANA 05-MAY-69 3
ANNA BANANA 06-JUN-69 4
ANNA BANANA 08-AUG-69 5
ANNA Banger 03-APR-81 1
ANNA Banger 30-DEC-99 2
Execution Plan
----------------------------------------------------------
Plan hash value: 1193522455
-------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 | 455 | 401 (1)| 00:00:05 |
|* 1 | COUNT STOPKEY | | | | | |
|* 2 | VIEW | | 2050 | 182K| 401 (1)| 00:00:05 |
| 3 | WINDOW NOSORT | | 2050 | 65600 | 401 (1)| 00:00:05 |
| 4 | TABLE ACCESS BY INDEX ROWID| PATIENT | 2050 | 65600 | 400 (1)| 00:00:05 |
|* 5 | INDEX RANGE SCAN | ENAM_FAMI_IDDE | 369 | | 31 (4)| 00:00:01 |
-------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM<=5)
2 - filter("A"."I">=3 OR NLSSORT("ENAM",'nls_sort=''GERMAN''')>HEXTORAW('1455551400010
1010100') OR NLSSORT("FAMILIEN",'nls_sort=''GERMAN''')>HEXTORAW('1A145514551400010101010
10100') )
5 - access(NLSSORT("ENAM",'nls_sort=''GERMAN''')>=HEXTORAW('14555514000101010100')
AND NLSSORT("ENAM",'nls_sort=''GERMAN''') IS NOT NULL)
filter(NLSSORT("ENAM",'nls_sort=''GERMAN''')>HEXTORAW('14555514000101010100') OR
NLSSORT("FAMILIEN",'nls_sort=''GERMAN''')>=HEXTORAW('1A14551455140001010101010100') )
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
11 consistent gets
0 physical reads
0 redo size
697 bytes sent via SQL*Net to client
396 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
5 rows processed
/* Analyzing the index does not change anything */
SQL> exec DBMS_STATS.GATHER_INDEX_STATS (ownname => 'ORAUSER', indname => 'ENAM_FAMI_IDDE');
PL/SQL procedure successfully completed.
SQL> SELECT
2 ENAM,FAMILIEN,GEBURT, i
3 FROM (
4 SELECT /*+ INDEX_RS_ASC(PATIENT ENAM_FAMI_IDDE) FIRST_ROWS */
5 row_number() OVER (PARTITION BY NLSSORT("ENAM",'nls_sort=GERMAN'),NLSSORT("FAMILIEN",'nls_sort=GERMAN') ORDER BY NLSSORT("ENAM",'nls_sort=GERMAN'),NLSSORT("FAMILIEN",'nls_sort=GERMAN'),ID) I,
6 ENAM,
7 FAMILIEN,
8 GEBURT
9 FROM PATIENT
10 WHERE NLSSORT("ENAM",'nls_sort=GERMAN')>=NLSSORT('ANNA','nls_sort=GERMAN') AND (NLSSORT("ENAM",'nls_sort=GERMAN')>NLSSORT('ANNA','nls_sort=GERMAN') OR NLSSORT("FAMILIEN",'nls_sort=GERMAN')>=NLSSORT('BANANA','nls_sort=GERMAN'))
11 ORDER BY NLSSORT("ENAM",'nls_sort=GERMAN'),NLSSORT("FAMILIEN",'nls_sort=GERMAN'),ID
12 ) a
13 WHERE rownum<=5 AND (a.I>=3 OR NLSSORT("ENAM",'nls_sort=GERMAN')>NLSSORT('ANNA','nls_sort=GERMAN') OR NLSSORT("FAMILIEN",'nls_sort=GERMAN')>NLSSORT('BANANA','nls_sort=GERMAN'));
ENAM FAMILIEN GEBURT I
-------------------------------------------------- -------------------------------------------------------------------------------- --------- ----------
ANNA BANANA 05-MAY-69 3
ANNA BANANA 06-JUN-69 4
ANNA BANANA 08-AUG-69 5
ANNA Banger 03-APR-81 1
ANNA Banger 30-DEC-99 2
Execution Plan
----------------------------------------------------------
Plan hash value: 1193522455
-------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 | 455 | 401 (1)| 00:00:05 |
|* 1 | COUNT STOPKEY | | | | | |
|* 2 | VIEW | | 2050 | 182K| 401 (1)| 00:00:05 |
| 3 | WINDOW NOSORT | | 2050 | 65600 | 401 (1)| 00:00:05 |
| 4 | TABLE ACCESS BY INDEX ROWID| PATIENT | 2050 | 65600 | 400 (1)| 00:00:05 |
|* 5 | INDEX RANGE SCAN | ENAM_FAMI_IDDE | 369 | | 31 (4)| 00:00:01 |
-------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM<=5)
2 - filter("A"."I">=3 OR NLSSORT("ENAM",'nls_sort=''GERMAN''')>HEXTORAW('1455551400010
1010100') OR NLSSORT("FAMILIEN",'nls_sort=''GERMAN''')>HEXTORAW('1A145514551400010101010
10100') )
5 - access(NLSSORT("ENAM",'nls_sort=''GERMAN''')>=HEXTORAW('14555514000101010100')
AND NLSSORT("ENAM",'nls_sort=''GERMAN''') IS NOT NULL)
filter(NLSSORT("ENAM",'nls_sort=''GERMAN''')>HEXTORAW('14555514000101010100') OR
NLSSORT("FAMILIEN",'nls_sort=''GERMAN''')>=HEXTORAW('1A14551455140001010101010100') )
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
11 consistent gets
0 physical reads
0 redo size
697 bytes sent via SQL*Net to client
396 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
5 rows processed
/* We can wait a day or analyze the table below to get the undesirable CBO bahvior immediately */
SQL> exec DBMS_STATS.GATHER_TABLE_STATS (ownname => 'ORAUSER', tabname => 'PATIENT');
PL/SQL procedure successfully completed.
SQL> SELECT
2 ENAM,FAMILIEN,GEBURT, i
3 FROM (
4 SELECT /*+ INDEX_RS_ASC(PATIENT ENAM_FAMI_IDDE) FIRST_ROWS */
5 row_number() OVER (PARTITION BY NLSSORT("ENAM",'nls_sort=GERMAN'),NLSSORT("FAMILIEN",'nls_sort=GERMAN') ORDER BY NLSSORT("ENAM",'nls_sort=GERMAN'),NLSSORT("FAMILIEN",'nls_sort=GERMAN'),ID) I,
6 ENAM,
7 FAMILIEN,
8 GEBURT
9 FROM PATIENT
10 WHERE NLSSORT("ENAM",'nls_sort=GERMAN')>=NLSSORT('ANNA','nls_sort=GERMAN') AND (NLSSORT("ENAM",'nls_sort=GERMAN')>NLSSORT('ANNA','nls_sort=GERMAN') OR NLSSORT("FAMILIEN",'nls_sort=GERMAN')>=NLSSORT('BANANA','nls_sort=GERMAN'))
11 ORDER BY NLSSORT("ENAM",'nls_sort=GERMAN'),NLSSORT("FAMILIEN",'nls_sort=GERMAN'),ID
12 ) a
13 WHERE rownum<=5 AND (a.I>=3 OR NLSSORT("ENAM",'nls_sort=GERMAN')>NLSSORT('ANNA','nls_sort=GERMAN') OR NLSSORT("FAMILIEN",'nls_sort=GERMAN')>NLSSORT('BANANA','nls_sort=GERMAN'));
ENAM FAMILIEN GEBURT I
-------------------------------------------------- -------------------------------------------------------------------------------- --------- ----------
ANNA BANANA 05-MAY-69 3
ANNA BANANA 06-JUN-69 4
ANNA BANANA 08-AUG-69 5
ANNA Banger 03-APR-81 1
ANNA Banger 30-DEC-99 2
Execution Plan
----------------------------------------------------------
Plan hash value: 54679478
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 | 455 | 8663 (3)| 00:01:44 |
|* 1 | COUNT STOPKEY | | | | | |
|* 2 | VIEW | | 413K| 35M| 8663 (3)| 00:01:44 |
| 3 | WINDOW SORT | | 413K| 12M| 8663 (3)| 00:01:44 |
| 4 | CONCATENATION | | | | | |
|* 5 | INDEX FULL SCAN| IDX_ENAM_FAMI_ID_GEB | 363K| 11M| 2429 (3)| 00:00:30 |
|* 6 | INDEX FULL SCAN| IDX_ENAM_FAMI_ID_GEB | 50488 | 1577K| 2416 (2)| 00:00:29 |
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM<=5)
2 - filter("A"."I">=3 OR NLSSORT("ENAM",'nls_sort=''GERMAN''')>HEXTORAW('14555514
000101010100') OR NLSSORT("FAMILIEN",'nls_sort=''GERMAN''')>HEXTORAW('1A14551455140
001010101010100') )
5 - filter(NLSSORT("ENAM",'nls_sort=''GERMAN''')>HEXTORAW('14555514000101010100')
AND NLSSORT("ENAM",'nls_sort=''GERMAN''')>=HEXTORAW('14555514000101010100') )
6 - filter(NLSSORT("ENAM",'nls_sort=''GERMAN''')>=HEXTORAW('14555514000101010100'
) AND NLSSORT("FAMILIEN",'nls_sort=''GERMAN''')>=HEXTORAW('1A1455145514000101010101
0100') AND LNNVL(NLSSORT("ENAM",'nls_sort=''GERMAN''')>HEXTORAW('145555140001010101
00') ))
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
11 consistent gets
0 physical reads
0 redo size
697 bytes sent via SQL*Net to client
396 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
5 rows processed