From rjessil@yahoo.com Fri Jul 4 00:54:38 2008 Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id DEBAA650E87 for ; Thu, 3 Jul 2008 21:54:38 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 10327-02 for ; Thu, 3 Jul 2008 21:54:27 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from web56409.mail.re3.yahoo.com (web56409.mail.re3.yahoo.com [216.252.111.88]) by postgresql.org (Postfix) with SMTP id 0D2A4650E85 for ; Thu, 3 Jul 2008 21:54:31 -0300 (ADT) Received: (qmail 48478 invoked by uid 60001); 4 Jul 2008 00:47:49 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Message-ID; b=XkfxdPuHfm08ouvEfNmyYVB6fDl0zUkcOAo8unDfNqfUO0LZpFfHsPghG/O2Ocgvw+RD6uXZJxEX1qUMIRegI1HlpFqY8SlhlDAmnIYCFkayTmIveJwnFidqjDH9ndy3oQc1Oi8tPLanH1DZxwsuzTGHcj0qwoR2JsjWg0TD/MA=; Received: from [198.119.134.32] by web56409.mail.re3.yahoo.com via HTTP; Thu, 03 Jul 2008 17:47:49 PDT X-Mailer: YahooMailRC/1042.33 YahooMailWebService/0.7.199 Date: Thu, 3 Jul 2008 17:47:49 -0700 (PDT) From: Jessica Richard Subject: slow delete... To: pgsql-admin@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1268677426-1215132469=:47881" Message-ID: <695185.47881.qm@web56409.mail.re3.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200807/60 X-Sequence-Number: 29670 --0-1268677426-1215132469=:47881 Content-Type: text/plain; charset=us-ascii I have a table with 29K rows total and I need to delete about 80K out of it. I have a b-tree index on column cola (varchar(255) ) for my where clause to use. my "select count(*) from test where cola = 'abc' runs very fast, but my actual "delete from test where cola = 'abc';" takes forever, never can finish and I haven't figured why.... In my explain output, what is that "Bitmap Heap Scan on table"? is it a table scan? is my index being used? How does delete work? to delete 80K rows that meet my condition, does Postgres find them all and delete them all together or one at a time? by the way, there is a foreign key on another table that references the primary key col0 on table test. Could some one help me out here? Thanks a lot, Jessica testdb=# select count(*) from test; count -------- 295793 --total 295,793 rows (1 row) Time: 155.079 ms testdb=# select count(*) from test where cola = 'abc'; count ------- 80998 - need to delete 80,988 rows (1 row) testdb=# explain delete from test where cola = 'abc'; QUERY PLAN ---------------------------------------------------------------------------------------------------- Bitmap Heap Scan on test (cost=2110.49..10491.57 rows=79766 width=6) Recheck Cond: ((cola)::text = 'abc'::text) -> Bitmap Index Scan on test_cola_idx (cost=0.00..2090.55 rows=79766 width=0) Index Cond: ((cola)::text = 'abc'::text) (4 rows) --0-1268677426-1215132469=:47881 Content-Type: text/html; charset=us-ascii
I have a table with 29K rows total and I need to delete about 80K out of it.

I have a b-tree index on column cola (varchar(255) ) for my where clause to use.

my "select count(*) from test where cola = 'abc' runs very fast,
 
but my actual "delete from test where cola = 'abc';" takes forever, never can finish and I haven't figured why....

In my explain output, what is that "Bitmap Heap Scan on table"? is it a table scan? is my index being used?

How does delete work? to delete 80K rows that meet my condition, does Postgres find them all and delete them all together or one at a time?


by the way, there is a foreign key on another table that references the primary key col0 on table test.

Could some one help me out here?

Thanks a lot,
Jessica


testdb=# select count(*) from test;
 count 
--------
 295793  --total 295,793 rows
(1 row)

Time: 155.079 ms

testdb=# select count(*) from test where cola = 'abc';
 count
-------
 80998  - need to delete 80,988 rows
(1 row)



testdb=# explain delete from test where cola = 'abc';
                                             QUERY PLAN                                            
----------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on test  (cost=2110.49..10491.57 rows=79766 width=6)
   Recheck Cond: ((cola)::text = 'abc'::text)
   ->  Bitmap Index Scan on test_cola_idx  (cost=0.00..2090.55 rows=79766 width=0)
         Index Cond: ((cola)::text = 'abc'::text)
(4 rows)


--0-1268677426-1215132469=:47881-- From charles.duffy@gmail.com Fri Jul 4 07:17:48 2008 Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 18534650E8A for ; Fri, 4 Jul 2008 04:17:48 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 84740-04 for ; Fri, 4 Jul 2008 04:17:43 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.250]) by postgresql.org (Postfix) with ESMTP id 2EFCA650E23 for ; Fri, 4 Jul 2008 04:17:45 -0300 (ADT) Received: by an-out-0708.google.com with SMTP id d30so241263and.33 for ; Fri, 04 Jul 2008 00:17:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=H0DIadYW7P49f6KjHN5PMayy5mQBQoc+8b4RESd9WXQ=; b=aGjtgYhs8t0M/FK7DK6BLl4ZwstMZfiDEUjnnZBOZF5wIPOrnqsmOYxnXCapbBiaAR jgLJ4ZSehLqziNaW018jfKUW8XVWui54mfMYts8EcZ51QUxJvWOnt15nxBT6mKgZgoNt dKadaNvn5dFGdWahy2QnRjRmxgTDr7oMSa9qw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=slgmEUOhrEEBVjDUBrdHzJhLmR8p4lJ/8lQJt+E6WIHT0H7Gr12cAI+vaBRCTyMySE a+SlePZQx/kyAMuPHrvgF32sQn6ULMAV9lL7agCx4bBHMjvYUBh2gpW7ZwAHcbTyuJuS pE1r71UCZKQKWBiIoA7X0j6PCiweZDadrS4AU= Received: by 10.100.31.3 with SMTP id e3mr177021ane.21.1215155864251; Fri, 04 Jul 2008 00:17:44 -0700 (PDT) Received: by 10.100.172.18 with HTTP; Fri, 4 Jul 2008 00:17:43 -0700 (PDT) Message-ID: Date: Fri, 4 Jul 2008 17:17:43 +1000 From: "Charles Duffy" To: "Jessica Richard" Subject: Re: slow delete... Cc: pgsql-admin@postgresql.org In-Reply-To: <695185.47881.qm@web56409.mail.re3.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <695185.47881.qm@web56409.mail.re3.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200807/62 X-Sequence-Number: 29672 > by the way, there is a foreign key on another table that references the > primary key col0 on table test. > Try putting an index on the FK column in the other table. Analyse the table. Test by starting a transaction then issuing: explain analyze delete from test where cola = 'abc'. Should be faster. Charles Duffy From rjessil@yahoo.com Fri Jul 4 12:37:01 2008 Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id B605D650EA7 for ; Fri, 4 Jul 2008 09:37:01 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 87549-02 for ; Fri, 4 Jul 2008 09:36:50 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from web56415.mail.re3.yahoo.com (web56415.mail.re3.yahoo.com [216.252.111.94]) by postgresql.org (Postfix) with SMTP id 502F9650EA8 for ; Fri, 4 Jul 2008 09:36:43 -0300 (ADT) Received: (qmail 61840 invoked by uid 60001); 4 Jul 2008 12:36:40 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Received:X-Mailer:Date:From:Subject:To:Cc:MIME-Version:Content-Type:Message-ID; b=Tp3jJp1mOkH3F8EclIyC0Pkn9SI95iKy4pIVv3FUlKMmnCjZ3E4d+TOx6oKtGzHIyBAyh7iKDuNfr0DZia4EPd/uEIk34yY9dn2JGu79eT8Rqjv0FeC6NaCJzSff3aDOTGMgh3+d285nSibC19efK21ORWpD3dZLqaF5VCZYBpw=; Received: from [98.166.112.215] by web56415.mail.re3.yahoo.com via HTTP; Fri, 04 Jul 2008 05:36:40 PDT X-Mailer: YahooMailRC/1042.33 YahooMailWebService/0.7.199 Date: Fri, 4 Jul 2008 05:36:40 -0700 (PDT) From: Jessica Richard Subject: Re: slow delete... To: Charles Duffy Cc: pgsql-admin@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1834116338-1215175000=:61618" Message-ID: <310112.61618.qm@web56415.mail.re3.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200807/64 X-Sequence-Number: 29674 --0-1834116338-1215175000=:61618 Content-Type: text/plain; charset=us-ascii thanks a lot. I imagine this will help me a lot. I will give it a try!!! One more question: in the explain output, what is that "Bitmap Heap Scan on test"?, is it a bad thing (a table scan)? I would love to see the index scan instead of this Heap scan... what does "Heap Scan" actually do here? Bitmap Heap Scan on test (cost=2110.49..10491.57 rows=79766 width=6) Recheck Cond: ((cola)::text = 'abc'::text) -> Bitmap Index Scan on test_cola_idx (cost=0.00..2090.55 rows=79766 width=0) Index Cond: ((cola)::text = 'abc'::text) (4 rows) Thanks again, Jessica ----- Original Message ---- From: Charles Duffy To: Jessica Richard Cc: pgsql-admin@postgresql.org Sent: Friday, July 4, 2008 3:17:43 AM Subject: Re: [ADMIN] slow delete... > by the way, there is a foreign key on another table that references the > primary key col0 on table test. > Try putting an index on the FK column in the other table. Analyse the table. Test by starting a transaction then issuing: explain analyze delete from test where cola = 'abc'. Should be faster. Charles Duffy -- Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin --0-1834116338-1215175000=:61618 Content-Type: text/html; charset=us-ascii
thanks a lot. I imagine this will help me a lot. I will give it a try!!!

One more question: in the explain output, what is that "Bitmap Heap Scan on test"?, is it a bad thing (a table scan)? I would love to see the index scan instead of this Heap scan... what does "Heap Scan" actually do here?

 Bitmap Heap Scan on test  (cost=2110.49..10491.57 rows=79766 width=6)
   Recheck Cond: ((cola)::text = 'abc'::text)
   ->  Bitmap Index Scan on test_cola_idx  (cost=0.00..2090.55 rows=79766 width=0)
         Index Cond: ((cola)::text = 'abc'::text)
(4 rows)

Thanks again,
Jessica

----- Original Message ----
From: Charles Duffy <charles.duffy@gmail.com>
To: Jessica Richard <rjessil@yahoo.com>
Cc: pgsql-admin@postgresql.org
Sent: Friday, July 4, 2008 3:17:43 AM
Subject: Re: [ADMIN] slow delete...

> by the way, there is a foreign key on another table that references the
> primary key col0 on table test.
>

Try putting an index on the FK column in the other table. Analyse the
table. Test by starting a transaction then
issuing: explain analyze delete from test where cola = 'abc'. Should be faster.


Charles Duffy

--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin

--0-1834116338-1215175000=:61618--