Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aZCbT-0002V9-Tl for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Feb 2016 07:14:20 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aZCbT-0006e9-D9 for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Feb 2016 07:14:19 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aZCbS-0006dU-2B for pgsql-hackers@postgresql.org; Fri, 26 Feb 2016 07:14:18 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aZCbP-0003g6-AP for pgsql-hackers@postgresql.org; Fri, 26 Feb 2016 07:14:16 +0000 Received: from vc2.ecl.ntt.co.jp (vc2.ecl.ntt.co.jp [129.60.86.154]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id u1Q7ECse011745; Fri, 26 Feb 2016 16:14:12 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id A8F4F5F594; Fri, 26 Feb 2016 16:14:12 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 924BD5F592; Fri, 26 Feb 2016 16:14:12 +0900 (JST) Received: from [127.0.0.1] (unknown [129.60.241.61]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTP id 8333C400B91; Fri, 26 Feb 2016 16:14:12 +0900 (JST) Subject: Re: Declarative partitioning References: <6fecdc5455863ad2585e3922fdd314e5@mail.gmail.com> From: Amit Langote Message-ID: <56CFFB39.5000609@lab.ntt.co.jp> Date: Fri, 26 Feb 2016 16:14:01 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <6fecdc5455863ad2585e3922fdd314e5@mail.gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit To: jppelletier@e-djuster.com, pgsql-hackers@postgresql.org X-TM-AS-MML: disable X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Hi, Thanks for your feedback. On 2016/02/26 0:43, Jean-Pierre Pelletier wrote: > Why not based it on "Exclusion Constraint" ? > > Most discussions as of late seems to focus on Range overlaps which appeal > (I would think) is that it supports both "equality" and "overlaps", two > popular partitioning schemes. > > "Equality" as in "value1 = value2" can be implemented with "range > overlaps" > as "range(value1,value) = range(value,value2)". > > I would think that Partitioning schemes can be Declarative, Efficient and > not restricted to Equality and Overlaps as long as all partitions (of a > partitioned table) are using a single partitioning definition expressed > as: > - An Immutable Expression on tuple columns, in the simplest case a single > column > - An Operator, in the simplest case, "equality" > > That seems very close to the semantic of "Constraint Exclusion" as > described here: > http://thoughts.davisjeff.com/2010/09/25/exclusion-constraints-are-general > ized-sql-unique/ > > If partitioning could be based on EC, it would bring these additional > benefits: > - The choice of operator as long as it is boolean. commutative and > Indexable > - The use of Expression/Function and not just bare columns Note that proposed patch does more or less what you say we should be doing minus the "exclusion constraint" part. With the proposed, you can specify an expression(s)/column(s) as partition key along with an "operator class" for the column like below: CREATE TABLE foo (a type_name) PARTITION BY LIST (a USING opclass_name); CREATE TABLE bar (a type_name) PARTITION BY RANGE (a USING opclass_name); Right now, supported partition strategies are RANGE and LIST where "btree operators" suffice. So in the above example, type_name must have a suitable btree operators class defined in the system which could be opclass_name. If opclass_name was created as the default for type_name, one need not write USING opclass_name. Then when you create a partition of foo: CREATE TABLE foo_partition PARTITION OF foo FOR VALUES IN (val1, val2); system enforces that foo_partition only contains values such that: a = ANY ( ARRAY [val1, val2] ), where the operator "=" refers to an operator belonging to the operator class opclass_name (hence can have a user-defined notion of "equality"). And when you create a partition of bar: CREATE TABLE bar_partition PARTITION OF bar FOR VALUES [val1, val2); system enforces that bar_partition only contains values such that: val1 <= a < val2, where operators "<=" and "<" refer to the operators belonging to the operator class opclass_name (hence can have a user-defined notion of ordering). Further, system can also optimize queries based on its knowledge of operators appearing in query clauses and implicit constraints just mentioned above. Specifically, it can can exclude partitions using "constraint exclusion" which is NOT the same thing as "exclusion constraints", as you might be aware. "Exclusion constraints" depend on having suitable a index (just like unique constraint enforcing btree index) that uses the specified operator to enforce the constraint: postgres=# CREATE TABLE circles ( postgres(# c circle, postgres(# EXCLUDE USING gist (c WITH &&) postgres(# ); CREATE TABLE postgres=# \d+ circles Table "public.circles" Column | Type | Modifiers | Storage | Stats target | Description -------+--------+-----------+---------+--------------+------------- c | circle | | plain | | Indexes: "circles_c_excl" EXCLUDE USING gist (c WITH &&) The talk of "non-overlapping partitions" in this thread refers to the invariant that partition DDL should maintain which uses ad-hoc logic to do that but which is based on the semantics of the specified operators. Thanks, Amit -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers