X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 50FB8D1B18E for ; Thu, 13 May 2004 10:56:28 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 04981-06 for ; Thu, 13 May 2004 10:56:02 -0300 (ADT) Received: from mail.interlogica.org (host34-209.pool8174.interbusiness.it [81.74.209.34]) by svr1.postgresql.org (Postfix) with ESMTP id 5357DD1B175 for ; Thu, 13 May 2004 10:55:57 -0300 (ADT) Received: from [10.2.8.2] (helo=ilbug) by mail.interlogica.org with esmtp (Exim 3.16 #1) id 1BOGnd-00053J-00; Thu, 13 May 2004 16:03:01 +0200 From: "Fabio Panizzutti" To: "'Shridhar Daithankar'" Cc: Subject: R: Query plan on identical tables differs . Why ? Date: Thu, 13 May 2004 16:06:01 +0200 Message-ID: <006301c438f3$6ca33460$3c02020a@ufficio> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.4024 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 Importance: Normal In-Reply-To: <40A3728F.2030402@frodo.hserus.net> X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200405/122 X-Sequence-Number: 6953 >>>-----Messaggio originale----- >>>Da: pgsql-performance-owner@postgresql.org=20 >>>[mailto:pgsql-performance-owner@postgresql.org] Per conto di=20 >>>Shridhar Daithankar >>>Inviato: gioved=EC 13 maggio 2004 15.05 >>>A: Fabio Panizzutti >>>Cc: pgsql-performance@postgresql.org >>>Oggetto: Re: [PERFORM] Query plan on identical tables differs . Why ? >>> >>> >>>Fabio Panizzutti wrote: >>>> storico=3D# explain select tag_id,valore_tag,data_tag from=20 >>>> storico_misure where (data_tag>'2004-05-03' and data_tag=20 >>>> <'2004-05-12') and tag_id=3D37423 ; >>> >>>Can you please post explain analyze? That includes actual timings. storico=3D# explain analyze select tag_id,valore_tag,data_tag from storico_misure where (data_tag>'2004-05-03' and data_tag <'2004-05-12') and tag_id=3D37423 ; =20 QUERY PLAN ------------------------------------------------------------------------ ------------------------------------------------------------------------ -------------------------- Index Scan using pk_storico_misure_2 on storico_misure (cost=3D0.00..1984.64 rows=3D658 width=3D21) (actual time=3D723.441..1858.1= 07 rows=3D835 loops=3D1) Index Cond: ((data_tag > '2004-05-03 00:00:00'::timestamp without time zone) AND (data_tag < '2004-05-12 00:00:00'::timestamp without time zone) AND (tag_id =3D 37423)) Total runtime: 1860.641 ms (3 rows) storico=3D# explain analyze select tag_id,valore_tag,data_tag from storico_misure_short where (data_tag>'2004-05-03' and data_tag <'2004-05-12') and tag_id=3D37423 ; =20 QUERY PLAN ------------------------------------------------------------------------ ------------------------------------------------------------------------ ------------------- Index Scan using pk_anagtstorico_misuree_short_idx_2 on storico_misure_short (cost=3D0.00..1783.04 rows=3D629 width=3D20) (actual time=3D0.323..42.186 rows=3D864 loops=3D1) Index Cond: (tag_id =3D 37423) Filter: ((data_tag > '2004-05-03 00:00:00'::timestamp without time zone) AND (data_tag < '2004-05-12 00:00:00'::timestamp without time zone)) Total runtime: 43.166 ms >>>Looking at the schema, can you try "and=20 >>>tag_id=3D37423::integer" instead? >>> I try :=20 explain analyze select tag_id,valore_tag,data_tag from storico_misure where (data_tag>'2004-05-03' and data_tag <'2004-05-12') and tag_id=3D37423::integer; Index Scan using pk_storico_misure_2 on storico_misure (cost=3D0.00..1984.64 rows=3D658 width=3D21) (actual time=3D393.337..1303.9= 98 rows=3D835 loops=3D1) Index Cond: ((data_tag > '2004-05-03 00:00:00'::timestamp without time zone) AND (data_tag < '2004-05-12 00:00:00'::timestamp without time zone) AND (tag_id =3D 37423)) Total runtime: 1306.484 ms >>>> enable_hashagg =3D false >>>> enable_hashjoin =3D false >>>> enable_indexscan =3D true >>>> enable_mergejoin =3D true >>>> enable_nestloop =3D false >>>> enable_seqscan =3D true >>>> enable_sort =3D false >>>> enable_tidscan =3D false >>>Why do you have these off? AFAIK, 7.4 improved hash=20 >>>aggregates a lot. So you=20 >>>might miss on these in this case. I try for debug purpose , now i reset all 'enable' to default : =20 select * from pg_settings where name like 'enable%'; name | setting | context | vartype | source | min_val | max_val ------------------+---------+---------+---------+--------------------+-- -------+--------- enable_hashagg | on | user | bool | configuration file | | enable_hashjoin | on | user | bool | configuration file | | enable_indexscan | on | user | bool | configuration file | | enable_mergejoin | on | user | bool | configuration file | | enable_nestloop | on | user | bool | configuration file | | enable_seqscan | on | user | bool | configuration file | | enable_sort | on | user | bool | configuration file | | enable_tidscan | on | user | bool | configuration file | | (8 rows) The query plan are the same .... >>>> # - Planner Cost Constants - >>>>=20 >>>> #effective_cache_size =3D 1000 # typically 8KB each >>> >>>You might set it to something realistic. >>> I try 10000 and 100000 but nothing change . >>>And what is your hardware setup? Disks/CPU/RAM? 32GB SCSI/DUAL Intel(R) Pentium(R) III CPU family 1133MHz/ 1GB RAM and linux red-hat 9 I don't understand why the planner chose a different query plan on identical tables with same indexes .=20 Thanks a lot for help!. Fabio