Re: COPY FREEZE has no warning

Lists: pgsql-hackers
From: Bruce Momjian <bruce(at)momjian(dot)us>
To: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: COPY FREEZE has no warning
Date: 2013-01-23 19:02:46
Message-ID: 20130123190246.GC23670@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

As a reminder, COPY FREEZE still does not issue any warning/notice if
the freezing does not happen:

Requests copying the data with rows already frozen, just as they
would be after running the <command>VACUUM FREEZE</> command.
This is intended as a performance option for initial data loading.
Rows will be frozen only if the table being loaded has been created
in the current subtransaction, there are no cursors open and there
are no older snapshots held by this transaction. If those conditions
are not met the command will continue without error though will not
freeze rows. It is also possible in rare cases that the request
cannot be honoured for internal reasons, hence <literal>FREEZE</literal>
is more of a guideline than a hard rule.

Note that all other sessions will immediately be able to see the data
once it has been successfully loaded. This violates the normal rules
of MVCC visibility and by specifying this option the user acknowledges
explicitly that this is understood.

Didn't we want to issue the user some kind of feedback?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-23 20:04:40
Message-ID: CA+TgmobSWqv1HAjr81-QjnC78LWxauFnfT346q4ErntU=b2-GQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Jan 23, 2013 at 2:02 PM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
> As a reminder, COPY FREEZE still does not issue any warning/notice if
> the freezing does not happen:
>
> Requests copying the data with rows already frozen, just as they
> would be after running the <command>VACUUM FREEZE</> command.
> This is intended as a performance option for initial data loading.
> Rows will be frozen only if the table being loaded has been created
> in the current subtransaction, there are no cursors open and there
> are no older snapshots held by this transaction. If those conditions
> are not met the command will continue without error though will not
> freeze rows. It is also possible in rare cases that the request
> cannot be honoured for internal reasons, hence <literal>FREEZE</literal>
> is more of a guideline than a hard rule.
>
> Note that all other sessions will immediately be able to see the data
> once it has been successfully loaded. This violates the normal rules
> of MVCC visibility and by specifying this option the user acknowledges
> explicitly that this is understood.
>
> Didn't we want to issue the user some kind of feedback?

I believe that is what was agreed.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-24 22:09:51
Message-ID: 20130124220951.GD21914@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Jan 23, 2013 at 02:02:46PM -0500, Bruce Momjian wrote:
> As a reminder, COPY FREEZE still does not issue any warning/notice if
> the freezing does not happen:
>
> Requests copying the data with rows already frozen, just as they
> would be after running the <command>VACUUM FREEZE</> command.
> This is intended as a performance option for initial data loading.
> Rows will be frozen only if the table being loaded has been created
> in the current subtransaction, there are no cursors open and there
> are no older snapshots held by this transaction. If those conditions
> are not met the command will continue without error though will not
> freeze rows. It is also possible in rare cases that the request
> cannot be honoured for internal reasons, hence <literal>FREEZE</literal>
> is more of a guideline than a hard rule.
>
> Note that all other sessions will immediately be able to see the data
> once it has been successfully loaded. This violates the normal rules
> of MVCC visibility and by specifying this option the user acknowledges
> explicitly that this is understood.
>
> Didn't we want to issue the user some kind of feedback?

As no one wanted to write this patch, I have developed the attached
version.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachment Content-Type Size
freeze.diff text/x-diff 2.0 KB

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-24 22:30:22
Message-ID: 5101B5FE.4080900@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 1/24/13 5:09 PM, Bruce Momjian wrote:
> On Wed, Jan 23, 2013 at 02:02:46PM -0500, Bruce Momjian wrote:
>> As a reminder, COPY FREEZE still does not issue any warning/notice if
>> the freezing does not happen:

> As no one wanted to write this patch, I have developed the attached
> version.

I think it would be useful to add why it was unable to honor the option.
Otherwise this might just end up spamming the logs without any chance
for improvement.


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-24 23:15:33
Message-ID: 20130124231533.GH21914@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jan 24, 2013 at 05:30:22PM -0500, Peter Eisentraut wrote:
> On 1/24/13 5:09 PM, Bruce Momjian wrote:
> > On Wed, Jan 23, 2013 at 02:02:46PM -0500, Bruce Momjian wrote:
> >> As a reminder, COPY FREEZE still does not issue any warning/notice if
> >> the freezing does not happen:
>
> > As no one wanted to write this patch, I have developed the attached
> > version.
>
> I think it would be useful to add why it was unable to honor the option.
> Otherwise this might just end up spamming the logs without any chance
> for improvement.

Well, I would need to repeat what is already in the COPY docs. Do you
have any suggested text?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-24 23:55:17
Message-ID: 28697.1359071717@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
>> Didn't we want to issue the user some kind of feedback?

> As no one wanted to write this patch, I have developed the attached
> version.

Please note the comment directly above where you patched.

The proposed message doesn't seem to me to be following the message
style guide, either.

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-25 01:17:55
Message-ID: 20130125011755.GM21914@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jan 24, 2013 at 06:55:17PM -0500, Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> >> Didn't we want to issue the user some kind of feedback?
>
> > As no one wanted to write this patch, I have developed the attached
> > version.
>
> Please note the comment directly above where you patched.
>
> The proposed message doesn't seem to me to be following the message
> style guide, either.

OK, updated patch attached.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachment Content-Type Size
freeze.diff text/x-diff 2.2 KB

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-25 01:48:37
Message-ID: 20130125014836.GA23136@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2013-01-23 14:02:46 -0500, Bruce Momjian wrote:
> As a reminder, COPY FREEZE still does not issue any warning/notice if
> the freezing does not happen:

FWIW, and I won't annoy anyone further after this email, now that its
deterministic, I still think that this should be an ERROR not a WARNING.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-25 15:03:34
Message-ID: 20130125150334.GV21914@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jan 25, 2013 at 02:48:37AM +0100, Andres Freund wrote:
> On 2013-01-23 14:02:46 -0500, Bruce Momjian wrote:
> > As a reminder, COPY FREEZE still does not issue any warning/notice if
> > the freezing does not happen:
>
> FWIW, and I won't annoy anyone further after this email, now that its
> deterministic, I still think that this should be an ERROR not a WARNING.

As the FREEZE is just an optimization, I thought NOTICE, vs WARNING or
ERROR was fine. If others want this changed, please reply.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-25 15:30:40
Message-ID: 20130125153040.GQ16126@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Bruce Momjian (bruce(at)momjian(dot)us) wrote:
> On Fri, Jan 25, 2013 at 02:48:37AM +0100, Andres Freund wrote:
> > On 2013-01-23 14:02:46 -0500, Bruce Momjian wrote:
> > > As a reminder, COPY FREEZE still does not issue any warning/notice if
> > > the freezing does not happen:
> >
> > FWIW, and I won't annoy anyone further after this email, now that its
> > deterministic, I still think that this should be an ERROR not a WARNING.
>
> As the FREEZE is just an optimization, I thought NOTICE, vs WARNING or
> ERROR was fine. If others want this changed, please reply.

tbh, I tend to agree w/ Andres on this one. COPY FREEZE means "do
this", not "if you can get away with it, then do it". That said, I can
really see a use-case for both which would imply that we'd have a way to
specify, ala DROP TABLE and IF EXISTS. Not sure exactly what that'd
look like though and having one or the other is better than nothing
(presuming everyone is fine with the visibility impacts of this, which I
still contend will cause our users to give us grief over in the
future..).

Thanks,

Stephen


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-25 15:51:39
Message-ID: 20130125155139.GZ21914@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jan 25, 2013 at 10:30:40AM -0500, Stephen Frost wrote:
> * Bruce Momjian (bruce(at)momjian(dot)us) wrote:
> > On Fri, Jan 25, 2013 at 02:48:37AM +0100, Andres Freund wrote:
> > > On 2013-01-23 14:02:46 -0500, Bruce Momjian wrote:
> > > > As a reminder, COPY FREEZE still does not issue any warning/notice if
> > > > the freezing does not happen:
> > >
> > > FWIW, and I won't annoy anyone further after this email, now that its
> > > deterministic, I still think that this should be an ERROR not a WARNING.
> >
> > As the FREEZE is just an optimization, I thought NOTICE, vs WARNING or
> > ERROR was fine. If others want this changed, please reply.
>
> tbh, I tend to agree w/ Andres on this one. COPY FREEZE means "do
> this", not "if you can get away with it, then do it". That said, I can
> really see a use-case for both which would imply that we'd have a way to
> specify, ala DROP TABLE and IF EXISTS. Not sure exactly what that'd
> look like though and having one or the other is better than nothing
> (presuming everyone is fine with the visibility impacts of this, which I
> still contend will cause our users to give us grief over in the
> future..).

Interesting. I can see the visibility as making this more than an
optimization, because it has external visibility. However, the
visibility problem is when it is silent (no NOTICE). Do we need
a message that says we did honor FREEZE?

We could get fancy and make FREEZE more than a boolean, e.g. OFF,
PREFER, FORCE.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-25 16:59:21
Message-ID: 13712.1359133161@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> On Fri, Jan 25, 2013 at 02:48:37AM +0100, Andres Freund wrote:
>> FWIW, and I won't annoy anyone further after this email, now that its
>> deterministic, I still think that this should be an ERROR not a WARNING.

> As the FREEZE is just an optimization, I thought NOTICE, vs WARNING or
> ERROR was fine. If others want this changed, please reply.

The previous argument about it was "if you bothered to specify FREEZE,
you probably really want/need that behavior". So I can definitely see
Andres' point. Perhaps WARNING would be a suitable compromise?

regards, tom lane


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-25 17:42:49
Message-ID: CA+TgmobkAWUkuxXppS11hVVuixV7eRAR5JUCCfjN=LY9RxV89Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jan 25, 2013 at 11:59 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
>> On Fri, Jan 25, 2013 at 02:48:37AM +0100, Andres Freund wrote:
>>> FWIW, and I won't annoy anyone further after this email, now that its
>>> deterministic, I still think that this should be an ERROR not a WARNING.
>
>> As the FREEZE is just an optimization, I thought NOTICE, vs WARNING or
>> ERROR was fine. If others want this changed, please reply.
>
> The previous argument about it was "if you bothered to specify FREEZE,
> you probably really want/need that behavior". So I can definitely see
> Andres' point. Perhaps WARNING would be a suitable compromise?

I'll vote for ERROR. I don't see why this sound be a best-effort thing.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-25 18:06:05
Message-ID: 20130125180605.GR16126@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Fri, Jan 25, 2013 at 11:59 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > Bruce Momjian <bruce(at)momjian(dot)us> writes:
> >> On Fri, Jan 25, 2013 at 02:48:37AM +0100, Andres Freund wrote:
> >>> FWIW, and I won't annoy anyone further after this email, now that its
> >>> deterministic, I still think that this should be an ERROR not a WARNING.
> >
> >> As the FREEZE is just an optimization, I thought NOTICE, vs WARNING or
> >> ERROR was fine. If others want this changed, please reply.
> >
> > The previous argument about it was "if you bothered to specify FREEZE,
> > you probably really want/need that behavior". So I can definitely see
> > Andres' point. Perhaps WARNING would be a suitable compromise?
>
> I'll vote for ERROR. I don't see why this sound be a best-effort thing.

Yeah, I tend to agree. In part, I think having it error when the
conditions aren't met would actually reduce the chances of having this
'feature' end up as the default in some ORM somewhere...

Thanks,

Stephen


From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-25 19:55:12
Message-ID: CAMkU=1xVxjuhORdLxOn35WhVZS+JTdAw5arO2JXyhtAawM_MMw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jan 25, 2013 at 9:42 AM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> On Fri, Jan 25, 2013 at 11:59 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Bruce Momjian <bruce(at)momjian(dot)us> writes:
>>> On Fri, Jan 25, 2013 at 02:48:37AM +0100, Andres Freund wrote:
>>>> FWIW, and I won't annoy anyone further after this email, now that its
>>>> deterministic, I still think that this should be an ERROR not a WARNING.
>>
>>> As the FREEZE is just an optimization, I thought NOTICE, vs WARNING or
>>> ERROR was fine. If others want this changed, please reply.
>>
>> The previous argument about it was "if you bothered to specify FREEZE,
>> you probably really want/need that behavior". So I can definitely see
>> Andres' point. Perhaps WARNING would be a suitable compromise?
>
> I'll vote for ERROR. I don't see why this sound be a best-effort thing.
>

+1. If I had no objection to my database getting stuffed to the gills
with unfrozen tuples, I wouldn't have invoked the feature in the first
place.

As far as can tell, this ERROR/WARNING must occur immediately, because
once the first tuple is inserted frozen it is too late to change ones
mind. So the problem can be immediately fixed and retried.

Except, is there perhaps some way for the user to decide to promote
WARNINGs to ERRORs on for a given command/transaction?

Cheers,

Jeff


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-25 20:16:45
Message-ID: 20130125201645.GM6848@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jan 25, 2013 at 11:55:12AM -0800, Jeff Janes wrote:
> On Fri, Jan 25, 2013 at 9:42 AM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> > On Fri, Jan 25, 2013 at 11:59 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> >> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> >>> On Fri, Jan 25, 2013 at 02:48:37AM +0100, Andres Freund wrote:
> >>>> FWIW, and I won't annoy anyone further after this email, now that its
> >>>> deterministic, I still think that this should be an ERROR not a WARNING.
> >>
> >>> As the FREEZE is just an optimization, I thought NOTICE, vs WARNING or
> >>> ERROR was fine. If others want this changed, please reply.
> >>
> >> The previous argument about it was "if you bothered to specify FREEZE,
> >> you probably really want/need that behavior". So I can definitely see
> >> Andres' point. Perhaps WARNING would be a suitable compromise?
> >
> > I'll vote for ERROR. I don't see why this sound be a best-effort thing.
> >
>
> +1. If I had no objection to my database getting stuffed to the gills
> with unfrozen tuples, I wouldn't have invoked the feature in the first
> place.
>
> As far as can tell, this ERROR/WARNING must occur immediately, because
> once the first tuple is inserted frozen it is too late to change ones
> mind. So the problem can be immediately fixed and retried.
>
> Except, is there perhaps some way for the user to decide to promote
> WARNINGs to ERRORs on for a given command/transaction?

OK, updated patch attached that throws an error with a more specific
message.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachment Content-Type Size
freeze.diff text/x-diff 3.1 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-25 22:30:58
Message-ID: 24089.1359153058@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> OK, updated patch attached that throws an error with a more specific
> message.

> *
> * As noted above rd_newRelfilenodeSubid is not set in all cases
> * where we can apply the optimization, so in those rare cases
> ! * where we cannot honor the request.
> */

This sentence not complete. I kind of think the entire para visible
above could be removed, anyway.

> ! ereport(ERROR, (errmsg("cannot perform FREEZE operation due to invalid table or transaction state")));

I don't find this terribly specific. It would at least be useful to
have two messages distinguishing whether the cause was invalid table
state (rd_createSubid and rd_newRelfilenodeSubid not set) or invalid
transaction state (the snapshot and portal tests). The former might
usefully be phrased as "because the table was not created or truncated
in the current transaction" and the latter as "because other actions are
in progress within the current transaction".

I'd also suggest "cannot perform COPY FREEZE because <whatever>" rather
than using the unnecessarily vague "operation".

Also, this is missing an errcode, which means it will report itself as
an internal error, which it ain't. It's also randomly unlike the
standard layout for ereport calls.
ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE would do for the table case,
not sure about the other.

regards, tom lane


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <bruce(at)momjian(dot)us>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-26 00:45:30
Message-ID: CAB7nPqSzHtpR_epYuDpi3TK8nKh87dSyurBz7WJSDkNDNCzg3w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Jan 26, 2013 at 2:42 AM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:

> On Fri, Jan 25, 2013 at 11:59 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > Bruce Momjian <bruce(at)momjian(dot)us> writes:
> >> On Fri, Jan 25, 2013 at 02:48:37AM +0100, Andres Freund wrote:
> >>> FWIW, and I won't annoy anyone further after this email, now that its
> >>> deterministic, I still think that this should be an ERROR not a
> WARNING.
> >
> >> As the FREEZE is just an optimization, I thought NOTICE, vs WARNING or
> >> ERROR was fine. If others want this changed, please reply.
> >
> > The previous argument about it was "if you bothered to specify FREEZE,
> > you probably really want/need that behavior". So I can definitely see
> > Andres' point. Perhaps WARNING would be a suitable compromise?
>
> I'll vote for ERROR. I don't see why this sound be a best-effort thing.
>
+ 1. I was surprised to see COPY FREEZE failing silently when testing the
feature. An ERROR would be suited.
--
Michael Paquier
http://michael.otacoo.com


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-26 03:59:28
Message-ID: 20130126035928.GA9274@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jan 25, 2013 at 05:30:58PM -0500, Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > OK, updated patch attached that throws an error with a more specific
> > message.
>
>
> > *
> > * As noted above rd_newRelfilenodeSubid is not set in all cases
> > * where we can apply the optimization, so in those rare cases
> > ! * where we cannot honor the request.
> > */
>
> This sentence not complete. I kind of think the entire para visible
> above could be removed, anyway.
>
> > ! ereport(ERROR, (errmsg("cannot perform FREEZE operation due to invalid table or transaction state")));
>
> I don't find this terribly specific. It would at least be useful to
> have two messages distinguishing whether the cause was invalid table
> state (rd_createSubid and rd_newRelfilenodeSubid not set) or invalid
> transaction state (the snapshot and portal tests). The former might
> usefully be phrased as "because the table was not created or truncated
> in the current transaction" and the latter as "because other actions are
> in progress within the current transaction".
>
> I'd also suggest "cannot perform COPY FREEZE because <whatever>" rather
> than using the unnecessarily vague "operation".
>
> Also, this is missing an errcode, which means it will report itself as
> an internal error, which it ain't. It's also randomly unlike the
> standard layout for ereport calls.
> ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE would do for the table case,
> not sure about the other.

OK, that was tricky, but completed with the attached patch.
Surprisingly, truncation wasn't mention in our docs, though it was used
in the regression tests. I have fixed that.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachment Content-Type Size
freeze2.diff text/x-diff 6.7 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-26 04:08:56
Message-ID: 4883.1359173336@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> ! ereport(ERROR,
> ! (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE,
> ! errmsg("cannot perform FREEZE because of previous table activity in the current transaction")));

[ itch... ] What is "table activity"? I always thought of tables as
being rather passive objects. And anyway, isn't this backwards? What
we're complaining of is *lack* of activity. I don't see why this isn't
using the same message as the other code path, namely

> + ereport(ERROR,
> + (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE,
> + errmsg("cannot perform FREEZE because the table was not created or truncated in the current transaction")));

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-26 04:28:58
Message-ID: 20130126042858.GB9274@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jan 25, 2013 at 11:08:56PM -0500, Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > ! ereport(ERROR,
> > ! (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE,
> > ! errmsg("cannot perform FREEZE because of previous table activity in the current transaction")));
>
> [ itch... ] What is "table activity"? I always thought of tables as
> being rather passive objects. And anyway, isn't this backwards? What
> we're complaining of is *lack* of activity. I don't see why this isn't
> using the same message as the other code path, namely

Well, here is an example of this message:

BEGIN;
TRUNCATE vistest;
SAVEPOINT s1;
COPY vistest FROM stdin CSV FREEZE;
ERROR: cannot perform FREEZE because of previous table activity in the current transaction
COMMIT;

Clearly it was truncated in the same transaction, but the savepoint
somehow invalidates the freeze. There is a C comment about it:

* BEGIN;
* TRUNCATE t;
* SAVEPOINT save;
* TRUNCATE t;
* ROLLBACK TO save;
* COPY ...

I changed it to:

ERROR: cannot perform FREEZE because of transaction activity after table creation or truncation

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachment Content-Type Size
freeze3.diff text/x-diff 6.7 KB

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-26 18:34:07
Message-ID: 20130126183407.GD9274@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jan 25, 2013 at 11:28:58PM -0500, Bruce Momjian wrote:
> On Fri, Jan 25, 2013 at 11:08:56PM -0500, Tom Lane wrote:
> > Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > > ! ereport(ERROR,
> > > ! (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE,
> > > ! errmsg("cannot perform FREEZE because of previous table activity in the current transaction")));
> >
> > [ itch... ] What is "table activity"? I always thought of tables as
> > being rather passive objects. And anyway, isn't this backwards? What
> > we're complaining of is *lack* of activity. I don't see why this isn't
> > using the same message as the other code path, namely
>
> Well, here is an example of this message:
>
> BEGIN;
> TRUNCATE vistest;
> SAVEPOINT s1;
> COPY vistest FROM stdin CSV FREEZE;
> ERROR: cannot perform FREEZE because of previous table activity in the current transaction
> COMMIT;
>
> Clearly it was truncated in the same transaction, but the savepoint
> somehow invalidates the freeze. There is a C comment about it:
>
> * BEGIN;
> * TRUNCATE t;
> * SAVEPOINT save;
> * TRUNCATE t;
> * ROLLBACK TO save;
> * COPY ...
>
> I changed it to:
>
> ERROR: cannot perform FREEZE because of transaction activity after table creation or truncation

Patch applied.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Noah Misch <noah(at)leadboat(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-01-30 01:34:24
Message-ID: 20130130013424.GC3524@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jan 25, 2013 at 11:28:58PM -0500, Bruce Momjian wrote:
> On Fri, Jan 25, 2013 at 11:08:56PM -0500, Tom Lane wrote:
> > Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > > ! ereport(ERROR,
> > > ! (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE,
> > > ! errmsg("cannot perform FREEZE because of previous table activity in the current transaction")));
> >
> > [ itch... ] What is "table activity"? I always thought of tables as
> > being rather passive objects. And anyway, isn't this backwards? What
> > we're complaining of is *lack* of activity. I don't see why this isn't
> > using the same message as the other code path, namely
>
> Well, here is an example of this message:
>
> BEGIN;
> TRUNCATE vistest;
> SAVEPOINT s1;
> COPY vistest FROM stdin CSV FREEZE;
> ERROR: cannot perform FREEZE because of previous table activity in the current transaction
> COMMIT;
>
> Clearly it was truncated in the same transaction, but the savepoint
> somehow invalidates the freeze. There is a C comment about it:

The savepoint prevents the COPY FREEZE, because COPY FREEZE needs the table to
have been created or truncated in the current *sub*transaction. Issuing
"RELEASE s1" before the COPY makes it work again, for example.

>
> * BEGIN;
> * TRUNCATE t;
> * SAVEPOINT save;
> * TRUNCATE t;
> * ROLLBACK TO save;
> * COPY ...

This is different. The table was truncated in the current subtransaction, and
it's safe in principle to apply the optimization. Due to an implementation
artifact, we'll reject it anyway.


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-02-01 17:57:18
Message-ID: 20130201175718.GC2371@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jan 29, 2013 at 08:34:24PM -0500, Noah Misch wrote:
> On Fri, Jan 25, 2013 at 11:28:58PM -0500, Bruce Momjian wrote:
> > On Fri, Jan 25, 2013 at 11:08:56PM -0500, Tom Lane wrote:
> > > Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > > > ! ereport(ERROR,
> > > > ! (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE,
> > > > ! errmsg("cannot perform FREEZE because of previous table activity in the current transaction")));
> > >
> > > [ itch... ] What is "table activity"? I always thought of tables as
> > > being rather passive objects. And anyway, isn't this backwards? What
> > > we're complaining of is *lack* of activity. I don't see why this isn't
> > > using the same message as the other code path, namely
> >
> > Well, here is an example of this message:
> >
> > BEGIN;
> > TRUNCATE vistest;
> > SAVEPOINT s1;
> > COPY vistest FROM stdin CSV FREEZE;
> > ERROR: cannot perform FREEZE because of previous table activity in the current transaction
> > COMMIT;
> >
> > Clearly it was truncated in the same transaction, but the savepoint
> > somehow invalidates the freeze. There is a C comment about it:
>
> The savepoint prevents the COPY FREEZE, because COPY FREEZE needs the table to
> have been created or truncated in the current *sub*transaction. Issuing
> "RELEASE s1" before the COPY makes it work again, for example.
>
> >
> > * BEGIN;
> > * TRUNCATE t;
> > * SAVEPOINT save;
> > * TRUNCATE t;
> > * ROLLBACK TO save;
> > * COPY ...
>
> This is different. The table was truncated in the current subtransaction, and
> it's safe in principle to apply the optimization. Due to an implementation
> artifact, we'll reject it anyway.

OK, so, should we change the error message:

cannot perform FREEZE because of transaction activity after table
creation or truncation

to

cannot perform FREEZE because the table was not created or
truncated in the current subtransaction

or do we need to keep the "transaction activity" weasel wording because
of the second case you listed above? I am suspecting the later.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Noah Misch <noah(at)leadboat(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-02-02 14:51:13
Message-ID: 20130202145113.GA19169@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Feb 01, 2013 at 12:57:18PM -0500, Bruce Momjian wrote:
> On Tue, Jan 29, 2013 at 08:34:24PM -0500, Noah Misch wrote:
> > On Fri, Jan 25, 2013 at 11:28:58PM -0500, Bruce Momjian wrote:
> > > BEGIN;
> > > TRUNCATE vistest;
> > > SAVEPOINT s1;
> > > COPY vistest FROM stdin CSV FREEZE;
> > > ERROR: cannot perform FREEZE because of previous table activity in the current transaction
> > > COMMIT;
> > >
> > > Clearly it was truncated in the same transaction, but the savepoint
> > > somehow invalidates the freeze. There is a C comment about it:
> >
> > The savepoint prevents the COPY FREEZE, because COPY FREEZE needs the table to
> > have been created or truncated in the current *sub*transaction. Issuing
> > "RELEASE s1" before the COPY makes it work again, for example.
> >
> > >
> > > * BEGIN;
> > > * TRUNCATE t;
> > > * SAVEPOINT save;
> > > * TRUNCATE t;
> > > * ROLLBACK TO save;
> > > * COPY ...
> >
> > This is different. The table was truncated in the current subtransaction, and
> > it's safe in principle to apply the optimization. Due to an implementation
> > artifact, we'll reject it anyway.
>
> OK, so, should we change the error message:
>
> cannot perform FREEZE because of transaction activity after table
> creation or truncation
>
> to
>
> cannot perform FREEZE because the table was not created or
> truncated in the current subtransaction
>
> or do we need to keep the "transaction activity" weasel wording because
> of the second case you listed above? I am suspecting the later.

Let's touch on the exception in passing by using the phrase "last truncated",
giving this wording for both the second and the third COPY FREEZE error sites:

cannot perform FREEZE because the table was not created or last
truncated in the current subtransaction


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-02-02 15:12:54
Message-ID: 20130202151254.GD2371@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Feb 2, 2013 at 09:51:13AM -0500, Noah Misch wrote:
> > OK, so, should we change the error message:
> >
> > cannot perform FREEZE because of transaction activity after table
> > creation or truncation
> >
> > to
> >
> > cannot perform FREEZE because the table was not created or
> > truncated in the current subtransaction
> >
> > or do we need to keep the "transaction activity" weasel wording because
> > of the second case you listed above? I am suspecting the later.
>
> Let's touch on the exception in passing by using the phrase "last truncated",
> giving this wording for both the second and the third COPY FREEZE error sites:
>
> cannot perform FREEZE because the table was not created or last
> truncated in the current subtransaction

Well, so you are saying that there really isn't any use-visible logic
for those messages to be different, i.e. that the transaction id can be
set to invalid even if we created/truncated in the same transaction, but
not the same subtransaction?

The comparisons that trigger the two messages are:

if (cstate->rel->rd_createSubid != InvalidSubTransactionId ||
cstate->rel->rd_newRelfilenodeSubid != InvalidSubTransactionId)

and
if (cstate->rel->rd_createSubid != GetCurrentSubTransactionId() ||
cstate->rel->rd_newRelfilenodeSubid != GetCurrentSubTransactionId())

The first comparison is creation, the second, truncation.

Please confirm and I will make the change, or you can.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-02-02 17:09:05
Message-ID: 18389.1359824945@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> Well, so you are saying that there really isn't any use-visible logic
> for those messages to be different,

No, and in fact the whole block of code is badly written because it
conflates two unrelated tests. I guess somebody was trying to save
a couple of nanoseconds by not calling GetCurrentSubTransactionId
if a previous test had failed, but really why should we care about
that number of cycles in COPY preliminaries? The code ought to be
more like this:

/* comment about skipping FSM or WAL here */
if (cstate->rel->rd_createSubid != InvalidSubTransactionId ||
cstate->rel->rd_newRelfilenodeSubid != InvalidSubTransactionId)
{
hi_options |= HEAP_INSERT_SKIP_FSM;
if (!XLogIsNeeded())
hi_options |= HEAP_INSERT_SKIP_WAL;
}
/* comment about when we can perform FREEZE here */
if (cstate->freeze)
{
if (!ThereAreNoPriorRegisteredSnapshots() || !ThereAreNoReadyPortals())
ereport(ERROR,
(ERRCODE_INVALID_TRANSACTION_STATE,
errmsg("cannot perform FREEZE because of prior transaction activity")));

if (cstate->rel->rd_createSubid != GetCurrentSubTransactionId() &&
cstate->rel->rd_newRelfilenodeSubid != GetCurrentSubTransactionId())
ereport(ERROR,
(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE,
errmsg("cannot perform FREEZE because the table was not created or truncated in the current subtransaction")));
hi_options |= HEAP_INSERT_FROZEN;
}

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-02-02 17:56:33
Message-ID: 20130202175633.GA7812@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Feb 2, 2013 at 12:09:05PM -0500, Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Well, so you are saying that there really isn't any use-visible logic
> > for those messages to be different,
>
> No, and in fact the whole block of code is badly written because it
> conflates two unrelated tests. I guess somebody was trying to save
> a couple of nanoseconds by not calling GetCurrentSubTransactionId
> if a previous test had failed, but really why should we care about
> that number of cycles in COPY preliminaries? The code ought to be
> more like this:
>
> /* comment about skipping FSM or WAL here */
> if (cstate->rel->rd_createSubid != InvalidSubTransactionId ||
> cstate->rel->rd_newRelfilenodeSubid != InvalidSubTransactionId)
> {
> hi_options |= HEAP_INSERT_SKIP_FSM;
> if (!XLogIsNeeded())
> hi_options |= HEAP_INSERT_SKIP_WAL;
> }
> /* comment about when we can perform FREEZE here */
> if (cstate->freeze)
> {
> if (!ThereAreNoPriorRegisteredSnapshots() || !ThereAreNoReadyPortals())
> ereport(ERROR,
> (ERRCODE_INVALID_TRANSACTION_STATE,
> errmsg("cannot perform FREEZE because of prior transaction activity")));
>
> if (cstate->rel->rd_createSubid != GetCurrentSubTransactionId() &&
> cstate->rel->rd_newRelfilenodeSubid != GetCurrentSubTransactionId())
> ereport(ERROR,
> (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE,
> errmsg("cannot perform FREEZE because the table was not created or truncated in the current subtransaction")));
> hi_options |= HEAP_INSERT_FROZEN;
> }

Yes, I found the blocking odd too --- the test for
InvalidSubTransactionId is used by hi_options, and for freeze checking.
I assumed "!= InvalidSubTransactionId" and "!=
GetCurrentSubTransactionId()" had different meanings for freeze
checking.

I compounded the problem because originally there was no FREEZE failure
so no action was taken if "!= InvalidSubTransactionId".

Applied patch attached.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachment Content-Type Size
freeze.diff text/x-diff 4.6 KB

From: Noah Misch <noah(at)leadboat(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY FREEZE has no warning
Date: 2013-02-02 19:27:24
Message-ID: 20130202192724.GB19169@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Feb 02, 2013 at 10:12:54AM -0500, Bruce Momjian wrote:
> On Sat, Feb 2, 2013 at 09:51:13AM -0500, Noah Misch wrote:
> > Let's touch on the exception in passing by using the phrase "last truncated",
> > giving this wording for both the second and the third COPY FREEZE error sites:
> >
> > cannot perform FREEZE because the table was not created or last
> > truncated in the current subtransaction
>
> Well, so you are saying that there really isn't any use-visible logic
> for those messages to be different, i.e. that the transaction id can be
> set to invalid even if we created/truncated in the same transaction, but
> not the same subtransaction?

Right. The latest committed code makes sense to me.