SELECT COUNT (*) FROM rps2_workflow WHERE workflow_added > TO_DATE ('01.09.2011', 'dd.mm.yyyy') AND workflow_finished < TO_DATE ('wtf', 'dd.mm.yyyy') AND workflow_status IN (7, 12, 17) AND workflow_worker = 159
由于日期无效,我预计此查询将失败,但它返回0
此查询的计划表明,在第8步 中 处理了无效子句:
8 TABLE ACCESS BY INDEX ROWID TABLE RPS2.RPS2_WORKFLOW Object Instance: 1 Filter Predicates: ("WORKFLOW_STATUS"=7 OR "WORKFLOW_STATUS"=12 OR "WORKFLOW_STATUS"=17) AND SYS_EXTRACT_UTC("WORKFLOW_FINISHED")<SYS_EXTRACT_UTC(TO_DATE('wtf','dd.mm.yyyy')) Cost: 11 Bytes: 33 Cardinality: 1 CPU Cost: 8 M IO Cost: 10 Time: 1
如果我们注释掉AND workflow_status IN (7, 12, 17)条件-那么我们有望得到ORA-01858: a non- numeric character was found where a numeric was expected
AND workflow_status IN (7, 12, 17)
ORA-01858: a non- numeric character was found where a numeric was expected
如果我们注释掉,AND workflow_finished < TO_DATE ('wtf', 'dd.mm.yyyy')那么我们将获得满足该条件的记录数量(> 0)
AND workflow_finished < TO_DATE ('wtf', 'dd.mm.yyyy')
这怎么可能?
UPD :
提示/*+no_index(rps2_workflow) */没有任何改变(而在该计划中,我们看到执行了全扫描)
/*+no_index(rps2_workflow) */
SELECT STATEMENT ALL_ROWSCost: 254 Bytes: 31 Cardinality: 1 CPU Cost: 34 M IO Cost: 248 Time: 4 2 SORT AGGREGATE Bytes: 31 Cardinality: 1 1 TABLE ACCESS FULL TABLE RPS2.RPS2_WORKFLOW Object Instance: 1 Filter Predicates: "WORKFLOW_WORKER"=159 AND ("WORKFLOW_STATUS"=7 OR "WORKFLOW_STATUS"=12 OR "WORKFLOW_STATUS"=17) AND SYS_EXTRACT_UTC("WORKFLOW_ADDED")>SYS_EXTRACT_UTC(TIMESTAMP' 2011-09-01 00:00:00') AND SYS_EXTRACT_UTC("WORKFLOW_FINISHED")<SYS_EXTRACT_UTC(TO_DATE('wtf','dd.mm.yyyy')) Cost: 254 Bytes: 31 Cardinality: 1 CPU Cost: 34 M IO Cost: 248 Time: 4
它可能发现满足所有其他条件的每条记录都有一个NULL workflow_finished字段。
NULL
workflow_finished
而且NULL与之比较的任何事物都是未知的,因此不需要评估另一个操作数。