Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UrcNw-0004hK-2q for pgsql-performance@arkaria.postgresql.org; Tue, 25 Jun 2013 23:10:52 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1UrcNv-0004Dv-Ef for pgsql-performance@arkaria.postgresql.org; Tue, 25 Jun 2013 23:10:51 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UrcNu-0004Do-7a for pgsql-performance@postgresql.org; Tue, 25 Jun 2013 23:10:50 +0000 Received: from smtp.01.com ([199.36.142.181] helo=smtp-out-1.01.com) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UrcNn-0007Uj-Id for pgsql-performance@postgresql.org; Tue, 25 Jun 2013 23:10:49 +0000 Received: from localhost (localhost [127.0.0.1]) by smtp-out-1.01.com (Postfix) with ESMTP id 7185D29409C; Tue, 25 Jun 2013 18:10:42 -0500 (CDT) X-Virus-Scanned: amavisd-new at smtp-out-1.01.com Received: from smtp-out-1.01.com ([127.0.0.1]) by localhost (smtp-out-1.01.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DxyIk-fbNAti; Tue, 25 Jun 2013 18:10:42 -0500 (CDT) Received: from smtp-out-1.01.com (localhost [127.0.0.1]) by smtp-out-1.01.com (Postfix) with ESMTP id 50ECF2940F9; Tue, 25 Jun 2013 18:10:42 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by smtp-out-1.01.com (Postfix) with ESMTP id 437C22940F3; Tue, 25 Jun 2013 18:10:42 -0500 (CDT) X-Virus-Scanned: amavisd-new at smtp-out-1.01.com Received: from smtp-out-1.01.com ([127.0.0.1]) by localhost (smtp-out-1.01.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Bq0iIxcT4CvA; Tue, 25 Jun 2013 18:10:42 -0500 (CDT) Received: from [172.47.23.103] (70-36-143-10.dsl.dynamic.sonic.net [70.36.143.10]) by smtp-out-1.01.com (Postfix) with ESMTPSA id CFC6D29409C; Tue, 25 Jun 2013 18:10:41 -0500 (CDT) Message-ID: <51CA2370.7040803@agliodbs.com> Date: Tue, 25 Jun 2013 16:10:40 -0700 From: Josh Berkus Organization: PostgreSQL Experts Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: Tom Lane CC: "pgsql-performance@postgresql.org" Subject: Re: Weird, bad 0.5% selectivity estimate for a column equal to itself References: <51C4AEE5.8040704@agliodbs.com> <25930.1371850378@sss.pgh.pa.us> <51C4D1E8.6090602@agliodbs.com> <24522.1371932688@sss.pgh.pa.us> In-Reply-To: X-Enigmail-Version: 1.5.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org > Personally, I'll bet lunch that that external software is outright > broken, ie it probably thinks "X = X" is constant true and they found > they could save two lines of code and a few machine cycles by emitting > that rather than not emitting anything. Of course, the amount of > parsing/planning time wasted in dealing with the useless-and-incorrect > clause exceeds what was saved by multiple orders of magnitude, but hey > it was easy. Well, it was more in the form of: tab1.x = COALESCE(tab2.y,tab1.x) ... which some programmer 8 years ago though would be a cute shorthand for: tab.x = tab2.y OR tab2.y IS NULL Still stupid, sure, but when you're dealing with partly-third-party legacy software which was ported from MSSQL (which has issues with "IS NULL"), that's what you get. > It wouldn't take too much new code to get the planner to replace "X = X" > with "X IS NOT NULL", but I think we're probably fixing the wrong piece > of software if we do. Well, I'd be more satisfied with having a solution for: WHERE tab1.x = tab1.y ... in general, even if it didn't have correlation stats. Like, what's preventing us from using the same selectivity logic we would on a join for that? It wouldn't be accurate for highly correlated columns (or for colX = colx) but it would be a damsight better than defaultsel. Heck, even multiplying the the two ndistincts together would be an improvement ... -- Josh Berkus PostgreSQL Experts Inc. http://pgexperts.com -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance