X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id DEF18D91F0 for ; Fri, 16 Sep 2005 22:28:25 -0300 (ADT) 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 37524-03 for ; Sat, 17 Sep 2005 01:28:13 +0000 (GMT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id CA400D8F77 for ; Fri, 16 Sep 2005 22:28:15 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.13.1/8.13.1) with ESMTP id j8H1SCd7040751 for ; Sat, 17 Sep 2005 01:28:12 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.13.1/8.13.1/Submit) id j8H1SBAN040748 for pgsql-performance@postgresql.org; Sat, 17 Sep 2005 01:28:11 GMT (envelope-from news) From: Martin Nickel X-Newsgroups: pgsql.performance Subject: How can this be? Date: Fri, 16 Sep 2005 20:34:14 -0500 Organization: Hub.Org Networking Services Lines: 51 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@news.hub.org To: pgsql.performance@postgresql.org User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) To: pgsql-performance@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=-2.82 required=5 tests=[ALL_TRUSTED=-2.82] X-Spam-Level: X-Archive-Number: 200509/203 X-Sequence-Number: 14511 Hello all, Mostly Postgres makes sense to me. But now and then it does something that boggles my brain. Take the statements below. I have a table (agent) with 5300 rows. The primary key is agent_id. I can do SELECT agent_id FROM agent and it returns all PK values in less than half a second (dual Opteron box, 4G ram, SATA Raid 10 drive system). But when I do a DELETE on two rows with an IN statement, using the primary key index (as stated by EXPLAIN) it take almost 4 minutes. pg_stat_activity shows nine other connections, all idle. If someone can explain this to me it will help restore my general faith in order and consistancy in the universe. Martin -- Executing query: SELECT count(*) from agent; Total query runtime: 54 ms. Data retrieval runtime: 31 ms. 1 rows retrieved. Result: 5353 -- Executing query: VACUUM ANALYZE agent; -- Executing query: DELETE FROM agent WHERE agent_id IN (15395, 15394); Query returned successfully: 2 rows affected, 224092 ms execution time. -- Executing query: EXPLAIN DELETE FROM agent WHERE agent_id IN (15395, 15394); Index Scan using agent2_pkey, agent2_pkey on agent (cost=0.00..7.27 rows=2 width=6) Index Cond: ((agent_id = 15395) OR (agent_id = 15394)) Here's my table CREATE TABLE agent ( agent_id int4 NOT NULL DEFAULT nextval('agent_id_seq'::text), office_id int4 NOT NULL, lastname varchar(25), firstname varchar(25), ...other columns... CONSTRAINT agent2_pkey PRIMARY KEY (agent_id), CONSTRAINT agent_office_fk FOREIGN KEY (office_id) REFERENCES office (office_id) ON UPDATE RESTRICT ON DELETE RESTRICT ) WITHOUT OIDS;