Re: [JDBC] [HACKERS] Plan invalidation vs. unnamed prepared statements

2007-03-08 Thread Тимчишин Виталий


I am from pgsql-jdbc, so I may not be in the thread, so please ignore 
places where my misunderstanding goes out.

The main two questions, IMHO, is:
1) What is the key to plan cache. Current option is some statement key 
(id). Another option would be statement text (you still need to store it 
if you want to replan at some point). In this case you can use same plan 
for multiple statements going from different sessions. That's the point 
Simon was talking about. This should significantly reduce planning, 
especially on multiple similar clients. Now, as I understand, every 
connection prepare same statements and plan then independent. Such 
change would make Application servers prepare new connections much 
faster (given they prepare a number of same statements for each 
connection, which is the case for my engine). This should work for both 
named and unnamed. Note that adding unnamed statements to cache (and not 
removing on statement disposal) may require much larger cache.

BTW: This is used by IBM DB2 UDB.
2) Specific plans when parameters are known. This is the point about 
using partial index(and sometimes even using full  index- i.e. 
specifying frequent value of some index or one of two tables in a join). 
I'd say the best would be to have generic plan and try to replan, 
starting from generic plan results (dispose any possibility that gives 
values worse then generic plan). Such a replan should be much faster 
then original planning because you have rather high starting point. 
Another option is to catch possibilities at original planning and select 
correct plan when parameters are known - you check all possible uses 
with this will be frequent value, this will match this partial index, 
... the question is the number of such plans. But since all of them 
must be better then generic (and it is possible to make a three, i.e. A 
and B are not frequent - A is frequent - A is frequent and B meets 
partial index and children must be better then parent), I'd say there 
won't be many (and you can always limit it's number and leave only the 
best if one goes out of number or even collect usages and leave the 
plans that are used).




---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [JDBC] [HACKERS] Plan invalidation vs. unnamed prepared statements

2007-03-06 Thread Dave Cramer
I think C is how the JDBC driver is written. We name the statements  
if they have been used more than prepareThreshold times.


So we have a mechanism by which to allow statements to be cached, or  
not.


Dave

On 6-Mar-07, at 1:14 PM, Tom Lane wrote:


Gregory Stark [EMAIL PROTECTED] writes:

Can we forcibly discard it if *any* messages are received that might
invalidate a plan? So basically it would work fine unless anyone  
in the system
does any DDL at all? I guess that has the downside of introducing  
random

unpredictable failures.


Ugh :-(

Or stash the query string and replan it (possibly in the query  
cache this

time) if someone executes it a second time?


I think that's either my plan A or C.

The main problem with uncontrolled replanning is that there's no  
way to
detect a change in the query properties.  For example suppose the  
query

is SELECT * FROM foo and we've already told the client (via Describe
Statement) that that returns two integer columns.  If an inval now
arrives because of ALTER TABLE foo ADD COLUMN (or perhaps worse,  
ALTER
COLUMN TYPE), we've got a problem.  If we just blindly replan then  
we'll

return tuples that do not match the previously given row description,
which will certainly break most clients.

The plan caching module has enough infrastructure to detect and  
complain

about these sorts of situations, and it also knows how to manage lock
acquisition so that once we've decided a plan is still good, the  
tables

won't change underneath us while we use the plan.  I don't see any way
to make comparable guarantees without the overhead that goes with the
cache manager.

regards, tom lane

---(end of  
broadcast)---

TIP 2: Don't 'kill -9' the postmaster




---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings