Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 1A5E59FB61C; Wed, 7 Mar 2007 07:32:21 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 92945-05; Wed, 7 Mar 2007 07:32:04 -0400 (AST) X-Greylist: delayed 00:26:45.267083 by SQLgrey-1.7.4 X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from relay2.sitel.com.ua (houp.sitel.com.ua [217.27.144.4]) by postgresql.org (Postfix) with ESMTP id 907069FB52E; Wed, 7 Mar 2007 07:32:08 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by relay2.sitel.com.ua (Postfix) with ESMTP id C5D7945993; Wed, 7 Mar 2007 13:05:19 +0200 (EET) Received: from relay2.sitel.com.ua ([127.0.0.1]) by localhost (houp.sitel.com.ua [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 87200-01; Wed, 7 Mar 2007 13:05:17 +0200 (EET) Received: from mail.gtech.kiev.ua (mail.gtech.kiev.ua [217.27.159.169]) by relay2.sitel.com.ua (Postfix) with ESMTP id 12B9545A8A; Wed, 7 Mar 2007 13:05:17 +0200 (EET) Received: from [127.0.0.1] ([82.193.98.2]) (authenticated user tivv@gtech-ua.com) by mail.gtech.kiev.ua; Wed, 7 Mar 2007 14:05:30 +0200 Message-ID: <45EE9D8F.9080504@gtech-ua.com> Date: Wed, 07 Mar 2007 13:10:07 +0200 From: =?KOI8-R?Q?=F4=C9=CD=DE=C9=DB=C9=CE_=F7=C9=D4=C1=CC=C9=CA?= User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 Cc: pgsql-hackers@postgreSQL.org, pgsql-jdbc@postgreSQL.org Subject: Re: [JDBC] Plan invalidation vs. unnamed prepared statements References: <6080.1173201777@sss.pgh.pa.us> <1173222262.3760.2171.camel@silverbirch.site> <12575.1173223438@sss.pgh.pa.us> In-Reply-To: <12575.1173223438@sss.pgh.pa.us> Content-Type: text/plain; charset=KOI8-R; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 000722-1, 07.03.2007), Outbound message X-Antivirus-Status: Clean X-Virus-Scanned: amavisd-new at sitel.com.ua X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50 X-Spam-Level: X-Archive-Number: 200703/530 X-Sequence-Number: 100014 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).