Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: which is fast and good output
Mark D Powell wrote:
> On Dec 14, 8:17 pm, Frank van Bortel <frank.van.bor..._at_gmail.com>
> wrote:
> > oracle dba schreef:
> >
> >
> >
> > > Hello All,
> >
> > > I am showing 2 explain plans, please tell me which is good and why.
> >
> > > SQL> @?\rdbms\admin\utlxplp.sql
> >
> > > PLAN_TABLE_OUTPUT
> > > -------------------------------------------------------------------------
> >
> > > ------------------------------------------------------------------------
> > > | Id | Operation | Name | Rows | Bytes | Cost
> > > |
> > > ------------------------------------------------------------------------
> > > | 0 | SELECT STATEMENT | | 1 | 235 | 6
> > > |
> > > |* 1 | VIEW | | 1 | 235 | 6
> > > |
> > > |* 2 | WINDOW SORT PUSHED RANK| | 1 | 40 | 6
> > > |
> > > |* 3 | TABLE ACCESS FULL | N | 1 | 40 | 4
> > > |
> > > ------------------------------------------------------------------------
> >
> > > SQL> @?\rdbms\admin\utlxplp.sql
> >
> > > PLAN_TABLE_OUTPUT
> > > ----------------------------------------------------------------------
> >
> > > --------------------------------------------------------------------
> > > | Id | Operation | Name | Rows | Bytes | Cost |
> > > --------------------------------------------------------------------
> > > | 0 | SELECT STATEMENT | | 1 | 40 | 4 |
> > > |* 1 | TABLE ACCESS FULL | N | 1 | 40 | 4 |
> > > |* 2 | TABLE ACCESS FULL | N | 1 | 15 | 4 |
> > > |* 3 | TABLE ACCESS FULL | N | 1 | 15 | 4 |
> > > --------------------------------------------------------------------The mauve one.
> >
> > --
> > Regards,
> > Frank van Bortel
> >
> > Top-posting is one way to shut me up...- Hide quoted text -- Show quoted text -
> >
>
>
here cost is 6
SELECT a,b,n,whateverElse
FROM
(SELECT t.*,DENSE_RANK() OVER (PARTITION BY a ORDER BY a,b,n) rn
FROM tblTest t WHERE a=12 AND NVL(b,3)=3 AND NVL(n,7)=7) WHERE rn=1;
here cost is 4
select a,b,n,whateverElse from tblTest
where (a=12 and b is null and not exists
(select 1 from n where a=12 and b=3 and (n is null or n=7)))
or(a=12 and b=3 and n is null and
not exists(select 1 from n where a=12 and b=3 and n=7))
or
(a=12 and b=3 and n=7)
Received on Thu Dec 14 2006 - 22:59:30 CST