Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 66F3F47653F for ; Wed, 15 Jan 2003 15:34:31 -0500 (EST) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by postgresql.org (Postfix) with ESMTP id 88A2A477220 for ; Wed, 15 Jan 2003 14:36:39 -0500 (EST) Received: from [66.219.92.2] (HELO chocolate-mousse) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 2315109; Wed, 15 Jan 2003 11:36:42 -0800 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: vernonw@gatewaytech.com Subject: Re: query speed joining tables Date: Tue, 14 Jan 2003 11:38:43 -0800 X-Mailer: KMail [version 1.4] Cc: pgsql-sql@postgresql.org References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200301141138.43029.josh@agliodbs.com> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/231 X-Sequence-Number: 11096 Vernon, > What I stated is my observation on my project with over twenty multivalue= d=20 detail tables. I have a selection query=20 > contained 200 characters, involving 10 tables, and using subquery. The=20 performance is not bad after properly indexing,=20 > least than 3 second (what the planner says). I will have longer queries= =20 later and hope they won't have any performance=20 > problem. One trick for you is to create a custom aggregate for string contination fo= r=20 each detail table, and that will allow you to list the values in the detail= =20 table as if they were a continuous text string. A concat aggregate is eve= n=20 fast on PostgreSQL. CREATE FUNCTION "comma_cat" (text,text) RETURNS text AS ' SELECT CASE WHEN $2 IS NULL OR $2 =3D '''' THEN $1 WHEN $1 IS NULL OR $1 =3D '''' THEN $2 ELSE $1 || '', '' || $2 END ' LANGUAGE 'sql'; CREATE FUNCTION "br_cat" (text, text) RETURNS text AS ' SELECT CASE WHEN $2 IS NULL OR $2 =3D '''' THEN $1 WHEN $1 IS NULL OR $1 =3D '''' THEN $2 ELSE $1 || ''
'' || $2 END ' LANGUAGE 'sql'; --create aggregate with html between items CREATE AGGREGATE br_list ( BASETYPE =3D text, SFUNC =3D br_cat, STYPE =3D t= ext,=20 INITCOND =3D '' ); --create aggregate with commas between items CREATE AGGREGATE comma_list ( BASETYPE =3D text, SFUNC =3D comma_cat, STYPE= =3D=20 text, INITCOND =3D '' ); -Josh Berkus