mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
New patch with corrected README attached.
Also quickly added mention that it may be a qualified schema name. Rod Taylor
This commit is contained in:
@ -8,7 +8,7 @@ pgstattuple README 2002/08/29 Tatsuo Ishii
|
||||
|
||||
test=# \x
|
||||
Expanded display is on.
|
||||
test=# select * from pgstattuple('pg_proc');
|
||||
test=# select * from pgstattuple('pg_catalog.pg_proc');
|
||||
-[ RECORD 1 ]------+-------
|
||||
table_len | 458752
|
||||
tuple_count | 1470
|
||||
@ -45,9 +45,14 @@ free_percent -- free space in %
|
||||
|
||||
CREATE OR REPLACE FUNCTION pgstattuple(text) RETURNS pgstattuple_type
|
||||
AS 'MODULE_PATHNAME', 'pgstattuple'
|
||||
LANGUAGE 'c' WITH (isstrict);
|
||||
LANGUAGE 'c' STRICT;
|
||||
|
||||
The argument is the table name. Note that pgstattuple only returns
|
||||
CREATE OR REPLACE FUNCTION pgstattuple(oid) RETURNS pgstattuple_type
|
||||
AS 'MODULE_PATHNAME', 'pgstattuplebyid'
|
||||
LANGUAGE 'c' STRICT;
|
||||
|
||||
The argument is the table name (optionally it may be qualified)
|
||||
or the OID of the table. Note that pgstattuple only returns
|
||||
one row.
|
||||
|
||||
4. Notes
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Header: /cvsroot/pgsql/contrib/pgstattuple/pgstattuple.c,v 1.9 2002/09/04 20:31:08 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/contrib/pgstattuple/pgstattuple.c,v 1.10 2003/06/12 08:02:53 momjian Exp $
|
||||
*
|
||||
* Copyright (c) 2001,2002 Tatsuo Ishii
|
||||
*
|
||||
@ -33,8 +33,12 @@
|
||||
|
||||
|
||||
PG_FUNCTION_INFO_V1(pgstattuple);
|
||||
PG_FUNCTION_INFO_V1(pgstattuplebyid);
|
||||
|
||||
extern Datum pgstattuple(PG_FUNCTION_ARGS);
|
||||
extern Datum pgstattuplebyid(PG_FUNCTION_ARGS);
|
||||
|
||||
static Datum pgstattuple_real(Relation rel);
|
||||
|
||||
/* ----------
|
||||
* pgstattuple:
|
||||
@ -46,7 +50,7 @@ extern Datum pgstattuple(PG_FUNCTION_ARGS);
|
||||
* ----------
|
||||
*/
|
||||
|
||||
#define DUMMY_TUPLE "pgstattuple_type"
|
||||
#define DUMMY_TUPLE "public.pgstattuple_type"
|
||||
#define NCOLUMNS 9
|
||||
#define NCHARS 32
|
||||
|
||||
@ -56,6 +60,41 @@ pgstattuple(PG_FUNCTION_ARGS)
|
||||
text *relname = PG_GETARG_TEXT_P(0);
|
||||
RangeVar *relrv;
|
||||
Relation rel;
|
||||
Datum result;
|
||||
|
||||
/* open relation */
|
||||
relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname,
|
||||
"pgstattuple"));
|
||||
rel = heap_openrv(relrv, AccessShareLock);
|
||||
|
||||
result = pgstattuple_real(rel);
|
||||
|
||||
PG_RETURN_DATUM(result);
|
||||
}
|
||||
|
||||
Datum
|
||||
pgstattuplebyid(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Oid relid = PG_GETARG_OID(0);
|
||||
Relation rel;
|
||||
Datum result;
|
||||
|
||||
/* open relation */
|
||||
rel = heap_open(relid, AccessShareLock);
|
||||
|
||||
result = pgstattuple_real(rel);
|
||||
|
||||
PG_RETURN_DATUM(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* pgstattuple_real
|
||||
*
|
||||
* The real work occurs here
|
||||
*/
|
||||
static Datum
|
||||
pgstattuple_real(Relation rel)
|
||||
{
|
||||
HeapScanDesc scan;
|
||||
HeapTuple tuple;
|
||||
BlockNumber nblocks;
|
||||
@ -92,11 +131,6 @@ pgstattuple(PG_FUNCTION_ARGS)
|
||||
*/
|
||||
attinmeta = TupleDescGetAttInMetadata(tupdesc);
|
||||
|
||||
/* open relation */
|
||||
relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname,
|
||||
"pgstattuple"));
|
||||
rel = heap_openrv(relrv, AccessShareLock);
|
||||
|
||||
nblocks = RelationGetNumberOfBlocks(rel);
|
||||
scan = heap_beginscan(rel, SnapshotAny, 0, NULL);
|
||||
|
||||
@ -187,5 +221,5 @@ pgstattuple(PG_FUNCTION_ARGS)
|
||||
pfree(values[i]);
|
||||
pfree(values);
|
||||
|
||||
PG_RETURN_DATUM(result);
|
||||
return(result);
|
||||
}
|
||||
|
@ -17,4 +17,9 @@ CREATE TYPE pgstattuple_type AS (
|
||||
CREATE OR REPLACE FUNCTION pgstattuple(text)
|
||||
RETURNS pgstattuple_type
|
||||
AS 'MODULE_PATHNAME', 'pgstattuple'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
LANGUAGE 'C' STRICT;
|
||||
|
||||
CREATE OR REPLACE FUNCTION pgstattuple(oid)
|
||||
RETURNS pgstattuple_type
|
||||
AS 'MODULE_PATHNAME', 'pgstattuplebyid'
|
||||
LANGUAGE 'C' STRICT;
|
||||
|
Reference in New Issue
Block a user