Execution time of query on different indexes
Hello,
I have a query on the table, the execution time has hugh difference using different indexes on the table. The table has about 200,000 rows. Any explaination on it?
Thanks,
create table TB_test
( A1 number(9),
A2 number(9)
select count(*) from TB_test
where A1=123 and A2=456;
A. With index IDX_test on column A1:
Create index IDX_test on TB_test(A1);
Explain plan:
SELECT STATEMENT
Cost: 3,100
SORT AGGREGATE
Bytes: 38 Cardinality: 1
TABLE ACCESS BY INDEX ROWID TABLE TB_test
Cost: 3,100 Bytes: 36 Cardinality: 1
INDEX RANGE SCAN INDEX IDX_test
Cost: 40 Cardinality: 21,271
Execution time is : 5 Minutes
B. With index IDX_test on column A1 and A2:
Create index IDX_test on TB_test(A1, A2);
Explain plan:
SELECT STATMENT
Cost: 3 Bytes: 37 Cardinality: 1
SORT AGGREGATE
Bytes: 37 Cardinality: 1
INDEX RANGE SCAN INDEZ IDX_test
Cost: 3 Bytes 37 Cardinality:1
Execution time is: 1.5 Seconds
Additional you should check how many values you have in your table for the specific column values.
The following select might be helful for that.
select count(*) "total_count"
,count(case when A1=123 then 1 end) "A1_count"
,count(case when A1=123 and A2=456 then 1 end) "A1andA2_count"
from TB_test;Share your output of this.
I expect the value for A1_count still to be high. But the value for A1+A2_count relatively low.
However 5 minutes is far to long for such a small table. Even if you run it on a laptop.
There must be a reason why it is that slow.
First thing to consider would be to update your statistics for the table and the index.
Second thing could be that the table is very sparsly fillled. Meaning, if you frequently delete records from this table and load new data using APPEND hint, then the table will grow, because the free space from the deletes is never reused. Any table access in the execution plan, will be slower then needed.
A similar thing can happen, if many updates on previously empty columns are made on a table (row chaining problem).
So if you explain a little, how this table is filled and used, we could recognize a typical pattern that leads to performance issues.
Edited by: Sven W. on Nov 28, 2012 5:54 PM
Similar Messages
-
Execution time of query with high variance
I have an Oracle Database 11.2 R2 which is set up just for testing purposes, so there is no other activity except mine. Now I have a query which I ran 10 times in a row. Between the executions I always flushed BUFFER_CACHE and SHARED_POOL. The strange thing is, that the execution time of the query is strongly varying from 13 seconds up to 207 seconds. From the 10 executions I have 4 times <25 seconds and 4 times > 120 seconds.
What could be the reason for this? As I've said, there is no other activity on the database and it is always the same query with the same parameters running on the same set of data.
The background to this is that I would like to compare the execution time of exactly the same query with different database settings. So I thought I could just run the query ten times and use the average but I didn't expect such a high variance.
Kind regards
PeterHi,
for each execution, look at:
1) plan hash value
2) total logical I/O
3) physical I/O
That should give you some clues as to what's going on.
Best regards,
Nikolay -
Many execution of a query with different selections in the same work book
Hi all,
I have a workbook with one query that show sales of a plant. User can select many plants, but he doesn't like it, too easy. In this way query shows all the plant in the same sheet and he want a sheet for each plant.
The most simply way to do this is making a query for each plant with a filter with the plant as a constant. Then I put all that queries in the workbook. But this is not too smart, right?
Any suggestion?Hi,
I will try and explain here, if you get stuck and do get back.
1) On Sheet1 Rename it to BEX01 and Add the Query that will return all Plants. Hide this Sheet
2) On Sheet2 Rename it to BEX02 and Add the Main Query. Hide this Sheet.
3) On Sheet3 Rename it to Main and Add a Command Button. Goto Properties and Change the Name to cmdRefresh and then do View Code and add following code.
Private Sub cmdRefresh_Click()
Call RefreshReports
End Sub
4) Add a Module to your VBA Project
5) Open Module1 and Add following code.
Option Explicit
Public Sub RefreshReports()
Dim wksBEX01 As Worksheet, wksBEX02 As Worksheet, wks As Worksheet
Dim lRows As Long, lRow As Long
Dim sPlant As String, sName As String
Dim fRng As Range
sName = "Main"
With ThisWorkbook
Set wksBEX01 = .Sheets("BEX01")
Set wksBEX02 = .Sheets("BEX02")
End With
wksBEX01.Activate
wksBEX01.Range("A1").Select
'This will refresh both the Queries All Plants and the Main one.
If Run("SAPBEX.XLA!SAPBEXrefresh", True) <> 0 Then
MsgBox "Refresh of All Queries Failed."
Exit Sub
End If
'Lets say your All Plants Query, Lists all the Plants Starting in Cell A15
'Then Do the following.
lRows = wksBEX01.Cells(Rows.Count, 1).End(xlUp).Row
For lRow = 15 To lRows
sPlant = Trim$(wksBEX01.Cells(lRow, 1).Value)
'Now Use this Plant to Set the Filter Value for the Main Query.
'I am assuming that your Plant Charateristic will show up in A14 on the Worksheet.
With wksBEX02
.Activate
'Adjust this according to where you insert the Query and which cell has correct info.
.Range("A14").Select
Set fRng = Selection
End With
'Call the API to Do a Select Filter Value.
If Run("SAPBEX.XLA!SAPBEXSetFilterValue", sPlant, "", fRng) <> 0 Then
MsgBox "Unble to Set Filter for Plant : " & sPlant
Exit Sub
Else
'Here you can Now Copy the the Sheet to new Sheet. If filter value worked.
Set wks = ThisWorkbook.Sheets.Add(After:=sName)
wksBEX02.Cells.Select
wksBEX02.Copy
wks.Range("A1").Paste
wks.Name = sPlant
sName = sPlant
End If
Next
'Save the workbook as new name else you will have to first delete all the old sheets.
Thisworkbook.SaveAs "Some New Name"
End Sub
Here I have just created a new Sheet for Each Plant. You can work on the EXCEL Part to take and do what you want with new Sheets.
Hope this gets you started.
Just a Suggestion. Don't hide the BEX01 and BEX02 sheets untill the code works correctly.
Datta -
SSIS execution time vs Query Analyser
Hello there, I'm getting 2 contradicting results when executing a query from
a) SSIS package
b) Query Analyser
SSIS package seems to take forever where as the QA does the job in 5 secs.
I'd really appreciate your feedback.
Thanks,
Vivekyes. Here is the query
====================================
select *
from W
where (DATEADD(yy, -21, GETDATE())) <= DOB and
REM is NULL and CoverageGrp not in ('C13') and
O_RID NOT IN
select O_RID
from W
where CoverageGrp in ('C13')
) and
O_RID not in
select DQO_RID from dbo.DRLoad
where DQP_Id = '776'
order by O_RID
====================================== -
Report execution time is in milliseconds
My report execution time is in milliseconds.Where should i examine this time?
If u have permisssions to see the log..(logging level >2) then you can see your execution time in the following path
setting--->Administration------>Manage Sessions------>View Log
In that you can find different sections which can give your the execution time
-------------------- Physical query response time
-------------------- Physical Query Summary Stats
-------------------- Logical Query Summary Stats -
Workbook Execution time...
Hi friends
i have one report which takes more than 20 mins. query can give o/p of 50000 rows. now tell how i can reduce the execution time. my query is well tuned. and giving minimum cost. but still in discoverer it takes 20 min. can u tell me how i can reduce the execution time(it should be executed 2-3 mins . should i go for high configuration PC?
thanx.....Hi,
You need to establish where the report is waiting to complete. If the report is waiting for the database query to finish then tuning the database query will improve performance. If the you are using Discoverer Desktop or Plus then you may be waiting for the PC to sort and format the results and so upgrading the PC will help, or if you are using Discovere Plus or Viewer you may be waiting for the Application Server to process the report so tuning the Application server may improve the timings.
You say "my query is well tuned. and giving minimum cost". The cost of the query tells you nothing. You need to examine the query execution plan and benchmark the query before to determine the optimum query plan.
Rod West -
How to find the Executed time of query
hi,
i want to find out the execution time of query like a sales report executed in 10 min. how to find out that? is there is any TC for that or what is the option to use that?
and how to fing out execution time of Data source to info providers.. or DSOs to IC? like how much time taken to load data?
regards,
preetyHello Preety,
Goto RSRT give the query name and see the technical property you will find the query generation time.
For the time taken for execution Select the execute and debug mode in the options select display statistics.
Execute the query
Click back
You can see the statistics.
Thanks
Chandran -
Can the format of a SQL Statement modify the execution time of an SQL statement?
Thanks in advanceIt depends on:
1) What oracle version are you using
2) What do you mean for "format"
For example: if you're on Oracle9i and changing format means changing the order of the tables in the FROM clause and you're using Rule Based Optimizer then the execution plan and the execution time can be very different...
Max
[My Italian Oracle blog|http://oracleitalia.wordpress.com/2009/12/29/estrarre-i-dati-in-formato-xml-da-sql/] -
Getting estimated execution time via JDBC
Hi,
I have a web application that's meant to query by multiple search criteria, so queries can quickly become too complex. I know that using Resource Manager it is possible to prevent certain queries from running, based on estimated execution time.
Is there any way to query these time estimates, making them available to the calling application? (before going ahead with execution)
Thanks
IvanI am not sure if this is possible in JDBC, the best thing you can do is, get an average execution time for query and use in your application OR do a start time and end time while you are executing the scripts and get the difference.
-
Execution time of sql query differing a lot between two computer
hi
execution time of a query in my computer and more than 30 different computer is less than one second but on one of our
customers' computers, execution time is more than ten minute. databases and data and queries are same. i re-install sql but problem remains. my sql is ms sql 2008 r2.
any one has idea for this problem?Hi mahdi,
Obviously, we can't get enough information to help you troubleshoot this issue. So, please elaborate your issue with more detail so that the community members can help you in more effecient manner.
In addition, here is a good article regarding checklist for analyzing Slow-Running queries. Please see:
http://technet.microsoft.com/en-us/library/ms177500(v=sql.105).aspx
And SQL Server Profiler and Performance Monitor are good tools to troubleshoot performance issue, please see:
Correlating SQL Server Profiler with Performance Monitor:
https://www.simple-talk.com/sql/database-administration/correlating-sql-server-profiler-with-performance-monitor/
Regards,
Elvis Long
TechNet Community Support -
Query with different parameter take different time to execute.
Hi,
I am a C/C++ programmer and newbie to database. I find weird case to my company database. oracle 10g.
I have a query (below). When I set GENRE_ID value to 20, query execution time only take *5* seconds. But when I change to 10, it take *54* seconds! The same query but different values GENRE_ID (20 or 10) -- it also happen to other GENRE_ID values.
on below query
WHERE substr(GENRE_ID,0,2) = 10 and GENRE_ID != 10) take 54 seconds
WHERE substr(GENRE_ID,0,2) = 20 and GENRE_ID != 20) take 5 seconds
The explain plan give exact same result for both queries.
I have follow Re: 3. How to improve the performance of my query? / My query is running slow. for optimizer but the problem still there.
And we have rebuilt all indexes.
Anyone can help me? I need any advises for this problem.
Note:
Song table only have 570K records and Song_vod table 1100 records.
Query:
select *
from(
select rownum rowno, a.*
from(
select a.SONG_VOD_ID, a.SONG_ID, a.VOD_TITLE, a.ALBUM_ID, a.ARTIST_ID, a.VOD_ISSUE_DATE, a.VOD_ORDER_ISSUE_DATE, a.VOD_ADULT_YN, a.VOD_L_IMG_PATH, a.VOD_M_IMG_PATH, a.VOD_S_IMG_PATH, a.RECOMMEND_CNT, a.OPPOSE_CNT, get_song_name(a.SONG_ID) SONG_NAME, get_album_name(a.ALBUM_ID) ALBUM_NAME, get_artist_name(a.ARTIST_ID) ARTIST_NAME, VOD_ISSUE_DATE vodIssueDate
from SONG_VOD a inner join SONG b on a.SONG_ID = b.SONG_ID
where a.LC_STATUS_CD = 'CS0006'
AND (b.GENRE_ID
in (
select GENRE_ID
from MD_GENRE
WHERE substr(GENRE_ID,0,2) = 10
and GENRE_ID != 10)
OR b.GENRE_ID
in (
select GENRE_ID
from MD_GENRE
WHERE substr(GENRE_ID,0,2) = '40'
and GENRE_ID != '40'
) order by a.REG_DATE desc, a.SONG_VOD_ID desc
) a WHERE rownum <= 0 + 30
Thank you,
Regards
-=Rika Chaniago=-907814 wrote:
I am a C/C++ programmer and newbie to database. I find weird case to my company database. oracle 10g.
I have a query (below). When I set GENRE_ID value to 20, query execution time only take *5* seconds. But when I change to 10, it take *54* seconds! The same query but different values GENRE_ID (20 or 10) -- it also happen to other GENRE_ID values.This is to be expected. Even an IDENTICAL query can (and often will) have DIFFERENT execution times.
The typical reason is how fast the query process can get to the data block(s) containing the relevant row(s). Is that data block still on disk and require expensive and slow physical I/O to move it into the buffer cache for use? Is that data block already cached for much faster logical I/O access? If in memory, is there any contention in getting a latch for the chain the data block hangs off from (how hot is that block)? Etc.
The run-time environment is not static. Thus execution times of queries (called cursors in Oracle) is not static. Execution times are expected to vary.
Some basics. SQL code is source code. SQL code needs to be parsed and converted into a set of instructions that the server can execute. So it is similar to C/C++. SQL source code needs to be compiled. This executable code in Oracle is called a cursor.
Like your code, the cursor can be executed with different input variables (bind variables). However, that code would have been compiled using certain assumptions about the data. And that executable code may work fine for some input data, and work not so okay for other input data. As the input parameter values are not not equal. E.g. there are a 1000 rows to process when employee type parameter is "employee" and only 10 rows when it is "manager". The code could have been compiled with the assumption that 10 rows would be the average for all input parameters - the Cost Based Optimiser needs to base its decision on the best execution path for that SQL source code on certain assumptions about the data. These may not always be correct. (usually due incorrect or stale stats about the data)
Thus you also need to look at what the execution plan is (the URL for which has already been supplied).
The Oracle® Database Performance Tuning Guide is at http://www.oracle.com/pls/db112/portal.all_books -
Clustering of SQL query execution times
In doing some query execution experiments I have noted a curious (to me, anyhow) clustering of execution times around two distinct points. Across about 100 tests each running 1000 queries using (pseudo-)randomly generated IDs the following pattern emerges. The queries were run from Java using all combinations of pooled/non-pooled and thin/oci driver combinations:
100 *
90 *
R 80 *
u 70 *
n 60 *
s 50 *
40 * *
30 * *
20 * * * *
10 * * * * * *
0 100 200 300 400 500 600 700 800 900 1000 1100 1200
Time(ms)Where about half of the total execution times cluster strongly about a given (short) time value with a smaller but broader clustering at a significantly slower mark, with zero intermediate values. The last point is the one I find most curious.
What I would have expected is something like this:
100
90
R 80
u 70
n 60
s 50
40 *
30 * * *
20 * * * * * *
10 * * * * * * * * * *
0 100 200 300 400 500 600 700 800 900 1000 1100 1200
Time(ms)The variables I have tentatively discounted thus far:
-query differences (single query used)
-connection differences (using single pooled connection)
-garbage collection (collection spikes independent of query execution times)
-amount of data returned in bytes (single varchar2 returned and size is independent of execution time)
-driver differences (thin and oci compared, overall times differ but pattern of clustering remains)
-differences between Statement and PreparedStatement usage (both show same pattern)
I know this is a rather open-ended question, but does the described pattern seem faniliar or spark any thoughts?
DB-side file I/O?
Thread time-slicing variations (client or DB-side)?
FWIW, the DB is 9.2.0.3 DB and the clients are running on WinXP with Java 5.0 and 9i drivers.
Thanks and regards,
MFurther context:
Are your queries only SELECT queries ?
Yes, the same SELECT query is used for all tests. The only variable is the bind variable used to identify the primary key of the selection set (i.e. SELECT a.* from a, b, c where a.x = b.x and b.y = c.y and c.pk = ?) where all PKs and FKs are indexed.Do the queries always use the same tables, the same where clauses ?
Yes, the same tables are always invoked. The where clauses invoked are identical with the excepton of the single bind variable as described above.Do your queries always use bind variables ?
A single bind variable is used in all invocations as described above.Are your queries also running in single user mode or multi user mode (do you use SELECT FOR UPDATE ?) ?
We are not using SELECT FOR UPDATEDid something else run on the database/on the server hosting the database on the same time ?
I have not eliminated the idea, but the test has been repeated roughly 100 times over the course of a week and at different times of day with the same pattern emerging. I suppose it is not out of the question that a resource-hogging process is running consistently and constantly on the DB-side box.Thanks for the input,
M -
Same sqlID with different execution plan and Elapsed Time (s), Executions time
Hello All,
The AWR reports for two days with same sqlID with different execution plan and Elapsed Time (s), Executions time please help me to find out what is reason for this change.
Please find the below detail 17th day my process are very slow as compare to 18th
17th Oct 18th Oct
221,808,602
21
2tc2d3u52rppt
213,170,100
72,495,618
9c8wqzz7kyf37
209,239,059
71,477,888
9c8wqzz7kyf37
139,331,777
1
7b0kzmf0pfpzn
144,813,295
1
0cqc3bxxd1yqy
102,045,818
1
8vp1ap3af0ma5
128,892,787
16,673,829
84cqfur5na6fg
89,485,065
1
5kk8nd3uzkw13
127,467,250
16,642,939
1uz87xssm312g
67,520,695
8,058,820
a9n705a9gfb71
104,490,582
12,443,376
a9n705a9gfb71
62,627,205
1
ctwjy8cs6vng2
101,677,382
15,147,771
3p8q3q0scmr2k
57,965,892
268,353
akp7vwtyfmuas
98,000,414
1
0ybdwg85v9v6m
57,519,802
53
1kn9bv63xvjtc
87,293,909
1
5kk8nd3uzkw13
52,690,398
0
9btkg0axsk114
77,786,274
74
1kn9bv63xvjtc
34,767,882
1,003
bdgma0tn8ajz9
Not only queries are different but also the number of blocks read by top 10 queries are much higher on 17th than 18th.
The other big difference is the average read time on two days
Tablespace IO Stats
17th Oct
Tablespace
Reads
Av Reads/s
Av Rd(ms)
Av Blks/Rd
Writes
Av Writes/s
Buffer Waits
Av Buf Wt(ms)
INDUS_TRN_DATA01
947,766
59
4.24
4.86
185,084
11
2,887
6.42
UNDOTBS2
517,609
32
4.27
1.00
112,070
7
108
11.85
INDUS_MST_DATA01
288,994
18
8.63
8.38
52,541
3
23,490
7.45
INDUS_TRN_INDX01
223,581
14
11.50
2.03
59,882
4
533
4.26
TEMP
198,936
12
2.77
17.88
11,179
1
732
2.13
INDUS_LOG_DATA01
45,838
3
4.81
14.36
348
0
1
0.00
INDUS_TMP_DATA01
44,020
3
4.41
16.55
244
0
1,587
4.79
SYSAUX
19,373
1
19.81
1.05
14,489
1
0
0.00
INDUS_LOG_INDX01
17,559
1
4.75
1.96
2,837
0
2
0.00
SYSTEM
7,881
0
12.15
1.04
1,361
0
109
7.71
INDUS_TMP_INDX01
1,873
0
11.48
13.62
231
0
0
0.00
INDUS_MST_INDX01
256
0
13.09
1.04
194
0
2
10.00
UNDOTBS1
70
0
1.86
1.00
60
0
0
0.00
STG_DATA01
63
0
1.27
1.00
60
0
0
0.00
USERS
63
0
0.32
1.00
60
0
0
0.00
INDUS_LOB_DATA01
62
0
0.32
1.00
60
0
0
0.00
TS_AUDIT
62
0
0.48
1.00
60
0
0
0.00
18th Oct
Tablespace
Reads
Av Reads/s
Av Rd(ms)
Av Blks/Rd
Writes
Av Writes/s
Buffer Waits
Av Buf Wt(ms)
INDUS_TRN_DATA01
980,283
91
1.40
4.74The AWR reports for two days with same sqlID with different execution plan and Elapsed Time (s), Executions time please help me to find out what is reason for this change.
Please find the below detail 17th day my process are very slow as compare to 18th
You wrote with different execution plan, I think, you saw plans. It is very difficult, you get old plan.
I think Execution plans is not changed in different days, if you not added index or ...
What say ADDM report about this script?
As you know, It is normally, different Elapsed Time for same statement in different day.
It is depend your database workload.
It think you must use SQL Access and SQl Tuning advisor for this script.
You can get solution for slow running problem.
Regards
Mahir M. Quluzade -
Dear SCN,
I am new to BOBJ Environment. I have created a webi report on top of bex query by using BISC connection. Bex query is build for Vendor Ageing Analysis. My bex query will take very less time to execute the report (max 1 min). But in case of webi is takeing around 5 min when i click on refresh. I have not used any conditions,filters,restrictions are done at webi level all are done at bex level only.
Please let me know techniques to optimize the query execution time in webi. Currently we are in BO 4.0.
Regards,
PRKHi Praveen
Go through this document for performance optimization using BICS connection
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/d0e3c552-e419-3010-1298-b32e6210b58d?QuickLink=index&… -
Reduce the execution time for the below query
Hi,
Please help me to reduce the execution time on the following query .. if any tuning is possible.
I have a table A with the columns :
ID , ORG_LINEAGE , INCLUDE_IND ( -- the org lineage is a string of ID's. If ID 5 reports to 4 and 4 to 1 .. the lineage for 5 will be stored as the string -1-4-5)
Below is the query ..
select ID
from A a
where INCLUDE_IND = '1' and
exists (
select 1
from A b
where b.ID = '5'
and b.ORG_LINEAGE like '%-'||a.ID||'-%'
order by ORG_LINEAGE;
The only constraint on the table A is the primary key on the ID column.
Following will be the execution plan :
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=406 Card=379 Bytes=2
653)
1 0 SORT (ORDER BY) (Cost=27 Card=379 Bytes=2653)
2 1 FILTER
3 2 TABLE ACCESS (FULL) OF 'A' (Cost=24 Card
=379 Bytes=2653)
4 2 TABLE ACCESS (BY INDEX ROWID) OF 'A' (Co
st=1 Card=1 Bytes=6)
5 4 INDEX (RANGE SCAN) OF 'ORG_LINEAGE'
(NON-UNIQUE)I order it by the org_lineage to get the first person. So it is a result problem? The order by doesn't give you the first person, it gives you a sorted result set (of which there may be zero, one, or thousands).
If you only want one row from that, then you're spending a lot of time tuning the wrong query.
How do you know which ORG_LINEAGE row you want?
Maybe it would help if you posted some sample data.
Maybe you are looking for
-
Unable to write, type anything in source code of a function module.
Hi all, We have a registered name space for our client called /ABCD/EFG. I need to create a function module in the name space. So first I created a Function Group called /ABCD/EFG_FG in /ABCD/EFG. I activated it in se80. Then I created a Function Mod
-
How To Smooth "Ken Burns Effect"
Hello, I have some stills that I am zooming and panning at the same time. For example, starting at the top right corner of a still and zooming out as well as panning right to left so that the still stays centered. Looks great so far except for the in
-
Nokia Lumia 928 unresponsive even after several re...
I had just watched a video online, and suddenly at the end of the video, the phone's screen started displaying weird pixels and lines throughout and the phone is now completely unresponsive, except for the power and volume buttons. I've tried the ha
-
html:select Struts tag problems
hello I've a bean "Profile" in my sessionScope under name "myProfile" This bean is defined as public class Profile implements java.io.Serializable { private User user; private List<Groups> groups; private List<Function> function;
-
Hp 610 Touch Smart Windows 7 64 bit Where do I find the settings, etc. for the built-in Webcam? Do I need third party software to use the webcam? Thanks... This question was solved. View Solution.