[20200129] sub cursor does not share bind_ EQUIV_ FAILURE.txt

Time:2021-3-4

[20200129] sub cursor does not share bind_ EQUIV_ FAILURE.txt

–//The production system encountered a large number of bind again_ EQUIV_ Failure causes a sub cursor. I looked at the situation I encountered in my previous tests.
–//Links http://blog.itpub.net/267265/viewspace-2156139/ =>[20180613] sub cursor does not share bind_ EQUIV_ FAILURE。
–//Other people have suggested to me that the problem may lie in alter session set statistics_ For the level = all; setting, I’ll repeat the test.

1. Environment:
[email protected]> @ ver1
PORT_STRING          VERSION    BANNER                                                                       CON_ID
——————– ———- —————————————————————————- ——
IBMPC/WIN_NT64-9.1.0 12.2.0.1.0 Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 – 64bit Production      0

[email protected]> @ hide _cursor_obsolete_threshold
NAME                       DESCRIPTION                                     DEFAULT_VALUE SESSION_VALUE SYSTEM_VALUE ISSES ISSYS_MOD
————————– ———————————————– ————- ————- ———— —– ———
_cursor_obsolete_threshold Number of cursors per parent before obsoletion. TRUE          8192          8192         TRUE  FALSE

/*
grant execute on sys.dbms_lock to scott;

CREATE OR REPLACE FUNCTION sleep1 (seconds IN NUMBER)
RETURN NUMBER
is
d_date date;
BEGIN
  select sysdate into d_date from dual;
  sys.dbms_lock.sleep(seconds/10);
  RETURN seconds;
END;
/

CREATE OR REPLACE FUNCTION sleep (seconds IN NUMBER)
RETURN NUMBER
is
d_date date;
BEGIN
  select sysdate into d_date from dual;
–//sys.dbms_lock.sleep(0.01);
  RETURN seconds;
END;
/
*/
–//Note: at that time, the test executed the above code for other reasons, but now the test is not needed.

create table t as select rownum id1,mod(rownum-1,1000)+1 id2 from dual connect by level<=2000;

[email protected]> select * from dba_extents where owner=user and segment_name=’T’
  2  @ prxx
==============================
OWNER                         : SCOTT
SEGMENT_NAME                  : T
PARTITION_NAME                :
SEGMENT_TYPE                  : TABLE
TABLESPACE_NAME               : USERS
EXTENT_ID                     : 0
FILE_ID                       : 11
BLOCK_ID                      : 176
BYTES                         : 65536
BLOCKS                        : 8
RELATIVE_FNO                  : 11
PL/SQL procedure successfully completed.

2. Build test script
–//Create script by.txt , annotate alter session set statistics_ level=all;:
set term off
–//alter session set statistics_level=all;
variable x number;
exec 😡 := &&1;
SElect t.* from t where id2<=:x;
set term on
@ dpc ” ”
quit

–//Creating shell scripts by.sh :
#!/bin/bash
# rm -f ez.txt
for i in $(seq 1000)
do
    sqlplus -s -l scott/[email protected] @by.txt $i >> ez.txt
done
–//It’s a bit slow to test on your laptop at home, reducing the number of cycles to 1000.

3. Test:
–//Execute script by.sh .
$ grep “SQL_ID” ez.txt |  uniq -c
   1000 SQL_ID  ckynkwp4t00rz, child number 0
–//You can see that no child cursor is generated. It’s exactly what others say.

4. Continue testing:
–//Modify script by.txt . uncomment alter session set statistics_ level=all;.
set term off
alter session set statistics_level=all;
variable x number;
exec 😡 := &&1;
SElect t.* from t where id2<=:x;
set term on
@ dpc ” ”
quit

–//Refresh the shared pool 3 times.
alter session set statistics_level=all;
alter session set statistics_level=all;
alter session set statistics_level=all;

$ mv ez.txt ezold.txt

–//Execute script by.sh

$ grep “SQL_ID” ez.txt |  uniq -c
    500 SQL_ID  ckynkwp4t00rz, child number 0
     51 SQL_ID  ckynkwp4t00rz, child number 1
     56 SQL_ID  ckynkwp4t00rz, child number 2
     61 SQL_ID  ckynkwp4t00rz, child number 3
     67 SQL_ID  ckynkwp4t00rz, child number 4
     74 SQL_ID  ckynkwp4t00rz, child number 5
     81 SQL_ID  ckynkwp4t00rz, child number 6
     90 SQL_ID  ckynkwp4t00rz, child number 7
     20 SQL_ID  ckynkwp4t00rz, child number 8
–//In the process of execution, a large number of sub cursors can be found and appear

[email protected]> @ share ckynkwp4t00rz
old  15:           and q.sql_id like ”&1”’,
new  15:           and q.sql_id like ”ckynkwp4t00rz”’,
SQL_TEXT                       = SElect t.* from t where id2<=:x
SQL_ID                         = ckynkwp4t00rz
ADDRESS                        = 000007FF12B9AA10
CHILD_ADDRESS                  = 000007FF1265EDE8
CHILD_NUMBER                   = 0
LOAD_OPTIMIZER_STATS           = Y
REASON                         = 039Bind mismatch(25)0x0

extended_cursor_sharing

————————————————–
SQL_TEXT                       = SElect t.* from t where id2<=:x
SQL_ID                         = ckynkwp4t00rz
ADDRESS                        = 000007FF12B9AA10
CHILD_ADDRESS                  = 000007FF16F0F400
CHILD_NUMBER                   = 1
REASON                         = 139Bind mismatch(33)1×42540213050
————————————————–
SQL_TEXT                       = SElect t.* from t where id2<=:x
SQL_ID                         = ckynkwp4t00rz
ADDRESS                        = 000007FF12B9AA10
CHILD_ADDRESS                  = 000007FF13C989F8
CHILD_NUMBER                   = 2
BIND_EQUIV_FAILURE             = Y
REASON                         = 239Bind mismatch(33)1×42841161709
————————————————–

————————————————–
SQL_TEXT                       = SElect t.* from t where id2<=:x
SQL_ID                         = ckynkwp4t00rz
ADDRESS                        = 000007FF12B9AA10
CHILD_ADDRESS                  = 000007FF13F41A10
CHILD_NUMBER                   = 8
BIND_EQUIV_FAILURE             = Y
REASON                         =
————————————————–
PL/SQL procedure successfully completed.

$ grep “SQL_ID” ez.txt |  uniq -c | awk ‘{ sum=sum+$1};END {print sum}’
1000
–//Exactly 1000 times.
–//You can see that setting alter session set statistics_ Level = all; the sub cursor cannot be shared, and the specific reason is not clear.
–//I tested it many times and the result was the same.

5. How about establishing histogram?

[email protected]> execute sys.dbms_stats.gather_table_stats ( OwnName => user,TabName => ‘t’,Estimate_Percent => NULL,Method_Opt => ‘FOR ALL COLUMNS SIZE 1024 ‘,Cascade => True ,No_Invalidate => false)
PL/SQL procedure successfully completed.
–//12C can support more than 254 buckets

[email protected]> @ tab_lh scott t ”

DISPLAY TABLE_NAME OF COLUMN_NAME INFORMATION.
INPUT   OWNER TABLE_NAME COLUMN
SAMPLE  : @ TAB_LH TABLE_NAME [COLUMN_NAME]
IF NOT INPUT COLUMN_NAME ,USE “” .

COLUMN_NAME DATA_TYPE DATA_LENGTH N NUM_DISTINCT    DENSITY SAMPLE_SIZE TRANS_LOW TRANS_HIGH  NUM_NULLS NUM_BUCKETS LAST_ANALYZED       HISTOGRAM  DATA_DEFAULT
———– ——— ———– – ———— ———- ———– ——— ———- ———- ———– ——————- ———- ————————-
ID1         NUMBER             22 Y         2000      .0005        2000 1         2000                0        1024 2020-01-29 19:44:04 HYBRID
ID2         NUMBER             22 Y         1000     .00025        2000 1         1000                0        1000 2020-01-29 19:44:04 FREQUENCY

–//Refresh the shared pool 3 times.
alter session set statistics_level=all;
alter session set statistics_level=all;
alter session set statistics_level=all;

–//Execute script by.txt .
set term off
–//alter session set statistics_level=all;
variable x number;
exec 😡 := &&1;
SElect t.* from t where id2<=:x;
set term on
@ dpc ” ”
quit

$ mv ez.txt ez17.txt
$ grep “SQL_ID” ez.txt |  uniq -c
   1000 SQL_ID  ckynkwp4t00rz, child number 0
–//No child cursor is generated.

[email protected]> execute sys.dbms_stats.gather_table_stats ( OwnName => user,TabName => ‘t’,Estimate_Percent => NULL,Method_Opt => ‘FOR ALL COLUMNS SIZE 254 ‘,Cascade => True ,No_Invalidate => false)
PL/SQL procedure successfully completed.

[email protected]> @ tab_lh scott t ”

DISPLAY TABLE_NAME OF COLUMN_NAME INFORMATION.
INPUT   OWNER TABLE_NAME COLUMN
SAMPLE  : @ TAB_LH TABLE_NAME [COLUMN_NAME]
IF NOT INPUT COLUMN_NAME ,USE “” .
COLUMN_NAME DATA_TYPE DATA_LENGTH N NUM_DISTINCT    DENSITY SAMPLE_SIZE TRANS_LOW TRANS_HIGH NUM_NULLS NUM_BUCKETS LAST_ANALYZED       HISTOGRAM DATA_DEFAULT
———– ——— ———– – ———— ———- ———– ——— ———- ——— ———– ——————- ——— ————
ID1         NUMBER             22 Y         2000      .0005        2000 1         2000               0         254 2020-01-29 20:01:43 HYBRID
ID2         NUMBER             22 Y         1000       .001        2000 1         1000               0         254 2020-01-29 20:01:43 HYBRID

–//Refresh the shared pool 3 times.
alter session set statistics_level=all;
alter session set statistics_level=all;
alter session set statistics_level=all;

$ mv ez.txt ez18.txt

$ grep “SQL_ID” ez.txt |  uniq -c
   1000 SQL_ID  ckynkwp4t00rz, child number 0
–//No child cursor is generated.
–//That is, it has nothing to do with histogram.

6. Continue testing:
–//Cancel histogram setting.
[email protected]> execute sys.dbms_stats.gather_table_stats ( OwnName => user,TabName => ‘t’,Estimate_Percent => NULL,Method_Opt => ‘FOR ALL COLUMNS SIZE 1 ‘,Cascade => True ,No_Invalidate => false)
PL/SQL procedure successfully completed.

$ cat by.txt
set term off
alter session set statistics_level=all;
variable x number;
exec 😡 := &&1;
SElect t.* from t where id1<=:x;
set term on
@ dpc ” ”
quit

$ cat by.sh
#!/bin/bash
# rm -f ez.txt
for i in $(seq 2000 )
do
   sqlplus -s -l scott/[email protected] @by.txt $i >> ez.txt
done

alter system flush shared_pool;

–//Note that the novelty search condition is Id1 < =: X, and verify whether the sub cursor appears after x = 1000.

[email protected]> @ share basmuva6swhg4
SQL_TEXT                       = SElect t.* from t where id1<=:x
SQL_ID                         = basmuva6swhg4
ADDRESS                        = 000007FF1314E908
CHILD_ADDRESS                  = 000007FF13133298
CHILD_NUMBER                   = 0
LOAD_OPTIMIZER_STATS           = Y
REASON                         = 039Bind mismatch(25)0x0

extended_cursor_sharing

————————————————–
SQL_TEXT                       = SElect t.* from t where id1<=:x
SQL_ID                         = basmuva6swhg4
ADDRESS                        = 000007FF1314E908
CHILD_ADDRESS                  = 000007FF13270B40
CHILD_NUMBER                   = 1
REASON                         = 139Bind mismatch(33)1×43229815407
————————————————–
SQL_TEXT                       = SElect t.* from t where id1<=:x
SQL_ID                         = basmuva6swhg4
ADDRESS                        = 000007FF1314E908
CHILD_ADDRESS                  = 000007FF1343C4A0
CHILD_NUMBER                   = 2
BIND_EQUIV_FAILURE             = Y
REASON                         = 239Bind mismatch(33)1×42954937500
..
PL/SQL procedure successfully completed.

$ grep “SQL_ID” ez.txt |  uniq -c
   1000 SQL_ID  basmuva6swhg4, child number 0
    101 SQL_ID  basmuva6swhg4, child number 1
    111 SQL_ID  basmuva6swhg4, child number 2
    122 SQL_ID  basmuva6swhg4, child number 3
    134 SQL_ID  basmuva6swhg4, child number 4
    147 SQL_ID  basmuva6swhg4, child number 5
    162 SQL_ID  basmuva6swhg4, child number 6
    178 SQL_ID  basmuva6swhg4, child number 7
     45 SQL_ID  basmuva6swhg4, child number 8

$ grep “SQL_ID” ez.txt |  uniq -c | awk ‘BEGIN {a=909;} {sum=sum+$1;a=a*1.10;print  sum, a }’
1000 999.9
1101 1099.89
1212 1209.88
1334 1330.87
1468 1463.95
1615 1610.35
1777 1771.38
1955 1948.52
2000 2143.37

–//It can be seen that a rule returns 1000 records as the first threshold, and then increases by a ratio of 0.11 (the last line is not enough). Of course, this is just my guess.

7. Continue testing:
–//Turn over the execution and see, first execute 2000:
$ cat by.sh
#!/bin/bash
# rm -f ez.txt
for i in $(seq 2000 -1 1 )
do
        sqlplus -s -l scott/[email protected] @by.txt $i >> ez.txt
done

$ grep “SQL_ID” ez.txt |  uniq -c
   2000 SQL_ID  basmuva6swhg4, child number 0

–//No child cursor is generated.

Recommended Today

Practice analysis of rust built-in trait: partialeq and EQ

Abstract:Rust uses traits in many places, from simple operator overloading to subtle features like send and sync. This article is shared from Huawei cloud community《Analysis of rust built-in trait: partialeq and EQ》Author: debugzhang Rust uses traits in many places, from simple operator overloading to subtle features like send and sync. Some traits can be automatically […]