Tuning Statements
Hi all,
i need to tune this query , iam on 10Gr2 ON windows 2003
select INV.INV_ID, INV.INV_DT_TM, INV.EQ_NAME, I.NAME, I.VALUE, I.UNIT, I.CONF
from INV INV, INPUT_INV I
where INV.INV_ID = I.INV_ID
and I.VALUE IS NOT NULL
and I.NAME NOT IN
(select O.NAME
from INV INV, OUTPUT_INV O
where INV.INV_ID = O.INV_ID
and INV.INV_ID = I.INV_ID));
Execution Plan
Plan hash value: 230622443
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 506K| 38M| | 3702 (1)| 00:00:45 |
|* 1 | HASH JOIN | | 506K| 38M| | 3702 (1)| 00:00:45 |
| 2 | TABLE ACCESS FULL | INV | 11923 | 197K| | 73 (0)| 00:00:01 |
|* 3 | HASH JOIN ANTI | | 506K| 29M| 16M| 3626 (1)| 00:00:44 |
|* 4 | TABLE ACCESS FULL |INPUT_INV | 506K| 10M| | 978 (1)| 00:00:12 |
| 5 | VIEW | VW_SQ_1 | 426K| 16M| | 500 (1)| 00:00:06 |
|* 6 | HASH JOIN | | 426K| 7502K| | 500 (1)| 00:00:06 |
| 7 | INDEX FAST FULL SCAN| INV_PK | 11923 | 47692 | | 6 (0)| 00:00:01 |
| 8 | INDEX FAST FULL SCAN| OUTPUT_INV_PK | 426K| 5835K| | 492 (1)| 00:00:06 |
Predicate Information (identified by operation id):
1 - access("INV"."INV_ID"="I"."INV_ID")
3 - access("I"."NAME"="VW_COL_1" AND "INV_ID"="I"."INV_ID")
4 - filter("I"."VALUE" IS NOT NULL)
6 - access("O"."INV_ID"="INV"."INV_ID")is it posiible to conver the not in to not exists
SQL> show parameter optimizer
NAME TYPE
VALUE
optimizer_dynamic_sampling integer
2
optimizer_features_enable string
10.2.0.4
optimizer_index_caching integer
0
optimizer_index_cost_adj integer
100
optimizer_mode string
NAME TYPE
VALUE
choose
optimizer_secure_view_merging boolean
TRUE
SQL> desc input_inv
Name Null? Type
INV_ID NOT NULL NUMBER
NAME NOT NULL VARCHAR2(50)
VALUE VARCHAR2(32)
UNIT VARCHAR2(32)
CONF NUMBER
TAGNAME VARCHAR2(32)
STATUS NUMBER(38)
USERID VARCHAR2(50)
INFORMATION_MESSAGE VARCHAR2(4000)
USER_COMMENT VARCHAR2(255)
DATE_TIME DATE
SQL> desc output_inv
Name Null? Type
INV_ID NOT NULL NUMBER
NAME NOT NULL VARCHAR2(50)
VALUE VARCHAR2(32)
UNIT VARCHAR2(32)
CONF NUMBER
TAGNAME VARCHAR2(32)
STATUS NUMBER(38)
USERID VARCHAR2(50)
INFORMATION_MESSAGE VARCHAR2(4000)
USER_COMMENT VARCHAR2(255)
DATE_TIME DATE
SQL> desc inv
Name Null? Type
INV_ID NOT NULL NUMBER
SRC_ID NOT NULL VARCHAR2(10)
EQ_NAME NOT NULL VARCHAR2(40)
INV_DT_TM NOT NULL DATE
VOL_UNIT VARCHAR2(32)
LEVEL_UNIT VARCHAR2(32)
TEMP_UNIT VARCHAR2(32)
TOLERANCE VARCHAR2(25)
DENSITY_UNIT VARCHAR2(32)
MASS_UNIT VARCHAR2(32)
PRESSURE_UNIT VARCHAR2(32)
DATA_QUALITY NUMBER(38)
CHECKED NUMBER(38)
RELEASED NUMBER(38)
INFORMATION_MESSAGE VARCHAR2(4000)
MODIFIED_ON DATE
MODIFIED_BY VARCHAR2(50)
SQL> show parameter db_file_multi
NAME TYPE
VALUE
db_file_multiblock_read_count integer
32
SQL> show parameter db_block_size
NAME TYPE
VALUE
db_block_size integer
8192
SQL> show parameter cursor_sharing
NAME TYPE
VALUE
cursor_sharing string
EXACT
Similar Messages
-
Tuning Statement - Parallel Execution... but why ?
Hello All,
We tuned a query last week and everything was fine. However yesterday, we noticed that the query took 5 minutes to complete instead of 3 seconds. When we executed the explain plan of the query, we noticed that it was using parallel features (PX SEND HASH, etc.) and seems to take more time now. We have not set any parallel features until now so I am wondering if Oracle can use parallelism even if we have not set it ?
and if not, why now Oracle uses parallelism ?
Many thanks.We have not set any parallel features until now so I am wondering if Oracle can use parallelism even if we have not set it ?
and if not, why now Oracle uses parallelism ?
If you do not want to have any SQL run in parallel, you can just set your DB that way.
To do that at system level you can set PARALLEL_MAX_SERVERS to 0.
To do it at session level you can issue
alter session disable parallelEven though you can use Oracle Resource Manager to do that, I do not recommend it - http://iiotzov.wordpress.com/2011/09/30/is-controlling-parallelism-with-an-oracle-resource-plan-ever-a-good-option
Iordan Iotzov
http://iiotzov.wordpress.com/
Edited by: Iordan Iotzov on Mar 19, 2013 7:44 AM -
It's hard to present AWR report content here as if i go for copy paste the content alinment and format get changed. Is there any better way to present AWR report in my query.
Here is my query.
In a 2 hour AWR reports for a database I can see the below top 5 wait event's
the database is running on high CPU consumption (there are very less physical reads on database and Logical read is high i suppose ) so I also gather the Segments by Logical Reads. Please provide any suggestion how can i avoid logical reads I/o for the dataabse. If you see at bottom only two segments are responsible for high logical reads.
Please let me know if more content of AWR report is required.
Per Second Per Transaction
Redo size: 12,765.52 2,030.27
Logical reads: 324,030.64 51,534.93
Block changes: 71.62 11.39
Physical reads: 28.26 4.49
Physical writes: 3.84 0.61
User calls: 333.61 53.06
Parses: 157.16 24.99
Hard parses: 0.17 0.03
Sorts: 30.07 4.78
Logons: 1.71 0.27
Executes: 156.35 24.87
Transactions: 6.29
% Blocks changed per Read: 0.02 Recursive Call %: 28.05
Rollback per transaction %: 16.17 Rows per Sort: 29.99
Top 5 Timed Events
Event Waits Time(s) Avg Wait(ms) % Total Call TimeWait Class
CPU time 4,711 88.0
db file sequential read 190,548 356 2 6.7 User I/O
gc current block 2-way 172,948 151 1 2.8 Cluster
gc cr grant 2-way 128,668 67 1 1.2 Cluster
log file sync 37,920 54 1 1.0 Commit
Segments by Logical Reads
Total Logical Reads: 2,342,983,880
Captured Segments account for 99.8% of Total
Owner Tablespace Name Object Name Subobject Name Obj. Type Logical Reads %Total
web_dc DECOINDX D_1F01BC958000013B INDEX 909,141,504 38.80
web_dc DECODATA DM_RELATION_TYPE_S TABLE 908,104,384 38.76
web_dc DECOINDX D_1F01BC9580000518 INDEX 165,716,752 7.07
web_dc DECODATA DM_RELATION_S TABLE 136,235,504 5.81
web_dc DECOINDX D_1F01BC9580000024 INDEX 62,935,008 2.69
Regards
balvindarIn a 2 hour AWR reports for a database I can see the below top 5 wait event's
Comment: 2 hour is a too big interval to draw any conclusion. It should be 15-30 mins maximum.
Apart from that: 88 percent of the wall time is devoted to CPU, so do you have a problem? Not at all!!! Your database is doing pretty nothing.
the database is running on high CPU consumption (there are very less physical reads on database and Logical read is high i suppose ) so I also gather the Segments by Logical Reads. Please provide any suggestion how can i avoid logical reads I/o for the dataabse. If you see at bottom only two segments are responsible for high logical reads.
Comment: the database is not running on high CPU consumption. You would need to run an ADDM report to be able to ascertain that. We have no data on the CPU load of the server, nor how much Oracle is contributing to the load.
You cannot avoid logical read I/O, other than just stopping the application. You can tune them by tuning statements.
In the future, please wrap the output in tags (no spaces, lowercase), or I will need new glasses ;)
Sybrand Bakker
Senior Oracle DBA -
HOW TO: Post a SQL statement tuning request - template posting
This post is not a question, but similar to Rob van Wijk's "When your query takes too long ..." post should help to improve the quality of the requests for SQL statement tuning here on OTN.
On the OTN forum very often tuning requests about single SQL statements are posted, but the information provided is rather limited, and therefore it's not that simple to provide a meaningful advice. Instead of writing the same requests for additional information over and over again I thought I put together a post that describes how a "useful" post for such a request should look like and what information it should cover.
I've also prepared very detailed step-by-step instructions how to obtain that information on my blog, which can be used to easily gather the required information. It also covers again the details how to post the information properly here, in particular how to use the \ tag to preserve formatting and get a fixed font output:
http://oracle-randolf.blogspot.com/2009/02/basic-sql-statement-performance.html
So again: This post here describes how a "useful" post should look like and what information it ideally covers. The blog post explains in detail how to obtain that information.
In the future, rather than requesting the same additional information and explaining how to obtain it, I'll simply refer to this HOW TO post and the corresponding blog post which describes in detail how to get that information.
*Very important:*
Use the \ tag to enclose any output that should have its formatting preserved as shown below.
So if you want to use fixed font formatting that preserves the spaces etc., do the following:
\ This preserves formatting
\And it will look like this:
This preserves formatting
. . .Your post should cover the following information:
1. The SQL and a short description of its purpose
2. The version of your database with 4-digits (e.g. 10.2.0.4)
3. Optimizer related parameters
4. The TIMING and AUTOTRACE output
5. The EXPLAIN PLAN output
6. The TKPROF output snippet that corresponds to your statement
7. If you're on 10g or later, the DBMS_XPLAN.DISPLAY_CURSOR output
The above mentioned blog post describes in detail how to obtain that information.
Your post should have a meaningful subject, e.g. "SQL statement tuning request", and the message body should look similar to the following:
*-- Start of template body --*
The following SQL statement has been identified to perform poorly. It currently takes up to 10 seconds to execute, but it's supposed to take a second at most.
This is the statement:
select
from
t_demo
where
type = 'VIEW'
order by
id;It should return data from a table in a specific order.
The version of the database is 11.1.0.7.
These are the parameters relevant to the optimizer:
SQL>
SQL> show parameter optimizer
NAME TYPE VALUE
optimizer_capture_sql_plan_baselines boolean FALSE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 11.1.0.7
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
optimizer_use_invisible_indexes boolean FALSE
optimizer_use_pending_statistics boolean FALSE
optimizer_use_sql_plan_baselines boolean TRUE
SQL>
SQL> show parameter db_file_multi
NAME TYPE VALUE
db_file_multiblock_read_count integer 8
SQL>
SQL> show parameter db_block_size
NAME TYPE VALUE
db_block_size integer 8192
SQL>
SQL> show parameter cursor_sharing
NAME TYPE VALUE
cursor_sharing string EXACT
SQL>
SQL> column sname format a20
SQL> column pname format a20
SQL> column pval2 format a20
SQL>
SQL> select
2 sname
3 , pname
4 , pval1
5 , pval2
6 from
7 sys.aux_stats$;
SNAME PNAME PVAL1 PVAL2
SYSSTATS_INFO STATUS COMPLETED
SYSSTATS_INFO DSTART 01-30-2009 16:25
SYSSTATS_INFO DSTOP 01-30-2009 16:25
SYSSTATS_INFO FLAGS 0
SYSSTATS_MAIN CPUSPEEDNW 494,397
SYSSTATS_MAIN IOSEEKTIM 10
SYSSTATS_MAIN IOTFRSPEED 4096
SYSSTATS_MAIN SREADTIM
SYSSTATS_MAIN MREADTIM
SYSSTATS_MAIN CPUSPEED
SYSSTATS_MAIN MBRC
SYSSTATS_MAIN MAXTHR
SYSSTATS_MAIN SLAVETHR
13 rows selected.Here is the output of EXPLAIN PLAN:
SQL> explain plan for
2 -- put your statement here
3 select
4 *
5 from
6 t_demo
7 where
8 type = 'VIEW'
9 order by
10 id;
Explained.
Elapsed: 00:00:00.01
SQL>
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
Plan hash value: 1390505571
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 60 | 0 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T_DEMO | 1 | 60 | 0 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_DEMO | 1 | | 0 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("TYPE"='VIEW')
14 rows selected.Here is the output of SQL*Plus AUTOTRACE including the TIMING information:
SQL> rem Set the ARRAYSIZE according to your application
SQL> set autotrace traceonly arraysize 100
SQL> select
2 *
3 from
4 t_demo
5 where
6 type = 'VIEW'
7 order by
8 id;
149938 rows selected.
Elapsed: 00:00:02.21
Execution Plan
Plan hash value: 1390505571
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 60 | 0 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T_DEMO | 1 | 60 | 0 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_DEMO | 1 | | 0 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("TYPE"='VIEW')
Statistics
0 recursive calls
0 db block gets
149101 consistent gets
800 physical reads
196 redo size
1077830 bytes sent via SQL*Net to client
16905 bytes received via SQL*Net from client
1501 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
149938 rows processed
SQL>
SQL> disconnect
Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing optionsThe TKPROF output for this statement looks like the following:
TKPROF: Release 11.1.0.7.0 - Production on Mo Feb 23 10:23:08 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Trace file: orcl11_ora_3376_mytrace1.trc
Sort options: default
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
select
from
t_demo
where
type = 'VIEW'
order by
id
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1501 0.53 1.36 800 149101 0 149938
total 1503 0.53 1.36 800 149101 0 149938
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 88
Rows Row Source Operation
149938 TABLE ACCESS BY INDEX ROWID T_DEMO (cr=149101 pr=800 pw=0 time=60042 us cost=0 size=60 card=1)
149938 INDEX RANGE SCAN IDX_DEMO (cr=1881 pr=1 pw=0 time=0 us cost=0 size=0 card=1)(object id 74895)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 1501 0.00 0.00
db file sequential read 800 0.05 0.80
SQL*Net message from client 1501 0.00 0.69
********************************************************************************The DBMS_XPLAN.DISPLAY_CURSOR output:
SQL> -- put your statement here
SQL> -- use the GATHER_PLAN_STATISTICS hint
SQL> -- if you're not using STATISTICS_LEVEL = ALL
SQL> select /*+ gather_plan_statistics */
2 *
3 from
4 t_demo
5 where
6 type = 'VIEW'
7 order by
8 id;
149938 rows selected.
Elapsed: 00:00:02.21
SQL>
SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
SQL_ID d4k5acu783vu8, child number 0
select /*+ gather_plan_statistics */ * from t_demo
where type = 'VIEW' order by id
Plan hash value: 1390505571
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads |
| 0 | SELECT STATEMENT | | 1 | | 149K|00:00:00.02 | 149K| 1183 |
| 1 | TABLE ACCESS BY INDEX ROWID| T_DEMO | 1 | 1 | 149K|00:00:00.02 | 149K| 1183 |
|* 2 | INDEX RANGE SCAN | IDX_DEMO | 1 | 1 | 149K|00:00:00.02 | 1880 | 383 |
Predicate Information (identified by operation id):
2 - access("TYPE"='VIEW')
20 rows selected.I'm looking forward for suggestions how to improve the performance of this statement.
*-- End of template body --*
I'm sure that if you follow these instructions and obtain the information described, post them using a proper formatting (don't forget about the \ tag) you'll receive meaningful advice very soon.
So, just to make sure you didn't miss this point:Use proper formatting!
If you think I missed something important in this sample post let me know so that I can improve it.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/Alex Nuijten wrote:
...you missed the proper formatting of the Autotrace section ;-)Alex,
can't reproduce, does it still look unformatted? Or are you simply kidding? :-)
Randolf
PS: Just noticed that it actually sometimes doesn't show the proper formatting although the code tags are there. Changing to the \ tag helped in this case, but it seems to be odd.
Edited by: Randolf Geist on Feb 23, 2009 11:28 AM
Odd behaviour of forum software -
Query Tuning - using CASE statement in the WHERE clause - Duplicate Post
Duplicate Post by mistake.
Please check
Query Tuning - using CASE statement in the WHERE clause
Edited by: Chaitanya on Jun 9, 2011 2:45 AM
Edited by: Chaitanya on Jun 9, 2011 2:46 AMDuplicate Post by mistake.
Please check
Query Tuning - using CASE statement in the WHERE clause
Edited by: Chaitanya on Jun 9, 2011 2:45 AM
Edited by: Chaitanya on Jun 9, 2011 2:46 AM -
I have a select statement that I am repeating 12 times with the only difference between them all being the date range that is grabbed. Essentially, I am grabbing the last 12 months of information from the same table here is a copy of one of the sections:
(select
a.account_id as account_id,
a.company_id as company_id,
a.account_number as acct_number,
to_char(a.trx_date, 'YYYY/MM') as month,
sum(a.amount_due_original) as amount
from
crystal.financial_vw a
where
a.cust_since_dt is not null
and a.cust_end_dt is null
and a.trx_date > add_months(sysdate, -13)
and a.trx_date <= add_months(sysdate, -12)
group by
a.account_id,
a.company_id,
a.account_number,
to_char(a.trx_date, 'YYYY/MM')) b
I am now looking to do some tuning on this and was wondering if anyone has any suggestions. My initial thought was to use cursors or some sort of in memory storage to temporarily process the information into a pipe-delimited flat file."Don't need:
to_char(a.trx_date, 'YYYY/MM')"
Are you sure?
"Change to (just to make it easier to read):
a.trx_date between add_months(sysdate, -13)
and a.trx_date <= add_months(sysdate, -12)"
What? That's not even valid syntax is it? Besides the fact that the BETWEEN operator is inclusive (i.e. > add_months(sysdate, -13) is not the same as between add_months(sysdate, -13) ...).
"And be sure you have an index on:
cust_since_dt, cust_end_dt, trx_date in financial_vw."
What information did you base this conclusion on. Just because something is in the where clause doesn't mean you should automatically throw an index on it. What if 90% of the rows satisfy those null/not null criteria? What if there's only one year of data in this table? Are you certain an index would help pick out all the data for one month more efficiently than a full table scan?
My immediate question was why are you breaking the data for each month up into separate subqueries like this at all? What is it that your doing with these subqueries that you don't believe can be accomplished with a single grouped query? -
Stucked between SQL Tuning Advisor and and SQL statement
Hi,
There is an important query running on my system which consists
MEMBER OF function.
At first place let me explain why i used MEMBER OF,
I am sending a string( eg : #123#124#125) to query and a function converts this string into a number array.
After then I use this number array inside my sql.
The reason I am using this structure, in order to generate a dynamic IN statement inside my sql. (IF you have any other solution that would be great)
The most important point is; when I put this statement to SQL Tuning Advisor the response is only ORA-00932: inconsistent datatypes: expected UDT got CHAR
Any answer will be greatly appreciated.
ThanksSolomon Yakobson wrote:
Object oriented stuff almost never provides better performance over relational. You should stay away from MEMBER OF if performance is a factor. Instead of:
WHERE expr MEMBER OF nested-tableI'd test:
WHERE expr IN (SELECT column_value FROM TABLE(nested-table))SY.
expr IN (SELECT COLUMN_VALUE FROM TABLE (CAST (v_type_number_table AS type_number_table)))worked like a charm. i hope tuning advisor will like it as i do.
thanks. -
Tuning PL/SQL - tkprof shows much more work for RECURSIVE STATEMENTS
Hi,
Firstly I'm not sure if this should be in "Database - General" or "SQL and PL/SQL". Since it's more of a performance tuning question than specifically about the PL/SQL, I'm going to put it here in "Database - General". I hope that doesn't offend anyone.
I've just started looking at a reported performance problem in our app. One of the developers set me up a procedure that replicates the issue, I ran it while tracing the session and then fed the trace file to tkprof. The results at the bottom of my tkprof output file look like this:
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 3 0.01 0.07 10 60 0 0
Execute 3 0.01 0.01 0 3 0 3
Fetch 0 0.00 0.00 0 0 0 0
total 6 0.03 0.08 10 63 0 3
Misses in library cache during parse: 1
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 5 0.00 0.00
SQL*Net message from client 4 1.68 1.70
db file sequential read 18 0.01 0.10
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 416 0.00 0.01 0 0 2 0
Execute 1456 0.71 0.75 26 1739 425 590
Fetch 2932 0.12 2.21 337 6338 0 3061
total 4804 0.84 2.98 363 8077 427 3651
Misses in library cache during parse: 25
Misses in library cache during execute: 24
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file sequential read 343 0.08 2.09
db file scattered read 1 0.00 0.00
47 user SQL statements in session.
888 internal SQL statements in session.
935 SQL statements in session.
31 statements EXPLAINed in this session.I'm looking in particular at that relatively high activity for RECURSIVE STATEMENTS, because to me, the NON-RECURSIVE (ie the actual submitted statements that form our code) looks pretty harmless. This is my first experience of trying to tune some complex looking PL/SQL and I've no idea what could be considered more "normal", but from what I think I know, and google searches, the results look quite odd to me.
Is this high activity for RECURSIVE STATEMENTS a problem, and if so, what should I start looking at to reduce that activity?
Regards,
AdosIf you have a PLSQL block or stored procedure running SQL statements, the SQL statements, too, will appear as RECURSIVE STATEMENTS in the trace file and tkprof.
It is a misconception that RECURSIVE STATEMENTS are only SYS statements doing data dictionary lookups / updates.
For example, I ran this :
SQL> create or replace procedure test_procedure as
2 begin
3 insert into my_emp_table select * from my_emp_table;
4 dbms_output.put_line('Rows Inserted : ' || sql%rowcount);
5 insert into my_emp_table select * from my_emp_table where emplid=1;
6 dbms_output.put_line('Rows Inserted : ' || sql%rowcount);
7 end;
8 /
Procedure created.
SQL> alter session set events '10046 trace name context forever, level 8';
Session altered.
SQL> execute test_procedure;
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.
SQL> select 'x' from dual;
x
SQL> exitThe tkprof shows ;
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 3 0.00 0.00 0 0 0 0
Execute 3 0.00 0.00 0 0 1 1
Fetch 2 0.00 0.00 0 0 0 1
total 8 0.00 0.00 0 0 1 2
Misses in library cache during parse: 2
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 5 0.00 0.00
SQL*Net message from client 5 5.31 11.97
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 4 0.00 0.00 0 2 0 0
Execute 4 0.00 0.00 2 16 7 5
Fetch 2 0.00 0.00 0 14 0 2
total 10 0.01 0.01 2 32 7 7
Misses in library cache during parse: 2
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file sequential read 2 0.00 0.00
7 user SQL statements in session.
0 internal SQL statements in session.
7 SQL statements in session.Which were the Non-Recursive statements ?
BEGIN test_procedure; END;
commit
select 'x' from dualWhich were the RECURSIVE statements (which you can identify by the keywords : (recursive depth) ?
SELECT /* OPT_DYN_SAMP */ /*+ ALL_ROWS IGNORE_WHERE_CLAUSE
NO_PARALLEL(SAMPLESUB) opt_param('parallel_execution_enabled', 'false')
NO_PARALLEL_INDEX(SAMPLESUB) NO_SQL_TUNE */ NVL(SUM(C1),:"SYS_B_0"),
NVL(SUM(C2),:"SYS_B_1")
FROM
(SELECT /*+ NO_PARALLEL("MY_EMP_TABLE") FULL("MY_EMP_TABLE")
NO_PARALLEL_INDEX("MY_EMP_TABLE") */ :"SYS_B_2" AS C1, :"SYS_B_3" AS C2
FROM "MY_EMP_TABLE" "MY_EMP_TABLE") SAMPLESUB
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 7 0 1
total 3 0.00 0.00 0 7 0 1
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 64 (recursive depth: 2)
INSERT INTO MY_EMP_TABLE SELECT * FROM MY_EMP_TABLE
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 1 0 0
Execute 1 0.00 0.00 2 8 4 3
Fetch 0 0.00 0.00 0 0 0 0
total 2 0.00 0.00 2 9 4 3
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 64 (recursive depth: 1)
SELECT /* OPT_DYN_SAMP */ /*+ ALL_ROWS IGNORE_WHERE_CLAUSE
NO_PARALLEL(SAMPLESUB) opt_param('parallel_execution_enabled', 'false')
NO_PARALLEL_INDEX(SAMPLESUB) NO_SQL_TUNE */ NVL(SUM(C1),:"SYS_B_0"),
NVL(SUM(C2),:"SYS_B_1")
FROM
(SELECT /*+ IGNORE_WHERE_CLAUSE NO_PARALLEL("MY_EMP_TABLE")
FULL("MY_EMP_TABLE") NO_PARALLEL_INDEX("MY_EMP_TABLE") */ :"SYS_B_2" AS C1,
CASE WHEN "MY_EMP_TABLE"."EMPLID"=:"SYS_B_3" THEN :"SYS_B_4" ELSE
:"SYS_B_5" END AS C2 FROM "MY_EMP_TABLE" "MY_EMP_TABLE") SAMPLESUB
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 1 0.00 0.00 0 7 0 1
total 3 0.00 0.00 0 7 0 1
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 64 (recursive depth: 2)
INSERT INTO MY_EMP_TABLE SELECT * FROM MY_EMP_TABLE WHERE EMPLID=1
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 1 0 0
Execute 1 0.00 0.00 0 8 3 2
Fetch 0 0.00 0.00 0 0 0 0
total 2 0.00 0.00 0 9 3 2
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 64 (recursive depth: 1)The INSERT statments are recursive depth 1 while the SELECTS they cause are recursive depth 2.
Note that neither of these are are actually SYS statements agaisnt the data dictionary !!
Edit :
IF you read the last few lines, it would become evident that some (in my case all) the RECURSIVE STATEMENTS are non-SYS statements, actually being my code, not Oracle's code.
1 session in tracefile.
7 user SQL statements in trace file.
0 internal SQL statements in trace file.
7 SQL statements in trace file.
7 unique SQL statements in trace file.
87 lines in trace file.
6 elapsed seconds in trace file.I have 3 non-recursive and 4 "RECURSIVE" statements. All 7 are correctly identified as "user SQL statements in trace file".
Hemant K Chitale
http://hemantoracledba.blogspot.com
Edited by: Hemant K Chitale on Jul 29, 2009 11:44 PM
Edited by: Hemant K Chitale on Jul 29, 2009 11:47 PM -
Performance Tuning 'Runtime Error' on Select statement
Hi Experts,
Good Day!
I would like to ask some help regarding a custom program that will encounter 'Runtime Error' on the below codes on how to perform performance tunning especially number 1.
1.
SELECT A~VBELN A~ERDAT A~AUART A~VKORG A~VTWEG A~SPART A~VDATU
A~KUNNR B~POSNR B~MATNR B~ARKTX B~ABGRU B~KWMENG B~VRKME
B~WERKS B~VSTEL B~ROUTE
FROM VBAK AS A INNER JOIN VBAP AS B ON A~VBELN EQ B~VBELN
INNER JOIN VBEP AS C ON A~VBELN EQ C~VBELN
AND B~POSNR EQ C~POSNR
INTO CORRESPONDING FIELDS OF TABLE I_DATA_TAB
WHERE A~VBELN IN S_VBELN
AND A~VKORG IN S_VKORG
AND A~AUART IN S_AUART
AND A~VTWEG IN S_VTWEG
AND A~SPART IN S_SPART
AND A~VDATU IN S_VDATU
AND A~KUNNR IN S_KUNNRD
AND B~MATNR IN S_MATNR
AND B~KWMENG IN S_KWMENG
AND B~VRKME IN S_VRKME
AND B~WERKS IN S_WERKS
AND C~EDATU IN S_VDATU.
2.
SELECT VBELN FROM LIKP INTO LIKP-VBELN
WHERE LFDAT IN S_VDATU
AND VKORG IN S_VKORG
AND LFART EQ 'YSTD'
AND KUNNR IN S_KUNNRP
AND KUNAG IN S_KUNNRD
SELECT VBELN POSNR LFIMG MATNR WERKS
FROM LIPS INTO (LIPS-VBELN, LIPS-POSNR, DISPLAY_TAB-DEL_QTY,
LIPS-MATNR, LIPS-WERKS)
WHERE VBELN EQ LIKP-VBELN
AND MATNR IN S_MATNR
AND VTWEG IN S_VTWEG
AND SPART IN S_SPART
AND WERKS IN S_WERKS.
ENDSELECT.
ENDSELECT.
4.
SELECT DELIVERY POSNR MATNR PODLFIMG FROM T9YPODI INTO
(T9YPODI-DELIVERY, T9YPODI-POSNR, T9YPODI-MATNR, T9YPODI-PODLFIMG)
WHERE MATNR IN S_MATNR
AND PODDATE IN S_VDATU.
Answer's will be a great help.
~Thank You,
Lourd
Edited by: Lourd06 on Oct 23, 2009 10:32 AM
Moderator message - Welcome to SCN.
Moderator message - Please see Please Read before Posting in the Performance and Tuning Forum before posting. You're in the driver's seat here. It's up to you to do some analysis before expecting that people can halp you. - post locked
And please use code tags.
Edited by: Rob Burbank on Oct 23, 2009 9:13 AMHi All,
We've checked the transaction ST22 it is TIME OUT. I really need your help on this the program will dump in number 1 Select statement. Can you help me perform a performance tunning.
In transaction ST22
Runtime Errors TIME_OUT
Date and Time 21.10.2009 08:51:33
Short text
Time limit exceeded.
What happened?
The program "ZV0PSR10" has exceeded the maximum permitted runtime without
interruption and has therefore been terminated.
What can you do?
Note down which actions and inputs caused the error.
To process the problem further, contact you SAP system
administrator.
Using Transaction ST22 for ABAP Dump Analysis, you can look
at and manage termination messages, and you can also
keep them for a long time.
Error analysis
After a specific time, the program is terminated to make the work area
available to other users who may be waiting.
This is to prevent a work area being blocked unnecessarily long by, for
example:
- Endless loops (DO, WHILE, ...),
- Database accesses with a large result set
- Database accesses without a suitable index (full table scan)
The maximum runtime of a program is limited by the system profile
parameter "rdisp/max_wprun_time". The current setting is 1200 seconds. If this
time limit is
exceeded, the system attempts to cancel any running SQL statement or
signals the ABAP processor to stop the running program. Then the system
waits another 60 seconds maximum. If the program is then still active,
the work process is restarted.
~Thank you
Lourd
Edited by: Lourd06 on Oct 23, 2009 11:22 AM
Edited by: Lourd06 on Oct 23, 2009 11:33 AM -
Invalid statement in Performance Tuning Guide
Oracle® Database Performance Tuning Guide
10g Release 2 (10.2)
Part Number B14211-01
13 The Query Optimizer
http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/optimops.htm#sthref1324
excerpt:
"You can specify fast full index scans with the initialization parameter OPTIMIZER_FEATURES_ENABLE or the INDEX_FFS hint. Fast full index scans cannot be performed against bitmap indexes."
Emphasis mine - Gints
Here is counterexample:
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> create table blah (sex varchar2(1) not null, data varchar2(4000));
Table created.
SQL> insert into blah select 'F', lpad('a', 4000, 'a') from user_objects where rownum<=10;
10 rows created.
SQL> insert into blah select 'M', lpad('a', 4000, 'a') from user_objects where rownum<=10;
10 rows created.
SQL> commit;
Commit complete.
SQL> create bitmap index sexidx on blah(sex);
Index created.
SQL> exec dbms_stats.gather_table_stats(user, 'blah', cascade=>true)
PL/SQL procedure successfully completed.
SQL>
SQL> set autot traceonly expl
SQL> set lines 100
SQL> select count(*) from blah where sex = 'F';
SQL> /
Execution Plan
Plan hash value: 1028317341
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 2 | 1 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 2 | | |
| 2 | BITMAP CONVERSION COUNT | | 10 | 20 | 1 (0)| 00:00:01 |
|* 3 | BITMAP INDEX FAST FULL SCAN| SEXIDX | | | | |
Predicate Information (identified by operation id):
3 - filter("SEX"='F')
SQL> set autot off
SQL> alter session set events '10046 trace name context forever, level 12';
Session altered.
SQL> select count(*) from blah where sex = 'F';
COUNT(*)
10
SQL> disconn
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining optionsand here is relevant section from tkprofed trace file assuring that bitmap index fast full scan really was performed.
select count(*)
from
blah where sex = 'F'
call count cpu elapsed disk query current rows
Parse 1 0.00 0.02 0 0 0 0
Execute 1 0.00 0.03 0 0 0 0
Fetch 2 0.00 0.00 0 3 0 1
total 4 0.00 0.05 0 3 0 1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 60
Rows Row Source Operation
1 SORT AGGREGATE (cr=3 pr=0 pw=0 time=74 us)
1 BITMAP CONVERSION COUNT (cr=3 pr=0 pw=0 time=55 us)
1 BITMAP INDEX FAST FULL SCAN SEXIDX (cr=3 pr=0 pw=0 time=43 us)(object id 98446)Gints Plivna
http://www.gplivna.euHello Gints. I've reported this to the writer responsible for the Performance Tuning Guide. One of us will get back to you with the resolution.
Regards,
Diana -
Code tuning on SELECT SINGLE statement
Hi,
Is there a way to optimize a SINGLE SELECT statement ?
SELECT SINGLE pernr bukrs FROM pa0001
INTO (it_pernr-pernr,it_pernr-bukrs)
WHERE pernr = lv_pa9070-pernr
AND endda GE lv_yhr_py_pdidom-begda
AND begda LE lv_yhr_py_pdidom-endda.
APPEND it_pernr.
Thanks in advance for your help.
ThibaultWhat do you mean by optimize? Runtime?
If the statement is inside a huge loop, there could be room for improvement.
Please describe the actual problem in detail.
Also look into the ABAP performance forum and Please Read before Posting in the Performance and Tuning Forum.
Thomas -
Error ORA-29900 when tuning spatial sql statement for tuning task
I am trying to tune a SQL statement and getting ORA-29900: operating binding does not exist and PLS-306 wrong number of arguments in call to SDO_FILTER. Oracle Version 11.1.
Query trying to tune:
Select ROUTE_LINK_ID,ROUTE_ID,ROUTE_SYSTEM_ID,ROUTE_SYSTEM_NAME,ASSIGNED_ROUTES_ID,
GEOGRAPHIC_EXTENT_ID,GEOGRAPHIC_EXTENT_NAME,ROUTE_NAME,ROUTE_DIRECTION,FULL_NAME,
OFFICIAL_NAME,ROUTE_LINK_ID,ORDINAL,DISTANCE,RELATIVE_DIRECTION,TRANSPORT_LINK_ID,
GEOMETRY_GA_TW From IDOTLRS.ROUTE_DETAIL A where (ROUTE_SYSTEM_ID=8) AND
MDSYS.SDO_FILTER(A.GEOMETRY_GA_TW, :GeometryFilter, 'querytype=window') = 'TRUE';
Example query with bind variable populated:
Select ROUTE_LINK_ID,ROUTE_ID,ROUTE_SYSTEM_ID,ROUTE_SYSTEM_NAME,ASSIGNED_ROUTES_ID,
GEOGRAPHIC_EXTENT_ID,GEOGRAPHIC_EXTENT_NAME,ROUTE_NAME,ROUTE_DIRECTION,FULL_NAME,
OFFICIAL_NAME,ROUTE_LINK_ID,ORDINAL,DISTANCE,RELATIVE_DIRECTION,TRANSPORT_LINK_ID,
GEOMETRY_GA_TW From IDOTLRS.ROUTE_DETAIL A where (ROUTE_SYSTEM_ID=1) AND
MDSYS.SDO_FILTER(A.GEOMETRY_GA_TW, SDO_GEOMETRY (2003, 1050010, NULL, sdo_elem_info_array (1, 1003, 3), sdo_ordinate_array (288325, 222066, 326949, 245295 )), 'querytype=window') = 'TRUE';
--Tuning Task that throws error ORA-29900
DECLARE
my_task_name VARCHAR2(30);
my_sqltext CLOB;
BEGIN
GeometryFilter := 'MDSYS.SDO_GEOMETRY(2003,1050010,NULL,MDSYS.sdo_elem_info_array(1,1003,3),mdsys.sdo_ordinate_array(288325,222066,326949,245295))';
my_sqltext := 'Select ROUTE_LINK_ID,ROUTE_ID,ROUTE_SYSTEM_ID,ROUTE_SYSTEM_NAME,ASSIGNED_ROUTES_ID, GEOGRAPHIC_EXTENT_ID,GEOGRAPHIC_EXTENT_NAME,ROUTE_NAME,ROUTE_DIRECTION,FULL_NAME, OFFICIAL_NAME,ROUTE_LINK_ID,ORDINAL,DISTANCE,RELATIVE_DIRECTION,TRANSPORT_LINK_ID,GEOMETRY_GA_TW From IDOTLRS.ROUTE_DETAIL A where (ROUTE_SYSTEM_ID=1) AND MDSYS.SDO_FILTER(A.GEOMETRY_GA_TW, :GeometryFilter,''MASK=INSIDE'') = ''TRUE'' ';
my_task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK(
sql_text => my_sqltext,
bind_list => sql_binds(anyData.convertChar('MDSYS.SDO_GEOMETRY(2003,1050010,NULL,MDSYS.sdo_elem_info_array(1,1003,3),mdsys.sdo_ordinate_array(288325,222066,326949,245295))')),
user_name => 'IDOTLRS',
scope => 'COMPREHENSIVE',
time_limit => 240,
task_name => 'lrs_tuning_task_27',
description => 'Task to tune a query on delete');
END;
BEGIN
DBMS_SQLTUNE.EXECUTE_TUNING_TASK( task_name => 'lrs_tuning_task_27' );
END;
any advice would be appreciated to get the tuning task functioning.
thanks in advance.convertObject allowed EXECUTE_TUNING_TASK to run, but stops with an end of file communication. I need to look and see why.
ORA-03113: end-of-file on communication channel
Process ID: 4676
Session ID: 510 Serial number: 60166
I will try the other option and see what happens.
Will file a bug....
Edited by: Eric Abrams on Sep 27, 2011 7:33 AM
Appears to be logged.
ORA-03113 reported when Enequeueing an ADT which contains a SYS.ANYDATA type [ID 799393.1], unpublished Bug 6830995
Edited by: Eric Abrams on Sep 27, 2011 7:41 AM
Edited by: Eric Abrams on Sep 27, 2011 7:42 AM -
Tuning a stubborn SQL statement
Hello,
I have performance problems with this SQL statement:
SELECT
T_00 . "FBRNR" , T_00 . "FBFNR" , T_01 . "DIVISION" , T_01 . "SERVCODE" , T_01 . "KUNSND" ,
T_01 . "KUNRCV" , T_01 . "KUNREG" , T_01 . "LFBED" , T_00 . "ABRDAT" , T_01 . "REGNL"
FROM
"ZFBINFO" T_00 , "ZFBDT" T_01
WHERE
( T_01 . "MANDT" = :A0 AND T_00 . "FBRNR" = T_01 . "FBRNR" AND T_00 . "FBFNR" = T_01 . "FBFNR" )
AND T_00 . "MANDT" = :A1 AND "DIVISION" = :A2 AND T_00 . "FBSTAT" <= :A3;
On Oracle 9i it ran within 90 seconds and the execution plan was this:
Execution Plan
Plan hash value: 298645010
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1525K| 141M| 5595K (1)| 09:33:38 |
| 1 | NESTED LOOPS | | 1525K| 141M| 5595K (1)| 09:33:38 |
| 2 | TABLE ACCESS BY INDEX ROWID| ZFBINFO | 9152K| 305M| 97247 (1)| 00:09:59 |
|* 3 | INDEX RANGE SCAN | ZFBINFO~B | 9152K| | 6121 (2)| 00:00:38 |
|* 4 | TABLE ACCESS BY INDEX ROWID| ZFBDT | 1 | 62 | 1 (0)| 00:00:01 |
|* 5 | INDEX UNIQUE SCAN | ZFBDT_____0 | 1 | | 0 (0)| 00:00:01 |
Statistics
1 recursive calls
0 db block gets
302386 consistent gets
19689 physical reads
After an upgrade to Oracle 10g the statement runs for more than 8 minutes and the execution plan is like this:
Execution Plan
Plan hash value: 4079065069
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost(%CPU)| Time |
| 0 | SELECT STATEMENT | | 1525K| 141M| | 909K (4)| 01:33:13 |
|* 1 | HASH JOIN | | 1525K| 141M| 410M| 909K (4)| 01:33:13 |
| 2 | TABLE ACCESS BY INDEX ROWID| ZFBINFO | 9152K| 305M| | 97247 (1)| 00:09:59 |
|* 3 | INDEX RANGE SCAN | ZFBINFO~B | 9152K| | | 6121 (2)| 00:00:38 |
|* 4 | TABLE ACCESS FULL | ZFBDT | 25M| 1535M| | 716K (4)| 01:13:26 |
Statistics
495 recursive calls
66 db block gets
4709177 consistent gets
4691042 physical reads
I have asked the SQL Tuning Advisor to tune this statement on Oracle 10g, but it
believes the "TABLE ACCESS FULL" on table ZFBDT is the best way for this statement.
The index ZFBDT_____0 is defined on columns MANDT, FBRNR, FBFNR, so not suprisingly
if I add a hint manually /+INDEX(T_01, "ZFBDT_____0") / then the statement runs 5 times
faster and requires only very few physical and logical reads.
How can I convince the Oracle 10g optimizer to use the primary key index on ZFBDT?
Regards,
MarkHello Martin,
the tables ZFBDT and ZFBINFO have got 155 million rows. When
checking the bind variables I can see the condition FBSTAT<=70.
The SQL statement selects only 58000 entries from table ZFBINFO:
FB COUNT(*)
00 3
10 33151
20 5657
28 28
30 11971
40 1734
50 163
55 5934
72 437
73 17355
74 49113
75 24438
76 529
78 122828
80 139801614
82 11099678
85 3054910
90 1627482
So I say the selection on FBSTAT is really selective.
However, I don't see how manipulating the CBO statistics
(as described in SAP note 724545) would help here.
Regards,
Mark -
SQL Tuning Advisor evaluates statement using wrong plan_hash_value
The execution plan for one of my SQL statements changed this morning. The statement is in a third-party package. The new plan runs worse than the old plan. I had the SQL tuning advisor evaluate the statement. I ran it three times. Each time it evaluated the original plan, not the new one. I can tell that because the plan_hash_value shown in the advisor's recommendations is the old plan's plan_hash_value. The old plan no longer appears in DBA_HIST_SQL_PLAN. I do not understand why the advisor is using the original plan, nor where it is getting it. It does not show up in Oracle Enterprise Manager either.
Has anyone see this before?
Do you have any suggestions how I can force the advisor to evaluate the new execution plan?
I am running Oracle Database Server 10gR2 Enterprise Edition.
Thanks,
BillFollowing advice given earlier, I ran the SQL Tuning Advisor by executing DBMS_SQLTUNE from within a SQL*Plus session instead of via Oracle Enterprise Manager. The problem I originally encountered in OEM also happened using DBMS_SQLTUNE. Using DBMS_SQLTUNE I specified plan_hash_value => '3657286666' but the results of running create_tuning_task shows that the utility used a different plan_hash_value. See below:
Based on this, I think the problem I originally blamed on OEM's creation of a SQL Tuning Advisor job was misdirected. I now believe that OEM supplied the proper information to the advisor, but the advisor did not correctly use what is was given.
Below is what I submitted when I ran create_tuning_task and execute_tuning_task. Note that the value assigned to plan_hash_value is 3657286666. Following the messages from execute_tuning_task, see the output produced by the execution of report_tuning_task. In EXPLAIN PLANS SECTION heading 1 - ORIGINAL, note that Plan Hash Value = 3541843898.
I submitted instructions to use plan_hash_value 3657286666 but instead it used 3541843898. Why did it do this??????
I have not found a published bug that describes this condition.
Thanks,
Bill
SQL> DECLARE
2 stmt_task VARCHAR2(64);
3 BEGIN
4 stmt_task:=dbms_sqltune.create_tuning_task(sql_id => 'ab30ujpshkur3', plan_hash_
value => '3657286666', time_limit => 3600, task_name => 'Tune_ab30ujpshkur3_3657286666'
, description => 'Task to tune sql_id ab30ujpshkur3 plan_hash_value 3657286666');
5 END;
6 /
PL/SQL procedure successfully completed.
SQL> EXECUTE dbms_sqltune.execute_tuning_task('Tune_ab30ujpshkur3_3657286666');
PL/SQL procedure successfully completed.
Here is the output produced by report_tuning_task:
SQL> SET linesize 200
SQL> SET LONG 999999999
SQL> SET pages 1000
SQL> SET longchunksize 20000
SQL> SELECT dbms_sqltune.report_tuning_task('Tune_ab30ujpshkur3_3657286666', 'TEXT', 'ALL') FROM dual;
SELECT dbms_sqltune.script_tuning_task('Tune_ab30ujpshkur3_3657286666', 'ALL')
FROM dual;
DBMS_SQLTUNE.REPORT_TUNING_TASK('TUNE_AB30UJPSHKUR3_3657286666','TEXT','ALL')
GENERAL INFORMATION SECTION
Tuning Task Name : Tune_ab30ujpshkur3_3657286666
Tuning Task Owner : EXPTEST
Tuning Task ID : 110190
Scope : COMPREHENSIVE
Time Limit(seconds) : 3600
Completion Status : COMPLETED
Started at : 08/03/2012 14:47:45
Completed at : 08/03/2012 14:48:54
Number of Index Findings : 1
Schema Name: EXPTEST
SQL ID : ab30ujpshkur3
SQL Text : SELECT ATTACHED_ACC_ID FROM SERVICE_EVENTS WHERE TSERV_ID = :B4
AND EQ_NBR = :B3 AND ASSOC_EQ_NBR = :B2 AND (PERFORMED <= :B1 +
1/1440 AND PERFORMED >= :B1 - 1/1440)
FINDINGS SECTION (1 finding)
1- Index Finding (see explain plans section below)
The execution plan of this statement can be improved by creating one or more
indices.
Recommendation (estimated benefit: 100%)
- Consider running the Access Advisor to improve the physical schema design
or creating the recommended index.
create index EXPTEST.IDX$$_1AE6E0001 on
EXPTEST.SERVICE_EVENTS('EQ_NBR','ASSOC_EQ_NBR');
Rationale
Creating the recommended indices significantly improves the execution plan
of this statement. However, it might be preferable to run "Access Advisor"
using a representative SQL workload as opposed to a single statement. This
will allow to get comprehensive index recommendations which takes into
account index maintenance overhead and additional space consumption.
EXPLAIN PLANS SECTION
1- Original
Plan hash value: 3541843898
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
| 0 | SELECT STATEMENT | | 1 | 32 | 4 (0)|
00:00:01 |
|* 1 | FILTER | | | | |
|
|* 2 | TABLE ACCESS BY INDEX ROWID| SERVICE_EVENTS | 1 | 32 | 4 (0)|
00:00:01 |
|* 3 | INDEX RANGE SCAN | SEVENTS_PERFORMED | 18 | | 2 (0)|
00:00:01 |
Query Block Name / Object Alias (identified by operation id):
1 - SEL$1
2 - SEL$1 / SERVICE_EVENTS@SEL$1
3 - SEL$1 / SERVICE_EVENTS@SEL$1
Predicate Information (identified by operation id):
1 - filter(:B1+.000694444444444444444444444444444444444444>=:B1-.0006944444444444444
444
44444444444444444444)
2 - filter("EQ_NBR"=:B3 AND "ASSOC_EQ_NBR"=:B2 AND "TSERV_ID"=:B4)
3 - access("PERFORMED">=:B1-.000694444444444444444444444444444444444444 AND
"PERFORMED"<=:B1+.000694444444444444444444444444444444444444)
Column Projection Information (identified by operation id):
1 - "ATTACHED_ACC_ID"[VARCHAR2,12]
2 - "ATTACHED_ACC_ID"[VARCHAR2,12]
3 - "SERVICE_EVENTS".ROWID[ROWID,10]
2- Using New Indices
Plan hash value: 2568062050
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| T
ime |
| 0 | SELECT STATEMENT | | 1 | 32 | 2 (0)| 0
0:00:01 |
|* 1 | FILTER | | | | |
|
|* 2 | TABLE ACCESS BY INDEX ROWID| SERVICE_EVENTS | 1 | 32 | 2 (0)| 0
0:00:01 |
|* 3 | INDEX RANGE SCAN | IDX$$_1AE6E0001 | 1 | | 2 (0)| 0
0:00:01 |
Query Block Name / Object Alias (identified by operation id):
1 - SEL$1
2 - SEL$1 / SERVICE_EVENTS@SEL$1
3 - SEL$1 / SERVICE_EVENTS@SEL$1
Predicate Information (identified by operation id):
1 - filter(:B1+.000694444444444444444444444444444444444444>=:B1-.0006944444444444444
4
4444444444444444444444)
2 - filter("TSERV_ID"=:B4 AND "PERFORMED">=:B1-.000694444444444444444444444444444444
4
44444 AND "PERFORMED"<=:B1+.000694444444444444444444444444444444444444)
3 - access("EQ_NBR"=:B3 AND "ASSOC_EQ_NBR"=:B2)
Column Projection Information (identified by operation id):
1 - "ATTACHED_ACC_ID"[VARCHAR2,12]
2 - "ATTACHED_ACC_ID"[VARCHAR2,12]
3 - "SERVICE_EVENTS".ROWID[ROWID,10]
SQL> 2
DBMS_SQLTUNE.SCRIPT_TUNING_TASK('TUNE_AB30UJPSHKUR3_3657286666','ALL')
-- Script generated by DBMS_SQLTUNE package, advisor framework --
-- Use this script to implement some of the recommendations --
-- made by the SQL tuning advisor. --
-- NOTE: this script may need to be edited for your system --
-- (index names, privileges, etc) before it is executed. --
create index EXPTEST.IDX$$_1AE6E0001 on EXPTEST.SERVICE_EVENTS('EQ_NBR','ASSOC_EQ_NBR')
; -
SQL Tuning Advisor on a specific SQL statement
Hi all,
How can I used SQL Tuning Advisor in Oracle EM Database Control to tune a specific SQL statement; i.e. the statement is not any of: Top SQL, SQL Tuning Sets, Snapshots Preserved Snapshot Sets.
Thanks in advance,
Ahmed B.Hi,
You can use either the automatic SQL tuning features that are accessible from Enterprise Manager Database Console on the "Advisor Central" page or trough SQL*PLUS using the DBMS_SQLTUNE pakage:
-- creating the tuning task
set serveroutput on
declare
l_sql_tune_task_id varchar2(100);
begin
l_sql_tune_task_id := dbms_sqltune.create_tuning_task (
sql_id => '<your_sql_id>',
scope => dbms_sqltune.scope_comprehensive,
time_limit => 60,
task_name => '<your_tuning_task_name>',
description => 'tuning task for statement your_sql_id.');
dbms_output.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
end;
-- executing the tuning task
exec dbms_sqltune.execute_tuning_task(task_name => '<your_tuning_task_name>');
-- displaying the recommendations
set long 100000;
set longchunksize 1000
set pagesize 10000
set linesize 100
select dbms_sqltune.report_tuning_task('<your_tuning_task_name>') as recommendations from dual;For more information, take a look at link provided by Jaffy.
Cheers
Legatti
Maybe you are looking for
-
Satellite Pro A200 Windows XP, 4Gb SDHC Card does not work.
Hi, I have had a Satellite Pro A200 installed with Windows XP, SP2 for some time - No problems there, a great piece of kit. However I recently have bought a new camera and splashed out on a Kingston 4Gb SDHC card. The manual for my A200 seemes to ind
-
How to insert a Carriage Return + Line Feed inside a TextView UI element ?
Hello All, Does anyone know how can I achieve the above scenario ? I have a string variable that collects and appeneds text messages from various BAPI calls. At the end of the process, the contents of this variable will be mapped to a textview. Pro
-
Difference between XI 3.0 and PI 7.0
Hi, What is difference between XI 3.0 and PI 7.0 Is this way we check version: System-- Staus -- Component Information -- PI_BASIS -- 2005_1_700 So the above system is PI 7.0 -- right? Regards
-
How to run custom Oracle report6i concurrent program in web forms
I developed a custom report using oracle6i and registered into AOL and assigned to a request group. I can run this concurrent program from form based application works fine. How to run this concurrent request from web forms? What are the steps to fol
-
I am working with a slide 800x600 in Captivate 6.0.1.240 on a Windows 7 machine. The working slide is the layout I want. But the filmstrip shows the slide size that is displayed and it crops off the working slide evenly on all sides. How do I change