Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

View doesn't use index on underlying Mview but mview uses index

gauravApr 17 2015 — edited Apr 21 2015

Hi,

I faced a situation where while querying data from view based on mview does not use index but when we query from mview it uses index and give fast results.

Following are the details:

querying from view: (completes in more than a minute even after passing hint)

================================

explain plan for select /*+ index(  ITGI_CREDITOR_LEDGER_CMV ITGI_CREDITOR_LEDGER_INDX) */ * from CR_LEDGER_REP_V where vendor_id='1474911';

Plan hash value: 463951623

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

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

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

|   0 | SELECT STATEMENT       |                          |  9056K|  5648M| 97644   (1)| 00:00:04 |

|*  1 |  VIEW                  | CR_LEDGER_REP_V          |  9056K|  5648M| 97644   (1)| 00:00:04 |

|   2 |   COUNT                |                          |       |       |            |          |

|   3 |    MAT_VIEW ACCESS FULL| ITGI_CREDITOR_LEDGER_CMV |  9056K|  2159M| 97644   (1)| 00:00:04 |

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

Predicate Information (identified by operation id):

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

   1 - filter("VENDOR_ID"=1474911)

Querying from mview: (completes within a second)

==============================

explain plan for select /*+ index(  ITGI_CREDITOR_LEDGER_CMV ITGI_CREDITOR_LEDGER_INDX) */ * from ITGI_CREDITOR_LEDGER_CMV where vendor_id='1474911';

Plan hash value: 1726512073

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

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

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

|   0 | SELECT STATEMENT                       |                           |    21 |  5880 |    21   (0)| 00:00:01 |

|   1 |  MAT_VIEW ACCESS BY INDEX ROWID BATCHED| ITGI_CREDITOR_LEDGER_CMV  |    21 |  5880 |    21   (0)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN                     | ITGI_CREDITOR_LEDGER_INDX |    22 |       |     3   (0)| 00:00:01 |

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

Predicate Information (identified by operation id):

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

   2 - access("VENDOR_ID"=1474911)

View DDL

========================

CREATE OR REPLACE FORCE VIEW SANJAY.CR_LEDGER_REP_V

(

   QRY,

   SR_NO,

   VENDOR_ID,

   VENDOR_TYPE,

   VENDOR_NUMBER,

   VENDOR_NAME,

   VENDOR_SITE_ID,

   VENDOR_SITE_CODE,

   GL_DATE,

   ACCOUNTING_DATE,

   PO,

   INVOICE_TYPE,

   AP_INVOICE_NO,

   INVOICE_DOC_CAT,

   AP_INVOICE_DATE,

   INVOICE_VOUCHER_NO,

   PAYMENT_VOUCHER_NO,

   CHQ_NO,

   DESCRIPTION,

   PAYMENT_DATE,

   ACC_CODE,

   PAYMENT_METHOD,

   CURR_CODE,

   DEBIT,

   CREDIT

)

AS

   SELECT qry,

          ROWNUM srn,

          vendor_id,

          vendor_type_lookup_code,

          vendor_no,

          vendor_name,

          vendor_site_id,

          vendor_site_code,

          gl_date,

          accounting_date,

          po_distribution_id,

          invoice_type_lookup_code,

          invoice_num,

          doc_category_code,

          invoice_date,

          inv_voucher_num,

          payment_num,

          check_number,

          description,

          pay_accounting_date,

          account_code,

          payment_method_code,

          invoice_currency_code,

          debit,

          credit

     FROM sanjay.itgi_creditor_ledger_cmv;

Even if I don't use the hints the plan doesn't change.

Though I have told developer to use mview directly, but I could not understand this behaviour.

DB version : 12.1

OS : AIX 6.1

Regards,

Gaurav

This post has been answered by AndrewSayer on Apr 19 2015
Jump to Answer

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 19 2015
Added on Apr 17 2015
10 comments
2,736 views