Re: Query optimization - Mailing list pgsql-general

From David Johnston
Subject Re: Query optimization
Date
Msg-id CAKFQuwb4_k86x7_J4Hx6KOCzkgCY8u49cbsdqdRV-B_saa6HSg@mail.gmail.com
Whole thread Raw
In response to Re: Query optimization  (Jorge Arevalo <jorgearevalo@libregis.org>)
Responses Re: Query optimization
List pgsql-general
On Wed, Oct 29, 2014 at 12:14 PM, Jorge Arevalo <jorgearevalo@libregis.org> 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.f3 = field7))) as values_array FROM table1

​More generally, you really should table-prefix all column in correlated subqueries.

[...] from table2 p where p.f3 = table1.field7 [...]

​I guess the InitPlan 1 you showed simply scanned table2 and applied the filter which then was fed to InitPlan 2 where the array is built; that array then is inserted into the outer query ~8M​ times...

David J.

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Query optimization
Next
From: Jorge Arevalo
Date:
Subject: Re: Query optimization