Pages

Saturday, May 16, 2020

SQL investigation for my reference


SELECT plan_hash_value,
       child_number,
       INVALIDATIONS,
       is_obsolete,
       IS_BIND_SENSITIVE,
       FIRST_LOAD_TIME,
       LAST_LOAD_TIME,
       LAST_ACTIVE_TIME,
       LOADS
  FROM v$sql
 WHERE sql_id = '530ubrcgf9tbw'


--One row per child for SQL_ID
SELECT *
  FROM V$SQL
 WHERE sql_id = '530ubrcgf9tbw'

-- Each child execution plan for the SQL
SELECT *
  FROM V$SQL_PLAN
 WHERE sql_id = '530ubrcgf9tbw'

-- Know Reason for Child cursors
select * from V$SQL_SHARED_CURSOR where sql_id='530ubrcgf9tbw';

--single line per SQL ID execution and other stats
-- Historical DBA_HIST_SQLSTAT
SELECT *
  FROM V$SQLSTATS
 WHERE sql_id = '530ubrcgf9tbw'

-- One row for SQL ID and plan_hash, if two plans for the same SQLID two lines with each plan
select * from V$SQLSTATS_PLAN_HASH where sql_id='530ubrcgf9tbw';

 --Bind values for the SQL
select * from V$SQL_BIND_CAPTURE   where sql_id='530ubrcgf9tbw';

-- distinct plan_hash_value for a SQL_ID
SELECT sql_id,
         parsing_schema_name parsing_schema,
         COUNT (DISTINCT (plan_hash_value)) "no_of_plans"
    FROM v$sql
   WHERE parsing_schema_name = 'SCOTT'
GROUP BY sql_id, parsing_schema_name
ORDER BY 3 DESC;


https://blogs.oracle.com/optimizer/adaptive-cursor-sharing-acs-and-bind-sensitivity
https://www.oracle.com/technical-resources/articles/database/sql-11g-sqlplanmanagement.html
https://tanelpoder.com/oracle-sql-plan-stability/

Column PLAN_HASH_VALUE IN V$SQLSTATS Continuously Changes (Doc ID 1345516.1)
Rolling Cursor Invalidations with DBMS_STATS.AUTO_INVALIDATE (Doc ID 557661.1)