Commit 0f3cdf87 authored by Michael Paquier's avatar Michael Paquier

Make pg_partition_tree return no rows on unsupported and undefined objects

The function was tweaked so as it returned one row full of NULLs when
working on an unsupported relkind or an undefined object as of cc53123b,
and after discussion with Amit and Álvaro it looks more natural to make
it return no rows.

Author: Michael Paquier
Reviewed-by: Álvaro Herrera, Amit Langote
Discussion: https://postgr.es/m/20190227184808.GA17357@alvherre.pgsql
parent 25365511
...@@ -69,9 +69,6 @@ pg_partition_tree(PG_FUNCTION_ARGS) ...@@ -69,9 +69,6 @@ pg_partition_tree(PG_FUNCTION_ARGS)
FuncCallContext *funcctx; FuncCallContext *funcctx;
ListCell **next; ListCell **next;
if (!check_rel_can_be_partition(rootrelid))
PG_RETURN_NULL();
/* stuff done only on the first call of the function */ /* stuff done only on the first call of the function */
if (SRF_IS_FIRSTCALL()) if (SRF_IS_FIRSTCALL())
{ {
...@@ -82,6 +79,9 @@ pg_partition_tree(PG_FUNCTION_ARGS) ...@@ -82,6 +79,9 @@ pg_partition_tree(PG_FUNCTION_ARGS)
/* create a function context for cross-call persistence */ /* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT(); funcctx = SRF_FIRSTCALL_INIT();
if (!check_rel_can_be_partition(rootrelid))
SRF_RETURN_DONE(funcctx);
/* switch to memory context appropriate for multiple function calls */ /* switch to memory context appropriate for multiple function calls */
oldcxt = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); oldcxt = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
......
...@@ -9,8 +9,7 @@ SELECT * FROM pg_partition_tree(NULL); ...@@ -9,8 +9,7 @@ SELECT * FROM pg_partition_tree(NULL);
SELECT * FROM pg_partition_tree(0); SELECT * FROM pg_partition_tree(0);
relid | parentrelid | isleaf | level relid | parentrelid | isleaf | level
-------+-------------+--------+------- -------+-------------+--------+-------
| | | (0 rows)
(1 row)
SELECT pg_partition_root(NULL); SELECT pg_partition_root(NULL);
pg_partition_root pg_partition_root
...@@ -163,14 +162,12 @@ CREATE MATERIALIZED VIEW ptif_test_matview AS SELECT 1; ...@@ -163,14 +162,12 @@ CREATE MATERIALIZED VIEW ptif_test_matview AS SELECT 1;
SELECT * FROM pg_partition_tree('ptif_test_view'); SELECT * FROM pg_partition_tree('ptif_test_view');
relid | parentrelid | isleaf | level relid | parentrelid | isleaf | level
-------+-------------+--------+------- -------+-------------+--------+-------
| | | (0 rows)
(1 row)
SELECT * FROM pg_partition_tree('ptif_test_matview'); SELECT * FROM pg_partition_tree('ptif_test_matview');
relid | parentrelid | isleaf | level relid | parentrelid | isleaf | level
-------+-------------+--------+------- -------+-------------+--------+-------
| | | (0 rows)
(1 row)
SELECT pg_partition_root('ptif_test_view'); SELECT pg_partition_root('ptif_test_view');
pg_partition_root pg_partition_root
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment