X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3C27F3A3F09 for ; Sat, 6 Nov 2004 00:26:57 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 10307-09 for ; Sat, 6 Nov 2004 00:26:49 +0000 (GMT) Received: from web52107.mail.yahoo.com (web52107.mail.yahoo.com [206.190.39.76]) by svr1.postgresql.org (Postfix) with SMTP id 200B13A3F0C for ; Sat, 6 Nov 2004 00:26:51 +0000 (GMT) Message-ID: <20041106002649.19809.qmail@web52107.mail.yahoo.com> Received: from [198.182.200.22] by web52107.mail.yahoo.com via HTTP; Fri, 05 Nov 2004 16:26:49 PST Date: Fri, 5 Nov 2004 16:26:49 -0800 (PST) From: patrick ~ Subject: Re: vacuum analyze slows sql query To: pgsql-performance@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/118 X-Sequence-Number: 9072 Looking around at the pg_ tables and some PostgreSQL online docs prompted by another post/reply on this list regarding ALERT TABLE SET STATISTICS i found out that prior to a VACUUM the following select (taken from the online docs) shows: pkk=# select relname, relkind, reltuples, relpages from pg_class where relname like 'pkk_%'; relname | relkind | reltuples | relpages -------------------+---------+-----------+---------- pkk_billing | r | 1000 | 10 pkk_offer | r | 1000 | 10 pkk_offer_pkey | i | 1000 | 1 pkk_purchase | r | 1000 | 10 pkk_purchase_pkey | i | 1000 | 1 (5 rows) Time: 1097.263 ms and after a VACUUM: pkk=# vacuum analyze ; VACUUM Time: 100543.359 ms it shows: pkk=# select relname, relkind, reltuples, relpages from pg_class where relname like 'pkk_%'; relname | relkind | reltuples | relpages -------------------+---------+-------------+---------- pkk_billing | r | 714830 | 4930 pkk_offer | r | 618 | 6 pkk_offer_pkey | i | 618 | 4 pkk_purchase | r | 1.14863e+06 | 8510 pkk_purchase_pkey | i | 1.14863e+06 | 8214 (5 rows) Time: 3.868 ms Further, I notice that if I were to delete rows from the pg_statistic table I get the db in a state where the query is fast again: pkk=# explain analyze select offer_id, pkk_offer_has_pending_purch( offer_id ) from pkk_offer ; QUERY PLAN ----------------------------------------------------------------------------------------------------------------- Seq Scan on pkk_offer (cost=0.00..13.72 rows=618 width=4) (actual time=2415.739..1065709.092 rows=618 loops=1) Total runtime: 1065711.651 ms (2 rows) Time: 1065713.446 ms pkk=# delete from pg_statistic where pg_statistic.starelid = pg_class.oid and pg_class.relname like 'pkk_%'; DELETE 11 Time: 3.368 ms pkk=# select offer_id, pkk_offer_has_pending_purch( offer_id ) from pkk_offer ; (618 rows) Time: 876.377 ms pkk=# explain analyze select offer_id, pkk_offer_has_pending_purch( offer_id ) from pkk_offer ; QUERY PLAN ---------------------------------------------------------------------------------------------------------- Seq Scan on pkk_offer (cost=0.00..13.72 rows=618 width=4) (actual time=1.329..846.786 rows=618 loops=1) Total runtime: 848.170 ms (2 rows) Time: 849.958 ms Now, I'm sure someone (a PostgreSQL developer most likely) is about to shoot me for doing such a thing :-) But, however *ugly, wrong, sacrilege* this may be, if this is the only solution...err workaround I have that will help me i must resort to it. The only two questions I have about this are: 1. Is this really the only solution left for me? 2. Am I in anyway screwing the db doing this? Best regards, --patrick __________________________________ Do you Yahoo!? Check out the new Yahoo! Front Page. www.yahoo.com