[20220422]為什麼執行不報錯.txt
[20220422]為什麼執行不報錯.txt
--//生產系統1條sql語句,明視訊記憶體在隱式轉換,而且這個轉換無法進行的,但是我奇怪的是執行不報錯。
1.環境:
> @ ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
2.分析:
> @ sql_id 0818yxqmw7n43
--SQL_ID = 0818yxqmw7n43
select c.brch,
c.brxm,
a.tmbh,
a.examinaim,
null cause,
a.requesttime,
null register_time,
null report_person,
:"SYS_B_0" clyj,
a.doctrequestno
from l_lis_sqd a ,
zy_brry c
where a.patientid = c.zyhm
and a.qrht is null
and c.brbq = :al_brbq and c.brxm =:"SYS_B_1";
> @ bind_cap 0818yxqmw7n43 ''
SQL_ID CHILD_NUMBER WAS NAME POSITION MAX_LENGTH LAST_CAPTURED DATATYPE_STRING VALUE_STRING
------------- ------------ --- -------- -------- ---------- ------------------- --------------- ------------
0818yxqmw7n43 0 YES :AL_BRBQ 2 22 2022-04-08 09:05:43 NUMBER 1
YES :SYS_B_1 3 22 2022-04-08 09:05:43 NUMBER 1
--//brxm表示病人姓名,直接帶入數字1,存在隱式轉換,變成to_number(c.brxm)=:"SYS_B_1".
> @ d_buffer 0818yxqmw7n43 60 1
EXECUTIONS1 BUFFER_GETS1 ELAPSED_TIME1 ROWS_PROCESSED1 每次buffer_gets 每次執行時間 平均處理記錄數 INST_ID
--------------- --------------- --------------- --------------- --------------- --------------- --------------- ---------------
105124 189651724 1193685786 0 1804.0763669571 11355.026311784 0 1
... sleep 60 , waiting ....
EXECUTIONS2 BUFFER_GETS2 ELAPSED_TIME2 ROWS_PROCESSED2 每次buffer_gets 每次執行時間 平均處理記錄數 INST_ID
--------------- --------------- --------------- --------------- --------------- --------------- --------------- ---------------
105126 189655482 1193717300 0 1804.0777923634 11355.110058406 0 1
執行次數 總buffer_gets 總執行時間 總處理記錄數 每次buffer_gets 每次執行時間 平均處理記錄數
--------------- --------------- --------------- --------------- --------------- --------------- ---------------
2 3758 31514 0 1879 15757 0
--//至少說明這條語句可以執行的。每次邏輯讀1879,但是每次記錄數都是0。
> select * from pppppp_hhh.zy_brry where brxm=1;
select * from pppppp_hhh.zy_brry where brxm=1
*
ERROR at line 1:
ORA-01722: invalid number
> @ sl all
alter session set statistics_level = all;
Session altered.
> variable a number;
> exec :a := 1;
PL/SQL procedure successfully completed.
> select * from pppppp_hhh.zy_brry where brxm=:a;
select * from pppppp_hhh.zy_brry where brxm=:a
*
ERROR at line 1:
ORA-01722: invalid number
> @ dpc '' '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 9fqpamj5sc661, child number 0
-------------------------------------
select * from pppppp_hhh.zy_brry where brxm=:a
Plan hash value: 1081078487
-------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time |
-------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 509 (100)| | 0 |00:00:00.01 |
|* 1 | TABLE ACCESS FULL| ZY_BRRY | 1 | 1 | 568 | 509 (1)| 00:00:07 | 0 |00:00:00.01 |
-------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / ZY_BRRY@SEL$1
Peeked Binds (identified by position):
--------------------------------------
1 - (NUMBER): 1
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(TO_NUMBER("BRXM")=:A)
--//即使語句不能正常執行,執行計劃還是存在的。
> @ tpt/sqlid 9fqpamj5sc661 %
Show SQL text, child cursors and execution stats for SQLID 9fqpamj5sc661 child %
CH# PLAN_HASH PARSES H_PARSES EXECUTIONS FETCHES ROWS_PROCESSED ROWS_PER_FETCH CPU_SEC_EXEC ELA_SEC/EXEC LIOS_PER_EXEC PIOS_PER_EXEC TOTAL_CPU_SEC TOTAL_ELA_SEC TOTAL_IOWAIT_SEC TOTAL_LIOS TOTAL_PIOS SORTS USERS_EXECUTING LAST_ACTIVE_TIME PARENT_HANDLE OBJECT_HANDLE
----- ------------ ------------ ------------ ---------- ------------ -------------- -------------- ------------ ------------ ------------- ------------- ------------- ------------- ---------------- ------------ ------------ ------------ --------------- ------------------- ---------------- ----------------
0 1081078487 3 1 3 3 0 0 .001 .002 3 0 .004 .005 0 9 0 0 0 2022-04-22 10:26:55 00000005E77DF028 00000005E77DEEB8
--//僅僅執行3次,邏輯讀每次也就是3個。看看上面的執行計劃:
Plan hash value: 2161839103
--------------------------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
--------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 514 (100)| |
| 1 | NESTED LOOPS | | 1 | 91 | 514 (1)| 00:00:07 |
| 2 | NESTED LOOPS | | 7 | 91 | 514 (1)| 00:00:07 |
|* 3 | TABLE ACCESS FULL | ZY_BRRY | 1 | 24 | 509 (1)| 00:00:07 |
|* 4 | INDEX RANGE SCAN | I_L_LIS_SQD_PATIENT_ID | 7 | | 2 (0)| 00:00:01 |
|* 5 | TABLE ACCESS BY INDEX ROWID| L_LIS_SQD | 7 | 469 | 5 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
3 - SEL$1 / C@SEL$1
4 - SEL$1 / A@SEL$1
5 - SEL$1 / A@SEL$1
Peeked Binds (identified by position):
--------------------------------------
2 - (NUMBER): 1
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter(("C"."BRBQ"=:AL_BRBQ AND TO_NUMBER("C"."BRXM")=:SYS_B_1))
4 - access("A"."PATIENTID"="C"."ZYHM")
5 - filter("A"."QRHT" IS NULL)
--//難道過濾是先執行"C"."BRBQ"=:AL_BRBQ,如果不滿足就沒有執行TO_NUMBER("C"."BRXM")=:SYS_B_1)。
> select * from pppppp_hhh.zy_brry where brbq=1;
no rows selected
--//確實沒有這樣的記錄。
> select * from pppppp_hhh.zy_brry where brbq=1 and brxm=1;
no rows selected
--//發現可以正常執行,這樣就驗證前面生產系統遇到的情況。
> @ dpc '' '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 0sxwy69ac6p7d, child number 0
-------------------------------------
select * from pppppp_hhh.zy_brry where brbq=1 and brxm=1
Plan hash value: 1081078487
-----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers |
-----------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 509 (100)| | 0 |00:00:00.01 | 1879 |
|* 1 | TABLE ACCESS FULL| ZY_BRRY | 1 | 1 | 568 | 509 (1)| 00:00:07 | 0 |00:00:00.01 | 1879 |
-----------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / ZY_BRRY@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(("BRBQ"=1 AND TO_NUMBER("BRXM")=1))
--//邏輯讀=1879.反過來寫看看:
> select * from pppppp_hhh.zy_brry where brxm=1 and brbq=1;
no rows selected
--//依舊可以正常執行。
> @ descz pppppp_hhh.zy_brry "column_name in ('BRXM','BRBQ')"
eXtended describe of pppppp_hhh.zy_brry
DISPLAY TABLE_NAME OF COLUMN_NAME INFORMATION.
INPUT OWNER.TABLE_NAME <filters>
SAMPLE : @ TAB_LH TABLE_NAME "column_id between 3 and 5"
IF NOT INPUT <filters> ,USE "1=1" .
Owner Table_Name SAMPLE_SIZE LAST_ANALYZED Col# Column Name Null? Type NUM_DISTINCT Density NUM_NULLS HISTOGRAM NUM_BUCKETS Low_value High_value
---------- -------------------- ------------ ------------------- ---- -------------------- ---------- -------------------- ------------ -------------- ------------ --------------- ------------ -------------- -----------
pppppp_hhh ZY_BRRY 25117 2022-04-21 09:24:39 8 BRXM NOT NULL VARCHAR2(40) 18390 .00005437738 0 1 LUC THI THA0毛 瞿鳳連
24996 2022-04-21 09:24:39 35 BRBQ NUMBER(18,0) 25 .04000000000 121 1 251 1219
--//我估計因為隱式轉換的函式,導致oracle最後做brxm=1的判斷,與欄位在資料段的位置沒有關係。換一個欄位brxz在brxm前面。
> select * from pppppp_hhh.zy_brry where brxz=100000 and brxm=1;
no rows selected
> select * from pppppp_hhh.zy_brry where brxz=2 and brxm=1;
select * from pppppp_hhh.zy_brry where brxz=2 and brxm=1
*
ERROR at line 1:
ORA-01722: invalid number
3.總結:
--//我不知道為什麼這樣的程式碼出現在生產系統中,而且在不斷的執行,這樣的程式碼說不定那一天就是一個殺手程式,目前zy_brry不大
--//。影響也不大。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2888180/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20230921]為什麼執行計劃不再awr中.txt
- python按f5為什麼不執行Python
- 20200909]為什麼執行計劃不是出現hash join semi.txt
- 為什麼CentOS8開機不執行rc.localCentOS
- [20201204]為什麼返回2行記錄.txt
- shell 命令在終端可以執行成功,為什麼放在 groovy 指令碼中不執行?指令碼
- 執行緒崩潰為什麼不會導致 JVM 崩潰執行緒JVM
- python為什麼要用執行緒Python執行緒
- [20220328]查詢游標為什麼不共享指令碼.txt指令碼
- pytest.main () 為什麼會報錯?AI
- httprunner 執行報錯,有人遇到過麼?何解HTTP
- 為什麼?為什麼StringBuilder是執行緒不安全的?UI執行緒
- [20220420]完善查詢游標為什麼不共享指令碼.txt指令碼
- Promise為什麼比setTimeout先執行?Promise
- 為什麼Podman執行容器更安全?
- 為什麼redis是單執行緒的以及為什麼這麼快?Redis執行緒
- [20201208]為什麼返回2行記錄補充.txt
- 執行緒池管理(1)-為什麼需要執行緒池執行緒
- redis為什麼用單執行緒不用多執行緒Redis執行緒
- PostgreSQL/LightDB 不走並行是為什麼?SQL並行
- 執行用例報錯
- [20240409]為什麼一條sql語句在例項2執行要慢的分析.txtSQL
- Redis為什麼是單執行緒?為什麼有如此高的效能?Redis執行緒
- [20190816]12c執行exec SYS.PRVT_ADVISOR.DELETE_EXPIRED_TASKS()報錯.txtdelete
- 為什麼在Docker裡使用gdb偵錯程式會報錯Docker
- yii執行phpunit時報錯PHP
- idea上執行scala報錯Idea
- 執行web專案報錯Web
- sh指令碼執行報錯指令碼
- [20181015]為什麼是3秒.txt
- [20220331]為什麼不使用索引.txt索引
- [20201203]為什麼不使用索引.txt索引
- 為什麼python執行效率低?原來因為它!Python
- 為什麼要進行等保?企業不進行等保有什麼影響?
- 如何建立一個執行緒池,為什麼不推薦使用Executors去建立呢?執行緒
- 第48問:為什麼 MySQL 執行時, 不鼓勵調整系統時間MySql
- spring配置檔案中配置了,但找不到Bean , 啟動不報錯,執行報錯No bean namedSpringBean
- [20220422]完善tpt ash ash_index_helperx指令碼2.txtIndex指令碼