0

我有一个查询在选择所有列时完成(使用 select * from),但在选择一个列名时它没有完成。我已经创建了必要的索引。这是我的查询

    SELECT q2.ssn vn_ssn
    --when * here instead of column name then the query completes
    FROM table_0 q2
    LEFT OUTER JOIN
      (SELECT ial_t.pin,
        ial_t.serial_number,
        ial_t.surname,
        ial_t.name,
        ial_t.patronymic,
        ial_t.prev_surname
      FROM
        (SELECT pin,
          MAX(serial_number) m_serial_number
        FROM table_1
        GROUP BY pin
        ) ial_m
      INNER JOIN table_1 ial_t
      ON ial_t.serial_number = ial_m.m_serial_number
      ) ial ON q2.pincode    = ial.pin
    LEFT OUTER JOIN table_2 v_q2
    ON V_Q2.VN_TPN     = Q2.TPN
    WHERE v_q2.vn_tpn IS NULL;

** EDIT: **



     1. Plan (Select * from table_name)

            Plan hash value: 2508092269

            ---------------------------------------------------------------------------------------------------
            | Id  | Operation              | Name             | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
            ---------------------------------------------------------------------------------------------------
            |   0 | SELECT STATEMENT       |                  |   438K|   248M|       |   341K  (1)| 01:08:13 |
            |*  1 |  HASH JOIN OUTER       |                  |   438K|   248M|   193M|   341K  (1)| 01:08:13 |
            |*  2 |   HASH JOIN RIGHT OUTER|                  |   438K|   188M|    54M| 19424   (1)| 00:03:54 |
            |   3 |    TABLE ACCESS FULL   | VN_Q2            |   439K|    49M|       |  1673   (2)| 00:00:21 |
            |   4 |    TABLE ACCESS FULL   | Q2               |   438K|   139M|       |  7889   (1)| 00:01:35 |
            |   5 |   VIEW                 |                  |  6751K|   914M|       |   262K  (1)| 00:52:34 |
            |*  6 |    HASH JOIN           |                  |  6751K|   386M|   122M|   262K  (1)| 00:52:34 |
            |   7 |     VIEW               |                  |  6742K|    45M|       |   134K  (1)| 00:26:55 |
            |   8 |      HASH GROUP BY     |                  |  6742K|   109M|   458M|   134K  (1)| 00:26:55 |
            |   9 |       TABLE ACCESS FULL| IAMAS_ALL_LAST_2 |    10M|   167M|       | 90003   (1)| 00:18:01 |
            |  10 |     TABLE ACCESS FULL  | IAMAS_ALL_LAST_2 |    10M|   521M|       | 90270   (1)| 00:18:04 |
            ---------------------------------------------------------------------------------------------------

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

               1 - access("Q2"."PINCODE"="IAL"."PIN"(+))
               2 - access("V_Q2"."VN_TPN"(+)="Q2"."TPN")
               6 - access("IAL_T"."SERIAL_NUMBER"="IAL_M"."M_SERIAL_NUMBER")

2. Plan (Select column_name from table_name)

Plan hash value: 1784658367

------------------------------------------------------------------------------------------------------------------
| Id  | Operation                      | Name                    | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT               |                         |     1 |    55 |       |   144K  (1)| 00:28:52 |
|   1 |  NESTED LOOPS OUTER            |                         |     1 |    55 |       |   144K  (1)| 00:28:52 |
|*  2 |   HASH JOIN RIGHT ANTI         |                         |     1 |    51 |  9880K|  9735   (1)| 00:01:57 |
|   3 |    INDEX FAST FULL SCAN        | VN_Q2_TPN_IDX           |   439K|  4722K|       |   301   (2)| 00:00:04 |
|   4 |    TABLE ACCESS FULL           | Q2                      |   438K|    16M|       |  7867   (1)| 00:01:35 |
|   5 |   VIEW PUSHED PREDICATE        |                         |     1 |     4 |       |   134K  (1)| 00:26:55 |
|*  6 |    HASH JOIN                   |                         |     1 |    32 |       |   134K  (1)| 00:26:55 |
|   7 |     TABLE ACCESS BY INDEX ROWID| IAMAS_ALL_LAST_2        |     2 |    50 |       |     5   (0)| 00:00:01 |
|*  8 |      INDEX RANGE SCAN          | IAMAS_ALL_LAST_2_INDEX2 |     2 |       |       |     3   (0)| 00:00:01 |
|   9 |     VIEW                       |                         |  6742K|    45M|       |   134K  (1)| 00:26:55 |
|  10 |      SORT GROUP BY             |                         |  6742K|   109M|   458M|   134K  (1)| 00:26:55 |
|  11 |       TABLE ACCESS FULL        | IAMAS_ALL_LAST_2        |    10M|   167M|       | 90003   (1)| 00:18:01 |
------------------------------------------------------------------------------------------------------------------

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

   2 - access("V_Q2"."VN_TPN"="Q2"."TPN")
   6 - access("IAL_T"."SERIAL_NUMBER"="IAL_M"."M_SERIAL_NUMBER")
   8 - access("IAL_T"."PIN"="Q2"."PINCODE")
4

1 回答 1

1

您可以将第一个外部联接替换为 OLAP 函数:

FROM table_0 q2
LEFT OUTER JOIN
  (
   SELECT *
   FROM
     (
      SELECT ial_t.pin,
        ial_t.serial_number,
        ial_t.surname,
        ial_t.name,
        ial_t.patronymic,
        ial_t.prev_surname,
        ROW_NUMBER() OVER (PARTITION BY pin ORDER BY serial_number DESC) AS rn
      FROM table_1
     ) ial_m
    WHERE rn = 1
  ) ial ON q2.pincode = ial.pin

如果您不需要在选择列表中访问此表的任何行,您可以简单地删除此联接,它不会更改返回的行数,因为它是外部联接。

于 2013-09-16T06:35:57.093 回答