[20150715]Wrong Results.txt

本文详细分析了一次SQL查询中,使用物化视图导致输出结果异常的问题,通过深入理解查询过程和物化视图的工作原理,揭示了问题的根本原因并提供了解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[20150715]Wrong Results.txt

http://afatkulin.blogspot.com/2015/07/wrong-results.html

--重复测试:

SCOTT@test> @ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.3.0     Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production


create table t as select mod(level, 10) n, level m from dual connect by level <= 1000;
create materialized view mv_t enable query rewrite as select n, sum(m), grouping_id(n) gid from t group by rollup(n);

with v as ( select 20 n from dual) select distinct v.n from v, t where v.n=t.n(+);

SCOTT@test> with v as ( select 20 n from dual) select distinct v.n from v, t where v.n=t.n(+);
no rows selected


SCOTT@test> @dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  4nhtt9tat8cws, child number 0
-------------------------------------
with v as ( select 20 n from dual) select distinct v.n from v, t where v.n=t.n(+)
Plan hash value: 29516041
-----------------------------------------------------------------------------------------
| Id  | Operation                       | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time   |
-----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                |      |        |       |     6 (100)|          |
|   1 |  SORT UNIQUE NOSORT             |      |      1 |    28 |     6  (17)| 00:00:01 |
|*  2 |   FILTER                        |      |        |       |            |          |
|   3 |    NESTED LOOPS OUTER           |      |      1 |    28 |     5   (0)| 00:00:01 |
|   4 |     TABLE ACCESS FULL           | DUAL |      1 |     2 |     2   (0)| 00:00:01 |
|*  5 |     MAT_VIEW REWRITE ACCESS FULL| MV_T |      1 |    26 |     3   (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$9EB47AD3
   4 - SEL$9EB47AD3 / DUAL@SEL$1
   5 - SEL$9EB47AD3 / MV_T@SEL$EE2C87C0
Predicate Information (identified by operation id):
---------------------------------------------------
   2 - filter("MV_T"."GID"=0)
   5 - filter("MV_T"."N"=CASE  WHEN (ROWID IS NOT NULL) THEN 20 ELSE 20 END )

--仔细观察可以发现2 - filter("MV_T"."GID"=0),导致没有结果输出。

SCOTT@test> select * from MV_T;
         N     SUM(M)        GID
---------- ---------- ----------
         0      50500          0
         1      49600          0
         2      49700          0
         3      49800          0
         4      49900          0
         5      50000          0
         6      50100          0
         7      50200          0
         8      50300          0
         9      50400          0
               500500          1
11 rows selected.

--查询使用物化视图,导致结果出现异常。

SCOTT@test> drop materialized view mv_t;
Materialized view dropped.

SCOTT@test> with v as ( select 20 n from dual) select distinct v.n from v, t where v.n=t.n(+);
         N
----------
        20

Status Evaluation failed Evaluation failed. Please check the error messages below and correct your submission if possible. If the error message seems too cryptic or you don't know what you need to correct, please e-mail the contact for more information (see below). Please use [VOC2010] in the title and copy the URL of this page in your e-mail. Thank you. Score Competition Category Score Messages Evaluation errors Detections file /var/voc_challenges/VOC2012/submissions/40772/input/results/VOC2012/Main/comp1_cls_test_person.txt has wrong format at line 0 . Expected <image> <confidence> Error in a file format Evaluation log Checking submission Submission file: /var/voc_challenges/VOC2012/submissions/40772/input/results.tgz Working directory: /var/voc_challenges/VOC2012/submissions/40772/input Extracting submission Submission MD5 sum is: 1694af5739d254f14333e3895e1ab3c5 Extraction complete. Checking submission. Detections file /var/voc_challenges/VOC2012/submissions/40772/input/results/VOC2012/Main/comp1_cls_test_person.txt has wrong format at line 0 . Expected <image> <confidence> Error in a file format Challenge 1. No results present. Challenge 2. No results present. Challenge 3. No results present. Challenge 4. No results present. Challenge 5. Not submitted (looking for folder results/VOC2012/Segmentation/comp5_test_cls) Challenge 6. Not submitted - no images (looking for png images in folder results/VOC2012/Segmentation/comp6_test_cls) E.g. results/VOC2012/Segmentation/comp6_test_cls/2008_000006.png
03-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值