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 1gz4Gm-0008CA-ET for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Feb 2019 18:49:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gz4Gl-00074i-1k for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Feb 2019 18:49:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gz4Gk-00074Z-M0 for pgsql-hackers@lists.postgresql.org; Wed, 27 Feb 2019 18:49:26 +0000 Received: from mail-qt1-x844.google.com ([2607:f8b0:4864:20::844]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gz4Gh-0008Uj-MH for pgsql-hackers@postgresql.org; Wed, 27 Feb 2019 18:49:26 +0000 Received: by mail-qt1-x844.google.com with SMTP id a48so20490764qtb.4 for ; Wed, 27 Feb 2019 10:49:23 -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=X7w2/tbRbi4sQRI61J0kc7c7cMGOGykf9h4lZbRIMeA=; b=ghWX0UQrHik3QzXCIdICbNjsP/0ERJGcXIh1vcZsVK6/TR7SzK58LG3sjS8aTvyyOS KoDQZIY7whiji+l0g2Cm6I5xGPVrFrAaV95XVsMYIUt+Wl+YPw8DNyS5znyADc8VCW/G 2Sx5MYgNxBrYdvAt4WXHegScfsqXJReDvLRy0IXmTQC/KbJiIvl975xqubQchxaPwJC0 7rNU+DkceB71WCt9fGR39DEzU7HiCmWW5xzlM+X7iFcEYj1h/BfH9zwZVSNDg5HYKg6m XPEnLzeR7gUOGuLOJspHB0RCW1yaOTIAvHS6kmzJnYo5MXQ+WaDRI68MLEPm6wX7C+GZ +HrA== 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=X7w2/tbRbi4sQRI61J0kc7c7cMGOGykf9h4lZbRIMeA=; b=kEYfTqt2Yoe13Xi2Pz0Pi4N5eoIR910/HBH6cRrrbPPm8zrXGlbPJX5evoxJp6VcYm vZV7TadcSsPniliZPXbmOK7L2R1SxFJCfGZE5FrPLd/K1C+heK0ZC+L7byUG38eiISwo L8iVqpAGkvCzWEPeUNZ3PZDNf9FInsHCzw0ysLlgM+CaN8TbbNb1n8dDm3793WxotWDw k1c7iI3q2eNoIAf7A87ypjaW2OETWGtj60MG1+Vxy3R6FOK6Te+BDaPZAsMdUM12PUVX tN9HTha7LXPABNNnOTngE9PKoHwJTwqNUWUsrdvLnsiUqOYFZ6QTuGabcFlhwlkVQ7MG MCoQ== X-Gm-Message-State: APjAAAVvM2t/SQoAGf7kWs89s+3RkFCgiruWXxM5CN7XIb2t+HNpl1zc lqt7oilRmkGLhmBnh3fclS3MVg== X-Google-Smtp-Source: APXvYqzaqLAPazESvq7vzIyU47Q2QvQvmQFD9cEeGoPFW11H55uzvez1Js3VhzaWHDMwWs5Qo61Qdw== X-Received: by 2002:a0c:95dd:: with SMTP id t29mr3164914qvt.174.1551293361745; Wed, 27 Feb 2019 10:49:21 -0800 (PST) Received: from nimloth.alvh.no-ip.org ([191.126.99.65]) by smtp.gmail.com with ESMTPSA id d50sm15410207qta.31.2019.02.27.10.49.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 27 Feb 2019 10:49:21 -0800 (PST) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 8580212475B; Wed, 27 Feb 2019 15:48:08 -0300 (-03) Date: Wed, 27 Feb 2019 15:48:08 -0300 From: Alvaro Herrera To: Tom Lane Cc: Stephen Frost , Michael Paquier , Postgres hackers , Amit Langote Subject: Re: pg_partition_tree crashes for a non-defined relation Message-ID: <20190227184808.GA17357@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <19520.1544382449@sss.pgh.pa.us> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2018-Dec-09, Tom Lane wrote: > Stephen Frost writes: > > * Tom Lane (tgl@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 example. Perhaps we could have these functions run just > > once per relkind. > > Well, the relevant code is likely to be "if relkind is not x, y, or z, > then PG_RETURN_NULL". If we add a new relkind and forget to consider the > function, the outcome is a NULL result that perhaps should not have been > NULL ... but a test like this won't help us notice that. 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. alvherre=# select * from pg_partition_tree('information_schema.sequences'); relid | parentrelid | isleaf | level -------+-------------+--------+------- | | | (1 fila) -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services