v3-0002-Change-pg_set_relation_stats-return-type-to-void.patch
text/x-patch
Filename: v3-0002-Change-pg_set_relation_stats-return-type-to-void.patch
Type: text/x-patch
Part: 1
Message:
Re: Statistics Import and Export
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v3-0002
Subject: Change pg_set_relation_stats() return type to void.
| File | + | − |
|---|---|---|
| doc/src/sgml/func.sgml | 4 | 7 |
| src/backend/catalog/system_functions.sql | 1 | 1 |
| src/backend/statistics/relation_stats.c | 4 | 2 |
| src/include/catalog/pg_proc.dat | 2 | 2 |
| src/test/regress/expected/stats_import.out | 8 | 8 |
From b36976de8d2e5a797eb48859ef597d8c157e8a3e Mon Sep 17 00:00:00 2001
From: Corey Huinker <corey.huinker@gmail.com>
Date: Fri, 18 Oct 2024 19:06:13 -0400
Subject: [PATCH v3 2/2] Change pg_set_relation_stats() return type to void.
This function will either raise an ERROR or run to normal completion.
The boolean return value of relation_statistics_update() is preserved,
but that is useful for more nuanced future uses than
pg_set_relation_stats().
---
src/include/catalog/pg_proc.dat | 4 ++--
src/backend/catalog/system_functions.sql | 2 +-
src/backend/statistics/relation_stats.c | 6 ++++--
src/test/regress/expected/stats_import.out | 16 ++++++++--------
doc/src/sgml/func.sgml | 11 ++++-------
5 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 7c0b74fe05..b4430e7c77 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -12345,14 +12345,14 @@
{ oid => '9944',
descr => 'set statistics on relation',
proname => 'pg_set_relation_stats', provolatile => 'v', proisstrict => 'f',
- proparallel => 'u', prorettype => 'bool',
+ proparallel => 'u', prorettype => 'void',
proargtypes => 'regclass int4 float4 int4',
proargnames => '{relation,relpages,reltuples,relallvisible}',
prosrc => 'pg_set_relation_stats' },
{ oid => '9945',
descr => 'clear statistics on relation',
proname => 'pg_clear_relation_stats', provolatile => 'v', proisstrict => 'f',
- proparallel => 'u', prorettype => 'bool',
+ proparallel => 'u', prorettype => 'void',
proargtypes => 'regclass',
proargnames => '{relation}',
prosrc => 'pg_clear_relation_stats' },
diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql
index 92b6aefe7a..b7e2906f11 100644
--- a/src/backend/catalog/system_functions.sql
+++ b/src/backend/catalog/system_functions.sql
@@ -644,7 +644,7 @@ CREATE OR REPLACE FUNCTION
relpages integer DEFAULT NULL,
reltuples real DEFAULT NULL,
relallvisible integer DEFAULT NULL)
-RETURNS bool
+RETURNS void
LANGUAGE INTERNAL
CALLED ON NULL INPUT VOLATILE
AS 'pg_set_relation_stats';
diff --git a/src/backend/statistics/relation_stats.c b/src/backend/statistics/relation_stats.c
index 126eab49d8..7c6ae4ecd8 100644
--- a/src/backend/statistics/relation_stats.c
+++ b/src/backend/statistics/relation_stats.c
@@ -179,7 +179,8 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel)
Datum
pg_set_relation_stats(PG_FUNCTION_ARGS)
{
- PG_RETURN_BOOL(relation_statistics_update(fcinfo, ERROR));
+ relation_statistics_update(fcinfo, ERROR);
+ PG_RETURN_VOID();
}
/*
@@ -202,5 +203,6 @@ pg_clear_relation_stats(PG_FUNCTION_ARGS)
newfcinfo->args[3].value = DEFAULT_RELALLVISIBLE;
newfcinfo->args[3].isnull = false;
- PG_RETURN_BOOL(relation_statistics_update(newfcinfo, ERROR));
+ relation_statistics_update(newfcinfo, ERROR);
+ PG_RETURN_VOID();
}
diff --git a/src/test/regress/expected/stats_import.out b/src/test/regress/expected/stats_import.out
index a4e3a0f3c4..b50af75bb9 100644
--- a/src/test/regress/expected/stats_import.out
+++ b/src/test/regress/expected/stats_import.out
@@ -38,7 +38,7 @@ SELECT
relallvisible => 4::integer);
pg_set_relation_stats
-----------------------
- t
+
(1 row)
-- reltuples default
@@ -50,7 +50,7 @@ SELECT
relallvisible => 4::integer);
pg_set_relation_stats
-----------------------
- t
+
(1 row)
-- relallvisible default
@@ -62,7 +62,7 @@ SELECT
relallvisible => NULL::integer);
pg_set_relation_stats
-----------------------
- f
+
(1 row)
-- named arguments
@@ -74,7 +74,7 @@ SELECT
relallvisible => 4::integer);
pg_set_relation_stats
-----------------------
- f
+
(1 row)
SELECT relpages, reltuples, relallvisible
@@ -94,7 +94,7 @@ SELECT
5::integer);
pg_set_relation_stats
-----------------------
- t
+
(1 row)
SELECT relpages, reltuples, relallvisible
@@ -111,7 +111,7 @@ SELECT
'stats_import.test'::regclass);
pg_clear_relation_stats
-------------------------
- t
+
(1 row)
SELECT relpages, reltuples, relallvisible
@@ -158,7 +158,7 @@ SELECT
relpages => 2::integer);
pg_set_relation_stats
-----------------------
- t
+
(1 row)
-- nothing stops us from setting it to -1
@@ -168,7 +168,7 @@ SELECT
relpages => -1::integer);
pg_set_relation_stats
-----------------------
- t
+
(1 row)
DROP SCHEMA stats_import CASCADE;
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index ad663c94d7..14dd035134 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -30174,15 +30174,13 @@ DETAIL: Make sure pg_wal_replay_wait() isn't called within a transaction with a
<optional>, <parameter>relpages</parameter> <type>integer</type></optional>
<optional>, <parameter>reltuples</parameter> <type>real</type></optional>
<optional>, <parameter>relallvisible</parameter> <type>integer</type></optional> )
- <returnvalue>boolean</returnvalue>
+ <returnvalue>void</returnvalue>
</para>
<para>
Updates relation-level statistics for the given relation to the
specified values. The parameters correspond to columns in <link
linkend="catalog-pg-class"><structname>pg_class</structname></link>. Unspecified
- or <literal>NULL</literal> values leave the setting
- unchanged. Returns <literal>true</literal> if a change was made;
- <literal>false</literal> otherwise.
+ or <literal>NULL</literal> values leave the setting unchanged.
</para>
<para>
Ordinarily, these statistics are collected automatically or updated
@@ -30212,12 +30210,11 @@ DETAIL: Make sure pg_wal_replay_wait() isn't called within a transaction with a
<primary>pg_clear_relation_stats</primary>
</indexterm>
<function>pg_clear_relation_stats</function> ( <parameter>relation</parameter> <type>regclass</type> )
- <returnvalue>boolean</returnvalue>
+ <returnvalue>void</returnvalue>
</para>
<para>
Clears table-level statistics for the given relation, as though the
- table was newly created. Returns <literal>true</literal> if a change
- was made; <literal>false</literal> otherwise.
+ table was newly created.
</para>
<para>
The caller must have the <literal>MAINTAIN</literal> privilege on
--
2.47.0