Union All slow with order by

I have 2 queries that I do an "union all" and then an order by after the "union all" This seems to be extremely slow. But when I run the queries individually, they are really fast. Could some help me out with this please.
SELECT *
  FROM (SELECT a.*, ROWNUM rnum
          FROM (SELECT   COLS......
    FROM (((SELECT  from tables with joins)
           UNION ALL
           (SELECT from tables and view with joins))
            order by colname)
      ) a
         WHERE ROWNUM <= 500)
WHERE rnum >= 1
PLAN_TABLE_OUTPUT
Plan hash value: 3988534528
| Id  | Operation                                      | Name                          | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
|   0 | SELECT STATEMENT                               |                               |   500 |  1600K|       |  3634M  (1)|999:59:59 |       |       |
|*  1 |  VIEW                                          |                               |   500 |  1600K|       |  3634M  (1)|999:59:59 |       |       |
|*  2 |   COUNT STOPKEY                                |                               |       |       |       |            |          |       |       |
|   3 |    VIEW                                        |                               |  4277K|    13G|       |  3634M  (1)|999:59:59 |       |       |
|*  4 |     SORT ORDER BY STOPKEY                      |                               |  4277K|   311M|  1095M|  3634M  (1)|999:59:59 |       |       |
|   5 |      UNION-ALL                                 |                               |       |       |       |            |          |       |       |
PLAN_TABLE_OUTPUT
|*  6 |       FILTER                                   |                               |       |       |       |            |          |       |       |
|*  7 |        HASH JOIN                               |                               |   212K|    15M|       |   153K  (1)| 00:03:37 |       |       |
|*  8 |         HASH JOIN RIGHT OUTER                  |                               |   507 | 22308 |       |     6  (17)| 00:00:01 |       |       |
|   9 |          TABLE ACCESS FULL                     | DIR                           |   143 |  3861 |       |     2   (0)| 00:00:01 |       |       |
|  10 |          TABLE ACCESS FULL                     | USER                          |   507 |  8619 |       |     3   (0)| 00:00:01 |       |       |
|  11 |         PARTITION RANGE ITERATOR               |                               |   212K|  6645K|       |   153K  (1)| 00:03:37 |   KEY |   KEY |
|  12 |          TABLE ACCESS BY LOCAL INDEX ROWID     | FL                                |   212K|  6645K|       |   153K  (1)| 00:03:37 |   KEY |   KEY |
|* 13 |           INDEX RANGE SCAN                     | I_FL_ID                      |   382K|       |       | 38943   (2)| 00:00:56 |   KEY |   KEY |
|* 14 |            COUNT STOPKEY                       |                               |       |       |       |            |          |       |       |
|* 15 |             FILTER                             |                               |       |       |       |            |          |       |       |
|  16 |              PARTITION RANGE ITERATOR          |                               |     1 |    22 |       |   856   (1)| 00:00:02 |   KEY |   KEY |
PLAN_TABLE_OUTPUT
|* 17 |               TABLE ACCESS BY LOCAL INDEX ROWID| PAY                           |     1 |    22 |       |   856   (1)| 00:00:02 |   KEY |   KEY |
|* 18 |                INDEX RANGE SCAN                | I_PAY_FLID                       |     1 |       |       |   855   (1)| 00:00:02 |   KEY |   KEY |
|* 19 |       FILTER                                   |                               |       |       |       |            |          |       |       |
|* 20 |        HASH JOIN RIGHT OUTER                   |                               | 25019 |  3029K|       |   138K  (1)| 00:03:17 |       |       |
|  21 |         TABLE ACCESS FULL                      | DIR                            |   143 |  3861 |       |     2   (0)| 00:00:01 |       |       |
|* 22 |         HASH JOIN                              |                               | 25019 |  2369K|       |   138K  (1)| 00:03:17 |       |       |
|  23 |          TABLE ACCESS FULL                     | USER                          |   507 |  8619 |       |     3   (0)| 00:00:01 |       |       |
|* 24 |          HASH JOIN                             |                               | 25019 |  1954K|       |   138K  (1)| 00:03:17 |       |       |
|  25 |           INDEX FULL SCAN                      | PK_HO                         |   278 |  1112 |       |     1   (0)| 00:00:01 |       |       |
|* 26 |           HASH JOIN                            |                               | 25019 |  1856K|       |   138K  (1)| 00:03:17 |       |       |
|  27 |            INDEX FULL SCAN                     | PK_HO                         |   278 |  1112 |       |     1   (0)| 00:00:01 |       |       |
PLAN_TABLE_OUTPUT
|  28 |            NESTED LOOPS                        |                               | 25019 |  1759K|       |   138K  (1)| 00:03:17 |       |       |
|  29 |             PARTITION RANGE ITERATOR           |                               | 25018 |   830K|       | 63575   (1)| 00:01:30 |   KEY |   KEY |
|* 30 |              TABLE ACCESS BY LOCAL INDEX ROWID | PAY                           | 25018 |   830K|       | 63575   (1)| 00:01:30 |   KEY |   KEY |
|* 31 |               INDEX RANGE SCAN                 | I_PAY_TIME_ID                  |  1493K|       |       |  9052   (2)| 00:00:13 |   KEY |   KEY |
|* 32 |             TABLE ACCESS BY GLOBAL INDEX ROWID | FL                            |     1 |    38 |       |     3   (0)| 00:00:01 | ROWID | ROWID |
|* 33 |              INDEX UNIQUE SCAN                 | PK_FL                         |     1 |       |       |     2   (0)| 00:00:01 |       |       |
  SELECT *
  FROM (SELECT a.*, ROWNUM rnum
          FROM ( SELECT  from tables with joins order by colname) a
         WHERE ROWNUM <= 500)
WHERE rnum >= 1
PLAN_TABLE_OUTPUT
Plan hash value: 3503998222
| Id  | Operation                                     | Name                    | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
|   0 | SELECT STATEMENT                              |                         |   500 |  1228K|   222K  (1)| 00:05:15 |       |       |
|*  1 |  VIEW                                         |                         |   500 |  1228K|   222K  (1)| 00:05:15 |       |       |
|*  2 |   COUNT STOPKEY                               |                         |       |       |            |          |       |       |
|   3 |    VIEW                                       |                         |   520 |  1271K|   222K  (1)| 00:05:15 |       |       |
|*  4 |     FILTER                                    |                         |       |       |            |          |       |       |
|   5 |      NESTED LOOPS OUTER                       |                         |    26 |  1976 |    54   (0)| 00:00:01 |       |       |
PLAN_TABLE_OUTPUT
|   6 |       NESTED LOOPS                            |                         |    26 |  1274 |    48   (0)| 00:00:01 |       |       |
|   7 |        PARTITION RANGE ITERATOR               |                         |   212K|  6645K|    22   (0)| 00:00:01 |   KEY |   KEY |
|   8 |         TABLE ACCESS BY LOCAL INDEX ROWID     | FL                      |   212K|  6645K|    22   (0)| 00:00:01 |   KEY |   KEY |
|*  9 |          INDEX RANGE SCAN                     | I_FL_START_ID              |    47 |       |     8   (0)| 00:00:01 |   KEY |   KEY |
|* 10 |           COUNT STOPKEY                       |                         |       |       |            |          |       |       |
|* 11 |            FILTER                             |                         |       |       |            |          |       |       |
|  12 |             PARTITION RANGE ITERATOR          |                         |     1 |    22 |   856   (1)| 00:00:02 |   KEY |   KEY |
|* 13 |              TABLE ACCESS BY LOCAL INDEX ROWID| PAY                   |     1 |    22 |   856   (1)| 00:00:02 |   KEY |   KEY |
|* 14 |               INDEX RANGE SCAN                | I_PAY_ID               |     1 |       |   855   (1)| 00:00:02 |   KEY |   KEY |
|  15 |        TABLE ACCESS BY INDEX ROWID            | USER                     |     1 |    17 |     1   (0)| 00:00:01 |       |       |
|* 16 |         INDEX UNIQUE SCAN                     | PK_USER                  |     1 |       |     0   (0)| 00:00:01 |       |       |
PLAN_TABLE_OUTPUT
|  17 |       TABLE ACCESS BY INDEX ROWID             | DIR                    |     1 |    27 |     1   (0)| 00:00:01 |       |       |
|* 18 |        INDEX UNIQUE SCAN                      | PK_DIR                 |     1 |       |     0   (0)| 00:00:01 |       |       |
   SELECT *
  FROM (SELECT a.*, ROWNUM rnum
          FROM ( SELECT from tables and view with joins order by colname) a
         WHERE ROWNUM <= 500)
WHERE rnum >= 1
PLAN_TABLE_OUTPUT
Plan hash value: 1786470271
| Id  | Operation                                   | Name                          | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
|   0 | SELECT STATEMENT                            |                               |   500 |  1600K|  1696   (1)| 00:00:03 |       |       |
|*  1 |  VIEW                                       |                               |   500 |  1600K|  1696   (1)| 00:00:03 |       |       |
|*  2 |   COUNT STOPKEY                             |                               |       |       |            |          |       |       |
|   3 |    VIEW                                     |                               |   501 |  1596K|  1696   (1)| 00:00:03 |       |       |
|*  4 |     FILTER                                  |                               |       |       |            |          |       |       |
|   5 |      NESTED LOOPS                           |                               |   501 | 60120 |  1696   (1)| 00:00:03 |       |       |
PLAN_TABLE_OUTPUT
|   6 |       NESTED LOOPS                          |                               |   501 | 58116 |  1696   (1)| 00:00:03 |       |       |
|   7 |        NESTED LOOPS OUTER                   |                               |   501 | 56112 |  1695   (1)| 00:00:03 |       |       |
|   8 |         NESTED LOOPS                        |                               |   501 | 42585 |  1689   (1)| 00:00:03 |       |       |
|   9 |          NESTED LOOPS                       |                               |   501 | 34068 |  1550   (1)| 00:00:03 |       |       |
|  10 |           PARTITION RANGE ITERATOR          |                               |   829K|    23M|    42   (0)| 00:00:01 |   KEY |   KEY |
|  11 |            TABLE ACCESS BY LOCAL INDEX ROWID| PAY                        |   829K|    23M|    42   (0)| 00:00:01 |   KEY |   KEY |
|* 12 |             INDEX RANGE SCAN                | I_PAY_TIME_ID               |   902 |       |     9   (0)| 00:00:01 |   KEY |   KEY |
|* 13 |           TABLE ACCESS BY GLOBAL INDEX ROWID| FL                               |     1 |    38 |     3   (0)| 00:00:01 | ROWID | ROWID |
|* 14 |            INDEX UNIQUE SCAN                | PK_FL                            |     1 |       |     2   (0)| 00:00:01 |       |       |
|  15 |          TABLE ACCESS BY INDEX ROWID        | USER                              |     1 |    17 |     1   (0)| 00:00:01 |       |       |
|* 16 |           INDEX UNIQUE SCAN                 | PK_USER                           |     1 |       |     0   (0)| 00:00:01 |       |       |
PLAN_TABLE_OUTPUT
|  17 |         TABLE ACCESS BY INDEX ROWID         | DIR                          |     1 |    27 |     1   (0)| 00:00:01 |       |       |
|* 18 |          INDEX UNIQUE SCAN                  | PK_DIR                          |     1 |       |     0   (0)| 00:00:01 |       |       |
|* 19 |        INDEX UNIQUE SCAN                    | PK_HO                         |     1 |     4 |     0   (0)| 00:00:01 |       |       |
|* 20 |       INDEX UNIQUE SCAN                     | PK_HO                         |     1 |     4 |     0   (0)| 00:00:01 |       |       |
---------------------------------------------------------------------------------------------------------------------------------------------

Can you limit the number of rows coming out of each part of the UNION ALL before limiting the number of rows you're trying to return? So that you end up with something like
SELECT *
  FROM (<<Get first 500 rows from first query>>
       UNION ALL
       <<Get first 500 rows from second query>>)
WHERE rownum <= 500It appears from the query plan that your problem is that Oracle is sorting the entire result of the UNION ALL before finding the first 500 rows. That's obviously rather time consuming since the two queries return 10's of GB of data. Individually, the two queries are fast because you're limiting each of them to 500 rows, so Oracle can do a quick index scan (presumably on the sort column) that would find those rows.
And depending on what's behind the queries, I'd look to see whether you can put some additional filter conditions in place to look for data with dates in the past day or two in order to at least limit the worst case if Oracle does have to sort everything.
Justin

Similar Messages

  • Trying to create table using Union All Clause with multiple Select stmts

    The purpose of the query is to get the Substring from the value for eg.
    if the value is *2 ASA* then it should come as ASA
    where as if the value is *1.5 TST* the it sholud come as TST like wise for others too.
    I am trying to execute the below written SQL stmt but getting error as:
    *"ORA-00998 must name this expression with the column alias 00998.00000 - Must name this expression with the column alias"*
    CREATE TABLE TEST_CARE AS
    SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
    WHERE LENGTH(old_care_lvl) =5
    UNION ALL
    SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
    WHERE LENGTH(old_care_lvl) =7
    UNION ALL
    SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
    WHERE LENGTH(old_care_lvl) =14
    UNION ALL
    SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3),LEN FROM test_care_lvl
    WHERE LENGTH(old_care_lvl) =7 AND old_care_lvl ='Regular'
    I want to create the table using the above given multiple select using the Union ALL clause but when trying to create run the query getting error as "ORA-00998 must name this expression with the column alias 00998.00000 - Must name this expression with the column alias"
    Please guide me how to approach to resolve this problem.
    Thanks in advance.

    When you create a table using a SELECT statement the column names are derived from the SELECT list.
    Your problem is that one of your columns is an expression that does not work as a column name SUBSTR(old_care_lvl,3)What you need to do is alias this expression and the CREATE will pick up the alias as the column name, like this:
    CREATE TABLE TEST_CARE AS
    SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3) column3, len FROM test_care_lvl
    WHERE LENGTH(old_care_lvl) =5
    UNION ALL
    SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
    WHERE LENGTH(old_care_lvl) =7
    UNION ALL
    SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3), len FROM test_care_lvl
    WHERE LENGTH(old_care_lvl) =14
    UNION ALL
    SELECT row_id, old_care_lvl,SUBSTR(old_care_lvl,3),LEN FROM test_care_lvl
    WHERE LENGTH(old_care_lvl) =7 AND old_care_lvl ='Regular'
    );You may not like the name "column3" so use something appropriate.

  • UNION ALL slow (cost goes from 75 and 173 to 450,789!)

    Hi,
    I have two Selects (lots of joins - big tables)
    Select A) has an explain plan cost of 75
    Select B) has an explain plan cost of 173
    If I union (or union all) the cost goes up to 450,789!
    I can paste in the queries, plans etc - but if anyone has any quick ideas that'd be great.
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    What I'd like is to force the optomiser to run each query sequentially - but not really sure how.
    Any help would be really appreciated - I have few hairs left and am just about to tear the last one out!
    Cheers,
    Patrick

    Attached are the queries and the explain plan.
    I have simply tried UNION and UNION ALL to see if there's a difference (expecting UNION ALL to be faster).. but (distinct) UNION Is what I want.
    Queries
    explain plan for
    (SELECT ety_entity_identifier "a" ,
      ety_current_name "b" ,
      gment.ety_discriminant "c" ,
      upper(ind_first_name)
      || ' '
      || upper(ind_last_name) "d" ,
      CASE
        WHEN ind_last_name = NULL
        then null
      END e
    FROM gv_emr_entity_master m
    INNER JOIN gv_ety_entities gv_ety
    ON gv_ety.ety_entity_identifier = m.mtr_identifier
    AND gv_ety.ety_ety_version      = m.mtr_current_version
    AND gv_ety.ety_reg_code         = m.mtr_reg_code
    INNER JOIN gm_ety_entities gment
    ON gment.ety_id               = gv_ety.ety_id
    INNER JOIN gv_erl_entity_roles gve
    ON m.mtr_identifier       = gve.erl_entity_identifier
    AND m.mtr_current_version = gve.erl_ety_version
    INNER JOIN gm_erl_entity_roles gme
    ON gve.erl_id = gme.erl_id
    INNER JOIN gv_imr_individual_master gvm
    ON gme.erl_ind_individual_identifier = gvm.mtr_identifier
    AND gme.erl_ind_version              = gvm.mtr_current_version
    INNER JOIN gv_ind_individuals gvi
    ON gvm.mtr_identifier       = gvi.ind_individual_identifier
    AND gvm.mtr_current_version = gvi.ind_ind_version
    INNER JOIN gm_ind_individuals gmn
    ON gvi.ind_id = gmn.ind_id
    INNER JOIN gv_ias_individual_addresses gvad
    ON gvi.ind_reg_code               = gvad.ias_reg_code
    AND gvi.ind_individual_identifier = gvad.ias_individual_identifier
    AND gvi.ind_ind_version           = gvad.ias_ind_version
    INNER JOIN gm_rfr_repository_folder gmrfr
    ON gmrfr.rfr_entity_identifier = gv_ety.ety_entity_identifier
    INNER JOIN gm_rdt_repository_documents gmrdt
    ON gmrdt.rdt_rfr_id = gmrfr.rfr_id
    INNER JOIN rdi_repository_documents_info rdire
    ON rdire.rdi_rdt_id                                   = gmrdt.rdt_id
    WHERE
    gmrdt.rdt_dte_code                               IN ('OPD','PD')
    AND TO_CHAR(rdire.rdi_submission_date, 'YYYY-MM-DD') >= TO_CHAR('2007-11-01')
    and to_char(rdire.rdi_submission_date, 'YYYY-MM-DD') <= to_char('2009-01-05')
    and rownum > 0
    and rownum < 10
    union all
    SELECT ety_entity_identifier a ,
      ety_current_name "b" ,
      gment.ety_discriminant "c" ,
      gment.ety_current_name "d" ,
      gment.ety_entity_identifier "e"
    FROM gv_emr_entity_master m
    INNER JOIN gv_ety_entities gv_ety
    ON gv_ety.ety_entity_identifier = m.mtr_identifier
    AND gv_ety.ety_ety_version      = m.mtr_current_version
    AND gv_ety.ety_reg_code         = m.mtr_reg_code
    INNER JOIN gm_ety_entities gment
    ON gment.ety_id               = gv_ety.ety_id
    INNER JOIN gv_erl_entity_roles gve
    ON m.mtr_identifier       = gve.erl_entity_identifier
    AND m.mtr_current_version = gve.erl_ety_version
    INNER JOIN gm_erl_entity_roles gm_erl
    ON gve.erl_id = gm_erl.erl_id
    INNER JOIN gv_ety_entities gv_ety_temp
    ON gm_erl.erl_entity_identifier_assoc = gv_ety_temp.ety_entity_identifier
    INNER JOIN gv_emr_entity_master gv_emr_master
    ON gv_ety_temp.ety_entity_identifier = gv_emr_master.mtr_identifier
    AND gv_ety_temp.ety_ety_version      = gv_emr_master.mtr_current_version
    INNER JOIN gm_ety_entities gm_ety_temp
    ON gm_ety_temp.ety_id = gv_ety_temp.ety_id
    INNER JOIN gv_eas_entity_addresses gva
    ON gv_ety_temp.ety_reg_code           = gva.eas_reg_code
    AND gv_ety_temp.ety_entity_identifier = gva.eas_entity_identifier
    AND gv_ety_temp.ety_ety_version       = gva.eas_ety_version
    INNER JOIN gm_rfr_repository_folder gmrfr
    ON gmrfr.rfr_entity_identifier = gv_ety.ety_entity_identifier
    INNER JOIN gm_rdt_repository_documents gmrdt
    ON gmrdt.rdt_rfr_id = gmrfr.rfr_id
    INNER JOIN rdi_repository_documents_info rdire
    on rdire.rdi_rdt_id                                   = gmrdt.rdt_id
    WHERE 
    gmrdt.rdt_dte_code                               IN ('OPD','PD')
    AND gm_erl.erl_rre_name                               = 'SHR'
    AND TO_CHAR(rdire.rdi_submission_date, 'YYYY-MM-DD') >= TO_CHAR('2007-11-01')
    and to_char(rdire.rdi_submission_date, 'YYYY-MM-DD') <= to_char('2009-01-05')
    and rownum > 0
    and rownum < 10
    Plan hash value: 91542951
    | Id  | Operation                                 | Name                          | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                          |                               |    18 |  4905 |       |   450K (46)| 01:30:10 |
    |   1 |  UNION-ALL                                |                               |       |       |       |            |          |
    |*  2 |   COUNT STOPKEY                           |                               |       |       |       |            |          |
    |*  3 |    FILTER                                 |                               |       |       |       |            |          |
    |*  4 |     HASH JOIN                             |                               |   173K|    47M|    38M|   249K  (1)| 00:49:54 |
    |*  5 |      HASH JOIN                            |                               |   151K|    36M|    36M|   231K  (1)| 00:46:24 |
    |*  6 |       HASH JOIN                           |                               |   151K|    34M|    30M|   203K  (1)| 00:40:43 |
    |*  7 |        HASH JOIN                          |                               |   151K|    28M|    27M|   182K  (1)| 00:36:35 |
    |*  8 |         HASH JOIN                         |                               |   151K|    25M|    23M|   170K  (1)| 00:34:06 |
    |*  9 |          HASH JOIN                        |                               |   151K|    21M|  4840K|   140K  (1)| 00:28:05 |
    |* 10 |           HASH JOIN                       |                               | 34132 |  4433K|  3464K|   127K  (1)| 00:25:35 |
    |* 11 |            HASH JOIN                      |                               | 34419 |  3058K|  2776K|   120K  (1)| 00:24:03 |
    |* 12 |             HASH JOIN                     |                               | 34229 |  2373K|  1912K|   117K  (1)| 00:23:35 |
    |* 13 |              HASH JOIN                    |                               | 34229 |  1504K|  1440K|   114K  (1)| 00:22:49 |
    |  14 |               NESTED LOOPS                |                               | 34229 |  1036K|       | 99509   (1)| 00:19:55 |
    |* 15 |                TABLE ACCESS FULL          | RDI_REPOSITORY_DOCUMENTS_INFO | 34205 |   467K|       | 31522   (2)| 00:06:19 |
    |* 16 |                TABLE ACCESS BY INDEX ROWID| GM_RDT_REPOSITORY_DOCUMENTS   |     1 |    17 |       |     2   (0)| 00:00:01 |
    |* 17 |                 INDEX UNIQUE SCAN         | SYS_C0082075                  |     1 |       |       |     1   (0)| 00:00:01 |
    |  18 |               TABLE ACCESS FULL           | GM_RFR_REPOSITORY_FOLDER      |  2125K|    28M|       | 11843   (1)| 00:02:23 |
    |  19 |              TABLE ACCESS FULL            | GV_ETY_ENTITIES               |   953K|    23M|       |  1958   (1)| 00:00:24 |
    |  20 |             TABLE ACCESS FULL             | GV_EMR_ENTITY_MASTER          |   951K|    18M|       |   758   (2)| 00:00:10 |
    |  21 |            TABLE ACCESS FULL              | GM_ETY_ENTITIES               |   945K|    37M|       |  5120   (1)| 00:01:02 |
    |  22 |           TABLE ACCESS FULL               | GV_ERL_ENTITY_ROLES           |  4233K|    68M|       |  6413   (1)| 00:01:17 |
    |* 23 |          TABLE ACCESS FULL                | GM_ERL_ENTITY_ROLES           |  3611K|    92M|       | 22218   (1)| 00:04:27 |
    |  24 |         TABLE ACCESS FULL                 | GV_IMR_INDIVIDUAL_MASTER      |  3994K|    83M|       |  4547   (2)| 00:00:55 |
    |  25 |        TABLE ACCESS FULL                  | GV_IND_INDIVIDUALS            |  3994K|   144M|       |  9720   (1)| 00:01:57 |
    |  26 |       TABLE ACCESS FULL                   | GM_IND_INDIVIDUALS            |  4008K|    68M|       | 20842   (1)| 00:04:11 |
    |  27 |      INDEX FAST FULL SCAN                 | FKGV_IAS_IND592213_IDX        |  4564K|   139M|       |  6062   (1)| 00:01:13 |
    |* 28 |   COUNT STOPKEY                           |                               |       |       |       |            |          |
    |* 29 |    FILTER                                 |                               |       |       |       |            |          |
    |* 30 |     HASH JOIN                             |                               |  1163K|   286M|    35M|   201K  (1)| 00:40:16 |
    |* 31 |      HASH JOIN                            |                               |   150K|    33M|    30M|   180K  (1)| 00:36:11 |
    |* 32 |       HASH JOIN                           |                               |   151K|    28M|    20M|   172K  (1)| 00:34:25 |
    |  33 |        TABLE ACCESS FULL                  | GV_EMR_ENTITY_MASTER          |   951K|     9M|       |   758   (2)| 00:00:10 |
    |* 34 |        HASH JOIN                          |                               |   151K|    27M|    25M|   168K  (1)| 00:33:46 |
    |* 35 |         HASH JOIN                         |                               |   151K|    23M|  2328K|   163K  (1)| 00:32:47 |
    |* 36 |          TABLE ACCESS FULL                | GM_ERL_ENTITY_ROLES           | 99240 |  1162K|       | 22205   (1)| 00:04:27 |
    |* 37 |          HASH JOIN                        |                               |   151K|    21M|  4840K|   140K  (1)| 00:28:05 |
    |* 38 |           HASH JOIN                       |                               | 34132 |  4433K|  3464K|   127K  (1)| 00:25:35 |
    |* 39 |            HASH JOIN                      |                               | 34419 |  3058K|  2776K|   120K  (1)| 00:24:03 |
    |* 40 |             HASH JOIN                     |                               | 34229 |  2373K|  1912K|   117K  (1)| 00:23:35 |
    |* 41 |              HASH JOIN                    |                               | 34229 |  1504K|  1440K|   114K  (1)| 00:22:49 |
    |  42 |               NESTED LOOPS                |                               | 34229 |  1036K|       | 99509   (1)| 00:19:55 |
    |* 43 |                TABLE ACCESS FULL          | RDI_REPOSITORY_DOCUMENTS_INFO | 34205 |   467K|       | 31522   (2)| 00:06:19 |
    |* 44 |                TABLE ACCESS BY INDEX ROWID| GM_RDT_REPOSITORY_DOCUMENTS   |     1 |    17 |       |     2   (0)| 00:00:01 |
    |* 45 |                 INDEX UNIQUE SCAN         | SYS_C0082075                  |     1 |       |       |     1   (0)| 00:00:01 |
    |  46 |               TABLE ACCESS FULL           | GM_RFR_REPOSITORY_FOLDER      |  2125K|    28M|       | 11843   (1)| 00:02:23 |
    |  47 |              TABLE ACCESS FULL            | GV_ETY_ENTITIES               |   953K|    23M|       |  1958   (1)| 00:00:24 |
    |  48 |             TABLE ACCESS FULL             | GV_EMR_ENTITY_MASTER          |   951K|    18M|       |   758   (2)| 00:00:10 |
    |  49 |            TABLE ACCESS FULL              | GM_ETY_ENTITIES               |   945K|    37M|       |  5120   (1)| 00:01:02 |
    |  50 |           TABLE ACCESS FULL               | GV_ERL_ENTITY_ROLES           |  4233K|    68M|       |  6413   (1)| 00:01:17 |
    |  51 |         TABLE ACCESS FULL                 | GV_ETY_ENTITIES               |   953K|    23M|       |  1958   (1)| 00:00:24 |
    |  52 |       TABLE ACCESS FULL                   | GM_ETY_ENTITIES               |   945K|    34M|       |  5102   (1)| 00:01:02 |
    |  53 |      INDEX FAST FULL SCAN                 | FKGV_EAS_ENT111959_IDX        |  7325K|   146M|       |  7127   (1)| 00:01:26 |
    Query Block Name / Object Alias (identified by operation id):
       1 - SET$1      
       2 - SEL$B4C8BCFD
      15 - SEL$B4C8BCFD / RDIRE@SEL$11
      16 - SEL$B4C8BCFD / GMRDT@SEL$10
      17 - SEL$B4C8BCFD / GMRDT@SEL$10
      18 - SEL$B4C8BCFD / GMRFR@SEL$9
      19 - SEL$B4C8BCFD / GV_ETY@SEL$1
      20 - SEL$B4C8BCFD / M@SEL$1
      21 - SEL$B4C8BCFD / GMENT@SEL$2
      22 - SEL$B4C8BCFD / GVE@SEL$3
      23 - SEL$B4C8BCFD / GME@SEL$4
      24 - SEL$B4C8BCFD / GVM@SEL$5
      25 - SEL$B4C8BCFD / GVI@SEL$6
      26 - SEL$B4C8BCFD / GMN@SEL$7
      27 - SEL$B4C8BCFD / GVAD@SEL$8
      28 - SEL$5ECD7CF3
      33 - SEL$5ECD7CF3 / GV_EMR_MASTER@SEL$17
      36 - SEL$5ECD7CF3 / GM_ERL@SEL$15
      43 - SEL$5ECD7CF3 / RDIRE@SEL$22
      44 - SEL$5ECD7CF3 / GMRDT@SEL$21
      45 - SEL$5ECD7CF3 / GMRDT@SEL$21
      46 - SEL$5ECD7CF3 / GMRFR@SEL$20
      47 - SEL$5ECD7CF3 / GV_ETY@SEL$12
      48 - SEL$5ECD7CF3 / M@SEL$12
      49 - SEL$5ECD7CF3 / GMENT@SEL$13
      50 - SEL$5ECD7CF3 / GVE@SEL$14
      51 - SEL$5ECD7CF3 / GV_ETY_TEMP@SEL$16
      52 - SEL$5ECD7CF3 / GM_ETY_TEMP@SEL$18
      53 - SEL$5ECD7CF3 / GVA@SEL$19
    Predicate Information (identified by operation id):
       2 - filter(ROWNUM<10)
       3 - filter(ROWNUM>0)
       4 - access("GVI"."IND_REG_CODE"="GVAD"."IAS_REG_CODE" AND "GVI"."IND_INDIVIDUAL_IDENTIFIER"="GVAD"."IAS_INDIVIDUAL_IDENT
                  IFIER" AND "GVI"."IND_IND_VERSION"="GVAD"."IAS_IND_VERSION")
       5 - access("GVI"."IND_ID"="GMN"."IND_ID")
       6 - access("GVM"."MTR_IDENTIFIER"="GVI"."IND_INDIVIDUAL_IDENTIFIER" AND
                  "GVM"."MTR_CURRENT_VERSION"="GVI"."IND_IND_VERSION")
       7 - access("GME"."ERL_IND_INDIVIDUAL_IDENTIFIER"="GVM"."MTR_IDENTIFIER" AND
                  "GME"."ERL_IND_VERSION"="GVM"."MTR_CURRENT_VERSION")
       8 - access("GVE"."ERL_ID"="GME"."ERL_ID")
       9 - access("M"."MTR_IDENTIFIER"="GVE"."ERL_ENTITY_IDENTIFIER" AND "M"."MTR_CURRENT_VERSION"="GVE"."ERL_ETY_VERSION")
      10 - access("GMENT"."ETY_ID"="GV_ETY"."ETY_ID")
      11 - access("GV_ETY"."ETY_ENTITY_IDENTIFIER"="M"."MTR_IDENTIFIER" AND
                  "GV_ETY"."ETY_ETY_VERSION"="M"."MTR_CURRENT_VERSION" AND "GV_ETY"."ETY_REG_CODE"="M"."MTR_REG_CODE")
      12 - access("GMRFR"."RFR_ENTITY_IDENTIFIER"="GV_ETY"."ETY_ENTITY_IDENTIFIER")
      13 - access("GMRDT"."RDT_RFR_ID"="GMRFR"."RFR_ID")
      15 - filter(TO_CHAR(INTERNAL_FUNCTION("RDIRE"."RDI_SUBMISSION_DATE"),'YYYY-MM-DD')>='2007-11-01' AND
                  TO_CHAR(INTERNAL_FUNCTION("RDIRE"."RDI_SUBMISSION_DATE"),'YYYY-MM-DD')<='2009-01-05')
      16 - filter("GMRDT"."RDT_DTE_CODE"='OPD' OR "GMRDT"."RDT_DTE_CODE"='PD')
      17 - access("RDIRE"."RDI_RDT_ID"="GMRDT"."RDT_ID")
      23 - filter("GME"."ERL_IND_INDIVIDUAL_IDENTIFIER" IS NOT NULL AND "GME"."ERL_IND_VERSION" IS NOT NULL)
      28 - filter(ROWNUM<10)
      29 - filter(ROWNUM>0)
      30 - access("GV_ETY_TEMP"."ETY_REG_CODE"="GVA"."EAS_REG_CODE" AND
                  "GV_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"="GVA"."EAS_ENTITY_IDENTIFIER" AND
                  "GV_ETY_TEMP"."ETY_ETY_VERSION"="GVA"."EAS_ETY_VERSION")
      31 - access("GM_ETY_TEMP"."ETY_ID"="GV_ETY_TEMP"."ETY_ID")
      32 - access("GV_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"="GV_EMR_MASTER"."MTR_IDENTIFIER" AND
                  "GV_ETY_TEMP"."ETY_ETY_VERSION"="GV_EMR_MASTER"."MTR_CURRENT_VERSION")
      34 - access("GM_ERL"."ERL_ENTITY_IDENTIFIER_ASSOC"="GV_ETY_TEMP"."ETY_ENTITY_IDENTIFIER")
      35 - access("GVE"."ERL_ID"="GM_ERL"."ERL_ID")
      36 - filter("GM_ERL"."ERL_ENTITY_IDENTIFIER_ASSOC" IS NOT NULL AND "GM_ERL"."ERL_RRE_NAME"='SHR')
      37 - access("M"."MTR_IDENTIFIER"="GVE"."ERL_ENTITY_IDENTIFIER" AND "M"."MTR_CURRENT_VERSION"="GVE"."ERL_ETY_VERSION")
      38 - access("GMENT"."ETY_ID"="GV_ETY"."ETY_ID")
      39 - access("GV_ETY"."ETY_ENTITY_IDENTIFIER"="M"."MTR_IDENTIFIER" AND
                  "GV_ETY"."ETY_ETY_VERSION"="M"."MTR_CURRENT_VERSION" AND "GV_ETY"."ETY_REG_CODE"="M"."MTR_REG_CODE")
      40 - access("GMRFR"."RFR_ENTITY_IDENTIFIER"="GV_ETY"."ETY_ENTITY_IDENTIFIER")
      41 - access("GMRDT"."RDT_RFR_ID"="GMRFR"."RFR_ID")
      43 - filter(TO_CHAR(INTERNAL_FUNCTION("RDIRE"."RDI_SUBMISSION_DATE"),'YYYY-MM-DD')>='2007-11-01' AND
                  TO_CHAR(INTERNAL_FUNCTION("RDIRE"."RDI_SUBMISSION_DATE"),'YYYY-MM-DD')<='2009-01-05')
      44 - filter("GMRDT"."RDT_DTE_CODE"='OPD' OR "GMRDT"."RDT_DTE_CODE"='PD')
      45 - access("RDIRE"."RDI_RDT_ID"="GMRDT"."RDT_ID")
    Column Projection Information (identified by operation id):
       1 - STRDEF[200], STRDEF[4000], STRDEF[400], STRDEF[4000], STRDEF[200]
       2 - "GMN"."IND_LAST_NAME"[VARCHAR2,400], "GMN"."IND_FIRST_NAME"[VARCHAR2,400],
           "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
           "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200]
       3 - "GMN"."IND_LAST_NAME"[VARCHAR2,400], "GMN"."IND_FIRST_NAME"[VARCHAR2,400],
           "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
           "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200]
       4 - (#keys=3) "GMN"."IND_LAST_NAME"[VARCHAR2,400], "GMN"."IND_FIRST_NAME"[VARCHAR2,400],
           "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
           "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200]
       5 - (#keys=1) "GVI"."IND_INDIVIDUAL_IDENTIFIER"[VARCHAR2,200], "GVI"."IND_IND_VERSION"[NUMBER,22],
           "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
           "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GVI"."IND_REG_CODE"[VARCHAR2,200], "GMN"."IND_LAST_NAME"[VARCHAR2,400],
           "GMN"."IND_FIRST_NAME"[VARCHAR2,400]
       6 - (#keys=2) "GVI"."IND_INDIVIDUAL_IDENTIFIER"[VARCHAR2,200], "GVI"."IND_IND_VERSION"[NUMBER,22],
           "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
           "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GVI"."IND_REG_CODE"[VARCHAR2,200], "GVI"."IND_ID"[NUMBER,22]
       7 - (#keys=2) "GVM"."MTR_IDENTIFIER"[VARCHAR2,200], "GVM"."MTR_CURRENT_VERSION"[NUMBER,22],
           "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400]
       8 - (#keys=1) "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GME"."ERL_IND_VERSION"[NUMBER,22],
           "GME"."ERL_IND_INDIVIDUAL_IDENTIFIER"[VARCHAR2,200]
       9 - (#keys=2) "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GVE"."ERL_ID"[NUMBER,22]
      10 - (#keys=1) "M"."MTR_IDENTIFIER"[VARCHAR2,200], "M"."MTR_CURRENT_VERSION"[NUMBER,22],
           "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000]
      11 - (#keys=3) "M"."MTR_IDENTIFIER"[VARCHAR2,200], "M"."MTR_CURRENT_VERSION"[NUMBER,22], "GV_ETY"."ETY_ID"[NUMBER,22]
      12 - (#keys=1) "GV_ETY"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GV_ETY"."ETY_REG_CODE"[VARCHAR2,200],
           "GV_ETY"."ETY_ID"[NUMBER,22], "GV_ETY"."ETY_ETY_VERSION"[NUMBER,22]
      13 - (#keys=1) "GMRFR"."RFR_ENTITY_IDENTIFIER"[VARCHAR2,200]
      14 - (#keys=0) "GMRDT"."RDT_RFR_ID"[NUMBER,22]
      15 - "RDIRE"."RDI_RDT_ID"[NUMBER,22]
      16 - "GMRDT"."RDT_RFR_ID"[NUMBER,22]
      17 - "GMRDT".ROWID[ROWID,10]
      18 - "GMRFR"."RFR_ID"[NUMBER,22], "GMRFR"."RFR_ENTITY_IDENTIFIER"[VARCHAR2,200]
      19 - "GV_ETY"."ETY_REG_CODE"[VARCHAR2,200], "GV_ETY"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GV_ETY"."ETY_ETY_VERSION"[NUMBER,22], "GV_ETY"."ETY_ID"[NUMBER,22]
      20 - "M"."MTR_REG_CODE"[VARCHAR2,200], "M"."MTR_IDENTIFIER"[VARCHAR2,200], "M"."MTR_CURRENT_VERSION"[NUMBER,22]
      21 - "GMENT"."ETY_ID"[NUMBER,22], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400]
      22 - "GVE"."ERL_ENTITY_IDENTIFIER"[VARCHAR2,200], "GVE"."ERL_ETY_VERSION"[NUMBER,22], "GVE"."ERL_ID"[NUMBER,22]
      23 - "GME"."ERL_ID"[NUMBER,22], "GME"."ERL_IND_INDIVIDUAL_IDENTIFIER"[VARCHAR2,200], "GME"."ERL_IND_VERSION"[NUMBER,22]
      24 - "GVM"."MTR_IDENTIFIER"[VARCHAR2,200], "GVM"."MTR_CURRENT_VERSION"[NUMBER,22]
      25 - "GVI"."IND_REG_CODE"[VARCHAR2,200], "GVI"."IND_INDIVIDUAL_IDENTIFIER"[VARCHAR2,200],
           "GVI"."IND_IND_VERSION"[NUMBER,22], "GVI"."IND_ID"[NUMBER,22]
      26 - "GMN"."IND_ID"[NUMBER,22], "GMN"."IND_FIRST_NAME"[VARCHAR2,400], "GMN"."IND_LAST_NAME"[VARCHAR2,400]
      27 - "GVAD"."IAS_REG_CODE"[VARCHAR2,200], "GVAD"."IAS_INDIVIDUAL_IDENTIFIER"[VARCHAR2,200],
           "GVAD"."IAS_IND_VERSION"[NUMBER,22]
      28 - "GM_ETY_TEMP"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GM_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
           "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200]
      29 - "GM_ETY_TEMP"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GM_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
           "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200]
      30 - (#keys=3) "GM_ETY_TEMP"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GM_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
           "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200]
      31 - (#keys=1) "GV_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GV_ETY_TEMP"."ETY_ETY_VERSION"[NUMBER,22],
           "GV_ETY_TEMP"."ETY_REG_CODE"[VARCHAR2,200], "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400],
           "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GM_ETY_TEMP"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GM_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200]
      32 - (#keys=2) "GV_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GV_ETY_TEMP"."ETY_ETY_VERSION"[NUMBER,22],
           "GV_ETY_TEMP"."ETY_ID"[NUMBER,22], "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
           "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GV_ETY_TEMP"."ETY_REG_CODE"[VARCHAR2,200]
      33 - "GV_EMR_MASTER"."MTR_IDENTIFIER"[VARCHAR2,200], "GV_EMR_MASTER"."MTR_CURRENT_VERSION"[NUMBER,22]
      34 - (#keys=1) "GV_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400],
           "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GV_ETY_TEMP"."ETY_REG_CODE"[VARCHAR2,200], "GV_ETY_TEMP"."ETY_ID"[NUMBER,22], "GV_ETY_TEMP"."ETY_ETY_VERSION"[NUMBER,22]
      35 - (#keys=1) "GM_ERL"."ERL_ENTITY_IDENTIFIER_ASSOC"[VARCHAR2,200], "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000],
           "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400]
      36 - "GM_ERL"."ERL_ID"[NUMBER,22], "GM_ERL"."ERL_ENTITY_IDENTIFIER_ASSOC"[VARCHAR2,200]
      37 - (#keys=2) "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GVE"."ERL_ID"[NUMBER,22]
      38 - (#keys=1) "M"."MTR_IDENTIFIER"[VARCHAR2,200], "M"."MTR_CURRENT_VERSION"[NUMBER,22],
           "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000]
      39 - (#keys=3) "M"."MTR_IDENTIFIER"[VARCHAR2,200], "M"."MTR_CURRENT_VERSION"[NUMBER,22], "GV_ETY"."ETY_ID"[NUMBER,22]
      40 - (#keys=1) "GV_ETY"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200], "GV_ETY"."ETY_REG_CODE"[VARCHAR2,200],
           "GV_ETY"."ETY_ID"[NUMBER,22], "GV_ETY"."ETY_ETY_VERSION"[NUMBER,22]
      41 - (#keys=1) "GMRFR"."RFR_ENTITY_IDENTIFIER"[VARCHAR2,200]
      42 - (#keys=0) "GMRDT"."RDT_RFR_ID"[NUMBER,22]
      43 - "RDIRE"."RDI_RDT_ID"[NUMBER,22]
      44 - "GMRDT"."RDT_RFR_ID"[NUMBER,22]
      45 - "GMRDT".ROWID[ROWID,10]
      46 - "GMRFR"."RFR_ID"[NUMBER,22], "GMRFR"."RFR_ENTITY_IDENTIFIER"[VARCHAR2,200]
      47 - "GV_ETY"."ETY_REG_CODE"[VARCHAR2,200], "GV_ETY"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GV_ETY"."ETY_ETY_VERSION"[NUMBER,22], "GV_ETY"."ETY_ID"[NUMBER,22]
      48 - "M"."MTR_REG_CODE"[VARCHAR2,200], "M"."MTR_IDENTIFIER"[VARCHAR2,200], "M"."MTR_CURRENT_VERSION"[NUMBER,22]
      49 - "GMENT"."ETY_ID"[NUMBER,22], "GMENT"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GMENT"."ETY_CURRENT_NAME"[VARCHAR2,4000], "GMENT"."ETY_DISCRIMINANT"[VARCHAR2,400]
      50 - "GVE"."ERL_ENTITY_IDENTIFIER"[VARCHAR2,200], "GVE"."ERL_ETY_VERSION"[NUMBER,22], "GVE"."ERL_ID"[NUMBER,22]
      51 - "GV_ETY_TEMP"."ETY_REG_CODE"[VARCHAR2,200], "GV_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GV_ETY_TEMP"."ETY_ETY_VERSION"[NUMBER,22], "GV_ETY_TEMP"."ETY_ID"[NUMBER,22]
      52 - "GM_ETY_TEMP"."ETY_ID"[NUMBER,22], "GM_ETY_TEMP"."ETY_ENTITY_IDENTIFIER"[VARCHAR2,200],
           "GM_ETY_TEMP"."ETY_CURRENT_NAME"[VARCHAR2,4000]
      53 - "GVA"."EAS_REG_CODE"[VARCHAR2,200], "GVA"."EAS_ENTITY_IDENTIFIER"[VARCHAR2,200], "GVA"."EAS_ETY_VERSION"[NUMBER,22]Edited by: user12839343 on Jun 14, 2010 6:43 PM

  • UNION ALL destroys performance

    Strangely, we have 2 queries, which when they run independently, run pretty fast (2 seconds for one, instantaneous for the other), but when they're concatenated into a UNION ALL query with no ORDER BY clause, it takes 45 seconds for it to run.
    We tried pushing the SQL into a WITH clause, and some other subquery rewrites, but no perfomance boost. Has anyone seen this before?
    version 10.1.0.4
    --=Chuck

    Here are the results from DBMS_XPLAN. The prior explain plan was copied & pasted from TOAD.
    SQL> explain plan for SELECT   rownum, RUN_DATE.RUN_DATE,
      2           RUN_TIME.RUN_TIME,
      3           cc_report_work.report_name,
      4           cc_report_work.line_sequence,
      5           PURGE_DATE.PURGE_DATE,
      6           NULL AS LAD_GROUP,
      7           NULL AS NP_REASON,
      8           SUBSTR (cc_report_work.print_line, 11, 8) AS FILENR,
      9           SUBSTR (cc_report_work.print_line, 21, 27) AS CLAIMANT,
    10           SUBSTR (cc_report_work.print_line, 48, 10) AS LAD,
    11           SUBSTR (cc_report_work.print_line, 62, 11) AS SSN
    12    FROM   claims.cc_report_work,
    13           (SELECT   report_name, SUBSTR (print_line, 7, 8) AS RUN_DATE
    14              FROM   claims.cc_report_work
    15             WHERE   report_name = 'CC2518B' AND line_sequence = 8) RUN_DATE,
    16           (SELECT   report_name, SUBSTR (print_line, 124, 5) AS RUN_TIME
    17              FROM   claims.cc_report_work
    18             WHERE   report_name = 'CC2518A' AND line_sequence = 2) RUN_TIME,
    19           (SELECT   DISTINCT
    20                     report_name, SUBSTR (print_line, 66, 10) AS PURGE_DATE
    21              FROM   claims.cc_report_work
    22             WHERE   cc_report_work.report_name = 'CC2518B'
    23                     AND SUBSTR (cc_report_work.print_line, 54, 11) =
    24                           'Purged Thru') PURGE_DATE
    25   WHERE   cc_report_work.report_name = 'CC2518B'
    26           AND SUBSTR (cc_report_work.print_line, 14, 1) = ' '
    27           AND TRIM (cc_report_work.print_line) <>
    28                 'M A N U A L   P U R G E   L I S T I N G'
    29           AND cc_report_work.report_name = RUN_DATE.report_name
    30           AND cc_report_work.report_name = PURGE_DATE.report_name;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3196380662
    | Id  | Operation               | Name           | Rows  | Bytes | Cost (%CPU)|Time     |
    PLAN_TABLE_OUTPUT
    |   0 | SELECT STATEMENT        |                |     1 |   206 | 16903   (2)|00:03:23 |
    |   1 |  COUNT                  |                |       |       |            |         |
    |   2 |   MERGE JOIN CARTESIAN  |                |     1 |   206 | 16903   (2)|00:03:23 |
    |*  3 |    HASH JOIN            |                |     1 |   192 | 12674   (2)|00:02:33 |
    |   4 |     MERGE JOIN CARTESIAN|                |     1 |   128 |  8445   (2)|00:01:42 |
    |*  5 |      TABLE ACCESS FULL  | CC_REPORT_WORK |     1 |    64 |  4222   (2)|00:00:51 |
    |   6 |      BUFFER SORT        |                |     1 |    64 |  4222   (2)|00:00:51 |
    |*  7 |       TABLE ACCESS FULL | CC_REPORT_WORK |     1 |    64 |  4222   (2)|00:00:51 |
    |*  8 |     TABLE ACCESS FULL   | CC_REPORT_WORK |     1 |    64 |  4229   (2)|00:00:51 |
    |   9 |    BUFFER SORT          |                |     1 |    14 | 12675   (2)|00:02:33 |
    |  10 |     VIEW                |                |     1 |    14 |  4230   (2)|00:00:51 |
    |  11 |      SORT UNIQUE        |                |     1 |    62 |  4230   (2)|00:00:51 |
    |* 12 |       TABLE ACCESS FULL | CC_REPORT_WORK |     1 |    62 |  4229   (2)|00:00:51 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
       3 - access("CC_REPORT_WORK"."REPORT_NAME"="REPORT_NAME")
       5 - filter("REPORT_NAME"='CC2518B' AND "LINE_SEQUENCE"=8)
       7 - filter("REPORT_NAME"='CC2518A' AND "LINE_SEQUENCE"=2)
       8 - filter("CC_REPORT_WORK"."REPORT_NAME"='CC2518B' AND
                  SUBSTR("CC_REPORT_WORK"."PRINT_LINE",14,1)=' ' AND
                  TRIM("CC_REPORT_WORK"."PRINT_LINE")<>'M A N U A L   P U R G E   L I S T I N G')
      12 - filter("CC_REPORT_WORK"."REPORT_NAME"='CC2518B' AND
    PLAN_TABLE_OUTPUT
                  SUBSTR("CC_REPORT_WORK"."PRINT_LINE",54,11)='Purged Thru')
    31 rows selected.
    SQL> explain plan for SELECT   rownum, RUN_DATE.RUN_DATE,
      2           RUN_TIME.RUN_TIME,
      3           cc_report_work.report_name,
      4           cc_report_work.line_sequence,
      5           PURGE_DATE.PURGE_DATE,
      6           LAD_GROUP.LAD_GROUP,
      7           NP_REASON.NP_REASON,
      8           SUBSTR (cc_report_work.print_line, 11, 8) AS FILENR,
      9           SUBSTR (cc_report_work.print_line, 21, 31) AS CLAIMANT,
    10           SUBSTR (cc_report_work.print_line, 52, 10) AS LAD,
    11           SUBSTR (cc_report_work.print_line, 70, 11) AS SSN
    12    FROM   claims.cc_report_work,
    13           (SELECT   DISTINCT
    14                     report_name, SUBSTR (print_line, 7, 8) AS RUN_DATE
    15              FROM   claims.cc_report_work
    16             WHERE   report_name = 'CC2518C'
    17                     AND SUBSTR (print_line, 7, 8) LIKE '%/%/%') RUN_DATE,
    18           (SELECT   report_name, SUBSTR (print_line, 124, 5) AS RUN_TIME
    19              FROM   claims.cc_report_work
    20             WHERE   report_name = 'CC2518A' AND line_sequence = 2) RUN_TIME,
    21           (SELECT   DISTINCT
    22                     report_name, SUBSTR (print_line, 67, 10) AS PURGE_DATE
    23              FROM   claims.cc_report_work
    24             WHERE   report_name = 'CC2518C'
    25                     AND SUBSTR (print_line, 37, 29) =
    26                           'Claims with No Activity since') PURGE_DATE,
    27           (SELECT   TRIM (print_line) AS LAD_GROUP, page_advance
    28              FROM   claims.cc_report_work
    29             WHERE   report_name = 'CC2518C'
    30                     AND SUBSTR (print_line, 11, 13) = 'Last Activity')
    31           LAD_GROUP,
    32           (SELECT   TRIM (print_line) AS NP_REASON,
    33                     page_advance,
    34                     line_sequence,
    35                     LEAD (page_advance, 1, NULL)
    36                        OVER (ORDER BY page_advance, line_sequence)
    37                        AS NEXT_PAGE,
    38                     LEAD (line_sequence, 1, NULL)
    39                        OVER (ORDER BY page_advance, line_sequence)
    40                        AS NEXT_LINE
    41              FROM   claims.cc_report_work
    42             WHERE   cc_report_work.report_name = 'CC2518C'
    43                     AND SUBSTR (cc_report_work.print_line, 11, 20) =
    44                           'Reason for Non-Purge') NP_REASON
    45   WHERE       cc_report_work.report_name = 'CC2518C'
    46           AND cc_report_work.page_advance = LAD_GROUP.page_advance
    47           AND cc_report_work.report_name = PURGE_DATE.report_name
    48           AND cc_report_work.report_name = RUN_DATE.report_name
    49           AND SUBSTR (cc_report_work.print_line, 14, 1) = '-'
    50           AND ( (cc_report_work.page_advance = NP_REASON.page_advance
    51                  AND cc_report_work.line_sequence BETWEEN NP_REASON.line_sequence
    52                                                       AND  NP_REASON.NEXT_LINE)
    53                OR (    cc_report_work.page_advance = NP_REASON.page_advance
    54                    AND NP_REASON.NEXT_PAGE IS NULL
    55                    AND NP_REASON.NEXT_LINE IS NULL
    56                    AND cc_report_work.line_sequence > NP_REASON.line_sequence));
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 1773249683
    | Id  | Operation                 | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    PLAN_TABLE_OUTPUT
    |   0 | SELECT STATEMENT          |                |     1 |   381 | 25361   (2)| 00:05:05 |
    |   1 |  COUNT                    |                |       |       ||          |
    |   2 |   NESTED LOOPS            |                |     1 |   381 | 25361   (2)| 00:05:05 |
    |   3 |    MERGE JOIN CARTESIAN   |                |     1 |   221 | 21131   (2)| 00:04:14 |
    |   4 |     MERGE JOIN CARTESIAN  |                |     1 |   207 | 16902   (2)| 00:03:23 |
    |*  5 |      HASH JOIN            |                |     1 |   194 | 12672   (2)| 00:02:33 |
    |   6 |       MERGE JOIN CARTESIAN|                |     1 |   128 |  8447   (2)| 00:01:42 |
    |*  7 |        TABLE ACCESS FULL  | CC_REPORT_WORK |     1 |    64 |  4222   (2)| 00:00:51 |
    |   8 |        BUFFER SORT        |                |     1 |    64 |  4225   (2)| 00:00:51 |
    |*  9 |         TABLE ACCESS FULL | CC_REPORT_WORK |     1 |    64 |  4225   (2)| 00:00:51 |
    |* 10 |       TABLE ACCESS FULL   | CC_REPORT_WORK |     1 |    66 |  4225   (2)| 00:00:51 |
    |  11 |      BUFFER SORT          |                |     1 |    13 | 12677   (2)| 00:02:33 |
    |  12 |       VIEW                |                |     1 |    13 |  4230   (2)| 00:00:51 |
    |  13 |        SORT UNIQUE        |                |     1 |    62 |  4230   (2)| 00:00:51 |
    |* 14 |         TABLE ACCESS FULL | CC_REPORT_WORK |     1 |    62 |  4229   (2)| 00:00:51 |
    |  15 |     BUFFER SORT           |                |     1 |    14 | 16902   (2)| 00:03:23 |
    |  16 |      VIEW                 |                |     1 |    14 |  4230   (2)| 00:00:51 |
    |  17 |       SORT UNIQUE         |                |     1 |    62 |  4230   (2)| 00:00:51 |
    |* 18 |        TABLE ACCESS FULL  | CC_REPORT_WORK |     1 |    62 |  4229   (2)| 00:00:51 |
    |* 19 |    VIEW                   |                |     1 |   160 |  4230   (2)| 00:00:51 |
    |  20 |     WINDOW SORT           |                |     1 |    66 |  4230   (2)| 00:00:51 |
    |* 21 |      TABLE ACCESS FULL    | CC_REPORT_WORK |     1 |    66 |  4229   (2)| 00:00:51 |
    Predicate Information (identified by operation id):
       5 - access("CC_REPORT_WORK"."PAGE_ADVANCE"="PAGE_ADVANCE")
       7 - filter("REPORT_NAME"='CC2518A' AND "LINE_SEQUENCE"=2)
       9 - filter("PAGE_ADVANCE" IS NOT NULL AND "REPORT_NAME"='CC2518C' AND
                  SUBSTR("PRINT_LINE",11,13)='Last Activity')
      10 - filter("CC_REPORT_WORK"."PAGE_ADVANCE" IS NOT NULL AND
                  "CC_REPORT_WORK"."REPORT_NAME"='CC2518C' AND
                  SUBSTR("CC_REPORT_WORK"."PRINT_LINE",14,1)='-')
      14 - filter("REPORT_NAME"='CC2518C' AND SUBSTR("PRINT_LINE",7,8) LIKE '%/%/%')
      18 - filter("REPORT_NAME"='CC2518C' AND SUBSTR("PRINT_LINE",37,29)='Claims with No Activity since')
      19 - filter("CC_REPORT_WORK"."PAGE_ADVANCE"="NP_REASON"."PAGE_ADVANCE" AND
                  "CC_REPORT_WORK"."PAGE_ADVANCE" IS NOT NULL AND
                  "CC_REPORT_WORK"."LINE_SEQUENCE">="NP_REASON"."LINE_SEQUENCE" AND
                  "CC_REPORT_WORK"."LINE_SEQUENCE"<="NP_REASON"."NEXT_LINE" OR
                  "CC_REPORT_WORK"."PAGE_ADVANCE"="NP_REASON"."PAGE_ADVANCE" AND
                  "CC_REPORT_WORK"."PAGE_ADVANCE" IS NOT NULL AND "NP_REASON"."NEXT_PAGE" IS NULL AND
                  "NP_REASON"."NEXT_LINE" IS NULL AND "CC_REPORT_WORK"."LINE_SEQUENCE">"NP_REASON"."LINE_SEQUENCE")
      21 - filter("CC_REPORT_WORK"."REPORT_NAME"='CC2518C' AND
                  SUBSTR("CC_REPORT_WORK"."PRINT_LINE",11,20)='Reason for Non-Purge')
    52 rows selected.
    SQL> explain plan for SELECT   rownum, RUN_DATE.RUN_DATE,
      2           RUN_TIME.RUN_TIME,
      3           cc_report_work.report_name,
      4           cc_report_work.line_sequence,
      5           PURGE_DATE.PURGE_DATE,
      6           NULL AS LAD_GROUP,
      7           NULL AS NP_REASON,
      8           SUBSTR (cc_report_work.print_line, 11, 8) AS FILENR,
      9           SUBSTR (cc_report_work.print_line, 21, 27) AS CLAIMANT,
    10           SUBSTR (cc_report_work.print_line, 48, 10) AS LAD,
    11           SUBSTR (cc_report_work.print_line, 62, 11) AS SSN
    12    FROM   claims.cc_report_work,
    13           (SELECT   report_name, SUBSTR (print_line, 7, 8) AS RUN_DATE
    14              FROM   claims.cc_report_work
    15             WHERE   report_name = 'CC2518B' AND line_sequence = 8) RUN_DATE,
    16           (SELECT   report_name, SUBSTR (print_line, 124, 5) AS RUN_TIME
    17              FROM   claims.cc_report_work
    18             WHERE   report_name = 'CC2518A' AND line_sequence = 2) RUN_TIME,
    19           (SELECT   DISTINCT
    20                     report_name, SUBSTR (print_line, 66, 10) AS PURGE_DATE
    21              FROM   claims.cc_report_work
    22             WHERE   cc_report_work.report_name = 'CC2518B'
    23                     AND SUBSTR (cc_report_work.print_line, 54, 11) =
    24                           'Purged Thru') PURGE_DATE
    25   WHERE   cc_report_work.report_name = 'CC2518B'
    26           AND SUBSTR (cc_report_work.print_line, 14, 1) = ' '
    27           AND TRIM (cc_report_work.print_line) <>
    28                 'M A N U A L   P U R G E   L I S T I N G'
    29           AND cc_report_work.report_name = RUN_DATE.report_name
    30           AND cc_report_work.report_name = PURGE_DATE.report_name
    31  UNION ALL
    32  SELECT   rownum, RUN_DATE.RUN_DATE,
    33           RUN_TIME.RUN_TIME,
    34           cc_report_work.report_name,
    35           cc_report_work.line_sequence,
    36           PURGE_DATE.PURGE_DATE,
    37           LAD_GROUP.LAD_GROUP,
    38           NP_REASON.NP_REASON,
    39           SUBSTR (cc_report_work.print_line, 11, 8) AS FILENR,
    40           SUBSTR (cc_report_work.print_line, 21, 31) AS CLAIMANT,
    41           SUBSTR (cc_report_work.print_line, 52, 10) AS LAD,
    42           SUBSTR (cc_report_work.print_line, 70, 11) AS SSN
    43    FROM   claims.cc_report_work,
    44           (SELECT   DISTINCT
    45                     report_name, SUBSTR (print_line, 7, 8) AS RUN_DATE
    46              FROM   claims.cc_report_work
    47             WHERE   report_name = 'CC2518C'
    48                     AND SUBSTR (print_line, 7, 8) LIKE '%/%/%') RUN_DATE,
    49           (SELECT   report_name, SUBSTR (print_line, 124, 5) AS RUN_TIME
    50              FROM   claims.cc_report_work
    51             WHERE   report_name = 'CC2518A' AND line_sequence = 2) RUN_TIME,
    52           (SELECT   DISTINCT
    53                     report_name, SUBSTR (print_line, 67, 10) AS PURGE_DATE
    54              FROM   claims.cc_report_work
    55             WHERE   report_name = 'CC2518C'
    56                     AND SUBSTR (print_line, 37, 29) =
    57                           'Claims with No Activity since') PURGE_DATE,
    58           (SELECT   TRIM (print_line) AS LAD_GROUP, page_advance
    59              FROM   claims.cc_report_work
    60             WHERE   report_name = 'CC2518C'
    61                     AND SUBSTR (print_line, 11, 13) = 'Last Activity')
    62           LAD_GROUP,
    63           (SELECT   TRIM (print_line) AS NP_REASON,
    64                     page_advance,
    65                     line_sequence,
    66                     LEAD (page_advance, 1, NULL)
    67                        OVER (ORDER BY page_advance, line_sequence)
    68                        AS NEXT_PAGE,
    69                     LEAD (line_sequence, 1, NULL)
    70                        OVER (ORDER BY page_advance, line_sequence)
    71                        AS NEXT_LINE
    72              FROM   claims.cc_report_work
    73             WHERE   cc_report_work.report_name = 'CC2518C'
    74                     AND SUBSTR (cc_report_work.print_line, 11, 20) =
    75                           'Reason for Non-Purge') NP_REASON
    76   WHERE       cc_report_work.report_name = 'CC2518C'
    77           AND cc_report_work.page_advance = LAD_GROUP.page_advance
    78           AND cc_report_work.report_name = PURGE_DATE.report_name
    79           AND cc_report_work.report_name = RUN_DATE.report_name
    80           AND SUBSTR (cc_report_work.print_line, 14, 1) = '-'
    81           AND ( (cc_report_work.page_advance = NP_REASON.page_advance
    82                  AND cc_report_work.line_sequence BETWEEN NP_REASON.line_sequence
    83                                                       AND  NP_REASON.NEXT_LINE)
    84                OR (    cc_report_work.page_advance = NP_REASON.page_advance
    85                    AND NP_REASON.NEXT_PAGE IS NULL
    86                    AND NP_REASON.NEXT_LINE IS NULL
    87                    AND cc_report_work.line_sequence > NP_REASON.line_sequence));
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3197798840
    | Id  | Operation                  | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    PLAN_TABLE_OUTPUT
    |   0 | SELECT STATEMENT           |                |     2 |   609 | 42264  (61)| 00:08:28 |
    |   1 |  UNION-ALL                 |                |       |       |            |          |
    |   2 |   COUNT                    |                |       |       |            |          |
    |   3 |    MERGE JOIN CARTESIAN    |                |     1 |   206 | 16903   (2)| 00:03:23 |
    |*  4 |     HASH JOIN              |                |     1 |   192 | 12674   (2)| 00:02:33 |
    |   5 |      MERGE JOIN CARTESIAN  |                |     1 |   128 |  8445   (2)| 00:01:42 |
    |*  6 |       TABLE ACCESS FULL    | CC_REPORT_WORK |     1 |    64 |  4222   (2)| 00:00:51 |
    |   7 |       BUFFER SORT          |                |     1 |    64 |  4222   (2)| 00:00:51 |
    |*  8 |        TABLE ACCESS FULL   | CC_REPORT_WORK |     1 |    64 |  4222   (2)| 00:00:51 |
    |*  9 |      TABLE ACCESS FULL     | CC_REPORT_WORK |     1 |    64 |  4229   (2)| 00:00:51 |
    |  10 |     BUFFER SORT            |                |     1 |    14 | 12675   (2)| 00:02:33 |
    |  11 |      VIEW                  |                |     1 |    14 |  4230   (2)| 00:00:51 |
    |  12 |       SORT UNIQUE          |                |     1 |    62 |  4230   (2)| 00:00:51 |
    |* 13 |        TABLE ACCESS FULL   | CC_REPORT_WORK |     1 |    62 |  4229   (2)| 00:00:51 |
    |  14 |   COUNT                    |                |       |       |            |          |
    |  15 |    NESTED LOOPS            |                |     1 |   403 | 25361   (2)| 00:05:05 |
    |  16 |     MERGE JOIN CARTESIAN   |                |     1 |   221 | 21131   (2)| 00:04:14 |
    |  17 |      MERGE JOIN CARTESIAN  |                |     1 |   207 | 16902   (2)| 00:03:23 |
    |* 18 |       HASH JOIN            |                |     1 |   194 | 12672   (2)| 00:02:33 |
    |  19 |        MERGE JOIN CARTESIAN|                |     1 |   128 |  8447   (2)| 00:01:42 |
    |* 20 |         TABLE ACCESS FULL  | CC_REPORT_WORK |     1 |    64 |  4222   (2)| 00:00:51 |
    |  21 |         BUFFER SORT        |                |     1 |    64 |  4225   (2)| 00:00:51 |
    |* 22 |          TABLE ACCESS FULL | CC_REPORT_WORK |     1 |    64 |  4225   (2)| 00:00:51 |
    |* 23 |        TABLE ACCESS FULL   | CC_REPORT_WORK |     1 |    66 |  4225   (2)| 00:00:51 |
    |  24 |       BUFFER SORT          |                |     1 |    13 | 12677   (2)| 00:02:33 |
    |  25 |        VIEW                |                |     1 |    13 |  4230   (2)| 00:00:51 |
    |  26 |         SORT UNIQUE        |                |     1 |    62 |  4230   (2)| 00:00:51 |
    |* 27 |          TABLE ACCESS FULL | CC_REPORT_WORK |     1 |    62 |  4229   (2)| 00:00:51 |
    |  28 |      BUFFER SORT           |                |     1 |    14 | 16902   (2)| 00:03:23 |
    |  29 |       VIEW                 |                |     1 |    14 |  4230   (2)| 00:00:51 |
    |  30 |        SORT UNIQUE         |                |     1 |    62 |  4230   (2)| 00:00:51 |
    |* 31 |         TABLE ACCESS FULL  | CC_REPORT_WORK |     1 |    62 |  4229   (2)| 00:00:51 |
    |* 32 |     VIEW                   |                |     1 |   182 |  4230   (2)| 00:00:51 |
    |  33 |      WINDOW SORT           |                |     1 |    66 |  4230   (2)| 00:00:51 |
    |* 34 |       TABLE ACCESS FULL    | CC_REPORT_WORK |     1 |    66 |  4229   (2)| 00:00:51 |
    Predicate Information (identified by operation id):
       4 - access("CC_REPORT_WORK"."REPORT_NAME"="REPORT_NAME")
       6 - filter("REPORT_NAME"='CC2518B' AND "LINE_SEQUENCE"=8)
       8 - filter("REPORT_NAME"='CC2518A' AND "LINE_SEQUENCE"=2)   9 - filter("CC_REPORT_WORK"."REPORT_NAME"='CC2518B' AND
                  SUBSTR("CC_REPORT_WORK"."PRINT_LINE",14,1)=' ' AND
                  TRIM("CC_REPORT_WORK"."PRINT_LINE")<>'M A N U A L   P U R G E   LI S T I N G')
      13 - filter("CC_REPORT_WORK"."REPORT_NAME"='CC2518B' AND
                  SUBSTR("CC_REPORT_WORK"."PRINT_LINE",54,11)='Purged Thru')
      18 - access("CC_REPORT_WORK"."PAGE_ADVANCE"="PAGE_ADVANCE")
      20 - filter("REPORT_NAME"='CC2518A' AND "LINE_SEQUENCE"=2)
      22 - filter("PAGE_ADVANCE" IS NOT NULL AND "REPORT_NAME"='CC2518C' AND
                  SUBSTR("PRINT_LINE",11,13)='Last Activity')
      23 - filter("CC_REPORT_WORK"."PAGE_ADVANCE" IS NOT NULL AND
                  "CC_REPORT_WORK"."REPORT_NAME"='CC2518C' AND
                  SUBSTR("CC_REPORT_WORK"."PRINT_LINE",14,1)='-')
      27 - filter("REPORT_NAME"='CC2518C' AND SUBSTR("PRINT_LINE",7,8) LIKE '%/%/%')
      31 - filter("REPORT_NAME"='CC2518C' AND SUBSTR("PRINT_LINE",37,29)='Claims with No
                  Activity since')
      32 - filter("CC_REPORT_WORK"."PAGE_ADVANCE"="NP_REASON"."PAGE_ADVANCE" AND
                  "CC_REPORT_WORK"."PAGE_ADVANCE" IS NOT NULL AND
                  "CC_REPORT_WORK"."LINE_SEQUENCE">="NP_REASON"."LINE_SEQUENCE" AND
                  "CC_REPORT_WORK"."LINE_SEQUENCE"<="NP_REASON"."NEXT_LINE" OR
                  "CC_REPORT_WORK"."PAGE_ADVANCE"="NP_REASON"."PAGE_ADVANCE" AND
                  "CC_REPORT_WORK"."PAGE_ADVANCE" IS NOT NULL AND "NP_REASON"."NEXT_PAGE" IS NULL AND
                  "NP_REASON"."NEXT_LINE" IS NULL AND "CC_REPORT_WORK"."LINE_SEQUENCE">"NP_REASON"."LINE_SEQUENCE")
      34 - filter("CC_REPORT_WORK"."REPORT_NAME"='CC2518C' AND
                  SUBSTR("CC_REPORT_WORK"."PRINT_LINE",11,20)='Reason for Non-Purge')
    73 rows selected.--=cf

  • SQL Union all VS SSIS Union All

    I have 4 source SQL queries which is pointing different db's in the same server. All 4 queries results need to stored in single SQLServer table of different server. which one is best approach mentioned in below ?
    1) Writing SP using union all option with all four source queries and use this sp in single data flow task[single source and destination tasks].
    2) 4 source tasks to execute the 4 sql queries and then use Union all transformation to club the result and then one destination.
    3) 4 different data flow task. Each data flow task point the different souurce queries and the same destination.
    Please suggest in all aspects.

    Prabu,
    You are right in your observations from your previous post. Based on my experience, number 2 would be the best option.
    First of all, it might be best to parallelize the extraction because the time taken to read from all sources equals the time to read from the source with the highest volume of data, whereas reading from sources serially would result in a sum of the time
    taken to read from each of them individually.
    Secondly, BULK LOADS with table locks are very fast, but you can only have one process writting to the same destination at the same time, because a table level lock is placed on the object. This will probably offset the performance gains of a parallel insert
    into the same destination, but it is worth testing.
    IF, and only IF, your process uses a lot of CPU time for some reason (transformations are performed), then there is a chance option number 3 will outperform option number 2 because CPU workload would generally be split between multiple processors, but I
    dont think this is your case.
    Just because there are clouds in the sky it doesn't mean it isn't blue. Some people would disagree.

  • Help with slow union all

    Hi
    The problem Im having is that I had a query on sales order tables that used to take a couple of minutes to run. The user wanted contract orders to be added to the query and these were stored in different tables to the sales orders. I carried out union all joins in views and then applied the query to the views. Unfortunately it now takes 30 minutes to run.
    I apologise for the large post, I am just trying to provide enough information for someone to help me out.
    Any help will be greatly appreciated.
    Thanks
    Stephen
    The original query was:
    SELECT
    C_STD_COST.MAT, C_STD_COST.LAB, C_STD_COST.OHD, ITEM.PC, BILL_HDR.RATE,
    BILL_SO.SO_SHIP_QTY, BILL_SO.SO_SHIP_EXT_AMT, AR_DOC.CUSTOMER,
    BILL_SO.AR_DOC,
    CUS_LOC.NAME, AR_DOC.CREATED_DATE, MEMO.TOT_ORD_QTY, MEMO.UNIT_PRICE,
    MEMO.BOOK_RATE, AR_DOC.AR_DOC_TYPE, MEMO.MEMO_TYPE, BILL_SO.ITEM
    FROM
    AR_DOC, BILL_HDR, CUS_LOC, BILL_SO, ITEM, MEMO, C_STD_COST
    WHERE
    AR_DOC.AR_CCN=BILL_HDR.AR_CCN AND
    AR_DOC.AR_DOC_TYPE=BILL_HDR.AR_DOC_TYPE AND
    AR_DOC.AR_DOC=BILL_HDR.AR_DOC AND
    AR_DOC.CUSTOMER=CUS_LOC.CUSTOMER AND
    AR_DOC.CUS_AR_LOC=CUS_LOC.CUS_LOC AND
    BILL_HDR.AR_CCN=BILL_SO.AR_CCN AND
    BILL_HDR.AR_DOC_TYPE=BILL_SO.AR_DOC_TYPE AND
    BILL_HDR.AR_DOC=BILL_SO.AR_DOC AND
    BILL_SO.ITEM=ITEM.ITEM (+) AND
    BILL_SO.REVISION=ITEM.REVISION (+) AND
    BILL_SO.AR_DOC=MEMO.AR_DOC (+) AND
    BILL_SO.AR_DOC_LINE=MEMO.MEMO_LINE (+) AND
    BILL_SO.AR_CCN=MEMO.SALES_CCN (+) AND
    BILL_SO.AR_DOC_TYPE=MEMO.MEMO_TYPE (+) AND
    ITEM.ITEM=C_STD_COST.ITEM (+) AND
    ITEM.REVISION=C_STD_COST.REVISION (+) AND
    AR_DOC.CREATED_DATE>=TO_DATE ('30-05-2006 00:00:00', 'DD-MM-YYYY
    HH24:MI:SS') AND
    AR_DOC.CREATED_DATE<TO_DATE ('14-06-2006 00:00:00', 'DD-MM-YYYY
    HH24:MI:SS')
    ORDER BY
    AR_DOC.CUSTOMER, ITEM.PCThe explain plan showed:
    SELECT STATEMENT
    SORT                ORDER BY
    MERGE JOIN          OUTER
    SORT                JOIN
    NESTED LOOPS        OUTER
    NESTED LOOPS
    NESTED LOOPS
    NESTED LOOPS
    NESTED LOOPS        OUTER
    TABLE ACCESS        FULL              BILL_SO       4
    TABLE ACCESS        BY INDEX ROWID    ITEM          5
    INDEX               UNIQUE SCAN       PK_ITEM           UNIQUE
    TABLE ACCESS        BY INDEX ROWID    BILL_HDR      2
    INDEX               UNIQUE SCAN       PK_BILL_HDR       UNIQUE
    TABLE ACCESS        BY INDEX ROWID    AR_DOC        1
    INDEX               UNIQUE SCAN       PK_AR_DOC         UNIQUE
    TABLE ACCESS        BY INDEX ROWID    CUS_LOC       3
    INDEX               UNIQUE SCAN       PK_CUS_LOC        UNIQUE
    TABLE ACCESS        BY INDEX ROWID    MEMO          6
    INDEX               RANGE SCAN        PK_MEMO           UNIQUE
    SORT                JOIN
    TABLE ACCESS        FULL              COST_ITM      8The views I created were:
    CREATE VIEW C_BILL_DET AS
    SELECT
    AR_CCN, AR_DOC_TYPE, AR_DOC, AR_DOC_LINE, ITEM,
    REVISION, SO_SHIP_QTY, SO_SHIP_EXT_AMT, COST1
    FROM
    BILL_SO
    UNION ALL
    SELECT
    AR_CCN, AR_DOC_TYPE, AR_DOC, AR_DOC_LINE, ITEM,
    REVISION, SHIP_QTY, SHIP_EXT_AMT, COST1
    FROM
      CR_BLSH;
    CREATE VIEW C_BILL_HDR AS
    SELECT
    AR_CCN, AR_DOC_TYPE, AR_DOC, RATE
    FROM
    BILL_HDR
    UNION ALL
    SELECT
    AR_CCN, AR_DOC_TYPE, AR_DOC, RATE
    FROM
    CR_BLHD;The new query is:
    SELECT
    C_STD_COST.MAT, C_STD_COST.LAB, C_STD_COST.OHD, ITEM.PC, C_BILL_HDR.RATE,
    C_BILL_DET.SO_SHIP_QTY, C_BILL_DET.SO_SHIP_EXT_AMT, AR_DOC.CUSTOMER,
    C_BILL_DET.AR_DOC,
    CUS_LOC.NAME, AR_DOC.CREATED_DATE, MEMO.TOT_ORD_QTY, MEMO.UNIT_PRICE,
    MEMO.BOOK_RATE, AR_DOC.AR_DOC_TYPE, MEMO.MEMO_TYPE, C_BILL_DET.ITEM
    FROM
    AR_DOC, C_BILL_HDR, CUS_LOC, C_BILL_DET, ITEM, MEMO, C_STD_COST
    WHERE
    AR_DOC.AR_CCN=C_BILL_HDR.AR_CCN AND
    AR_DOC.AR_DOC_TYPE=C_BILL_HDR.AR_DOC_TYPE AND
    AR_DOC.AR_DOC=C_BILL_HDR.AR_DOC AND
    AR_DOC.CUSTOMER=CUS_LOC.CUSTOMER AND
    AR_DOC.CUS_AR_LOC=CUS_LOC.CUS_LOC AND
    C_BILL_HDR.AR_CCN=C_BILL_DET.AR_CCN AND
    C_BILL_HDR.AR_DOC_TYPE=C_BILL_DET.AR_DOC_TYPE AND
    C_BILL_HDR.AR_DOC=C_BILL_DET.AR_DOC AND
    C_BILL_DET.ITEM=ITEM.ITEM (+) AND
    C_BILL_DET.REVISION=ITEM.REVISION (+) AND
    C_BILL_DET.AR_DOC=MEMO.AR_DOC (+) AND
    C_BILL_DET.AR_DOC_LINE=MEMO.MEMO_LINE (+) AND
    C_BILL_DET.AR_CCN=MEMO.SALES_CCN (+) AND
    C_BILL_DET.AR_DOC_TYPE=MEMO.MEMO_TYPE (+) AND
    ITEM.ITEM=C_STD_COST.ITEM (+) AND
    ITEM.REVISION=C_STD_COST.REVISION (+) AND
    AR_DOC.CREATED_DATE>=TO_DATE ('30-05-2006 00:00:00', 'DD-MM-YYYY
    HH24:MI:SS') AND
    AR_DOC.CREATED_DATE<TO_DATE ('14-06-2006 00:00:00', 'DD-MM-YYYY
    HH24:MI:SS')
    ORDER BY
    AR_DOC.CUSTOMER, ITEM.PCThe explain plan is:
    SELECT STATEMENT
    SORT                ORDER BY
    MERGE JOIN          OUTER
    SORT                JOIN
    NESTED LOOPS
    NESTED LOOPS
    MERGE JOIN
    SORT                JOIN
    NESTED LOOPS        OUTER
    NESTED LOOPS        OUTER
    VIEW                                  C_BILL_DET   4
    UNION-ALL
    TABLE ACCESS        FULL              BILL_SO      9
    TABLE ACCESS        FULL              CR_BLSH      10
    TABLE ACCESS        BY INDEX ROWID    ITEM         5
    INDEX               UNIQUE SCAN       PK_ITEM           UNIQUE
    TABLE ACCESS        BY INDEX ROWID    MEMO         6
    INDEX               RANGE SCAN        PK_MEMO           UNIQUE
    SORT                JOIN
    VIEW                                  C_BILL_HDR   2
    UNION-ALL
    TABLE ACCESS        FULL              BILL_HDR     11
    TABLE ACCESS        FULL              CR_BLHD      12
    TABLE ACCESS        BY INDEX ROWID    AR_DOC       1
    INDEX               UNIQUE SCAN       PK_AR_DOC         UNIQUE
    TABLE ACCESS        BY INDEX ROWID    CUS_LOC      3
    INDEX               UNIQUE SCAN       PK_CUS_LOC        UNIQUE
    SORT                JOIN
    TABLE ACCESS        FULL              COST_ITM     8

    I don't understand.
    I try your with statement and get: "end_date" invalid identifier as an error
    I start my query out:
    WITH start_date as
    (select to_date ('08/15/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM') from dual),
    end_date as (select to_date ('08/18/2007 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM) from dual)
    select sales.id, start_date as callstart, end_date as callend
    where sales.created_timestamp >= start_date
    and sales.created_timestamp < end_date
    UNION ALL
    <<<<<<<here is where you take the last select statement and replace sales with manufacturing>>>>>>>>>>>>>
    UNION ALL
    <<<<<<<here is where you take the last select statement and replace sales with engineering>>>>>>>>>>>>>
    and it still fails.

  • Using order by with the UNION ALL operator

    Hi,
    I have 2 queries and i'm using UNION ALL to join both of them.
    And i want to sort the final result based on a column.
    When i try to do that, its not allowing me to use the ORDER BY clause.
    Any suggestions??
    Example
    select * from xxx where job='Manager'
    order by ename
    union all
    select * from yyy where job='Engineer'
    order by ename
    Thanks in advance
    --Kumar                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    SQL> select * from test_emp where deptno = 10 order by ename
      2  union all
      3  select * from test_emp where deptno = 20 order by ename;
    union all
    ERROR at line 2:
    ORA-00933: SQL command not properly ended
    SQL> select * from test_emp where deptno = 10 --order by ename
      2  union all
      3  select * from test_emp where deptno = 20 order by ename;
    select * from test_emp where deptno = 20 order by ename
    ERROR at line 3:
    ORA-00904: "ENAME": invalid identifier
    SQL> select * from test_emp where deptno = 10 --order by ename
      2  union all
      3  select * from test_emp where deptno = 20 --order by ename;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7698 BLAKE      MANAGER         7839 01-MAY-81       3141          1         10
          7782 CLARK      MANAGER         7839 09-JUN-81       2700                    10
          7839 KING       PRESIDENT            17-NOV-81       5512                    10
          7934 MILLER     CLERK           7782 23-JAN-82       1433                    10
          7369 SMITH      CLERK           7902 10-OCT-06        882        123         20
          7566 JONES      MANAGER         7839 10-OCT-06       3279        123         20
          7788 SCOTT      ANALYST         7566 11-OCT-06       3307        123         20
          7876 ADAMS      CLERK           7788 10-OCT-06       1212        123         20
          7902 FORD       ANALYST         7566 10-OCT-06       3307        123         20
    9 rows selected.
    SQL> select * from
      2  (select * from test_emp where deptno = 10 union all
      3  select * from test_emp where deptno = 20)
      4  order by ename;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7876 ADAMS      CLERK           7788 10-OCT-06       1212        123         20
          7698 BLAKE      MANAGER         7839 01-MAY-81       3141          1         10
          7782 CLARK      MANAGER         7839 09-JUN-81       2700                    10
          7902 FORD       ANALYST         7566 10-OCT-06       3307        123         20
          7566 JONES      MANAGER         7839 10-OCT-06       3279        123         20
          7839 KING       PRESIDENT            17-NOV-81       5512                    10
          7934 MILLER     CLERK           7782 23-JAN-82       1433                    10
          7788 SCOTT      ANALYST         7566 11-OCT-06       3307        123         20
          7369 SMITH      CLERK           7902 10-OCT-06        882        123         20
    9 rows selected.
    SQL>

  • Order by decode statement with Union all

    Hi
    I use Database Version: Oracle 9.2.0.1.0
    OCI version 9.2
    I try to use order by decode while i have a select base on union and I get en error:
    ORA-01785: ORDER BY item must be the number of a SELECT-list expression
    Here is my code:
    select catalog_type, catalog_id, item_id, item_name
    from items_catalog
    union all
    select catalog_type, catalog_id, organisation_unit_id, organisation_unit_name
    from units_catalog
    order by decode(catalog_type, 1, item_id, organisation_unit_id)
    If I use the decode on a select statement without union, it works.
    What I have to do in order to make it work on union all select?
    Tnx

    Hi,
    Here's a slightly different way:
    COLUMN     sort_key   NOPRINT
    VARIABLE     catalog_type_wanted     VARCHAR2 (5)
    EXEC         :catalog_type_wanted := '4'; 
    SELECT       catalog_id, item_id, item_name
    ,       CASE
               WHEN  :catalog_type_wanted = '1'  THEN  '1'
                                               ELSE  '2'
           END || item_id          AS sort_key
    FROM       items_catalog
          UNION ALL
    SELECT    catalog_id, organisation_unit_id, organisation_unit_name
    ,       CASE
               WHEN  :catalog_type_wanted = '1'  THEN  '2'
                                               ELSE  '1'
           END || organisation_unit_name     AS sort_key
    FROM       units_catalog
    ORDER BY  sort_key
    ;This way guarantees that (for example) 'SHOP50' comes before 'SHOP58', whether or not they are in the first half of the output or the second half.
    Notice that this uses the SQL*Plus COLUMN ... NOPRINT command to hide the sort_key column.
    If you're not using SQL*Plus, then whatever front end you are using may have a similar feature.
    If not, then you can do the UNION in a sub-query, as Daniel did, but do the ORDER BY in the main query (only).

  • Very slow performance with UNION and UNION ALL

    I am returning three datasets as one with a UNION ALL between each of three SQL statements. The first one returns either 3 or 4 rows, the second one returns about 10 rows and the third one returns one row. The SQL statements are a little complex but they're all working on very small datasets ( < 1000 rows ) so when I run each of the three SQL statements by themselves, they run to completion and return data in less than 1 second.
    However.
    When I join the three statements together with a UNION ALL statement between them, the statement runs until I manually abort it. I've run it for up to two hours and it shows no signs of either 1) erroring or 2) running to completion. And, I've tried replacing the UNION ALL with UNION and I get the identical results - nothing returned, no error message.
    I've checked the obvious -- same column names, same number of columns, etc. I think that if there were something obvious like that, I would get an error message as soon as I attempted to execute the statements.
    I will be happy to post the code if you'd like, but I'm wondering if anyone has experienced these or similar symptoms when joining together SQL statements with UNIONs and if so what you did to get around it.
    Thanks in advance,
    Carl

    Or I guess you could use subquery factoring (WITH clause) and MATERIALIZE hints to create the temp tables inline, e.g.
    WITH table1 AS
         ( SELECT /*+ materialize */ somecolumns FROM sometable )
       , table2 AS
         ( SELECT /*+ materialize */ somecolumns FROM othertable )
       , table2 AS
         ( SELECT /*+ materialize */  somecolumns FROM anothertable )
    SELECT somecolumns FROM table1
    UNION ALL
    SELECT somecolumns FROM table2
    UNION ALL
    SELECT somecolumns FROM table3It might also be valuable to investigate exactly what is happening and why, as this might suggest a way to address the root cause.

  • Improve performance with union all

    Hello there,
    Oracle Database 11g Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    SQL> show parameter optimizer
    ORA-00942: Tabel of view bestaat niet. (Does not exist)I have the following query using the following input variables
    - id
    - startdate
    - enddate
    The query has the following format
    - assume that the number of columns are the same
    - t1 != t3 and t2 != t4
    select ct.*
    from
      select t1.*
      from   tabel1 t1
        join tabel2 t2
          on t2.key = t1.key
      union all
      select t3.*
      from   tabel3 t3
        join tabel4 t4
          on t4.key = t3.key
    where ct.id = :id
      and ct.date >= :startdate
      and ct.date < :enddate
    order by ct.dateIt is performing really slow, after the first read it performs fast.
    I tried the following thing, which was actually even slower!
    with t1c as
    select t1.*
      from   tabel1 t1
        join tabel2 t2
          on t2.key = t1.key
    where t1.id = :id
      and t1.date >= :startdate
      and t1.date < :enddate
    t2c as
    select t3.*
      from   tabel3 t3
        join tabel4 t4
          on t4.key = t3.key
    where t3.id = :id
      and t3.date >= :startdate
      and t3.date < :enddate
    select ct.*
    from
      select *
      from   t1c
      union all
      select *
      from   t2c
    order by ct.dateSo in words, I have an 'union all' construction reading from different tables with matching columns 'id' and 'date'.
    How can I improve this? Can it be improved? If you do not know the answer, but maybe a suggestion, I will be happy aswell!!!
    Thanks in advance!
    Kind regards,
    Metroickha

    >
    So in words, I have an 'union all' construction reading from different tables with matching columns 'id' and 'date'.
    How can I improve this? Can it be improved? If you do not know the answer, but maybe a suggestion, I will be happy aswell!!!
    >
    If you want to improve on what Oracle is doing you first need to know 'what Oracle is doing'.
    Post the execution plans for the query that show what Oracle is doing.
    Also post the DDL for the tables and indexes and the record counts for the tables and ID/DATE predicates.

  • Re Creating  a chart getting an error with a 'Union All' statement

    Hi
    I have some data to chart with the following fields;
    Product , Jul-08 , Aug-08, Sep-08 etc ...... to Jan-10.
    The PRODUCT field is text showing the numerous Product Names
    The Jul-08 & other month fields have numbers per product that is to be aggregated for that month & plotted on the line graph.
    My SQL to create the first point on the chart is as below;
    select null link, PRODUCT label, SUM(JUL-08) "FFF"
    from "SCHEMANAME"."TABLENAME"
    WHERE PRODUCT = 'FFF'
    GROUP by PRODUCT
    ORDER BY PRODUCT
    This works fine until I want add the second point of this line graph using a 'union all' join as follows;
    select null link, PRODUCT label, SUM(JUL_08) "FFF"
    from "SCHEMANAME"."TABLENAME"
    WHERE PRODUCT = 'FFF'
    UNION ALL
    select null link, PRODUCT label, SUM(AUG_08) "FFF"
    from "SCHEMANAME"."TABLENAME"
    WHERE PRODUCT = 'FFF'
    I can't work out how I can join the other months on the line graph in one series.
    The error is as follows;
    1 error has occurred
    Failed to parse SQL query:
    select null link, PRODUCT label, SUM(OCT_09) "NCDS - STD" from "BI_A_DATA"."CDW_VS_NCDS_CALLS" WHERE PRODUCT = 'NCDS - STD' UNION ALL select null link, PRODUCT label, SUM(NOV_09) "NCDS - LOCAL" from "BI_A_DATA"."CDW_VS_NCDS_CALLS" WHERE PRODUCT = 'NCDS - LOCAL'
    ORA-00937: not a single-group group function
    Certain queries can only be executed when running your application, if your query appears syntactically correct, you can save your query without validation (see options below query source).
    Can anyone assist?
    I want a continuous Line Graph that shows all the months from Jul-08 , Aug-08, Sep-08 etc ...... to Jan-10 for the same product.
    I will then add other series for the other products, Thanks

    OK, I thought each month would be separated by the different months in each selct subquery, but I see what you mean.
    I'm creating a line graph for various PRODUCTS that has a numeric value for each month, from JUL_08 ..... for a number of months.
    I want a LINE graph that shows the different totals each month for that PRODUCT.
    The error advises that there are more values in the SELECT statement than the expected and to use Use the following syntax:
    SELECT LINK, LABEL, VALUE
    FROM ...
    I then went on to use the '[ ]' brackets to separate data but this didn't fix the problem.
    I've changed the script to suit as per your 'PERIOD' addition but now have the error as per below;
    error script
    1 error has occurred
    Invalid chart query: SELECT null link, PRODUCT label, PERIOD, SUM(ABC) FROM (SELECT null link, PRODUCT, 'JUL_08' PERIOD,SUM(JUL_08)ABC FROM BI_A_DATA.APEX_TEST WHERE PRODUCT = 'ABC' GROUP BY PRODUCT UNION ALL SELECT null link, PRODUCT, 'AUG_08' PERIOD,SUM(AUG_08)ABC FROM BI_A_DATA.APEX_TEST WHERE PRODUCT = 'ABC' GROUP BY PRODUCT UNION ALL SELECT null link, PRODUCT, 'SEP_08' PERIOD,SUM(SEP_08)ABC FROM BI_A_DATA.APEX_TEST WHERE PRODUCT = 'ABC' GROUP BY PRODUCT) GROUP BY link, PRODUCT, PERIOD
    Use the following syntax:
    SELECT LINK, LABEL, VALUE
    FROM ...
    Or use the following syntax for a query returning multiple series:
    SELECT LINK, LABEL, VALUE1 [, VALUE2 [, VALUE3...]]
    FROM ...
    LINK URL
    LABEL Text that displays along a chart axis.
    VALUE1, VALUE2, VALUE3... Numeric columns that define the data values.
    Note: The series names for Column and Line charts are derived from the column aliases used in the query.
    My script amended;
    SELECT null link, PRODUCT label, PERIOD, SUM(ABC)
    FROM
    (SELECT null link, PRODUCT, 'JUL_08' PERIOD,SUM(JUL_08)ABC
    FROM BI_A_DATA.APEX_TEST
    WHERE PRODUCT = 'ABC'
    GROUP BY PRODUCT
    UNION ALL
    SELECT null link, PRODUCT, 'AUG_08' PERIOD,SUM(AUG_08)ABC
    FROM BI_A_DATA.APEX_TEST
    WHERE PRODUCT = 'ABC'
    GROUP BY PRODUCT
    UNION ALL
    SELECT null link, PRODUCT, 'SEP_08' PERIOD,SUM(SEP_08)ABC
    FROM BI_A_DATA.APEX_TEST
    WHERE PRODUCT = 'ABC'
    GROUP BY PRODUCT)
    GROUP BY link, PRODUCT, PERIOD

  • TSQL verify sort order / UNION ALL

    CREATE PROCEDURE Test
    AS
    BEGIN
    SELECT * FROM (
    SELECT 1 AS a,'test1' as b, 'query1' as c
    UNION ALL
    SELECT 2 AS a,'test22' as b, 'query22' as c
    UNION ALL
    SELECT 2 AS a,'test2' as b, 'query2' as c
    UNION ALL
    SELECT 3 AS a,'test3' as b, 'query3' as c
    UNION ALL
    SELECT 4 AS a,'test4' as b, 'query4' as c
    ) As sample
    FOR XML RAW
    END
    Can we guarantee that the stored procedure returns results in given order?
    Normally it says when we insert these select query to temporary table we can't guarantee its inserting order. So we have to use order by clause. But most of time it gives same order. Can we enforce to give it some different order? Is this related with clustered
    and non clustered indices.
    In second case can we enforce inserting order by adding Identity column?
    Explain more on behind logic as well. I'm checking whether I need to add ORDER BY in old Stored Procedures or not.

    Can we guarantee that the stored procedure returns results in given order?  
    No. The only way to get a guaranteed order is to use an ORDER BY clause.
    Normally it says when we insert these select query to temporary table we can't guarantee its inserting order. So we have to use order by clause. But most of time it gives same order. Can we enforce to give it some different order? Is this related with
    clustered and non clustered indices.  
    The only way to get a guaranteed order is to use an ORDER BY clause. Anything else is happenstance.
    In second case can we enforce inserting order by adding Identity column?   Explain more on behind logic as well. I'm checking whether I need to add ORDER BY in old Stored Procedures or not.
    Again: the only way to get a guaranteed order is to use an ORDER BY clause.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Query using Union All and CTEs is slow

    TypePatient
    [ednum] int NOT NULL,  PK
    [BackgroundID] int NOT NULL, FK
    [Patient_No] varchar(50) NULL, FK
    [Last_Name] varchar(30) NULL,
    [First_Name] varchar(30) NULL,
    [ADateTime] datetime NULL,
    Treat
    [ID] int NOT NULL, PK
    [Ednum] numeric(10, 0) NOT NULL, FK
    [Doctor] char(50) NULL,
    [Dr_ID] numeric(10, 0) NULL,
    background
    [ID] int NOT NULL, PK
    [Patient_No] varchar(50) NULL, FK
    [Last_Name] char(30) NULL,
    [First_Name] char(30) NULL,
    [DateofBirth] datetime NULL,
    pdiagnose
    [ID] int NOT NULL, PK
    [Ednum] int NOT NULL, FK
    [DSMNo] char(10) NULL,
    [DSMNoIndex] char(5) NULL,
    substance
    [ID] int NOT NULL, PK
    [Ednum] int NOT NULL, FK
    [Substance] varchar(120) NULL,
    DXCAT
    [id] int NULL, PK
    [dx_description] char(100) NULL,
    [dx_code] char(10) NULL,
    [dx_category_description] char(100) NULL,
    [diagnosis_category_code] char(10) NULL)
    Substance
    ID
    Ednum
    Substance
    1
    100
    Alcohol Dependence
    4
    200
    Caffeine Dependence
    5
    210
    Cigarettes
    dxcat
    id
    dx_description
    dx_code
    dx_category_description
    diagnosis_category_code
    10
    Tipsy
    zzz
    Alcohol
    SA
    20
    Mellow
    ppp
    Mary Jane
    SA
    30
    Spacey
    fff
    LSD
    SA
    50
    Smoker
    ggg
    Nicotine
    SA
    pdiagnose
    ID
    Ednum
    DSMNo
    Diagnosis
    1
    100
    zzz
    Alcohol
    2
    100
    ddd
    Caffeine
    3
    210
    ggg
    Smoker
    4
    130
    ppp
    Mary Jane
    TypePatient
    ednum
    Patient_No
    Last_Name
    First_Name
    ADateTime
    100
    sssstttt
    Wolly
    Polly
    12/4/2013
    130
    rrrrqqqq
    Jolly
    Molly
    12/8/2013
    200
    bbbbcccc
    Wop
    Doo
    12/12/2013
    210
    vvvvwww
    Jazz
    Razz
    12/14/2013
    Treat
    ID
    Ednum
    Doctor
    Dr_ID
    2500
    100
    Welby, Marcus
    1000
    2550
    200
    Welby, Marcus
    1000
    3000
    210
    Welby, Marcus
    1000
    3050
    130
    Welby, Marcus
    1000
    background
    ID
    Patient_No
    Last_Name
    First_Name
    DateofBirth
    2
    sssstttt
    Wolly
    Polly
    8/6/1974
    3
    rrrrqqqq
    Jolly
    Molly
    3/10/1987
    5
    bbbbcccc
    Wop
    Doo
    8/12/1957
    6
    vvvvwww
    Jazz
    Razz
    7/16/1995
    Desired output:
    Staff ID
    Doctor
    Patient_No
    Client Name
    Date of Service
    Ednum
    DX Code
    DX Cat
    DX Desc
    Substance
    1000
    Welby, Marcus
    bbbcccc
    Wop, Doo
    12/12/2013
    200
    Caffeine Dependence
    1000
    Welby, Marcus
    rrrqqq
    Jolly, Molly
    12/8/2013
    130
    ppp
    SA
    Mary Jane
    1000
    Welby, Marcus
    sssttt
    Wolly, Polly
    12/4/2013
    100
    zzz
    SA
    Alcohol
    1000
    Welby, Marcus
    sssttt
    Wolly, Polly
    12/4/2013
    100
    ddd
    SA
    LSD
    1000
    Welby, Marcus
    sssttt
    Wolly, Polly
    12/4/2013
    100
    Alcohol Dependence
    1000
    Welby, Marcus
    vvvvwww
    Jazz, Razz
    12/14/2013
    210
    ggg
    SA
    Smoker
    1000
    Welby, Marcus
    vvvvwww
    Jazz, Razz
    12/14/2013
    210
    Cigarettes
    A patient is assigned an ednum. There are two different menus for staff to enter
    diagnoses. Each menu stores the entries in a different table. The two tables are substance and pdiagnose. A patient’s diagnosis for a substance abuse can be entered in one table and not the other. 
    The number of entries for different substances for each patient can vary between the two tables. John Doe might be entered for alcohol and caffeine abuse in the pdiagnosis table and entered only for caffeine abuse in the substance table. They are only
    linked by the ednum which has nothing to do with the diagnosis/substance. The substance entered in one table is not linked to the substance entered in the other. A query will not put an entry for alcohol from the pdiagnosis table on the same row as an alcohol
    entry from the substance table except by chance. That is the reason for the way the query is written.
    The query accepts parameters for a Dr ID and a start and end date. It takes about 7 to 15 seconds to run. Hard coding the dates cuts it down to about a second.
    I might be able to select directly from the union all query instead of having it separate. But then I’m not sure about the order by clauses using aliases.
    Is there a way to rewrite the query to speed it up?
    I did not design the tables or come up with the process of entering diagnoses. It can’t be changed at this time.
    Please let me know if you notice any inconsistencies between the DDLs, data, and output. I did a lot of editing.
    Thanks for any suggestions.
    with cte_dxcat (Dr_ID, Doctor, Patient_No,Last_Name,
    First_Name, Adatetime,Ednum,
    dx_code,diagnosis_category_code,dx_description,substance,
    DateofBirth) as
    (Select distinct t.Dr_ID, t.Doctor, TP.Patient_No,TP.Last_Name,
    TP.First_Name, TP.Adatetime as 'Date of Service',TP.Ednum,
    DXCAT.dx_code,DXCAT.diagnosis_category_code,DXCAT.dx_description,
    null as 'substance',BG.DateofBirth
    From TypePatient TP
    inner join treat t on TP.ednum = t.Ednum
    inner join background BG on BG.Patient_No = TP.Patient_No
    inner join pdiagnose PD on TP.Ednum = PD.Ednum
    inner join Live_Knowledge.dbo.VA_DX_CAT_MAPPING DXCAT on DXCAT.dx_code = PD.DSMNo
    Where (TP.Adatetime >= convert(varchar(10), :ST, 121)+ ' 00:00:00.000'
    and TP.Adatetime <= convert(varchar(10), :SP, 121)+ ' 23:59:59.000')
    and DXCAT.diagnosis_category_code = 'SA'
    and t.Dr_ID =:DBLookupComboBox2
    cte_substance (Dr_ID, Doctor, Patient_No,Last_Name,
    First_Name,Adatetime, Ednum,
    dx_code,diagnosis_category_code,dx_description,Substance,DateofBirth) as
    (Select distinct t.Dr_ID, t.Doctor, TP.Patient_No,TP.Last_Name,
    TP.First_Name, TP.Adatetime as 'Date of Service', TP.Ednum,
    null as 'dx_code',null as 'diagnosis_category_code',null as 'dx_description',s.Substance, BG.DateofBirth
    From TypePatient TP
    inner join treat t on TP.ednum = t.Ednum
    inner join background BG on BG.Patient_No = TP.Patient_No
    inner join pdiagnose PD on TP.Ednum = PD.Ednum
    inner join substance s on TP.Ednum = s.Ednum
    Where (TP.Adatetime >= convert(varchar(10), '12/1/2013', 121)+ ' 00:00:00.000'
    and TP.Adatetime <= convert(varchar(10), '12/31/2013', 121)+ ' 23:59:59.000')
    and t.Dr_ID =:DBLookupComboBox2
    cte_all (Dr_ID, Doctor, Patient_No,Last_Name,
    First_Name,Adatetime, Ednum,
    dx_code,diagnosis_category_code,dx_description,Substance,DateofBirth) as
    (select cte_dxcat.Dr_ID as 'Staff ID', cte_dxcat.Doctor as 'Doctor',
    cte_dxcat.Patient_No as 'Patient_No',
    cte_dxcat.Last_Name as 'Last',cte_dxcat.First_Name as 'First',
    cte_dxcat.Adatetime as 'Date of Service',cte_dxcat.Ednum as 'Ednum',
    cte_dxcat.dx_code as 'DX Code',cte_dxcat.diagnosis_category_code as 'DX Category Code',
    cte_dxcat.dx_description as 'DX Description',
    cte_dxcat.substance as 'Substance',cte_dxcat.DateofBirth as 'DOB'
    from cte_dxcat
    union all
    select cte_substance.Dr_ID as 'Staff ID', cte_substance.Doctor as 'Doctor',
    cte_substance.Patient_No as 'Patient_No',
    cte_substance.Last_Name as 'Last',cte_substance.First_Name as 'First',
    cte_substance.Adatetime as 'Date of Service',cte_substance.Ednum as 'Ednum',
    cte_substance.dx_code as 'DX Code',cte_substance.diagnosis_category_code as 'DX Category Code',
    cte_substance.dx_description as 'DX Description',
    cte_substance.substance as 'Substance',cte_substance.DateofBirth as 'DOB'
    from cte_substance)
    select cte_all.Dr_ID as 'Staff ID', cte_all.Doctor as 'Doctor',
    cte_all.Patient_No as 'Patient_No',
    (cte_all.Last_Name + ', '+ cte_all.First_Name) as 'Client Name',
    cte_all.Adatetime as 'Date of Service',cte_all.Ednum as 'Ednum',
    cte_all.dx_code as 'DX Code',cte_all.diagnosis_category_code as 'DX Category Code',
    cte_all.dx_description as 'DX Description',
    cte_all.substance as 'Substance',
    CONVERT(char(10), cte_all.DateofBirth,101) as 'DOB'
    from cte_all
    order by cte_all.Patient_No,cte_all.Adatetime

    Please post real DDL instead of your invented non-language, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions
    and formatting rules. Your rude, non-SQL narrative is so far away from standards I cannot even use you as a bad example in book. 
    Temporal data should use ISO-8601 formats (we have to re-type the dialect you used!). Code should be in Standard SQL as much as possible and not local dialecT. 
    This is minimal polite behavior on SQL forums. You posted a total mess! Do you really have patients without names?? You really use a zero to fifty characters for a patient_nbr??? Give me an example. That is insane! 
    Your disaster has more NULLs than entire major corporate systems. Since you cannot change it, can you quit? I am serious. I have been employed in IT since 1965, and can see a meltdown.
    I looked at this and I am  not even going to try to help you; it is not worth it. I am sorry for you; you are in an environment where you cannot learn to do any right. 
    But you are still responsible for the rudeness of not posting DDL. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Different results using View with union all in 11R1 compared to 10R2

    Hello,
    I have the following situation:
    In Oracle 10R2 I defined a view which looks like this
    create view test_view
    as
    select 'field1;field2;field3' field from dual
    union all
    select field
    from (
    select tfield1||';'||tfield2||';'||tfield3 field
    from table1
    order by tfield1,tfield2,tfield3
    The idea is, my first line contains a header information an then the data in the required sorting order.
    So, in 10R2, when I export the view with select field from test_view, I get the result as expected, which means, the header from the part with the dual was in the first line and after that, the data in the required sort order.
    Now, in 11.1.0.7, it is completely different, because the row of the dual is somewhere in my result set. But if I send the sql instead of the view, I get the expected result as in 10R2.
    I have no idea why this is the case now, because in 10R2 this was working permanently as expected. When I look at the execution plan, I see, that he starts parallelisation, which is ok, but the difference is, that in this parallelisation the select from dual is included and in 10R2 he first make the line from the dual and then the parallelisation with the data. It's not clear to me, that if I send the sql to the database I see the required result, but if i define the view as mentioned, and start a select field from view, I get now get the different sorting, because of the parallelisation, where the optimizer he changes his behavior comparing the both database versions. So my question ist, how can I change this behavior to get the same behavior as in release 10R2.
    Best regards
    Rainer

    Hello,
    thank you for your sample, I see your idea for my sorting purpose.
    I want to look at the following point:
    I create the table, as you described. The table has the degree and instances 1. Now I deefine the following view:
    create view view_test
    as
    select 'field1;field2;field3' field
    from dual
    union all
    select tfield1 || ';' || tfield2 || ';' || tfield3 field
    from (select * from table1 order by tfield1,tfield2).
    This is the way I used it in 10 R2.
    Now, the SQL select field from view_test delivers the expected result:
    field1;field2;field3
    a;b;c
    d;e;f
    So far so good. But now, I changed the degree of the table1 (alter table table1 parallel (degree 4 instances 1);).
    The result looks like that:
    a;b;c
    field1;field2;field3
    d;e;f
    So, the parallelisation of my object seems to be the reason for the, in my eyes, "wrong" sort order. In 10R2 I used this degree and instance values for my table and defined a view and it was working fine. Now, after our migration, I had this "trouble". For me it seems, that the optimizer made some changes, or mabe this is a bug, who knows ?
    I also tried, to change the nls_comp, and set the undocumented parameters as described in the Metalink note 7497640.8, but with no effect of my result set.
    Best regards
    Rainer

  • Materalized view with union all and fast referesh

    I have a one view which is very slow. in this view we are joining many tables and many union all queries.
    now I am planing to make materalized view
    Tell me how i will created view with fast refresh with union all query.
    Pls help its urgent..
    Thanks
    Reena

    Refer to the Replication Manual for the create syntax and exceptions.

Maybe you are looking for