Improving query which is using IN clause
Hi,
I am currently using a query which has IN (1.2.3....N) clause in where condition.
The table has more than 100000 records in it. I have a set of 20 values which I pass inside this IN clause.
The column which is used for IN clause is indexed.
Can I use anything other than IN clause for this purpose?
What is better way?
Thanks,
Plad
> Can I use anything other than IN clause for this purpose? > What is better way?
Sure you could use something else, but the IN clause would perfectly suit your needs. And the one who has to maintain the code after you are gone, will be glad you used IN, because it is as clear as you can get.
If you are hinting at the fact that the query is too slow, then please read [url http://forums.oracle.com/forums/thread.jspa?threadID=501834&tstart=0]this thread and try to find out how many rows out of the 100K satisfy your IN predicate.
Regards,
Rob.
Similar Messages
-
Is there any way to improve Query which searches XML data from a table??
hi all,
i have a table which have one column say 'colA' as Varchar(max) datatype which i save xml data and it have other cols too
Currently i am searching data inside this table using like operator
eg:
Select * from tablename where colA like ‘%<tagname>parameterstringvalue</tagname>%’
when i check with the Execution plan i could see it Takes 82% for clusterd index scan ( primarykey col
not ColA)
i added new non clusterd index for the same with include col as ColA and i found nonclusterd index scan
with same estimated I O cost and Extimated operator cost as clusterd index scan
My Question is :-
1. why didnt nonclusterd index seek come?
2. In What way i can improve perfomance for such situvation? i had seen couple of post suggesting to rewrite the Query as SELECT
* FROM myTable WHERE CONTAINS (myCol1, myCol2, "myString").
I Try creating Full text index and found cost increased compared to the original Query ?
3. As per my assumption the wild charecter ('%') in begining makes perfomance issue is there any option
or an alternative for such case?hi...i can give a skeleton
--Table Structure------------
Table1:-
(colA - int(PK),
ColB - Varchar(max),
ColC-uniquieidentifier,
ColD-datetime,
ColE-Bit)
It have clusterd index for ColA
Table2:-
(ColA-int(fk)
colF-int(pk)
colG-varchar(max),
ColH-uniqueidentifier,
colI-int,
colJ-int
ColK-date)
-----------------Query Skeleton-------------------:
select Distinct
s.colA,
s.ColB,
S.colC,
S.colD
from Table1 s with (nolock)
left outer join table2 Q with (nolock) on s.colA=q.ColA
where Q.ColA is null
and s.colB like '%<tag>sometext</tag>%'
and s.colD >='1/1/2010'
and s.colD <='1/1/2014'
i hope this will help to understand it clearly......... -
Hi Guys,
I am using DB2 database in SSRS. I have to pass Single Value and Multi Value Parameters. I tried with Select * From DB2Table Where
Column=@PRM_Name Or Select * From DB2Table Where
Column=:PRM_Name . It is not working and throwing error. Please help me out.
Connection Details: ODBC
Thanks Shiven:)Hi SKM,
So you mean to say that Go to DataSource->Add Dataset-> Query Type-Text-> Under Query:
click on fx (Expression)-> Write this expression
For Single Value Parameter:
="SELECT customer_name, telephone_number, address1, address2, city from MyTable
WHERE city = '" + Parameters!City.Value + "'"
OR
="SELECT customer_name, telephone_number, address1, address2, city from MyTable
WHERE city = '" & Parameters!City.Value & "'"
Keep it in mind if Parameter is String then
It should be in Single quote ''.
Like
="SELECT customer_name, telephone_number, address1, address2, city from MyTable WHERE city
='Hyderabad' "
For Multivalu Parameter:
="SELECT EmployeeID, FirstName, LastName, LoginID FROM SHIVEN.AUDIT Where FirstName
in ('" + REPLACE(JOIN(Parameters!City.Value,","),",","','") + "')"
NOTE:
If your Parameter is Single Value Parameter and You want to enter string values with Coma (,)
separated (Like Hyderabad, Chennai, Delhi).
In this case, you have to use below expression.
="SELECT customer_name, telephone_number, address1, address2, city from MyTable
WHERE city IN ('" + REPLACE(Parameters!City.Value ,",","','") + "')"
OR
="SELECT customer_name, telephone_number, address1, address2, city from MyTable
WHERE city IN ('" & REPLACE(Parameters!City.Value ,",","','") & "')"
In above expression: Replace will replace all , with ‘,’ and city IN (‘Hyderabad’, ‘Chennai’,
‘Delhi’) will not throw any error.
Note: You have to write expression in one line in Expression editor for dataset
query
Thanks It is working fine but it is tough job if query is big.
Hi S kumar,
The above approach we use when we have source like DB2, becasue DB2 has some syntactical differences to pass multivalue paramaeter. I tested and it works good, if i am mentioning the query in above format by using Fx button while creating dataset.
but if we want fetch data from view which exist in DB2 and we need to call db2 view in SSRS and pass multivalue parameter in a way we did above then could you please mention the steps and way to achieve this.
Thanks in advance! -
Query in jdeveloper using distinct clause
hello
I am a user of oracle10G jdeveloper using jclient/swing
in my product.
I had written a query in my default view object as
Select distinct(Name) from emp then i test it.
Then message get displayed Query is valid.
But when i bind this view object with my form ie with combobox using model property and finally run the form then it throw an error message .
Please do help me to sort out this problem .
thanksPlease post the error message and the exception stack.
My guess is that the error is: your VO's SQL statement did not include the primary key attribute (say Empno).
Thanks.
Sung -
Tuning query which is using joins.....
Hello ,
i have a following query and want to use bind variable .
so can you please assist me on that ???
SELECT aq.a, aq.b, COUNT(aa.c) AS qcount
FROM USER.TQ aq, USER.TGI agi,USER.TA aa
WHERE aa.d = aq.e
AND aq.f = 'Up'
AND agi.g = 'Tel'
AND aq.h = 'Tel'
AND aa.j = agi.k
AND aq.l = aa.m
AND TRUNC(agi.n(+)) BETWEEN TO_DATE('1/17/2006','MM/DD/YYYY') AND TO_DATE('4/3/2008','MM/DD/YYYY')
AND aa.x = 'No' AND y <> '0'
GROUP BY aq.a, aq.b
ORDER BY aq.a
thanks in advance...so can you please assist me on that ???What's your problem: replacing literals with bind variables or passing values to bind variables at runtime? How are you going to run this query? SQL*Plus? PL/SQL? some other front end?
Cheers, APC
Blog : http://radiofreetooting.blogspot.com/ -
How to use in clause with variable elements with a prepared statement?
Is there any way to use a prepared statement for a query which incorporates an in clause with unknown number of elements in the list?
null<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Iraj ():
Is there any way to use a prepared statement for a query which incorporates an in clause with unknown number of elements in the list?<HR></BLOCKQUOTE>
Sorry, can't be done. The PreparedStatement is precomplied, so you can't have variable number of params or unknown number of elements in a list. -
How to improve query performance using infoset
I create one infoset that including 4 char.and 3 DSO which all are time-dependent.When query run, system show very poor perfomance, sometimes no data show in BEX anayzer. In this case I have to close BEX analyzer at first and then open it again, after that it show real results. It seems very strange. Does anybody has experience on infoset performance improvement. pls info, thanks!
Hi
As info set itself doesn't have any data so it improves Performance
also go through the below tips.
Find the query Run-time
where to find the query Run-time ?
557870 'FAQ BW Query Performance'
130696 - Performance trace in BW
This info may be helpful.
General tips
Using aggregates and compression.
Using less and complex cell definitions if possible.
1. Avoid using too many nav. attr
2. Avoid RKF and CKF
3. Many chars in row.
By using T-codes ST03 or ST03N
Go to transaction ST03 > switch to expert mode > from left side menu > and there in system load history and distribution for a particular day > check query execution time.
Statistical Records Part 4: How to read ST03N datasets from DB in NW2004
How to read ST03N datasets from DB
Try table rsddstats to get the statistics
Using cache memory will decrease the loading time of the report.
Run reporting agent at night and sending results to email. This will ensure use of OLAP cache. So later report execution will retrieve the result faster from the OLAP cache.
Also try
1. Use different parameters in ST03 to see the two important parameters aggregation ratio and records transferred to F/E to DB selected.
2. Use the program SAP_INFOCUBE_DESIGNS (Performance of BW infocubes) to see the aggregation ratio for the cube. If the cube does not appear in the list of this report, try to run RSRV checks on the cube and aggregates.
Go to SE38 > Run the program SAP_INFOCUBE_DESIGNS
It will shown dimension Vs Fact tables Size in percent.If you mean speed of queries on a cube as performance metric of cube,measure query runtime.
3. To check the performance of the aggregates,see the columns valuation and usage in aggregates.
Open the Aggregates...and observe VALUATION and USAGE columns.
"---" sign is the valuation of the aggregate. You can say -3 is the valuation of the aggregate design and usage. ++ means that its compression is good and access is also more (in effect, performance is good). If you check its compression ratio, it must be good. -- means the compression ratio is not so good and access is also not so good (performance is not so good).The more is the positives...more is useful the aggregate and more it satisfies the number of queries. The greater the number of minus signs, the worse the evaluation of the aggregate. The larger the number of plus signs, the better the evaluation of the aggregate.
if "-----" then it means it just an overhead. Aggregate can potentially be deleted and "+++++" means Aggregate is potentially very useful.
In valuation column,if there are more positive sign it means that the aggregate performance is good and it is useful to have this aggregate.But if it has more negative sign it means we need not better use that aggregate.
In usage column,we will come to know how far the aggregate has been used in query.
Thus we can check the performance of the aggregate.
Refer.
http://help.sap.com/saphelp_nw70/helpdata/en/b8/23813b310c4a0ee10000000a114084/content.htm
http://help.sap.com/saphelp_nw70/helpdata/en/60/f0fb411e255f24e10000000a1550b0/frameset.htm
performance ISSUE related to AGGREGATE
Note 356732 - Performance Tuning for Queries with Aggregates
Note 166433 - Options for finding aggregates (find optimal aggregates for an InfoCube)
4. Run your query in RSRT and run the query in the debug mode. Select "Display Aggregates Found" and "Do not use cache" in the debug mode. This will tell you if it hit any aggregates while running. If it does not show any aggregates, you might want to redesign your aggregates for the query.
Also your query performance can depend upon criteria and since you have given selection only on one infoprovider...just check if you are selecting huge amount of data in the report
Check for the query read mode in RSRT.(whether its A,X or H)..advisable read mode is X.
5. In BI 7 statistics need to be activated for ST03 and BI admin cockpit to work.
By implementing BW Statistics Business Content - you need to install, feed data and through ready made reports which for analysis.
http://help.sap.com/saphelp_nw70/helpdata/en/26/4bc0417951d117e10000000a155106/frameset.htm
/people/vikash.agrawal/blog/2006/04/17/query-performance-150-is-aggregates-the-way-out-for-me
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/1955ba90-0201-0010-d3aa-8b2a4ef6bbb2
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/ce7fb368-0601-0010-64ba-fadc985a1f94
http://help.sap.com/saphelp_nw04/helpdata/en/c1/0dbf65e04311d286d6006008b32e84/frameset.htm
You can go to T-Code DB20 which gives you all the performance related information like
Partitions
Databases
Schemas
Buffer Pools
Tablespaces etc
use tool RSDDK_CHECK_AGGREGATE in se38 to check for the corrupt aggregates
If aggregates contain incorrect data, you must regenerate them.
202469 - Using aggregate check tool
Note 646402 - Programs for checking aggregates (as of BW 3.0B SP15)
You can find out whether an aggregate is usefull or useless you can find out through a proccess of checking the tables RSDDSTATAGGRDEF*
Run the query in RSRT with statistics execute and come back you will get STATUID... copy this and check in the table...
This gives you exactly which infoobjects it's hitting, if any one of the object is missing it's useless aggregate.
6
Check SE11 > table RSDDAGGRDIR . You can find the last callup in the table.
Generate Report in RSRT
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/cccad390-0201-0010-5093-fd9ec8157802
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/4c0ab590-0201-0010-bd9a-8332d8b4f09c
Business Intelligence Journal Improving Query Performance in Data Warehouses
http://www.tdwi.org/Publications/BIJournal/display.aspx?ID=7891
Achieving BI Query Performance Building Business Intelligence
http://www.dmreview.com/issues/20051001/1038109-1.html
Assign points if useful
Cheers
SM -
How to get the query result of improvement (Before and After ) using sql de
how to get the query result of improvement (Before and After ) using sql developer.
Check
http://www.oracle.com/technetwork/articles/sql/exploring-sql-developer-1637307.html -
Bex Query which uses Dynamic columns to display actuals
Hi Bex experts,
I have a query issue/question.
I currently have a Bex query which shows me the the planned values for each period, spanning 6 years into the future. My Key figure columns are defined as follows:
Value type = '020'
Version = mandatory variable, entered at execution.
Posting period (FISCPER3) = These columns are fixed values using periods 1 to 12 for each column.
Fiscal year (0FISCYEAR) = Each column contains SAP exit for current year, and using the offset +1, +2, +3, +4 etc, when I define the future years coulmns.
Currency = fixed 'USD'.
Fiscal year variant = fixed 'Z4'
The above works fine for plan data.
I want to now include is:
Seperate 'Dynamic columns' to show only actuals for period ranges from period one to the previous period (or current period minus 1). Each period should have it's own column for actuals.
The dynamic actuals columns should be grouped together to the left of the plan columns.
Actuals are only for current year, so I will still use the SAP EXIT for current year in the column definition.
Example: If I am currently in period 10, the query should show me actuals from period 1 to period 9 in seperate columns, then continue to show me my plan values columns that I have in place already.
How can I construct these actuals columns in to my existing query. If you have possible screens shots.
Thanks, and maximum points will be alotted.The way I have approached this you may not like as it involves quite a bit of coding
12 CKFs
each CKF adds up 2 RKFs
So 24 RKFs
example Column 6 CKF
Adds Column 6 RKF Actual and Column 6 RKF Plan
Column 6 RKF Actual contains Actual version + key figure + Period variable column 6 Actual
Column 6 RKF Plan contains Plan version + key figure + Period Variable column 6 Plan
Period variable column 6 Actual
is a cmod variable which reads the entered date
if the period of entered date is LE 6
then return period 6 into "Period variable column 6 Actual"
else put 0 into "Period variable column 6 Actual"
Period variable column 6 Plan
is a cmod variable which reads the entered date
if the period of entered date is LE 6
then return period 0 into "Period variable column 6 Plan"
else put 6 into "Period variable column 6 Plan"
Now what happens is that if you enter period 6 in your selection screen all the Actuals of columns greater than 6 all have period 0 put into their selection so return 0 and all the columns less than or equal to 6 return the values for the fiscal period (ie column 1 gets period 1)
And in addition all the Plans columns return the value of their column ie for their period for those greater than 6 and for those less than 6 they all return 0
It's convulted - but you get the idea - and yes it works
There may be a better way to do it - and I am open to suggestions
(this does assume that NOTHING is posted to period 0 otherwise it won't work) -
I am not able to run a SQL query using where clause.
the query is as follows:
I extract the text input by the user in a text field say 'a' and
store it in string 'y'.
String y= a.getText();
//running the query
Select A from B where B.x=y;
how do we run a where clause when y is a string variable instead of value?Use the following :
String y = a.getText();
String query ="select A.CODE from Port A where A.NAME=" + "'" + y + "'" ;
ResultSet rs= stmt.executeQuery(query); -
Performance hit using "where" clause in the query
Hi All,
I am facing a huge performance hit in the java code when using "where" clause in queries. Following are the details:
1. SELECT * FROM Employee
2. SELECT * FROM Employee where employeeid in (26,200,330,571,618,945)
There is no difference in Query Execution Time for both queries.
Business Logic Time is huge in second case as compared to first one (ratio - 1:20).
Rows returned are more in first case as compared to second case.(ratio - 1:4)
Business Logic is same for both the cases where I iterate through the ResultSet, get the objects and set them in a data structure.
Does anybody know the reason of unexpected time difference for the business logic in the second case?Since you're mentioning clustering your index, I'll assume you are using Oracle. Knowing what database you are using makes it a lot easier to suggest things.
Since you are using Oracle, you can get the database to tell you what execution plan it is using for each of the 2 SQL statements, and figure out why they have similar times (if they do).
First, you need to be able to run SQL*Plus; that comes as part of a standard database installation and as part of the Oracle client installation - getting it set up and running is outside the scope of this forum.
Second, you may need your DBA to enable autotracing, if it's not already:
http://asktom.oracle.com/~tkyte/article1/autotrace.html
http://www.samoratech.com/tips/swenableautotrace.htm
Once it's all set up, you can log in to your database using sql*plus, issue "SET AUTOTRACE ON", issue queries and get execution plan information back.
For example:
SQL> set autotrace on
SQL> select count(*) from it.ticket where ticket_number between 10 and 20;
COUNT(*)
11
Execution Plan
Plan hash value: 2983758974
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 4 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 4 | | |
|* 2 | INDEX RANGE SCAN| TICKET_N10 | 12 | 48 | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("TICKET_NUMBER">=10 AND "TICKET_NUMBER"<=20)
Statistics
0 recursive calls
0 db block gets
1 consistent gets
0 physical reads
0 redo size
515 bytes sent via SQL*Net to client
469 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> This tells me that this query used an INDEX RANGE SCAN on index TICKET_N1; the query can't do much better than that logically... In fact, the statistic "1 consistent gets" tells me that Oracle had to examine only one data block to get the answer, also can't do better than that. the statistic, "0 physical reads" tells me that the 1 data block used was already cached in Oracle's memory.
the above is from Oracle 10g; autotrace is available back to at least 8i, but they've been adding information to the output with each release.
If you have questions about sql_plus, check the forums at asktom.oracle.com or http://forums.oracle.com/forums/category.jspa?categoryID=18
since sql*plus is not a JDBC thing...
Oh, and sql*plus can also give you easier access to timing information, with "set timing on". -
How to query which Tcodes specified user used with one day?
Hi guys:
How to query which Tcodes specified user used with one day?Hi
You can use transaction code ST03N.
1. Go to tx code - ST03N
2. Under "Workload" you can select your "Instance or Total" so that it expands and shows you Days, Week, Month.
3. If you want to look at the transactions executed for a particular day, lets say, then double click on any day.
4. At the bottom left you get "Analysis Views"
5. Select & expand "User and Settlement Statistics"
6. Double click on "User Profile"
7. On the right side of the window you get a list of all the users
8. Double click on a particular user you want to view the details of.
9. The new screen will display the "Transactions/Reports Utilized by User XXX"
If you wanna track which users executed a particular transacation then follow this:
10. In "Analysis Views" expand "Transaction Profile"
11. Double click on "Standard"
You can view the list of Transactions and Reports.
12. Double click on the Tx Code or Report you wanna check and it will show the Use of it.
This will help you.
Regards
Sumit Jain
[reward with points if the answer is useful] -
Select Query where multiple column in multiple values (cant use in clause)
I can use (in clause) with on column like this:
Select code from table where code in(1,2,3)
-------------------------------My case:-------------------------------------------------
I’ve 4 columns PK of table as below
I need to :
select
where (code, month, year) in ((1,1,2013) and (2,1,2014) and (2,2,2015))
i can't write it this way :
select where code in (1,2) and month in (1,2) and year in (2013,2014,2015)
case i'll get my rows but others included like (1,1,2015) , (1,1,2014),(2,1,2013) .. etc
I’m terribly want to solve this problem
Please help me
Code (pk)
Month (pk)
Year (pk)
emp_code(pk)
1
1
2013
101
1
1
2013
102
2
1
2013
101
2
1
2013
102
1
2
2013
101
1
2
2013
102
2
2
2013
101
2
2
2013
102
1
1
2014
101
1
1
2014
102
2
1
2014
101
2
1
2014
102
1
2
2014
101
1
2
2014
102
2
2
2014
101
2
2
2014
102
1
1
2015
101
1
1
2015
102
2
1
2015
101
2
1
2015
102
1
2
2015
101
1
2
2015
102
2
2
2015
101
2
2
2015
102
thank youIn T-SQL you have to use OR-ed predicates.
In full ANSI Standard SQL youcan write row comparisons (a,b,c) = (1,2,3) etc! but not in T-SQL dialect. Ignoring that problem, what you have is a design flaw called attribute splitting; you have put one unit of measurement
in two columns.
I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the
ISO-8601 data format required by Standard SQL and it is language independent. The pattern for validation is '[12][0-9][0-9][0-9]-00-00' and '[12][0-9][0-9][0-9]-[01][0-9]-00'
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Construct a Sql block using With Clause to improve the performance
I have got four diff parametrized cursor in my Pl/Sql Procedure. As the performance of the Procedure is very pathetic,so i have been asked to tune the Select statements used in those cursors.
So I am trying to use the With Clause in order to club all those four Select Statements.
I would appreciate if anybody can help me to construct the Sql Block using With Clause.
My DB version is..
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
Four Diff cursors are defined below.
CURSOR all_iss (
b_batch_end_date IN TIMESTAMP,
IS
SELECT isb.*
FROM IMPLMN_STEP_BREKPN isb
, ISSUE iss
WHERE isb.issue_id = iss.issue_id
AND iss.issue_status_id = 50738
AND ewo_no IN
(SELECT TO_CHAR(wo_no)
FROM MGO_PLANT_AUDIT
WHERE dml_status = 'U' OR dml_status = 'I')
UNION ALL
SELECT isb.*
FROM IMPLMN_STEP_BREKPN isb
, ISSUE iss
WHERE isb.issue_id = iss.issue_id
AND iss.issue_status_id = 50738
AND CAST (isb.last_updt_timstm AS TIMESTAMP) >=
b_batch_end_date;
CURSOR ewo_plant ( p_ewo_no IN IMPLMN_STEP_BREKPN.ewo_no%TYPE)
IS
SELECT DISTINCT wo_no ,
plant_code
FROM MGO_PLANT
WHERE TO_CHAR(wo_no) = p_ewo_no;
CURSOR iss_ewo_plnt (
p_issue_id IN IMPLMN_STEP_BREKPN.issue_id%TYPE ,
p_ewo_no IN IMPLMN_STEP_BREKPN.EWO_NO%TYPE,
p_plnt_code IN IMPLMN_STEP_BREKPN.PLT_FACLTY_ID%TYPE)
IS
SELECT *
FROM IMPLMN_STEP_BREKPN
WHERE issue_id = p_issue_id
AND ewo_no = p_ewo_no
AND
(plt_faclty_id = p_plnt_code
OR
plt_faclty_id IS NULL);
CURSOR iss_ewo_plnt_count (
p_issue_id IN IMPLMN_STEP_BREKPN.issue_id%TYPE ,
p_ewo_no IN IMPLMN_STEP_BREKPN.EWO_NO%TYPE,
p_plnt_code IN IMPLMN_STEP_BREKPN.PLT_FACLTY_ID%TYPE)
IS
SELECT COUNT(*)
FROM IMPLMN_STEP_BREKPN
WHERE issue_id = p_issue_id
AND ewo_no = p_ewo_no
AND
(plt_faclty_id = p_plnt_code
OR
plt_faclty_id IS NULL);Not tested. Some thing like below. i just made the queries as tables and given name as a,b,c and substituted columns for the parameters used in the 2nd cursor and third cursor. Try like this.
CURSOR all_iss (
b_batch_end_date IN TIMESTAMP,
IS
select a.*,b.*,c.* from
( SELECT isb.*
FROM IMPLMN_STEP_BREKPN isb
, ISSUE iss
WHERE isb.issue_id = iss.issue_id
AND iss.issue_status_id = 50738
AND ewo_no IN
(SELECT TO_CHAR(wo_no)
FROM MGO_PLANT_AUDIT
WHERE dml_status = 'U' OR dml_status = 'I')
UNION ALL
SELECT isb.*
FROM IMPLMN_STEP_BREKPN isb
, ISSUE iss
WHERE isb.issue_id = iss.issue_id
AND iss.issue_status_id = 50738
AND CAST (isb.last_updt_timstm AS TIMESTAMP) >=
b_batch_end_date) a,
( SELECT DISTINCT wo_no ,
plant_code
FROM MGO_PLANT
WHERE TO_CHAR(wo_no) = p_ewo_no) b,
( SELECT *
FROM IMPLMN_STEP_BREKPN
WHERE issue_id = p_issue_id
AND ewo_no = p_ewo_no
plt_faclty_id IS NULL) c
where b.wo_no = c.ewo_no and
c.issue_id = a.issue_id ;
vinodh
Edited by: Vinodh2 on Jul 11, 2010 12:03 PM -
Problem in sql query because of order by clause
Hi All,
I am facing a one problem in my one sql query.I am using Oracle 10gR2.
Query is given below:
SELECT t1.ename
FROM T1, T2
WHERE T1.EMPNO = 1234
AND T1.ACCOUNTNO = T2.ACCOUNTNO
AND T1.SEQ = T2.SEQ
ORDER BY T2.SEQThe Plan of the query is :
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 2 | 218 | 11716 (1)| 00:00:41 |
|* 1 | TABLE ACCESS BY INDEX ROWID | T1 | 1 | 89 | 1 (0)| 00:00:01 |
| 2 | NESTED LOOPS | | 2 | 218 | 11716 (1)| 00:00:41 |
|* 3 | TABLE ACCESS BY INDEX ROWID| T2 | 2 | 40 | 11715 (1)| 00:00:41 |
| 4 | INDEX FULL SCAN | PK_T2_SEQ | 58752 | | 122 (5)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | FK_ACCOUNTNO | 3 | | 0 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------Now i want to reduce the time of this query.
If i am removing Order by clause from query than performance of the query is totally perfect but with order by clause its taking a time.
I have already set SORT_AREA_SIZE but still nothing is improving.
Welcome and thanks for your suggestions.
Thanks,
Edited by: BluShadow on 23-Jun-2011 07:55
added {noformat}{noformat} tags and formatted explain plan to make it readable. Please see {message:id=9360002} for details on how to post code and dataHi,
There are a couple of things I do not understand.
1. Why don't you put {noformat}{noformat} around your code, it makes it so much easier to read, especially your explain plan
2. You claim that the ORDER BY is problematic compared to no order by. Then why do you choose to post only one plan?
3. It is hard to understand how your tables relate, and which indexes you have and which you don't.
- PK_T2_SEQ, does this mean that SEQ alone is primary key of T2?
- If SEQ is primary key of T2, why do you join on accountno, seq and not just seq?
- If SEQ is primary key of T2 one of the tables is denormalized.
4. FK_ACCOUNTNO, is this an index on accountno, alone?
- Or is this AccountNo, Seq?
5. Is there no index on T1.EMPNO?
Above could of course just be a case of my not understanding the names of your indexes.
So, here are my guesses:
Above plan is for the ORDER BY query. That means the optimizer, has chosen to full scan PK_T2_SEQ, since data is then read according to the ORDER BY.
(This could be a bad choice)I
You could try and order by t1.seq, instead. Result should be the same.
Regards
Peter
Maybe you are looking for
-
ITunes won't run because of Quick Time issue
I can't get Quick Time to work, so I can use my ITunes. I have tried to reinstall. but it just gives me an error sending report. Any help, pleae.
-
Plug-in Error for Acrobat 6 Professional
Working with Vista on a 2.66Ghz laptop with GB memory. The application fails in one regard.. when navigating to URLs ending in "pdf" e.g. http://www.adobe.com/education/pdf/cib/acro6/acro6_cib_16.pdf the error message: Acrobat Plug-in... could not fi
-
Hi, Can any body please share some knowledge about how to create an Integration Process in Integration Repository. Any help would be appriciable. Thanks, Kulwant Singh
-
Inspector window doesn't appear
I suddenly find that the inspector window won't appear. Media, color & fonts windows are fine. Quitting Keynote, and restarting haven't helped.
-
Invalid month error in WEBI report level
Hi, I had a issue with date format.I am using oracle10g as a backend database.I have a date object in universe level i used that object in web intelligence report level.I created prompt for date object after select the date from the list i am getti