Thinking Out Loud

November 2, 2016

Identify SQL_ID from Failed Per-SQL Time Limit SQL_TUNING_TASK

Filed under: 11g,oracle,performance — mdinh @ 2:32 am

First, many thanks to Ivica Arsov from Pythian for all his help is solving the issue.

The objective is to find the 2 SQLs failed due to time limit.

Advance apologies for lazy post as I am just going to only provide references and results from triage.

$ oerr ora 16957
16957, 00000, "SQL Analyze time limit interrupt"
// *Cause: This is an internal error code used indicate that SQL analyze has
//         reached its time limit.
// *Action:

$ oerr ora 13639
13639, 00000, "The current operation was interrupted because it timed out."
// *Cause:  The task or object operation timed out.
// *Action: None

+++++++++++

SQL> 
SELECT DBMS_AUTO_SQLTUNE.report_auto_tuning_task FROM dual;

REPORT_AUTO_TUNING_TASK
--------------------------------------------------------------------------------
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name                        : SYS_AUTO_SQL_TUNING_TASK
Tuning Task Owner                       : SYS
Workload Type                           : Automatic High-Load SQL Workload
Execution Count                         : 39
Current Execution                       : EXEC_17554
Execution Type                          : TUNE SQL
Scope                                   : COMPREHENSIVE
Global Time Limit(seconds)              : 14400
Per-SQL Time Limit(seconds)             : 2700
Completion Status                       : INTERRUPTED
Started at                              : 10/20/2016 22:00:01
Completed at                            : 10/21/2016 02:00:03
Number of Candidate SQLs                : 248
Cumulative Elapsed Time of SQL (s)      : 4837418

-------------------------------------------------------------------------------
Error: ORA-13639: The current operation was interrupted because it timed out.
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
SUMMARY SECTION
-------------------------------------------------------------------------------
                      Global SQL Tuning Result Statistics
-------------------------------------------------------------------------------
Number of SQLs Analyzed                      : 130
Number of SQLs in the Report                 : 23
Number of SQLs with Findings                 : 22
Number of SQLs with Statistic Findings       : 2
Number of SQLs with Alternative Plan Findings: 5
Number of SQLs with SQL profiles recommended : 14
Number of SQLs with Index Findings           : 11
Number of SQLs with SQL Restructure Findings : 3
Number of SQLs with Timeouts                 : 2
Number of SQLs with Errors                   : 1


Here are the references and what have been attempted.
It looks like attr7 varies by versions.

+++++++++

Automatic SQL Tune Job Fails With ORA-13639 (Doc ID 1363111.1)
Increase the job "Time Limit" Parameter to appropriate higher value to allow the tuning task to complete , using the following command :

Global Time Limit(seconds)              : 14400
Per-SQL Time Limit(seconds)             : 2700
Number of SQLs with Timeouts            : 2

+++++++

https://anargodjaev.wordpress.com/2014/07/22/ora-16957-sql-analyze-time-limit-interrupt-2/

SQL> r
  1  SELECT sql_id, sql_text FROM dba_hist_sqltext
  2  WHERE sql_id IN (SELECT attr1 FROM dba_advisor_objects
  3  WHERE execution_name = 'EXEC_17554'
  4  AND task_name = 'SYS_AUTO_SQL_TUNING_TASK'
  5  AND type = 'SQL' AND bitand(attr7,64) <> 0 )
  6*

no rows selected

SQL>

++++++++++

Bug 9874145 : PROCESS 0X0X00000002E2392938 APPEARS TO BE HUNG IN AUTO SQL TUNING TASK   
Product Version    11.1.0.7

SQL> select attr1 SQL_ID from dba_advisor_objects
  where task_name ='SYS_AUTO_SQL_TUNING_TASK'
  and type = 'SQL'
  and attr7 = 32
  order by 1;
 
SQL> r
  1* select attr7, count(*) from DBA_ADVISOR_OBJECTS where execution_name='EXEC_17554' and task_name ='SYS_AUTO_SQL_TUNING_TASK' and type='SQL' group by attr7

     ATTR7   COUNT(*)
---------- ----------
    32       99
     0       31

SQL> r
  1  SELECT count(sql_id)  FROM dba_hist_sqltext
  2  WHERE sql_id IN (SELECT attr1 FROM dba_advisor_objects
  3  WHERE execution_name = 'EXEC_17554'
  4  AND task_name = 'SYS_AUTO_SQL_TUNING_TASK'
  5  AND type = 'SQL' AND bitand(attr7,32) <> 0 )
  6*

COUNT(SQL_ID)
-------------
       99

SQL> r
  1  select  distinct sql_id
  2  from    DBA_ADVISOR_SQLPLANS
  3  where   execution_name = 'EXEC_17554'
  4         and sql_id not in (select sql_id from dba_advisor_sqlstats where execution_name = 'EXEC_17554')
  5*

SQL_ID
-------------
2dhfrqwrv0m16
58h2g858zqckc
apzyk43bfp6np
g84pgjy5ycw2g
20ypq7mzad6ah
cr1s7zpp7285p
ag01z6qn8450d
4z3gq9xh9a5jr
byav70kx3bj8w
8m3qru4z4687w
d28dgmyr5910n
5mgq2hd4xz6vv

12 rows selected.

SQL>

++++++++++

SQL> select sql_id from DBA_ADVISOR_SQLPLANS where EXECUTION_NAME='EXEC_17554'
minus
select sql_id from DBA_ADVISOR_SQLSTATS where EXECUTION_NAME='EXEC_17554'
;  2    3    4

SQL_ID
-------------
20ypq7mzad6ah
2dhfrqwrv0m16
4z3gq9xh9a5jr
58h2g858zqckc
5mgq2hd4xz6vv
8m3qru4z4687w
ag01z6qn8450d
apzyk43bfp6np
byav70kx3bj8w
cr1s7zpp7285p
d28dgmyr5910n
g84pgjy5ycw2g

12 rows selected.

SQL> select sql_id from DBA_ADVISOR_SQLSTATS where EXECUTION_NAME='EXEC_17554'
minus
select sql_id from DBA_ADVISOR_SQLPLANS where EXECUTION_NAME='EXEC_17554'
;  2    3    4

no rows selected

SQL>

++++++++++

case when finding_type = 3 AND bitand(finding_flags, 2) <> 0 then 1 else 0 end

1 - has timeout
0 - no timeout

finding_type and finding_flags are from sys.wri$_adv_findings table.

SQL> r
  1* select distinct TYPE, FLAGS from sys.wri$_adv_findings

      TYPE    FLAGS
---------- ----------
     4        1
     1        0
     4
     4        4
     2        0
     5        0
     2
     3        0
     4        0
     3        2
     4        9
     1
     3       16

13 rows selected.

SQL> r
  1  SELECT oe.*,
  2          f.id finding_id,
  3          f.type finding_type,
  4          f.flags finding_flags
  5  FROM
  6    (SELECT
  7       o.exec_name ,
  8        o.id object_id,
  9        o.attr1 sql_id,
 10        o.attr3 parsing_schema,
 11        to_number(NVL(o.attr5, '0')) phv,
 12        NVL(o.attr8,0) obj_attr8
 13      FROM  sys.wri$_adv_objects o
 14      WHERE o.exec_name = 'EXEC_17554'
 15      AND o.type      = 7
 16    ) oe,
 17    wri$_adv_findings f
 18  WHERE  f.exec_name (+)  = oe.exec_name
 19  AND f.obj_id (+)     = oe.object_id
 20  AND type             = 3
 21  AND bitand(flags,2) <> 0
 22*

EXEC_NAME        OBJECT_ID SQL_ID          PARSING_SCHEMA         PHV  OBJ_ATTR8 FINDING_ID FINDING_TYPE FINDING_FLAGS
--------------- ---------- --------------- --------------- ---------- ---------- ---------- ------------ -------------
EXEC_17554           29975 bxurwhv4muqj5   DEMO1234        2724156332 2438782765      31681            3             2
EXEC_17554           30015 1gzgzfuxn18v1   DEMO345670      4228937525 3182936792      31724            3             2

SQL> 
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: