Re: BUG #6572: The example of SPI_execute is bogus

Lists: pgsql-bugspgsql-hackers
From: umi(dot)tanuki(at)gmail(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #6572: The example of SPI_execute is bogus
Date: 2012-04-04 01:42:01
Message-ID: E1SFFEX-0006wr-AT@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

The following bug has been logged on the website:

Bug reference: 6572
Logged by: Hitoshi Harada
Email address: umi(dot)tanuki(at)gmail(dot)com
PostgreSQL version: 9.1.3
Operating system: Any
Description:

http://www.postgresql.org/docs/9.1/static/spi-spi-execute.html

===
SPI_execute("INSERT INTO foo SELECT * FROM bar", false, 5);

will allow at most 5 rows to be inserted into the table.
===

This seems not true unless I'm missing something.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: umi(dot)tanuki(at)gmail(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #6572: The example of SPI_execute is bogus
Date: 2012-04-04 15:00:41
Message-ID: 25939.1333551641@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

umi(dot)tanuki(at)gmail(dot)com writes:
> http://www.postgresql.org/docs/9.1/static/spi-spi-execute.html

> ===
> SPI_execute("INSERT INTO foo SELECT * FROM bar", false, 5);
> will allow at most 5 rows to be inserted into the table.
> ===

> This seems not true unless I'm missing something.

Hmm ... that did work as described, until we broke it :-(. This is an
oversight in the 9.0 changes that added separate ModifyTuple nodes to
plan trees. ModifyTuple doesn't return after each updated row, unless
there's a RETURNING clause; which means that the current_tuple_count
check logic in ExecutePlan() no longer stops execution as intended.

Given the lack of complaints since 9.0, maybe we should not fix this
but just redefine the new behavior as being correct? But it seems
mighty inconsistent that the tuple limit would apply if you have
RETURNING but not when you don't. In any case, the ramifications
are wider than one example in the SPI docs.

Thoughts?

regards, tom lane


From: Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #6572: The example of SPI_execute is bogus
Date: 2012-04-05 06:39:53
Message-ID: CAP7QgmkvMYAwYw1wXAtxbVOEYVeJs7hBUNFkbgssaCxc_FNa_w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Wed, Apr 4, 2012 at 8:00 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> umi(dot)tanuki(at)gmail(dot)com writes:
>> http://www.postgresql.org/docs/9.1/static/spi-spi-execute.html
>
>> ===
>> SPI_execute("INSERT INTO foo SELECT * FROM bar", false, 5);
>> will allow at most 5 rows to be inserted into the table.
>> ===
>
>> This seems not true unless I'm missing something.
>
> Hmm ... that did work as described, until we broke it :-(.  This is an
> oversight in the 9.0 changes that added separate ModifyTuple nodes to
> plan trees.  ModifyTuple doesn't return after each updated row, unless
> there's a RETURNING clause; which means that the current_tuple_count
> check logic in ExecutePlan() no longer stops execution as intended.
>
> Given the lack of complaints since 9.0, maybe we should not fix this
> but just redefine the new behavior as being correct?  But it seems
> mighty inconsistent that the tuple limit would apply if you have
> RETURNING but not when you don't.  In any case, the ramifications
> are wider than one example in the SPI docs.
>
> Thoughts?

To be honest, I was surprised when I found tcount parameter is said to
be applied to even INSERT. I believe people think that parameter is
to limit memory consumption when returning tuples thus it'd be applied
for only SELECT or DML with RETURNING. So I'm +1 for non-fix but
redefine the behavior. Who wants to limit the number of rows
processed inside the backend, from SPI?

Thanks,
--
Hitoshi Harada


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #6572: The example of SPI_execute is bogus
Date: 2012-04-13 22:53:48
Message-ID: CA+TgmobS_t4ixo+wEAx-KyhRzapYTapY06q0qSctFuGiOBSEmA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Thu, Apr 5, 2012 at 2:39 AM, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com> wrote:
> On Wed, Apr 4, 2012 at 8:00 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> umi(dot)tanuki(at)gmail(dot)com writes:
>>> http://www.postgresql.org/docs/9.1/static/spi-spi-execute.html
>>
>>> ===
>>> SPI_execute("INSERT INTO foo SELECT * FROM bar", false, 5);
>>> will allow at most 5 rows to be inserted into the table.
>>> ===
>>
>>> This seems not true unless I'm missing something.
>>
>> Hmm ... that did work as described, until we broke it :-(.  This is an
>> oversight in the 9.0 changes that added separate ModifyTuple nodes to
>> plan trees.  ModifyTuple doesn't return after each updated row, unless
>> there's a RETURNING clause; which means that the current_tuple_count
>> check logic in ExecutePlan() no longer stops execution as intended.
>>
>> Given the lack of complaints since 9.0, maybe we should not fix this
>> but just redefine the new behavior as being correct?  But it seems
>> mighty inconsistent that the tuple limit would apply if you have
>> RETURNING but not when you don't.  In any case, the ramifications
>> are wider than one example in the SPI docs.
>>
>> Thoughts?
>
> To be honest, I was surprised when I found tcount parameter is said to
> be applied to even INSERT.  I believe people think that parameter is
> to limit memory consumption when returning tuples thus it'd be applied
> for only SELECT or DML with RETURNING.  So I'm +1 for non-fix but
> redefine the behavior.  Who wants to limit the number of rows
> processed inside the backend, from SPI?

Yeah. I think it would be a good idea for UPDATE and DELETE to expose
a LIMIT option, but I can't really see the virtue in making that
functionality available only through SPI.

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


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #6572: The example of SPI_execute is bogus
Date: 2012-04-14 02:43:36
Message-ID: CAFj8pRD3WUDKC-q-EhCnraNXF9pyD9qSxGKQ0O=UkoHiisXAVQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

>
> Yeah.  I think it would be a good idea for UPDATE and DELETE to expose
> a LIMIT option, but I can't really see the virtue in making that
> functionality available only through SPI.
>

I don't agree - LIMIT after UPDATE or DELETE has no sense. Clean
solution should be based on using updateable CTE.

Regards

Pavel


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #6572: The example of SPI_execute is bogus
Date: 2012-04-14 04:21:22
Message-ID: CA+Tgmob0yP0Y4FQG8Oi0KU0b8-24ZABL+0OAJr4YR2CgZDEasQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Fri, Apr 13, 2012 at 10:43 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>> Yeah.  I think it would be a good idea for UPDATE and DELETE to expose
>> a LIMIT option, but I can't really see the virtue in making that
>> functionality available only through SPI.
>
> I don't agree - LIMIT after UPDATE or DELETE has no sense. Clean
> solution should be based on using updateable CTE.

It has a lot of sense. Without it, it's very difficult to do logical
replication on a table with no primary key.

(Whether or not people should create such tables in the first place
is, of course, beside the point.)

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


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #6572: The example of SPI_execute is bogus
Date: 2012-04-14 07:27:58
Message-ID: CAFj8pRA7O2TWeYt5dfpLQAFieLB57qD4=_dL+c4mYfDbsBCt-Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2012/4/14 Robert Haas <robertmhaas(at)gmail(dot)com>:
> On Fri, Apr 13, 2012 at 10:43 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>>> Yeah.  I think it would be a good idea for UPDATE and DELETE to expose
>>> a LIMIT option, but I can't really see the virtue in making that
>>> functionality available only through SPI.
>>
>> I don't agree - LIMIT after UPDATE or DELETE has no sense. Clean
>> solution should be based on using updateable CTE.
>
> It has a lot of sense.  Without it, it's very difficult to do logical
> replication on a table with no primary key.
>
> (Whether or not people should create such tables in the first place
> is, of course, beside the point.)

I am not against to functionality - I am against just to syntax DELETE
FROM tab LIMIT x

because is it ambiguous what means: DELETE FROM tab RETURNING * LIMIT x

Regards

Pavel

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


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #6572: The example of SPI_execute is bogus
Date: 2012-04-14 12:23:40
Message-ID: CA+TgmoYL_GC=1OSpPFW=Qz_LVe6_y0x2qQ=GSgEx2NpFKYhPNw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Sat, Apr 14, 2012 at 3:27 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>> It has a lot of sense.  Without it, it's very difficult to do logical
>> replication on a table with no primary key.
>>
>> (Whether or not people should create such tables in the first place
>> is, of course, beside the point.)
>
> I am not against to functionality - I am against just to syntax DELETE
> FROM tab LIMIT x
>
> because is it ambiguous what means: DELETE FROM tab RETURNING * LIMIT x

What's ambiguous about that?

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


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #6572: The example of SPI_execute is bogus
Date: 2012-04-14 16:15:59
Message-ID: 1334420159.9019.38.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On lör, 2012-04-14 at 08:23 -0400, Robert Haas wrote:
> On Sat, Apr 14, 2012 at 3:27 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> >> It has a lot of sense. Without it, it's very difficult to do logical
> >> replication on a table with no primary key.
> >>
> >> (Whether or not people should create such tables in the first place
> >> is, of course, beside the point.)
> >
> > I am not against to functionality - I am against just to syntax DELETE
> > FROM tab LIMIT x
> >
> > because is it ambiguous what means: DELETE FROM tab RETURNING * LIMIT x
>
> What's ambiguous about that?

I suppose one could wonder whether the LIMIT applies to the deleting or
just the returning.


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #6572: The example of SPI_execute is bogus
Date: 2012-04-14 17:01:24
Message-ID: CAFj8pRDM4Q92esE8_BadrrSUc=mRveZL-hdmRDr8CSY7YwnnNw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2012/4/14 Peter Eisentraut <peter_e(at)gmx(dot)net>:
> On lör, 2012-04-14 at 08:23 -0400, Robert Haas wrote:
>> On Sat, Apr 14, 2012 at 3:27 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>> >> It has a lot of sense.  Without it, it's very difficult to do logical
>> >> replication on a table with no primary key.
>> >>
>> >> (Whether or not people should create such tables in the first place
>> >> is, of course, beside the point.)
>> >
>> > I am not against to functionality - I am against just to syntax DELETE
>> > FROM tab LIMIT x
>> >
>> > because is it ambiguous what means: DELETE FROM tab RETURNING * LIMIT x
>>
>> What's ambiguous about that?
>
> I suppose one could wonder whether the LIMIT applies to the deleting or
> just the returning.
>

yes, exactly

Regards

Pavel


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #6572: The example of SPI_execute is bogus
Date: 2012-04-14 21:48:31
Message-ID: CA+TgmoZ5eK8rBhW3EttfJ7bLWKuXm48ei2ZROYFF-p6cazkzbA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Sat, Apr 14, 2012 at 12:15 PM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> On lör, 2012-04-14 at 08:23 -0400, Robert Haas wrote:
>> On Sat, Apr 14, 2012 at 3:27 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>> >> It has a lot of sense.  Without it, it's very difficult to do logical
>> >> replication on a table with no primary key.
>> >>
>> >> (Whether or not people should create such tables in the first place
>> >> is, of course, beside the point.)
>> >
>> > I am not against to functionality - I am against just to syntax DELETE
>> > FROM tab LIMIT x
>> >
>> > because is it ambiguous what means: DELETE FROM tab RETURNING * LIMIT x
>>
>> What's ambiguous about that?
>
> I suppose one could wonder whether the LIMIT applies to the deleting or
> just the returning.

I suppose. I had in mind it would apply to both.

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


From: Boszormenyi Zoltan <zb(at)cybertec(dot)at>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #6572: The example of SPI_execute is bogus
Date: 2012-04-15 09:14:38
Message-ID: 4F8A917E.4020305@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2012-04-14 18:15 keltezéssel, Peter Eisentraut írta:
> On lör, 2012-04-14 at 08:23 -0400, Robert Haas wrote:
>> On Sat, Apr 14, 2012 at 3:27 AM, Pavel Stehule<pavel(dot)stehule(at)gmail(dot)com> wrote:
>>>> It has a lot of sense. Without it, it's very difficult to do logical
>>>> replication on a table with no primary key.
>>>>
>>>> (Whether or not people should create such tables in the first place
>>>> is, of course, beside the point.)
>>> I am not against to functionality - I am against just to syntax DELETE
>>> FROM tab LIMIT x
>>>
>>> because is it ambiguous what means: DELETE FROM tab RETURNING * LIMIT x
>> What's ambiguous about that?
> I suppose one could wonder whether the LIMIT applies to the deleting or
> just the returning.

Ambigous only in this order. LIMIT x RETURNING * wouldn't be.

--
----------------------------------
Zoltán Böszörményi
Cybertec Schönig& Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
http://www.postgresql.at/


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Boszormenyi Zoltan <zb(at)cybertec(dot)at>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Robert Haas <robertmhaas(at)gmail(dot)com>, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #6572: The example of SPI_execute is bogus
Date: 2012-04-15 09:20:42
Message-ID: CAFj8pRCfEtO1_c03Qw1=zFt2r1CFqDkzBxAnLRqGC21Y8ytRtg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

2012/4/15 Boszormenyi Zoltan <zb(at)cybertec(dot)at>:
> 2012-04-14 18:15 keltezéssel, Peter Eisentraut írta:
>
>> On lör, 2012-04-14 at 08:23 -0400, Robert Haas wrote:
>>>
>>> On Sat, Apr 14, 2012 at 3:27 AM, Pavel Stehule<pavel(dot)stehule(at)gmail(dot)com>
>>>  wrote:
>>>>>
>>>>> It has a lot of sense.  Without it, it's very difficult to do logical
>>>>> replication on a table with no primary key.
>>>>>
>>>>> (Whether or not people should create such tables in the first place
>>>>> is, of course, beside the point.)
>>>>
>>>> I am not against to functionality - I am against just to syntax DELETE
>>>> FROM tab LIMIT x
>>>>
>>>> because is it ambiguous what means: DELETE FROM tab RETURNING * LIMIT x
>>>
>>> What's ambiguous about that?
>>
>> I suppose one could wonder whether the LIMIT applies to the deleting or
>> just the returning.
>
>
> Ambigous only in this order. LIMIT x RETURNING * wouldn't be.

but theoretically you can has two LIMIT clauses in one SQL statements

DELETE FROM tab LIMIT n RETURNING * LIMIT m

without updatable CTE it is probably only one solution, but because we
have UCTE, then we don't need this construct.

Regards

Pavel

>
> --
> ----------------------------------
> Zoltán Böszörményi
> Cybertec Schönig&  Schönig GmbH
> Gröhrmühlgasse 26
> A-2700 Wiener Neustadt, Austria
> Web: http://www.postgresql-support.de
>     http://www.postgresql.at/
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #6572: The example of SPI_execute is bogus
Date: 2012-04-15 16:29:39
Message-ID: 9674.1334507379@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> On Thu, Apr 5, 2012 at 2:39 AM, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com> wrote:
>> On Wed, Apr 4, 2012 at 8:00 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> Given the lack of complaints since 9.0, maybe we should not fix this
>>> but just redefine the new behavior as being correct? But it seems
>>> mighty inconsistent that the tuple limit would apply if you have
>>> RETURNING but not when you don't. In any case, the ramifications
>>> are wider than one example in the SPI docs.

>> To be honest, I was surprised when I found tcount parameter is said to
>> be applied to even INSERT. I believe people think that parameter is
>> to limit memory consumption when returning tuples thus it'd be applied
>> for only SELECT or DML with RETURNING. So I'm +1 for non-fix but
>> redefine the behavior. Who wants to limit the number of rows
>> processed inside the backend, from SPI?

> Yeah.

Okay, apparently nobody cares about RETURNING behaving differently from
non-RETURNING, so the consensus is to redefine the current behavior as
correct. That means what we need is to go through the docs and see what
places need to be updated (and, I guess, back-patch the changes to 9.0).
I will get to this if nobody else does, but not right away.

> I think it would be a good idea for UPDATE and DELETE to expose
> a LIMIT option, but I can't really see the virtue in making that
> functionality available only through SPI.

FWIW, I'm not excited about that. You can get well-defined behavior
today from a SELECT/LIMIT drawing from a writable CTE (namely, that
the UPDATE/DELETE runs to completion but you only see a subset of
its RETURNING result). LIMIT directly on the UPDATE/DELETE would be
ill-defined, unless perhaps you want to also invent a way of specifying
the order in which rows get selected for update; but I don't want to
go there.

regards, tom lane


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: BUG #6572: The example of SPI_execute is bogus
Date: 2012-04-18 15:11:14
Message-ID: CA+TgmobbJZSLb1mKj3QwRjk1LmtS5uZsmycf_oZMaF4FXSdFtA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Sun, Apr 15, 2012 at 12:29 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> I think it would be a good idea for UPDATE and DELETE to expose
>> a LIMIT option, but I can't really see the virtue in making that
>> functionality available only through SPI.
>
> FWIW, I'm not excited about that.  You can get well-defined behavior
> today from a SELECT/LIMIT drawing from a writable CTE (namely, that
> the UPDATE/DELETE runs to completion but you only see a subset of
> its RETURNING result).  LIMIT directly on the UPDATE/DELETE would be
> ill-defined, unless perhaps you want to also invent a way of specifying
> the order in which rows get selected for update; but I don't want to
> go there.

In the use cases I'm thinking of, it doesn't matter which row you
decide to update or delete, only that you pick a single one.

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


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] BUG #6572: The example of SPI_execute is bogus
Date: 2012-08-29 03:16:47
Message-ID: 20120829031647.GB26103@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Sun, Apr 15, 2012 at 12:29:39PM -0400, Tom Lane wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> > On Thu, Apr 5, 2012 at 2:39 AM, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com> wrote:
> >> On Wed, Apr 4, 2012 at 8:00 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> >>> Given the lack of complaints since 9.0, maybe we should not fix this
> >>> but just redefine the new behavior as being correct? But it seems
> >>> mighty inconsistent that the tuple limit would apply if you have
> >>> RETURNING but not when you don't. In any case, the ramifications
> >>> are wider than one example in the SPI docs.
>
> >> To be honest, I was surprised when I found tcount parameter is said to
> >> be applied to even INSERT. I believe people think that parameter is
> >> to limit memory consumption when returning tuples thus it'd be applied
> >> for only SELECT or DML with RETURNING. So I'm +1 for non-fix but
> >> redefine the behavior. Who wants to limit the number of rows
> >> processed inside the backend, from SPI?
>
> > Yeah.
>
> Okay, apparently nobody cares about RETURNING behaving differently from
> non-RETURNING, so the consensus is to redefine the current behavior as
> correct. That means what we need is to go through the docs and see what
> places need to be updated (and, I guess, back-patch the changes to 9.0).
> I will get to this if nobody else does, but not right away.

Would someone make the doc change outlined above? Thanks.

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

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


From: Rajeev rastogi <rajeev(dot)rastogi(at)huawei(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] BUG #6572: The example of SPI_execute is bogus
Date: 2012-08-29 13:13:51
Message-ID: BF2827DCCE55594C8D7A8F7FFD3AB771313C5825@SZXEML508-MBS.china.huawei.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

________________________________________
From: pgsql-bugs-owner(at)postgresql(dot)org [pgsql-bugs-owner(at)postgresql(dot)org] on behalf of Bruce Momjian [bruce(at)momjian(dot)us]
Sent: Wednesday, August 29, 2012 8:46 AM
To: Tom Lane
Cc: Robert Haas; Hitoshi Harada; pgsql-bugs(at)postgresql(dot)org; pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] [BUGS] BUG #6572: The example of SPI_execute is bogus

On Sun, Apr 15, 2012 at 12:29:39PM -0400, Tom Lane wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> > On Thu, Apr 5, 2012 at 2:39 AM, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com> wrote:
> >> On Wed, Apr 4, 2012 at 8:00 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> >>> Given the lack of complaints since 9.0, maybe we should not fix this
> >>> but just redefine the new behavior as being correct? But it seems
> >>> mighty inconsistent that the tuple limit would apply if you have
> >>> RETURNING but not when you don't. In any case, the ramifications
> >>> are wider than one example in the SPI docs.
>
> >> To be honest, I was surprised when I found tcount parameter is said to
> >> be applied to even INSERT. I believe people think that parameter is
> >> to limit memory consumption when returning tuples thus it'd be applied
> >> for only SELECT or DML with RETURNING. So I'm +1 for non-fix but
> >> redefine the behavior. Who wants to limit the number of rows
> >> processed inside the backend, from SPI?
>
> > Yeah.
>
> Okay, apparently nobody cares about RETURNING behaving differently from
> non-RETURNING, so the consensus is to redefine the current behavior as
> correct. That means what we need is to go through the docs and see what
> places need to be updated (and, I guess, back-patch the changes to 9.0).
> I will get to this if nobody else does, but not right away.

> Would someone make the doc change outlined above? Thanks.

I would like to work on this documentation bug.
As per analysis I am planning to update following SPI function:
1. SPI_Execute: Here we will mention that argument count is used only for the kind of command which returns result i.e. all kind of SELECT and DML with returning clause. count is ignored for any other kind of commands. I will add one example also to indicate the difference.
2. SPI_execute_plan_with_paramlist: Here we can give just reference to SPI_execute i.e. I will mention that count has same interpretation as in SPI_execute.
3. SPI_execp: Here we can give just reference to SPI_execute i.e. I will mention that count has same interpretation as in SPI_execute.

Please provide your feedback.

Thanks and Regards,
Kumar Rajeev Rastogi
Cell No - +91 8971367787


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Rajeev rastogi <rajeev(dot)rastogi(at)huawei(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] BUG #6572: The example of SPI_execute is bogus
Date: 2013-01-24 20:59:42
Message-ID: 20130124205942.GC21914@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Wed, Aug 29, 2012 at 01:13:51PM +0000, Rajeev rastogi wrote:
> ________________________________________
> From: pgsql-bugs-owner(at)postgresql(dot)org [pgsql-bugs-owner(at)postgresql(dot)org] on behalf of Bruce Momjian [bruce(at)momjian(dot)us]
> Sent: Wednesday, August 29, 2012 8:46 AM
> To: Tom Lane
> Cc: Robert Haas; Hitoshi Harada; pgsql-bugs(at)postgresql(dot)org; pgsql-hackers(at)postgresql(dot)org
> Subject: Re: [HACKERS] [BUGS] BUG #6572: The example of SPI_execute is bogus
>
> On Sun, Apr 15, 2012 at 12:29:39PM -0400, Tom Lane wrote:
> > Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> > > On Thu, Apr 5, 2012 at 2:39 AM, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com> wrote:
> > >> On Wed, Apr 4, 2012 at 8:00 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > >>> Given the lack of complaints since 9.0, maybe we should not fix this
> > >>> but just redefine the new behavior as being correct? But it seems
> > >>> mighty inconsistent that the tuple limit would apply if you have
> > >>> RETURNING but not when you don't. In any case, the ramifications
> > >>> are wider than one example in the SPI docs.
> >
> > >> To be honest, I was surprised when I found tcount parameter is said to
> > >> be applied to even INSERT. I believe people think that parameter is
> > >> to limit memory consumption when returning tuples thus it'd be applied
> > >> for only SELECT or DML with RETURNING. So I'm +1 for non-fix but
> > >> redefine the behavior. Who wants to limit the number of rows
> > >> processed inside the backend, from SPI?
> >
> > > Yeah.
> >
> > Okay, apparently nobody cares about RETURNING behaving differently from
> > non-RETURNING, so the consensus is to redefine the current behavior as
> > correct. That means what we need is to go through the docs and see what
> > places need to be updated (and, I guess, back-patch the changes to 9.0).
> > I will get to this if nobody else does, but not right away.
>
> > Would someone make the doc change outlined above? Thanks.
>
>
> I would like to work on this documentation bug.
> As per analysis I am planning to update following SPI function:
> 1. SPI_Execute: Here we will mention that argument count is used only for the kind of command which returns result i.e. all kind of SELECT and DML with returning clause. count is ignored for any other kind of commands. I will add one example also to indicate the difference.
> 2. SPI_execute_plan_with_paramlist: Here we can give just reference to SPI_execute i.e. I will mention that count has same interpretation as in SPI_execute.
> 3. SPI_execp: Here we can give just reference to SPI_execute i.e. I will mention that count has same interpretation as in SPI_execute.

Would someone please provide answers to these questions, or write a
patch?

--
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: Rajeev rastogi <rajeev(dot)rastogi(at)huawei(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] BUG #6572: The example of SPI_execute is bogus
Date: 2013-01-24 21:51:04
Message-ID: 26202.1359064264@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> Would someone make the doc change outlined above? Thanks.

Sorry, I'd nearly forgotten about this issue. Will see about fixing the
docs. (It looks like some of the comments in execMain.c could use work
too.)

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Rajeev rastogi <rajeev(dot)rastogi(at)huawei(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Hitoshi Harada <umi(dot)tanuki(at)gmail(dot)com>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] BUG #6572: The example of SPI_execute is bogus
Date: 2013-01-24 22:12:02
Message-ID: 20130124221202.GE21914@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs pgsql-hackers

On Thu, Jan 24, 2013 at 04:51:04PM -0500, Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > Would someone make the doc change outlined above? Thanks.
>
> Sorry, I'd nearly forgotten about this issue. Will see about fixing the
> docs. (It looks like some of the comments in execMain.c could use work
> too.)

Thanks.

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

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