Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id E46B46328A1 for ; Wed, 19 Aug 2009 03:28:02 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 67947-03 for ; Wed, 19 Aug 2009 06:27:48 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from 27.mail-out.ovh.net (27.mail-out.ovh.net [91.121.30.210]) by mail.postgresql.org (Postfix) with SMTP id C97B3632342 for ; Wed, 19 Aug 2009 03:27:50 -0300 (ADT) Received: (qmail 29170 invoked by uid 503); 19 Aug 2009 08:19:17 -0000 Received: from b9.ovh.net (HELO mail95.ha.ovh.net) (213.186.33.59) by 27.mail-out.ovh.net with SMTP; 19 Aug 2009 08:19:17 -0000 Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 19 Aug 2009 06:30:52 -0000 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO soyouz) (88.161.102.87) by ns0.ovh.net with SMTP; 19 Aug 2009 06:30:52 -0000 Date: Wed, 19 Aug 2009 08:27:52 +0200 To: "Karl Denninger" , "Tom Lane" Subject: Re: [SQL] SQL Query Performance - what gives? From: =?utf-8?Q?Pierre_Fr=C3=A9d=C3=A9ric_Caillau?= =?utf-8?Q?d?= Cc: "Kevin Grittner" , pgsql-performance@postgresql.org, pgsql-sql@postgresql.org Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: <4A8B04C7.6060702@denninger.net> <4A8AC75C0200002500029C8A@gw.wicourts.gov> <4A8B1606.2040209@denninger.net> <4A8ADDEA0200002500029CA3@gw.wicourts.gov> <4A8B334F.1010801@denninger.net> <9800.1250647338@sss.pgh.pa.us> <4A8B67DD.2020608@denninger.net> Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: <4A8B67DD.2020608@denninger.net> User-Agent: Opera Mail/9.62 (Linux) X-Ovh-Tracer-Id: 11248865970955486810 X-Ovh-Remote: 88.161.102.87 (par69-8-88-161-102-87.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|U 0.5/N X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=AWL=0.000, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200908/204 X-Sequence-Number: 35236 > The bitmask allows the setting of multiple permissions but the table > definition doesn't have to change (well, so long as the bits fit into a > word!) Finally, this is a message forum - the actual code itself is > template-driven and the bitmask permission structure is ALL OVER the > templates; getting that out of there would be a really nasty rewrite, > not to mention breaking the user (non-developer, but owner) > extensibility of the current structure. > > Is there a way to TELL the planner how to deal with this, even if it > makes the SQL non-portable or is a hack on the source mandatory? You could use an integer array instead of a bit mask, make a gist index on it, and instead of doing "mask & xxx" do "array contains xxx", which is indexable with gist. The idea is that it can get much better row estimation. Instead of 1,2,3, you can use 1,2,4,8, etc if you like. you'd probably need a function to convert a bitmask into ints and another to do the conversion back, so the rest of your app gets the expected bitmasks. Or add a bitmask type to postgres with ptoper statistics...