Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: Select Statement Gone South??
Laura,
Unfortunately it's hard to provide advice without knowing a lot more about the tables, the cardinality of the columns in the where clause, and perhaps even whether there are tricks we might be able to abuse by knowing information about the data that's not immediately obvious.
Ignoring that, an explain plan (as requested by Connor) will certainly help. Other things that would help are row counts of each table, and for the columns in the where clause what is there selectivity like.
One way to determine selectivity would be something like:
select count(*) total_rows,
sum(decode(pre_approved_purch_flag, 'N', 1, 0)) pre_app_is_n, sum(decode(company_reimburse_flag, 'Y', 1, 0)) com_reim_is_y, sum(decode(pre_approved_purch_flag||company_reimburse_flag, 'NY', 1,0)) both_cond_met
This will give an idea of how many rows meet each criteria, and how many meet both criteria. This may then give some hint as to whether an index access path is worthwhile or whether a full table scan is quicker. Is there a magic figure to determine which is faster? No. But the extremes (like 1% and 90%) will be obvious.
With regard to your specific query, I would ensure that the subselect performs very fast since it is probably being called in some kind of nested loop. Since some of the columns in the subselect aren't prefixed with a table alias I can't even work out which table they necessarily come from.
Regards,
Mark.
"Burton, Laura L." To: Multiple recipients of list ORACLE-L <ORACLE-L_at_fatcity.com> <BurtonL_at_prism cc: plus.com> Subject: Select Statement Gone South?? Sent by: root_at_fatcity.c om 26/02/2003 12:23 Please respond to ORACLE-L
I am inserting records into a table based on a select statement and it is taking way too much time. I have created indexes of the foreign keys and tried to rearrange the where clause to omit records earlier, but to no avail. The statement looks like this:
Insert into table test
select part_num,
nomenclature,
to_char(requisition_date,'yddd') ||lpad(preq.document_serial,4,0),
2, /* '53-Purchase' */
PSA.TRANS_date,
requisition_qty,
unit_price,
4 /* 'ALMD Disapproval' */
from part_master_catalogs pmc,
part_requisitions preq,
part_price_histories pph,
part_status_assocs psa
where preq.pmc_id_fk = pmc.pmc_id
and preq.preq_id = psa.preq_id_fk
and psa.req_status_cd_fk = 'D'
AND PSA.TRANS_DATE <= TO_DATE('&&NEWMEDATE','MM-DD-YYYY')
AND PSA.TRANS_DATE > TO_DATE('&&LASTMEDATE','MM-DD-YYYY') and pmc.pre_approved_purch_flag = 'N'
and pmc.company_reimburse_flag = 'Y'
and pph.pph_id = (select max(pph_id) from part_price_histories
where preq.pmc_id_fk = pmc_id_fk and requisition_date >= effective_date)
Any ideas?? Any insight would be appreciated.
Thanks,
Laura
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Privileged/Confidential information may be contained in this message.
If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should destroy this message and kindly notify the sender by reply e-mail or by telephone on (61 3) 9612-6999. Please advise immediately if you or your employer does not consent to Internet e-mail for messages of this kind. Opinions, conclusions and other information in this message that do not relate to the official business of Transurban City Link Ltd shall be understood as neither given nor endorsed by it. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Mark Richard INET: mrichard_at_transurban.com.au Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).Received on Tue Feb 25 2003 - 20:48:53 CST