Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 8A90A133798E for ; Thu, 11 Nov 2010 16:56:34 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 49349-03 for ; Thu, 11 Nov 2010 20:56:27 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp02.lnh.mail.rcn.net (smtp02.lnh.mail.rcn.net [207.172.157.102]) by mail.postgresql.org (Postfix) with ESMTP id 8CF321336971 for ; Thu, 11 Nov 2010 16:56:26 -0400 (AST) Received: from ms14.lnh.mail.rcn.net ([208.58.56.82]) by smtp02.lnh.mail.rcn.net with ESMTP; 11 Nov 2010 15:56:25 -0500 Received: (from ms14.lnh.mail.rcn.net [69.182.178.231]) by ms14.lnh.mail.rcn.net (MOS 4.1.9-GA) with HTTP/1.1 id AQO09772 (AUTH gnuoytr@rcn.com); Thu, 11 Nov 2010 15:56:25 -0500 (EST) From: Subject: Re: anti-join chosen even when slower than old plan To: pgsql-performance@postgresql.org X-Mailer: Mirapoint Webmail Direct 4.1.9-GA MIME-Version: 1.0 In-Reply-To: References: <4CD9663502000025000374B1@gw.wicourts.gov> <20961.1289347680@sss.pgh.pa.us> <4CDA62C60200002500037512@gw.wicourts.gov> <4CDACBBF020000250003755B@gw.wicourts.gov> <4CDB7BAA.7020506@vmsinfo.com> <4CDBB0A40200002500037571@gw.wicourts.gov> <18450.1289499783@sss.pgh.pa.us> <19088.1289501929@sss.pgh.pa.us> <19796.1289504156@sss.pgh.pa.us> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Message-Id: <20101111155625.AQO09772@ms14.lnh.mail.rcn.net> Date: Thu, 11 Nov 2010 15:56:25 -0500 (EST) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201011/173 X-Sequence-Number: 41197 ---- Original message ---- >Date: Thu, 11 Nov 2010 15:29:40 -0500 >Fro= m: pgsql-performance-owner@postgresql.org (on behalf of Robert Haas ) >Subject: Re: [PERFORM] anti-join chosen even when= slower than old plan = >To: Tom Lane >Cc: Kevin Grittner ,Mladen Gogala ,"pgsql-performanc= e@postgresql.org" > >On Thu, Nov 11= , 2010 at 2:35 PM, Tom Lane wrote: >> Robert Haas <= robertmhaas@gmail.com> writes: >>> Yeah. =A0For Kevin's case, it seems = like we want the caching percentage >>> to vary not so much based on wh= ich table we're hitting at the moment >>> but on how much of it we're a= ctually reading. >> >> Well, we could certainly take the expected numb= er of pages to read and >> compare that to effective_cache_size. =A0The= thing that's missing in that >> equation is how much other stuff is co= mpeting for cache space. =A0I've >> tried to avoid having the planner n= eed to know the total size of the >> database cluster, but it's kind of= hard to avoid that if you want to >> model this honestly. > >I'm not= sure I agree with that. I mean, you could easily have a >database tha= t is much larger than effective_cache_size, but only that >much of it i= s hot. Or, the hot portion could move around over time. >And for reaso= ns of both technical complexity and plan stability, I >don't think we w= ant to try to model that. It seems perfectly >reasonable to say that r= eading 25% of effective_cache_size will be >more expensive *per-page* t= han reading 5% of effective_cache_size, >independently of what the tota= l cluster size is. > >> Would it be at all workable to have an estimat= e that so many megs of a >> table are in cache (independently of any ot= her table), and then we could >> scale the cost based on the expected n= umber of pages to read versus that >> number? =A0The trick here is that= DBAs really aren't going to want to set >> such a per-table number (at= least, most of the time) so we need a >> formula to get to a default e= stimate for that number based on some simple >> system-wide parameters.= =A0I'm not sure if that's any easier. > >That's an interesting idea. = For the sake of argument, suppose we >assume that a relation which is = less than 5% of effective_cache_size >will be fully cached; and anythin= g larger we'll assume that much of it >is cached. Consider a 4GB machi= ne with effective_cache_size set to >3GB. Then we'll assume that any r= elation less than 153MB table is >100% cached, a 1 GB table is 15% cach= ed, and a 3 GB table is 5% >cached. That doesn't seem quite right, tho= ugh: the caching percentage >drops off very quickly after you exceed th= e threshold. > >*thinks* > >I wondering if we could do something wit= h a formula like 3 * >amount_of_data_to_read / (3 * amount_of_data_to_r= ead + >effective_cache_size) =3D percentage NOT cached. That is, if we= 're >reading an amount of data equal to effective_cache_size, we assume= 25% >caching, and plot a smooth curve through that point. In the exam= ples >above, we would assume that a 150MB read is 87% cached, a 1GB rea= d is >50% cached, and a 3GB read is 25% cached. > >> BTW, it seems th= at all these variants have an implicit assumption that >> if you're rea= ding a small part of the table it's probably part of the >> working set= ; which is an assumption that could be 100% wrong. =A0I don't >> see a = way around it without trying to characterize the data access at >> an u= nworkably fine level, though. > >Me neither, but I think it will frequ= ently be true, and I'm not sure >it will hurt very much when it isn't. = I mean, if you execute the same >query repeatedly, that data will beco= me hot soon enough. If you >execute a lot of different queries that ea= ch touch a small portion of >a big, cold table, we might underestimate = the costs of the index >probes, but so what? There's probably no bette= r strategy for >accessing that table anyway. Perhaps you can construct= an example >where this underestimate affects the join order in an unde= sirable >fashion, but I'm having a hard time getting worked up about th= at as a >potential problem case. Our current system - where we essenti= ally >assume that the caching percentage is uniform across the board - = can >have the same problem in less artificial cases. > >-- = >Robert Haas >EnterpriseDB: http://www.enterprisedb.com >The Enterpris= e PostgreSQL Company > >-- = >Sent via pgsql-performance mailing list (pgsql-performance@postgresql.o= rg) >To make changes to your subscription: >http://www.postgresql.org/= mailpref/pgsql-performance On a thread some time ago, on a similar su= bject, I opined that I missed the ability to assign tables to tablespace= s and buffers to tablespaces, thus having the ability to isolate needed = tables (perhaps a One True Lookup Table, for example; or a Customer tabl= e) to memory without fear of eviction. I was sounding beaten about th= e face and breast. It really is an "Enterprise" way of handling the sit= uation. regards, Robert