Re: pg_partition_tree crashes for a non-defined relation

2019-03-04 Thread Michael Paquier
On Mon, Mar 04, 2019 at 03:56:00PM -0300, Alvaro Herrera wrote: > I added tests to immortalize the current behavior for legacy inheritance > relations too. Thanks! Makes sense, thanks. -- Michael signature.asc Description: PGP signature

Re: pg_partition_tree crashes for a non-defined relation

2019-03-04 Thread Alvaro Herrera
On 2019-Feb-28, Alvaro Herrera wrote: > What about legacy inheritance? I see that pg_partition_tree handles > that case perfectly well -- it seems to return the complete hierarchy > rooted at the given relation. However, it seems odd that it works at > all, don't you think? Consider this: > [..

Re: pg_partition_tree crashes for a non-defined relation

2019-03-03 Thread Michael Paquier
On Mon, Mar 04, 2019 at 10:44:10AM +0900, Amit Langote wrote: > Thanks for committing and adding me as an author. Sure. A good portion of the changes suggested on the backend was mainly yours, so that looked right to me. -- Michael signature.asc Description: PGP signature

Re: pg_partition_tree crashes for a non-defined relation

2019-03-03 Thread Amit Langote
On 2019/03/02 18:21, Michael Paquier wrote: > On Fri, Mar 01, 2019 at 11:38:20AM -0500, Tom Lane wrote: >> Right, while you'd get zero rows out for a non-partitioned table. >> WFM. > > Exactly. I have committed a patch doing exactly that, and I have > added test cases with a partitioned table and

Re: pg_partition_tree crashes for a non-defined relation

2019-03-02 Thread Michael Paquier
On Fri, Mar 01, 2019 at 11:38:20AM -0500, Tom Lane wrote: > Right, while you'd get zero rows out for a non-partitioned table. > WFM. Exactly. I have committed a patch doing exactly that, and I have added test cases with a partitioned table and a partitioned index which have no partitions. -- Mic

Re: pg_partition_tree crashes for a non-defined relation

2019-03-01 Thread Tom Lane
Michael Paquier writes: > On Thu, Feb 28, 2019 at 11:50:16PM -0500, Tom Lane wrote: >> But, having said that, we've learned that it's generally bad for >> catalog-query functions to fail outright just because they're pointed >> at the wrong kind of catalog object. So I think that what we want her

Re: pg_partition_tree crashes for a non-defined relation

2019-02-28 Thread Michael Paquier
On Thu, Feb 28, 2019 at 11:50:16PM -0500, Tom Lane wrote: > FWIW, I don't agree with Michael's suggestion above. A plain table is > significantly different from a partitioned table with no children: > you can store rows in the former but not the latter, and you can add > partitions to the latter b

Re: pg_partition_tree crashes for a non-defined relation

2019-02-28 Thread Tom Lane
Amit Langote writes: > On 2019/03/01 9:22, Michael Paquier wrote: >> What I am writing next sounds perhaps a bit fancy, but in my opinion a >> normal table is itself a partition tree, made of one single member: >> itself. > That's what we discussed, but it seems that we ended up allowing regular

Re: pg_partition_tree crashes for a non-defined relation

2019-02-28 Thread Amit Langote
Hi, On 2019/03/01 9:22, Michael Paquier wrote: > On Thu, Feb 28, 2019 at 04:32:03PM -0300, Alvaro Herrera wrote: >> Yeah, looks good, please push. > > Done for this part. > >> I would opt for returning the empty set for legacy inheritance too. >> >> More generally, I think we should return empty

Re: pg_partition_tree crashes for a non-defined relation

2019-02-28 Thread Michael Paquier
On Thu, Feb 28, 2019 at 04:32:03PM -0300, Alvaro Herrera wrote: > Yeah, looks good, please push. Done for this part. > I would opt for returning the empty set for legacy inheritance too. > > More generally, I think we should return empty for anything that's > either not RELKIND_PARTITIONED_TABLE

Re: pg_partition_tree crashes for a non-defined relation

2019-02-28 Thread Alvaro Herrera
On 2019-Feb-28, Michael Paquier wrote: > On Wed, Feb 27, 2019 at 03:48:08PM -0300, Alvaro Herrera wrote: > > I just happened to come across the result of this rationale in > > pg_partition_tree() (an SRF) while developing a new related function, > > pg_partition_ancestors(), and find the resulting

Re: pg_partition_tree crashes for a non-defined relation

2019-02-27 Thread Amit Langote
Hi, On 2019/02/28 10:45, Michael Paquier wrote: > On Wed, Feb 27, 2019 at 03:48:08PM -0300, Alvaro Herrera wrote: >> I just happened to come across the result of this rationale in >> pg_partition_tree() (an SRF) while developing a new related function, >> pg_partition_ancestors(), and find the res

Re: pg_partition_tree crashes for a non-defined relation

2019-02-27 Thread Michael Paquier
On Wed, Feb 27, 2019 at 03:48:08PM -0300, Alvaro Herrera wrote: > I just happened to come across the result of this rationale in > pg_partition_tree() (an SRF) while developing a new related function, > pg_partition_ancestors(), and find the resulting behavior rather absurd > -- it returns one row

Re: pg_partition_tree crashes for a non-defined relation

2019-02-27 Thread Alvaro Herrera
On 2018-Dec-09, Tom Lane wrote: > Stephen Frost writes: > > * Tom Lane (t...@sss.pgh.pa.us) wrote: > >> ... especially in code that's highly unlikely to break once written. > > > I don't entirely buy off on the argument that it's code that's 'highly > > unlikely to break once written' though- we

Re: pg_partition_tree crashes for a non-defined relation

2018-12-13 Thread Michael Paquier
On Thu, Dec 13, 2018 at 03:34:56PM +0900, Amit Langote wrote: > Thank you Michael for taking care of this. I agree with the consensus > that instead of throwing an error for unsupported relkinds, > pg_partition_tree should rather return single row containing NULL for all > columns. Cool, thanks f

Re: pg_partition_tree crashes for a non-defined relation

2018-12-12 Thread Amit Langote
On 2018/12/12 9:52, Michael Paquier wrote: > On Mon, Dec 10, 2018 at 10:52:37PM +0900, Michael Paquier wrote: >> OK. Sure, let's do as you suggest then. I'll wait a couple of days >> before committing the patch so as if someone has extra comments they >> have the time to post. So please feel fre

Re: pg_partition_tree crashes for a non-defined relation

2018-12-11 Thread Michael Paquier
On Mon, Dec 10, 2018 at 10:52:37PM +0900, Michael Paquier wrote: > OK. Sure, let's do as you suggest then. I'll wait a couple of days > before committing the patch so as if someone has extra comments they > have the time to post. So please feel free to comment! And done this way. Thanks for th

Re: pg_partition_tree crashes for a non-defined relation

2018-12-10 Thread Michael Paquier
On Mon, Dec 10, 2018 at 08:21:43AM -0500, Stephen Frost wrote: > * Michael Paquier (mich...@paquier.xyz) wrote: >> This still looks adapted to me. Or would you reword it because "allow" >> rather implies that an ERROR is returned? Would you prefer changing it >> something like that perhaps: >> "R

Re: pg_partition_tree crashes for a non-defined relation

2018-12-10 Thread Stephen Frost
Greetings, * Michael Paquier (mich...@paquier.xyz) wrote: > On Sun, Dec 09, 2018 at 12:49:18PM -0500, Stephen Frost wrote: > > Looks alright on a quick glance, but shouldn't you also update the > > comment..? > > The comment on HEAD or with the patch is that: > /* Only allow relation types th

Re: pg_partition_tree crashes for a non-defined relation

2018-12-10 Thread Stephen Frost
Greetings, * Michael Paquier (mich...@paquier.xyz) wrote: > On Sun, Dec 09, 2018 at 02:07:29PM -0500, Tom Lane wrote: > > Stephen Frost writes: > >> I don't entirely buy off on the argument that it's code that's 'highly > >> unlikely to break once written' though- we do add new relkinds from time

Re: pg_partition_tree crashes for a non-defined relation

2018-12-09 Thread Michael Paquier
On Sun, Dec 09, 2018 at 12:49:18PM -0500, Stephen Frost wrote: > Looks alright on a quick glance, but shouldn't you also update the > comment..? The comment on HEAD or with the patch is that: /* Only allow relation types that can appear in partition trees. */ This still looks adapted to me.

Re: pg_partition_tree crashes for a non-defined relation

2018-12-09 Thread Michael Paquier
On Sun, Dec 09, 2018 at 02:07:29PM -0500, Tom Lane wrote: > Stephen Frost writes: >> I don't entirely buy off on the argument that it's code that's 'highly >> unlikely to break once written' though- we do add new relkinds from time >> to time, for example. Perhaps we could have these functions ru

Re: pg_partition_tree crashes for a non-defined relation

2018-12-09 Thread Tom Lane
Stephen Frost writes: > * Tom Lane (t...@sss.pgh.pa.us) wrote: >> ... especially in code that's highly unlikely to break once written. > I don't entirely buy off on the argument that it's code that's 'highly > unlikely to break once written' though- we do add new relkinds from time > to time, for

Re: pg_partition_tree crashes for a non-defined relation

2018-12-09 Thread Stephen Frost
Greetings, * Tom Lane (t...@sss.pgh.pa.us) wrote: > Stephen Frost writes: > > * Michael Paquier (mich...@paquier.xyz) wrote: > >> On Sat, Dec 08, 2018 at 08:46:08AM -0500, Stephen Frost wrote: > >>> I wonder if we maybe should have a regression test for every such > >>> function which just querie

Re: pg_partition_tree crashes for a non-defined relation

2018-12-09 Thread Tom Lane
Stephen Frost writes: > * Michael Paquier (mich...@paquier.xyz) wrote: >> On Sat, Dec 08, 2018 at 08:46:08AM -0500, Stephen Frost wrote: >>> I wonder if we maybe should have a regression test for every such >>> function which just queries the catalog in a way to force the function >>> to be called

Re: pg_partition_tree crashes for a non-defined relation

2018-12-09 Thread Stephen Frost
Greetings, * Michael Paquier (mich...@paquier.xyz) wrote: > On Sun, Dec 09, 2018 at 08:15:07AM +0900, Michael Paquier wrote: > > On Sat, Dec 08, 2018 at 08:46:08AM -0500, Stephen Frost wrote: > >> We should really have a more clearly defined policy around this, but my > >> recollection is that we

Re: pg_partition_tree crashes for a non-defined relation

2018-12-09 Thread Stephen Frost
Greetings, * Michael Paquier (mich...@paquier.xyz) wrote: > On Sat, Dec 08, 2018 at 08:46:08AM -0500, Stephen Frost wrote: > > I wonder if we maybe should have a regression test for every such > > function which just queries the catalog in a way to force the function > > to be called for every rel

Re: pg_partition_tree crashes for a non-defined relation

2018-12-08 Thread Michael Paquier
On Sun, Dec 09, 2018 at 08:15:07AM +0900, Michael Paquier wrote: > On Sat, Dec 08, 2018 at 08:46:08AM -0500, Stephen Frost wrote: >> We should really have a more clearly defined policy around this, but my >> recollection is that we often prefer to return NULL rather than throwing >> an error for th

Re: pg_partition_tree crashes for a non-defined relation

2018-12-08 Thread Michael Paquier
On Sat, Dec 08, 2018 at 08:46:08AM -0500, Stephen Frost wrote: > We should really have a more clearly defined policy around this, but my > recollection is that we often prefer to return NULL rather than throwing > an error for the convenience of people doing things like querying > pg_class using si

Re: pg_partition_tree crashes for a non-defined relation

2018-12-08 Thread Stephen Frost
Greetings, * Michael Paquier (mich...@paquier.xyz) wrote: > On Fri, Dec 07, 2018 at 11:33:32PM -0500, Tom Lane wrote: > > How about cases where the relation OID exists but it's the wrong > > kind of relation? > > Such cases already return an error: > =# create sequence popo; > CREATE SEQUENCE > =

Re: pg_partition_tree crashes for a non-defined relation

2018-12-07 Thread Michael Paquier
On Fri, Dec 07, 2018 at 11:33:32PM -0500, Tom Lane wrote: > How about cases where the relation OID exists but it's the wrong > kind of relation? Such cases already return an error: =# create sequence popo; CREATE SEQUENCE =# select pg_partition_tree('popo'); ERROR: 42809: "popo" is not a table, a

Re: pg_partition_tree crashes for a non-defined relation

2018-12-07 Thread Tom Lane
Michael Paquier writes: > On Fri, Dec 07, 2018 at 10:04:06AM +0900, Michael Paquier wrote: >> I think that we should make the function return NULL if the relation >> defined does not exist, as we usually do for system-facing functions. >> It is also easier for the caller to know that the relation

Re: pg_partition_tree crashes for a non-defined relation

2018-12-07 Thread Michael Paquier
On Sat, Dec 08, 2018 at 12:28:53PM +0900, Amit Langote wrote: > Thanks for noticing it and creating the patch. The fix makes sense. Thanks a lot for looking at it! -- Michael signature.asc Description: PGP signature

Re: pg_partition_tree crashes for a non-defined relation

2018-12-07 Thread Amit Langote
Hi, Sorry for not replying sooner. On Sat, Dec 8, 2018 at 8:06 Michael Paquier wrote: > On Fri, Dec 07, 2018 at 10:04:06AM +0900, Michael Paquier wrote: > > While testing another patch, I have bumped into the issue of > > $subject... I should have put some more negative testing from the start

Re: pg_partition_tree crashes for a non-defined relation

2018-12-07 Thread Michael Paquier
On Fri, Dec 07, 2018 at 10:04:06AM +0900, Michael Paquier wrote: > While testing another patch, I have bumped into the issue of > $subject... I should have put some more negative testing from the start > on this stuff, here is a culprit query when passing directly an OID: > select pg_partition_tre

pg_partition_tree crashes for a non-defined relation

2018-12-06 Thread Michael Paquier
Hi all, While testing another patch, I have bumped into the issue of $subject... I should have put some more negative testing from the start on this stuff, here is a culprit query when passing directly an OID: select pg_partition_tree(0); I think that we should make the function return NULL if t