Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9de2cc4

Browse files
committed
Fix confusion about data type of pg_class.relpages and relallvisible.
Although they're exposed as int4 in pg_class, relpages andrelallvisible are really of type BlockNumber, that is uint32.Correct type puns in relation_statistics_update() and removeinappropriate range-checks. The type puns are only cosmeticissues, but the range checks would cause failures with hugerelations.Reported-by: Tom Lane <tgl@sss.pgh.pa.us>Author: Corey Huinker <corey.huinker@gmail.com>Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/614341.1740269035@sss.pgh.pa.us
1 parente889422 commit9de2cc4

File tree

1 file changed

+13
-40
lines changed

1 file changed

+13
-40
lines changed

‎src/backend/statistics/relation_stats.c

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
#include"utils/fmgrprotos.h"
2525
#include"utils/syscache.h"
2626

27-
#defineDEFAULT_RELPAGES Int32GetDatum(0)
28-
#defineDEFAULT_RELTUPLES Float4GetDatum(-1.0)
29-
#defineDEFAULT_RELALLVISIBLE Int32GetDatum(0)
3027

3128
/*
3229
* Positional argument numbers, names, and types for
@@ -60,40 +57,25 @@ static bool relation_statistics_update(FunctionCallInfo fcinfo, int elevel,
6057
staticbool
6158
relation_statistics_update(FunctionCallInfofcinfo,intelevel,boolinplace)
6259
{
60+
boolresult= true;
6361
Oidreloid;
6462
Relationcrel;
65-
int32relpages=DEFAULT_RELPAGES;
63+
BlockNumberrelpages=0;
6664
boolupdate_relpages= false;
67-
floatreltuples=DEFAULT_RELTUPLES;
65+
floatreltuples=0;
6866
boolupdate_reltuples= false;
69-
int32relallvisible=DEFAULT_RELALLVISIBLE;
67+
BlockNumberrelallvisible=0;
7068
boolupdate_relallvisible= false;
71-
boolresult= true;
7269

7370
if (!PG_ARGISNULL(RELPAGES_ARG))
7471
{
75-
relpages=PG_GETARG_INT32(RELPAGES_ARG);
76-
77-
/*
78-
* Partitioned tables may have relpages=-1. Note: for relations with
79-
* no storage, relpages=-1 is not used consistently, but must be
80-
* supported here.
81-
*/
82-
if (relpages<-1)
83-
{
84-
ereport(elevel,
85-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
86-
errmsg("relpages cannot be < -1")));
87-
result= false;
88-
}
89-
else
90-
update_relpages= true;
72+
relpages=PG_GETARG_UINT32(RELPAGES_ARG);
73+
update_relpages= true;
9174
}
9275

9376
if (!PG_ARGISNULL(RELTUPLES_ARG))
9477
{
9578
reltuples=PG_GETARG_FLOAT4(RELTUPLES_ARG);
96-
9779
if (reltuples<-1.0)
9880
{
9981
ereport(elevel,
@@ -107,17 +89,8 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel, bool inplace)
10789

10890
if (!PG_ARGISNULL(RELALLVISIBLE_ARG))
10991
{
110-
relallvisible=PG_GETARG_INT32(RELALLVISIBLE_ARG);
111-
112-
if (relallvisible<0)
113-
{
114-
ereport(elevel,
115-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
116-
errmsg("relallvisible cannot be < 0")));
117-
result= false;
118-
}
119-
else
120-
update_relallvisible= true;
92+
relallvisible=PG_GETARG_UINT32(RELALLVISIBLE_ARG);
93+
update_relallvisible= true;
12194
}
12295

12396
stats_check_required_arg(fcinfo,relarginfo,RELATION_ARG);
@@ -201,7 +174,7 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel, bool inplace)
201174
if (update_relpages&&relpages!=pgcform->relpages)
202175
{
203176
replaces[nreplaces]=Anum_pg_class_relpages;
204-
values[nreplaces]=Int32GetDatum(relpages);
177+
values[nreplaces]=UInt32GetDatum(relpages);
205178
nreplaces++;
206179
}
207180

@@ -215,7 +188,7 @@ relation_statistics_update(FunctionCallInfo fcinfo, int elevel, bool inplace)
215188
if (update_relallvisible&&relallvisible!=pgcform->relallvisible)
216189
{
217190
replaces[nreplaces]=Anum_pg_class_relallvisible;
218-
values[nreplaces]=Int32GetDatum(relallvisible);
191+
values[nreplaces]=UInt32GetDatum(relallvisible);
219192
nreplaces++;
220193
}
221194

@@ -263,11 +236,11 @@ pg_clear_relation_stats(PG_FUNCTION_ARGS)
263236

264237
newfcinfo->args[0].value=PG_GETARG_OID(0);
265238
newfcinfo->args[0].isnull=PG_ARGISNULL(0);
266-
newfcinfo->args[1].value=DEFAULT_RELPAGES;
239+
newfcinfo->args[1].value=UInt32GetDatum(0);
267240
newfcinfo->args[1].isnull= false;
268-
newfcinfo->args[2].value=DEFAULT_RELTUPLES;
241+
newfcinfo->args[2].value=Float4GetDatum(-1.0);
269242
newfcinfo->args[2].isnull= false;
270-
newfcinfo->args[3].value=DEFAULT_RELALLVISIBLE;
243+
newfcinfo->args[3].value=UInt32GetDatum(0);
271244
newfcinfo->args[3].isnull= false;
272245

273246
relation_statistics_update(newfcinfo,ERROR, false);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp