From: Michael Paquier <michael@paquier.xyz>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Stephen Frost <sfrost@snowman.net>
Cc: Postgres hackers <pgsql-hackers@postgresql.org>
Cc: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
Subject: Re: pg_partition_tree crashes for a non-defined relation
Date: Thu, 28 Feb 2019 10:45:49 +0900
Message-ID: <20190228014549.GD1617@paquier.xyz> (raw)
In-Reply-To: <20190227184808.GA17357@alvherre.pgsql>
References: <19520.1544382449@sss.pgh.pa.us>
<20190227184808.GA17357@alvherre.pgsql>
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.
Does the attached look fine to you?
--
Michael
Attachments:
[text/x-diff] partition-tree-srf.patch (1.9K, ../20190228014549.GD1617@paquier.xyz/2-partition-tree-srf.patch)
download | inline diff:diff --git a/src/backend/utils/adt/partitionfuncs.c b/src/backend/utils/adt/partitionfuncs.cindex ffd66b6439..36d9f69cbc 100644--- a/src/backend/utils/adt/partitionfuncs.c+++ b/src/backend/utils/adt/partitionfuncs.c@@ -69,9 +69,6 @@ pg_partition_tree(PG_FUNCTION_ARGS)
FuncCallContext *funcctx;
ListCell **next;
- if (!check_rel_can_be_partition(rootrelid))- PG_RETURN_NULL();-
/* stuff done only on the first call of the function */
if (SRF_IS_FIRSTCALL())
{
@@ -82,6 +79,9 @@ pg_partition_tree(PG_FUNCTION_ARGS)
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
+ if (!check_rel_can_be_partition(rootrelid))+ SRF_RETURN_DONE(funcctx);+
/* switch to memory context appropriate for multiple function calls */
oldcxt = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
diff --git a/src/test/regress/expected/partition_info.out b/src/test/regress/expected/partition_info.outindex a884df976f..73269ffd09 100644--- a/src/test/regress/expected/partition_info.out+++ b/src/test/regress/expected/partition_info.out@@ -9,8 +9,7 @@ SELECT * FROM pg_partition_tree(NULL);
SELECT * FROM pg_partition_tree(0);
relid | parentrelid | isleaf | level
-------+-------------+--------+-------
- | | | -(1 row)+(0 rows)
SELECT pg_partition_root(NULL);
pg_partition_root
@@ -163,14 +162,12 @@ CREATE MATERIALIZED VIEW ptif_test_matview AS SELECT 1;
SELECT * FROM pg_partition_tree('ptif_test_view');
relid | parentrelid | isleaf | level
-------+-------------+--------+-------
- | | | -(1 row)+(0 rows)
SELECT * FROM pg_partition_tree('ptif_test_matview');
relid | parentrelid | isleaf | level
-------+-------------+--------+-------
- | | | -(1 row)+(0 rows)
SELECT pg_partition_root('ptif_test_view');
pg_partition_root
[application/pgp-signature] signature.asc (832B, ../20190228014549.GD1617@paquier.xyz/3-signature.asc)
download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: michael@paquier.xyz, alvherre@2ndquadrant.com, tgl@sss.pgh.pa.us, sfrost@snowman.net, Langote_Amit_f8@lab.ntt.co.jp
Subject: Re: pg_partition_tree crashes for a non-defined relation
In-Reply-To: <20190228014549.GD1617@paquier.xyz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox