Subject Plans involving views
Author Rick Debay
If I have a view that wraps an aggregate query, and query the view
adding a where clause the plan doesn't use the available indexes and
instead goes through the entire table.
If I cut-and-paste the body of the view into the query, then the plan
uses the correct index.

SELECT
*
FROM
V_CLAIM_BO_INVOICE
WHERE
DECIMALQTY = 123

PLAN SORT (JOIN (JOIN (JOIN (V_CLAIM_BO_INVOICE CPR
NATURAL,V_CLAIM_BO_INVOICE COI INDEX
(FK_RPLCLMPOITM_CLAIM)),V_CLAIM_BO_INVOICE CII INDEX
(FK_RPLCLMPOBILLITM_CLAIM)),V_CLAIM_BO_INVOICE CBO INDEX
(FK_RPLCLMBUYOUTITM_CLAIM)))

SELECT
cpr.ID, cpr.ACCOUNTID, cpr.SRVPROVID, cpr.PRODUCTID, cpr.DECIMALQTY,
cpr.DATESBM,
COALESCE(SUM(coi.QTY_CLAIM),0), COALESCE(SUM(cii.QTY_CLAIM),0),
COALESCE(SUM(cbo.QTY_CLAIM),0)
FROM
PBM_CLAIM cpr
LEFT JOIN RPL_CLM_PO_ITM coi
ON coi.CLAIM_ID = cpr.ID
LEFT JOIN RPL_CLM_POBILL_ITM cii
ON cii.CLAIM_ID = cpr.ID
LEFT JOIN RPL_CLM_BUYOUT_ITM cbo
ON cbo.CLAIM_ID = cpr.ID
WHERE
DECIMALQTY = 123
GROUP BY
cpr.ID, cpr.PRODUCTID, cpr.ACCOUNTID, cpr.SRVPROVID, cpr.DECIMALQTY,
cpr.DATESBM

PLAN SORT (JOIN (JOIN (JOIN (CPR INDEX (I_PBMCLAIM_DECIMALQTY),COI INDEX
(FK_RPLCLMPOITM_CLAIM)),CII INDEX (FK_RPLCLMPOBILLITM_CLAIM)),CBO INDEX
(FK_RPLCLMBUYOUTITM_CLAIM)))