Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZSMez-0002OO-Og for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Aug 2015 10:01:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZSMez-0000NM-BQ for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Aug 2015 10:01:25 +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 1ZSMdf-0006Nu-5p for pgsql-hackers@postgresql.org; Thu, 20 Aug 2015 10:00:03 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZSMdc-0006hM-9l for pgsql-hackers@postgresql.org; Thu, 20 Aug 2015 10:00:02 +0000 Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id t7K9xtk3016221; Thu, 20 Aug 2015 18:59:55 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id C9C595F623; Thu, 20 Aug 2015 18:59:55 +0900 (JST) Received: from imail3.m.ecl.ntt.co.jp (imail3.m.ecl.ntt.co.jp [129.60.5.248]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id BBDFA5F612; Thu, 20 Aug 2015 18:59:55 +0900 (JST) Received: from [127.0.0.1] ([129.60.241.61]) by imail3.m.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id t7K9xt0g022963; Thu, 20 Aug 2015 18:59:55 +0900 Subject: Re: Declarative partitioning To: David Fetter References: <55D3093C.5010800@lab.ntt.co.jp> <20150818134323.GC18054@fetter.org> <55D4309F.8030601@lab.ntt.co.jp> <20150819125239.GE11258@fetter.org> Cc: Pg Hackers From: Amit Langote Message-ID: <55D5A4C0.4040900@lab.ntt.co.jp> Date: Thu, 20 Aug 2015 18:58:24 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <20150819125239.GE11258@fetter.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Pg-Spam-Score: -3.2 (---) 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 On 2015-08-19 PM 09:52, David Fetter wrote: > On Wed, Aug 19, 2015 at 04:30:39PM +0900, Amit Langote wrote: >>> >>> One small change to make this part more efficient: >>> >>> 1. Take the access exclusive lock on table_name. >>> 2. Check for a matching constraint on it. >>> 3. If it's there, mark it as a valid partition. >>> 4. If not, check for values outside the boundaries as above. >>> >> >> That's an interesting idea. Thanks! > > I hope I'm advancing this feature rather than bogging it down... > Definitely advancing. >> By a matching constraint, I guess you mean a 'valid' constraint from >> which the declared partition constraint can be proven to follow. For >> (a simple) example, from a CHECK (a >= 100 AND a < 150) on >> table_name, the partition constraint implied by FOR VALUES START >> (100) END (200) can be assumed to hold. > > Well, I was assuming an exact match, but a stricter match seems like a > nice-to-have...possibly later. > >>> Should the be a *valid* constraint? Perhaps that should be >>> parameterized, as I'm not yet seeing a compelling argument either >>> direction. I'm picturing something like: >>> >>> ALTER TABLE table_name SET VALID PARTITION OF [TRUST] >>> >>> where TRUST would mean that an existing constraint need not be VALID. >> >> Hmm, I'd think this step must be able to assert the partition >> constraint beyond any doubt. If the DBA added the constraint and >> marked it invalid, she should first VALIDATE the constraint to make >> it valid by performing whatever steps necessary before. IOW, a full >> heap scan at least once is inevitable (the reason why we might want >> to make this a two step process at all). Am I missing something? > > There are use cases where we need to warn people that their assertions > need to be true, and if those assertions are not true, this will > explode, leaving them to pick the resulting shrapnel out of their > faces. There are other parts of the system where this is true, as > when people write UDFs in C. > > As I understand it, NOT VALID means, "I assert that the tuples already > here fit the constraint. Any changes will be checked against the > constraint." > > I've seen cases where a gigantic amount of data is coming out of some > distributed system which holds the constraint as an invariant. This > let a DBA decide to add a NOT VALID constraint in order not to take > the hit of a second full scan of the data, which might have made the > import, and possibly the entire project, untenable. > > See above. > Ah, I understand the point of parameterization (TRUST). Seems like it would be good to have with appropriate documentation of the same. Perhaps, it might as well a parameter to the step 1 itself. >>>> 5. Detach partition >>>> >>>> ALTER TABLE partitioned_table >>>> DETACH PARTITION partition_name [USING table_name] >>>> >>>> This removes partition_name as partition of partitioned_table. >>>> The table continues to exist with the same name or 'table_name', >>>> if specified. pg_class.relispartition is set to false for the >>>> table, so it behaves like a normal table. >>> >>> Could this take anything short of an access exclusive lock on the >>> parent? >> >> Yes, both the step 1 of ATTACH command and DETACH command take >> access exclusive lock on the parent. They are rather quick metadata >> changes, so should not stall others significantly, I think. > > So no. Weakening required locks has been something of an ongoing > project, project-wide, and need not be part of the first cut of this > long-needed feature. > Do you mean ATTACH and DETACH, if they require access exclusive lock on the parent, should not be in the first cut? Or am I misreading? If so, there is no way to drop partitions. With the patch, it would be achieved with detach and drop (if required). > Thanks so much for working on this! > Thanks for the feedback and suggestions! Regards, Amit -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers