Skip to content

Commit c9a6490

Browse files
committed
Clean up some leftover problems in pgstattuple: remove unwanted and
unportable elog(NOTICE) report, fix install/uninstall sequence. Itagaki Takahiro
1 parent 57bfb27 commit c9a6490

File tree

4 files changed

+32
-93
lines changed

4 files changed

+32
-93
lines changed

contrib/pgstattuple/pgstatindex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ bt_page_items(PG_FUNCTION_ARGS)
561561
values[j] = palloc(32);
562562
snprintf(values[j++], 32, "(%u,%u)", blkno, itup->t_tid.ip_posid);
563563
values[j] = palloc(32);
564-
snprintf(values[j++], 32, "%d", IndexTupleSize(itup));
564+
snprintf(values[j++], 32, "%d", (int) IndexTupleSize(itup));
565565
values[j] = palloc(32);
566566
snprintf(values[j++], 32, "%c", IndexTupleHasNulls(itup) ? 't' : 'f');
567567
values[j] = palloc(32);

contrib/pgstattuple/pgstattuple.c

Lines changed: 17 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/pgstattuple/pgstattuple.c,v 1.23 2006/07/11 17:26:58 momjian Exp $
2+
* $PostgreSQL: pgsql/contrib/pgstattuple/pgstattuple.c,v 1.24 2006/09/04 02:03:04 tgl Exp $
33
*
44
* Copyright (c) 2001,2002 Tatsuo Ishii
55
*
@@ -59,35 +59,19 @@ typedef struct pgstattuple_type
5959
uint64 free_space; /* free/reusable space in bytes */
6060
} pgstattuple_type;
6161

62-
/*
63-
* struct pgstat_btree_type
64-
*/
65-
typedef struct pgstat_btree_type
66-
{
67-
pgstattuple_type base; /* inherits pgstattuple_type */
68-
69-
uint64 continuous;
70-
uint64 forward;
71-
uint64 backward;
72-
} pgstat_btree_type;
73-
7462
typedef void (*pgstat_page)(pgstattuple_type *, Relation, BlockNumber);
7563

7664
static Datum build_pgstattuple_type(pgstattuple_type *stat,
7765
FunctionCallInfo fcinfo);
7866
static Datum pgstat_relation(Relation rel, FunctionCallInfo fcinfo);
7967
static Datum pgstat_heap(Relation rel, FunctionCallInfo fcinfo);
80-
static Datum pgstat_btree(Relation rel, FunctionCallInfo fcinfo);
8168
static void pgstat_btree_page(pgstattuple_type *stat,
8269
Relation rel, BlockNumber blkno);
83-
static Datum pgstat_hash(Relation rel, FunctionCallInfo fcinfo);
8470
static void pgstat_hash_page(pgstattuple_type *stat,
8571
Relation rel, BlockNumber blkno);
86-
static Datum pgstat_gist(Relation rel, FunctionCallInfo fcinfo);
8772
static void pgstat_gist_page(pgstattuple_type *stat,
8873
Relation rel, BlockNumber blkno);
89-
static Datum pgstat_index(pgstattuple_type *stat,
90-
Relation rel, BlockNumber start,
74+
static Datum pgstat_index(Relation rel, BlockNumber start,
9175
pgstat_page pagefn, FunctionCallInfo fcinfo);
9276
static void pgstat_index_page(pgstattuple_type *stat, Page page,
9377
OffsetNumber minoff, OffsetNumber maxoff);
@@ -217,11 +201,14 @@ pgstat_relation(Relation rel, FunctionCallInfo fcinfo)
217201
switch(rel->rd_rel->relam)
218202
{
219203
case BTREE_AM_OID:
220-
return pgstat_btree(rel, fcinfo);
204+
return pgstat_index(rel, BTREE_METAPAGE + 1,
205+
pgstat_btree_page, fcinfo);
221206
case HASH_AM_OID:
222-
return pgstat_hash(rel, fcinfo);
207+
return pgstat_index(rel, HASH_METAPAGE + 1,
208+
pgstat_hash_page, fcinfo);
223209
case GIST_AM_OID:
224-
return pgstat_gist(rel, fcinfo);
210+
return pgstat_index(rel, GIST_ROOT_BLKNO + 1,
211+
pgstat_gist_page, fcinfo);
225212
case GIN_AM_OID:
226213
err = "gin index";
227214
break;
@@ -321,36 +308,13 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
321308
}
322309

323310
/*
324-
* pgstat_btree -- returns live/dead tuples info in a btree index
325-
*/
326-
static Datum
327-
pgstat_btree(Relation rel, FunctionCallInfo fcinfo)
328-
{
329-
pgstat_btree_type stat = { { 0 } };
330-
Datum datum;
331-
332-
datum = pgstat_index((pgstattuple_type *) &stat, rel,
333-
BTREE_METAPAGE + 1, pgstat_btree_page, fcinfo);
334-
335-
ereport(NOTICE,
336-
(errmsg("%.2f%% fragmented",
337-
100.0 * (stat.forward + stat.backward) /
338-
(stat.continuous + stat.forward + stat.backward)),
339-
errhint("continuous=%llu, forward=%llu, backward=%llu",
340-
stat.continuous, stat.forward, stat.backward)));
341-
342-
return datum;
343-
}
344-
345-
/*
346-
* pgstat_btree_page
311+
* pgstat_btree_page -- check tuples in a btree page
347312
*/
348313
static void
349314
pgstat_btree_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
350315
{
351316
Buffer buf;
352317
Page page;
353-
pgstat_btree_type *btstat = (pgstat_btree_type *)stat;
354318

355319
buf = ReadBuffer(rel, blkno);
356320
LockBuffer(buf, BT_READ);
@@ -373,16 +337,6 @@ pgstat_btree_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
373337
}
374338
else if (P_ISLEAF(opaque))
375339
{
376-
/* check fragmentation */
377-
if (P_RIGHTMOST(opaque))
378-
btstat->continuous++;
379-
else if (opaque->btpo_next < blkno)
380-
btstat->backward++;
381-
else if (opaque->btpo_next > blkno + 1)
382-
btstat->forward++;
383-
else
384-
btstat->continuous++;
385-
386340
pgstat_index_page(stat, page, P_FIRSTDATAKEY(opaque),
387341
PageGetMaxOffsetNumber(page));
388342
}
@@ -396,17 +350,7 @@ pgstat_btree_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
396350
}
397351

398352
/*
399-
* pgstat_hash -- returns live/dead tuples info in a hash index
400-
*/
401-
static Datum
402-
pgstat_hash(Relation rel, FunctionCallInfo fcinfo)
403-
{
404-
pgstattuple_type stat = { 0 };
405-
return pgstat_index(&stat, rel, HASH_METAPAGE + 1, pgstat_hash_page, fcinfo);
406-
}
407-
408-
/*
409-
* pgstat_hash_page
353+
* pgstat_hash_page -- check tuples in a hash page
410354
*/
411355
static void
412356
pgstat_hash_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
@@ -448,17 +392,7 @@ pgstat_hash_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
448392
}
449393

450394
/*
451-
* pgstat_gist -- returns live/dead tuples info in a gist index
452-
*/
453-
static Datum
454-
pgstat_gist(Relation rel, FunctionCallInfo fcinfo)
455-
{
456-
pgstattuple_type stat = { 0 };
457-
return pgstat_index(&stat, rel, GIST_ROOT_BLKNO + 1, pgstat_gist_page, fcinfo);
458-
}
459-
460-
/*
461-
* pgstat_gist_page
395+
* pgstat_gist_page -- check tuples in a gist page
462396
*/
463397
static void
464398
pgstat_gist_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
@@ -488,11 +422,12 @@ pgstat_gist_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
488422
* pgstat_index -- returns live/dead tuples info in a generic index
489423
*/
490424
static Datum
491-
pgstat_index(pgstattuple_type *stat, Relation rel, BlockNumber start,
492-
pgstat_page pagefn, FunctionCallInfo fcinfo)
425+
pgstat_index(Relation rel, BlockNumber start, pgstat_page pagefn,
426+
FunctionCallInfo fcinfo)
493427
{
494428
BlockNumber nblocks;
495429
BlockNumber blkno;
430+
pgstattuple_type stat = { 0 };
496431

497432
blkno = start;
498433
for (;;)
@@ -505,17 +440,17 @@ pgstat_index(pgstattuple_type *stat, Relation rel, BlockNumber start,
505440
/* Quit if we've scanned the whole relation */
506441
if (blkno >= nblocks)
507442
{
508-
stat->table_len = (uint64) nblocks * BLCKSZ;
443+
stat.table_len = (uint64) nblocks * BLCKSZ;
509444
break;
510445
}
511446

512447
for (; blkno < nblocks; blkno++)
513-
pagefn(stat, rel, blkno);
448+
pagefn(&stat, rel, blkno);
514449
}
515450

516451
relation_close(rel, AccessShareLock);
517452

518-
return build_pgstattuple_type(stat, fcinfo);
453+
return build_pgstattuple_type(&stat, fcinfo);
519454
}
520455

521456
/*

contrib/pgstattuple/pgstattuple.sql.in

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ LANGUAGE C STRICT;
2626
--
2727
-- pgstatindex
2828
--
29-
DROP TYPE pgstatindex_type CASCADE;
3029
CREATE TYPE pgstatindex_type AS (
3130
version int4,
3231
tree_level int4,
@@ -48,7 +47,6 @@ LANGUAGE 'C' STRICT;
4847
--
4948
-- bt_metap()
5049
--
51-
DROP TYPE bt_metap_type CASCADE;
5250
CREATE TYPE bt_metap_type AS (
5351
magic int4,
5452
version int4,
@@ -66,7 +64,6 @@ LANGUAGE 'C' STRICT;
6664
--
6765
-- bt_page_stats()
6866
--
69-
DROP TYPE bt_page_stats_type CASCADE;
7067
CREATE TYPE bt_page_stats_type AS (
7168
blkno int4,
7269
type char,
@@ -81,8 +78,6 @@ CREATE TYPE bt_page_stats_type AS (
8178
btpo_flags int4
8279
);
8380

84-
DROP FUNCTION bt_page_stats(text, int4);
85-
8681
CREATE OR REPLACE FUNCTION bt_page_stats(text, int4)
8782
RETURNS bt_page_stats_type
8883
AS 'MODULE_PATHNAME', 'bt_page_stats'
@@ -91,7 +86,6 @@ LANGUAGE 'C' STRICT;
9186
--
9287
-- bt_page_items()
9388
--
94-
DROP TYPE bt_page_items_type CASCADE;
9589
CREATE TYPE bt_page_items_type AS (
9690
itemoffset int4,
9791
ctid tid,
@@ -101,8 +95,6 @@ CREATE TYPE bt_page_items_type AS (
10195
data text
10296
);
10397

104-
DROP FUNCTION bt_page_items(text, int4);
105-
10698
CREATE OR REPLACE FUNCTION bt_page_items(text, int4)
10799
RETURNS SETOF bt_page_items_type
108100
AS 'MODULE_PATHNAME', 'bt_page_items'

contrib/pgstattuple/uninstall_pgstattuple.sql

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22
SET search_path = public;
33

44
DROP FUNCTION pgstattuple(oid);
5-
65
DROP FUNCTION pgstattuple(text);
7-
86
DROP TYPE pgstattuple_type;
7+
8+
DROP FUNCTION pgstatindex(text);
9+
DROP TYPE pgstatindex_type;
10+
11+
DROP FUNCTION bt_metap(text);
12+
DROP TYPE bt_metap_type;
13+
14+
DROP FUNCTION bt_page_stats(text, int4);
15+
DROP TYPE bt_page_stats_type;
16+
17+
DROP FUNCTION bt_page_items(text, int4);
18+
DROP TYPE bt_page_items_type;
19+
20+
DROP FUNCTION pg_relpages(text);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy