Concatenation and Union all

Hi,
From Oracle 9i performance guide:
"Concatenation is useful for statements with different conditions combined with an OR clause"
"If a query contains a WHERE clause with multiple conditions combined with OR operators, then the optimizer transforms it into an equivalent compound query that uses the UNION ALL set operator, if this makes the query execute more efficiently"
Can anyone tell me when concatenation is better than union and vice versa?

skde wrote:
Hi,
From Oracle 9i performance guide:
"Concatenation is useful for statements with different conditions combined with an OR clause"
"If a query contains a WHERE clause with multiple conditions combined with OR operators, then the optimizer transforms it into an equivalent compound query that uses the UNION ALL set operator, if this makes the query execute more efficiently"
Can anyone tell me when concatenation is better than union and vice versa?Concatenation is not exactly the same as UNION ALL (the ALL is important, by the way), as it has to eliminate repetitions of data. You may rewrite an 'OR' query as a UNION ALL, concatenation is simply Oracle's strategy for doing this. There's an example on my blog which might help you understand the issues: http://jonathanlewis.wordpress.com/2007/02/26/subquery-with-or/
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk
To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format.
There is a +"Preview"+ tab at the top of the text entry panel. Use this to check what your message will look like before you post the message. If it looks a complete mess you're unlikely to get a response. (Click on the +"Plain text"+ tab if you want to edit the text to tidy it up.)
+"I believe in evidence. I believe in observation, measurement, and reasoning, confirmed by independent observers. I'll believe anything, no matter how wild and ridiculous, if there is evidence for it. The wilder and more ridiculous something is, however, the firmer and more solid the evidence will have to be."+
Isaac Asimov                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Materialized view issue with spatial index and UNION all.

    Hi guys,
    I'm trying to build the following materialized view:
    create materialized VIEW MV_ElectricalStuffs
      refresh fast
      AS
      SELECT jb.ROWID,
        jb.FID,
        JB.NAME_NUMBER
      FROM EL_BUS_BAR jb
      UNION ALL
      SELECT INC.ROWID,
        INC.FID,
        NULL,
        INC.NAME_NUMBER
      FROM EL_INTERNAL_CELL INC;
    I have this error showing up:
    ORA-12015: cannot create a fast refresh materialized view from a complex query
    This is because the table EL_INTERNAL_CELL has a SDO_GEOMETRY column that has a spatial index, whose ddl is
    CREATE INDEX EL_INTERNAL_CELL_S ON EL_INTERNAL_CELL (GEOM) INDEXTYPE IS MDSYS.SPATIAL_INDEX
    PARAMETERS('SDO_INDX_DIMS=2 TABLESPACE=USERS LAYER_GTYPE=COLLECTION');
    When I remove the spatial index from EL_INTERNAL_CELL column GEOM, Oracle is very happy and creates the view.
    Is there a mean however to keep the spatial index in the materialized view?

    I've managed to drop the spatial index prior to create the materialized view and it is ok. After the materialized view creation, I've recreated the spatial index on the table and all ran smooth. Hope nothing will go bad in the future because of this trick on spatial index..

  • 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.

  • Oracle doc inconsistent on materialize view with union all and self joins

    First of all, I can't seem to create a materialized view containing self-joins AND union all. Is it possible?
    I checked Oracle 9i (my version: PL/SQL Release 9.2.0.4.0 - Production) documentation and I get different answers (or so it seems to me).
    First I saw this: "The COMPATIBILITY parameter must be set to 9.0 if the materialized aggregate view has inline views, outer joins, self joins or grouping sets and FAST REFRESH is specified during creation..."
    Did you see the part about 'self joins' in there? I did and I was pumped because that seems to say that you CAN have 'self joins' (and my compatibility is 9.2...)
    BUT
    In the very same document I also found "Oracle does not allow self-joins in materialized join views." (rage)
    You can see the document I am speaking of here: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96520/mv.htm#574889
    Whenever I try to create the mview I get the following error. (
    In any caseORA-01446 cannot select ROWID from view with DISTINCT, GROUP BY, etc.

    First of all, I can't seem to create a materialized view containing self-joins AND union all. Is it possible?
    I checked Oracle 9i (my version: PL/SQL Release 9.2.0.4.0 - Production) documentation and I get different answers (or so it seems to me).
    First I saw this: "The COMPATIBILITY parameter must be set to 9.0 if the materialized aggregate view has inline views, outer joins, self joins or grouping sets and FAST REFRESH is specified during creation..."
    Did you see the part about 'self joins' in there? I did and I was pumped because that seems to say that you CAN have 'self joins' (and my compatibility is 9.2...)
    BUT
    In the very same document I also found "Oracle does not allow self-joins in materialized join views." (rage)
    You can see the document I am speaking of here: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96520/mv.htm#574889
    Whenever I try to create the mview I get the following error. (
    In any caseORA-01446 cannot select ROWID from view with DISTINCT, GROUP BY, etc.

  • 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

  • Report which concatenates 13 views with union all running slowly

    Oracle 8.1.7 windows 2000 server
    I am trying to improve the performance of a report which is comprised of 13 views.
    When I run each of the views individually, the total run time for the views is less than 5 minutes. When I run the report, it takes 28 minutes.
    Can anyone suggest why the extra time is being taken?
    To reiterate:
    select a,b from c; (executes in 10 seconds)
    select d, e from f (executes in 3 seconds)
    select x, y from z (executes in 1 minute)
    total runs time = 5 minutes
    However,
    select a,b from c
    union all
    select d, e from f
    union all
    select x, y from z (executes in 28 minutes)
    The execution plans do not change between the report and the indiividual views. Views are being concatenated with union all so no sorting is taking place
    Many thanks,
    Jason Parker.
    Edited by: jclparker on Feb 18, 2009 4:26 AM
    Edited by: jclparker on Feb 18, 2009 4:30 AM

    Could you post the execution plan? Please use formatting tags to save the white space while posting the plan.

  • Union All with Linked Servers - Works until loaded on to the report server then fails.

    Hi,
    On our production server I have 2 linked servers.  One that leads to ServiceNow via ODBC and one that leads to an HP Openview database.
    Testing these linked servers works fine.  I have a query that obtains info from each source and 'union all' together.  When i run this query in SQL Server management studio it works fine and I get info from both data sources union-ed together perfectly.
    I transfer this into Visual Studio and create a report, which again runs perfectly.
    I upload this report to the report server and try to run it and get the error: 
    An error has occurred during report processing. (rsProcessingAborted)
    Query execution failed for dataset 'Dataset1'. (rsErrorExecutingCommand)
    For more information about this error navigate to the report server on the local server machine, or enable remote errors
    When I rummage through the log files for the report server, I find very little helpful errors, basically this:
    ERROR: Throwing Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: , Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: Query execution failed for dataset 'Dataset1'. ---> System.Data.SqlClient.SqlException: Cannot
    execute the query.
    I did a test where I created a copy of the report and ran only he Servicenow  section of the report and it works, then ran only the HP section of the report and it works.  It seems the UNION ALL is the problem somehow. 
    Anyone have any ideas??
    Thanks
    Kirsty

    Hi Kirsty,
    As you posted, this issue is caused by the security configuration of Linked Server.
    Generally, in a domain environment, we can specify a domain account as the stored credentials for the report, and then configure the Linked Server to "Be made using the login’s current security context".
    However,if we specify a SQL Server login as the stored credentials for the report, please set the Linked Server security to "By using this security context", and then providing the necessary credentials to authenticate at the linked server.
    Please also add the Reporting Services Security role to the Linked Server Remote Server Login Mappings.
    For more information about Creating Linked Servers, please refer to
    http://msdn.microsoft.com/en-us/library/ff772782.aspx
    About Security for Linked Servers, please refer to
    http://msdn.microsoft.com/en-us/library/ms175537.aspx
    Regards,
    Swallow

  • 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

  • Inconsistent SQL results when using View with UNION-ALL and table function

    Can any of you please execute the below scripts and check the output. In the table type variable, I am adding 4 distinct object ids, where as in the result, I get only the row pertaining to last id in the table type variable. Same row is returned 4 times (4= number of values in the table type).
    This scenario is occurring in our product with a SQL with exactly same pattern. I could simulate the same issue with the sample script I have provided.
    Database version: 11.2.0.3 Enterprise Edition, Single node
    Thank you.
    CREATE TABLE TEMP_T1 AS SELECT * FROM ALL_OBJECTS;
    CREATE TABLE TEMP_T2 AS SELECT * FROM ALL_OBJECTS;
    UPDATE TEMP_T2 SET OBJECT_ID = OBJECT_ID * 37;
    CREATE UNIQUE INDEX TEMP_T1_U1 ON TEMP_T1(OBJECT_ID);
    CREATE UNIQUE INDEX TEMP_T2_U1 ON TEMP_T2(OBJECT_ID);
    CREATE OR REPLACE VIEW TEMP_T1T2_V AS
    SELECT * FROM TEMP_T1 UNION ALL SELECT * FROM TEMP_T2;
    CREATE OR REPLACE TYPE TEMP_OBJ_TYPE AS OBJECT (OBJ_ID NUMBER);
    CREATE OR REPLACE TYPE TEMP_OBJ_TAB_TYPE IS TABLE OF TEMP_OBJ_TYPE;
    SET SERVEROUTPUT ON;
    DECLARE
    TYPE TEMP_T1T2_V_ROW_TAB_TYPE IS TABLE OF TEMP_T1T2_V%ROWTYPE;
    TEMP_T1T2_V_ROW_TAB TEMP_T1T2_V_ROW_TAB_TYPE;
    TEMP_OBJ_TAB TEMP_OBJ_TAB_TYPE := TEMP_OBJ_TAB_TYPE();
    PROCEDURE ADD_TO_TEMP_OBJ_TAB(OBJ_ID IN NUMBER) IS
    BEGIN
    TEMP_OBJ_TAB.EXTEND;
    TEMP_OBJ_TAB(TEMP_OBJ_TAB.LAST) := TEMP_OBJ_TYPE(OBJ_ID);
    END;
    BEGIN
    ADD_TO_TEMP_OBJ_TAB(100);
    ADD_TO_TEMP_OBJ_TAB(116);
    ADD_TO_TEMP_OBJ_TAB(279);
    ADD_TO_TEMP_OBJ_TAB(364);
    DBMS_OUTPUT.PUT_LINE('=====================');
    FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
    LOOP
    DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('---------------------');
    SELECT * BULK COLLECT INTO TEMP_T1T2_V_ROW_TAB
    FROM TEMP_T1T2_V VW
    WHERE ((VW.OBJECT_ID) IN (SELECT OBJ_ID
    FROM TABLE(CAST(TEMP_OBJ_TAB AS TEMP_OBJ_TAB_TYPE))));
    FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
    LOOP
    DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('---------------------');
    IF TEMP_T1T2_V_ROW_TAB.COUNT > 0 THEN
    FOR I IN TEMP_T1T2_V_ROW_TAB.FIRST..TEMP_T1T2_V_ROW_TAB.LAST
    LOOP
    DBMS_OUTPUT.PUT_LINE(TEMP_T1T2_V_ROW_TAB(I).OBJECT_ID||' : '||TEMP_T1T2_V_ROW_TAB(I).OBJECT_NAME);
    END LOOP;
    ELSE
    DBMS_OUTPUT.PUT_LINE('NO ROWS RETURNED!');
    END IF;
    DBMS_OUTPUT.PUT_LINE('---------------------');
    END;
    /

    I can reproduce it:
    SQL*Plus: Release 11.2.0.3.0 Production on Tue Oct 30 14:05:39 2012
    Copyright (c) 1982, 2011, Oracle.  All rights reserved.
    Enter user-name: scott
    Enter password:
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> select  *
      2    from  v$version
      3  /
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    SQL> CREATE TABLE TEMP_T1 AS SELECT * FROM ALL_OBJECTS;
    Table created.
    SQL>
    SQL> CREATE TABLE TEMP_T2 AS SELECT * FROM ALL_OBJECTS;
    Table created.
    SQL>
    SQL> UPDATE TEMP_T2 SET OBJECT_ID = OBJECT_ID * 37;
    72883 rows updated.
    SQL>
    SQL> CREATE UNIQUE INDEX TEMP_T1_U1 ON TEMP_T1(OBJECT_ID);
    Index created.
    SQL>
    SQL> CREATE UNIQUE INDEX TEMP_T2_U1 ON TEMP_T2(OBJECT_ID);
    Index created.
    SQL>
    SQL> CREATE OR REPLACE VIEW TEMP_T1T2_V AS
      2  SELECT * FROM TEMP_T1 UNION ALL SELECT * FROM TEMP_T2;
    View created.
    SQL>
    SQL> CREATE OR REPLACE TYPE TEMP_OBJ_TYPE AS OBJECT (OBJ_ID NUMBER)
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE TEMP_OBJ_TAB_TYPE IS TABLE OF TEMP_OBJ_TYPE
      2  /
    Type created.
    SQL> SET SERVEROUTPUT ON;
    SQL>
    SQL> DECLARE
      2  TYPE TEMP_T1T2_V_ROW_TAB_TYPE IS TABLE OF TEMP_T1T2_V%ROWTYPE;
      3  TEMP_T1T2_V_ROW_TAB TEMP_T1T2_V_ROW_TAB_TYPE;
      4  TEMP_OBJ_TAB TEMP_OBJ_TAB_TYPE := TEMP_OBJ_TAB_TYPE();
      5  PROCEDURE ADD_TO_TEMP_OBJ_TAB(OBJ_ID IN NUMBER) IS
      6  BEGIN
      7  TEMP_OBJ_TAB.EXTEND;
      8  TEMP_OBJ_TAB(TEMP_OBJ_TAB.LAST) := TEMP_OBJ_TYPE(OBJ_ID);
      9  END;
    10  BEGIN
    11  ADD_TO_TEMP_OBJ_TAB(100);
    12  ADD_TO_TEMP_OBJ_TAB(116);
    13  ADD_TO_TEMP_OBJ_TAB(279);
    14  ADD_TO_TEMP_OBJ_TAB(364);
    15  DBMS_OUTPUT.PUT_LINE('=====================');
    16  FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
    17  LOOP
    18  DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
    19  END LOOP;
    20  DBMS_OUTPUT.PUT_LINE('---------------------');
    21  SELECT * BULK COLLECT INTO TEMP_T1T2_V_ROW_TAB
    22  FROM TEMP_T1T2_V VW
    23  WHERE ((VW.OBJECT_ID) IN (SELECT OBJ_ID
    24  FROM TABLE(CAST(TEMP_OBJ_TAB AS TEMP_OBJ_TAB_TYPE))));
    25  FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
    26  LOOP
    27  DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
    28  END LOOP;
    29  DBMS_OUTPUT.PUT_LINE('---------------------');
    30  IF TEMP_T1T2_V_ROW_TAB.COUNT > 0 THEN
    31  FOR I IN TEMP_T1T2_V_ROW_TAB.FIRST..TEMP_T1T2_V_ROW_TAB.LAST
    32  LOOP
    33  DBMS_OUTPUT.PUT_LINE(TEMP_T1T2_V_ROW_TAB(I).OBJECT_ID||' : '||TEMP_T1T2_V_ROW_TAB(I).OBJECT_NAME);
    34  END LOOP;
    35  ELSE
    36  DBMS_OUTPUT.PUT_LINE('NO ROWS RETURNED!');
    37  END IF;
    38  DBMS_OUTPUT.PUT_LINE('---------------------');
    39  END;
    40  /
    =====================
    OBJ_ID = 100
    OBJ_ID = 116
    OBJ_ID = 279
    OBJ_ID = 364
    OBJ_ID = 100
    OBJ_ID = 116
    OBJ_ID = 279
    OBJ_ID = 364
    364 : I_AUDIT
    364 : I_AUDIT
    364 : I_AUDIT
    364 : I_AUDIT
    PL/SQL procedure successfully completed.
    SQL> column object_name format a30
    SQL> select  object_id,
      2          object_name
      3    from  dba_objects
      4    where object_id in (100,116,279,364)
      5  /
    OBJECT_ID OBJECT_NAME
           100 ORA$BASE
           116 DUAL
           279 MAP_OBJECT
           364 I_AUDIT
    SQL>  Works fine in:
    =====================
    OBJ_ID = 100
    OBJ_ID = 116
    OBJ_ID = 279
    OBJ_ID = 364
    OBJ_ID = 100
    OBJ_ID = 116
    OBJ_ID = 279
    OBJ_ID = 364
    100 : ORA$BASE
    116 : DUAL
    364 : SYSTEM_PRIVILEGE_MAP
    279 : MAP_OBJECT
    PL/SQL procedure successfully completed.
    SQL> select  object_id,
      2          object_name
      3    from  dba_objects
      4    where object_id in (100,116,279,364)
      5  /
    OBJECT_ID OBJECT_NAME
          100 ORA$BASE
          116 DUAL
          364 SYSTEM_PRIVILEGE_MAP
          279 MAP_OBJECT
    SQL> select  *
      2    from  v$version
      3  /
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    SQL>SY.
    Edited by: Solomon Yakobson on Oct 30, 2012 2:14 PM

  • 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.

  • Using union all and rownum

    Hello again.
    Another question.
    Can I query with union all and stop it when I get N rows.
    For example:
    select 1 from dba_segments
    union all
    select 2 from dba_segments where
    union all
    select 3 from dba_segments where;
    and get the 100 first rows without doing the whole query:(not like that-->)
    select * from (
    select 1 from dba_segments
    union all
    select 2 from dba_segments where
    union all
    select 3 from dba_segments where)
    where rownum < 100);
    I want the query will stop when there are 100 rows in the result set.
    thank you!

    You already posted your own answer. It just seems you don't want to use it.
    ROWNUM is NOT assigned until the rows are selected to be returned. So you need to wrap the three inner queries into a query that uses ROWNUM.

  • UNION ALL and UNION performance issue

    Hi All,
    I am trying to figure out the data for which only receive transaction has been done and further processing is pending. These transactions include all PO, RMA , ISO etc...
    I have to use UNION ALL in this case as for RMA and ISO, details which i want are not able to gather in a single query.
    But query is taking a lot of time ...may be around 30..mins in UNION ALL while 6 to 7 mins in UNION.
    To get all records I must have to use UNION ALL...
    So kindly suggest the solution for this problem
    Thanks
    Sachin
    Query is given below...
    SELECT /* + FIRST_ROWS */ DECODE(rsl.SOURCE_DOCUMENT_CODE,'REQ',(SELECT org1.ORGANIZATION_NAME
                                                           FROM     org_organization_definitions org1
                                                           WHERE org1.ORGANIZATION_ID =
                                                           rsl.FROM_ORGANIZATION_ID)) Vendor_Name
    ,rsh.RECEIPT_NUM Receipt_Number
         ,TO_CHAR(rt3.TRANSACTION_DATE,'Mon-DD-YYYY HH:MM:SS') Receipt_Date_and_Time
         ,msi.SEGMENT1 Part_Number
         ,msi.DESCRIPTION Part_Name
         ,rt3.QUANTITY Quantity
         ,rt3.UNIT_OF_MEASURE UOM
         ,NULL ASL_Status
         --for ISO no asl flag ASL Flag
         ,TO_CHAR(TRUNC((((86400*(SYSDATE-rt3.TRANSACTION_DATE))/60)/60)/24))|| ' Days ' || TO_CHAR(TRUNC(((86400*(SYSDATE-rt3.TRANSACTION_DATE))/60)/60)-24*(TRUNC((((86400*(SYSDATE-rt3.TRANSACTION_DATE))/60)/60)/24)))|| ' Hours' Days_and_hours_passed
         ,DECODE(
                        NVL(msi.max_minmax_quantity,0) ,
                        0 , 0 ,
                        (NVL(msi.max_minmax_quantity,0) -
                        NVL(inmohqd.onhand,0))
                             * 100
                             / NVL(msi.max_minmax_quantity,0)
                        ) gap_percent
    FROM rcv_transactions rt3
         ,rcv_shipment_headers rsh
         ,rcv_shipment_lines rsl
         ,mtl_system_items msi
         ,org_organization_definitions org
         --,MTL_ONHAND_QUANTITIES_DETAIL moqhd
         ,(SELECT NVL(SUM(primary_transaction_quantity),0) onhand,INVENTORY_ITEM_ID item_id,ORGANIZATION_ID organization_id
         FROM      mtl_onhand_quantities_detail
         WHERE SUBINVENTORY_CODE NOT IN ('Wip_SF','Wip_Int','Reject','Scrap','FG Trading','FG')
         GROUP BY INVENTORY_ITEM_ID, ORGANIZATION_ID) inmohqd
    WHERE inmohqd.item_id(+) = msi.INVENTORY_ITEM_ID
         AND inmohqd.organization_id(+) = msi.ORGANIZATION_ID
         --AND inmoqhd.SUBINVENTORY_CODE NOT IN  ('Wip_SF','Wip_Int','Reject','Scrap','FG Trading','FG')
         AND msi.INVENTORY_ITEM_ID = rsl.ITEM_ID
         AND rsh.SHIPMENT_HEADER_ID = rsl.SHIPMENT_HEADER_ID
         AND org.ORGANIZATION_ID = rt3.ORGANIZATION_ID
         AND msi.ORGANIZATION_ID = rt3.ORGANIZATION_ID
         AND rsh.SHIPMENT_HEADER_ID = rt3.SHIPMENT_HEADER_ID
         AND rsl.SHIPMENT_HEADER_ID = rt3.SHIPMENT_HEADER_ID
         AND rsl.SHIPMENT_LINE_ID = rt3.SHIPMENT_LINE_ID
         AND rt3.PO_HEADER_ID IS NULL
         AND TRUNC(rt3.TRANSACTION_DATE) <= TRUNC(p_tilldate)
         AND rsl.TO_ORGANIZATION_ID = p_organization_id
         AND rsh.ORGANIZATION_ID = p_organization_id
         AND CONCAT(TRIM(rt3.SHIPMENT_HEADER_ID),TRIM(rt3.SHIPMENT_LINE_ID)) IN
         SELECT CONCAT(TRIM(rt1.SHIPMENT_HEADER_ID),TRIM(rt1.SHIPMENT_LINE_ID))
         FROM     rcv_transactions rt1
         WHERE NOT EXISTS(
         SELECT 1
              FROM     rcv_transactions rt2
              WHERE     rt2.TRANSACTION_TYPE <> 'RECEIVE'
                        AND rt1.SHIPMENT_HEADER_ID = rt2.SHIPMENT_HEADER_ID
                        AND rt1.SHIPMENT_LINE_ID = rt2.SHIPMENT_LINE_ID
                        AND rt2.ORGANIZATION_ID = p_organization_id
    UNION
    SELECT /* + FIRST_ROWS */ pv.VENDOR_NAME Vendor_Name
         ,rsh.RECEIPT_NUM Receipt_Number
         ,TO_CHAR(rt.TRANSACTION_DATE,'Mon-DD-YYYY HH:MM:SS') Receipt_Date_and_Time
         ,msi.SEGMENT1 Part_Number
         ,msi.DESCRIPTION Part_Name
         ,rt.QUANTITY Quantity
         ,rt.UNIT_OF_MEASURE UOM
         --start 001
         ,NVL((SELECT DISTINCT DECODE (ASL_STATUS_ID,1,'New',2,'Approved','To be checked')
                   FROM po_approved_supplier_list pasl
                   WHERE pasl.item_id=rsl.ITEM_ID
                             AND pasl.VENDOR_ID(+) = pv.VENDOR_ID
                             AND pasl.VENDOR_SITE_ID(+) = pvs.VENDOR_SITE_ID),'No_data') ASL_Status
              --end 001
              ,TO_CHAR(TRUNC((((86400*(SYSDATE-rt.TRANSACTION_DATE))/60)/60)/24))|| ' Days ' || TO_CHAR(TRUNC(((86400*(SYSDATE-rt.TRANSACTION_DATE))/60)/60)-24*(TRUNC((((86400*(SYSDATE-rt.TRANSACTION_DATE))/60)/60)/24)))|| ' Hours' Days_and_hours_passed          ,DECODE(
                   NVL(msi.max_minmax_quantity,0) ,
              0 , 0 ,
              (NVL(msi.max_minmax_quantity,0) -
              NVL(inmohqd.onhand,0))
                   * 100
                   / NVL(msi.max_minmax_quantity,0)
              ) gap_percent
    FROM rcv_transactions rt
         ,po_vendors pv
         ,po_vendor_sites_all pvs
         ,rcv_shipment_headers rsh
         ,rcv_shipment_lines rsl
         ,mtl_system_items msi
         ,org_organization_definitions org
         --,mtl_onhand_quantities_detail moqhd
         ,(SELECT NVL(SUM(primary_transaction_quantity),0) onhand,INVENTORY_ITEM_ID item_id,ORGANIZATION_ID organization_id
         FROM      mtl_onhand_quantities_detail
         WHERE SUBINVENTORY_CODE NOT IN ('Wip_SF','Wip_Int','Reject','Scrap','FG Trading','FG')
         GROUP BY INVENTORY_ITEM_ID, ORGANIZATION_ID) inmohqd
    WHERE inmohqd.item_id(+) = msi.INVENTORY_ITEM_ID
         AND inmohqd.ORGANIZATION_ID(+) = msi.ORGANIZATION_ID
         --AND inmoqhd.SUBINVENTORY_CODE NOT IN  ('Wip_SF','Wip_Int','Reject','Scrap','FG Trading','FG')
         AND msi.INVENTORY_ITEM_ID = rsl.ITEM_ID
         AND rsh.SHIPMENT_HEADER_ID = rsl.SHIPMENT_HEADER_ID
         AND pv.VENDOR_ID = pvs.VENDOR_ID
         AND org.ORGANIZATION_ID = rt.ORGANIZATION_ID
         AND msi.ORGANIZATION_ID = rt.ORGANIZATION_ID
         AND pvs.VENDOR_SITE_ID = rt.VENDOR_SITE_ID
         AND pv.VENDOR_ID = rt.VENDOR_ID
         AND rsh.SHIPMENT_HEADER_ID = rt.SHIPMENT_HEADER_ID
         AND rsl.SHIPMENT_HEADER_ID = rt.SHIPMENT_HEADER_ID
         AND rsl.SHIPMENT_LINE_ID = rt.SHIPMENT_LINE_ID
         AND TRUNC(rt.TRANSACTION_DATE) <= TRUNC(p_tilldate)
         AND rsl.TO_ORGANIZATION_ID = p_organization_id
         AND CONCAT(TRIM(rt.SHIPMENT_HEADER_ID),TRIM(rt.SHIPMENT_LINE_ID)) IN
              SELECT CONCAT(TRIM(rt1.SHIPMENT_HEADER_ID),TRIM(rt1.SHIPMENT_LINE_ID))
              FROM RCV_TRANSACTIONS rt1
              WHERE rt1.TRANSACTION_TYPE = 'RECEIVE'
                   AND rt1.DESTINATION_TYPE_CODE = 'RECEIVING'
                   AND rt1.PO_HEADER_ID IS NOT NULL
                   AND NOT EXISTS(
                   SELECT 1
                        FROM     RCV_TRANSACTIONS rt2
                        WHERE     rt2.SHIPMENT_HEADER_ID = rt1.SHIPMENT_HEADER_ID
                                  AND rt2.SHIPMENT_LINE_ID = rt1.SHIPMENT_LINE_ID
                                  AND rt2.TRANSACTION_TYPE <> 'RECEIVE'
         )

    In this case, for selected columns, all data is same for one of the RMA with more than one line. So UNION will skip one of the records. However, shipment line id are different for both records, so by selecting it in select list is solving the problem and so no need to use UNION ALL. But, anyhow UNION ALL is better than UNION in performance as it does not require to sort. Then why I am facing this problem...
    Kindly suggest
    Regards,
    Sachin

  • Help required on UNION ALL for select query

    Hello all,
    The execution plan for an SQL is impacted when another SELECT is concatenated with a UNION ALL. The two SELECTS are very efficient when run separately (< 100 buffer gets), but when run together (using a UNION ALL), the execution plan changes (for the first SELECT) and the buffer gets jumps to over 45000!
    what customer says with the UNION ALL, Oracle instead of doing a Merge Scan (that allows the inner table to filter out the rows from the outer table), chooses to do a NL join. This results in a Unique Index scan for each one of the 15000 rows in the outer table, resulting in 46000 consistent gets.
    Can you please suggest customer why plan changes when they use UNION ALL &  also suggest better way of running query.
    Please refer to below explain plan .
    WITH THE UNIONS
    ===============
      1  SELECT  count(*)
      2     FROM SOC_LIST SOC
      3     WHERE
      4       ( EXISTS(  SELECT  1
      5               FROM    ELIGIBILITY_RELATION
      6               WHERE   SRC_CODE = 'SHDMM4215'
      7                    AND   DEST_CODE = SOC.SOC
      8                 AND   SRC_TYPE = 'P'
      9                 AND   DEST_TYPE = 'S'))
    10  UNION ALL
    11   SELECT count(*)
    12     FROM SOC_LIST SOC
    13*    WHERE        ( = 'Y')
    12:25:39 SQL> /
      COUNT(*)                                                                                                                                           
           153                                                                                                                                           
             0                                                                                                                                           
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=31 Card=2 Bytes=10)                                                                                
       1    0   UNION-ALL                                                                                                                                
       2    1     SORT (AGGREGATE)                                                                                                                       
       3    2       FILTER                                                                                                                               
       4    3         TABLE ACCESS (FULL) OF 'SOC_LIST' (Cost=15 Card=749                                                                                
              Bytes=7490)                                                                                                                                
       5    3         PARTITION HASH (SINGLE)                                                                                                            
       6    5           INDEX (UNIQUE SCAN) OF 'ELIGIBILITY_RELATION_PK' (                                                                               
              UNIQUE) (Cost=2 Card=1 Bytes=24)                                                                                                           
       7    1     SORT (AGGREGATE)                                                                                                                       
       8    7       FILTER                                                                                                                               
       9    8         TABLE ACCESS (FULL) OF 'SOC_LIST' (Cost=15 Card=1497                                                                               
              8)                                                                                                                                         
    Statistics
              0  recursive calls                                                                                                                         
              0  db block gets                                                                                                                           
          46712  consistent gets         <------large number                                                                                                                 
              0  physical reads                                                                                                                          
              0  redo size                                                                                                                               
            215  bytes sent via SQL*Net to client                                                                                                        
            241  bytes received via SQL*Net from client                                                                                                  
              2  SQL*Net roundtrips to/from client                                                                                                       
              0  sorts (memory)                                                                                                                          
              0  sorts (disk)                                                                                                                            
              2  rows processed                                                                                                                          
    12:25:40 SQL> ed
    Wrote file C:/PADDY/AFIEDT.BUF
    PART 1 of the UNION ALL
    ========================
      1  SELECT  count(*)
      2     FROM SOC_LIST SOC
      3     WHERE
      4       ( EXISTS(  SELECT  1
      5               FROM    ELIGIBILITY_RELATION
      6               WHERE   SRC_CODE = 'SHDMM4215'
      7                    AND   DEST_CODE = SOC.SOC
      8                 AND   SRC_TYPE = 'P'
      9*                AND   DEST_TYPE = 'S'))
    12:25:54 SQL> /
      COUNT(*)                                                                                                                                           
           153                                                                                                                                           
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=4 Card=1 Bytes=34)                                                                                 
       1    0   SORT (AGGREGATE)                                                                                                                         
       2    1     MERGE JOIN (SEMI) (Cost=4 Card=149 Bytes=5066)                                                                                         
       3    2       INDEX (FULL SCAN) OF 'SOC_LIST_1IX' (NON-UNIQUE) (Cost                                                                               
              =41 Card=14978 Bytes=149780)                                                                                                               
       4    2       SORT (UNIQUE) (Cost=3 Card=149 Bytes=3576)                                                                                           
       5    4         PARTITION HASH (ALL)                                                                                                               
       6    5           INDEX (RANGE SCAN) OF 'ELIGIBILITY_RELATION_PK' (U                                                                               
              NIQUE) (Cost=10 Card=149 Bytes=3576)                                                                                                       
    Statistics
              0  recursive calls                                                                                                                         
              0  db block gets                                                                                                                           
             56  consistent gets                                                                                                                         
              0  physical reads                                                                                                                          
              0  redo size                                                                                                                               
            218  bytes sent via SQL*Net to client                                                                                                        
            241  bytes received via SQL*Net from client                                                                                                  
              2  SQL*Net roundtrips to/from client                                                                                                       
              1  sorts (memory)                                                                                                                          
              0  sorts (disk)                                                                                                                            
              1  rows processed                                                                                                                          
    12:25:55 SQL> ed
    Wrote file C:/PADDY/AFIEDT.BUF
    PART 2 of the UNION ALL
    ========================
      1   SELECT count(*)
      2     FROM SOC_LIST SOC
      3*    WHERE        ( = 'Y')
    12:26:15 SQL> /
      COUNT(*)                                                                                                                                           
             0                                                                                                                                           
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=15 Card=1)                                                                                         
       1    0   SORT (AGGREGATE)                                                                                                                         
       2    1     FILTER                                                                                                                                 
       3    2       TABLE ACCESS (FULL) OF 'SOC_LIST' (Cost=15 Card=14978)                                                                               
    Statistics
              0  recursive calls                                                                                                                         
              0  db block gets                                                                                                                           
              0  consistent gets                                                                                                                         
              0  physical reads                                                                                                                          
              0  redo size                                                                                                                               
            215  bytes sent via SQL*Net to client                                                                                                        
            241  bytes received via SQL*Net from client                                                                                                  
              2  SQL*Net roundtrips to/from client                                                                                                       
              0  sorts (memory)                                                                                                                          
              0  sorts (disk)                                                                                                                            
              1  rows processed                                                                                                                          
    12:26:20 SQL> spool off
    Same results but with theUNION ALL, the buffergets is massive ...
    Thanks
    Krishna

    i am also attaching 10043/10053 trace file .
    /opt/oracle/adm/STCUST/udump/stcust_ora_7919_10046_10053_trace_file.trc
    *** TRACE DUMP CONTINUED FROM FILE  ***
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.8.0 - Production
    ORACLE_HOME = /opt/oracle/product/9.2.0.8
    System name: HP-UX
    Node name: rcihp009
    Release: B.11.23
    Version: U
    Machine: 9000/800
    Instance name: STCUST
    Redo thread mounted by this instance: 1
    Oracle process number: 152
    Unix process pid: 7919, image: oracle@rcihp009 (TNS V1-V3)
    *** 2013-06-10 13:32:48.943
    *** SESSION ID:(533.15875) 2013-06-10 13:32:48.943
    APPNAME mod='SQL*Plus' mh=3669949024 act='' ah=4029777240
    =====================
    PARSING IN CURSOR #1 len=69 dep=0 uid=33 oct=42 lid=33 tim=3017585934213 hv=2004533713 ad='4aa33998'
    alter session set events '10046 trace name context forever, level 12'
    END OF STMT
    EXEC #1:c=0,e=209,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017585933683
    WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:33:00.090
    WAIT #1: nam='SQL*Net message from client' ela= 10884599 p1=1413697536 p2=1 p3=0
    =====================
    PARSING IN CURSOR #1 len=69 dep=0 uid=33 oct=42 lid=33 tim=3017596819944 hv=2030017677 ad='3af92970'
    alter session set events '10053 trace name context forever, level 1'
    END OF STMT
    PARSE #1:c=0,e=484,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017596819933
    BINDS #1:
    EXEC #1:c=0,e=160,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017596820180
    WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:33:50.197
    WAIT #1: nam='SQL*Net message from client' ela= 48932344 p1=1413697536 p2=1 p3=0
    PARAMETERS USED BY THE OPTIMIZER
    OPTIMIZER_FEATURES_ENABLE = 9.2.0
    OPTIMIZER_MODE/GOAL = Choose
    _OPTIMIZER_PERCENT_PARALLEL = 101
    HASH_AREA_SIZE = 131072
    HASH_JOIN_ENABLED = TRUE
    HASH_MULTIBLOCK_IO_COUNT = 0
    SORT_AREA_SIZE = 65536
    OPTIMIZER_SEARCH_LIMIT = 5
    PARTITION_VIEW_ENABLED = FALSE
    _ALWAYS_STAR_TRANSFORMATION = FALSE
    _B_TREE_BITMAP_PLANS = TRUE
    STAR_TRANSFORMATION_ENABLED = FALSE
    _COMPLEX_VIEW_MERGING = TRUE
    _PUSH_JOIN_PREDICATE = TRUE
    PARALLEL_BROADCAST_ENABLED = TRUE
    OPTIMIZER_MAX_PERMUTATIONS = 2000
    OPTIMIZER_INDEX_CACHING = 0
    _SYSTEM_INDEX_CACHING = 0
    OPTIMIZER_INDEX_COST_ADJ = 1
    OPTIMIZER_DYNAMIC_SAMPLING = 1
    _OPTIMIZER_DYN_SMP_BLKS = 32
    QUERY_REWRITE_ENABLED = TRUE
    QUERY_REWRITE_INTEGRITY = ENFORCED
    _INDEX_JOIN_ENABLED = TRUE
    _SORT_ELIMINATION_COST_RATIO = 0
    _OR_EXPAND_NVL_PREDICATE = TRUE
    _NEW_INITIAL_JOIN_ORDERS = TRUE
    ALWAYS_ANTI_JOIN = CHOOSE
    ALWAYS_SEMI_JOIN = CHOOSE
    _OPTIMIZER_MODE_FORCE = TRUE
    _OPTIMIZER_UNDO_CHANGES = FALSE
    _UNNEST_SUBQUERY = TRUE
    _PUSH_JOIN_UNION_VIEW = TRUE
    _FAST_FULL_SCAN_ENABLED = TRUE
    _OPTIM_ENHANCE_NNULL_DETECTION = TRUE
    _ORDERED_NESTED_LOOP = TRUE
    _NESTED_LOOP_FUDGE = 100
    _NO_OR_EXPANSION = FALSE
    _QUERY_COST_REWRITE = TRUE
    QUERY_REWRITE_EXPRESSION = TRUE
    _IMPROVED_ROW_LENGTH_ENABLED = TRUE
    _USE_NOSEGMENT_INDEXES = FALSE
    _ENABLE_TYPE_DEP_SELECTIVITY = TRUE
    _IMPROVED_OUTERJOIN_CARD = TRUE
    _OPTIMIZER_ADJUST_FOR_NULLS = TRUE
    _OPTIMIZER_CHOOSE_PERMUTATION = 0
    _USE_COLUMN_STATS_FOR_FUNCTION = TRUE
    _SUBQUERY_PRUNING_ENABLED = TRUE
    _SUBQUERY_PRUNING_REDUCTION_FACTOR = 50
    _SUBQUERY_PRUNING_COST_FACTOR = 20
    _LIKE_WITH_BIND_AS_EQUALITY = FALSE
    _TABLE_SCAN_COST_PLUS_ONE = TRUE
    _SORTMERGE_INEQUALITY_JOIN_OFF = FALSE
    _DEFAULT_NON_EQUALITY_SEL_CHECK = TRUE
    _ONESIDE_COLSTAT_FOR_EQUIJOINS = TRUE
    _OPTIMIZER_COST_MODEL = CHOOSE
    _GSETS_ALWAYS_USE_TEMPTABLES = FALSE
    DB_FILE_MULTIBLOCK_READ_COUNT = 128
    _NEW_SORT_COST_ESTIMATE = TRUE
    _GS_ANTI_SEMI_JOIN_ALLOWED = TRUE
    _CPU_TO_IO = 0
    _PRED_MOVE_AROUND = TRUE
    BASE STATISTICAL INFORMATION
    Table stats    Table: SOC_LIST   Alias: SOC
      TOTAL ::  CDN: 17584  NBLKS:  653  AVG_ROW_LEN:  260
    Column:        SOC  Col#: 3      Table: SOC_LIST   Alias: SOC
        NDV: 17584     NULLS: 0         DENS: 5.6870e-05
        NO HISTOGRAM: #BKT: 1 #VAL: 2
    -- Index stats
      INDEX NAME: I_SNAP$_SOC_LIST  COL#: 1
        TOTAL ::  LVLS: 1   #LB: 64  #DK: 17487  LB/K: 1  DB/K: 1  CLUF: 699
      INDEX NAME: SOC_LIST_1IX  COL#: 3
        TOTAL ::  LVLS: 1   #LB: 47  #DK: 17487  LB/K: 1  DB/K: 1  CLUF: 14065
    Table stats    Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
      (Using composite stats)
      TOTAL ::  CDN: 11982220  NBLKS:  125493  AVG_ROW_LEN:  71
    -- Index stats
      INDEX NAME: ELIGIBILITY_RELATION_1IX  COL#: 3 4 5
        USING COMPOSITE STATS
        TOTAL ::  LVLS: 2   #LB: 38360  #DK: 4164  LB/K: 9  DB/K: 740  CLUF: 3081860
      INDEX NAME: ELIGIBILITY_RELATION_PK  COL#: 2 3 4 5
        USING COMPOSITE STATS
        TOTAL ::  LVLS: 2   #LB: 50740  #DK: 11873160  LB/K: 1  DB/K: 1  CLUF: 9158280
      INDEX NAME: I_SNAP$_ELIGIBILITY_RELATI  COL#: 1
        TOTAL ::  LVLS: 2   #LB: 49600  #DK: 11953600  LB/K: 1  DB/K: 1  CLUF: 8833300
    _OPTIMIZER_PERCENT_PARALLEL = 0
    SINGLE TABLE ACCESS PATH
    Column:   SRC_CODE  Col#: 2      Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
        NDV: 22087     NULLS: 0         DENS: 4.5276e-05
        NO HISTOGRAM: #BKT: 1 #VAL: 2
    Column:   SRC_TYPE  Col#: 3      Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
        NDV: 2         NULLS: 0         DENS: 5.0000e-01
        NO HISTOGRAM: #BKT: 1 #VAL: 2
    Column:  DEST_TYPE  Col#: 5      Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
        NDV: 2         NULLS: 0         DENS: 5.0000e-01
        NO HISTOGRAM: #BKT: 1 #VAL: 2
      TABLE: ELIGIBILITY_RELATION     ORIG CDN: 11982220  ROUNDED CDN: 136  CMPTD CDN: 136
      Access path: tsc  Resc:  3072  Resp:  3072
      Access path: index (iff)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 1243
      IX_SEL:  0.0000e+00  TB_SEL:  1.0000e+00
      Access path: iff  Resc:  1243  Resp:  1243
      Skip scan: ss-sel 0  andv 11970 
        ss cost 119700
        index io scan cost 19180
      Access path: index (scan)
          Index: ELIGIBILITY_RELATION_1IX
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 789653
      IX_SEL:  5.0000e-01  TB_SEL:  2.5000e-01
      Skip scan: ss-sel 0  andv 11970 
        ss cost 11970
        index io scan cost 2
      Access path: index (index-only)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 10
      IX_SEL:  2.2638e-05  TB_SEL:  2.2638e-05
      ****** trying bitmap/domain indexes ******
      ****** finished trying bitmap/domain indexes ******
      BEST_CST: 1.00  PATH: 4  Degree:  1
    SINGLE TABLE ACCESS PATH
      TABLE: SOC_LIST     ORIG CDN: 17584  ROUNDED CDN: 17584  CMPTD CDN: 17584
      Access path: tsc  Resc:  18  Resp:  18
      Access path: index (iff)
          Index: SOC_LIST_1IX
      TABLE: SOC_LIST
          RSC_CPU: 0   RSC_IO: 3
      IX_SEL:  0.0000e+00  TB_SEL:  1.0000e+00
      Access path: iff  Resc:  3  Resp:  3
      Access path: index (no sta/stp keys)
          Index: SOC_LIST_1IX
      TABLE: SOC_LIST
          RSC_CPU: 0   RSC_IO: 48
      IX_SEL:  1.0000e+00  TB_SEL:  1.0000e+00
      BEST_CST: 1.00  PATH: 4  Degree:  1
    OPTIMIZER STATISTICS AND COMPUTATIONS
    GENERAL PLANS
    Join order[1]:  SOC_LIST[SOC]#0  ELIGIBILITY_RELATION[ELIGIBILITY_RELATION]#1
    Now joining: ELIGIBILITY_RELATION[ELIGIBILITY_RELATION]#1 *******
    NL Join
      Outer table: cost: 1  cdn: 17584  rcz: 10  resp:  1
      Inner table: ELIGIBILITY_RELATION
        Access path: tsc  Resc: 768
        Join:  Resc:  13504513  Resp:  13504513
      Access path: index (iff)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 1243
      IX_SEL:  0.0000e+00  TB_SEL:  1.0000e+00
      Inner table: ELIGIBILITY_RELATION
        Access path: iff  Resc: 311
        Join:  Resc:  5464229  Resp:  5464229
      Access path: index (unique)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 1
      IX_SEL:  8.3457e-08  TB_SEL:  8.3457e-08
        Join:  resc: 177  resp: 177
      Access path: index (join index)
          Index: ELIGIBILITY_RELATION_1IX
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 750
      IX_SEL:  0.0000e+00  TB_SEL:  2.0886e-05
        Join:  resc: 131881  resp: 131881
      Access path: index (eq-unique)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 1
      IX_SEL:  0.0000e+00  TB_SEL:  0.0000e+00
        Join:  resc: 177  resp: 177
      ****** trying bitmap/domain indexes ******
      Access path: index (join index)
          Index: ELIGIBILITY_RELATION_1IX
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 10
      IX_SEL:  1.4217e-05  TB_SEL:  2.0886e-05
        Join:  resc: 1759  resp: 1759
      Access path: index (index-only)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 4
      IX_SEL:  4.5276e-05  TB_SEL:  4.5276e-05
        Join:  resc: 704  resp: 704
        SORT resource      Sort statistics
          Sort width:           11 Area size:      628736 Max Area size:    31457280   Degree: 1
          Blocks to Sort:        2 Row size:           21 Rows:        543
          Initial runs:          1 Merge passes:        1 IO Cost / pass:          3
          Total IO sort cost: 2
          Total CPU sort cost: 0
          Total Temp space used: 0
      ****** finished trying bitmap/domain indexes ******
      Best NL cost: 177  resp: 177
    Semi-join cardinality:  135 = outer (17584) * sel (7.6774e-03) [flag=12]
    SM Join
      Outer table:
        resc: 1  cdn: 17584  rcz: 10  deg: 1  resp: 1
      Inner table: ELIGIBILITY_RELATION
        resc: 1  cdn: 136  rcz: 24  deg:  1  resp: 1
        using join:1 distribution:2 #groups:1
        SORT resource      Sort statistics
          Sort width:           11 Area size:      628736 Max Area size:    31457280   Degree: 1
          Blocks to Sort:        1 Row size:           37 Rows:        136
          Initial runs:          1 Merge passes:        1 IO Cost / pass:          2
          Total IO sort cost: 2
          Total CPU sort cost: 0
          Total Temp space used: 0
      Merge join  Cost:  4  Resp:  4
    HA Join
      Outer table:
        resc: 1  cdn: 17584  rcz: 10  deg: 1  resp: 1
      Inner table: ELIGIBILITY_RELATION
        resc: 1  cdn: 136  rcz: 24  deg:  1  resp: 1
        using join:8 distribution:2 #groups:1
      Hash join one ptn Resc: 4   Deg: 1
          hash_area:  154 (max=7680)  buildfrag:  48                probefrag:   1 ppasses:    1
      Hash join   Resc: 6   Resp: 6
    Join result: cost: 4  cdn: 135  rcz: 34
    Best so far: TABLE#: 0  CST:          1  CDN:      17584  BYTES:     175840
    Best so far: TABLE#: 1  CST:          4  CDN:        135  BYTES:       4590
    Join order[2]:  ELIGIBILITY_RELATION[ELIGIBILITY_RELATION]#1  SOC_LIST[SOC]#0
        SORT resource      Sort statistics
          Sort width:           11 Area size:      628736 Max Area size:    31457280   Degree: 1
          Blocks to Sort:        1 Row size:           37 Rows:        136
          Initial runs:          1 Merge passes:        1 IO Cost / pass:          2
          Total IO sort cost: 2
          Total CPU sort cost: 0
          Total Temp space used: 0
    Now joining: SOC_LIST[SOC]#0 *******
    NL Join
      Outer table: cost: 3  cdn: 136  rcz: 24  resp:  2
      Inner table: SOC_LIST
        Access path: tsc  Resc: 18
        Join:  Resc:  2450  Resp:  2450
      Access path: index (iff)
          Index: SOC_LIST_1IX
      TABLE: SOC_LIST
          RSC_CPU: 0   RSC_IO: 3
      IX_SEL:  0.0000e+00  TB_SEL:  1.0000e+00
      Inner table: SOC_LIST
        Access path: iff  Resc: 3
        Join:  Resc:  410  Resp:  410
      Access path: index (join index)
          Index: SOC_LIST_1IX
      TABLE: SOC_LIST
          RSC_CPU: 0   RSC_IO: 1
      IX_SEL:  0.0000e+00  TB_SEL:  5.6870e-05
        Join:  resc: 4  resp: 4
      Best NL cost: 4  resp: 4
    Join cardinality:  136 = outer (136) * inner (17584) * sel (5.6870e-05)  [flag=0]
    SM Join
      Outer table:
        resc: 2  cdn: 136  rcz: 24  deg: 1  resp: 2
      Inner table: SOC_LIST
        resc: 1  cdn: 17584  rcz: 10  deg:  1  resp: 1
        using join:1 distribution:2 #groups:1
        SORT resource      Sort statistics
          Sort width:           11 Area size:      628736 Max Area size:    31457280   Degree: 1
          Blocks to Sort:        1 Row size:           37 Rows:        136
          Initial runs:          1 Merge passes:        1 IO Cost / pass:          2
          Total IO sort cost: 2
          Total CPU sort cost: 0
          Total Temp space used: 0
        SORT resource      Sort statistics
          Sort width:           11 Area size:      628736 Max Area size:    31457280   Degree: 1
          Blocks to Sort:       46 Row size:           21 Rows:      17584
          Initial runs:          1 Merge passes:        1 IO Cost / pass:         51
          Total IO sort cost: 48
          Total CPU sort cost: 0
          Total Temp space used: 0
      Merge join  Cost:  54  Resp:  54
    HA Join
      Outer table:
        resc: 2  cdn: 136  rcz: 24  deg: 1  resp: 2
      Inner table: SOC_LIST
        resc: 1  cdn: 17584  rcz: 10  deg:  1  resp: 1
        using join:8 distribution:2 #groups:1
      Hash join one ptn Resc: 1   Deg: 1
          hash_area:  154 (max=7680)  buildfrag:  1                probefrag:   48 ppasses:    1
      Hash join   Resc: 4   Resp: 4
    Final - All Rows Plan:
      JOIN ORDER: 1
      CST: 4  CDN: 135  RSC: 4  RSP: 4  BYTES: 4590
      IO-RSC: 4  IO-RSP: 4  CPU-RSC: 0  CPU-RSP: 0
    QUERY
    SELECT   count(*)
       FROM SOC_LIST SOC
       WHERE
         ( EXISTS(  SELECT  1
                 FROM    ELIGIBILITY_RELATION
                 WHERE   SRC_CODE = 'SHDMM4215'
                      AND   DEST_CODE = SOC.SOC
                   AND   SRC_TYPE = 'P'
                   AND   DEST_TYPE = 'S'))
    =====================
    PARSING IN CURSOR #1 len=278 dep=0 uid=33 oct=3 lid=33 tim=3017645761269 hv=183981413 ad='492d5bb0'
    SELECT   count(*)
       FROM SOC_LIST SOC
       WHERE
         ( EXISTS(  SELECT  1
                 FROM    ELIGIBILITY_RELATION
                 WHERE   SRC_CODE = 'SHDMM4215'
                      AND   DEST_CODE = SOC.SOC
                   AND   SRC_TYPE = 'P'
                   AND   DEST_TYPE = 'S'))
    END OF STMT
    PARSE #1:c=10000,e=8343,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017645761258
    BINDS #1:
    EXEC #1:c=0,e=529,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017645761970
    WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
    WAIT #1: nam='db file sequential read' ela= 9290 p1=2535 p2=142378 p3=1
    WAIT #1: nam='db file sequential read' ela= 2098 p1=2535 p2=142379 p3=1
    WAIT #1: nam='db file sequential read' ela= 11574 p1=2535 p2=33834 p3=1
    WAIT #1: nam='db file sequential read' ela= 10290 p1=2536 p2=60958 p3=1
    WAIT #1: nam='db file sequential read' ela= 11469 p1=2535 p2=61232 p3=1
    WAIT #1: nam='db file sequential read' ela= 378 p1=2535 p2=61233 p3=1
    WAIT #1: nam='db file sequential read' ela= 5493 p1=2535 p2=39498 p3=1
    WAIT #1: nam='db file sequential read' ela= 7397 p1=2536 p2=68185 p3=1
    WAIT #1: nam='db file sequential read' ela= 10037 p1=2536 p2=68520 p3=1
    WAIT #1: nam='db file sequential read' ela= 16125 p1=2535 p2=68809 p3=1
    WAIT #1: nam='db file sequential read' ela= 12426 p1=2535 p2=45162 p3=1
    WAIT #1: nam='db file sequential read' ela= 12447 p1=2535 p2=178335 p3=1
    WAIT #1: nam='db file sequential read' ela= 5974 p1=2535 p2=178798 p3=1
    WAIT #1: nam='db file sequential read' ela= 1247 p1=2535 p2=178799 p3=1
    WAIT #1: nam='db file sequential read' ela= 11010 p1=2535 p2=50826 p3=1
    WAIT #1: nam='db file sequential read' ela= 5421 p1=2536 p2=260451 p3=1
    WAIT #1: nam='db file sequential read' ela= 8230 p1=2536 p2=261538 p3=1
    WAIT #1: nam='db file sequential read' ela= 350 p1=2535 p2=142380 p3=1
    WAIT #1: nam='db file sequential read' ela= 346 p1=2535 p2=142381 p3=1
    WAIT #1: nam='db file sequential read' ela= 343 p1=2535 p2=142382 p3=1
    WAIT #1: nam='db file sequential read' ela= 480 p1=2535 p2=142383 p3=1
    WAIT #1: nam='db file sequential read' ela= 10237 p1=2535 p2=142384 p3=1
    WAIT #1: nam='db file sequential read' ela= 324 p1=2535 p2=142385 p3=1
    WAIT #1: nam='db file sequential read' ela= 359 p1=2535 p2=142386 p3=1
    WAIT #1: nam='db file sequential read' ela= 361 p1=2535 p2=142387 p3=1
    WAIT #1: nam='db file sequential read' ela= 375 p1=2535 p2=142388 p3=1
    WAIT #1: nam='db file sequential read' ela= 425 p1=2535 p2=142389 p3=1
    WAIT #1: nam='db file sequential read' ela= 540 p1=2535 p2=142390 p3=1
    WAIT #1: nam='db file sequential read' ela= 368 p1=2535 p2=142391 p3=1
    WAIT #1: nam='db file sequential read' ela= 479 p1=2535 p2=142392 p3=1
    WAIT #1: nam='db file sequential read' ela= 450 p1=2535 p2=142393 p3=1
    WAIT #1: nam='db file sequential read' ela= 307 p1=2535 p2=142394 p3=1
    WAIT #1: nam='db file sequential read' ela= 324 p1=2535 p2=142395 p3=1
    WAIT #1: nam='db file sequential read' ela= 396 p1=2535 p2=142396 p3=1
    WAIT #1: nam='db file sequential read' ela= 376 p1=2535 p2=142397 p3=1
    WAIT #1: nam='db file sequential read' ela= 295 p1=2535 p2=142398 p3=1
    WAIT #1: nam='db file sequential read' ela= 391 p1=2535 p2=142399 p3=1
    WAIT #1: nam='db file sequential read' ela= 396 p1=2535 p2=142400 p3=1
    WAIT #1: nam='db file sequential read' ela= 344 p1=2535 p2=142401 p3=1
    WAIT #1: nam='db file sequential read' ela= 337 p1=2535 p2=142402 p3=1
    WAIT #1: nam='db file sequential read' ela= 360 p1=2535 p2=142403 p3=1
    WAIT #1: nam='db file sequential read' ela= 402 p1=2535 p2=142404 p3=1
    WAIT #1: nam='db file sequential read' ela= 343 p1=2535 p2=142405 p3=1
    WAIT #1: nam='db file sequential read' ela= 408 p1=2535 p2=142406 p3=1
    WAIT #1: nam='db file sequential read' ela= 388 p1=2535 p2=142407 p3=1
    WAIT #1: nam='db file sequential read' ela= 400 p1=2535 p2=142408 p3=1
    WAIT #1: nam='db file sequential read' ela= 7999 p1=2536 p2=617 p3=1
    WAIT #1: nam='db file sequential read' ela= 520 p1=2536 p2=618 p3=1
    WAIT #1: nam='db file sequential read' ela= 294 p1=2536 p2=619 p3=1
    WAIT #1: nam='db file sequential read' ela= 311 p1=2536 p2=620 p3=1
    WAIT #1: nam='db file sequential read' ela= 316 p1=2536 p2=621 p3=1
    WAIT #1: nam='db file sequential read' ela= 306 p1=2536 p2=622 p3=1
    WAIT #1: nam='db file sequential read' ela= 303 p1=2536 p2=623 p3=1
    WAIT #1: nam='db file sequential read' ela= 1776 p1=2536 p2=624 p3=1
    FETCH #1:c=50000,e=216800,p=54,cr=54,cu=0,mis=0,r=1,dep=0,og=4,tim=3017645978865
    WAIT #1: nam='SQL*Net message from client' ela= 2802 p1=1413697536 p2=1 p3=0
    FETCH #1:c=0,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=3017645981803
    WAIT #1: nam='SQL*Net message to client' ela= 1 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:34:28.160
    WAIT #1: nam='SQL*Net message from client' ela= 36844121 p1=1413697536 p2=1 p3=0
    STAT #1 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=54 r=54 w=0 time=216788 us)'
    STAT #1 id=2 cnt=157 pid=1 pos=1 obj=0 op='MERGE JOIN SEMI (cr=54 r=54 w=0 time=216734 us)'
    STAT #1 id=3 cnt=14296 pid=2 pos=1 obj=5769123 op='INDEX FULL SCAN SOC_LIST_1IX (cr=39 r=39 w=0 time=55399 us)'
    STAT #1 id=4 cnt=157 pid=2 pos=2 obj=0 op='SORT UNIQUE (cr=15 r=15 w=0 time=141933 us)'
    STAT #1 id=5 cnt=286 pid=4 pos=1 obj=0 op='PARTITION HASH ALL PARTITION: 1 4 (cr=15 r=15 w=0 time=130847 us)'
    STAT #1 id=6 cnt=286 pid=5 pos=1 obj=5401812 op='INDEX RANGE SCAN ELIGIBILITY_RELATION_PK PARTITION: 1 4 (cr=15 r=15 w=0 time=130716 us)'
    QUERY
    BEGIN := 'N'; END;
    =====================
    PARSING IN CURSOR #1 len=23 dep=0 uid=33 oct=47 lid=33 tim=3017682828223 hv=16287806 ad='464edb18'
    BEGIN := 'N'; END;
    END OF STMT
    PARSE #1:c=0,e=1569,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=0,tim=3017682828214
    BINDS #1:
    bind 0: dty=96 mxl=01(01) mal=00 scl=00 pre=00 oacflg=03 oacfl2=200071100000000 size=8 offset=0
       bfp=800003ffefe9f748 bln=01 avl=00 flg=05
    WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
    EXEC #1:c=0,e=5494,p=0,cr=0,cu=0,mis=0,r=1,dep=0,og=4,tim=3017682833795
    *** 2013-06-10 13:34:44.174
    WAIT #1: nam='SQL*Net message from client' ela= 15630899 p1=1413697536 p2=1 p3=0
    QUERY
    SELECT count(*)
       FROM SOC_LIST SOC
       WHERE        ( = 'Y')
    =====================
    PARSING IN CURSOR #1 len=65 dep=0 uid=33 oct=3 lid=33 tim=3017698466665 hv=900106749 ad='43145458'
    SELECT count(*)
       FROM SOC_LIST SOC
       WHERE        ( = 'Y')
    END OF STMT
    PARSE #1:c=0,e=1409,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=0,tim=3017698466654
    PARAMETERS USED BY THE OPTIMIZER
    OPTIMIZER_FEATURES_ENABLE = 9.2.0
    OPTIMIZER_MODE/GOAL = Choose
    _OPTIMIZER_PERCENT_PARALLEL = 101
    HASH_AREA_SIZE = 131072
    HASH_JOIN_ENABLED = TRUE
    HASH_MULTIBLOCK_IO_COUNT = 0
    SORT_AREA_SIZE = 65536
    OPTIMIZER_SEARCH_LIMIT = 5
    PARTITION_VIEW_ENABLED = FALSE
    _ALWAYS_STAR_TRANSFORMATION = FALSE
    _B_TREE_BITMAP_PLANS = TRUE
    STAR_TRANSFORMATION_ENABLED = FALSE
    _COMPLEX_VIEW_MERGING = TRUE
    _PUSH_JOIN_PREDICATE = TRUE
    PARALLEL_BROADCAST_ENABLED = TRUE
    OPTIMIZER_MAX_PERMUTATIONS = 2000
    OPTIMIZER_INDEX_CACHING = 0
    _SYSTEM_INDEX_CACHING = 0
    OPTIMIZER_INDEX_COST_ADJ = 1
    OPTIMIZER_DYNAMIC_SAMPLING = 1
    _OPTIMIZER_DYN_SMP_BLKS = 32
    QUERY_REWRITE_ENABLED = TRUE
    QUERY_REWRITE_INTEGRITY = ENFORCED
    _INDEX_JOIN_ENABLED = TRUE
    _SORT_ELIMINATION_COST_RATIO = 0
    _OR_EXPAND_NVL_PREDICATE = TRUE
    _NEW_INITIAL_JOIN_ORDERS = TRUE
    ALWAYS_ANTI_JOIN = CHOOSE
    ALWAYS_SEMI_JOIN = CHOOSE
    _OPTIMIZER_MODE_FORCE = TRUE
    _OPTIMIZER_UNDO_CHANGES = FALSE
    _UNNEST_SUBQUERY = TRUE
    _PUSH_JOIN_UNION_VIEW = TRUE
    _FAST_FULL_SCAN_ENABLED = TRUE
    _OPTIM_ENHANCE_NNULL_DETECTION = TRUE
    _ORDERED_NESTED_LOOP = TRUE
    _NESTED_LOOP_FUDGE = 100
    _NO_OR_EXPANSION = FALSE
    _QUERY_COST_REWRITE = TRUE
    QUERY_REWRITE_EXPRESSION = TRUE
    _IMPROVED_ROW_LENGTH_ENABLED = TRUE
    _USE_NOSEGMENT_INDEXES = FALSE
    _ENABLE_TYPE_DEP_SELECTIVITY = TRUE
    _IMPROVED_OUTERJOIN_CARD = TRUE
    _OPTIMIZER_ADJUST_FOR_NULLS = TRUE
    _OPTIMIZER_CHOOSE_PERMUTATION = 0
    _USE_COLUMN_STATS_FOR_FUNCTION = TRUE
    _SUBQUERY_PRUNING_ENABLED = TRUE
    _SUBQUERY_PRUNING_REDUCTION_FACTOR = 50
    _SUBQUERY_PRUNING_COST_FACTOR = 20
    _LIKE_WITH_BIND_AS_EQUALITY = FALSE
    _TABLE_SCAN_COST_PLUS_ONE = TRUE
    _SORTMERGE_INEQUALITY_JOIN_OFF = FALSE
    _DEFAULT_NON_EQUALITY_SEL_CHECK = TRUE
    _ONESIDE_COLSTAT_FOR_EQUIJOINS = TRUE
    _OPTIMIZER_COST_MODEL = CHOOSE
    _GSETS_ALWAYS_USE_TEMPTABLES = FALSE
    DB_FILE_MULTIBLOCK_READ_COUNT = 128
    _NEW_SORT_COST_ESTIMATE = TRUE
    _GS_ANTI_SEMI_JOIN_ALLOWED = TRUE
    _CPU_TO_IO = 0
    _PRED_MOVE_AROUND = TRUE
    BASE STATISTICAL INFORMATION
    Table stats    Table: SOC_LIST   Alias: SOC
      TOTAL ::  CDN: 17584  NBLKS:  653  AVG_ROW_LEN:  260
    -- Index stats
      INDEX NAME: I_SNAP$_SOC_LIST  COL#: 1
        TOTAL ::  LVLS: 1   #LB: 64  #DK: 17487  LB/K: 1  DB/K: 1  CLUF: 699
      INDEX NAME: SOC_LIST_1IX  COL#: 3
        TOTAL ::  LVLS: 1   #LB: 47  #DK: 17487  LB/K: 1  DB/K: 1  CLUF: 14065
    _OPTIMIZER_PERCENT_PARALLEL = 0
    SINGLE TABLE ACCESS PATH
      TABLE: SOC_LIST     ORIG CDN: 17584  ROUNDED CDN: 17584  CMPTD CDN: 17584
      Access path: tsc  Resc:  18  Resp:  18
      ****** trying bitmap/domain indexes ******
      ****** finished trying bitmap/domain indexes ******
      BEST_CST: 18.00  PATH: 2  Degree:  1
    OPTIMIZER STATISTICS AND COMPUTATIONS
    GENERAL PLANS
    Join order[1]:  SOC_LIST[SOC]#0
    Best so far: TABLE#: 0  CST:         18  CDN:      17584  BYTES:          0
    Final - All Rows Plan:
      JOIN ORDER: 1
      CST: 18  CDN: 17584  RSC: 18  RSP: 18  BYTES: 0
      IO-RSC: 18  IO-RSP: 18  CPU-RSC: 0  CPU-RSP: 0
    BINDS #1:
    bind 0: dty=96 mxl=32(01) mal=00 scl=00 pre=00 oacflg=03 oacfl2=0 size=32 offset=0
       bfp=800003ffefea9490 bln=32 avl=01 flg=05
       value="N"
    EXEC #1:c=0,e=152,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017698469481
    WAIT #1: nam='SQL*Net message to client' ela= 4 p1=1413697536 p2=1 p3=0
    FETCH #1:c=10000,e=1506,p=0,cr=0,cu=0,mis=0,r=1,dep=0,og=4,tim=3017698471536
    WAIT #1: nam='SQL*Net message from client' ela= 2607 p1=1413697536 p2=1 p3=0
    FETCH #1:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=3017698474268
    WAIT #1: nam='SQL*Net message to client' ela= 1 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:35:07.656
    WAIT #1: nam='SQL*Net message from client' ela= 22922584 p1=1413697536 p2=1 p3=0
    STAT #1 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=0 r=0 w=0 time=93 us)'
    STAT #1 id=2 cnt=0 pid=1 pos=1 obj=0 op='FILTER  (cr=0 r=0 w=0 time=29 us)'
    STAT #1 id=3 cnt=0 pid=2 pos=1 obj=5769120 op='TABLE ACCESS FULL SOC_LIST '
    =====================
    PARSE ERROR #1:len=369 dep=0 uid=33 oct=0 lid=33 tim=3017721397730 err=900
    exec := 'N'
    SELEC ...
    WAIT #1: nam='SQL*Net break/reset to client' ela= 2 p1=1413697536 p2=1 p3=0
    WAIT #1: nam='SQL*Net break/reset to client' ela= 2403 p1=1413697536 p2=0 p3=0
    WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:35:24.017
    WAIT #1: nam='SQL*Net message from client' ela= 15973854 p1=1413697536 p2=1 p3=0
    QUERY
    SELECT  count(*)
       FROM SOC_LIST SOC
       WHERE
         ( EXISTS(  SELECT  1
                 FROM    ELIGIBILITY_RELATION
                 WHERE   SRC_CODE = 'SHDMM4215'
                      AND   DEST_CODE = SOC.SOC
                   AND   SRC_TYPE = 'P'
                   AND   DEST_TYPE = 'S'))
    UNION ALL
    SELECT count(*)
       FROM SOC_LIST SOC
       WHERE        ( = 'Y')
    =====================
    PARSING IN CURSOR #1 len=353 dep=0 uid=33 oct=3 lid=33 tim=3017737377655 hv=4202798596 ad='45639568'
    SELECT  count(*)
       FROM SOC_LIST SOC
       WHERE
         ( EXISTS(  SELECT  1
                 FROM    ELIGIBILITY_RELATION
                 WHERE   SRC_CODE = 'SHDMM4215'
                      AND   DEST_CODE = SOC.SOC
                   AND   SRC_TYPE = 'P'
                   AND   DEST_TYPE = 'S'))
    UNION ALL
    SELECT count(*)
       FROM SOC_LIST SOC
       WHERE        ( = 'Y')
    END OF STMT
    PARSE #1:c=0,e=2624,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=0,tim=3017737377644
    PARAMETERS USED BY THE OPTIMIZER
    OPTIMIZER_FEATURES_ENABLE = 9.2.0
    OPTIMIZER_MODE/GOAL = Choose
    _OPTIMIZER_PERCENT_PARALLEL = 101
    HASH_AREA_SIZE = 131072
    HASH_JOIN_ENABLED = TRUE
    HASH_MULTIBLOCK_IO_COUNT = 0
    SORT_AREA_SIZE = 65536
    OPTIMIZER_SEARCH_LIMIT = 5
    PARTITION_VIEW_ENABLED = FALSE
    _ALWAYS_STAR_TRANSFORMATION = FALSE
    _B_TREE_BITMAP_PLANS = TRUE
    STAR_TRANSFORMATION_ENABLED = FALSE
    _COMPLEX_VIEW_MERGING = TRUE
    _PUSH_JOIN_PREDICATE = TRUE
    PARALLEL_BROADCAST_ENABLED = TRUE
    OPTIMIZER_MAX_PERMUTATIONS = 2000
    OPTIMIZER_INDEX_CACHING = 0
    _SYSTEM_INDEX_CACHING = 0
    OPTIMIZER_INDEX_COST_ADJ = 1
    OPTIMIZER_DYNAMIC_SAMPLING = 1
    _OPTIMIZER_DYN_SMP_BLKS = 32
    QUERY_REWRITE_ENABLED = TRUE
    QUERY_REWRITE_INTEGRITY = ENFORCED
    _INDEX_JOIN_ENABLED = TRUE
    _SORT_ELIMINATION_COST_RATIO = 0
    _OR_EXPAND_NVL_PREDICATE = TRUE
    _NEW_INITIAL_JOIN_ORDERS = TRUE
    ALWAYS_ANTI_JOIN = CHOOSE
    ALWAYS_SEMI_JOIN = CHOOSE
    _OPTIMIZER_MODE_FORCE = TRUE
    _OPTIMIZER_UNDO_CHANGES = FALSE
    _UNNEST_SUBQUERY = TRUE
    _PUSH_JOIN_UNION_VIEW = TRUE
    _FAST_FULL_SCAN_ENABLED = TRUE
    _OPTIM_ENHANCE_NNULL_DETECTION = TRUE
    _ORDERED_NESTED_LOOP = TRUE
    _NESTED_LOOP_FUDGE = 100
    _NO_OR_EXPANSION = FALSE
    _QUERY_COST_REWRITE = TRUE
    QUERY_REWRITE_EXPRESSION = TRUE
    _IMPROVED_ROW_LENGTH_ENABLED = TRUE
    _USE_NOSEGMENT_INDEXES = FALSE
    _ENABLE_TYPE_DEP_SELECTIVITY = TRUE
    _IMPROVED_OUTERJOIN_CARD = TRUE
    _OPTIMIZER_ADJUST_FOR_NULLS = TRUE
    _OPTIMIZER_CHOOSE_PERMUTATION = 0
    _USE_COLUMN_STATS_FOR_FUNCTION = TRUE
    _SUBQUERY_PRUNING_ENABLED = TRUE
    _SUBQUERY_PRUNING_REDUCTION_FACTOR = 50
    _SUBQUERY_PRUNING_COST_FACTOR = 20
    _LIKE_WITH_BIND_AS_EQUALITY = FALSE
    _TABLE_SCAN_COST_PLUS_ONE = TRUE
    _SORTMERGE_INEQUALITY_JOIN_OFF = FALSE
    _DEFAULT_NON_EQUALITY_SEL_CHECK = TRUE
    _ONESIDE_COLSTAT_FOR_EQUIJOINS = TRUE
    _OPTIMIZER_COST_MODEL = CHOOSE
    _GSETS_ALWAYS_USE_TEMPTABLES = FALSE
    DB_FILE_MULTIBLOCK_READ_COUNT = 128
    _NEW_SORT_COST_ESTIMATE = TRUE
    _GS_ANTI_SEMI_JOIN_ALLOWED = TRUE
    _CPU_TO_IO = 0
    _PRED_MOVE_AROUND = TRUE
    BASE STATISTICAL INFORMATION
    Table stats    Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
      (Using composite stats)
      (adjusted for partition skews)
      ORIG STATS::  CDN: 11982220  NBLKS:  125493  AVG_ROW_LEN:  71
      PARTCNT::
      PRUNED: 4  ANALYZED: 4  UNANALYZED: 0
      TOTAL ::  CDN: 11982220  NBLKS:  125493  AVG_ROW_LEN:  71
    -- Index stats
      INDEX NAME: ELIGIBILITY_RELATION_1IX  COL#: 3 4 5
        USING COMPOSITE STATS
        TOTAL ::  LVLS: 2   #LB: 38360  #DK: 4164  LB/K: 9  DB/K: 740  CLUF: 3081860
      INDEX NAME: ELIGIBILITY_RELATION_PK  COL#: 2 3 4 5
        USING COMPOSITE STATS
        TOTAL ::  LVLS: 2   #LB: 50740  #DK: 11873160  LB/K: 1  DB/K: 1  CLUF: 9158280
      INDEX NAME: I_SNAP$_ELIGIBILITY_RELATI  COL#: 1
        TOTAL ::  LVLS: 2   #LB: 49600  #DK: 11953600  LB/K: 1  DB/K: 1  CLUF: 8833300
    _OPTIMIZER_PERCENT_PARALLEL = 0
    SINGLE TABLE ACCESS PATH
    Column:   SRC_CODE  Col#: 2      Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
        NDV: 22087     NULLS: 0         DENS: 4.5276e-05
        NO HISTOGRAM: #BKT: 1 #VAL: 2
    Column:  DEST_CODE  Col#: 4      Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
        NDV: 11970     NULLS: 0         DENS: 8.3542e-05
        NO HISTOGRAM: #BKT: 1 #VAL: 2
    Column:   SRC_TYPE  Col#: 3      Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
        NDV: 2         NULLS: 0         DENS: 5.0000e-01
        NO HISTOGRAM: #BKT: 1 #VAL: 2
    Column:  DEST_TYPE  Col#: 5      Table: ELIGIBILITY_RELATION   Alias: ELIGIBILITY_RELATION
        NDV: 2         NULLS: 0         DENS: 5.0000e-01
        NO HISTOGRAM: #BKT: 1 #VAL: 2
      TABLE: ELIGIBILITY_RELATION     ORIG CDN: 11982220  ROUNDED CDN: 1  CMPTD CDN: 0
      Access path: tsc  Resc:  3072  Resp:  3072
      Access path: index (iff)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 1243
      IX_SEL:  0.0000e+00  TB_SEL:  1.0000e+00
      Access path: iff  Resc:  1243  Resp:  1243
      Access path: index (unique)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 2
      IX_SEL:  8.3457e-08  TB_SEL:  8.3457e-08
      Access path: index (equal)
          Index: ELIGIBILITY_RELATION_1IX
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 68
      IX_SEL:  0.0000e+00  TB_SEL:  2.0886e-05
      Access path: index (eq-unique)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 2
      IX_SEL:  0.0000e+00  TB_SEL:  0.0000e+00
      ****** trying bitmap/domain indexes ******
      Access path: index (equal)
          Index: ELIGIBILITY_RELATION_1IX
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 3
      IX_SEL:  2.0886e-05  TB_SEL:  2.0886e-05
      Access path: index (index-only)
          Index: ELIGIBILITY_RELATION_PK
      TABLE: ELIGIBILITY_RELATION
          RSC_CPU: 0   RSC_IO: 5
      IX_SEL:  4.5276e-05  TB_SEL:  4.5276e-05
        SORT resource      Sort statistics
          Sort width:           11 Area size:      628736 Max Area size:    31457280   Degree: 1
          Blocks to Sort:        2 Row size:           21 Rows:        543
          Initial runs:          1 Merge passes:        1 IO Cost / pass:          3
          Total IO sort cost: 2
          Total CPU sort cost: 0
          Total Temp space used: 0
      ****** finished trying bitmap/domain indexes ******
    One row CDN: 1
      BEST_CST: 1.00  PATH: 3  Degree:  1
    OPTIMIZER STATISTICS AND COMPUTATIONS
    GENERAL PLANS
    Join order[1]:  ELIGIBILITY_RELATION[ELIGIBILITY_RELATION]#0
    Best so far: TABLE#: 0  CST:          1  CDN:          1  BYTES:         24
    Final - First Rows Plan:
      JOIN ORDER: 1
      CST: 1  CDN: 1  RSC: 1  RSP: 1  BYTES: 24
      IO-RSC: 1  IO-RSP: 1  CPU-RSC: 0  CPU-RSP: 0
      First Rows Plan
    PARAMETERS USED BY THE OPTIMIZER
    OPTIMIZER_FEATURES_ENABLE = 9.2.0
    OPTIMIZER_MODE/GOAL = Choose
    _OPTIMIZER_PERCENT_PARALLEL = 101
    HASH_AREA_SIZE = 131072
    HASH_JOIN_ENABLED = TRUE
    HASH_MULTIBLOCK_IO_COUNT = 0
    SORT_AREA_SIZE = 65536
    OPTIMIZER_SEARCH_LIMIT = 5
    PARTITION_VIEW_ENABLED = FALSE
    _ALWAYS_STAR_TRANSFORMATION = FALSE
    _B_TREE_BITMAP_PLANS = TRUE
    STAR_TRANSFORMATION_ENABLED = FALSE
    _COMPLEX_VIEW_MERGING = TRUE
    _PUSH_JOIN_PREDICATE = TRUE
    PARALLEL_BROADCAST_ENABLED = TRUE
    OPTIMIZER_MAX_PERMUTATIONS = 2000
    OPTIMIZER_INDEX_CACHING = 0
    _SYSTEM_INDEX_CACHING = 0
    OPTIMIZER_INDEX_COST_ADJ = 1
    OPTIMIZER_DYNAMIC_SAMPLING = 1
    _OPTIMIZER_DYN_SMP_BLKS = 32
    QUERY_REWRITE_ENABLED = TRUE
    QUERY_REWRITE_INTEGRITY = ENFORCED
    _INDEX_JOIN_ENABLED = TRUE
    _SORT_ELIMINATION_COST_RATIO = 0
    _OR_EXPAND_NVL_PREDICATE = TRUE
    _NEW_INITIAL_JOIN_ORDERS = TRUE
    ALWAYS_ANTI_JOIN = CHOOSE
    ALWAYS_SEMI_JOIN = CHOOSE
    _OPTIMIZER_MODE_FORCE = TRUE
    _OPTIMIZER_UNDO_CHANGES = FALSE
    _UNNEST_SUBQUERY = TRUE
    _PUSH_JOIN_UNION_VIEW = TRUE
    _FAST_FULL_SCAN_ENABLED = TRUE
    _OPTIM_ENHANCE_NNULL_DETECTION = TRUE
    _ORDERED_NESTED_LOOP = TRUE
    _NESTED_LOOP_FUDGE = 100
    _NO_OR_EXPANSION = FALSE
    _QUERY_COST_REWRITE = TRUE
    QUERY_REWRITE_EXPRESSION = TRUE
    _IMPROVED_ROW_LENGTH_ENABLED = TRUE
    _USE_NOSEGMENT_INDEXES = FALSE
    _ENABLE_TYPE_DEP_SELECTIVITY = TRUE
    _IMPROVED_OUTERJOIN_CARD = TRUE
    _OPTIMIZER_ADJUST_FOR_NULLS = TRUE
    _OPTIMIZER_CHOOSE_PERMUTATION = 0
    _USE_COLUMN_STATS_FOR_FUNCTION = TRUE
    _SUBQUERY_PRUNING_ENABLED = TRUE
    _SUBQUERY_PRUNING_REDUCTION_FACTOR = 50
    _SUBQUERY_PRUNING_COST_FACTOR = 20
    _LIKE_WITH_BIND_AS_EQUALITY = FALSE
    _TABLE_SCAN_COST_PLUS_ONE = TRUE
    _SORTMERGE_INEQUALITY_JOIN_OFF = FALSE
    _DEFAULT_NON_EQUALITY_SEL_CHECK = TRUE
    _ONESIDE_COLSTAT_FOR_EQUIJOINS = TRUE
    _OPTIMIZER_COST_MODEL = CHOOSE
    _GSETS_ALWAYS_USE_TEMPTABLES = FALSE
    DB_FILE_MULTIBLOCK_READ_COUNT = 128
    _NEW_SORT_COST_ESTIMATE = TRUE
    _GS_ANTI_SEMI_JOIN_ALLOWED = TRUE
    _CPU_TO_IO = 0
    _PRED_MOVE_AROUND = TRUE
    BASE STATISTICAL INFORMATION
    Table stats    Table: SOC_LIST   Alias: SYS_ALIAS_1
      TOTAL ::  CDN: 17584  NBLKS:  653  AVG_ROW_LEN:  260
    -- Index stats
      INDEX NAME: I_SNAP$_SOC_LIST  COL#: 1
        TOTAL ::  LVLS: 1   #LB: 64  #DK: 17487  LB/K: 1  DB/K: 1  CLUF: 699
      INDEX NAME: SOC_LIST_1IX  COL#: 3
        TOTAL ::  LVLS: 1   #LB: 47  #DK: 17487  LB/K: 1  DB/K: 1  CLUF: 14065
    _OPTIMIZER_PERCENT_PARALLEL = 0
    SINGLE TABLE ACCESS PATH
      TABLE: SOC_LIST     ORIG CDN: 17584  ROUNDED CDN: 879  CMPTD CDN: 879
      Access path: tsc  Resc:  18  Resp:  18
      ****** trying bitmap/domain indexes ******
      ****** finished trying bitmap/domain indexes ******
      BEST_CST: 18.00  PATH: 2  Degree:  1
    OPTIMIZER STATISTICS AND COMPUTATIONS
    GENERAL PLANS
    Join order[1]:  SOC_LIST[SYS_ALIAS_1]#0
    Best so far: TABLE#: 0  CST:         18  CDN:        879  BYTES:       8790
    Final - All Rows Plan:
      JOIN ORDER: 1
      CST: 18  CDN: 879  RSC: 18  RSP: 18  BYTES: 8790
      IO-RSC: 18  IO-RSP: 18  CPU-RSC: 0  CPU-RSP: 0
    PARAMETERS USED BY THE OPTIMIZER
    OPTIMIZER_FEATURES_ENABLE = 9.2.0
    OPTIMIZER_MODE/GOAL = Choose
    _OPTIMIZER_PERCENT_PARALLEL = 101
    HASH_AREA_SIZE = 131072
    HASH_JOIN_ENABLED = TRUE
    HASH_MULTIBLOCK_IO_COUNT = 0
    SORT_AREA_SIZE = 65536
    OPTIMIZER_SEARCH_LIMIT = 5
    PARTITION_VIEW_ENABLED = FALSE
    _ALWAYS_STAR_TRANSFORMATION = FALSE
    _B_TREE_BITMAP_PLANS = TRUE
    STAR_TRANSFORMATION_ENABLED = FALSE
    _COMPLEX_VIEW_MERGING = TRUE
    _PUSH_JOIN_PREDICATE = TRUE
    PARALLEL_BROADCAST_ENABLED = TRUE
    OPTIMIZER_MAX_PERMUTATIONS = 2000
    OPTIMIZER_INDEX_CACHING = 0
    _SYSTEM_INDEX_CACHING = 0
    OPTIMIZER_INDEX_COST_ADJ = 1
    OPTIMIZER_DYNAMIC_SAMPLING = 1
    _OPTIMIZER_DYN_SMP_BLKS = 32
    QUERY_REWRITE_ENABLED = TRUE
    QUERY_REWRITE_INTEGRITY = ENFORCED
    _INDEX_JOIN_ENABLED = TRUE
    _SORT_ELIMINATION_COST_RATIO = 0
    _OR_EXPAND_NVL_PREDICATE = TRUE
    _NEW_INITIAL_JOIN_ORDERS = TRUE
    ALWAYS_ANTI_JOIN = CHOOSE
    ALWAYS_SEMI_JOIN = CHOOSE
    _OPTIMIZER_MODE_FORCE = TRUE
    _OPTIMIZER_UNDO_CHANGES = FALSE
    _UNNEST_SUBQUERY = TRUE
    _PUSH_JOIN_UNION_VIEW = TRUE
    _FAST_FULL_SCAN_ENABLED = TRUE
    _OPTIM_ENHANCE_NNULL_DETECTION = TRUE
    _ORDERED_NESTED_LOOP = TRUE
    _NESTED_LOOP_FUDGE = 100
    _NO_OR_EXPANSION = FALSE
    _QUERY_COST_REWRITE = TRUE
    QUERY_REWRITE_EXPRESSION = TRUE
    _IMPROVED_ROW_LENGTH_ENABLED = TRUE
    _USE_NOSEGMENT_INDEXES = FALSE
    _ENABLE_TYPE_DEP_SELECTIVITY = TRUE
    _IMPROVED_OUTERJOIN_CARD = TRUE
    _OPTIMIZER_ADJUST_FOR_NULLS = TRUE
    _OPTIMIZER_CHOOSE_PERMUTATION = 0
    _USE_COLUMN_STATS_FOR_FUNCTION = TRUE
    _SUBQUERY_PRUNING_ENABLED = TRUE
    _SUBQUERY_PRUNING_REDUCTION_FACTOR = 50
    _SUBQUERY_PRUNING_COST_FACTOR = 20
    _LIKE_WITH_BIND_AS_EQUALITY = FALSE
    _TABLE_SCAN_COST_PLUS_ONE = TRUE
    _SORTMERGE_INEQUALITY_JOIN_OFF = FALSE
    _DEFAULT_NON_EQUALITY_SEL_CHECK = TRUE
    _ONESIDE_COLSTAT_FOR_EQUIJOINS = TRUE
    _OPTIMIZER_COST_MODEL = CHOOSE
    _GSETS_ALWAYS_USE_TEMPTABLES = FALSE
    DB_FILE_MULTIBLOCK_READ_COUNT = 128
    _NEW_SORT_COST_ESTIMATE = TRUE
    _GS_ANTI_SEMI_JOIN_ALLOWED = TRUE
    _CPU_TO_IO = 0
    _PRED_MOVE_AROUND = TRUE
    BASE STATISTICAL INFORMATION
    Table stats    Table: SOC_LIST   Alias: SOC
      TOTAL ::  CDN: 17584  NBLKS:  653  AVG_ROW_LEN:  260
    -- Index stats
      INDEX NAME: I_SNAP$_SOC_LIST  COL#: 1
        TOTAL ::  LVLS: 1   #LB: 64  #DK: 17487  LB/K: 1  DB/K: 1  CLUF: 699
      INDEX NAME: SOC_LIST_1IX  COL#: 3
        TOTAL ::  LVLS: 1   #LB: 47  #DK: 17487  LB/K: 1  DB/K: 1  CLUF: 14065
    _OPTIMIZER_PERCENT_PARALLEL = 0
    SINGLE TABLE ACCESS PATH
      TABLE: SOC_LIST     ORIG CDN: 17584  ROUNDED CDN: 17584  CMPTD CDN: 17584
      Access path: tsc  Resc:  18  Resp:  18
      ****** trying bitmap/domain indexes ******
      ****** finished trying bitmap/domain indexes ******
      BEST_CST: 18.00  PATH: 2  Degree:  1
    OPTIMIZER STATISTICS AND COMPUTATIONS
    GENERAL PLANS
    Join order[1]:  SOC_LIST[SOC]#0
    Best so far: TABLE#: 0  CST:         18  CDN:      17584  BYTES:          0
    Final - All Rows Plan:
      JOIN ORDER: 1
      CST: 18  CDN: 17584  RSC: 18  RSP: 18  BYTES: 0
      IO-RSC: 18  IO-RSP: 18  CPU-RSC: 0  CPU-RSP: 0
    BINDS #1:
    bind 0: dty=96 mxl=32(01) mal=00 scl=00 pre=00 oacflg=03 oacfl2=0 size=32 offset=0
       bfp=800003ffefea9490 bln=32 avl=01 flg=05
       value="N"
    EXEC #1:c=0,e=159,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017737385286
    WAIT #1: nam='SQL*Net message to client' ela= 2 p1=1413697536 p2=1 p3=0
    WAIT #1: nam='db file sequential read' ela= 9958 p1=586 p2=128001 p3=1
    WAIT #1: nam='db file scattered read' ela= 619 p1=586 p2=128002 p3=4
    WAIT #1: nam='db file sequential read' ela= 12880 p1=2535 p2=39498 p3=1
    WAIT #1: nam='db file sequential read' ela= 39878 p1=2536 p2=68185 p3=1
    WAIT #1: nam='db file sequential read' ela= 10240 p1=2536 p2=68520 p3=1
    WAIT #1: nam='db file sequential read' ela= 15805 p1=2535 p2=45162 p3=1
    WAIT #1: nam='db file sequential read' ela= 11733 p1=2535 p2=178335 p3=1
    WAIT #1: nam='db file sequential read' ela= 11863 p1=2535 p2=178798 p3=1
    WAIT #1: nam='db file sequential read' ela= 4886 p1=2535 p2=33834 p3=1
    WAIT #1: nam='db file sequential read' ela= 12067 p1=2536 p2=60958 p3=1
    WAIT #1: nam='db file sequential read' ela= 16496 p1=2535 p2=61232 p3=1
    WAIT #1: nam='db file sequential read' ela= 8970 p1=2535 p2=50826 p3=1
    WAIT #1: nam='db file sequential read' ela= 10940 p1=2536 p2=260451 p3=1
    WAIT #1: nam='db file sequential read' ela= 8508 p1=2536 p2=261538 p3=1
    WAIT #1: nam='db file scattered read' ela= 32000 p1=1613 p2=4622 p3=35
    WAIT #1: nam='db file sequential read' ela= 1762 p1=2535 p2=178799 p3=1
    WAIT #1: nam='db file sequential read' ela= 341 p1=2535 p2=61233 p3=1
    WAIT #1: nam='db file scattered read' ela= 50494 p1=957 p2=230324 p3=35
    WAIT #1: nam='db file scattered read' ela= 36716 p1=5 p2=588169 p3=35
    WAIT #1: nam='db file scattered read' ela= 45241 p1=2326 p2=227427 p3=35
    WAIT #1: nam='db file sequential read' ela= 11783 p1=2535 p2=68809 p3=1
    WAIT #1: nam='db file scattered read' ela= 26720 p1=471 p2=102809 p3=35
    WAIT #1: nam='db file scattered read' ela= 31074 p1=1496 p2=97015 p3=35
    WAIT #1: nam='db file scattered read' ela= 39750 p1=586 p2=69452 p3=35
    WAIT #1: nam='db file scattered read' ela= 30923 p1=1613 p2=8636 p3=35
    WAIT #1: nam='db file scattered read' ela= 46328 p1=957 p2=67050 p3=35
    WAIT #1: nam='db file scattered read' ela= 34570 p1=5 p2=362823 p3=35
    WAIT #1: nam='db file scattered read' ela= 43343 p1=2326 p2=240311 p3=35
    WAIT #1: nam='db file scattered read' ela= 30818 p1=471 p2=76417 p3=35
    WAIT #1: nam='db file scattered read' ela= 19167 p1=1496 p2=480612 p3=35
    WAIT #1: nam='db file scattered read' ela= 26405 p1=586 p2=193036 p3=35
    WAIT #1: nam='db file scattered read' ela= 35374 p1=1613 p2=201565 p3=35
    WAIT #1: nam='db file scattered read' ela= 14275 p1=957 p2=15804 p3=7
    FETCH #1:c=190000,e=926019,p=552,cr=43429,cu=0,mis=0,r=1,dep=0,og=4,tim=3017738311433
    WAIT #1: nam='SQL*Net message from client' ela= 2749 p1=1413697536 p2=1 p3=0
    WAIT #1: nam='SQL*Net message to client' ela= 2 p1=1413697536 p2=1 p3=0
    FETCH #1:c=0,e=79,p=0,cr=0,cu=0,mis=0,r=1,dep=0,og=4,tim=3017738314443
    *** 2013-06-10 13:35:44.078
    WAIT #1: nam='SQL*Net message from client' ela= 18650883 p1=1413697536 p2=1 p3=0
    STAT #1 id=1 cnt=2 pid=0 pos=1 obj=0 op='UNION-ALL  (cr=43429 r=552 w=0 time=926047 us)'
    STAT #1 id=2 cnt=1 pid=1 pos=1 obj=0 op='SORT AGGREGATE (cr=43429 r=552 w=0 time=925989 us)'
    STAT #1 id=3 cnt=157 pid=2 pos=1 obj=0 op='FILTER  (cr=43429 r=552 w=0 time=925909 us)'
    STAT #1 id=4 cnt=14296 pid=3 pos=1 obj=5769120 op='TABLE ACCESS FULL SOC_LIST (cr=541 r=537 w=0 time=579577 us)'
    STAT #1 id=5 cnt=157 pid=3 pos=2 obj=0 op='PARTITION HASH SINGLE PARTITION: KEY KEY (cr=42888 r=15 w=0 time=285564 us)'
    STAT #1 id=6 cnt=157 pid=5 pos=1 obj=5401812 op='INDEX UNIQUE SCAN ELIGIBILITY_RELATION_PK PARTITION: KEY KEY (cr=42888 r=15 w=0 time=265355 us)'
    STAT #1 id=7 cnt=1 pid=1 pos=2 obj=0 op='SORT AGGREGATE (cr=0 r=0 w=0 time=4 us)'
    STAT #1 id=8 cnt=0 pid=7 pos=1 obj=0 op='FILTER  (cr=0 r=0 w=0 time=1 us)'
    STAT #1 id=9 cnt=0 pid=8 pos=1 obj=5769120 op='TABLE ACCESS FULL SOC_LIST '
    QUERY
    select 'close cursor' from dual
    =====================
    PARSING IN CURSOR #1 len=31 dep=0 uid=33 oct=3 lid=33 tim=3017756967074 hv=3487944275 ad='48de6a60'
    select 'close cursor' from dual
    END OF STMT
    PARSE #1:c=0,e=986,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017756967063
    BINDS #1:
    EXEC #1:c=0,e=47,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017756967278
    WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
    FETCH #1:c=0,e=134,p=0,cr=3,cu=0,mis=0,r=1,dep=0,og=4,tim=3017756967515
    WAIT #1: nam='SQL*Net message from client' ela= 2682 p1=1413697536 p2=1 p3=0
    FETCH #1:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=3017756970325
    WAIT #1: nam='SQL*Net message to client' ela= 1 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:35:57.804
    WAIT #1: nam='SQL*Net message from client' ela= 13399621 p1=1413697536 p2=1 p3=0
    =====================
    PARSING IN CURSOR #3 len=116 dep=1 uid=0 oct=3 lid=0 tim=3017770371839 hv=431456802 ad='39fbad80'
    select o.owner#,o.name,o.namespace,o.remoteowner,o.linkname,o.subname,o.dataobj#,o.flags from obj$ o where o.obj#=:1
    END OF STMT
    PARSE #3:c=0,e=1249,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=0,tim=3017770371828
    BINDS #3:
    bind 0: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=08 oacfl2=1 size=24 offset=0
       bfp=800003ffefea7a90 bln=22 avl=03 flg=05
       value=172
    EXEC #3:c=0,e=666,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=3017770372725
    WAIT #3: nam='db file sequential read' ela= 10318 p1=1 p2=978 p3=1
    WAIT #3: nam='db file sequential read' ela= 10292 p1=1 p2=318 p3=1
    FETCH #3:c=10000,e=21071,p=2,cr=3,cu=0,mis=0,r=1,dep=1,og=4,tim=3017770393830
    STAT #1 id=1 cnt=1 pid=0 pos=1 obj=172 op='TABLE ACCESS FULL DUAL (cr=3 r=0 w=0 time=121 us)'
    QUERY
    ALTER SESSION SET EVENTS '10053 trace name context off'
    =====================
    PARSING IN CURSOR #1 len=55 dep=0 uid=33 oct=42 lid=33 tim=3017770394351 hv=3500836485 ad='3bed84c8'
    ALTER SESSION SET EVENTS '10053 trace name context off'
    END OF STMT
    PARSE #1:c=0,e=227,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017770394344
    BINDS #1:
    EXEC #1:c=0,e=177,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017770394624
    WAIT #1: nam='SQL*Net message to client' ela= 4 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:36:13.139
    WAIT #1: nam='SQL*Net message from client' ela= 14951473 p1=1413697536 p2=1 p3=0
    =====================
    PARSE ERROR #1:len=55 dep=0 uid=33 oct=42 lid=33 tim=3017785346905 err=911
    ALTER SESSION SET EVENT=¿10046 trace name context off¿
    WAIT #1: nam='SQL*Net break/reset to client' ela= 2 p1=1413697536 p2=1 p3=0
    WAIT #1: nam='SQL*Net break/reset to client' ela= 2358 p1=1413697536 p2=0 p3=0
    WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:36:53.497
    WAIT #1: nam='SQL*Net message from client' ela= 39408861 p1=1413697536 p2=1 p3=0
    =====================
    PARSE ERROR #1:len=56 dep=0 uid=33 oct=42 lid=33 tim=3017824759339 err=911
    ALTER SESSION SET EVENTS ¿10046 trace name context off¿
    WAIT #1: nam='SQL*Net break/reset to client' ela= 4 p1=1413697536 p2=1 p3=0
    WAIT #1: nam='SQL*Net break/reset to client' ela= 2342 p1=1413697536 p2=0 p3=0
    WAIT #1: nam='SQL*Net message to client' ela= 4 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:37:17.528
    WAIT #1: nam='SQL*Net message from client' ela= 23463963 p1=1413697536 p2=1 p3=0
    =====================
    PARSE ERROR #1:len=57 dep=0 uid=33 oct=42 lid=33 tim=3017848226738 err=911
    ALTER SESSION SET EVENTS '10043 trace name context off';
    WAIT #1: nam='SQL*Net break/reset to client' ela= 1 p1=1413697536 p2=1 p3=0
    WAIT #1: nam='SQL*Net break/reset to client' ela= 2305 p1=1413697536 p2=0 p3=0
    WAIT #1: nam='SQL*Net message to client' ela= 3 p1=1413697536 p2=1 p3=0
    WAIT #1: nam='SQL*Net message from client' ela= 9416071 p1=1413697536 p2=1 p3=0
    =====================
    PARSING IN CURSOR #1 len=55 dep=0 uid=33 oct=42 lid=33 tim=3017857646552 hv=2635134026 ad='4b92b7e8'
    ALTER SESSION SET EVENTS '10043 trace name context off'
    END OF STMT
    PARSE #1:c=0,e=616,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=3017857646541
    BINDS #1:
    EXEC #1:c=0,e=285,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=3017857647009
    WAIT #1: nam='SQL*Net message to client' ela= 4 p1=1413697536 p2=1 p3=0
    *** 2013-06-10 13:58:46.112
    WAIT #1: nam='SQL*Net message from client' ela= 1248974802 p1=1413697536 p2=1 p3=0
    XCTEND rlbk=0, rd_only=1

  • 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

  • Error while executing UNION ALL query

    Hello everyone,
    I'm executing the below query on Oracle 9.2.0.8 version.
    select hdr.*
    from ttl_hdr hdr, ttl_service ser
    where hdr.cus_nbr = ser.cus_nbr
    and hdr.dn in ('1232','2342',343','343')
    union all
    select hdr.*
    from ttl_hdr_his hdr, ttl_service ser
    where hdr.cus_nbr = ser.cus_nbr
    and hdr.dn in ('1232','2342',343','343')
    and I encounter following error:
    ORA-01790: expression must have same datatype as corresponding expression
    But instead of * if I'm specifying a list of few columns, it executes the query properly.
    Can anybody tell me what the problem is ?
    regards,
    Rossy

    Hi,
    All columns in your tables TTL_HDR and TTL_HDR_HIS are not with same data type.
    I'm sure you get same error if you specify all columns that * brings.
    Specify column names and use conversion function to get data type same to column from both selects.
    PS: and I think this is not Application Express related
    Br, Jari

Maybe you are looking for

  • Is there a way to transfer music from an iPod I found to my iPhone without a computer?

    Hey guys I found an ipod with music that I like and I wanted to transfer it to my phone but I do not have a computer. Is there any way to transfer or no?

  • Is Flash CS6 compatible with Yosemite?

    Has anyone tried running it? I have CS4, which I'm pretty sure is not compatible. I could upgrade to CS6, but I don't want to be tied down to the subscription model of CC.

  • Internal order error: AuC missing for origin assignment

    Hi, We had this requirement of blocking Internal Orders (their use has been discontinued from the past 2 years). I used KOK4. Many of the orders got blocked except for those of Order Type Capex. The following error appears: AuC missing for origin ass

  • Auto-starting dependencies with SMF

    I'm developing installers for an app that needs to be installed on Solaris 10, but I am not a Solaris administrator. My installer installs 2 server apps, App A and App B. App A depends on App B to be up and running when App A starts, but I'd prefer n

  • User Parameters

    Is there a defined report in which you can view all users and the parameters they currently have. SUIM does not provide this information. Thanks, Maritza Edited by: Maritza Ramos on Dec 27, 2007 7:27 PM