Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzRRJ-0006xQ-8p for pgsql-hackers@arkaria.postgresql.org; Thu, 28 Feb 2019 19:33:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gzRRG-00036c-FG for pgsql-hackers@arkaria.postgresql.org; Thu, 28 Feb 2019 19:33:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzRRG-00033X-0v for pgsql-hackers@lists.postgresql.org; Thu, 28 Feb 2019 19:33:50 +0000 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzRRC-0002YW-DY for pgsql-hackers@postgresql.org; Thu, 28 Feb 2019 19:33:48 +0000 Received: by mail-qk1-x741.google.com with SMTP id c2so12098312qkb.3 for ; Thu, 28 Feb 2019 11:33:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=+aC34H8z8PNMJhJKZxe8Ji/nOoVgxq3sTiSRXzZ09nk=; b=G/mCPb5dVy/1iOA5257kx/Wa2Nf9RApSYoJ1qGPVxU1EJ2Zeu9pf8ZFLRK3zdQ4jLe pDSxBdn/2D+M2Uj+KR1lFyo+txM45faZR2oinyTIgPUT/6f5b0fCA6gUgxALYg1672lV b4gapOsnqg4BvpANicz6gJ76jaRNeZgKpzSs9VBqdjT5TWT3dZ+Dq0Iq3yXoJhBMIopb OaCl38RhzcKFwJUJgsLUq3DHn1eWnF1ylCrnZLC/bAPiDzfENy4ae8lJOYiu9vvXQWme j5B7wQ8xuj+S8Mril7I0zaJFkWWiRbqbW55NKtnomYcnGrDzZKmdOsuQn/y5PVU5R1in LG4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=+aC34H8z8PNMJhJKZxe8Ji/nOoVgxq3sTiSRXzZ09nk=; b=b6UAlbn5eJlW9JhqnxecE+/8sDVXIYhMbfMxgDBshiE0nl4XPlk6e5bnBtEs7etB2/ m3VaJEO1HjndnmSB1dlpZOQczrGjD05CQL6UY+D7U0afRQx35+NHF9UcmaZ+AnKozDzN opcRMXIUgQIPW8b0G3qeQFkhCMUX0/gngAmZ6QGd2G2zk8WSUACiNu78Tuw+TSWyVqhR tHi1XdHr1TpN4L2356qOKNPM7QJlK4kHFQ+GkZVufiekHkrK1Futz7OQESAhoTz74vJj OVq2lKvK0t3iL4vlLIINa+TwLYwJO4OwNBtx0Qg7MCcMCq6MY7lZM8uOJqcfDjSECYnh e8TA== X-Gm-Message-State: APjAAAW8NahWZ0buLq4p5pY+/MeTWCbIaEhJiqo0Vb1PcXYovoeGYIk4 dRxHgO01z9grlohFlerx/Dk0xA== X-Google-Smtp-Source: APXvYqwZFw09fiNEtYeNyWRBLikXS/0YZaq41+ClgYsM2ixDP7xBIZo1v0W3qd4MisduxvhFY/8nhA== X-Received: by 2002:a37:8107:: with SMTP id c7mr863261qkd.77.1551382425519; Thu, 28 Feb 2019 11:33:45 -0800 (PST) Received: from nimloth.alvh.no-ip.org ([191.125.99.90]) by smtp.gmail.com with ESMTPSA id p64sm4083457qkc.62.2019.02.28.11.33.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 11:33:44 -0800 (PST) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 572E3121373; Thu, 28 Feb 2019 16:32:03 -0300 (-03) Date: Thu, 28 Feb 2019 16:32:03 -0300 From: Alvaro Herrera To: Michael Paquier Cc: Tom Lane , Stephen Frost , Postgres hackers , Amit Langote Subject: Re: pg_partition_tree crashes for a non-defined relation Message-ID: <20190228193203.GA26151@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190228014549.GD1617@paquier.xyz> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 behavior rather absurd > > -- it returns one row with all NULL columns, rather than no rows. I > > think the sensible behavior would be to do SRF_RETURN_DONE() before > > stashing any rows to the output, so that we get an empty result set > > instead. > > Hmm. Going through the thread again NULL was decided to make the > whole experience consistent, now by returning nothing we would get > a behavior as consistent as when NULL is used in input, so point taken > to tune the behavior for unsupported relkinds and undefined objects. Right, thanks. > Does the attached look fine to you? Yeah, looks good, please push. 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: create table t1 (a int); create table t11 () inherits (t1); create table t2 (b int); create table t111() inherits (t1, t2); alvherre=# select * from pg_partition_tree('t1'); relid | parentrelid | isleaf | level -------+-------------+--------+------- t1 | t | t | 0 t11 | t1 | t | 1 t111 | t1 | t | 1 (3 filas) OK so far... but look at t2's tree: alvherre=# select * from pg_partition_tree('t2'); relid | parentrelid | isleaf | level -------+-------------+--------+------- t2 | t | t | 0 t111 | t1 | t | 2 I think this one is just weird -- t1 is not listed as "relid" anywhere, and why does t111 has level=2? 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 or has relispartition set. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services