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

Commit691e8b2

Browse files
pageinspect: Fix types used for bt_metap() columns.
The data types that contrib/pageinspect's bt_metap() function weredeclared to return as OUT arguments were wrong in some cases. Forexample, the oldest_xact column (a TransactionId/xid field) was declaredinteger/int4 within the pageinspect extension's sql file. This led toerrors when an oldest_xact value that exceeded 2^31-1 was encountered.Some of the other columns were defined incorrectly ever sincepageinspect was first introduced, though they were far less likely toproduce problems in practice.Fix these issues by changing the declaration of bt_metap() toconsistently use data types that can reliably represent all possiblevalues. This fixes things on HEAD only. No backpatch, since it doesn'tseem like there is a safe way to fix the issue without including a newversion of the pageinspect extension (HEAD/Postgres 13 alreadyintroduced a new version of the extension). Besides, the oldest_xactissue has been around since the release of Postgres 11, and we haven'theard any complaints about it before now.Also, throw an error when we detect a bt_metap() declaration that mustbe from an old version of the pageinspect extension by examining thenumber of attributes from the tuple descriptor for the return tuples.It seems better to throw an error in a reliable and obvious wayfollowing a Postgres upgrade, rather than letting bt_metap() failunpredictably. The problem is fundamentally with the CREATE FUNCTIONdeclared data types themselves, so I see no sensible alternative.Reported-By: Victor YegorovBug: #16285Discussion:https://postgr.es/m/16285-df8fc1000ab3d5fc@postgresql.org
1 parentb9c3de6 commit691e8b2

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

‎contrib/pageinspect/btreefuncs.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,8 @@ bt_page_items_bytea(PG_FUNCTION_ARGS)
597597
}
598598
}
599599

600+
/* Number of output arguments (columns) for bt_metap() */
601+
#defineBT_METAP_COLS_V1_89
600602

601603
/* ------------------------------------------------
602604
* bt_metap()
@@ -653,13 +655,30 @@ bt_metap(PG_FUNCTION_ARGS)
653655
if (get_call_result_type(fcinfo,NULL,&tupleDesc)!=TYPEFUNC_COMPOSITE)
654656
elog(ERROR,"return type must be a row type");
655657

658+
/*
659+
* We need a kluge here to detect API versions prior to 1.8. Earlier
660+
* versions incorrectly used int4 for certain columns. This caused
661+
* various problems. For example, an int4 version of the "oldest_xact"
662+
* column would not work with TransactionId values that happened to exceed
663+
* PG_INT32_MAX.
664+
*
665+
* There is no way to reliably avoid the problems created by the old
666+
* function definition at this point, so insist that the user update the
667+
* extension.
668+
*/
669+
if (tupleDesc->natts<BT_METAP_COLS_V1_8)
670+
ereport(ERROR,
671+
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
672+
errmsg("function has wrong number of declared columns"),
673+
errhint("To resolve the problem, update the \"pageinspect\" extension to the latest version.")));
674+
656675
j=0;
657676
values[j++]=psprintf("%d",metad->btm_magic);
658677
values[j++]=psprintf("%d",metad->btm_version);
659-
values[j++]=psprintf("%d",metad->btm_root);
660-
values[j++]=psprintf("%d",metad->btm_level);
661-
values[j++]=psprintf("%d",metad->btm_fastroot);
662-
values[j++]=psprintf("%d",metad->btm_fastlevel);
678+
values[j++]=psprintf(INT64_FORMAT, (int64)metad->btm_root);
679+
values[j++]=psprintf(INT64_FORMAT, (int64)metad->btm_level);
680+
values[j++]=psprintf(INT64_FORMAT, (int64)metad->btm_fastroot);
681+
values[j++]=psprintf(INT64_FORMAT, (int64)metad->btm_fastlevel);
663682

664683
/*
665684
* Get values of extended metadata if available, use default values

‎contrib/pageinspect/pageinspect--1.7--1.8.sql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ DROP FUNCTION bt_metap(text);
2222
CREATEFUNCTIONbt_metap(IN relnametext,
2323
OUT magic int4,
2424
OUT version int4,
25-
OUT rootint4,
26-
OUT levelint4,
27-
OUT fastrootint4,
28-
OUT fastlevelint4,
29-
OUT oldest_xactint4,
30-
OUT last_cleanup_num_tuplesreal,
25+
OUT rootint8,
26+
OUT levelint8,
27+
OUT fastrootint8,
28+
OUT fastlevelint8,
29+
OUT oldest_xactxid,
30+
OUT last_cleanup_num_tuplesfloat8,
3131
OUT allequalimageboolean)
3232
AS'MODULE_PATHNAME','bt_metap'
3333
LANGUAGE C STRICT PARALLEL SAFE;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp