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 52CCEDAA17 for ; Thu, 10 Nov 2005 04:50:44 -0400 (AST) 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 21371-09 for ; Thu, 10 Nov 2005 08:50:40 +0000 (GMT) X-Greylist: delayed 00:05:03.677166 by SQLgrey- Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.183]) by svr1.postgresql.org (Postfix) with ESMTP id 11F93DA747 for ; Thu, 10 Nov 2005 04:50:40 -0400 (AST) Received: from p508E7143.dip.t-dialin.net [80.142.113.67] (helo=swtexchange2.technology.de) by mrelayeu.kundenserver.de (node=mrelayeu7) with ESMTP (Nemesis), id 0ML2Dk-1Ea83r1Gyi-0003P7; Thu, 10 Nov 2005 09:45:35 +0100 content-class: urn:content-classes:message Subject: Re: (View and SQL) VS plpgsql MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Thu, 10 Nov 2005 09:45:34 +0100 X-MimeOLE: Produced By Microsoft Exchange V6.0.6556.0 Message-ID: <16F953410A0F1346848DCB476A989CFE01D5D2@swtexchange2.technology.de> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: (View and SQL) VS plpgsql Thread-Index: AcXlbjcI8fv5lTwCRd6ecpvDfXlSkAAZBSFQAAAER0A= From: =?iso-8859-1?Q?N=F6rder-Tuitje=2C_Marcus?= To: "Eric Lauzon" , X-Provags-ID: kundenserver.de abuse@kundenserver.de login:24478085a861b01e05bdc3b8f80dc176 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.134 required=5 tests=[AWL=0.134] X-Spam-Score: 0.134 X-Spam-Level: X-Archive-Number: 200511/172 X-Sequence-Number: 15429 FOR r_record IN SELECT count(cid) AS hits,src, bid, tid,NULL::int8 as = min_time,NULL::int8 as max_time FROM archive_event WHERE inst=3D\'3\' = AND (utctime BETWEEN \'1114920000\' AND \'1131512399\') GROUP BY src, = bid, tid LOOP SELECT INTO one_record MIN(utctime) as timestart,MAX(utctime) as = timestop from archive_event where src =3Dr_record.src AND bid = =3Dr_record.bid AND tid =3D r_record.tid AND inst =3D\'3\' AND (utctime = BETWEEN \'1114920000\' AND \'1131512399\'); (it seems to me, that you might combine both queries) 1. have you ever tried to select the min/max within the first stmt ? as = i see you are reducing data in second stmt using same key as in stmt 1. 2. you are querying data using two keys (int, utctime). you may create = a combined index speeding up your query 3. same for grouping. you are grouping over three fields. composite = indexing may helps (8.1 supports index based grouping) regards, marcus -----Urspr=FCngliche Nachricht----- Von: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owner@postgresql.org]Im Auftrag von Eric Lauzon Gesendet: Mittwoch, 9. November 2005 21:43 An: pgsql-performance@postgresql.org Betreff: [PERFORM] (View and SQL) VS plpgsql Hello all , i post this question here because i wasen't able to find answer to my question elsewhere , i hope someone can answer. Abstract: The function that can be found at the end of the e-mail emulate two = thing. First it will fill a record set of result with needed column from a = table and two "empty result column" a min and a max. Those two column are then filled by a second query on the same table = that will do a min and a max on an index idx_utctime. The function loop for the first recordset and return a setof record that = is casted by caller to the function. The goald of this is to enabled the application that will receive the = result set to minimise its work by having to group internaly two matching rowset. We use to handle = two resultset but i am looking toward improving performances and at first glance it seem to speed up = the process. Questions: 1. How could this be done in a single combinasion of SQL and view?=20 2. In a case like that is plpgsql really givig significant overhead? 3. Performance difference [I would need a working pure-SQL version to = compare PLANNER and Explain results ] STUFF: --TABLE && INDEX CREATE TABLE archive_event ( inst int4 NOT NULL, cid int8 NOT NULL, src int8 NOT NULL, dst int8 NOT NULL, bid int8 NOT NULL, tid int4 NOT NULL, utctime int4 NOT NULL, CONSTRAINT ids_archives_event_pkey PRIMARY KEY (inst, cid), CONSTRAINT ids_archives_event_cid_index UNIQUE (cid) )=20 --index CREATE INDEX idx_archive_utctime ON archive_event USING btree (utctime); CREATE INDEX idx_archive_src ON archive_event USING btree (src); CREATE INDEX idx_archive_bid_tid ON archive_event USING btree (tid, bid); --FUNCTION CREATE OR REPLACE FUNCTION console_get_source_rule_level_1() RETURNS SETOF RECORD AS ' DECLARE one_record record; r_record record; BEGIN FOR r_record IN SELECT count(cid) AS hits,src, bid, tid,NULL::int8 as = min_time,NULL::int8 as max_time FROM archive_event WHERE inst=3D\'3\' = AND (utctime BETWEEN \'1114920000\' AND \'1131512399\') GROUP BY src, = bid, tid LOOP SELECT INTO one_record MIN(utctime) as timestart,MAX(utctime) as = timestop from archive_event where src =3Dr_record.src AND bid = =3Dr_record.bid AND tid =3D r_record.tid AND inst =3D\'3\' AND (utctime = BETWEEN \'1114920000\' AND \'1131512399\'); r_record.min_time :=3D one_record.timestart; r_record.max_time :=3D one_record.timestop; =20 RETURN NEXT r_record; END LOOP; RETURN; END; ' LANGUAGE 'plpgsql' VOLATILE; GRANT EXECUTE ON FUNCTION console_get_source_rule_level_1() TO console = WITH GRANT OPTION; --FUNCTION CALLER SELECT * from get_source_rule_level_1() AS (hits int8,src int8,bid = int8,tid int4,min_time int8,max_time int8) Eric Lauzon [Recherche & D=E9veloppement] Above S=E9curit=E9 / Above Security T=E9l : (450) 430-8166 Fax : (450) 430-1858=20 ---------------------------(end of broadcast)--------------------------- TIP 4: Have you searched our list archives? http://archives.postgresql.org