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

Commit6736da5

Browse files
committed
Make the blkno arguments bigints instead of int4s. A signed int4 is not
large enough for block numbers higher than 2^31. The old pre-FSM-rewritepg_freespacemap implementation got this right. While we're at it, removesome unnecessary #includes.
1 parentf10a86e commit6736da5

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

‎contrib/pg_freespacemap/pg_freespacemap.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
* pg_freespacemap.c
44
* display contents of a free space map
55
*
6-
* $PostgreSQL: pgsql/contrib/pg_freespacemap/pg_freespacemap.c,v 1.11 2008/09/30 11:17:07 heikki Exp $
6+
* $PostgreSQL: pgsql/contrib/pg_freespacemap/pg_freespacemap.c,v 1.12 2008/10/02 12:20:50 heikki Exp $
77
*-------------------------------------------------------------------------
88
*/
99
#include"postgres.h"
1010

1111
#include"access/heapam.h"
12-
#include"access/htup.h"
13-
#include"catalog/pg_type.h"
1412
#include"funcapi.h"
13+
#include"storage/block.h"
1514
#include"storage/freespace.h"
16-
#include"utils/builtins.h"
1715

1816

1917
PG_MODULE_MAGIC;
@@ -31,13 +29,13 @@ Datum
3129
pg_freespace(PG_FUNCTION_ARGS)
3230
{
3331
Oidrelid=PG_GETARG_OID(0);
34-
uint32blkno=PG_GETARG_UINT32(1);
32+
int64blkno=PG_GETARG_INT64(1);
3533
int16freespace;
3634
Relationrel;
3735

3836
rel=relation_open(relid,AccessShareLock);
3937

40-
if (!BlockNumberIsValid(blkno))
38+
if (blkno<0||blkno>MaxBlockNumber)
4139
ereport(ERROR,
4240
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4341
errmsg("invalid block number")));
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
/* $PostgreSQL: pgsql/contrib/pg_freespacemap/pg_freespacemap.sql.in,v 1.10 2008/09/30 11:17:07 heikki Exp $ */
1+
/* $PostgreSQL: pgsql/contrib/pg_freespacemap/pg_freespacemap.sql.in,v 1.11 2008/10/02 12:20:50 heikki Exp $ */
22

33
-- Adjust this setting to control where the objects get created.
44
SET search_path = public;
55

66

77
-- Register the C function.
8-
CREATE OR REPLACE FUNCTION pg_freespace(regclass,int4)
8+
CREATE OR REPLACE FUNCTION pg_freespace(regclass,bigint)
99
RETURNS int2
1010
AS 'MODULE_PATHNAME', 'pg_freespace'
1111
LANGUAGE C;
1212

1313
-- pg_freespace shows the recorded space avail at each block in a relation
1414
CREATE OR REPLACE FUNCTION
15-
pg_freespace(rel regclass, blkno OUTint4, avail OUT int2)
15+
pg_freespace(rel regclass, blkno OUTbigint, avail OUT int2)
1616
RETURNS SETOF RECORD
1717
AS $$
18-
SELECT blkno::int4, pg_freespace($1, blkno::int4) AS avail
18+
SELECT blkno, pg_freespace($1, blkno) AS avail
1919
FROM generate_series(0, pg_relation_size($1) / current_setting('block_size')::bigint - 1) AS blkno;
2020
$$
2121
LANGUAGE SQL;
2222

2323

2424
-- Don't want these to be available to public.
25-
REVOKE ALL ON FUNCTION pg_freespace(regclass,int4) FROM PUBLIC;
25+
REVOKE ALL ON FUNCTION pg_freespace(regclass,bigint) FROM PUBLIC;
2626
REVOKE ALL ON FUNCTION pg_freespace(regclass) FROM PUBLIC;

‎doc/src/sgml/pgfreespacemap.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgfreespacemap.sgml,v 2.4 2008/10/0210:26:51 heikki Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgfreespacemap.sgml,v 2.5 2008/10/0212:20:50 heikki Exp $ -->
22

33
<sect1 id="pgfreespacemap">
44
<title>pg_freespacemap</title>
@@ -41,13 +41,13 @@
4141

4242
<varlistentry>
4343
<term>
44-
<function>pg_freespace(rel regclass IN, blkno OUTint4, avail OUT int2)</function>
44+
<function>pg_freespace(rel regclass IN, blkno OUTbigint, avail OUT int2)</function>
4545
</term>
4646

4747
<listitem>
4848
<para>
4949
Displays the the amount of free space on each page of the relation,
50-
according to the FSM. A set of <literal>(blknoint4, avail int2)</>
50+
according to the FSM. A set of <literal>(blknobigint, avail int2)</>
5151
tuples is returned, one tuple for each page in the relation.
5252
</para>
5353
</listitem>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp