This SQL is grabbing tons of I/O with up to 31 sessions running it
I would like to know what module or component or user is in need of running this SQL. I checked for it on Google, and I found multiple hits, which tells me it is a part of standard Oracle, but recently it started showing up several times a day grabbing tons of I/O as the top SQL in GRID CONTROL, and I see up to 31 sessions running running it.
If this is a part of standard Oracle E-business Suite, then is there a way to purge data or created indexes to make it more efficient? Also if I find out what cmoponent is using it, maybe I can schedule its use to more suitable times.
Thanks
Here is the SQL:
SELECT R.Conc_Login_Id, R.Request_Id, R.Phase_Code, R.Status_Code, P.Application_ID, P.Concurrent_Program_ID, P.Concurrent_Program_Name, R.Enable_Trace, R.Restart, DECODE(R.Increment_Dates, 'Y', 'Y', 'N'), R.NLS_Compliant, R.OUTPUT_FILE_TYPE, E.Executable_Name, E.Execution_File_Name, A2.Basepath, DECODE(R.Stale, 'Y', 'C', P.Execution_Method_Code), P.Print_Flag, P.Execution_Options, DECODE(P.Srs_Flag, 'Y', 'Y', 'Q', 'Y', 'N'), P.Argument_Method_Code, R.Print_Style, R.Argument_Input_Method_Code, R.Queue_Method_Code, R.Responsibility_ID, R.Responsibility_Application_ID, R.Requested_By, R.Number_Of_Copies, R.Save_Output_Flag, R.Printer, R.Print_Group, R.Priority, U.User_Name, O.Oracle_Username, O.Encrypted_Oracle_Password, R.Cd_Id, A.Basepath, A.Application_Short_Name, TO_CHAR(R.Requested_Start_Date,'YYYY/MM/DD HH24:MI:SS'), R.Nls_Language, R.Nls_Territory, R.Nls_Numeric_Characters, DECODE(R.Parent_Request_ID, NULL, 0, R.Parent_Request_ID), R.Priority_Request_ID, R.Single_Thread_Flag, R.Has_Sub_Request, R.Is_Sub_Request, R.Req_Information, R.Description, R.Resubmit_Time, TO_CHAR(R.Resubmit_Interval), R.Resubmit_Interval_Type_Code, R.Resubmit_Interval_Unit_Code, TO_CHAR(R.Resubmit_End_Date,'YYYY/MM/DD HH24:MI:SS'), Decode(E.Execution_File_Name, NULL, 'N', Decode(E.Subroutine_Name, NULL, Decode(E.Execution_Method_Code, 'I', 'Y', 'J', 'Y', 'N'), 'Y')), R.Argument1, R.Argument2, R.Argument3, R.Argument4, R.Argument5, R.Argument6, R.Argument7, R.Argument8, R.Argument9, R.Argument10, R.Argument11, R.Argument12, R.Argument13, R.Argument14, R.Argument15, R.Argument16, R.Argument17, R.Argument18, R.Argument19, R.Argument20, R.Argument21, R.Argument22, R.Argument23, R.Argument24, R.Argument25, X.Argument26, X.Argument27, X.Argument28, X.Argument29, X.Argument30, X.Argument31, X.Argument32, X.Argument33, X.Argument34, X.Argument35, X.Argument36, X.Argument37, X.Argument38, X.Argument39, X.Argument40, X.Argument41, X.Argument42, X.Argument43, X.Argument44, X.Argument45, X.Argument46, X.Argument47, X.Argument48, X.Argument49, X.Argument50, X.Argument51, X.Argument52, X.Argument53, X.Argument54, X.Argument55, X.Argument56, X.Argument57, X.Argument58, X.Argument59, X.Argument60, X.Argument61, X.Argument62, X.Argument63, X.Argument64, X.Argument65, X.Argument66, X.Argument67, X.Argument68, X.Argument69, X.Argument70, X.Argument71, X.Argument72, X.Argument73, X.Argument74, X.Argument75, X.Argument76, X.Argument77, X.Argument78, X.Argument79, X.Argument80, X.Argument81, X.Argument82, X.Argument83, X.Argument84, X.Argument85, X.Argument86, X.Argument87, X.Argument88, X.Argument89, X.Argument90, X.Argument91, X.Argument92, X.Argument93, X.Argument94, X.Argument95, X.Argument96, X.Argument97, X.Argument98, X.Argument99, X.Argument100, R.number_of_arguments, C.CD_Name, NVL(R.Security_Group_ID, 0), NVL(R.org_id, 0)
FROM fnd_concurrent_requests R, fnd_concurrent_programs P, fnd_application A, fnd_user U, fnd_oracle_userid O, fnd_conflicts_domain C, fnd_concurrent_queues Q, fnd_application A2, fnd_executables E, fnd_conc_request_arguments X
WHERE R.Status_code = 'I' And ((R.OPS_INSTANCE is null) or (R.OPS_INSTANCE = -1) or (R.OPS_INSTANCE = decode(:dcp_on,1,FND_CONC_GLOBAL.OPS_INST_NUM,R.OPS_INSTANCE))) And R.Request_ID = X.Request_ID(+) And R.Program_Application_Id = P.Application_Id(+) And R.Concurrent_Program_Id = P.Concurrent_Program_Id(+) And R.Program_Application_Id = A.Application_Id(+) And P.Executable_Application_Id = E.Application_Id(+) And P.Executable_Id = E.Executable_Id(+) And P.Executable_Application_Id = A2.Application_Id(+) And R.Requested_By = U.User_Id(+) And R.Cd_Id = C.Cd_Id(+) And R.Oracle_Id = O.Oracle_Id(+) And Q.Application_Id = :q_applid And Q.Concurrent_Queue_Id = :queue_id And (P.Enabled_Flag is NULL OR P.Enabled_Flag = 'Y') And R.Hold_Flag = 'N' And R.Requested_Start_Date <= Sysdate And ( R.Enforce_Seriality_Flag = 'N' OR ( C.RunAlone_Flag = P.Run_Alone_Flag And (P.Run_Alone_Flag = 'N' OR Not Exists
(Select Null
From Fnd_Concurrent_Requests Sr
Where Sr.Status_Code In ('R', 'T') And Sr.Enforce_Seriality_Flag = 'Y' And Sr.CD_id = C.CD_Id)))) And Q.Running_Processes <= Q.Max_Processes And R.Rowid = :reqname And ((P.Execution_Method_Code != 'S' OR (R.PROGRAM_APPLICATION_ID,R.CONCURRENT_PROGRAM_ID) IN ((0,98),(0,100),(0,31721),(0,31722),(0,31757))) AND ((R.PROGRAM_APPLICATION_ID,R.CONCURRENT_PROGRAM_ID) NOT IN ((0,32263),(0,36888),(0,38121),(201,32766),(201,59331),(222,20428),(222,32752),(401,32320),(510,40112),(510,40113),(510,41497),(510,41498),(530,41859),(530,41860),(535,41492),(535,41493),(535,41494),(660,39744),(660,40879),(660,59332),(661,41634),(661,59333),(665,42645),(665,45133),(665,48615),(702,33733),(724,39467),(724,39470),(724,42387),(20004,58331),(20004,58332),(20004,58333),(20004,58334),(20004,58335),(20004,65334),(20004,66345),(20004,69335),(20004,72335),(20004,72336),(20004,72337),(20004,72338),(20004,72339),(20004,74334)))) FOR UPDATE OF R.status_code NoWait
What I don't understand is why are we seeing this query now grabbing a lot more CPU and I/O when we've had jobs running in concurrent manager for months. Why now, and why this query? Is there something we turned on by mistake?What changes have been done recently? We do not know if something was turned on by mistake and you have to verify that by checking the debug/trace options at the Site/Responsibility/Application/User levels.
It does not look like a query that is going after production data, it is housekeeping data from FND tables.Not sure what you mean but if you mean to say that it is a seeded query (not a custom one) then make sure you have the statistics collected up to date and you purge concurrent requests/managers tables on regular basis.
I actually want to find out what module is using it, and turn off that module.Please log a SR for this.
We did not see this query running today all day, or if it ran, then I missed it.Try to find out what concurrent requests did not run today comparing with the other days.
Thanks,
Hussein
Similar Messages
-
How to tune this SQL (takes long time to come up with results)
Dear all,
I have sum SQL which takes long time ... can any one help me to tune this.... thank You
SELECT SUM (n_amount)
FROM (SELECT DECODE (v_payment_type,
'D', n_amount,
'C', -n_amount
) n_amount, v_vou_no
FROM vouch_det a, temp_global_temp b
WHERE a.v_vou_no = TO_CHAR (b.n_column2)
AND b.n_column1 = :b5
AND b.v_column1 IN (:b4, :b3)
AND v_desc IN (SELECT v_trans_source_code
FROM benefit_trans_source
WHERE v_income_tax_app = :b6)
AND v_lob_code = DECODE (:b1, :b2, v_lob_code, :b1)
UNION ALL
SELECT DECODE (v_payment_type,
'D', n_amount,
'C', -n_amount
* -1 AS n_amount,
v_vou_no
FROM vouch_details a, temp_global_temp b
WHERE a.v_vou_no = TO_CHAR (b.n_column2)
AND b.n_column1 = :b5
AND b.v_column1 IN (:b12, :b11, :b10, :b9, :b8, :b7)
AND v_desc IN (SELECT v_trans_source_code
FROM benefit_trans_source
WHERE income_tax_app = :b6)
AND v_lob_code = DECODE (:b1, :b2, v_lob_code, :b1));
Thank You.....Thanks a lot,
i did change the SQL it works fine but slows down my main query.... actually my main query is calling a function which does the sum......
here is the query.....?
select A.* from (SELECT a.n_agent_no, a.v_agent_code, a.n_channel_no, v_iden_no, a.n_cust_ref_no, a.v_agent_type, a.v_company_code,
a.v_company_branch, a.v_it_no, bfn_get_agent_name(a.n_agent_no) agentname,
PKG_AGE__TAX.GET_TAX_AMT(:P_FROM_DATE,:P_TO_DATE,:P_LOB_CODE,A.N_AGENT_NO) comm,
c.v_ird_region
FROM agent_master a, agent_lob b, agency_region c
WHERE a.n_agent_no = b.n_agent_no
AND a.v_agency_region = c.v_agency_region
AND :p_lob_code = DECODE(:p_lob_code,'ALL', 'ALL',b.v_line_of_business)
AND :p_channel_no = DECODE(:p_channel_no,1000, 1000,a.n_channel_no)
AND :p_agency_group = DECODE(:p_agency_group,'ALL', 'ALL',c.v_ird_region)
group by a.n_agent_no, a.v_agent_code, a.n_channel_no, v_iden_no, a.n_cust_ref_no, a.v_agent_type, a.v_company_code, a.v_company_branch, a.v_it_no, bfn_get_agent_name(a.n_agent_no) ,
BPG_AGENCY_GEN_ACL_TAX.BFN_GET_TAX_AMOUNT(:P_FROM_DATE,:P_TO_DATE,:P_LOB_CODE,A.N_AGENT_NO),
c.v_ird_region
ORDER BY c.v_ird_region, a.v_agent_code DESC)
A
WHERE (COMM < :P_VAL_IND OR COMM >=:P_VAL_IND1);
Any idea to make this faster....
Thank You... -
Hi
Please can you help me to create this SQL statement ?
I have two tables: table1 consist of data (AAA,BBB), table2 consist of data(AAA)
And there is relation between table1 and table2 for example (Invoice_id) .
My question is ( How can create SQL statement to display only data in table1(BBB) but not available In table2 ?
Thanks and best regards .
KhaledTry this:
SQL> ed
Wrote file afiedt.buf
1 with t as (select 'AAA' col1,1 inv_id from dual
2 UNION select 'BBB',1 from dual)
3 , s as (select 'AAA' col1,1 inv_id from dual)
4 SELECT col1,inv_id FROM t
5* WHERE NOT EXISTS (SELECT 1 FROM s WHERE inv_id = t.inv_id AND col1 = t.col1)
SQL> /
COL INV_ID
BBB 1
SQL> -
Where can I download this SQL-Net Client software 8.1.6.3.8
What is the most current version of the SQL-Net Client software drivers that we should be using on our Windows Clients to hit our 8.1.6.3 server? Currently we are using 8.1.6.0.0 (per tnsping). According to the certification matrix, looks like 8.1.6.3.8, (right?)
Destination : Windows 98,NT,2000,XP Clients
Second, where can I download this SQL-Net Client software? And please don't tell me I have to download the entire server (I hoping, but if I do where?).
Thanks,
Jason
[email protected]I think you might be running into the issue that:
1) The Yoga 2 Pro does not have a DVD player built-in, and therefore they don't include DVD playback software
2) Windows 8 (or 8.1) no longer includes the codecs to play DVDs and such. You have to upgrade to the Professional edition of it. (silly, yes).
I would personally just grab VLC Player from videolan.org, and use that. Works perfectly fine, and it's free.
(Did the external USB DVD not come w/ software? That's actually strange). -
What's wrong with this SQL?
what's wrong with this SQL?
Posted: Jan 16, 2007 9:35 AM Reply
Hi, everyone:
when I insert into table, i use the fellowing SQL:
INSERT INTO xhealthcall_script_data
(XHC_CALL_ENDED, XHC_SWITCH_PORT, XHC_SCRIPT_ID, XHC_FAX_SPECIFIED)
VALUES (SELECT TO_DATE(HH_END_DATE||' '||HH_END_TIME,'MM/DD/YY HH24:MI:SS'), HH_SWITCHPORT, HH_SCRIPT,'N'
FROM tmp_healthhit_load WHERE HH_SCRIPT !='BROCHURE' UNION
SELECT TO_DATE(HH_END_DATE||' '||HH_END_TIME,'MM/DD/YY HH24:MI:SS'), HH_SWITCHPORT, HH_SCRIPT,'N' FROM tmp_healthhit_load WHERE HH_SCRIPT !='BROCHURE');
I always got an error like;
VALUES (SELECT TO_DATE(HH_END_DATE||' '||HH_END_TIME,'MM/DD/YY HH24:MI:SS'), HH_SWITCHPORT,
ERROR at line 3:
ORA-00936: missing expression
but I can't find anything wrong, who can tell me why?
thank you so much in advance
mpowel01
Posts: 1,516
Registered: 12/7/98
Re: what's wrong with this SQL?
Posted: Jan 16, 2007 9:38 AM in response to: jerrygreat Reply
For starters, an insert select does not have a values clause.
HTH -- Mark D Powell --
PP
Posts: 41
From: q
Registered: 8/10/06
Re: what's wrong with this SQL?
Posted: Jan 16, 2007 9:48 AM in response to: mpowel01 Reply
Even I see "missing VALUES" as the only error
Eric H
Posts: 2,822
Registered: 10/15/98
Re: what's wrong with this SQL?
Posted: Jan 16, 2007 9:54 AM in response to: jerrygreat Reply
...and why are you doing a UNION on the exact same two queries?
(SELECT TO_DATE(HH_END_DATE||' '||HH_END_TIME,'MM/DD/YY HH24:MI:SS') ,HH_SWITCHPORT ,HH_SCRIPT ,'N' FROM tmp_healthhit_load WHERE HH_SCRIPT !='BROCHURE' UNION SELECT TO_DATE(HH_END_DATE||' '||HH_END_TIME,'MM/DD/YY HH24:MI:SS') ,HH_SWITCHPORT ,HH_SCRIPT ,'N' FROM tmp_healthhit_load WHERE HH_SCRIPT !='BROCHURE');
jerrygreat
Posts: 8
Registered: 1/3/07
Re: what's wrong with this SQL?
Posted: Jan 16, 2007 9:55 AM in response to: mpowel01 Reply
Hi,
thank you for your answer, but the problem is, if I deleted "values" as you pointed out, and then execute it again, I got error like "ERROR at line 3:
ORA-03113: end-of-file on communication channel", and I was then disconnected with server, I have to relogin SQLplus, and do everything from beganing.
so what 's wrong caused disconnection, I can't find any triggers related. it is so wired?
I wonder if anyone can help me about this.
thank you very much
jerry
yingkuan
Posts: 1,801
From: San Jose, CA
Registered: 10/8/98
Re: what's wrong with this SQL?
Posted: Jan 16, 2007 9:59 AM in response to: jerrygreat Reply
Dup Post
jerrygreat
Posts: 8
Registered: 1/3/07
Re: what's wrong with this SQL?
Posted: Jan 16, 2007 10:00 AM in response to: Eric H Reply
Hi,
acturlly what I do is debugging a previous developer's scipt for data loading, this script was called by Cron work, but it never can be successfully executed.
I think he use union for eliminating duplications of rows, I just guess.
thank you
jerry
mpowel01
Posts: 1,516
Registered: 12/7/98
Re: what's wrong with this SQL?
Posted: Jan 16, 2007 10:03 AM in response to: yingkuan Reply
Scratch the VALUES keyword then make sure that the select list matches the column list in number and type.
1 insert into marktest
2 (fld1, fld2, fld3, fld4, fld5)
3* select * from marktest
UT1 > /
16 rows created.
HTH -- Mark D Powell --
Jagan
Posts: 41
From: Hyderabad
Registered: 7/21/06
Re: what's wrong with this SQL?
Posted: Jan 16, 2007 10:07 AM in response to: jerrygreat Reply
try this - just paste the code and give me the error- i mean past the entire error as it is if error occurs
INSERT INTO xhealthcall_script_data
(xhc_call_ended, xhc_switch_port, xhc_script_id,
xhc_fax_specified)
SELECT TO_DATE (hh_end_date || ' ' || hh_end_time, 'MM/DD/YY HH24:MI:SS'),
hh_switchport, hh_script, 'N'
FROM tmp_healthhit_load
WHERE hh_script != 'BROCHURE'
UNION
SELECT TO_DATE (hh_end_date || ' ' || hh_end_time, 'MM/DD/YY HH24:MI:SS'),
hh_switchport, hh_script, 'N'
FROM tmp_healthhit_load
WHERE hh_script != 'BROCHURE';
Regards
Jagan
jerrygreat
Posts: 8
Registered: 1/3/07
Re: what's wrong with this SQL?
Posted: Jan 16, 2007 11:31 AM in response to: Jagan Reply
Hi, Jagan:
thank you very much for your answer.
but when I execute it, I still can get error like:
ERROR at line 1:
ORA-03113: end-of-file on communication channel
so wired, do you have any ideas?
thank you very muchAnd this one,
Aother question about SQL?
I thought I already told him to deal with
ORA-03113: end-of-file on communication channel
problem first.
There's nothing wrong (syntax wise) with the query. (of course when no "value" in the insert) -
How to execute this SQL Query in ABAP Program.
Hi,
I have a string which is the SQL Query.
How to execute this sql Query (SQL_STR) in ABAP Program.
Code:-
DATA: SQL_STR type string.
SQL_STR = 'select * from spfli.'.
Thanks in Advance,
VinayHi Vinay
Here is a sample to dynamically generate a subroutine-pool having your SQL and calling it.
REPORT dynamic_sql_example .
DATA: BEGIN OF gt_itab OCCURS 1 ,
line(80) TYPE c ,
END OF gt_itab .
DATA gt_restab TYPE .... .
DATA gv_name(30) TYPE c .
DATA gv_err(120) TYPE c .
START-OF-SELECTION .
gt_itab-line = 'REPORT generated_sql .' .
APPEND gt_itab .
gt_itab-line = 'FORM exec_sql CHANGING et_table . ' .
APPEND gt_itab .
gt_itab-line = SQL_STR .
APPEND gt_itab .
gt_itab-line = 'ENDFORM.' .
APPEND gt_itab .
GENERATE SUBROUTINE POOL gt_itab NAME gv_name MESSAGE gv_err .
PERFORM exec_sql IN PROGRAM (gv_name) CHANGING gt_restab
IF FOUND .
WRITE:/ gv_err .
LOOP AT gt_result .
WRITE:/ .... .
ENDLOOP .
*--Serdar -
How to reduce the fetch time of this sql?
Here is the SQL, three-table join and joining conditions are:
ms_ets_cntrl.ims_cntrt_oid=ims_alctn.ims_alctn_oid
ims_alctn.ims_trde_oid=ims_trde.ims_trde_oid
SELECT 'MCH' Type, ims_ets_cntrl.STTS tp_stts, count(*) Count FROM ims_ets_cntrl where ims_ets_cntrl.ims_cntrt_oid in
(select ims_alctn.ims_alctn_oid FROM ims_alctn, ( select ims_trde.ims_trde_oid from ims_trde
where ( IMS_TRDE.IMS_TRDE_RCPT_DTTM >= TO_DATE('10/29/2009 00:00', 'MM/DD/YYYY HH24:MI') AND IMS_TRDE.IMS_TRDE_RCPT_DTTM <= (TO_DATE('11/5/2009 23:59', 'MM/DD/YYYY HH24:MI')) )
AND (IMS_TRDE.GRS_TRX_TYPE IN ('INJECTION','WITHDRAWAL','PAYMENT') OR IMS_TRDE.SSC_INVST_TYPE = 'FC' AND 1=1 and IMS_TRDE.SERVICE_TYPE='FS' )) TRDE
where IMS_ALCTN.IMS_TRDE_OID=TRDE.IMS_TRDE_OID) and ims_ets_cntrl.outbnd_dest = 'ETD' group by ims_ets_cntrl.STTSOptimizer and related parameter info:
SQL> show parameter optimizer
NAME TYPE VALUE
optimizer_dynamic_sampling integer 1
optimizer_features_enable string 9.2.0
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_max_permutations integer 2000
optimizer_mode string CHOOSE
SQL>select pname, pval1, pval2 from sys.aux_stats$ where sname='SYSSTATS_INFO';
DSTART 11-16-2009 10:23
DSTOP 11-16-2009 10:23
FLAGS 1
STATUS NOWORKLOADHere is autotrace output:
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 SORT (GROUP BY)
2 1 VIEW
3 2 SORT (UNIQUE)
4 3 TABLE ACCESS (BY INDEX ROWID) OF 'IMS_ETS_CNTRL'
5 4 NESTED LOOPS
6 5 NESTED LOOPS
7 6 TABLE ACCESS (BY INDEX ROWID) OF 'IMS_TRDE'
8 7 INDEX (RANGE SCAN) OF 'IMS_TRDE_INDX4' (NON- UNIQUE)
9 6 TABLE ACCESS (BY INDEX ROWID) OF 'IMS_ALCTN'
10 9 INDEX (RANGE SCAN) OF 'IMS_ALCTN_INDX1' (NON -UNIQUE)
11 5 INDEX (RANGE SCAN) OF 'IMS_ETS_CNTRL_INDX1' (NON -UNIQUE)
Statistics
0 recursive calls
0 db block gets
244608 consistent gets
58856 physical reads
0 redo size
497 bytes sent via SQL*Net to client
499 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
1 rows processedHere is TKPROF output:
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 4.85 129.72 53863 244608 0 1
total 4 4.85 129.72 53863 244608 0 1
Misses in library cache during parse: 1
Optimizer goal: CHOOSE
Parsing user id: 63
Rows Row Source Operation
1 SORT GROUP BY
12972 VIEW
12972 SORT UNIQUE
12972 TABLE ACCESS BY INDEX ROWID IMS_ETS_CNTRL
46236 NESTED LOOPS
19134 NESTED LOOPS
19744 TABLE ACCESS BY INDEX ROWID IMS_TRDE
176922 INDEX RANGE SCAN IMS_TRDE_INDX4 (object id 34099)
19134 TABLE ACCESS BY INDEX ROWID IMS_ALCTN
19134 INDEX RANGE SCAN IMS_ALCTN_INDX1 (object id 34094)
27101 INDEX RANGE SCAN IMS_ETS_CNTRL_INDX1 (object id 34101)
********************************************************************************Explain plan output:
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | | | |
| 1 | SORT GROUP BY | | | | |
| 2 | VIEW | | | | |
| 3 | SORT UNIQUE | | | | |
|* 4 | TABLE ACCESS BY INDEX ROWID | IMS_ETS_CNTRL | | | |
| 5 | NESTED LOOPS | | | | |
| 6 | NESTED LOOPS | | | | |
|* 7 | TABLE ACCESS BY INDEX ROWID| IMS_TRDE | | | |
|* 8 | INDEX RANGE SCAN | IMS_TRDE_INDX4 | | | |
| 9 | TABLE ACCESS BY INDEX ROWID| IMS_ALCTN | | | |
|* 10 | INDEX RANGE SCAN | IMS_ALCTN_INDX1 | | | |
|* 11 | INDEX RANGE SCAN | IMS_ETS_CNTRL_INDX1 | | | |
Predicate Information (identified by operation id):
4 - filter("IMS_ETS_CNTRL"."OUTBND_DEST"='ETD')
7 - filter("IMS_TRDE"."GRS_TRX_TYPE"='INJECTION' OR "IMS_TRDE"."GRS_TRX_TYPE"='WITHD
RAWAL' OR "IMS_TRDE"."GRS_TRX_TYPE"='PAYMENT' OR "IMS_TRDE"."SSC_INVST_TY
PE"='FC' AND "IMS_TRDE"."SERVICE_TYPE"='FS')
8 - access("IMS_TRDE"."IMS_TRDE_RCPT_DTTM">=TO_DATE('2009-10-29 00:00:00', 'yyyy-mm-
dd hh24:mi:ss') AND "IMS_TRDE"."IMS_TRDE_RCPT_DTTM"<=TO_DATE('2009-11-05
23:59:00', 'yyyy-mm-dd hh24:mi:ss')
10 - access("IMS_ALCTN"."IMS_TRDE_OID"="IMS_TRDE"."IMS_TRDE_OID")
11 - access("IMS_ETS_CNTRL"."IMS_CNTRT_OID"="IMS_ALCTN"."IMS_ALCTN_OID")
Note: rule based optimizationCould you please help tune this sql?
How can I reduce the elapsed time? How can I reduce query read?
If there is any other info that you need, please let me know!
thank you very much!What exactly is this logic meant to do?
AND (ims_trde.grs_trx_type IN ('INJECTION', 'WITHDRAWAL', 'PAYMENT')
OR ims_trde.ssc_invst_type = 'FC'
AND ims_trde.service_type = 'FS')is that really:
AND (ims_trde.grs_trx_type IN ('INJECTION', 'WITHDRAWAL', 'PAYMENT')
OR ims_trde.ssc_invst_type = 'FC')
AND ims_trde.service_type = 'FS'or is it maybe:
AND (ims_trde.grs_trx_type IN ('INJECTION', 'WITHDRAWAL', 'PAYMENT')
OR (ims_trde.ssc_invst_type = 'FC'
AND ims_trde.service_type = 'FS'))? -
How do I get rid of this sql warning?
Hi folks,
I am running oracle 10.2.0 on Linux. I would like to get rid of this sql code warning
(Warning(151,3): PLW-07202: bind type would result in conversion away from column type)I get when I compile the code below. Basically Oracle does not like the idea of using a number in an expression with sysdate. eg (sampling_date < sysdate - p_n_value) where p_n_value is a number;
What is the best way to do this?
CREATE TABLE "USERDATA"."TBL_SESSION_SQL_WAIT_HISTORY"
( "SESSION_SQL_WAIT_HIST_SEQ_ID" NUMBER,
"DBID" NUMBER,
"SID" NUMBER,
"SEQ#" NUMBER,
"EVENT" VARCHAR2(64 BYTE),
"P1TEXT" VARCHAR2(64 BYTE),
"P1" NUMBER,
"P1RAW" RAW(8),
"P2TEXT" VARCHAR2(64 BYTE),
"P2" NUMBER,
"P2RAW" RAW(8),
"P3TEXT" VARCHAR2(64 BYTE),
"P3" NUMBER,
"P3RAW" RAW(8),
"WAIT_TIME" NUMBER,
"SECONDS_IN_WAIT" NUMBER,
"STATE" VARCHAR2(19 BYTE),
"SAMPLING_DATE" DATE,
"SAMPLING_TIME" VARCHAR2(8 BYTE),
"SERIAL#" NUMBER,
"USERNAME" VARCHAR2(30 BYTE),
"OSUSER" VARCHAR2(30 BYTE),
"PADDR" RAW(4),
"LOGON_TIME" DATE,
"PROCESS" VARCHAR2(24 BYTE),
"SQL_HASH_VALUE" NUMBER,
"SADDR" RAW(4),
"MODULE" VARCHAR2(48 BYTE),
"ROW_WAIT_OBJ#" NUMBER,
"ROW_WAIT_FILE#" NUMBER,
"ROW_WAIT_BLOCK#" NUMBER,
"ROW_WAIT_ROW#" NUMBER
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 16384 NEXT 65536 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERDATA" ;
CREATE TABLE "USERDATA"."TBL_SQLTEXT_WAIT_HISTORY"
( "SQLTEXT_SEQ_ID" NUMBER,
"DBID" NUMBER,
"ADDRESS" RAW(4),
"HASH_VALUE" NUMBER,
"SQL_ID" VARCHAR2(13 BYTE),
"COMMAND_TYPE" NUMBER,
"PIECE" NUMBER,
"SQL_TEXT_PIECE" VARCHAR2(64 BYTE),
"SQL_TEXT" VARCHAR2(1000 BYTE),
"DISK_READS" NUMBER,
"BUFFER_GETS" NUMBER,
"DIRECT_WRITES" NUMBER,
"PARSE_CALLS" NUMBER
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 16384 NEXT 65536 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERDATA" ;
create or replace
PROCEDURE data_coll AS
p_n_value userdata.tbl_options.n_value%type; -- number
BEGIN
-- irrelevant code here
select n_value into p_n_value from tbl_options where name ='PURGE_DAY_COUNT';
DELETE FROM tbl_sqltext_wait_history t where t.hash_value in
(select s.sql_hash_value from cc_session_sql_wait_history s
where s.sampling_date < sysdate - p_n_value
and s.sql_hash_value = t.hash_value);
DELETE FROM tbl_session_sql_wait_history
WHERE sampling_date < sysdate - p_n_value;
END;Thanks in advance for your feedback.
rgds, Efachim
Edited by: efachim on Jan 19, 2009 10:44 AMOne general suggestion.
"TBL_SESSION_SQL_WAIT_HISTORY"Did you create your table and column names within double quotes?
It will make your table as case sensitive.
Regards.
Satyaki De. -
How to reduce execution time of this SQL?
This SQL will output only 2 rows. I tried using hints (an index) but to no avail.
http://www.freeimagehosting.net/uploads/cf214afcf1.jpg
Or, is it NOT possible, limit of query optimization has reached?Rakesh jayappa wrote:
Hi,
Run the sql tuning advisory.
Let me know recommendation.
Kind Regards,
Rakesh************************** Here is my tuning request **************************
1.) The following SQL statement has been identified to perform poorly. It currently takes up to 12 seconds to execute, but it's supposed to take a second at most.
This is the statement:
select DISTINCT trunc(c.sst_post_date) as post_date
from ac_t_sessn b , ac_t_ssntr c
where
b.ses_status = 0
and b.ses_profit_center = c.sst_profit_center
and b.ses_acct_year = c.sst_acct_year
and b.ses_acct_period = c.sst_acct_period
and b.ses_sessn_no = c.sst_sessn_no
AND
C.sst_post_mtd||C.sst_post_TYPE IN
(SELECT Y.pst_post_mtd||Y.pst_post_type
FROM ac_r_post_functions Y
WHERE Y.pst_post_status IN (0,'2'))
order by trunc(c.sst_post_date);It should return data from a table in a specific order.
2.) The version of the database is Oracle9i Enterprise Edition Release *9.2.0.6.0*
3.) These are the parameters relevant to the optimizer:
UAT_UML@umltest>show parameter optimizer
NAME TYPE VALUE
optimizer_dynamic_sampling integer 1
optimizer_features_enable string 9.2.0
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_max_permutations integer 2000
optimizer_mode string CHOOSE
UAT_UML@umltest>show parameter db_file_multi
NAME TYPE VALUE
db_file_multiblock_read_count integer 16
UAT_UML@umltest>show parameter db_block_size
NAME TYPE VALUE
db_block_size integer 8192
UAT_UML@umltest>show parameter cursor_sharing
NAME TYPE VALUE
cursor_sharing string EXACT
UAT_UML@umltest>column sname format a20
UAT_UML@umltest>column pname format a20
UAT_UML@umltest>column pval2 format a20
UAT_UML@umltest>select
2 sname
3 , pname
4 , pval1
5 , pval2
6 from
7 sys.aux_stats$;
no rows selected4.) Here is the output of EXPLAIN PLAN:
UAT_UML@umltest>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost |
| 0 | SELECT STATEMENT | | 454 | 22700 | | 5391 |
| 1 | SORT UNIQUE | | 454 | 22700 | | 5072 |
| 2 | HASH JOIN | | 69384 | 3387K| 2592K| 4478 |
| 3 | INDEX FAST FULL SCAN| INDX_AC_T_SESSN | 110K| 1294K| | 244 |
| 4 | HASH JOIN | | 416K| 15M| | 3877 |
| 5 | TABLE ACCESS FULL | AC_R_POST_FUNCTIONS | 23 | 253 | | 2 |
| 6 | TABLE ACCESS FULL | AC_T_SSNTR | 1790K| 46M| | 3866 |
Note: cpu costing is off, PLAN_TABLE' is old version5.) Here is the output of SQL*Plus AUTOTRACE including the TIMING information:
UAT_UML@umltest>set autotrace traceonly arraysize 100
UAT_UML@umltest>
UAT_UML@umltest>select DISTINCT trunc(c.sst_post_date) as post_date
2 from ac_t_sessn b , ac_t_ssntr c
3 where
4 b.ses_status = 0
5 and b.ses_profit_center = c.sst_profit_center
6 and b.ses_acct_year = c.sst_acct_year
7 and b.ses_acct_period = c.sst_acct_period
8 and b.ses_sessn_no = c.sst_sessn_no
9 AND
10 C.sst_post_mtd||C.sst_post_TYPE IN (SELECT Y.pst_post_mtd||Y.pst_post_type FROM ac_r_po
st_functions Y
11 WHERE Y.pst_post_status IN (0,'2'))
12 order by trunc(c.sst_post_date);
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=5391 Card=454 Bytes=
22700)
1 0 SORT (UNIQUE) (Cost=5072 Card=454 Bytes=22700)
2 1 HASH JOIN (Cost=4478 Card=69384 Bytes=3469200)
3 2 INDEX (FAST FULL SCAN) OF 'INDX_AC_T_SESSN' (NON-UNIQU
E) (Cost=244 Card=110433 Bytes=1325196)
4 2 HASH JOIN (Cost=3877 Card=416304 Bytes=15819552)
5 4 TABLE ACCESS (FULL) OF 'AC_R_POST_FUNCTIONS' (Cost=2
Card=23 Bytes=253)
6 4 TABLE ACCESS (FULL) OF 'AC_T_SSNTR' (Cost=3866 Card=
1790555 Bytes=48344985)
Statistics
0 recursive calls
0 db block gets
42741 consistent gets
171 physical reads
0 redo size
425 bytes sent via SQL*Net to client
507 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
2 rows processed
UAT_UML@umltest>DISCONNECT
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.6.0 - Production6.) The TKPROF output snippet
TKPROF: Release 11.2.0.1.0 - Development on Wed Oct 27 12:47:35 2010
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Trace file: umltest_ora_1604.trc
Sort options: prsela exeela fchela
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
select DISTINCT trunc(c.sst_post_date) as post_date
from ac_t_sessn b , ac_t_ssntr c
where
b.ses_status = 0
and b.ses_profit_center = c.sst_profit_center
and b.ses_acct_year = c.sst_acct_year
and b.ses_acct_period = c.sst_acct_period
and b.ses_sessn_no = c.sst_sessn_no
AND
C.sst_post_mtd||C.sst_post_TYPE IN (SELECT Y.pst_post_mtd||Y.pst_post_type FROM ac_r_post_functions Y
WHERE Y.pst_post_status IN (0,'2'))
order by trunc(c.sst_post_date)
call count cpu elapsed disk query current rows
Parse 1 0.01 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 3.20 4.38 171 42741 0 2
total 4 3.21 4.39 171 42741 0 2
Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 445
Rows Row Source Operation
2 SORT UNIQUE
24 HASH JOIN
11 INDEX FAST FULL SCAN OBJ#(62817) (object id 62817)
2293715 HASH JOIN
31 TABLE ACCESS FULL OBJ#(67305)
1790555 TABLE ACCESS FULL OBJ#(62828)
alter session set sql_trace true
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
total 1 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
Misses in library cache during execute: 1
Optimizer mode: CHOOSE
Parsing user id: 445
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 1 0.01 0.00 0 0 0 0
Execute 2 0.00 0.00 0 0 0 0
Fetch 2 3.20 4.38 171 42741 0 2
total 5 3.21 4.39 171 42741 0 2
Misses in library cache during parse: 1
Misses in library cache during execute: 1
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 0 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
total 0 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
2 user SQL statements in session.
0 internal SQL statements in session.
2 SQL statements in session.
Trace file: umltest_ora_1604.trc
Trace file compatibility: 9.02.00
Sort options: prsela exeela fchela
1 session in tracefile.
2 user SQL statements in trace file.
0 internal SQL statements in trace file.
2 SQL statements in trace file.
2 unique SQL statements in trace file.
51 lines in trace file.
10 elapsed seconds in trace file. Any help would be greatly appreciated? -
Whats wrong with this sql statement ??
Hello all, I am trying to run the below query out of persheet(tanel poder) performance excel chart...but i get below error...db is on 9.2
what is wrong with this sql statement ?
http://blog.tanelpoder.com/2008/12/28/performance-visualization-made-easy-perfsheet-20-beta/
select * from (
with fsq as (
select /*+ materialize */
i.dbid
, i.instance_name
, i.instance_number
-- , trunc(s.snap_time, 'DD') DAY
-- , to_number(to_char(s.snap_time, 'HH24')) HOUR
-- -- , to_char(s.snap_time, 'MI') MINUTE
-- , 0 MINUTE
, trunc(
lag(s.snap_time, 1)
over(
partition by
v.dbid
, i.instance_name
, v.instance_number
, v.event
order by
s.snap_time
, 'HH24'
) SNAP_TIME
, v.event_type EVENT_TYPE
, v.event EVENT_NAME
, nvl(
decode(
greatest(
time_waited_micro,
nvl(
lag(time_waited_micro,1,0)
over(
partition by
v.dbid
, i.instance_name
, v.instance_number
, v.event
order by v.snap_id
, time_waited_micro
time_waited_micro,
time_waited_micro - lag(time_waited_micro,1,0)
over (
partition by
v.dbid
, i.instance_name
, v.instance_number
, v.event
order by v.snap_id
time_waited_micro
, time_waited_micro
) / 1000000 SECONDS_SPENT
, total_waits WAIT_COUNT
from
(select distinct dbid, instance_name, instance_number from stats$database_instance) i
, stats$snapshot s
, ( select
snap_id, dbid, instance_number, 'WAIT' event_type, event, time_waited_micro, total_waits
from
stats$system_event
where
event not in (select event from stats$idle_event)
union all
select
snap_id, dbid, instance_number,
case
when name in ('CPU used by this session', 'parse time cpu', 'recursive cpu usage') then 'CPU'
when name like 'OS % time' then 'OS'
else 'STAT'
end,
name , value, 1
from
stats$sysstat
-- where name in ('CPU used by this session', 'parse time cpu', 'recursive cpu usage')
-- or name like('OS % time')
-- or 1 = 2 -- this will be a bind variable controlling whether all stats need to be returned
) v
where
i.dbid = s.dbid
and i.dbid = v.dbid
and s.dbid = v.dbid
and s.snap_id = v.snap_id
and s.snap_time between '%FROM_DATE%' and '%TO_DATE%'
and i.instance_name = '%INSTANCE%'
select * from (
select
instance_name
, instance_number
, snap_time
, trunc(snap_time, 'DD') DAY
, to_char(snap_time, 'HH24') HOUR
, to_char(snap_time, 'MI') MINUTE
, event_type
, event_name
, seconds_spent
, wait_count
, ratio_to_report(seconds_spent) over (
-- partition by (to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09'))
partition by (snap_time)
) ratio
from fsq
where
snap_time is not null -- lag(s.snap_time, 1) function above will leave time NULL for first snapshot
-- to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09')
-- > ( select min(to_char(day, 'YYYYMMDD')||to_char(hour,'09')||to_char(minute, '09')) from fsq)
where ratio > 0
order by
instance_name
, instance_number
, day
, hour
, minute
, event_type
, seconds_spent desc
, wait_count desc
Error at line 6
ORA-00604: error occurred at recursive SQL level 1
ORA-00972: identifier is too longHi Alex,
Subquery factoring a.k.a. the with-clause should be possible on 9.2:
http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_103a.htm#2075888
(used it myself as well on 9.2)
@OP
I recall having problems myself using PL/SQL Developer and trying to get the with clause to work on 9.2 some years ago.
A workaround might be to create a view based on the query.
Also, your error message is "ORA-00972: identifier is too long"...
http://download.oracle.com/docs/cd/B19306_01/server.102/b14219/e900.htm#sthref419
Can't test things currently, no 9.2 available at the moment, but perhaps tomorrow I'll have a chance. -
Whats wrong in this SQL - Help Required..
Hi,
Can you please tell me what is wrong in this SQL Query.
select
case
when
(SELECT territory_code
FROM
fnd_territories
where territory_code like 'BR') then
(SELECT description
FROM fnd_descr_flex_contexts_tl
WHERE descriptive_flexfield_name='JG_PO_VENDOR_SITES'
AND descriptive_flex_context_code='JL.BR.APXVDMVD.SITES')
else
NULL
end result
FROM dual;
Thanks,Based on the info supplied, here's a few possibilities,
you've typed the table name incorrectly
You've not restricted the results correctly,
you're using a version of oracle that doesn't support the CASE expression
You're using SQL server, which doesn't have the dual table.
you've / someone has manipulated teh dual table so that it now has 4billion and one rows
The subquery in your case statement returns more than one row.
1. It's poorly/not formatted.
2. It's not in code tags
3. You haven't given us anywhere near enough info e.g. Error messages, what you're actually trying to do etc, etc -
Translate this SQL to an oracle Complaint SQL.
Hi,
The SQL below runs fine with hsqldb but fails to run on ORACLE. There is a problem with the way the column alias is used in this; it is not supported by oracle(thanks to Justin Cave in the forum).
Any help in translating this query to run with oracle would be greatly appreciated as I am an Oracle newbie.
The error message I get is Error: ORA-00979: not a GROUP BY expression
The Query is
SELECT ct.test_doc_id , ct.test_date, ct.test_time, doc.doc_name,
doc.doc_type, doc.doc_url, ut.user_id, ut.first_name, ut.last_name,
tr.result_status, pt.policy_id, pt.policy_name, prjt.project_name,
COUNT(*) num ,
SUM(tr.result_number_of_findings) findings,
(SELECT COUNT(*)
FROM test_results_tbl d
WHERE ct.test_id = d.result_test_id AND
d.result_status = '1') passed ,
(SELECT COUNT(*)
FROM test_results_tbl d
WHERE ct.test_id = d.result_test_id AND
d.result_status = '-1') not_passed,
(SELECT COUNT(*)
FROM test_results_tbl d
WHERE ct.test_id = d.result_test_id AND
d.result_status = '0') undetermined
FROM conformance_tests_tbl ct, users_tbl ut, documents_tbl doc,
test_results_tbl tr, policies_tbl pt, association_tbl ab, project_tbl prjt
WHERE (ct.test_doc_id= doc.doc_id)
AND (ct.test_initiated_by = ut.user_id)
AND (ct.test_id = tr.result_test_id)
AND (ct.test_policy_id = pt.policy_id)
AND (ct.test_doc_id = ab.object_instance_id)
AND (ab.object_type_id = '3')
AND (ab.subject_type_id = '2')
AND (ab.subject_instance_id = prjt.project_id)
AND ((SELECT COUNT(*)
FROM test_results_tbl d
WHERE ct.test_id = d.result_test_id AND
d.result_status = '-1') > 0 )
GROUP BY ct.test_doc_id , ct.test_date, ct.test_time, doc.doc_name,
doc.doc_type, doc.doc_url, ut.user_id, ut.first_name,
ut.last_name, tr.result_status, pt.policy_id, pt.policy_name,
prjt.project_name
HAVING SUM(tr.result_number_of_findings) > 0
ORDER BY num DESC;I would try something like that to avoid the subquerys:
SELECT ct.test_doc_id ,
ct.test_date, ct.test_time, doc.doc_name,
doc.doc_type, doc.doc_url, ut.user_id, ut.first_name, ut.last_name,
tr.result_status, pt.policy_id, pt.policy_name, prjt.project_name,
COUNT(*) num,
SUM( tr.result_number_of_findings) findings,
SUM( DECODE( tr.result_status, '1', 1, 0 )) AS PASSED,
SUM( DECODE( tr.result_status, '-1', 1, 0)) AS not_passed,
SUM( DECODE( tr.result_status, '0', 1, 0 )) AS undetermined
FROM conformance_tests_tbl ct,
users_tbl ut,
documents_tbl doc,
test_results_tbl tr,
policies_tbl pt,
association_tbl ab,
project_tbl prjt
WHERE (ct.test_doc_id= doc.doc_id)
AND (ct.test_initiated_by = ut.user_id)
AND (ct.test_id = tr.result_test_id)
AND (ct.test_policy_id = pt.policy_id)
AND (ct.test_doc_id = ab.object_instance_id)
AND (ab.object_type_id = '3')
AND (ab.subject_type_id = '2')
AND (ab.subject_instance_id = prjt.project_id)
GROUP BY ct.test_doc_id ,
ct.test_date, ct.test_time, doc.doc_name,
doc.doc_type, doc.doc_url, ut.user_id, ut.first_name, ut.last_name,
tr.result_status, pt.policy_id, pt.policy_name, prjt.project_name,
HAVING SUM(tr.result_number_of_findings) > 0
AND SUM( DECODE( tr.result_status, '-1', 1, 0)) > 0
ORDER BY num DESC; -
Best way to write this sql ?
Please let me know best way to write this SQL.
select col1, count(*)
from TableA
group by col1
having count(*) =
(select max(vals)
from
select col1, count(*) as vals
from TableA
group by col1
having count(*) > 1
)post EXPLAIN PLAN
SELECT col1,
COUNT(*)
FROM tablea
GROUP BY col1
HAVING COUNT(*) = (SELECT MAX(vals)
FROM (SELECT col1,
COUNT(*) AS vals
FROM tablea
GROUP BY col1
HAVING COUNT(*) > 1)) -
What this SQL did is to generate a report like how many rows for each tp_stts when ims_toms_msge_type='TOMS NEW' (or 'TOMS CNCLO'). also, its corresponding total number for each ims_toms_msge_type.
Here is the sample:
Rownum H1 TP_STTS COUNT IMS_TOMS_MSGE_TYPE H FILTERTYPE
1 Trades Block Key Data Error 594 TOMS NEW A MSL
2 Allocation Data Error 334 TOMS NEW A MSL
3 Manual Processing Required 29 TOMS NEW A MSL
4 Manual Removal No Processing Required 67 TOMS NEW A MSL
5 Waiting For Authorization 2 TOMS NEW A MSL
6 Auto NAK 19764 TOMS NEW B SLS
7 Validated 165023 TOMS NEW B SLS
8 GRAND TOTAL 185813 TOMS NEW H MSL
9 Cancel Auto NAK 37 TOMS CNCLO X MSL
10 Manual Processing Required 114 TOMS CNCLO X MSL
11 Manually Processed 278 TOMS CNCLO X MSL
12 CANCEL GRAND TOTAL 429 TOMS CNCLO Z MSLSQL statement as below:
SELECT ROWNUM, MSGS.* FROM (with FTMReport as (
select tp_stts, ims_toms_msge_type, count(*) count from ims_trde, ims_toms_msge
where ( IMS_TRDE.PRCSG_GRP_ID = 5 ) AND ( IMS_TRDE.IMS_TRDE_RCPT_DTTM >= TO_DATE('12/01/2009 00:00', 'MM/DD/YYYY HH24:MI') AND IMS_TRDE.IMS_TRDE_RCPT_DTTM <= (TO_DATE('12/28/2009 23:59', 'MM/DD/YYYY HH24:MI')) ) AND (IMS_TRDE.GRS_TRX_TYPE NOT IN ('INJECTION','WITHDRAWAL','PAYMENT') OR IMS_TRDE.GRS_TRX_TYPE IS NULL) AND (IMS_TRDE.SSC_INVST_TYPE != 'FC' OR IMS_TRDE.SSC_INVST_TYPE IS NULL) AND (IMS_TRDE.SERVICE_TYPE='FS' OR IMS_TRDE.SERVICE_TYPE='CO') AND 1=1
and IMS_TRDE.SERVICE_TYPE='FS' and 1=1 and ims_trde.ims_trde_oid = ims_toms_msge.ims_trde_oid
group by tp_stts, ims_toms_msge_type
select 'GRAND TOTAL' H1, null tp_stts, sum(Count) count , ims_toms_msge_type ,'H', 'MSL' FilterType
from FTMReport where ims_toms_msge_type in ('TOMS NEW') group by ims_toms_msge_type
union
select 'CANCEL GRAND TOTAL' H1, null tp_stts, sum(Count) count, ims_toms_msge_type ,'Z', 'MSL' FilterType
from FTMReport where ims_toms_msge_type in ('TOMS CNCLO') group by ims_toms_msge_type
union
select DECODE(rownum, 1, 'Trades') H1, tp_stts, count, ims_toms_msge_type , 'A' , 'MSL' FilterType
from FTMReport where ims_toms_msge_type in ('TOMS NEW') and tp_stts not in ('Validated','Auto NAK','Manual NAK')
union
select ' ' H1, tp_stts, count, ims_toms_msge_type , 'B' , 'SLS' FilterType
from FTMReport where ims_toms_msge_type in ('TOMS NEW') and tp_stts in ('Validated','Auto NAK','Manual NAK')
union
select DECODE(rownum, 1, 'Cancel') H1, tp_stts, count, ims_toms_msge_type , 'X' , 'MSL' FilterType
from FTMReport where ims_toms_msge_type in ('TOMS CNCLO') order by 5,6
) MSGS;Explain plan as below:
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 193 | 12738 | 32 |
| 1 | COUNT | | | | |
| 2 | VIEW | | 193 | 12738 | 32 |
| 4 | TEMP TABLE TRANSFORMATION | | | | |
| 3 | RECURSIVE EXECUTION | SYS_LE_4_0 | | | |
| 0 | INSERT STATEMENT | | 61 | 4575 | 9264 |
| 1 | LOAD AS SELECT | | | | |
| 2 | SORT GROUP BY | | 61 | 4575 | 9264 |
| 3 | NESTED LOOPS | | 1604 | 117K| 9251 |
|* 4 | TABLE ACCESS BY INDEX ROWID| IMS_TRDE | 1603 | 80150 | 6045 |
|* 5 | INDEX RANGE SCAN | IMS_TRDE_INDX4 | 539K| | 3917 |
|* 6 | INDEX RANGE SCAN | IMS_TOMS_MSGE_INDX1 | 1 | 25 | 2 |
| 5 | SORT UNIQUE | | 193 | 8831 | 30 |
| 6 | UNION-ALL | | | | |
| 7 | SORT GROUP BY NOSORT | | 5 | 115 | 6 |
|* 8 | VIEW | | 61 | 1403 | 2 |
| 9 | TABLE ACCESS FULL | SYS_TEMP_0FD9D660F_B198D56F | 61 | 2074 | 2 |
| 10 | SORT GROUP BY NOSORT | | 5 | 115 | 6 |
|* 11 | VIEW | | 61 | 1403 | 2 |
| 12 | TABLE ACCESS FULL | SYS_TEMP_0FD9D660F_B198D56F | 61 | 2074 | 2 |
| 13 | COUNT | | | | |
|* 14 | VIEW | | 61 | 2867 | 2 |
| 15 | TABLE ACCESS FULL | SYS_TEMP_0FD9D660F_B198D56F | 61 | 2074 | 2 |
|* 16 | VIEW | | 61 | 2867 | 2 |
| 17 | TABLE ACCESS FULL | SYS_TEMP_0FD9D660F_B198D56F | 61 | 2074 | 2 |
| 18 | COUNT | | | | |
|* 19 | VIEW | | 61 | 2867 | 2 |
| 20 | TABLE ACCESS FULL | SYS_TEMP_0FD9D660F_B198D56F | 61 | 2074 | 2 |
Predicate Information (identified by operation id):
4 - filter(("IMS_TRDE"."GRS_TRX_TYPE"<>'INJECTION' AND "IMS_TRDE"."GRS_TRX_TYPE"<>'WITHDRAWAL'
AND "IMS_TRDE"."GRS_TRX_TYPE"<>'PAYMENT' OR "IMS_TRDE"."GRS_TRX_TYPE" IS NULL) AND
("IMS_TRDE"."SSC_INVST_TYPE"<>'FC' OR "IMS_TRDE"."SSC_INVST_TYPE" IS NULL))
5 - access("IMS_TRDE"."IMS_TRDE_RCPT_DTTM">=TO_DATE(' 2009-12-01 00:00:00', 'syyyy-mm-dd
hh24:mi:ss') AND "IMS_TRDE"."PRCSG_GRP_ID"=5 AND "IMS_TRDE"."SERVICE_TYPE"='FS' AND
"IMS_TRDE"."IMS_TRDE_RCPT_DTTM"<=TO_DATE(' 2009-12-28 23:59:00', 'syyyy-mm-dd hh24:mi:ss'))
filter("IMS_TRDE"."PRCSG_GRP_ID"=5 AND "IMS_TRDE"."SERVICE_TYPE"='FS')
6 - access("IMS_TRDE"."IMS_TRDE_OID"="IMS_TOMS_MSGE"."IMS_TRDE_OID")
8 - filter("FTMREPORT"."IMS_TOMS_MSGE_TYPE"='TOMS NEW')
11 - filter("FTMREPORT"."IMS_TOMS_MSGE_TYPE"='TOMS CNCLO')
14 - filter("FTMREPORT"."IMS_TOMS_MSGE_TYPE"='TOMS NEW' AND "FTMREPORT"."TP_STTS"<>'Validated'
AND "FTMREPORT"."TP_STTS"<>'Auto NAK' AND "FTMREPORT"."TP_STTS"<>'Manual NAK')
16 - filter("FTMREPORT"."IMS_TOMS_MSGE_TYPE"='TOMS NEW' AND ("FTMREPORT"."TP_STTS"='Auto NAK' OR
"FTMREPORT"."TP_STTS"='Manual NAK' OR "FTMREPORT"."TP_STTS"='Validated'))
19 - filter("FTMREPORT"."IMS_TOMS_MSGE_TYPE"='TOMS CNCLO')
Note: cpu costing is offCould you guys tell me what is wrong with this sql and how to tune it?
Is there any way to replace the UNION? Is using UNION a good idea?
Can I use DECODE or CASE WHEN to simplify it? How?
Also, could you help explain why there is SYS_LE_4_0, SYS_TEMP_0FD9D660F_B198D56F temporary segment? Is it caused by with FTMReport as ?
Thanks
Edited by: PhoenixBai on Dec 31, 2009 9:58 AM
Edited by: PhoenixBai on Dec 31, 2009 12:08 PM
Edited by: PhoenixBai on Dec 31, 2009 12:17 PMI consider using GROUP BY ROLLUP together with DECODE, CASE WHEN, but haven`t come out with a working sql yet:-(Some sample data to work with would have been much helpful. But we dont get that most of the time :(
I came up with this.
select case when ims_toms_msge_type = 'TOMS NEW' then
case when grouping(tp_stts) = 1 then 'GRAND TOTAL'
when tp_stts not in ('Validated','Auto NAK','Manual NAK') then 'Trades'
end
when ims_toms_msge_type = 'TOMS CNCLO' then
case when grouping(tp_stts) = 1 then 'CANCEL GRAND TOTAL'
when tp_stts in ('Validated','Auto NAK','Manual NAK') then 'Cancel'
end
end h1,
tp_stts,
count(*) count,
ims_toms_msge_type,
case when ims_toms_msge_type = 'TOMS NEW' then
case when grouping(tp_stts) = 1 then 'H'
when tp_stts not in ('Validated','Auto NAK','Manual NAK') then 'A'
end
when ims_toms_msge_type = 'TOMS CNCLO' then
case when grouping(tp_stts) = 1 then 'Z'
when tp_stts in ('Validated','Auto NAK','Manual NAK') then 'B'
end
end flag,
'MSL' FilterType
from ims_trde,
ims_toms_msge
where IMS_TRDE.PRCSG_GRP_ID = 5
AND IMS_TRDE.IMS_TRDE_RCPT_DTTM >= TO_DATE('12/01/2009 00:00', 'MM/DD/YYYY HH24:MI')
AND IMS_TRDE.IMS_TRDE_RCPT_DTTM <= TO_DATE('12/28/2009 23:59', 'MM/DD/YYYY HH24:MI')
AND (IMS_TRDE.GRS_TRX_TYPE NOT IN ('INJECTION','WITHDRAWAL','PAYMENT')
OR IMS_TRDE.GRS_TRX_TYPE IS NULL)
AND (IMS_TRDE.SSC_INVST_TYPE != 'FC'
OR IMS_TRDE.SSC_INVST_TYPE IS NULL)
AND (IMS_TRDE.SERVICE_TYPE = 'FS'
OR IMS_TRDE.SERVICE_TYPE = 'CO')
AND 1=1
and IMS_TRDE.SERVICE_TYPE = 'FS'
and 1=1
and ims_trde.ims_trde_oid = ims_toms_msge.ims_trde_oid
group by rollup(ims_toms_msge_type, tp_stts)Not sure if this code works. Because i dint have the table or the data to test it. So if it has some error just fix it and give it a try. Do post the kind of output it gives. So that we can see if we can work with this solution. -
How to optimize this SQL. Help needed.
Hi All,
Can you please help with this SQL:
SELECT /*+ INDEX(zl1 zipcode_lat1) */
zl2.zipcode as zipcode,l.location_id as location_id,
sqrt(POWER((69.1 * ((zl2.latitude*57.295779513082320876798154814105) - (zl1.latitude*57.295779513082320876798154814105))),2) + POWER((69.1 * ((zl2.longitude*57.295779513082320876798154814105) - (zl1.longitude*57.295779513082320876798154814105)) * cos((zl1.latitude*57.295779513082320876798154814105)/57.3)),2)) as distance
FROM location_atao l, zipcode_atao zl1, client c, zipcode_atao zl2
WHERE zl1.zipcode = l.zipcode
AND l.client_id = c.client_id
AND c.client_id = 306363
And l.appType = 'HOURLY'
and c.milessearchzipcode >= sqrt(POWER((69.1 * ((zl2.latitude*57.295779513082320876798154814105) - (zl1.latitude*57.295779513082320876798154814105))),2) + POWER((69.1 * ((zl2.longitude*57.295779513082320876798154814105) - (zl1.longitude*57.295779513082320876798154814105)) * cos((zl1.latitude*57.295779513082320876798154814105)/57.3)),2))
I tried to optimize it by adding country column in zipcode_atao table. So that we can limit the search in zipcode_atao table based on country.
Any other suggestions.
ThanksWelcome to the forum.
Please follow the instructions given in this thread:
How to post a SQL statement tuning request
HOW TO: Post a SQL statement tuning request - template posting
and add the nessecary details we need to your thread.
Depending on your database version (the result of: select * from v$version; ):
Have you tried running the query without the index-hint?
Are your table (and index) statatistics up-to-date?
Maybe you are looking for
-
Selective and slow syncing in iCal
Today I updated my iPhone and iPad to iOs 5 and my laptop to 10.7.2. The iPhone and iPad have subsribed to iCloud, but not yet for the laptop. I also have an imac running 10.6.8 (can't update it to Lion because I need Rosetta) and a G5 running 10.5.8
-
OK, guys, I'm in over my head here. Working on the 3-night project shot last week. Will be making DVDs out of this project. Shot with HV30 in 30P mode, last night in Cine, too. Film noise/grain PLUS not best audio first 2 nights because shooting from
-
StorEdge 3310 Slowness and "Memory Not Sufficient" Error
Hello, I have a 3310 single-controller array who's LUN inexplicably became incredibly lethargic a couple of days ago. I checked the controller's event log and have the following message: "Controller WARNING: memory not sufficient to fully support cur
-
Why Kodo tries to reload deleted object?
Hello, I'm deleting User object that has dependent child object. Child is removed in jdoPreDelete() method. Than client application invokes different method selecting all the Users by Extent (for different PersistenceManager instance): Extent userExt
-
Does anyone know where the DVD region information is stored, in the MBA or in the external drive? In other words would it be possible to buy two external drives, one set to Region 1 and the other to Region 2, and then watch both American and European