Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XjISz-0007L6-SY for pgsql-general@arkaria.postgresql.org; Wed, 29 Oct 2014 01:54:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XjISy-0002Sw-N7 for pgsql-general@arkaria.postgresql.org; Wed, 29 Oct 2014 01:54:28 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XjISx-0002Sp-Ll for pgsql-general@postgresql.org; Wed, 29 Oct 2014 01:54:27 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XjISq-0001zq-Cc for pgsql-general@postgresql.org; Wed, 29 Oct 2014 01:54:25 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1XjISp-0006CY-TI for pgsql-general@postgresql.org; Tue, 28 Oct 2014 18:54:19 -0700 Date: Tue, 28 Oct 2014 18:54:19 -0700 (PDT) From: David G Johnston To: pgsql-general@postgresql.org Message-ID: <1414547659900-5824746.post@n5.nabble.com> In-Reply-To: References: Subject: Re: Query optimization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: 0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org Jorge Ar=C3=A9valo-2 wrote > (SELECT value1,value2,value3,value4,value5, hstore(ARRAY['field9', > 'field10', 'field11', 'field12', 'field13', 'field14'], ARRAY[field9, > field10, field11, field12, field13, field14) as metadata, value7, (select > array((select row(f1, f2) from table2 p where p.field7 =3D field7))) as > values_array FROM table1) You might try seeing whether: FROM table1 JOIN ( SELECT field7, array_agg(row(f1, f2)) AS values_array FROM table2 GROUP BY field7 ) tbl2_agg USING (field7) helps... I'm also dubious (though this isn't necessarily a performance issue) of: array[...] AS metadata Without context I would say this would be better as a composite type instead of an array. You may find it useful to use named composite types elsewhere too... David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/Query= -optimization-tp5824739p5824746.html Sent from the PostgreSQL - general mailing list archive at Nabble.com. --=20 Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general