Performance of ORACLE query
Hi All,
i m having following issue kindly inform me the is there any performance diffrence between following quiries A & B.
A)
select * from
tab1 t1 , tab2 t2
where
t1.id = 100
and t2.id = 100;
B)
select * from
tab1 t1 , tab2 t2
where
t1.id = 100
and t2.id = 100
and t1.id = t2.id;
Thanks & Regards,
Vikas
This forum is meant for issues related to database upgrades. Pl re-post in a more appropriate forum - such as "Database - General" General Database Discussions
Pl see these two threads on how to post a tuning request
HOW TO: Post a SQL statement tuning request - template posting
When your query takes too long ...
HTH
Srini
Similar Messages
-
Need to improve performance of oracle query
Hi ,
Currently i have written query to get maximun salary from XYZ company like this
select salary from (
select salary from employee
where company='XYZ'
order by salary desc )
where rownum<2;
i thought of replacing the same with following query
select max(salary)
from employee
where company='XYZ';
Which one will be faster ? can you provide some statistical data.It will be good if you share some oracle documentation for this.
Thanks,
KannanMost likely the second one. And in any case: the second one is much more straightforward and readable (i.e. the syntax describes exactly what you want: get the max salary). In that way, your application is better maintainable (i.e. cheaper and better in the long run), and likely more easy to optimize for the database. And yes, in this case it's a simple query, but if you're thinking of writing even simple queries in the style of your first example, I'd hate to think of what more complex queries would get to look like...
-
Oracle Query Performance While calling a function in a View
Hi,
We have a performance issue in one of our Oracle queries.
Here is the scenario
We use a hard coded value (which is the maximum value from a table) in couple of DECODE statements in our query. We would like to remove this hard coded value from the query. So we wrote a function which will return a maximum value from the table. Now when we execute the query after replacing the hard coded value with the function, this function is called four times which hampers the query performance.
Pl find below the DECODE statements in the query. This query is part of a main VIEW.
Using Hardcoded values
=================
DECODE(pro_risk_weighted_ctrl_scr, 10, 9.9, pro_risk_weighted_ctrl_scr)
DECODE(pro_risk_score, 46619750, 46619749, pro_risk_score)
Using Functions
============
DECODE (pro_risk_weighted_ctrl_scr, rprowbproc.fn_max_rcsa_range_values ('CSR'), rprowbproc.fn_max_rcsa_range_values('CSR')- 0.1, pro_risk_weighted_ctrl_scr)
DECODE (pro_risk_score, rprowbproc.fn_max_rcsa_range_values ('RSR'), rprowbproc.fn_max_rcsa_range_values ('RSR') - 1, pro_risk_score)
Can any one suggest a way to improve the performance of the query.
Thanks & Regards,
Rajidrop table max_demo;
create table max_demo
(rcsa varchar2(10)
,value number);
insert into max_demo
select case when mod(rownum,2) = 0
then 'CSR'
else 'RSR'
end
, rownum
from dual
connect by rownum <= 10000;
create or replace function f_max (
i_rcsa in max_demo.rcsa%TYPE
return number
as
l_max number;
begin
select max(value)
into l_max
from max_demo
where rcsa = i_rcsa;
return l_max;
end;
-- slooooooooooooowwwwww
select m.*
, f_max(rcsa)
, decode(rcsa,'CSR',decode(value,f_max('CSR'),'Y - max is '||f_max('CSR'),'N - max is '||f_max('CSR'))) is_max_csr
, decode(rcsa,'RSR',decode(value,f_max('RSR'),'Y - max is '||f_max('RSR'),'N - max is '||f_max('RSR'))) is_max_rsr
from max_demo m
order by value desc;
-- ssllooooowwwww
with subq_max as
(select f_max('CSR') max_csr,
f_max('RSR') max_rsr
from dual)
select m.*
, decode(rcsa,'CSR',s.max_csr,'RSR',s.max_rsr) max
, decode(rcsa,'CSR',decode(value,s.max_csr,'Y - max is '||s.max_csr,'N - max is '||s.max_csr)) is_max_csr
, decode(rcsa,'RSR',decode(value,s.max_rsr,'Y - max is '||s.max_rsr,'N - max is '||s.max_rsr)) is_max_rsr
from max_demo m
, subq_max s
order by value desc;
-- faster
with subq_max as
(select /*+materialize */
f_max('CSR') max_csr,
f_max('RSR') max_rsr
from dual)
select m.*
, decode(rcsa,'CSR',s.max_csr,'RSR',s.max_rsr) max
, decode(rcsa,'CSR',decode(value,s.max_csr,'Y - max is '||s.max_csr,'N - max is '||s.max_csr)) is_max_csr
, decode(rcsa,'RSR',decode(value,s.max_rsr,'Y - max is '||s.max_rsr,'N - max is '||s.max_rsr)) is_max_rsr
from max_demo m
, subq_max s
order by value desc;
-- faster
with subq_max as
(select f_max('CSR') max_csr,
f_max('RSR') max_rsr,
rownum
from dual)
select m.*
, decode(rcsa,'CSR',s.max_csr,'RSR',s.max_rsr) max
, decode(rcsa,'CSR',decode(value,s.max_csr,'Y - max is '||s.max_csr,'N - max is '||s.max_csr)) is_max_csr
, decode(rcsa,'RSR',decode(value,s.max_rsr,'Y - max is '||s.max_rsr,'N - max is '||s.max_rsr)) is_max_rsr
from max_demo m
, subq_max s
order by value desc;
-- sloooooowwwwww
select m.*
, decode(rcsa,'CSR',s.max_csr,'RSR',s.max_rsr) max
, decode(rcsa,'CSR',decode(value,s.max_csr,'Y - max is '||s.max_csr,'N - max is '||s.max_csr)) is_max_csr
, decode(rcsa,'RSR',decode(value,s.max_rsr,'Y - max is '||s.max_rsr,'N - max is '||s.max_rsr)) is_max_rsr
from max_demo m
, (select /*+ materialize */
f_max('CSR') max_csr,
f_max('RSR') max_rsr
from dual) s
order by value desc;
-- faster
select m.*
, decode(rcsa,'CSR',s.max_csr,'RSR',s.max_rsr) max
, decode(rcsa,'CSR',decode(value,s.max_csr,'Y - max is '||s.max_csr,'N - max is '||s.max_csr)) is_max_csr
, decode(rcsa,'RSR',decode(value,s.max_rsr,'Y - max is '||s.max_rsr,'N - max is '||s.max_rsr)) is_max_rsr
from max_demo m
, (select f_max('CSR') max_csr,
f_max('RSR') max_rsr,
rownum
from dual) s
order by value desc; -
How to improve performance of Oracle Forms Server ?
Recently we converted our Application which was Developed in Forms 5.0 and Reports 3.0 into Forms6i to host that on to Web. We also loaded ORACLE 9iAS (on Windows NT 4 with service pack 3) from "Enterprise Edition" option by selecting Oracle Database Cache, Forms Server and Reports Server, HTTP Server(on port 80),Oracle Web Cache. Everything loaded succesfully including Caches.
Forms server is working perfectly and we were able to run our Application in Browser, but performance is the issue. We thought the caches will improve the performance, but it seems they are not at all working. When we run a report or form the Database cache is not giving any statistics whether a particular Query is a Hit or Miss though the cache is running. We got a doubt and searched in FAQ's and we found the following questions.
Oracle9iAS Web Cache Frequently Asked
Questions February 2001
Does Oracle9iAS Web Cache work with applications that use Oracle9iAS Forms?
Not in the 1.x release of Oracle9iAS. Integration between Oracle9iAS Web Cache and Oracle9iAS Forms will be addressed at a future date.
Oracle9iAS Database Cache
Does the Cache work with Oracle Forms and Portal in Oracle9i AS?
Since Oracle Forms and Portal utilize read/write PL/SQL stored procedures, these components cannot take advantage of the Cache. This support is being considered for a future version.
After coming to know that Caches doesnot boost the performance of Oracle Forms and reports. We have the following queries.
1) Clarify whether the above are True.
2) Apart from DB and Web Cache is there any other way where in we can improve the performance of Oracle Forms and Reports in Forms Server including the start up time.
3) What is the ideal configuration required for each tier (iAS Server,Database Server and Client) to host Forms on to Web considering our application as Medium scale.
(Presently our configuration are,
Application Server Configuration : Windows NT 4 with service pack 3,256 MB RAM,1 GB Virtual memory and 4GB free space and almost the same configuration is being used for
Database Configuration.
Client Configuration : Windows 98 with 64MB RAM).
4) Is there any way to track the performance and know the problem areas like TRACE.
Gopi Kumar
nullA couple of questions for you:
1) What version of IAS are you using?
2) What's the version of Forms&Reports and
3) What version of patch are you using if any
for forms&Reports?
4) What applications are you running on the
machine where Forms&Reports is installed?
(I mean non-Oracle applications?)
The problem could be that, the base addresses
of the DLL's in Forms&Reports could be having base address conflicts with some other application's DLL's.
Forms and Reports needs to be fully rebased to achieve full performance on NT. Before release of Forms and Reports, Oracle rebases all DLLs. Rebasing assigns unique base addresses to all of the DLL's in use by an executable. A properly based DLL will load at its preferred base address, greatly improving the efficiency of memory utilization and the runtime performance of the executable.
Multiple utilities are available on NT to verify proper rebasing of DLLs. HandleEx v4.0 is one such freeware from Sysinternals and is available at www.sysinternals.com. Some others are "depends.exe" that's part of the MS Visual Studio or msinfo32.exe that comes with Office 2000 on NT.
If after running any of these utilities you discover that the DLL's ar not properly rebased, you need to contact Oracle worldwide support.
If you find that rebasing is not the problem, then please post your feedback again. Hope this helps. -
Please help me to increase the performance of the query
Hello
I am not an oracle expert or developer and i have a problem to resolve.
Below is the query and explaiation plan and seeking the help to improve the performance of the query.
Our Analysis,
The query runs good,takes less one minute and fetches the results but during peak time it takes 8 minutes
Require anyone suggestion's to improve the query.
The query is generated from the Microsft dll so we dont have SQL code and require some help on tuning the tables.
If tuning the query improves then also fine please suggest for that also.
Enviroment: Solaris 8
DB : oracle 9i
(SELECT vw.dispapptobjid, vw.custsiteobjid, vw.emplastname, vw.empfirstname,
vw.scheduledonsite AS starttime, vw.appttype, vw.latestart,
vw.endtime, vw.typetitle, vw.empobjid, vw.latitude, vw.longitude,
vw.workduration AS DURATION, vw.dispatchtype, vw.availability
FROM ora_appt_disp_view vw
WHERE ( ( vw.starttime >=
TO_DATE ('2/12/2007 4:59 PM', 'MM/DD/YYYY HH12:MI AM')
AND vw.starttime <
TO_DATE ('2/21/2007 3:59 PM', 'MM/DD/YYYY HH12:MI AM')
OR vw.endtime >
TO_DATE ('2/12/2007 4:59 PM', 'MM/DD/YYYY HH12:MI AM')
AND vw.endtime <=
TO_DATE ('2/21/2007 3:59 PM', 'MM/DD/YYYY HH12:MI AM')
OR ( vw.starttime <=
TO_DATE ('2/12/2007 4:59 PM', 'MM/DD/YYYY HH12:MI AM')
AND vw.endtime >=
TO_DATE ('2/21/2007 3:59 PM', 'MM/DD/YYYY HH12:MI AM')
UNION
(SELECT 0 AS dispapptobjid, emp.emp_physical_site2site AS custsiteobjid,
emp.last_name AS emplastname, emp.first_name AS empfirstname,
TO_DATE ('1/1/3000', 'MM/DD/YYYY') AS starttime, 'E' AS appttype,
NULL AS latestart, NULL AS endtime, '' AS typetitle,
emp.objid AS empobjid, 0 AS latitude, 0 AS longitude, 0 AS DURATION,
'' AS dispatchtype, 0 AS availability
FROM table_employee emp, table_user usr
WHERE emp.employee2user = usr.objid AND emp.field_eng = 1 AND usr.status = 1)
ORDER BY empobjid, starttime, endtime DESC
Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
SELECT STATEMENT Optimizer Mode=HINT: ALL_ROWS 23 K 11312
SORT UNIQUE 23 K 3 M 11140
UNION-ALL
VIEW ORA_APPT_DISP_VIEW 17 K 3 M 10485
UNION-ALL
CONCATENATION
NESTED LOOPS OUTER 68 24 K 437
NESTED LOOPS 68 23 K 369
NESTED LOOPS OUTER 68 25 K 505
NESTED LOOPS OUTER 68 24 K 505
NESTED LOOPS 68 23 K 369
NESTED LOOPS 68 22 K 369
NESTED LOOPS OUTER 68 22 K 369
NESTED LOOPS 19 6 K 312
NESTED LOOPS 19 5 K 312
HASH JOIN 19 5 K 293
NESTED LOOPS 19 5 K 274
NESTED LOOPS 19 4 K 236
NESTED LOOPS 19 4 K 198
NESTED LOOPS OUTER 19 3 K 160
NESTED LOOPS OUTER 19 3 K 160
NESTED LOOPS OUTER 19 4 K 160
NESTED LOOPS OUTER 19 1 K 103
NESTED LOOPS OUTER 19 2 K 103
NESTED LOOPS OUTER 19 2 K 103
TABLE ACCESS BY INDEX ROWID TABLE_DISPTCHFE 19 1 K 46
INDEX RANGE SCAN GSA_SCHED_REPAIR 44 3
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 22
INDEX RANGE SCAN GSA_COMDFE 1 2
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 22
INDEX RANGE SCAN GSA_COMDFE 1 2
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 22 3
INDEX RANGE SCAN GSA_COMDFE 1 2
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 28
INDEX RANGE SCAN IND_CASE_COMMIT2CASE 2 2
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 28
INDEX RANGE SCAN IND_CASE_COMMIT2CASE 2 2
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 28 3
INDEX RANGE SCAN IND_CASE_COMMIT2CASE 2 2
TABLE ACCESS BY INDEX ROWID TABLE_CASE 1 30 2
INDEX UNIQUE SCAN CASE_OBJINDEX 1 1
TABLE ACCESS BY INDEX ROWID TABLE_SITE 1 12 2
INDEX UNIQUE SCAN SITE_OBJINDEX 1 1
TABLE ACCESS BY INDEX ROWID TABLE_ADDRESS 1 12 2
INDEX UNIQUE SCAN ADDRESS_OBJINDEX 1 1
TABLE ACCESS FULL TABLE_EMPLOYEE 1 34 1
INDEX UNIQUE SCAN SITE_OBJINDEX 1 6 1
INDEX UNIQUE SCAN USER_OBJINDEX 1 6
TABLE ACCESS BY INDEX ROWID TABLE_X_GSA_TIME_STAMPS 4 48 3
INDEX RANGE SCAN GSAIDX_TS2DISP 1 2
INDEX UNIQUE SCAN GBST_ELM_OBJINDEX 1 6
INDEX UNIQUE SCAN GBST_ELM_OBJINDEX 1 6
TABLE ACCESS BY INDEX ROWID TABLE_MOD_LEVEL 1 12 1
INDEX UNIQUE SCAN MOD_LEVEL_OBJINDEX 1
INDEX UNIQUE SCAN PART_NUM_OBJINDEX 1 6
INDEX UNIQUE SCAN GBST_ELM_OBJINDEX 1 6
INDEX UNIQUE SCAN SUBCASE_OBJINDX 1 6 1
NESTED LOOPS OUTER 68 25 K 505
NESTED LOOPS OUTER 68 24 K 505
NESTED LOOPS OUTER 68 24 K 437
NESTED LOOPS 68 23 K 369
NESTED LOOPS 68 23 K 369
NESTED LOOPS 68 22 K 369
NESTED LOOPS OUTER 68 22 K 369
NESTED LOOPS 19 6 K 312
NESTED LOOPS 19 5 K 312
NESTED LOOPS 19 5 K 293
NESTED LOOPS 19 5 K 274
NESTED LOOPS 19 4 K 236
NESTED LOOPS 19 4 K 198
NESTED LOOPS OUTER 19 4 K 160
NESTED LOOPS OUTER 19 3 K 160
NESTED LOOPS OUTER 19 3 K 160
NESTED LOOPS OUTER 19 2 K 103
NESTED LOOPS OUTER 19 2 K 103
NESTED LOOPS OUTER 19 1 K 103
TABLE ACCESS BY INDEX ROWID TABLE_DISPTCHFE 19 1 K 46
INDEX RANGE SCAN GSA_SCHED_REPAIR 44 3
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 22 3
INDEX RANGE SCAN GSA_COMDFE 1 2
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 22
INDEX RANGE SCAN GSA_COMDFE 1 2
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 22
INDEX RANGE SCAN GSA_COMDFE 1 2
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 28 3
INDEX RANGE SCAN IND_CASE_COMMIT2CASE 2 2
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 28
INDEX RANGE SCAN IND_CASE_COMMIT2CASE 2 2
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 28
INDEX RANGE SCAN IND_CASE_COMMIT2CASE 2 2
TABLE ACCESS BY INDEX ROWID TABLE_CASE 1 30 2
INDEX UNIQUE SCAN CASE_OBJINDEX 1 1
TABLE ACCESS BY INDEX ROWID TABLE_SITE 1 12 2
INDEX UNIQUE SCAN SITE_OBJINDEX 1 1
TABLE ACCESS BY INDEX ROWID TABLE_ADDRESS 1 12 2
INDEX UNIQUE SCAN ADDRESS_OBJINDEX 1 1
TABLE ACCESS BY INDEX ROWID TABLE_EMPLOYEE 1 34 1
INDEX UNIQUE SCAN EMPLOYEE_OBJINDEX 1
INDEX UNIQUE SCAN SITE_OBJINDEX 1 6 1
INDEX UNIQUE SCAN USER_OBJINDEX 1 6
TABLE ACCESS BY INDEX ROWID TABLE_X_GSA_TIME_STAMPS 4 48 3
INDEX RANGE SCAN GSAIDX_TS2DISP 1 2
INDEX UNIQUE SCAN GBST_ELM_OBJINDEX 1 6
INDEX UNIQUE SCAN GBST_ELM_OBJINDEX 1 6
INDEX UNIQUE SCAN GBST_ELM_OBJINDEX 1 6
INDEX UNIQUE SCAN SUBCASE_OBJINDX 1 6 1
TABLE ACCESS BY INDEX ROWID TABLE_MOD_LEVEL 1 12 1
INDEX UNIQUE SCAN MOD_LEVEL_OBJINDEX 1
INDEX UNIQUE SCAN PART_NUM_OBJINDEX 1 6
NESTED LOOPS OUTER 68 25 K 505
NESTED LOOPS OUTER 68 24 K 505
NESTED LOOPS OUTER 68 24 K 437
NESTED LOOPS 68 23 K 369
NESTED LOOPS 68 23 K 369
NESTED LOOPS 68 22 K 369
NESTED LOOPS OUTER 68 22 K 369
NESTED LOOPS 19 6 K 312
NESTED LOOPS 19 5 K 312
NESTED LOOPS 19 5 K 293
NESTED LOOPS 19 5 K 274
NESTED LOOPS 19 4 K 236
NESTED LOOPS 19 4 K 198
NESTED LOOPS OUTER 19 4 K 160
NESTED LOOPS OUTER 19 3 K 160
NESTED LOOPS OUTER 19 3 K 160
NESTED LOOPS OUTER 19 2 K 103
NESTED LOOPS OUTER 19 2 K 103
NESTED LOOPS OUTER 19 1 K 103
TABLE ACCESS BY INDEX ROWID TABLE_DISPTCHFE 19 1 K 46
INDEX RANGE SCAN GSA_REQ_ETA 44 3
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 22 3
INDEX RANGE SCAN GSA_COMDFE 1 2
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 22
INDEX RANGE SCAN GSA_COMDFE 1 2
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 22
INDEX RANGE SCAN GSA_COMDFE 1 2
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 28 3
INDEX RANGE SCAN IND_CASE_COMMIT2CASE 2 2
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 28
INDEX RANGE SCAN IND_CASE_COMMIT2CASE 2 2
TABLE ACCESS BY INDEX ROWID TABLE_COMMIT_LOG 1 28
INDEX RANGE SCAN IND_CASE_COMMIT2CASE 2 2
TABLE ACCESS BY INDEX ROWID TABLE_CASE 1 30 2
INDEX UNIQUE SCAN CASE_OBJINDEX 1 1
TABLE ACCESS BY INDEX ROWID TABLE_SITE 1 12 2
INDEX UNIQUE SCAN SITE_OBJINDEX 1 1
TABLE ACCESS BY INDEX ROWID TABLE_ADDRESS 1 12 2
INDEX UNIQUE SCAN ADDRESS_OBJINDEX 1 1
TABLE ACCESS BY INDEX ROWID TABLE_EMPLOYEE 1 34 1
INDEX UNIQUE SCAN EMPLOYEE_OBJINDEX 1
INDEX UNIQUE SCAN SITE_OBJINDEX 1 6 1
INDEX UNIQUE SCAN USER_OBJINDEX 1 6
TABLE ACCESS BY INDEX ROWID TABLE_X_GSA_TIME_STAMPS 4 48 3
INDEX RANGE SCAN GSAIDX_TS2DISP 1 2
INDEX UNIQUE SCAN GBST_ELM_OBJINDEX 1 6
INDEX UNIQUE SCAN GBST_ELM_OBJINDEX 1 6
INDEX UNIQUE SCAN GBST_ELM_OBJINDEX 1 6
INDEX UNIQUE SCAN SUBCASE_OBJINDX 1 6 1
TABLE ACCESS BY INDEX ROWID TABLE_MOD_LEVEL 1 12 1
INDEX UNIQUE SCAN MOD_LEVEL_OBJINDEX 1
INDEX UNIQUE SCAN PART_NUM_OBJINDEX 1 6
NESTED LOOPS 16 K 2 M 5812
HASH JOIN 16 K 2 M 5812
HASH JOIN 16 K 2 M 5286
TABLE ACCESS FULL TABLE_EMPLOYEE 13 K 441 K 28
HASH JOIN 16 K 1 M 5243
TABLE ACCESS FULL TABLE_SCHEDULE 991 11 K 2
HASH JOIN OUTER 16 K 1 M 5240
HASH JOIN OUTER 16 K 1 M 3866
HASH JOIN OUTER 16 K 1 M 450
HASH JOIN 16 K 1 M 44
TABLE ACCESS FULL TABLE_GBST_ELM 781 14 K 2
TABLE ACCESS FULL TABLE_APPOINTMENT 16 K 822 K 41
INDEX FAST FULL SCAN CASE_OBJINDEX 1 M 6 M 201
TABLE ACCESS FULL TABLE_SITE 967 K 11 M 3157
TABLE ACCESS FULL TABLE_ADDRESS 961 K 11 M 1081
INDEX FAST FULL SCAN SITE_OBJINDEX 967 K 5 M 221
INDEX UNIQUE SCAN USER_OBJINDEX 1 6
HASH JOIN 6 K 272 K 51
TABLE ACCESS FULL TABLE_USER 6 K 51 K 21
TABLE ACCESS FULL TABLE_EMPLOYEE 6 K 220 K 28Hi,
First-off, it appear that you are querying a view. I would redo the auery against the base table.
Next, look at a function-based index for the DATE column. Here are my notes:
http://www.dba-oracle.com/t_function_based_indexes.htm
http://www.dba-oracle.com/oracle_tips_index_scan_fbi_sql.htm
Also, make sure you are analyzed properly with dbms_stats:
http://www.dba-oracle.com/art_builder_dbms_stats.htm
And histograms, if appropriate:
http://www.dba-oracle.com/art_builder_histo.htm
Lasty, look at increasing hash_area_size or pga_aggregate_tagtet, depending on your table sizes:
http://www.dba-oracle.com/art_so_undocumented_pga_parameters.htm
Hope this helps. . . .
Donald K. Burleson
Oracle Press Author -
Bad performance of af:query
I am working on Oracle Jdeveloper 11g Release 1
I have a VO which gets executed when the first page gets loaded. suppose the VO is RuleLibraryVO
I have a view criteria RuleLibraryVOCriteria in the VO which is used in the af:query panel in the page.
When i do search for any attribute using the query panel the VO gets executed again everytime even if the VO is in the memory. This is hampering the performance of my query panel as it is again calling getters for all 2000+ rows and then searching. The VO Criteria used is:
<ViewCriteria
Name="RuleLibraryVOCriteria"
ViewObjectName="oracle.sysman.core.gccompliance.model.library.rule.view.RuleLibraryVO"
Conjunction="AND"
Mode="3">
<Properties>
<CustomProperties>
<Property
Name="displayOperators"
Value="InAdvancedMode"/>
<Property
Name="autoExecute"
Value="true"/>
<Property
Name="allowConjunctionOverride"
Value="true"/>
<Property
Name="showInList"
Value="false"/>
<Property
Name="mode"
Value="Basic"/>
<Property
Name="displayName"
ResId="DEFAULT_SEARCH"/>
</CustomProperties>
</Properties>
<ViewCriteriaRow
Name="vcrow3"
UpperColumns="1">
<ViewCriteriaItem
Name="RuleDnameTransient"
ViewAttribute="RuleDnameTransient"
Operator="CONTAINS"
Conjunction="AND"
Required="Optional">
<CompOper
Name="LessThan"
ToDo="-1"
Oper="<"
MinCardinality="0"
MaxCardinality="0"/>
<CompOper
Name="LessThanOrEqualTo"
ToDo="-1"
Oper="<="
MinCardinality="0"
MaxCardinality="0"/>
<CompOper
Name="GreaterThan"
ToDo="-1"
Oper=">"
MinCardinality="0"
MaxCardinality="0"/>
<CompOper
Name="GreaterThanOrEqualTo"
ToDo="-1"
Oper=">="
MinCardinality="0"
MaxCardinality="0"/>
</ViewCriteriaItem>
<ViewCriteriaItem
Name="DescriptionTransient"
ViewAttribute="DescriptionTransient"
Operator="CONTAINS"
Conjunction="AND"
Required="Optional">
<CompOper
Name="LessThan"
ToDo="-1"
Oper="<"
MinCardinality="0"
MaxCardinality="0"/>
<CompOper
Name="LessThanOrEqualTo"
ToDo="-1"
Oper="<="
MinCardinality="0"
MaxCardinality="0"/>
<CompOper
Name="GreaterThan"
ToDo="-1"
Oper=">"
MinCardinality="0"
MaxCardinality="0"/>
<CompOper
Name="GreaterThanOrEqualTo"
ToDo="-1"
Oper=">="
MinCardinality="0"
MaxCardinality="0"/>
</ViewCriteriaItem>
<ViewCriteriaItem
Name="IsSystem"
ViewAttribute="IsSystem"
Operator="="
Conjunction="AND"
Required="Optional"/>
<ViewCriteriaItem
Name="RuleType"
ViewAttribute="RuleType"
Operator="="
Conjunction="AND"
Required="Optional"/>
<ViewCriteriaItem
Name="TargetType"
ViewAttribute="TargetType"
Operator="="
Conjunction="AND"
Required="Optional"
Value=":targetType"
IsBindVarValue="true"/>
<ViewCriteriaItem
Name="KeywordsTransient"
ViewAttribute="KeywordsTransient"
Operator="CONTAINS"
Conjunction="AND"
Required="Optional"/>
</ViewCriteriaRow>
</ViewCriteria>The query panel in jspx is:
<af:query id="qryId2"
headerText="#{coregccomplianceuiBundle.COMPLIANCE_SEARCH}"
disclosed="false"
value="#{bindings.RuleLibraryVOCriteriaQuery.queryDescriptor}"
model="#{bindings.RuleLibraryVOCriteriaQuery.queryModel}"
queryListener="#{bindings.RuleLibraryVOCriteriaQuery.processQuery}"
queryOperationListener="#{bindings.RuleLibraryVOCriteriaQuery.processQueryOperation}"
resultComponentId="::pc1:ruleLib" rows="3" maxColumns="2"
saveQueryMode="hidden"/>How can i optimize the search behavior so that it only searches using the vo data already loaded in memory.Hi Frank,
Thanks for quick response,
As suggested i made the Query Execution Mode to - In-Memory. And my view criteria now is:
<ViewCriteria
Name="RuleLibraryVOCriteria"
ViewObjectName="oracle.sysman.core.gccompliance.model.library.rule.view.RuleLibraryVO"
Conjunction="AND"
Mode="2">
<Properties>
<CustomProperties>
<Property
Name="displayOperators"
Value="InAdvancedMode"/>
<Property
Name="autoExecute"
Value="true"/>
<Property
Name="allowConjunctionOverride"
Value="true"/>
<Property
Name="showInList"
Value="false"/>
<Property
Name="mode"
Value="Basic"/>
<Property
Name="displayName"
ResId="DEFAULT_SEARCH"/>
</CustomProperties>
</Properties>
<ViewCriteriaRow
Name="vcrow3"
UpperColumns="1">
<ViewCriteriaItem
Name="RuleDnameTransient"
ViewAttribute="RuleDnameTransient"
Operator="CONTAINS"
Conjunction="AND"
Required="Optional">
<CompOper
Name="LessThan"
ToDo="-1"
Oper="<"
MinCardinality="0"
MaxCardinality="0"/>
<CompOper
Name="LessThanOrEqualTo"
ToDo="-1"
Oper="<="
MinCardinality="0"
MaxCardinality="0"/>
<CompOper
Name="GreaterThan"
ToDo="-1"
Oper=">"
MinCardinality="0"
MaxCardinality="0"/>
<CompOper
Name="GreaterThanOrEqualTo"
ToDo="-1"
Oper=">="
MinCardinality="0"
MaxCardinality="0"/>
</ViewCriteriaItem>
<ViewCriteriaItem
Name="DescriptionTransient"
ViewAttribute="DescriptionTransient"
Operator="CONTAINS"
Conjunction="AND"
Required="Optional">
<CompOper
Name="LessThan"
ToDo="-1"
Oper="<"
MinCardinality="0"
MaxCardinality="0"/>
<CompOper
Name="LessThanOrEqualTo"
ToDo="-1"
Oper="<="
MinCardinality="0"
MaxCardinality="0"/>
<CompOper
Name="GreaterThan"
ToDo="-1"
Oper=">"
MinCardinality="0"
MaxCardinality="0"/>
<CompOper
Name="GreaterThanOrEqualTo"
ToDo="-1"
Oper=">="
MinCardinality="0"
MaxCardinality="0"/>
</ViewCriteriaItem>
<ViewCriteriaItem
Name="IsSystem"
ViewAttribute="IsSystem"
Operator="="
Conjunction="AND"
Required="Optional"/>
<ViewCriteriaItem
Name="RuleType"
ViewAttribute="RuleType"
Operator="="
Conjunction="AND"
Required="Optional"/>
<ViewCriteriaItem
Name="TargetType"
ViewAttribute="TargetType"
Operator="="
Conjunction="AND"
Required="Optional"
Value=":targetType"
IsBindVarValue="true"/>
<ViewCriteriaItem
Name="KeywordsTransient"
ViewAttribute="*KeywordsTransient*"
Operator="CONTAINS"
Conjunction="AND"
Required="Optional"
UpperColumns="0"/>
</ViewCriteriaRow>
</ViewCriteria>
The performance hit is when i search for attribute: KeywordsTransient.
The attribute is as :
<ViewAttribute
Name="KeywordsTransient"
IsSelected="false"
IsPersistent="false"
PrecisionRule="true"
Type="java.lang.String"
ColumnType="VARCHAR2"
AliasName="VIEW_ATTR"
SQLType="VARCHAR">
<RecalcCondition><![CDATA[return (adf.object.isAttributeChanged("Keywords")]]></RecalcCondition>
<TransientExpression><![CDATA[object.Keywords]]></TransientExpression>
<Dependencies>
<Item
Value="Keywords"/>
</Dependencies>
<Properties>
<SchemaBasedProperties>
<LABEL
ResId="KEYWORDS"/>
</SchemaBasedProperties>
</Properties>
</ViewAttribute>
This attribute is dependent on Keywords attribute of the VO , The keyword getter is as below:
* Gets the attribute value for the calculated attribute Keywords.
* @return the Keywords
public String getKeywords() {
if (((String) getAttributeInternal(KEYWORDS)) == null)
long startTime = System.currentTimeMillis();
String keyword = "";
CSRUtil csrUtil = new CSRUtil();
// get the keyword name list from RuleKeywordTableVO which stores ruleGuid to KeywordName mapping. This VO is Loaded in memory as soon as bean initailizes.
Set<String> keywordList =
csrUtil.getRuleKeywordListFromKeywordMapVO(getRuleGuid());
if (keywordList != null)
Iterator rowIter = keywordList.iterator();
while (rowIter.hasNext())
keyword =
keyword.concat(csrUtil.getKeywordNlsIdFromTable((String) rowIter.next())) +
if (keyword.endsWith(", "))
keyword = keyword.substring(0, keyword.length() - 2);
setKeywords(keyword);
setKeywordsTransient(keyword);
long endTime = System.currentTimeMillis();
logger.severe("Time taken for this rule in millis : "+ (endTime-startTime));
return (String) getAttributeInternal(KEYWORDS);
This getter is creating keyword list using nlsid translation based on other tables data for a rule.
Also, I have loaded the rule vo data in memory using invokeAction on my page as below:
<invokeAction id="ExecuteRuleInvoke" Binds="ExecuteRULE"
Refresh="renderModel" RefreshCondition="#{sdk_core_uifwk_refresh_ctrl.executeNeeded}"/>
<action IterBinding="RuleLibraryVO1Iterator" id="ExecuteRULE"
InstanceName="ComplianceLibraryAMDataControl.RuleLibraryVO1"
DataControl="ComplianceLibraryAMDataControl"
RequiresUpdateModel="true" Action="iteratorExecute"/>
So now when i search for a keywordTransient attribute using query panel the getter is always called for keywords even if the VO data is in memory.
So what am i missing, is the data loaded by invokeAction not visible to the query, or i have to use some other optimization. -
Need help in optimising the performance of a query
Need help in optimising the performance of a query. Below is the query that is executed on TABLE_A, TABLE_B and TABLE_C with record counts as 10M, 10m and 42 (only) respectively and it takes around 5-7 minutes to get 40 records:
SELECT DISTINCT a.T_ID_, a.FIRSTNAME, b.T_CODE, b.PRODUCT,
CASE WHEN TRUNC(b.DATE) +90 = TRUNC(SYSDATE) THEN -90 WHEN TRUNC(b.DATE) +30 = TRUNC(SYSDATE) THEN -30 ELSE 0 END AS T_DATE FROM TABLE_B b
INNER JOIN TABLE_A a ON (a.T_ID_ = b.T_ID_) LEFT JOIN TABLE_C c ON b.PRODUCT = c.PRODUCT
WHERE b.STATUS = 'T' AND (b.TYPE = 'ACTION'
AND ( TRUNC(b.DATE) + 1 = TRUNC(SYSDATE) ) ) AND b.PRODUCT = 2;
Note: Indices on the join columns are available in the respective tables
Please let me know if there is any better way to write it.
Edited by: 862944 on Aug 18, 2011 9:52 AM862944 wrote:
Need help in optimising the performance of a query. Below is the query that is executed on TABLE_A, TABLE_B and TABLE_C with record counts as 10M, 10m and 42 (only) respectively and it takes around 5-7 minutes to get 40 records:
SELECT DISTINCT a.T_ID_, a.FIRSTNAME, b.T_CODE, b.PRODUCT,
CASE WHEN TRUNC(b.DATE) +90 = TRUNC(SYSDATE) THEN -90 WHEN TRUNC(b.DATE) +30 = TRUNC(SYSDATE) THEN -30 ELSE 0 END AS T_DATE FROM TABLE_B b
INNER JOIN TABLE_A a ON (a.T_ID_ = b.T_ID_) LEFT JOIN TABLE_C c ON b.PRODUCT = c.PRODUCT
WHERE b.STATUS = 'T' AND (b.TYPE = 'ACTION'
AND ( TRUNC(b.DATE) + 1 = TRUNC(SYSDATE) ) ) AND b.PRODUCT = 2;
Note: Indices on the join columns are available in the respective tables
Please let me know if there is any better way to write it.
Edited by: 862944 on Aug 18, 2011 9:52 AM[When Your Query Takes Too Long|https://forums.oracle.com/forums/thread.jspa?messageID=1812597] -
Imporving the performance of a query
Hi,
I have the following query in Oracle:
SELECT distinct VECTOR_ID FROM SUMMARY_VECTOR where CASE_NAME like 'BASECASE_112_ECLIPSE100'
"SUMMARY_VECTOR" contains approximately 120 million records or tuples. So the total time for this query is about 62 seconds
I want to improve the performance of this query. How can I achieve this ?
any hint ?
ThanksPLAN_TABLE_OUTPUT
Plan hash value: 3042243244
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
PLAN_TABLE_OUTPUT
| 0 | SELECT STATEMENT | | 1 | 29 | 182K (3)| 00:36
:28 |
| 1 | SORT AGGREGATE | | 1 | 29 | |
|
|* 2 | TABLE ACCESS FULL| SUMMARY_VECTOR | 4323K| 119M| 182K (3)| 00:36
:28 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
2 - filter("CASE_NAME"='BASECASE_112_ECLIPSE100')
14 rows selected. -
Some diffrence in oracle query and mysql query
sir i see both query in SessionBean1
mysql query
SELECT ALL usert.username,
usert.userid,
usert.camid FROM usert
this not use user name
oracle query
SELECT ALL MFA.LUSER.USERID,
MFA.LUSER.TITLE,
MFA.LUSER.CAMPID,
MFA.LUSER.PWD,
MFA.LUSER.USERNAME
FROM MFA.LUSER
the user name mfa is use in this query you can see
this is main diffrence
but i yse both in code but not get result
try {
RowKey userRowKey = luserDataProvider.findFirst
(new String[] { "MFA.LUSER.USERNAME" },
new Object[] { textField4.getText()});
if (userRowKey == null) {
textField3.setText("11111");
return null;
} else {
textField3.setText("22222");
return null;
catch (Exception e) {
log("Cannot perform login for userid " + textField3.getText(), e);
error("Cannot perform login for userid " + textField3.getText() + ": " + e);
textField3.setText("77777");
return null;
problem in only oracle not in mysql
please give me idea how i get result
thank youcan you post your query with explain plan for both 9i version and 10g version.
Thanks,
karthick. -
Query on using Variables in Oracle Query
Hi
i am new to Oracle, i have tried extracting data from the Oracle Database using the following Query which includes 1 variable SYSDATE_UTS, however when i try to execute the Query i get an error. Please let me know what am i doing wrong and how can i correct it.
Error Message
ORA-06550: line 4, column 1:
PLS-00428: an INTO clause is expected in this SELECT statement
Oracle Query
DECLARE SYSDATE_UTS NUMBER := (sysdate-to_date('19700101','yyyymmdd'))*86400;
BEGIN
SELECT
INCIDENT_NUMBER,
to_date(to_char((1/86400*REPORTED_DATE)+to_date('19700101','yyyymmdd'),'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as REPORTED_DATE_TIME,
,GROUP_TRANSFERS
,LAST_MODIFIED_BY
,to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * LAST_MODIFIED_DATE,'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as LAST_MODIFIED_DATE
,(to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) as AGE
,CASE
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 0 AND 1 THEN '0-1 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS, 'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 2 AND 4 THEN '2-4 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 5 AND 9 THEN '5-9 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 10 AND 19 THEN '10-19 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) >20 THEN '20+ Days'
ELSE 'UNKNOWN'
END AS AGE_GROUP
FROM IncidentDataBase
and STATUS not in (4,5,6)
and rownum <10;
END;Hi Frank
i am using the following Oracle Version
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
CORE 10.2.0.5.0 Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
and Quest Toad for Oracle to write and execute the queries:
Toad for Oracle Xpert
Version 10.1.1.8
The code i am using is:
variable SYSDATE_UTS NUMBER;
exec SYSDATE_UTS := (sysdate-to_date('19700101','yyyymmdd'))*86400;
SELECT
INCIDENT_NUMBER,
to_date(to_char((1/86400*REPORTED_DATE)+to_date('19700101','yyyymmdd'),'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as REPORTED_DATE_TIME
,GROUP_TRANSFERS
,LAST_MODIFIED_BY
,to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * LAST_MODIFIED_DATE,'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss') as LAST_MODIFIED_DATE
,(to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) as AGE
,CASE
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 0 AND 1 THEN '0-1 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS, 'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 2 AND 4 THEN '2-4 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 5 AND 9 THEN '5-9 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) BETWEEN 10 AND 19 THEN '10-19 Days'
WHEN (to_date(to_char(to_date('01011970','ddmmyyyy')+1/24/60/60 * :SYSDATE_UTS,'mm/dd/yyyy'),'mm/dd/yyyy')) - (to_date(to_char(+to_date('19700101','yyyymmdd')+1/86400*REPORTED_DATE,'mm/dd/yyyy'),'mm/dd/yyyy')) >20 THEN '20+ Days'
ELSE 'UNKNOWN'
END AS AGE_GROUP
FROM IncidentDataBase
WHERE STATUS not in (4,5,6)
and rownum <10;
Notes:
1. When i put the cursor before "variable" (starting of the query) and execute the script i get an Error: ORA-00900: invalid SQL statement.
2. When i put the cursor just before "SELECT" i get a pop up.
a. it is a Toad window which displays the available variables (in this case :SYSDATE_UTS).
b. gives me a dropdown option to select the type (by default VARCHAR2 is selected).
c. there is a value field where i need to enter the value for the Variable.
d. the SQL statement shown in this dilog box does not include the 1st 2 lines
variable SYSDATE_UTS NUMBER;
exec SYSDATE_UTS := (sysdate-to_date('19700101','yyyymmdd'))*86400;
Q: is there something wrong in the syntax i am using?
Sven W. - I have been using your method all these days, which works just fine. i wanted to know how i could use a variable instead.
Business Requirement - My whole intent is to calculate the Age of an incident (Difference between "Reported Date" and current date) and to assign Age Groups (0-1 Days, 2-4 Days,....,20+ Days).
Edited by: 921713 on Mar 19, 2012 12:23 PM -
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.8.0 - Production
Report Builder 10.1.2.0.2
ORACLE Server Release 10.1.0.4.2
Oracle Procedure Builder 10.1.2.0.2
Oracle ORACLE PL/SQL V10.1.0.4.2 - Production
Oracle CORE 10.1.0.4.0 Production
Oracle Tools Integration Services 10.1.2.0.2
Oracle Tools Common Area 10.1.2.0.2
Oracle Toolkit 2 for Windows 32-bit platforms 10.1.2.0.2
Resource Object Store 10.1.2.0.2
Oracle Help 10.1.2.0.2
Oracle Sqlmgr 10.1.2.0.2
Oracle Query Builder 10.1.2.0.2 - Production
PL/SQL Editor (c) WinMain Software (www.winmain.com), v1.0 (Production)
Oracle ZRC 10.1.2.0.2
Oracle XML Developers Kit 10.1.0.4.2 - Production
Oracle Virtual Graphics System 10.1.2.0.2
Oracle Image 10.1.2.0.2
Oracle Multimedia Widget 10.1.2.0.2
Oracle Tools GUI Utilities 10.1.2.0.2
I have enclosed sample data and also table structure. I need help in getting the query.
select dept_id,proc_code,override_goal,goal_override_date
from table2
where goal_override_date between '02-jan-2014' and '11-jan-2014'
and dept_id = 10
and proc_code = 'CP'
select DEPT_ID, PROC_CODE, DAY_SUNDAY, DAY_MONDAY,
DAY_TUESDAY, DAY_WEDNESDAY, DAY_THURSDAY,
DAY_FRIDAY, DAY_SATURDAY
from table1
where dept_id =10
and proc_code = 'CP';
Table1 is kind of maintenance table.
In Table2 values can be overridden.
Requirement
Check to see if there is data in table 2 for the date range . If table2 has no value then take value from table1 for that day the date falls into. Any more clarification please ask me.
Sundays are all zeros.
I want this data. and the sum for the date range.
2-jan-2014 - 3
3-jan-2014 - 3
4-jan-2014 - 3
5-jan-2014 - 0
6-jan-2014 - 1
7-jan-2014 - 3
8-jan-2014 - 5
9-jan-2014 - 5
10-jan-2014 - 3
11-jan-2014 - 3
Sum for the date range has to be 29
Sample table and data
CREATE TABLE TABLE1
DEPT_ID NUMBER NOT NULL,
PROC_CODE VARCHAR2(2 BYTE) NOT NULL,
DAY_SUNDAY NUMBER(4) NOT NULL,
DAY_MONDAY NUMBER(4) NOT NULL,
DAY_TUESDAY NUMBER(4) NOT NULL,
DAY_WEDNESDAY NUMBER(4) NOT NULL,
DAY_THURSDAY NUMBER(4) NOT NULL,
DAY_FRIDAY NUMBER(4) NOT NULL,
DAY_SATURDAY NUMBER(4) NOT NULL
Insert into TABLE1
(DEPT_ID, PROC_CODE, DAY_SUNDAY, DAY_MONDAY, DAY_TUESDAY,
DAY_WEDNESDAY, DAY_THURSDAY, DAY_FRIDAY, DAY_SATURDAY)
Values
(10, 'CP', 0, 3, 3,
3, 3, 3, 3);
COMMIT;
CREATE TABLE TABLE2
DEPT_ID NUMBER NOT NULL,
PROC_CODE VARCHAR2(2 BYTE) NOT NULL,
OVERRIDE_GOAL NUMBER(4),
GOAL_OVERRIDE_DATE DATE NOT NULL
Insert into TABLE2
(DEPT_ID, PROC_CODE, OVERRIDE_GOAL, GOAL_OVERRIDE_DATE)
Values
(10, 'CP', 1, TO_DATE('01/06/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TABLE2
(DEPT_ID, PROC_CODE, OVERRIDE_GOAL, GOAL_OVERRIDE_DATE)
Values
(10, 'CP', 3, TO_DATE('01/07/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TABLE2
(DEPT_ID, PROC_CODE, OVERRIDE_GOAL, GOAL_OVERRIDE_DATE)
Values
(10, 'CP', 5, TO_DATE('01/08/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TABLE2
(DEPT_ID, PROC_CODE, OVERRIDE_GOAL, GOAL_OVERRIDE_DATE)
Values
(10, 'CP', 5, TO_DATE('01/09/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TABLE2
(DEPT_ID, PROC_CODE, OVERRIDE_GOAL, GOAL_OVERRIDE_DATE)
Values
(10, 'CP', 3, TO_DATE('01/10/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
Insert into TABLE2
(DEPT_ID, PROC_CODE, OVERRIDE_GOAL, GOAL_OVERRIDE_DATE)
Values
(10, 'CP', 3, TO_DATE('01/11/2014 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
COMMIT;
Help is highly appreciated.SELECT dates,
override_goal,
SUM(override_goal) OVER()
FROM(SELECT dates,
CASE WHEN EXISTS(SELECT 1
FROM table2 t2
WHERE t2.goal_override_date = qry1.dates
AND t2.dept_id = 10
AND t2.proc_code = 'CP')
THEN (SELECT override_goal
FROM table2 t2
WHERE t2.goal_override_date = qry1.dates
AND t2.dept_id = 10
AND t2.proc_code = 'CP')
ELSE (SELECT DECODE(days,'SUN',day_sunday,
'MON',day_monday,
'TUE',day_tuesday,
'WED',day_wednesday,
'THU',day_thursday,
'FRI',day_friday,
'SAT',day_saturday )
FROM table1)
END as override_goal
FROM (SELECT in_dt1+(LEVEL-1) dates,
TO_CHAR(in_dt1+(LEVEL-1),'DY') days
FROM(SELECT TO_DATE(&from_date,'DD-MON-YYYY') in_dt1,
TO_DATE(&to_date,'DD-MON-YYYY') in_dt2
FROM dual)
CONNECT BY LEVEL <= (in_dt2 - in_dt1)+1) qry1);
Now run the query it will prompt you for the inputs. You can pass the date values and check the result. Otherwise replace &from_date,&to_date with user inputs -
How to enforce index in oracle query
Hi all
how to enforce index in oracle query
RegardsUse INDEX hint to force Optimizer to use the specfied index.
You really need to investigate why Optimizer doesn't choose the index. Remember, INDEX SCAN are not always GOOD.
Jaffar -
Performance of my query based on cube ? and ods?
hi all,
how to identify the performance of my query based on a cube nor ods. I have requirement which enables to do flat file extraction and the extraction is only once and the records are less too. I need to sort whether my query will be faster based upon cube nor on ods.
Can anyone let me know how to measure the performance of my query based upon cube and ods and how to find out which one will be faster. bcos i need to explain them the entire process of going to load the data directly to ods and do reporting from there nor data loaded directly to cube and do reporting from cube.
thanxs
harithaHi,
ODS is 2 Dimensional so avoid reporting on ODS,
Cube is MultiDim, for analysis perpose we can go reporting on Cube only
Records in ODS are Overwritten whereas in Cube records are Aggregated
and can also do compression on Cube, which will increase the query performance and so data retrieval in cube is faster
Thanks -
How to improve the performance of the query
Hi,
Help me by giving tips how to improve the performance of the query. Can I post the query?
SureshBelow is the formatted query and no wonder it is taking lot of time. Will give you a list of issues soon after analyzing more. Till then understand the pitfalls yourself from this formatted query.
SELECT rt.awb_number,
ar.activity_id as task_id,
t.assignee_org_unit_id,
t.task_type_code,
ar.request_id
FROM activity_task ar,
request_task rt,
task t
WHERE ar.activity_id =t.task_id
AND ar.request_id = rt.request_id
AND ar.complete_status != 'act.stat.closed'
AND t.assignee_org_unit_id in (SELECT org_unit_id
FROM org_unit
WHERE org_unit_id in (SELECT oo.org_unit_id
FROM org_unit oo
WHERE oo.org_unit_id='3'
OR oo.parent_id ='3'
OR parent_id in (SELECT oo.org_unit_id
FROM org_unit oo
WHERE oo.org_unit_id='3'
OR oo.parent_id ='3'
AND has_queue=1
AND ar.parent_task_id not in (SELECT tt.task_id
FROM task tt
WHERE tt.assignee_org_unit_id in (SELECT org_unit_id
FROM org_unit
WHERE org_unit_id in (SELECT oo.org_unit_id
FROM org_unit oo
WHERE oo.org_unit_id='3'
OR oo.parent_id ='3'
OR parent_id in (SELECT oo.org_unit_id
FROM org_unit oo
WHERE oo.org_unit_id='3'
OR oo.parent_id ='3'
AND has_queue=1
AND rt.awb_number is not null
ORDER BY rt.awb_numberCheers
Sarma. -
HI All, How to improve the performance in given query?
HI All,
How to improve the performance in given query?
Query is..
PARAMETERS : p_vbeln type lips-vbeln.
DATA : par_charg TYPE LIPS-CHARG,
par_werks TYPE LIPS-WERKS,
PAR_MBLNR TYPE MSEG-MBLNR .
SELECT SINGLE charg
werks
INTO (par_charg, par_werks)
FROM lips
WHERE vbeln = p_vbeln.
IF par_charg IS NOT INITIAL.
SELECT single max( mblnr )
INTO par_mblnr
FROM mseg
WHERE bwart EQ '101'
AND werks EQ par_werks (index on werks only)
AND charg EQ par_charg.
ENDIF.
Regards
SteveHi steve,
Can't you use the material in your query (and not only the batch)?
I am assuming your system has an index MSEG~M by MANDT + MATNR + WERKS (+ other fields). Depending on your system (how many different materials you have), this will probably speed up the query considerably.
Anyway, in our system we ended up by creating an index by CHARG, but leave as a last option, only if selecting by matnr and werks is not good enough for your scenario.
Hope this helps,
Rui Dantas
Maybe you are looking for
-
How do I get Apple TV to play on my Macbook Pro?
I just bought a Macbool Pro and Apple TV to use as entertainment while out of town for work, but I can't get it to play on my computer. It plays fine on my TV, but when I plug the hdmi cable into my Macbook, nothing happens. How do I get this to work
-
Hi, I have two questions: 1> If reporting is done on an ODS then which table of ODS is used to get data? I guess data is retrived from "ACTIVE" table. 2> If ODS is used as an infosource then for updating takes place from which table? I think it is "C
-
Creating a scheduled task to sync phone's using PC...
I have two NOKIA (bluetooth) Phones and want to create a scheduled task to synchronise their agenda to outlook without user involvment. Using PCSync2 and some batch file I can get the synchronisation to work. One problem however remains. When both te
-
Help If anybody can try this and tell me how it works I would be forever grateful. I can not seem to get the FIND command to find timecodes of clips in a sequence. I have copied all my clips from my bin and pasted them into a new sequence I'll name s
-
Dell Vostro 1310 does not suspend/hibernate
I can't make my laptop suspend or hibernate. I read the pm utils wiki page and I don't understand what I have to do to make it work I want the machine to suspend to RAM when I close my lid... please help!