Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > IBM DB2 > Re: Question ab...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 12 Topic 8829 of 9234
Post > Topic >>

Re: Question about MIN/MAX optimization

by Michel Esber <michel@[EMAIL PROTECTED] > Apr 25, 2008 at 09:58 AM

> Hi.
>
> Try this. It will probably generate one indexs can instead of two.
>
> with temp (abc) as
> =A0 =A0 ( select abc from T were id =A0=3D ?)
> select =A0max (abc), min(abc) from temp
>
> /dg


DG, DB2 optimized the original statement into two index scans.

Original Statement:
------------------
with temp (COLLECT_TIME) as
       (select COLLECT_TIME
       from RTM.TBL_COLLECT_PSSTAT_WIN_RTM
       where MACHINE_ID=3D ? and COLLECT_TIME > ?)
select MIN(COLLECT_TIME), MAX(COLLECT_TIME)
from temp


Optimized Statement:
-------------------
SELECT Q6.$C0, Q3.$C0
FROM
   (SELECT MAX(Q2.$C0)
   FROM
      (SELECT Q1.COLLECT_TIME
      FROM RTM.TBL_COLLECT_PSSTAT_WIN_RTM AS Q1
      WHERE (:? < Q1.COLLECT_TIME) AND (Q1.MACHINE_ID =3D :?)) AS Q2) AS
Q3,
   (SELECT MIN(Q5.$C0)
   FROM
      (SELECT Q4.COLLECT_TIME
      FROM RTM.TBL_COLLECT_PSSTAT_WIN_RTM AS Q4
      WHERE (:? < Q4.COLLECT_TIME) AND (Q4.MACHINE_ID =3D :?)) AS Q5) AS
Q6

Access Plan:
-----------
        Total Cost:             51.2774
        Query Degree:           1

              Rows
             RETURN
             (   1)
              Cost
               I/O
               |
                1
             NLJOIN
             (   2)
             51.2774
             7.9774
          /-----+-----\
        1                1
     GRPBY            GRPBY
     (   3)           (   5)
     25.6383          25.6383
     3.98869          3.98871
       |                |
     448.726          448.726
     IXSCAN           IXSCAN
     (   4)           (   6)
     87.5883          87.5879
     13.6267          13.6267
       |                |
   1.48278e+06      1.48278e+06
 INDEX: RTM       INDEX: RTM
   IPSSTAT_WIN      IPSSTAT_WIN

The overall cost is higher than the original statement :(

Thanks
 




 12 Posts in Topic:
Question about MIN/MAX optimization
Michel Esber <michel@[  2008-04-25 08:05:00 
Re: Question about MIN/MAX optimization
Serge Rielau <srielau@  2008-04-25 11:15:27 
Re: Question about MIN/MAX optimization
Michel Esber <michel@[  2008-04-25 08:41:47 
Re: Question about MIN/MAX optimization
Serge Rielau <srielau@  2008-04-25 11:52:07 
Re: Question about MIN/MAX optimization
Michel Esber <michel@[  2008-04-25 09:00:01 
Re: Question about MIN/MAX optimization
"Dan van Ginhoven&qu  2008-04-25 16:34:10 
Re: Question about MIN/MAX optimization
"Dan van Ginhoven&qu  2008-04-25 17:03:10 
Re: Question about MIN/MAX optimization
Michel Esber <michel@[  2008-04-25 09:58:22 
Re: Question about MIN/MAX optimization
Serge Rielau <srielau@  2008-04-25 19:10:25 
Re: Question about MIN/MAX optimization
Michel Esber <michel@[  2008-04-26 08:18:19 
Re: Question about MIN/MAX optimization
Serge Rielau <srielau@  2008-04-26 11:57:00 
Re: Question about MIN/MAX optimization
Michel Esber <michel@[  2008-04-26 08:20:15 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Aug 29 18:22:37 CDT 2008.