Title: RE: Urgent problem with query in CBO Vs RBO

Here is an example ...

RULE Hint works ... but we can't find all the SQLs that will fail. The only other option suggested by OWS is setting optimizer_features_enable='8.1.6'. It works fine ...

Raj
---------------  start  ----------------------------

set feedback off
set define off
drop table mjc_junk;
drop table mjc_mst;
prompt Creating MJC_JUNK...
-- Create table
create table MJC_JUNK
(
  COLA NUMBER(9)
);
prompt Creating MJC_MST...
-- Create table
create table MJC_MST
(
  COLA NUMBER(9) not null,
  COLB NUMBER(9) not null,
  CDT  DATE
);

prompt Loading MJC_MST...
insert into MJC_MST (COLA, COLB, CDT)
values (1284457, 213841, to_date('06-06-2001 09:28:40', 'dd-mm-yyyy hh24:mi:ss'));
commit;
prompt 41 records loaded
declare
begin
  sys.dbms_stats.gather_table_stats(ownname => null,
                                    tabname => 'MJC_JUNK',
                                    estimate_percent => 20,
                                    block_sample => false,
                                    method_opt => 'FOR ALL COLUMNS',
                                    degree => 4,
                                    granularity => 'DEFAULT',
                                    cascade => true);
end;
/
set feedback on
set define on

prompt This query returns invalid results:
select sUM(a.colb)
  FROM mjc_mst a
 WHERE a.colb = 213841
   AND a.cdt = (SELECT MAX(b.cdt)
                        FROM mjc_mst b
                       WHERE b.cola = a.cola
                         AND b.colb = a.colb
)
  and exists ( select 1 from mjc_junk b, mjc_junk m where
                a.colb = m.cola
                 and 1 != 1);

prompt This query that returns valid results:
select sum(a.colb)
  FROM mjc_mst a
 WHERE a.colb = 213841
   AND a.cdt = (SELECT MAX(b.cdt)
                        FROM mjc_mst b
                       WHERE b.cola = a.cola
                         AND b.colb = a.colb
                        group by 1
)
  and exists ( select 1 from mjc_junk b, mjc_junk m where
                a.colb = m.cola
                 and 1 != 1)
prompt Go figure.

------------ end ----------------------


______________________________________________________
Rajendra Jamadagni              MIS, ESPN Inc.
Rajendra dot Jamadagni at ESPN dot com
Any opinion expressed here is personal and doesn't reflect that of ESPN Inc.
QOTD: Any clod can have facts, but having an opinion is an art!

********************************************************************This e-mail 
message is confidential, intended only for the named recipient(s) above and may 
contain information that is privileged, attorney work product or exempt from 
disclosure under applicable law. If you have received this message in error, or are 
not the named recipient(s), please immediately notify corporate MIS at (860) 766-2000 
and delete this e-mail message from your computer, Thank 
you.*********************************************************************2


Reply via email to