Awesome, thanks that works and is quite clear. The plan looks a bit funny on this. Any high-level synopsis on the performance of this? From: David Johnston [mailto:polobo@xxxxxxxxx]
Inline comments: On Aug 15, 2012, at 16:24, David Greco <David_Greco@xxxxxxxxxxxxxxx> wrote:
With o (id, result) as (select id, getRecord(...) from dave) Select id, (o.result).* From dave Left? Join o Using (id)
Regarding the INNER JOIN, actually it appears the opposite is true: SELECT id, generate_series(1, dave.field1) FROM Dave Works great if generate_series returns rows, but does not return any rows if generate_series does not return rows (i.e. if dave has a row with field1=null). So in fact, I need to figure out how to rewrite a LEFT
JOIN version of this query Agreed. See above example that can handle both.
From: David Johnston
[mailto:polobo@xxxxxxxxx] On Aug 15, 2012, at 15:55, David Greco <David_Greco@xxxxxxxxxxxxxxx> wrote:
I suggest putting your function calls within a CTE (common table _expression_: SQL command WITH) structure. I do not get why you think you need an "EXISTS" in the INNER JOIN situation. At worse you should make it a sub-query and add a IS NOT NULL condition on one of the function
result columns. There is no way to avoid evaluating once per record in dave but you should never have to evaluate more frequently than that. CTE and sub-selects are your friends. The original form is currently being developed but will not be available until at least 9.3 David J. |