Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W5TpN-0001BU-MD for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Jan 2014 05:24:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W5TpN-0006KO-6T for pgsql-hackers@arkaria.postgresql.org; Tue, 21 Jan 2014 05:24:45 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W5TpL-0006K8-Pr for pgsql-hackers@postgresql.org; Tue, 21 Jan 2014 05:24:43 +0000 Received: from tyo201.gate.nec.co.jp ([202.32.8.193]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W5TpI-0006rr-12 for pgsql-hackers@postgresql.org; Tue, 21 Jan 2014 05:24:43 +0000 Received: from mailgate3.nec.co.jp ([10.7.69.192]) by tyo201.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id s0L5OZRl008153; Tue, 21 Jan 2014 14:24:35 +0900 (JST) Received: from mailsv4.nec.co.jp (imss61.nec.co.jp [10.7.69.156]) by mailgate3.nec.co.jp (8.11.7/3.7W-MAILGATE-NEC) with ESMTP id s0L5OZh12497; Tue, 21 Jan 2014 14:24:35 +0900 (JST) Received: from mail02.kamome.nec.co.jp (mail02.kamome.nec.co.jp [10.25.43.5]) by mailsv4.nec.co.jp (8.13.8/8.13.4) with ESMTP id s0L5OZJx018805; Tue, 21 Jan 2014 14:24:35 +0900 (JST) Received: from chojiro.jp.nec.com ([10.26.220.28] [10.26.220.28]) by mail01b.kamome.nec.co.jp with ESMTP id BT-MMP-124909; Tue, 21 Jan 2014 14:24:09 +0900 Received: from [10.164.24.200] ([10.164.24.200] [10.164.24.200]) by mail.jp.nec.com with ESMTPA id BT-MMP-17179; Tue, 21 Jan 2014 14:24:09 +0900 Message-ID: <52DE047A.8020200@ak.jp.nec.com> Date: Tue, 21 Jan 2014 14:24:10 +0900 From: KaiGai Kohei User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 MIME-Version: 1.0 To: Shigeru Hanada CC: Tom Lane , Robert Haas , PostgreSQL-development Subject: Re: inherit support for foreign tables References: <12432.1384406906@sss.pgh.pa.us> <10163.1384786524@sss.pgh.pa.us> <52DDD071.9090405@ak.jp.nec.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -4.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 (2014/01/21 11:44), Shigeru Hanada wrote: > Thanks for the comments. > > 2014/1/21 KaiGai Kohei : >>> In addition, an idea which I can't throw away is to assume that all >>> constraints defined on foreign tables as ASSERTIVE. Foreign tables >>> potentially have dangers to have "wrong" data by updating source data >>> not through foreign tables. This is not specific to an FDW, so IMO >>> constraints defined on foreign tables are basically ASSERTIVE. Of >>> course PG can try to maintain data correct, but always somebody might >>> break it. >>> qu >>> >> Does it make sense to apply "assertive" CHECK constraint on the qual >> of ForeignScan to filter out tuples with violated values at the local >> side, as if row-level security feature doing. >> It enables to handle a situation that planner expects only "clean" >> tuples are returned but FDW driver is unavailable to anomalies. >> >> Probably, this additional check can be turned on/off on the fly, >> if FDW driver has a way to inform the core system its capability, >> like FDW_CAN_ENFORCE_CHECK_CONSTRAINT that informs planner to skip >> local checks. > > Hmm, IIUC you mean that local users can't (or don't need to) know that > data which violates the local constraints exist on remote side. > Applying constraints to the data which is modified through FDW would > be necessary as well. In that design, FDW is a bidirectional filter > which provides these features: > > 1) Don't push wrong data into remote data source, by applying local > constraints to the result of the modifying query executed on local PG. > This is not perfect filter, because remote constraints don't mapped > automatically or perfectly (imagine constraints which is available on > remote but is not supported in PG). > 2) Don't retrieve wrong data from remote to local PG, by applying > local constraints > Yes. (1) can be done with ExecConstraints prior to FDW callback on UPDATE or INSERT, even not a perfect solution because of side-channel on the remote data source. For (2), my proposition tries to drop retrieved violated tuples, however, the result is same. > I have a concern about consistency. It has not been supported, but > let's think of Aggregate push-down invoked by a query below. > > SELECT count(*) FROM remote_table; > > If this query was fully pushed down, the result is the # of records > exist on remote side, but the result would be # of valid records when > we don't push down the aggregate. This would confuse users. > Hmm. In this case, FDW driver needs to be responsible to push-down the additional check quals into remote side, so it does not work transparently towards the ForeignScan. It might be a little bit complicated suggestion for the beginning of the efforts. >>> Besides CHECK constraints, currently NOT NULL constraints are >>> virtually ASSERTIVE (not enforcing). Should it also be noted >>> explicitly? >>> >> Backward compatibility…. > > Yep, backward compatibility (especially visible ones to users) should > be minimal, ideally zero. > >> NOT NULL [ASSERTIVE] might be an option. > > Treating [ASSERTIVE | NOT ASSERTIVE] like DEFERRABLE, and allow > ingASSERTIVE for only foreign tables? It makes sense, though we need > consider exclusiveness . But It needs to default to ASSERTIVE on > foreign tables, and NOT ASSERTIVE (means "forced") on others. Isn't > is too complicated? > I think it is not easy to implement assertive checks, except for foreign tables, because all the write stuff to regular tables are managed by PostgreSQL itself. So, it is a good first step to add support "ASSERTIVE" CHECK on foreign table only, and to enforce FDW drivers nothing special from my personal sense. How about committer's opinion? Thanks, -- OSS Promotion Center / The PG-Strom Project KaiGai Kohei -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers