Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 34ABD2E2F1D for ; Sat, 12 Jan 2008 01:18:08 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 10427-01 for ; Sat, 12 Jan 2008 01:17:57 -0400 (AST) Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.241]) by postgresql.org (Postfix) with ESMTP id A05182E311C for ; Sat, 12 Jan 2008 01:00:44 -0400 (AST) Received: by an-out-0708.google.com with SMTP id c36so314100ana.33 for ; Fri, 11 Jan 2008 21:00:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=vf60bz8Nuu0cA/hST46ARnoLRHzjwaZUlm8bfQ4K7DY=; b=OQSI6zdmvuWRx3IYWdZQdIF10KucldJaEYdPxrRpnhdfoxukSOGIyPMcxhmGT0fyaZcDcn6JA3/xuLgjYJrqD2FkwEAq/N72CIdXoPhtm+9XJ2/Z/wME2GwY0POIqOGvzZny4ZP/KDSg4dfLsEam93CmT47yFaktZda9FnITzXI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=nJfM30knoEvx+UF+OfjJPQ+V+s+cN7eq9m8N/UPqpwLy7VX+QBa7kKrj7hZzxCGAb52xDLYe0F6AK6DdSA3cSOPPn8fb8TgbNKoOsNYzHnV3HjmTvRFGA97eDP1oIb6/Dd1EfgZPBf+2kvG4S3EYyP8HUMzzE3P8kZLtWUIQJn0= Received: by 10.100.201.16 with SMTP id y16mr8526250anf.30.1200114043505; Fri, 11 Jan 2008 21:00:43 -0800 (PST) Received: by 10.100.44.2 with HTTP; Fri, 11 Jan 2008 21:00:43 -0800 (PST) Message-ID: Date: Sat, 12 Jan 2008 10:30:43 +0530 From: "Rajesh Kumar Mallah" To: "Tom Lane" Subject: Re: (possible) bug with constraint exclusion Cc: pgsql-sql@postgresql.org In-Reply-To: <23924.1200081368@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <23924.1200081368@sss.pgh.pa.us> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/100 X-Sequence-Number: 29953 On Jan 12, 2008 1:26 AM, Tom Lane wrote: > "Rajesh Kumar Mallah" writes: > > looks like constraint exclusion is being too aggressive in excluding null values > > Hmm, you're right. Looks like I broke it here: > http://archives.postgresql.org/pgsql-committers/2007-05/msg00187.php > > > although its well known that check constraints apply on not null values only. > > No, that is not a correct statement either --- it's exactly that type of > sloppy thinking that got me into trouble with this patch :-( > > The problem is that predicate_refuted_by_simple_clause() is failing to > distinguish whether "refutes" means "proves false" or "proves not true". > For constraint exclusion we have to use the stricter "proves false" > interpretation, and in that scenario a clause "foo IS NULL" fails to > refute a check constraint "foo > 0", because the latter will produce > NULL which isn't false and therefore doesn't cause the check constraint > to fail. > > The motivation for that patch was to support IS NULL as one partition > of a partitioned table. Thinking about it I see that if the other > partitions have check constraints like "foo > 0" then the partitioning > is actually incorrect, because the other check constraints are failing > to exclude NULLs. The right way to set up such a partitioned table is > to include "foo IS NOT NULL" as part of the check constraint, or as > a special-purpose NOT NULL flag, except in the IS NULL partition. > The current constraint exclusion logic fails to notice attnotnull, > though. So the correct fix seems to be: Dear Tom, Thanks for the elaborate explanation on your part, owing to my limitations I could not understand all the parts of it. Am I correct in understanding that the current behavior is inappropriate and shall be corrected at some point of time in future versions ? thanks once again to all the developers for making PostgreSQL. regds mallah. > > * Fix predicate_refuted_by_simple_clause to not suppose that a strict > operator is proved FALSE by an IS NULL clause. > > * Fix relation_excluded_by_constraints to add "foo IS NOT NULL" clauses > to the constraint list for attnotnull columns (perhaps this should be > pushed into get_relation_constraints?). This buys back the loss of > exclusion from the other change, so long as the partitioning is done > correctly. > > regards, tom lane >