1 Reply Latest reply: Jan 23, 2013 3:04 AM by Jonathan Lewis RSS

    MINUS operator fetches invalid record count

    977068
      Hi,

      One of the application team complained that oracle MINUS operator fetches an invalid record count after data load.

      Here are the details of the data load:

      They are using source as PROD and target as UAT.

      They are replicating the data on UAT environment in schema A from fetching the data in PROD from the same schema.

      After load when we query the count of records in UAT it shows more records in target, that is in UAT, than PROD.

      When they use MINUS operator to fetch the extra records in UAT, it shows no rows selected.

      SQL> select 'A' count(1) from A.UAT union all select 'A' count(1) from A.PROD@BISLSPD1;

      A COUNT(1)
      -------------------------------- ----------
      A.UAT 19105022
      A.PROD 19104995


      SQL> select distinct count(*) from (select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.UAT minus select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.PROD@BISLSPD1);

      COUNT(*)
      ----------
      0

      SQL> select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.UAT minus select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.PROD@BISLSPD1

      no rows selected

      Please note that both are partitioned tables and they are using Informatica Data Replication 9.5 tool to populate the data from source to target.

      Not sure if this could be a bug or an issue.


      PROD DB Version: 10.2.0.5

      UAT DB Version: 10.2.0.5


      Both are in Linux 2.6


      Please throw some light on this.
        • 1. Re: MINUS operator fetches invalid record count
          Jonathan Lewis
          974065 wrote:
          SQL> select 'A' count(1) from A.UAT union all select 'A' count(1) from A.PROD@BISLSPD1;
          
          A                  COUNT(1)
          -------------------------------- ----------
          A.UAT                     19105022
          A.PROD                   19104995
          
          
          SQL> select distinct count(*) from (select distinct  DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.UAT minus select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.PROD@BISLSPD1);
          
          COUNT(*)
          ----------
          0
          
          SQL> select distinct  DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.UAT minus select distinct DW_DISCOUNT_KEY, DW_DISCOUNT_MODIFIER_KEY from A.PROD@BISLSPD1
          
          no rows selected
          Given that you've go "distinct" in your query, you're eliminating duplicates from each table (and MINUS implicitly means distinct anyway). Check for duplicates (of dw_discount_key, dw_discount_modifier_key) in both tables.

          If the combination is actually unique, I would check that you actually had the raw results the right way round - MINUS is not symmetrical, and for a complete picture you need to look at (select from uat minus select from prod) union all (select from prod minus select from uat)

          Regards
          Jonathan Lewis