Re: Partitioned Database and Choosing Subtables - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Partitioned Database and Choosing Subtables
Date
Msg-id 85AA656D-2E4E-47C0-9EF9-831EF101A514@solfertje.student.utwente.nl
Whole thread Raw
In response to Re: Partitioned Database and Choosing Subtables  (Bill Thoen <bthoen@gisnet.com>)
Responses Re: Partitioned Database and Choosing Subtables  (Bill Thoen <bthoen@gisnet.com>)
List pgsql-general
>> Try using "dynamic" sql:
>>
>> EXECUTE 'SELECT lions,  tigers, bears, statecode FROM WildLife WHERE
>> state_pt = ' || statecode INTO ...;

> Thanks Igor. It was a nice try -- and I thought it would work, but the Planner had other plans. Basically, I tried
theinteractive method using a PREPARE statement with one text parammeter followed by an EXECUTE statement.
Unfortunately,the query still went rummaging across the entire database sequentially. 


That's not the same as using dynamic SQL. In fact, that would behave just like your previous, problematic, query.

Dynamic SQL makes that the planner sees a new query each time, that needs to be planned from scratch.

OTOH, using prepared statements the query plan is stored with placeholders for the parameter values at the moment the
PREPAREexecutes. That query plan is already set in stone - it will be a generic plan that can't be optimised for
differentvalues of parameters anymore. Not what you want. 

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.


!DSPAM:737,4d8069c0235881427912932!



pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: A join of 2 tables with sum(column) > 30
Next
From: Alban Hertroys
Date:
Subject: Re: how to use savepoint and rollback in function