X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3FF6032A083 for ; Tue, 28 Sep 2004 14:13:59 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 24625-01 for ; Tue, 28 Sep 2004 13:13:46 +0000 (GMT) Received: from hotmail.com (bay18-dav12.bay18.hotmail.com [65.54.187.192]) by svr1.postgresql.org (Postfix) with ESMTP id 61AB5329FE2 for ; Tue, 28 Sep 2004 14:13:48 +0100 (BST) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Tue, 28 Sep 2004 06:05:01 -0700 Received: from 67.81.98.198 by bay18-dav12.bay18.hotmail.com with DAV; Tue, 28 Sep 2004 13:04:34 +0000 X-Originating-IP: [67.81.98.198] X-Originating-Email: [awerman2@hotmail.com] X-Sender: awerman2@hotmail.com From: "Aaron Werman" To: "Iain" , "Tom Lane" Cc: "Jim C. Nasby" , References: <20040923152925.18234.qmail@web41114.mail.yahoo.com> <20040927191836.GS1297@decibel.org> <00b201c4a4ff$bd73b8b0$7201a8c0@mst1x5r347kymb> <9617.1096341460@sss.pgh.pa.us> Subject: Re: Caching of Queries Date: Tue, 28 Sep 2004 09:04:34 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Message-ID: X-OriginalArrivalTime: 28 Sep 2004 13:05:01.0093 (UTC) FILETIME=[C354AD50:01C4A55B] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/307 X-Sequence-Number: 8435 ----- Original Message ----- From: "Tom Lane" To: "Iain" Cc: "Jim C. Nasby" ; Sent: Monday, September 27, 2004 11:17 PM Subject: Re: [PERFORM] Caching of Queries > "Iain" writes: > > I can only tell you (roughly) how it works wth Oracle, > > Which unfortunately has little to do with how it works with Postgres. > This "latches" stuff is irrelevant to us. Latches are the Oracle term for semaphores. Both Oracle and pg use semaphores and spin locks to serialize activity in critical sections. I believe that the point that blocking/queuing reduces scalability is valid. > > In practice, any repetitive planning in PG is going to be consulting > catalog rows that it draws from the backend's local catalog caches. > After the first read of a given catalog row, the backend won't need > to re-read it unless the associated table has a schema update. (There > are some other cases, like a VACUUM FULL of the catalog the rows came > from, but in practice catalog cache entries don't change often in most > scenarios.) We need place only one lock per table referenced in order > to interlock against schema updates; not one per catalog row used. > > The upshot of all this is that any sort of shared plan cache is going to > create substantially more contention than exists now --- and that's not > even counting the costs of managing the cache, ie deciding when to throw > away entries. I imagine a design where a shared plan cache would consist of the plans, indexed by a statement hash and again by dependant objects. A statement to be planned would be hashed and matched to the cache. DDL would need to synchronously destroy all dependant plans. If each plan maintains a validity flag, changing the cache wouldn't have to block so I don't see where there would be contention. > > A backend-local plan cache would avoid the contention issues, but would > of course not allow amortizing planning costs across multiple backends. > > I'm personally dubious that sharing planning costs is a big deal. > Simple queries generally don't take that long to plan. Complicated > queries do, but I think the reusability odds go down with increasing > query complexity. > I think both the parse and planning are major tasks if the transaction rate is high. Simple queries can easily take much longer to plan than execute, so this is a scalability concern. Caching complicated queries is valuable - apps seem to have lots of similar queries because they are intimately related to the data model. > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org >