From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at> |
Cc: | "Rushabh Lathia *EXTERN*" <rushabh(dot)lathia(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Rushabh Lathia <rushabh(dot)lathia(at)enterprisedb(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> |
Subject: | Re: NOT Null constraint on foreign table not working |
Date: | 2014-01-21 19:06:31 |
Message-ID: | 32365.1390331191@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at> writes:
> I believe that a column of a foreign table should be NOT NULL only if
> it is guaranteed that it cannot contain NULL values. Doesn't the planner
> rely on that?
The planner does expect that constraints tell the truth. I don't remember
how significant a false NOT NULL constraint might be, but certainly false
CHECK constraints can give rise to incorrect plans.
> But PostgreSQL cannot guarantee that, that has to happen on the remote side
> (or in the FDW). I think that it is best that an error for a constraint
> violation is thrown by the same entity that guarantees that the constraint
> is respected.
A point worth making here is that it's already implicit in the contract
that the CREATE FOREIGN TABLE command accurately represents what the
far-side table is. If you get the column datatypes wrong, for example,
it's possible to have subtle semantic bugs not all that different from
what will happen with an incorrectly-deduced plan. And we don't make
any attempt to slap your wrist for that. So I don't see that there's
anything fundamentally wrong with the position that any NOT NULL or CHECK
constraints attached to a foreign table must be accurate reflections of
constraints that exist on the far side, rather than something we should
enforce locally. (Note that this argument applies to FDWs for remote SQL
servers, but not necessarily for FDWs for non-SQL data sources, where
conceivably the CREATE FOREIGN TABLE command actually is itself the
authoritative truth. Such an FDW would then be responsible for enforcing
constraints.)
I agree though that we've failed miserably to explain this in the docs.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2014-01-21 19:09:39 | Re: inherit support for foreign tables |
Previous Message | Steve Crawford | 2014-01-21 18:59:41 | Documentation patch for to_date and to_timestamp |