Gurus,
Someone in my office has written the SQL below:
select a12.distrbtn_chnl_id
,max(a14.distrbtn_chnl) distrbtn_chnl
,a13.prod_type_id
,max(a16.prod_type) prod_type
,a11.month_id
,max(a15.month_name) month_name
,max(a15.year_id) year_id
,count(distinct a11.agrmt_id) ofactivecont
from salesmi_dm_owner.agreement_makeup_summary a11
,salesmi_dm_owner.agent_appointments a12
,salesmi_dm_owner.products a13
,salesmi_dm_owner.distribution_channels a14
,salesmi_dm_owner.lookup_months a15
,salesmi_dm_owner.product_types a16
where a11.agent_apptmnt_id = a12.agent_apptmnt_id
and a11.prod_id = a13.prod_id
and a12.distrbtn_chnl_id = a14.distrbtn_chnl_id
and a11.month_id = a15.month_id
and a13.prod_type_id = a16.prod_type_id
and a11.month_id in (200207, 200307)
and a13.prod_type_id in (0, 2, 1)
and a13.prod_line_id = 1
and a11.agrmt_status_id in 1
group by a12.distrbtn_chnl_id
,a13.prod_type_id
,a11.month_id;
The SQL returns 10 rows. If you change the WHERE clause to eliminate the line "and a13.prod_type_id in (0, 2, 1)", the SQL returns 19 rows. The only "prod_type_id"s in the database for all the criteria are 1 and 2. The difference is that without this line in the WHERE clause, the "a11.month_id" portion of the WHERE clause works. In the SQL above all rows are summarized to the rolled into the "200307" month id.
The explain plans for the two SQL's are vastly different, but that is not unusual. The extra check in the WHERE clause forces a new execution plan. The execution plan for the SQL above is:
Q_PLAN
--------------------------------------------------------------------------------
SELECT STATEMENT
SORT GROUP BY
HASH JOIN
TABLE ACCESS FULL DISTRIBUTION_CHANNELS
HASH JOIN
TABLE ACCESS FULL PRODUCT_TYPES
HASH JOIN
HASH JOIN
TABLE ACCESS FULL LOOKUP_MONTHS
NESTED LOOPS
TABLE ACCESS FULL PRODUCTS
PARTITION RANGE INLIST
TABLE ACCESS BY LOCAL INDEX ROWID AGREEMENT_MAKEUP_SUMMARY
BITMAP CONVERSION TO ROWIDS
BITMAP AND
BITMAP OR
BITMAP INDEX SINGLE VALUE I_AGRMKSM_MTH_ID
BITMAP INDEX SINGLE VALUE I_AGRMKSM_MTH_ID
BITMAP INDEX SINGLE VALUE I_AGRMKSM_PROD_ID
BITMAP INDEX SINGLE VALUE I_AGRMKSM_AS_ID
TABLE ACCESS FULL AGENT_APPOINTMENTS
The execution plan without the line in the WHERE plan is:
SELECT STATEMENT
SORT GROUP BY
HASH JOIN
TABLE ACCESS FULL DISTRIBUTION_CHANNELS
HASH JOIN
TABLE ACCESS FULL PRODUCT_TYPES
HASH JOIN
HASH JOIN
TABLE ACCESS FULL LOOKUP_MONTHS
HASH JOIN
TABLE ACCESS FULL PRODUCTS
PARTITION RANGE INLIST
TABLE ACCESS FULL AGREEMENT_MAKEUP_SUMMARY
TABLE ACCESS FULL AGENT_APPOINTMENTS
Any ideas why the "GROUP BY" for month_id works when this line ("and a13.prod_type_id in (0, 2, 1)"
is taken out of the WHERE clause?
If you need any other information, please let me know. This has me baffled. The use of this line should not change the results.
Thanks,
gsdcrazy
Someone in my office has written the SQL below:
select a12.distrbtn_chnl_id
,max(a14.distrbtn_chnl) distrbtn_chnl
,a13.prod_type_id
,max(a16.prod_type) prod_type
,a11.month_id
,max(a15.month_name) month_name
,max(a15.year_id) year_id
,count(distinct a11.agrmt_id) ofactivecont
from salesmi_dm_owner.agreement_makeup_summary a11
,salesmi_dm_owner.agent_appointments a12
,salesmi_dm_owner.products a13
,salesmi_dm_owner.distribution_channels a14
,salesmi_dm_owner.lookup_months a15
,salesmi_dm_owner.product_types a16
where a11.agent_apptmnt_id = a12.agent_apptmnt_id
and a11.prod_id = a13.prod_id
and a12.distrbtn_chnl_id = a14.distrbtn_chnl_id
and a11.month_id = a15.month_id
and a13.prod_type_id = a16.prod_type_id
and a11.month_id in (200207, 200307)
and a13.prod_type_id in (0, 2, 1)
and a13.prod_line_id = 1
and a11.agrmt_status_id in 1
group by a12.distrbtn_chnl_id
,a13.prod_type_id
,a11.month_id;
The SQL returns 10 rows. If you change the WHERE clause to eliminate the line "and a13.prod_type_id in (0, 2, 1)", the SQL returns 19 rows. The only "prod_type_id"s in the database for all the criteria are 1 and 2. The difference is that without this line in the WHERE clause, the "a11.month_id" portion of the WHERE clause works. In the SQL above all rows are summarized to the rolled into the "200307" month id.
The explain plans for the two SQL's are vastly different, but that is not unusual. The extra check in the WHERE clause forces a new execution plan. The execution plan for the SQL above is:
Q_PLAN
--------------------------------------------------------------------------------
SELECT STATEMENT
SORT GROUP BY
HASH JOIN
TABLE ACCESS FULL DISTRIBUTION_CHANNELS
HASH JOIN
TABLE ACCESS FULL PRODUCT_TYPES
HASH JOIN
HASH JOIN
TABLE ACCESS FULL LOOKUP_MONTHS
NESTED LOOPS
TABLE ACCESS FULL PRODUCTS
PARTITION RANGE INLIST
TABLE ACCESS BY LOCAL INDEX ROWID AGREEMENT_MAKEUP_SUMMARY
BITMAP CONVERSION TO ROWIDS
BITMAP AND
BITMAP OR
BITMAP INDEX SINGLE VALUE I_AGRMKSM_MTH_ID
BITMAP INDEX SINGLE VALUE I_AGRMKSM_MTH_ID
BITMAP INDEX SINGLE VALUE I_AGRMKSM_PROD_ID
BITMAP INDEX SINGLE VALUE I_AGRMKSM_AS_ID
TABLE ACCESS FULL AGENT_APPOINTMENTS
The execution plan without the line in the WHERE plan is:
SELECT STATEMENT
SORT GROUP BY
HASH JOIN
TABLE ACCESS FULL DISTRIBUTION_CHANNELS
HASH JOIN
TABLE ACCESS FULL PRODUCT_TYPES
HASH JOIN
HASH JOIN
TABLE ACCESS FULL LOOKUP_MONTHS
HASH JOIN
TABLE ACCESS FULL PRODUCTS
PARTITION RANGE INLIST
TABLE ACCESS FULL AGREEMENT_MAKEUP_SUMMARY
TABLE ACCESS FULL AGENT_APPOINTMENTS
Any ideas why the "GROUP BY" for month_id works when this line ("and a13.prod_type_id in (0, 2, 1)"
If you need any other information, please let me know. This has me baffled. The use of this line should not change the results.
Thanks,
gsdcrazy