summaryrefslogtreecommitdiff
path: root/contrib/pgstattuple
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/pgstattuple')
-rw-r--r--contrib/pgstattuple/README.pgstattuple11
-rw-r--r--contrib/pgstattuple/pgstattuple.c50
-rw-r--r--contrib/pgstattuple/pgstattuple.sql.in7
3 files changed, 56 insertions, 12 deletions
diff --git a/contrib/pgstattuple/README.pgstattuple b/contrib/pgstattuple/README.pgstattuple
index 42a7fc2165d..3e7facb80f0 100644
--- a/contrib/pgstattuple/README.pgstattuple
+++ b/contrib/pgstattuple/README.pgstattuple
@@ -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
diff --git a/contrib/pgstattuple/pgstattuple.c b/contrib/pgstattuple/pgstattuple.c
index 51cab46a1e7..fb0d9316151 100644
--- a/contrib/pgstattuple/pgstattuple.c
+++ b/contrib/pgstattuple/pgstattuple.c
@@ -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);
}
diff --git a/contrib/pgstattuple/pgstattuple.sql.in b/contrib/pgstattuple/pgstattuple.sql.in
index c32c00ba3fe..b75c8451592 100644
--- a/contrib/pgstattuple/pgstattuple.sql.in
+++ b/contrib/pgstattuple/pgstattuple.sql.in
@@ -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;