Re: What index do I need for this query ?
Date: Tue, 24 Mar 2009 17:12:27 -0700 (PDT)
On Mar 24, 7:04 pm, krisl..._at_gmail.com wrote:
> Hi gurus,
> I have the query like below :
> SELECT INVH.REGS_CODE, INVH.CUST_CODE, INVH.TAXDATE, INVH.TAXNO,
> INVH.INV_ID, INVH.INV_NO, INVH.INV_DATE,
> INVH.LOC_CODE, INVH.LOCGRP_CODE, NVL(INVH.DISCBM_RP,0) AS
> INVH.GROSS AS GROSS_HDR, NVL(INVH.VAT,0) AS VAT_HDR,
> INVH.NETTO AS NETTO_HDR, INVH.FLG_PPN_DP
> FROM INVOICE_H INVH
> WHERE INVH.INV_NO BETWEEN :InvoiceNumber AND :InvoiceNumberUpto
> AND INVH.TAXNO BETWEEN TRIM(SUBSTR(:TaxNoFr,3)) AND TRIM(SUBSTR
> AND INVH.TAXDATE BETWEEN TO_DATE(:TaxDateFr,'DD-MM-YYYY') AND
> TO_DATE(:TaxDateTo,'DD-MM-YYYY') AND
> INVH.CUST_CODE BETWEEN :CustFr AND :CustTo AND
> INVH.REGS_CODE BETWEEN :RegsFr AND :RegsTo AND
> AND NVL(INVH.TAXNO,' ')<>' '
> What index can help this query to perform ?
> Thank you very much,
Being that this appears to be an invoice header table the most likely canidate for indexing is the invoice number but the CBO might be able to make better use of an index on one or more of the other columns used in your where cause but without the explain plain and the column statistics there is no way for anyone to know.
The explain plan will show how Oracle is going to solve the query. The column statistics might show that one of the columns used in the where clause is highly selective.
Also shouldn't "AND NVL(INVH.TAXNO,' ')<>' " be " and invh.taxno is not null " ?
HTH -- Mark D Powell -- Received on Tue Mar 24 2009 - 19:12:27 CDT