SQL*Plus中ArraySize的设置会影响结果集的数量么?先不要轻易说“NO”,我们来看看Jonathan Lewis最近一篇文章中披露的一个案例。
当确定的查询在arraysize改变的情况下,结果集的数量出现不同:
SQL> set transaction read only;
Transaction set.
SQL> set arraysize 1
SQL> select ...
...
541 rows selected.
SQL> set arraysize 4
SQL> select ...
...
599 rows selected.
SQL> set arraysize 10
SQL> select ...
...
620 rows selected.
SQL> set arraysize 32
SQL> select ...
...
616 rows selected.
从查询结果看,随着arraysize的不同,结果集的数量忽多忽少,这显然不科学,一定是BUG导致的。
在执行计划中,可以看到12c的主要的特殊之处在于:rowset 的出现。这是Oracle 12c中引入的一个新特性。
当然,对于每一个新特性,Oracle都会提供隐含参数去控制,我们可以通过设置 _rowsets_enable=false 去关闭这一新特性。
参考链接:
https://jonathanlewis.wordpress.com/2015/11/09/wrong-results/
Oracle Support很快响应这一问题并给出进一步的WorkAround,可以通过设置Event 10055的特定级别修复该问题:
event = "10055 trace name context forever, level 2097152"
这个Bug的补丁也很快被提供出来,大家可以通过MOS找到这个BUG的修复补丁:Bug 22173980 : WRONG RESULTS WHEN "_ROWSETS_ENABLED" = TRUE 。
其影响的范围是 12.1.0.1 和 12.1.0.2 。参考:Note 2079913.1 。对于CDB环境下,还有另外一个参数 _rowsets_cdb_view_enabled 与这一特性有关,必要时需要关闭这个特性。BUG 17016479 也值得参考。
公开的BUG信息指出,这个问题出现的原因在于:当HASH JOIN在RowSet之间进行多次处理时,在特定情况下,其索引(ridx)定位行有问题,导致返回的结果集出现错误。
Internal Problem Description ---------------------------- The failing query involved several nested loops on top of a hash join.The hash join consumed rowsets from its two inputs and produced one row at a time for its parent.The top nested loops returned the rows to kpofcr, which returned rows=0 when the array fetch size was reached (the default was 15). After all the fetch functions returned, the release functions were called, in order to end the call. In the release function of the hash join, after the child release was done, it restored the last row it returned to its parent.This involved a call to qesrSetupOneCtxRow to use a row in the rowset where it saved away the input rows.If the last row it returned happened to be the first row in the rowset,and the index (ridx) was set to 0,the release was incorrectly restoring the last row in the rowset instead of the first.This led to wrong results. Internal Fix Description ------------------------ Modified the hash join release function to use the saved row index when the yet2finishrset_qerhjm flag is set, even if it is 0. That is,if it still has rows to process in the last rowset it received from the child, then the value stored in ridx is the last row that was returned to the parent. Only in the case that it finished processing the input rowset (and yet2finishrset_qerhjm is false) will a value of 0 for ridx indicate that the last row returned was the last row in the last input rowset.
参考Jonathan和Mos的文档可以了解这个有趣的Bug。
文章转自数据和云公众号,原文链接