1

sql 语句有 2 个计划,一个较慢,一个较快。
通过使用哈希值,我尝试创建基线,我收到如下错误:

ERROR at line 1:
ORA-13767: End snapshot ID must be greater than begin snapshot ID.
ORA-06512: at "SYS.DBMS_SQLTUNE", line 4715
ORA-06512: at line 21

并发现
我想要创建基线的计划的最小和最大快照 ID 是相同的。

在这种情况下,用我想要的计划创建基线的方法是什么?

谢谢您的帮助!

4

1 回答 1

1

-- 为了避免出现:ORA-13767:结束快照 ID 必须大于开始快照 ID。-- 如果 snap_ids 相同,则将 begin snap id 减一

BEGIN -- 如果它不在 V$SQL 中,我们将不得不查询工作负载存储库 select count(*) into cnt from V$SQLSTATS where sql_id = '&&sqlid';

IF (cnt > 0) THEN :task_name := dbms_sqltune.create_tuning_task(sql_id => '&&sqlid',scope => DBMS_SQLTUNE.scope_comprehensive,time_limit => 7200); ELSE select min(snap_id) into bsnap from dba_hist_sqlstat where sql_id = '&&sqlid';

select max(snap_id) into esnap
from   dba_hist_sqlstat
where  sql_id = '&&sqlid';

-- in order to avoid an: ORA-13767: End snapshot ID must be greater than begin snapshot ID.
-- if the snap_ids are the same, then lower the begin snap id by one
if (:bsnap = :esnap) then
   :bsnap := :bsnap - 1;
end if;

:task_name := dbms_sqltune.create_tuning_task(begin_snap => :bsnap,
                                              end_snap => :esnap,
                                              time_limit => 7200,
                                              sql_id => '&&sqlid',
                                              scope => DBMS_SQLTUNE.scope_comprehensive);

万一;

dbms_sqltune.execute_tuning_task(:task_name);

于 2020-05-26T12:39:18.110 回答