X-Original-To: pgsql-benchmarks-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C3C005E46CB; Thu, 12 Aug 2004 17:10:06 -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 42792-02; Thu, 12 Aug 2004 20:10:03 +0000 (GMT) Received: from cbc.ca (gwtor-out.cbc.ca [159.33.1.177]) by svr1.postgresql.org (Postfix) with ESMTP id 019EB5E46C0; Thu, 12 Aug 2004 17:10:01 -0300 (ADT) Received: from GWIADMOUT-MTA by cbc.ca with Novell_GroupWise; Thu, 12 Aug 2004 16:10:03 -0400 Message-Id: X-Mailer: Novell GroupWise Internet Agent 6.5.2 Date: Thu, 12 Aug 2004 16:09:48 -0400 From: "Arash Zaryoun" To: , , Subject: Performance Problem With Postgresql! Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline 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: 200408/1 X-Sequence-Number: 14 Hi All, We are having a performance problem with our database. The problem exists when we include a constraint in GCTBALLOT. The constraint is as follows: alter table GCTBALLOT add constraint FK_GCTBALLOT_GCTWEBU foreign key (GCTWEBU_SRL) references GCTWEBU (SRL) on delete restrict on update restrict; The two tables that we insert into are the following: GCTBALLOT: Table "cbcca.gctballot" Column | Type | Modifiers ------------------+-----------------------------+----------------------------------------------------------- srl | integer | not null default nextval('cbcca.gctballot_srl_seq'::text) gctbwindow_srl | numeric(12,0) | not null gctcandidate_srl | numeric(12,0) | not null gctwebu_srl | numeric(12,0) | gctphoneu_srl | numeric(12,0) | ballot_time | timestamp without time zone | not null ip_addr | character varying(15) | Indexes: "pk_gctballot" primary key, btree (srl) "i1_gctballot_webusrl" btree (gctwebu_srl) Foreign-key constraints: "fk_gctbwindow_gctballot" FOREIGN KEY (gctbwindow_srl) REFERENCES gctbwindow(srl) ON UPDATE RESTRICT ON DELETE RESTRICT "fk_gctcandidate_gctballot" FOREIGN KEY (gctcandidate_srl) REFERENCES gctcandidate(srl) ON UPDATE RESTRICT ON DELETE RESTRICT "fk_gctphoneu_gctballot" FOREIGN KEY (gctphoneu_srl) REFERENCES gctphoneu(srl) ON UPDATE RESTRICT ON DELETE RESTRICT with the extra constraint: "fk_gctballot_gctwebu" FOREIGN KEY (gctwebu_srl) REFERENCES gctwebu(srl) ON UPDATE RESTRICT ON DELETE RESTRICT GCTWEBU: Table "cbcca.gctwebu" Column | Type | Modifiers -----------------+-----------------------------+--------------------------------------------------------- srl | integer | not null default nextval('cbcca.gctwebu_srl_seq'::text) gctlocation_srl | numeric(12,0) | not null gctagerange_srl | numeric(12,0) | not null email | character varying(255) | not null uhash | character varying(255) | not null sex | character varying(1) | not null created_time | timestamp without time zone | not null Indexes: "pk_gctwebu" primary key, btree (srl) "i1_gctwebu_email" unique, btree (email) Foreign-key constraints: "fk_gctagerang_gctwebu" FOREIGN KEY (gctagerange_srl) REFERENCES gctagerange(srl) ON UPDATE RESTRICT ON DELETE RESTRICT "fk_gctwebu_gctlocation" FOREIGN KEY (gctlocation_srl) REFERENCES gctlocation(srl) ON UPDATE RESTRICT ON DELETE RESTRICT To begin, GCTBALLOT has 6122546 rows and GCTWEBU has 231444 rows. Now when we try and insert 100 entries into GCTBALLOT with the extra constraint it takes: 37981 milliseconds Also, when we try and insert 100 entries into GCTBALLOT with the extra constraint, but insert 'null' into the column gctwebu_srl it takes: 286 milliseconds However when we try and insert 100 entries into GCTBALLOT without the extra constraint (no foreign key between GCTBALLOT & GCTWEBU) it takes: 471 milliseconds In summary, inserting into GCTBALLOT without the constraint or inserting null for gctwebu_srl in GCTBALLOT gives us good performance. However, inserting into GCTBALLOT with the constraint and valid gctwebu_srl values gives us poor performance. Also, the insert we use is as follows: INSERT INTO GCTBALLOT (gctbwindow_srl, gctcandidate_srl, gctwebu_srl, gctphoneu_srl, ballot_time, ip_addr) VALUES (CBCCA.gcf_getlocation(?), ?, CBCCA.gcf_validvoter(?,?), null, ?, ?); NOTE: "gcf_validvoter" find 'gctweb_srl' value " CREATE OR REPLACE FUNCTION gcf_validvoter (VARCHAR, VARCHAR) RETURNS NUMERIC AS ' DECLARE arg1 ALIAS FOR $1; arg2 ALIAS FOR $2; return_val NUMERIC; BEGIN SELECT SRL INTO return_val FROM gctwebu WHERE EMAIL = arg1 AND UHASH = arg2; RETURN return_val; END; ' LANGUAGE plpgsql; " Where the question marks are filled in with values in our java code. We are puzzled as to why there is this difference in performance when inserting b/c we believe that we have indexed all columns used by this constraint. And we realize that inserting 'null' into GCTBALLOT doesn't use this constraint b/c no look up is necessary. So this causes good performance. Why is it that when we use this constraint that the performance is effected so much? Any help would be much appreciated. Thanks P.S. Even we added an index on 'gctwebu_srl' column and did 1- "Analyzed ALL TABLES" 2- "analyze GCTBALLOT(gctwebu_srl);" but still have the same problem!