Oracleが存在するクエリは、予想通りに機能していません-DBリンクバグ?

StackOverflow https://stackoverflow.com/questions/2976236

質問

私はこのクエリの結果に完全に困惑しています:

select count(*) from my_tab mt
where  mt.stat = '2473'
  and mt.name= 'Tom'
  and exists (select * from company_users@colink.world cu, 
                personnel_records@colink.world pr
              where cu.user_id = pr.user_id
              and mt.name = pr.name
              and mt.stat = cu.stat
              )

返品:1

company_users@colink.worldにはstat = '2473'を使用して0のレコードがあります。

そのようにクエリを変更すると、0が返されます。

select count(*) from my_tab mt
where  mt.stat = '2473'
  and mt.name= 'Tom'
  and exists (select * from company_users@colink.world cu, 
                personnel_records@colink.world pr
              where cu.user_id = pr.user_id
              and mt.name = pr.name
              and cu.stat = '2473'
              )

アップデート さて、これは本当に奇妙です。何が起こるかを見るために、私は他のデータベース(DBリンクで参照されているもの)からクエリを実行すると、異なる(正しい)結果が得られました。

select count(*) from my_tab@mylink.world mt
    where  mt.stat = '2473'
      and mt.name= 'Tom'
      and exists (select * from company_users cu, 
                    personnel_records pr
                  where cu.user_id = pr.user_id
                  and mt.name = pr.name
                  and mt.stat = cu.stat
                  )

0(予想どおり)を返します。

役に立ちましたか?

解決

最初のクエリの説明計画をご覧ください。バグがあると思われ、クエリ計画では、無効な書き換えがどのように行われているかを示している可能性があります。

他のヒント

質問の2番目のクエリは少し異なります - Cu.Statをまったく見ていないため、Cu.Stat = '2473'には何もないという事実は対処されていません。実行した場合はどうなりますか

select count(*)
  from company_users@colink.world cu,     
       personnel_records@colink.world pr,
       my_tab mt
  where mt.stat = '2473' and
        mt.name = 'Tom' and
        pr.name = mt.name and
        cu.user_id = pr.user_id and
        cu.stat = mt.stat

これは、存在することなく最初のクエリと同等であり、正しい結果を提供する必要があると思います。

共有して楽しんでください。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top