Received: from bonito.atc.unican.es (bonito.atc.unican.es [193.144.185.218]) by postgresql.org (Postfix) with ESMTP id 59061475DBA for ; Thu, 11 Jul 2002 11:18:20 -0400 (EDT) Received: from ALIGOTE (aligote [193.144.185.202]) by bonito.atc.unican.es (8.11.0/8.8.7) with SMTP id g6BFIQb08690 for ; Thu, 11 Jul 2002 17:18:26 +0200 Message-ID: <005e01c228ee$bd1913e0$cab990c1@atc.unican.es> From: "Luis Alberto Amigo Navarro" To: Subject: please help on query Date: Thu, 11 Jul 2002 17:22:14 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_005B_01C228FF.7FFB6AB0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Archive-Number: 200207/460 X-Sequence-Number: 24834 This is a multi-part message in MIME format. ------=_NextPart_000_005B_01C228FF.7FFB6AB0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I can't improve performance on this query: SELECT supplier.name, supplier.address FROM supplier, nation WHERE supplier.suppkey IN( SELECT partsupp.suppkey FROM partsupp WHERE partsupp.partkey IN( SELECT part.partkey FROM part WHERE part.name like 'forest%' ) AND partsupp.availqty>( SELECT 0.5*(sum(lineitem.quantity)::FLOAT) FROM lineitem WHERE lineitem.partkey=3Dpartsupp.partkey AND lineitem.suppkey=3Dpartsupp.partkey AND lineitem.shipdate>=3D('1994-01-01')::DATE AND lineitem.shipdate<(('1994-01-01')::DATE+('1 year')::INTERVAL)::DATE ) ) AND supplier.nationkey=3Dnation.nationkey AND nation.name=3D'CANADA' ORDER BY supplier.name; explain results: NOTICE: QUERY PLAN: Sort (cost=3D2777810917708.17..2777810917708.17 rows=3D200 width=3D81) -> Nested Loop (cost=3D0.00..2777810917700.53 rows=3D200 width=3D81) -> Seq Scan on nation (cost=3D0.00..1.31 rows=3D1 width=3D4) -> Index Scan using snation_index on supplier (cost=3D0.00..27778= 10917696.72 rows=3D200 width=3D77) SubPlan -> Materialize (cost=3D6944527291.72..6944527291.72 rows= =3D133333 width=3D4) -> Seq Scan on partsupp (cost=3D0.00..6944527291.72= rows=3D133333 width=3D4) SubPlan -> Materialize (cost=3D8561.00..8561.00 row= s=3D1 width=3D4) -> Seq Scan on part (cost=3D0.00..856= 1.00 rows=3D1 width=3D4) -> Aggregate (cost=3D119.61..119.61 rows=3D= 1 width=3D4) -> Index Scan using lineitem_index on = lineitem (cost=3D0.00..119.61 rows=3D1 width=3D4) partsupp::800000 tuples Table "partsupp" Column | Type | Modifiers=20 ------------+----------------+----------- partkey | integer | not null suppkey | integer | not null availqty | integer |=20 supplycost | numeric(10,2) |=20 comment | character(199) |=20 Primary key: partsupp_pkey Triggers: RI_ConstraintTrigger_16597, RI_ConstraintTrigger_16603 tpch=3D# select attname,n_distinct,correlation from pg_stats where tablenam= e=3D'partsupp'; attname | n_distinct | correlation=20 ------------+------------+------------- partkey | -0.195588 | 1 suppkey | 9910 | 0.00868363 availqty | 9435 | -0.00788662 supplycost | -0.127722 | -0.0116864 comment | -1 | 0.0170702 I accept query changes, reordering, indexes ideas and horizontal partitioni= ng thanks in advance. Regards ------=_NextPart_000_005B_01C228FF.7FFB6AB0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I can't improve performance on this=20 query:
 
SELECT
 supplier.name,
 supplier.address
FROM supplier,
 nation
WHERE
 supplier.suppkey=20 IN(
  SELECT
   partsupp.suppkey
 &n= bsp;FROM
   partsupp
  WHERE
  =  partsupp.partkey=20 IN(
    SELECT
     part= .partkey
    FROM
     p= art
    WHERE
     part.= name=20 like 'forest%'
     )
   AND= =20 partsupp.availqty>(
    SELECT
  &nb= sp;  0.5*(sum(lineitem.quantity)::FLOAT)
   &nb= sp;FROM
     lineitem
   &nbs= p;WHERE
     lineitem.partkey=3Dpartsupp.partke= y
     AND=20 lineitem.suppkey=3Dpartsupp.partkey
     AND=20 lineitem.shipdate>=3D('1994-01-01')::DATE
    &nb= sp;AND=20 lineitem.shipdate<(('1994-01-01')::DATE+('1=20 year')::INTERVAL)::DATE
     )
  )=
 AND=20 supplier.nationkey=3Dnation.nationkey
 AND nation.name=3D'CANADA'ORDER=20 BY
 supplier.name;
 
explain results:
NOTICE:  QUERY PLAN:
 
Sort  (cost=3D2777810917708.17..27778= 10917708.17=20 rows=3D200 width=3D81)
  ->  Nested Loop =20 (cost=3D0.00..2777810917700.53 rows=3D200=20 width=3D81)
        ->  Seq S= can on=20 nation  (cost=3D0.00..1.31 rows=3D1=20 width=3D4)
        ->  Index = Scan=20 using snation_index on supplier  (cost=3D0.00..2777810917696.72 rows= =3D200=20 width=3D77)
          =    =20 SubPlan
          &nbs= p;    =20 ->  Materialize  (cost=3D6944527291.72..6944527291.72 rows=3D1= 33333=20 width=3D4)
          &= nbsp;          =20 ->  Seq Scan on partsupp  (cost=3D0.00..6944527291.72 rows=3D1= 33333=20 width=3D4)
          &= nbsp;           &nbs= p;    =20 SubPlan
          &nbs= p;            &= nbsp;     =20 ->  Materialize  (cost=3D8561.00..8561.00 rows=3D1=20 width=3D4)
          &= nbsp;           &nbs= p;            = =20 ->  Seq Scan on part  (cost=3D0.00..8561.00 rows=3D1=20 width=3D4)
          &= nbsp;           &nbs= p;      =20 ->  Aggregate  (cost=3D119.61..119.61 rows=3D1=20 width=3D4)
          &= nbsp;           &nbs= p;            = =20 ->  Index Scan using lineitem_index on lineitem  (cost=3D0.00.= .119.61=20 rows=3D1 width=3D4)
partsupp::800000 tuples
           = Table=20 "partsupp"
   Column   |    &nbs= p;=20 Type      | Modifiers=20
------------+----------------+-----------
 partkey  &= nbsp;=20 | integer        | not=20 null
 suppkey    |=20 integer        | not=20 null
 availqty   |=20 integer        |
 supplycost |= =20 numeric(10,2)  |
 comment    | character(199) = |=20
Primary key: partsupp_pkey
Triggers:=20 RI_ConstraintTrigger_16597,
       &n= bsp; =20 RI_ConstraintTrigger_16603
tpch=3D# select attname,n_distinct,correla= tion from=20 pg_stats where tablename=3D'partsupp';
  attname   | n_di= stinct=20 | correlation=20
------------+------------+-------------
 partkey  &nb= sp;=20 |  -0.195588 |         &n= bsp;=20 1
 suppkey    |       = 9910=20 |  0.00868363
 availqty  =20 |       9435 | -0.00788662
 supplycos= t=20 |  -0.127722 |  -0.0116864
 comment   =20 |         -1 |  =20 0.0170702
I accept query changes, reordering, indexe= s ideas=20 and horizontal partitioning
thanks in advance.
Regards
 
 
 
------=_NextPart_000_005B_01C228FF.7FFB6AB0--