Noah Misch <noah@leadboat.com> writes:
> On Sun, Sep 07, 2014 at 01:06:04PM -0400, Tom Lane wrote:
>> This objection could be met by doing a precheck to verify that the table
>> contains at least one live row. That's pretty ugly and personally I'm not
>> sure it's necessary, but I think there's room to argue that it is.
> Yes; I doubt one could justify failing on an empty table as though it had been
> a one-row table. I see a couple ways we could avoid the I/O and complexity:
> 1) If contain_leaky_functions() approves every constraint expression, test the
> constraints once, and we're done. Otherwise, proceed as we do today.
> 2) Test the constraints in a subtransaction. If the subtransaction commits,
> we're done. Otherwise, proceed as we do today.
I'm not sure either of those is better than doing a single heap_getnext(),
which really should be pretty cheap except under pathological conditions.
It's the messiness I'm worried about more than the cost.
regards, tom lane