2022年8月9日下午,StoneDB資料庫主體研發單位石原子科技與華為、openGauss開源社區、雲和恩墨、甲骨文等組織受邀參與《開源資料庫服務商服務能力分級要求》標準第一次討論會。 重點討論:標準的能力域與能力項的分類。 後續,項目組將會繼續完善能力分級要求,推進開源資料庫標準的編製工作。至今 ...
[20220811]奇怪的隱式轉換問題.txt
--//生產系統遇到一個奇怪的隱式轉換問題,問題在於沒有發生隱式轉換,做一個分析調查。
--//後記:後面的分析存在一下偏差,不更正當時的分析,在這裡做一個補充,實際上從12.2版本開始,oracle就支持這樣的情況,當使
--//用綁定變數時,帶入的綁定變數參數是timestamp類型時,不再存在隱式轉換。即使秒後面的值非0!!
--//我另外寫一篇 [20220811]奇怪的隱式轉換問題(12c補充測試).txt 來說明問題。
--//感覺oracle 一個小小的改進,很奇怪我感覺至少我這之前沒見過別人寫過或者遇到這樣的情況。
1.環境:
[email protected]:1521/orcl> @ pr
==============================
PORT_STRING : x86_64/Linux 2.4.xx
VERSION : 19.0.0.0.0
BANNER : Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
BANNER_FULL : Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
BANNER_LEGACY : Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
CON_ID : 0
PL/SQL procedure successfully completed.
2.分析:
[email protected]:1521/orcl> @dashtop sql_id 1=1 &day
Total
Seconds AAS %This SQL_ID FIRST_SEEN LAST_SEEN
--------- ------- ------- ------------- ------------------- -------------------
18420 .2 36% 2022-08-10 08:54:16 2022-08-11 07:59:14
4420 .1 9% 4qz6aykj6gq6v 2022-08-10 08:54:37 2022-08-11 07:46:32
2640 .0 5% gxak7guzxkwbh 2022-08-10 08:54:27 2022-08-11 07:23:29
2000 .0 4% 3rhg88u6qnt7h 2022-08-10 10:01:05 2022-08-11 07:23:29
1690 .0 3% 79ymhrhpk0x3p 2022-08-10 08:55:47 2022-08-11 07:54:03
1600 .0 3% 9akuv534yadhw 2022-08-10 10:13:57 2022-08-11 07:55:33
1100 .0 2% 0bzc2mv4s5f30 2022-08-10 08:55:37 2022-08-11 07:46:42
1030 .0 2% 18xh7p6w137q5 2022-08-10 08:55:17 2022-08-11 07:55:43
...
30 rows selected.
--//分析sql_id=4qz6aykj6gq6v.
[email protected]:1521/orcl> @ sql_id 4qz6aykj6gq6v
--SQL_ID = 4qz6aykj6gq6v
select a.*,1 as TenantId from lis_test a where test_date=:end_date and inst_id=:inst_id AND SENT_INST_FLAG = 0 AND SENT_COUNT<3 and state < :state;
[email protected]:1521/orcl> @ dpc 4qz6aykj6gq6v '' '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 4qz6aykj6gq6v, child number 5
-------------------------------------
select a.*,1 as TenantId from lis_test a where test_date=:end_date
and inst_id=:inst_id AND SENT_INST_FLAG = 0 AND SENT_COUNT<3 and
state < :state
Plan hash value: 557083498
-----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
-----------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 52419 (100)| |
|* 1 | TABLE ACCESS BY INDEX ROWID BATCHED| LIS_TEST | 4 | 2784 | 52419 (1)| 00:00:03 |
|* 2 | INDEX SKIP SCAN | IX_LIS_TEST_TEST_NO__831848037 | 249 | | 52170 (1)| 00:00:03 |
-----------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / A@SEL$1
2 - SEL$1 / A@SEL$1
Peeked Binds (identified by position):
--------------------------------------
1 - :1 (TIMESTAMP): [Not Printable]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 - :2 (NUMBER): 2490
3 - (NUMBER): 90
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(("STATE"<:STATE AND "SENT_INST_FLAG"=0 AND "SENT_COUNT"<3))
2 - access("TEST_DATE"=:END_DATE AND "INST_ID"=:INST_ID)
filter(("TEST_DATE"=:END_DATE AND "INST_ID"=:INST_ID))
Note
-----
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
42 rows selected.
--//索引的名字命名有點怪怪的IX_LIS_TEST_TEST_NO__831848037,好像sql profile提示建立的索引不應該是這樣的格式,猜測該產品
--//早期可能在ms sqlserver下開發的。執行計划走的是INDEX SKIP SCAN,前面一個欄位是test_no,自然執行效率低下。
--//另外註意下劃線可以發現參數1類型timestamp類型,開始沒有註意這個細節。
[email protected]:1521/orcl> @ ind2 LIS.IX_LIS_TEST_TEST_NO__831848037
Display indexes where table or index name matches LIS.IX_LIS_TEST_TEST_NO__831848037...
TABLE_OWNER TABLE_NAME INDEX_NAME POS# COLUMN_NAME DSC
-------------------- ------------------------------ ------------------------------ ---- ------------------------------ ----
LIS LIS_TEST IX_LIS_TEST_TEST_NO__831848037 1 TEST_NO
2 TEST_DATE
3 INST_ID
4 NO_PREFIX
INDEX_OWNER TABLE_NAME INDEX_NAME IDXTYPE UNIQ STATUS PART TEMP H LFBLKS NDK NUM_ROWS CLUF LAST_ANALYZED DEGREE VISIBILIT
-------------------- ------------------------------ ------------------------------ ---------- ---- -------- ---- ---- -- ---------- ------------- ---------- ---------- ------------------- ------ ---------
LIS LIS_TEST IX_LIS_TEST_TEST_NO__831848037 NORMAL YES VALID NO N 3 52158 8238727 8238727 8217923 2022-08-09 22:19:23 1 VISIBLE
[email protected]:1521/orcl> @ descz LIS.LIS_TEST "column_name in ('TEST_NO','TEST_DATE','INST_ID','SENT_INST_FLAG','SENT_COUNT','STATE')"
eXtended describe of LIS.LIS_TEST
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
---------- -------------------- ----------- ------------------- ---- -------------------- ---------- -------------------- ------------ -------------- ---------- --------------- ----------- ------------------- -------------------
LIS LIS_TEST 8701 2022-08-09 22:07:12 3 TEST_NO NOT NULL NUMBER(19,0) 237680 .00000400000 0 HYBRID 254 -9020 2103294101535845721
8701 2022-08-09 22:07:12 4 TEST_DATE NOT NULL DATE(7) 561 .00177900000 0 HYBRID 254 0001-01-01 00:00:00 9773-06-08 00:00:00
8238717 2022-08-09 22:07:12 5 INST_ID NOT NULL NUMBER(10,0) 226 .00000006069 0 FREQUENCY 226 1530 4090
8238717 2022-08-09 22:07:12 28 SENT_INST_FLAG NOT NULL NUMBER(10,0) 2 .00000006069 0 FREQUENCY 2 0 1
8238717 2022-08-09 22:07:12 29 SENT_COUNT NOT NULL NUMBER(10,0) 224 .00000006069 0 FREQUENCY 224 0 393
8238717 2022-08-09 22:07:12 108 STATE NUMBER(10,0) 5 .00000006069 0 FREQUENCY 5 60 100
6 rows selected.
--//呵呵還可以看出TEST_DATE存在垃圾數據。High_value=9773-06-08 00:00:00.
--//查看綁定變數值如下:
[email protected]:1521/orcl> @ bind_cap 4qz6aykj6gq6v ''
SQL_ID CHILD_NUMBER WAS NAME POSITION MAX_LENGTH LAST_CAPTURED DATATYPE_STRING VALUE_STRING C30
------------- ------------ --- --------- -------- ---------- ------------------- --------------- ------------ ------------------------------
4qz6aykj6gq6v 5 YES :END_DATE 1 11 2022-08-11 08:54:14 TIMESTAMP 2022-08-11 00:00:00.000000000
YES :INST_ID 2 22 2022-08-11 08:54:14 NUMBER 2390
YES :STATE 3 22 2022-08-11 08:54:14 NUMBER 90
3 rows selected.
--//註意一個細節變數:END_DATE的數據類型帶入的是TIMESTAMP。而前面的顯示執行計劃顯示的是access,filter確是
--//"TEST_DATE"=:END_DATE,而欄位TEST_DATE的定義數據類型是date(7),也就是執行計劃沒有發生沒有執行隱式轉換。
--//開始懷疑是否存在打入參數即有date類型又有timestamp類型,開始沒有註意Peeked Binds (identified by position):部分顯示,
Peeked Binds (identified by position):
--------------------------------------
1 - :1 (TIMESTAMP): [Not Printable]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 - :2 (NUMBER): 2490
3 - (NUMBER): 90
--//不然就不會在開始優化開始時走彎路了。
--//查詢如下:
[email protected]:1521/orcl> @ bind_cap_awr 4qz6aykj6gq6v END_DATE
@bind_cap_awr sql_id [column]
1 row selected.
SNAP_ID INSTANCE_NUMBER SQL_ID WAS LAST_CAPTURED NAME POSITION MAX_LENGTH DATATYPE_STRING VALUE_STRING C30
---------- --------------- ------------- --- ------------------- --------- -------- ---------- --------------- ------------ ------------------------------
14720 1 4qz6aykj6gq6v YES 2022-08-02 22:48:44 :END_DATE 1 11 TIMESTAMP 2022-08-02 00:00:00.000000000
14721 1 4qz6aykj6gq6v YES 2022-08-02 23:48:48 :END_DATE 1 11 TIMESTAMP 2022-08-02 00:00:00.000000000
14722 1 4qz6aykj6gq6v YES 2022-08-03 00:48:52 :END_DATE 1 11 TIMESTAMP 2022-08-03 00:00:00.000000000
14723 1 4qz6aykj6gq6v YES 2022-08-03 01:48:54 :END_DATE 1 11 TIMESTAMP 2022-08-03 00:00:00.000000000
14724 1 4qz6aykj6gq6v YES 2022-08-03 02:48:58 :END_DATE 1 11 TIMESTAMP 2022-08-03 00:00:00.000000000
14725 1 4qz6aykj6gq6v YES 2022-08-03 03:49:01 :END_DATE 1 11 TIMESTAMP 2022-08-03 00:00:00.000000000
--//snip....
14921 1 4qz6aykj6gq6v YES 2022-08-11 07:54:12 :END_DATE 1 11 TIMESTAMP 2022-08-11 00:00:00.000000000
14922 1 4qz6aykj6gq6v YES 2022-08-11 08:54:14 :END_DATE 1 11 TIMESTAMP 2022-08-11 00:00:00.000000000
203 rows selected.
--//很明顯不存在參數即有date類型又有timestamp類型的情況。
[email protected]:1521/orcl> @ cntg LIS.LIS_TEST SENT_INST_FLAG
select count(*) , SENT_INST_FLAG from LIS.LIS_TEST group by SENT_INST_FLAG order by 1 desc;
COUNT(*) SENT_INST_FLAG
---------- --------------
5129342 0
3135070 1
2 rows selected.
[email protected]:1521/orcl> @ cntg LIS.LIS_TEST SENT_count
select count(*) , SENT_count from LIS.LIS_TEST group by SENT_count order by 1 desc;
COUNT(*) SENT_COUNT
---------- ----------
6186388 0
2059983 1
13864 2
2230 3
...
1 182
224 rows selected.
--//建立索引在SENT_INST_FLAG以及SENT_COUNT也是不合理的,也就是根據以上分析建立複合索引:TEST_DATE,INST_ID.而且不存在隱式
--//轉換的問題。
CREATE INDEX LIS.i_LIS_TEST_TEST_DATE_INST_ID ON LIS.LIS_TEST
(TEST_DATE, INST_ID)
LOGGING
STORAGE (
BUFFER_POOL DEFAULT
FLASH_CACHE DEFAULT
CELL_FLASH_CACHE DEFAULT
)
NOPARALLEL;
--//再看執行計劃,發現
[email protected]:1521/orcl> @ dpc 4qz6aykj6gq6v '' '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 4qz6aykj6gq6v, child number 1
-------------------------------------
select a.*,1 as TenantId from lis_test a where test_date=:end_date
and inst_id=:inst_id AND SENT_INST_FLAG = 0 AND SENT_COUNT<3 and
state < :state
Plan hash value: 2953700840
---------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
---------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 160 (100)| |
|* 1 | TABLE ACCESS BY INDEX ROWID BATCHED| LIS_TEST | 6 | 4176 | 160 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | I_LIS_TEST_TEST_DATE_INST_ID | 346 | | 4 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / A@SEL$1
2 - SEL$1 / A@SEL$1
Peeked Binds (identified by position):
--------------------------------------
1 - :1 (TIMESTAMP): [Not Printable]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 - :2 (NUMBER): 2890
3 - (NUMBER): 90
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(("STATE"<:STATE AND "SENT_INST_FLAG"=0 AND "SENT_COUNT"<3))
2 - access("TEST_DATE"=:END_DATE AND "INST_ID"=:INST_ID)
Note
-----
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
--//你可以發現oracle可以使用我建立的索引。並且執行計划走INDEX RANGE SCAN使用I_LIS_TEST_TEST_DATE_INST_ID索引。
--//我手工生成腳本,註在sqlplus使用variable無法定義date,timestamp類型,只能使用字元串,註意帶入日期的格式要符合要求:
[email protected]:1521/orcl> @b9 4qz6aykj6gq6v 0 1
variable END_DATE VARCHAR2(32)
variable INST_ID NUMBER
variable STATE NUMBER
begin
:END_DATE := '2022/08/11 00:00:00';
:INST_ID := 2490;
:STATE := 90;
end;
/
set termout off
set sqlblanklines on
alter session set current_schema=LIS;
alter session set statistics_level=all;
select a.*,1 as TenantId from lis_test a where test_date=:end_date and inst_id=:inst_id AND SENT_INST_FLAG = 0 AND SENT_COUNT<3 and state < :state;
set termout on
set sqlblanklines off
--@zws '' ''
--@dpc '' ''
@dpc '' outline
rollback;
alter session set current_schema=SYS ;
--//註我取消秒後面的000000000.不然報錯我開始就是通過這裡發現存在數據類型"轉換"問題的。
--//執行計劃如下:
SQL_ID 4qz6aykj6gq6v, child number 2
-------------------------------------
select a.*,1 as TenantId from lis_test a where test_date=:end_date
and inst_id=:inst_id AND SENT_INST_FLAG = 0 AND SENT_COUNT<3 and
state < :state
Plan hash value: 2953700840
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time | A-Rows | A-Time | Buffers | Reads |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | | 157 (100)| | 0 |00:00:00.01 | 335 | 4 |
|* 1 | TABLE ACCESS BY INDEX ROWID BATCHED| LIS_TEST | 1 | 6 | 4176 | 157 (0)| 00:00:01 | 0 |00:00:00.01 | 335 | 4 |
|* 2 | INDEX RANGE SCAN | I_LIS_TEST_TEST_DATE_INST_ID | 1 | 338 | | 4 (0)| 00:00:01 | 522 |00:00:00.01 | 5 | 4 |
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / A@SEL$1
2 - SEL$1 / A@SEL$1
Peeked Binds (identified by position):
--------------------------------------
1 - :1 (VARCHAR2(30), CSID=852): '2022/08/11 00:00:00'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 - :2 (NUMBER): 2490
3 - (NUMBER): 90
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(("STATE"<:STATE AND "SENT_INST_FLAG"=0 AND "SENT_COUNT"<3))
2 - access("TEST_DATE"=:END_DATE AND "INST_ID"=:INST_ID)
--//可以發現也可以使用索引,但是我的測試無法反映真實的情況,我帶入的:END_DATE是varchar2(32)。toad下執行也很麻煩,toad帶入
--//的參數類型沒有timestamp類型,我也不知道如何處理。我記憶里在itpub上問過,toad下如何使用timestamp數據類型,沒人解答這
--//個問題.
--//我個人認為問題在於帶入的timestamp類型沒有秒後面的0值,就不會出現隱式轉換。【後記:我有點想當然了】
--//也許oracle 19c版本支持這樣的操作,當帶入日期類型參數是timestamp類型時,如果秒後面的值全部是0,可以當作date類型使用。
--//導致沒有存在隱式轉換,我給在11g測試看看.
--//加入秒後面的0的情況。
$ cat 4qz6aykj6gq6v.sql9_0
variable END_DATE VARCHAR2(32)
variable INST_ID NUMBER
variable STATE NUMBER
begin
:END_DATE := '2022-08-11 00:00:00.000000000';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:INST_ID := 2490;
:STATE := 90;
end;
/
set termout off
set sqlblanklines on
alter session set current_schema=LIS;
alter session set statistics_level=all;
SElect a.*,1 as TenantId from lis_test a where test_date=:end_date and inst_id=:inst_id AND SENT_INST_FLAG = 0 AND SENT_COUNT<3 and state < :state;
set termout on
set sqlblanklines off
--@zws '' ''
--@dpc '' ''
@dpc '' outline
rollback;
alter session set current_schema=SYS ;
[email protected]:1521/orcl> @ 4qz6aykj6gq6v.sql9_0
PL/SQL procedure successfully completed.
PLAN_TABLE_OUTPUT
-----------------------------------------
Last statement has a PREV_SQL_ID of ZERO
2 rows selected.
argment : typical all advanced partition predicate remote note parallel projection alias peeked_binds outline bytes
argment : adaptive (12c) hint_report (19c)
Rollback complete.
Session altered.
--//執行報錯!!也就是這樣我才發現帶入類型是timestamp類型。
--//還可以通過生產系統的其它語句驗證我的測試有效,建立的I_LIS_TEST_TEST_DATE_INST_ID索引有用。
[email protected]:1521/orcl> @ sql_id 18xh7p6w137q5
--SQL_ID = 18xh7p6w137q5
select nvl(max(test_no),0) test_No from lis_test where test_date=:test_date and inst_id=:inst_id and TEST_NO between :StartNo and :MaxNo and is_initial<=1;
[email protected]:1521/orcl> @ bind_cap 18xh7p6w137q5 test_date
C200
-------------------------------------------------------------------------------------------------------------------------------------------------------------
select nvl(max(test_no),0) test_No from lis_test where test_date=:test_date and inst_id=:inst_id and TEST_NO between :StartNo and :MaxNo and is_initial<=1
SQL_ID CHILD_NUMBER WAS NAME POSITION MAX_LENGTH LAST_CAPTURED DATATYPE_STRING VALUE_STRING C30
------------- ------------ --- ---------- ---------- ---------- ------------------- --------------- ------------ ------------------------------
18xh7p6w137q5 2 YES :TEST_DATE 1 11 2022-08-11 09:36:03 TIMESTAMP 2022-08-11 00:00:00.000000000
--//一樣是timetamp類型。
[email protected]:1521/orcl> @ dpc 18xh7p6w137q5 ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 18xh7p6w137q5, child number 2
-------------------------------------
select nvl(max(test_no),0) test_No from lis_test where
test_date=:test_date and inst_id=:inst_id and TEST_NO between :StartNo
and :MaxNo and is_initial<=1
Plan hash value: 467228195
-----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
-----------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 316 (100)| |
| 1 | SORT AGGREGATE | | 1 | 20 | | |
|* 2 | FILTER | | | | | |
|* 3 | TABLE ACCESS BY INDEX ROWID BATCHED| LIS_TEST | 90 | 1800 | 316 (0)| 00:00:01 |
|* 4 | INDEX RANGE SCAN | I_LIS_TEST_TEST_DATE_INST_ID | 689 | | 5 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1
3 - SEL$1 / LIS_TEST@SEL$1
4 - SEL$1 / LIS_TEST@SEL$1
Peeked Binds (identified by position):
--------------------------------------
1 - :1 (TIMESTAMP): [Not Printable]
2 - :2 (NUMBER): 1671
3 - (NUMBER): 1000
4 - (NUMBER): 2000
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter(:MAXNO>=:STARTNO)
3 - filter(("TEST_NO"<=:MAXNO AND "TEST_NO">=:STARTNO AND "IS_INITIAL"<=1))
4 - access("TEST_DATE"=:TEST_DATE AND "INST_ID"=:INST_ID)
Note
-----
- Warning: basic plan statistics not available. These are only collected when:
* hint 'gather_plan_statistics' is used for the statement or
* parameter 'statistics_level' is set to 'ALL', at session or system level
--//索引有效!!
[email protected]:1521/orcl> @ b9 18xh7p6w137q5 0 1
variable TEST_DATE VARCHAR2(32)
variable INST_ID NUMBER
variable STARTNO NUMBER
variable MAXNO NUMBER
begin
:TEST_DATE := '2022/08/11 00:00:00.000000000';
:INST_ID := 1725;
:STARTNO := 0;
:MAXNO := 300;
end;
/
set termout off
set sqlblanklines on
alter session set current_schema=LIS;
alter session set statistics_level=all;
select nvl(max(test_no),0) test_No from lis_test where test_date=:test_date and inst_id=:inst_id and TEST_NO between :StartNo and :MaxNo and is_initial<=1;
set termout on
set sqlblanklines off
--@zws '' ''
--@dpc '' ''
@dpc '' outline
rollback;
alter session set current_schema=SYS ;
[email protected]:1521/orcl> @18xh7p6w137q5.sql9_0
PL/SQL procedure successfully completed.
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------
Last statement has a PREV_SQL_ID of ZERO
2 rows selected.
argment : typical all advanced partition predicate remote note parallel projection alias peeked_binds outline bytes
argment : adaptive (12c) hint_report (19c)
Rollback complete.
Session altered.
--//順便改寫如下:
select a.*,1 as TenantId from lis_test a where test_date=to_timestamp('2022-08-11 00:00:00.000000000','yyyy-mm-dd hh24:mi:ss.ff') and inst_id=1;
Plan hash value: 284515054
---------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
---------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 696 | 564 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| LIS_TEST | 1 | 696 | 564 (0)| 00:00:01 |
|* 2 | INDEX SKIP SCAN | I_LIS_TEST_TEST_DATE_INST_ID | 1 | | 563 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
1 - SEL$1 / A@SEL$1
2 - SEL$1 / A@SEL$1
Outline Data
-------------
/*+
BEGIN_OUTLINE_DATA
BATCH_TABLE_ACCESS_BY_ROWID(@"SEL$1" "A"@"SEL$1")
INDEX_SS(@"SEL$1" "A"@"SEL$1" ("LIS_TEST"."TEST_DATE" "LIS_TEST"."INST_ID"))
OUTLINE_LEAF(@"SEL$1")
ALL_ROWS
DB_VERSION('19.1.0')
OPTIMIZER_FEATURES_ENABLE('19.1.0')
IGNORE_OPTIM_EMBEDDED_HINTS
END_OUTLINE_DATA
*/
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("INST_ID"=1)
filter("INST_ID"=1 AND INTERNAL_FUNCTION("TEST_DATE")=TIMESTAMP' 2022-08-11 00:00:00.000000000')
--//可以驗證發生隱式轉換。
總結:
--//也就是在這種特殊的情況下隱式轉換並沒有發生,以前好像沒有遇到類似的問題,看來19c做了一些改進,看來給在11g下測試看看。