Re: [Review] Add SPI_gettypmod() to return a field's typemod from a TupleDesc

Lists: pgsql-hackers
From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Amit Kapila <amit(dot)kapila(at)huawei(dot)com>
Cc: chetan(dot)suttraway(at)enterprisedb(dot)com, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [Review] Add SPI_gettypmod() to return a field's typemod from a TupleDesc
Date: 2012-06-28 13:49:36
Message-ID: CA+TgmoZs3RUThB6kXtbOR6RKCa4-v-xbm5GWmK_Vrao+GeYTtA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jun 18, 2012 at 3:29 PM, Amit Kapila <amit(dot)kapila(at)huawei(dot)com> wrote:
> [ review ]

Chetan, this patch is waiting for an update from you. If you'd like
this to get committed this CommitFest, we'll need an updated patch
soon.

Thanks,

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


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Amit Kapila <amit(dot)kapila(at)huawei(dot)com>
Cc: chetan(dot)suttraway(at)enterprisedb(dot)com, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [Review] Add SPI_gettypmod() to return a field's typemod from a TupleDesc
Date: 2012-07-03 15:33:20
Message-ID: CA+TgmoYhrmaWHR9Vn8rM3=-PhaVG33CZejunT62BjS0_wiMgiA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jun 28, 2012 at 9:49 AM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> On Mon, Jun 18, 2012 at 3:29 PM, Amit Kapila <amit(dot)kapila(at)huawei(dot)com> wrote:
>> [ review ]
>
> Chetan, this patch is waiting for an update from you. If you'd like
> this to get committed this CommitFest, we'll need an updated patch
> soon.

Hearing no response, I've marked this patch Returned with Feedback.

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


From: Mark Wong <markwkm(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: chetan(dot)suttraway(at)enterprisedb(dot)com
Subject: Re: [Review] Add SPI_gettypmod() to return a field's typemod from a TupleDesc
Date: 2013-02-09 17:07:29
Message-ID: CAE+TzGqLoaty1UtZN4NzqpsW3TvdZ_7sT27qNCqs6zFHCKMCzA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jul 3, 2012 at 8:33 AM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> On Thu, Jun 28, 2012 at 9:49 AM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>> On Mon, Jun 18, 2012 at 3:29 PM, Amit Kapila <amit(dot)kapila(at)huawei(dot)com> wrote:
>>> [ review ]
>>
>> Chetan, this patch is waiting for an update from you. If you'd like
>> this to get committed this CommitFest, we'll need an updated patch
>> soon.
>
> Hearing no response, I've marked this patch Returned with Feedback.

Hello everyone,

I thought I'd take a stab at helping finish this patch. I have made
an attempt at adding documentation and replacing the couple of XXX
comments. I'll add it to the next commitfest.

Regards,
Mark

Attachment Content-Type Size
add_spigettypmod-20130209.diff application/octet-stream 5.4 KB

From: Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>
To: Mark Wong <markwkm(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Chetan Suttraway <chetan(dot)suttraway(at)enterprisedb(dot)com>
Subject: Re: [Review] Add SPI_gettypmod() to return a field's typemod from a TupleDesc
Date: 2013-06-25 08:38:51
Message-ID: CAM2+6=X=5i-csDsnH0Mx2w-9VfL5+x7tyPzpjmzKq3_sqR25rg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi Mark,

Is this the latest patch you are targeting for 9.4 CF1 ?

I am going to review it.

From the comment, here is one issue you need to resolve first:

*************** exec_eval_datum(PLpgSQL_execstate *estat
*** 4386,4396 ****
errmsg("record \"%s\" has no field \"%s\"",
rec->refname, recfield->fieldname)));
*typeid = SPI_gettypeid(rec->tupdesc, fno);
! /* XXX there's no SPI_gettypmod, for some reason */
! if (fno > 0)
! *typetypmod = rec->tupdesc->attrs[fno - 1]->atttypmod;
! else
! *typetypmod = -1;
*value = SPI_getbinval(rec->tup, rec->tupdesc, fno,
isnull);
break;
}
--- 4386,4392 ----
errmsg("record \"%s\" has no field \"%s\"",
rec->refname, recfield->fieldname)));
*typeid = SPI_gettypeid(rec->tupdesc, fno);
! *typetypmod = *SPI_gettypeid*(rec->tupdesc, fno);
*value = SPI_getbinval(rec->tup, rec->tupdesc, fno,
isnull);
break;
}

Once you confirm, I will go ahead reviewing it.

Thanks

On Sat, Feb 9, 2013 at 10:37 PM, Mark Wong <markwkm(at)gmail(dot)com> wrote:

> On Tue, Jul 3, 2012 at 8:33 AM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> > On Thu, Jun 28, 2012 at 9:49 AM, Robert Haas <robertmhaas(at)gmail(dot)com>
> wrote:
> >> On Mon, Jun 18, 2012 at 3:29 PM, Amit Kapila <amit(dot)kapila(at)huawei(dot)com>
> wrote:
> >>> [ review ]
> >>
> >> Chetan, this patch is waiting for an update from you. If you'd like
> >> this to get committed this CommitFest, we'll need an updated patch
> >> soon.
> >
> > Hearing no response, I've marked this patch Returned with Feedback.
>
> Hello everyone,
>
> I thought I'd take a stab at helping finish this patch. I have made
> an attempt at adding documentation and replacing the couple of XXX
> comments. I'll add it to the next commitfest.
>
> Regards,
> Mark
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>
>

--
Jeevan B Chalke
Senior Software Engineer, R&D
EnterpriseDB Corporation
The Enterprise PostgreSQL Company

Phone: +91 20 30589500

Website: www.enterprisedb.com
EnterpriseDB Blog: http://blogs.enterprisedb.com/
Follow us on Twitter: http://www.twitter.com/enterprisedb

This e-mail message (and any attachment) is intended for the use of the
individual or entity to whom it is addressed. This message contains
information from EnterpriseDB Corporation that may be privileged,
confidential, or exempt from disclosure under applicable law. If you are
not the intended recipient or authorized to receive this for the intended
recipient, any use, dissemination, distribution, retention, archiving, or
copying of this communication is strictly prohibited. If you have received
this e-mail in error, please notify the sender immediately by reply e-mail
and delete this message.


From: Mark Wong <markwkm(at)gmail(dot)com>
To: Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Chetan Suttraway <chetan(dot)suttraway(at)enterprisedb(dot)com>
Subject: Re: [Review] Add SPI_gettypmod() to return a field's typemod from a TupleDesc
Date: 2013-06-26 02:19:58
Message-ID: CAE+TzGotgnfUDMCG13EMJ5t-Y+F1y9N=3NzJ4pPN-XJ8pnAHHQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jun 25, 2013 at 1:38 AM, Jeevan Chalke
<jeevan(dot)chalke(at)enterprisedb(dot)com> wrote:
> Hi Mark,
>
> Is this the latest patch you are targeting for 9.4 CF1 ?
>
> I am going to review it.
>
> From the comment, here is one issue you need to resolve first:
>
> *************** exec_eval_datum(PLpgSQL_execstate *estat
> *** 4386,4396 ****
> errmsg("record \"%s\" has no field \"%s\"",
> rec->refname, recfield->fieldname)));
> *typeid = SPI_gettypeid(rec->tupdesc, fno);
> ! /* XXX there's no SPI_gettypmod, for some reason */
> ! if (fno > 0)
> ! *typetypmod = rec->tupdesc->attrs[fno - 1]->atttypmod;
> ! else
> ! *typetypmod = -1;
> *value = SPI_getbinval(rec->tup, rec->tupdesc, fno,
> isnull);
> break;
> }
> --- 4386,4392 ----
> errmsg("record \"%s\" has no field \"%s\"",
> rec->refname, recfield->fieldname)));
> *typeid = SPI_gettypeid(rec->tupdesc, fno);
> ! *typetypmod = SPI_gettypeid(rec->tupdesc, fno);
> *value = SPI_getbinval(rec->tup, rec->tupdesc, fno,
> isnull);
> break;
> }
>
>
> Once you confirm, I will go ahead reviewing it.

Hi Jeevan,

Oopsies, I've updated the patch and attached it.

Regards,
Mark

Attachment Content-Type Size
add_spigettypmod-20130625.diff application/octet-stream 5.4 KB

From: Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>
To: Mark Wong <markwkm(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [Review] Add SPI_gettypmod() to return a field's typemod from a TupleDesc
Date: 2013-06-26 10:02:15
Message-ID: CAM2+6=V7u6HHLhdL8xyGwxKc+Vwk5bYesLMERFbFaxBfF1r6Mg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Jun 26, 2013 at 7:49 AM, Mark Wong <markwkm(at)gmail(dot)com> wrote:

> On Tue, Jun 25, 2013 at 1:38 AM, Jeevan Chalke
> <jeevan(dot)chalke(at)enterprisedb(dot)com> wrote:
> > Hi Mark,
> >
> > Is this the latest patch you are targeting for 9.4 CF1 ?
> >
> > I am going to review it.
> >
> > From the comment, here is one issue you need to resolve first:
> >
> > *************** exec_eval_datum(PLpgSQL_execstate *estat
> > *** 4386,4396 ****
> > errmsg("record \"%s\" has no field
> \"%s\"",
> > rec->refname,
> recfield->fieldname)));
> > *typeid = SPI_gettypeid(rec->tupdesc, fno);
> > ! /* XXX there's no SPI_gettypmod, for some reason */
> > ! if (fno > 0)
> > ! *typetypmod = rec->tupdesc->attrs[fno -
> 1]->atttypmod;
> > ! else
> > ! *typetypmod = -1;
> > *value = SPI_getbinval(rec->tup, rec->tupdesc, fno,
> > isnull);
> > break;
> > }
> > --- 4386,4392 ----
> > errmsg("record \"%s\" has no field
> \"%s\"",
> > rec->refname,
> recfield->fieldname)));
> > *typeid = SPI_gettypeid(rec->tupdesc, fno);
> > ! *typetypmod = SPI_gettypeid(rec->tupdesc, fno);
> > *value = SPI_getbinval(rec->tup, rec->tupdesc, fno,
> > isnull);
> > break;
> > }
> >
> >
> > Once you confirm, I will go ahead reviewing it.
>
> Hi Jeevan,
>
> Oopsies, I've updated the patch and attached it.
>

Here are my review points:

1. Patch is very simple and straight forward.
2. Applies well with patch command. No issues at all.
3. Regression test passes. We have good coverage for that. Also NO issues
found with my testing.
4. New function is analogous to other SPI_get* functions
5. Ready for committer

However, while walking through your changes, I see following line:
/* XXX there's no SPI_getcollation either */
It says we do need function for SPI_getcollation as well. It will be another
simple patch.

Anyway this is not part of this topic so I will go ahead and mark it as
"Ready for committer"

Thanks

Regards,
> Mark
>

--
Jeevan B Chalke
Senior Software Engineer, R&D
EnterpriseDB Corporation
The Enterprise PostgreSQL Company

Phone: +91 20 30589500

Website: www.enterprisedb.com
EnterpriseDB Blog: http://blogs.enterprisedb.com/
Follow us on Twitter: http://www.twitter.com/enterprisedb

This e-mail message (and any attachment) is intended for the use of the
individual or entity to whom it is addressed. This message contains
information from EnterpriseDB Corporation that may be privileged,
confidential, or exempt from disclosure under applicable law. If you are
not the intended recipient or authorized to receive this for the intended
recipient, any use, dissemination, distribution, retention, archiving, or
copying of this communication is strictly prohibited. If you have received
this e-mail in error, please notify the sender immediately by reply e-mail
and delete this message.


From: Noah Misch <noah(at)leadboat(dot)com>
To: Mark Wong <markwkm(at)gmail(dot)com>
Cc: Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Chetan Suttraway <chetan(dot)suttraway(at)enterprisedb(dot)com>
Subject: Re: [Review] Add SPI_gettypmod() to return a field's typemod from a TupleDesc
Date: 2013-07-08 00:15:00
Message-ID: 20130708001500.GA1150570@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I find the SPI "interface support functions" quaint. They're thin wrappers,
of ancient origin, around standard backend coding patterns. They have the
anti-feature of communicating certain programming errors through return
value/SPI_result rather than elog()/Assert(). The chance that we could
substantially refactor the underlying primary backend APIs and data structures
while keeping these SPI wrappers unchanged seems slight.

On Tue, Jun 25, 2013 at 07:19:58PM -0700, Mark Wong wrote:
> + <function>SPI_gettypmod</function> returns the type-specific data supplied
> + at table creation time. For example: the max length of a varchar field.

SPI callers typically have no business interpreting the value, that being the
distinct purview of each type implementation. The text type does set its
typmod to 4 + max length, but other code should not know that. SPI callers
can use this to convey a typmod for later use, though.

> + <para>
> + The type-specific data supplied at table creation time of the specified
> + column or <symbol>InvalidOid</symbol> on error. On error,
> + <varname>SPI_result</varname> is set to
> + <symbol>SPI_ERROR_NOATTRIBUTE</symbol>.
> + </para>

You have it returning -1, not InvalidOid. Per Amit's review last year, I'm
wary of returning -1 in the error case. But I suspect most callers will, like
the two callers you add, make a point of never passing an invalid argument and
then not bother checking for error. So, no big deal.

I mildly recommend we reject this patch as such, remove the TODO item, remove
the XXX comments this patch removes, and plan not to add more trivial SPI
wrappers. If consensus goes otherwise, I think we should at least introduce
SPI_getcollation() at the same time. Code that needs to transfer one of them
very often needs to transfer the other. Having API coverage for just one
makes it easier for hackers to miss that.

Thanks,
nm

--
Noah Misch
EnterpriseDB http://www.enterprisedb.com


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: Mark Wong <markwkm(at)gmail(dot)com>, Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Chetan Suttraway <chetan(dot)suttraway(at)enterprisedb(dot)com>
Subject: Re: Re: [Review] Add SPI_gettypmod() to return a field's typemod from a TupleDesc
Date: 2013-07-08 00:55:01
Message-ID: 1373244901.12837.29.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, 2013-07-07 at 20:15 -0400, Noah Misch wrote:
> I mildly recommend we reject this patch as such, remove the TODO item,
> remove
> the XXX comments this patch removes, and plan not to add more trivial
> SPI
> wrappers. If consensus goes otherwise, I think we should at least
> introduce
> SPI_getcollation() at the same time. Code that needs to transfer one
> of them
> very often needs to transfer the other. Having API coverage for just
> one
> makes it easier for hackers to miss that.

The question is, what would one do with those values? It's hard to see
when you would need the typmod and the collation of a result set. There
might be cases, but enough to provide a special API for it?


From: Noah Misch <noah(at)leadboat(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Mark Wong <markwkm(at)gmail(dot)com>, Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: [Review] Add SPI_gettypmod() to return a field's typemod from a TupleDesc
Date: 2013-07-08 01:28:34
Message-ID: 20130708012834.GA1151026@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Jul 07, 2013 at 08:55:01PM -0400, Peter Eisentraut wrote:
> On Sun, 2013-07-07 at 20:15 -0400, Noah Misch wrote:
> > I mildly recommend we reject this patch as such, remove the TODO item,
> > remove
> > the XXX comments this patch removes, and plan not to add more trivial
> > SPI
> > wrappers. If consensus goes otherwise, I think we should at least
> > introduce
> > SPI_getcollation() at the same time. Code that needs to transfer one
> > of them
> > very often needs to transfer the other. Having API coverage for just
> > one
> > makes it easier for hackers to miss that.
>
> The question is, what would one do with those values? It's hard to see
> when you would need the typmod and the collation of a result set. There
> might be cases, but enough to provide a special API for it?

Good point. One of the ways PL/pgSQL uses it is to feed a result datum back
into a future query as a Param node.

--
Noah Misch
EnterpriseDB http://www.enterprisedb.com


From: Noah Misch <noah(at)leadboat(dot)com>
To: Mark Wong <markwkm(at)gmail(dot)com>
Cc: Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Chetan Suttraway <chetan(dot)suttraway(at)enterprisedb(dot)com>
Subject: Re: [Review] Add SPI_gettypmod() to return a field's typemod from a TupleDesc / audit of [E] TODO items
Date: 2013-07-12 23:29:54
Message-ID: 20130712232954.GA1193058@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Jul 07, 2013 at 08:15:00PM -0400, Noah Misch wrote:
> I mildly recommend we reject this patch as such, remove the TODO item, remove
> the XXX comments this patch removes, and plan not to add more trivial SPI
> wrappers.

Seeing just the one response consistent with that view, done.

--
Noah Misch
EnterpriseDB http://www.enterprisedb.com


From: Mark Wong <markwkm(at)gmail(dot)com>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [Review] Add SPI_gettypmod() to return a field's typemod from a TupleDesc / audit of [E] TODO items
Date: 2013-07-12 23:42:13
Message-ID: D07EC920-D6F8-4949-B40C-9225C940214A@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Jul 12, 2013, at 4:29 PM, Noah Misch <noah(at)leadboat(dot)com> wrote:

> On Sun, Jul 07, 2013 at 08:15:00PM -0400, Noah Misch wrote:
>> I mildly recommend we reject this patch as such, remove the TODO item, remove
>> the XXX comments this patch removes, and plan not to add more trivial SPI
>> wrappers.
>
> Seeing just the one response consistent with that view, done.

Shucks. :) Thanks for reviewing everyone.

Regards,
Mark