11/*
2- * $Header: /cvsroot/pgsql/contrib/pgstattuple/pgstattuple.c,v 1.9 2002/09/04 20:31:08 momjian Exp $
2+ * $Header: /cvsroot/pgsql/contrib/pgstattuple/pgstattuple.c,v 1.10 2003/06/12 08:02:53 momjian Exp $
33 *
44 * Copyright (c) 2001,2002Tatsuo Ishii
55 *
3333
3434
3535PG_FUNCTION_INFO_V1 (pgstattuple );
36+ PG_FUNCTION_INFO_V1 (pgstattuplebyid );
3637
3738extern Datum pgstattuple (PG_FUNCTION_ARGS );
39+ extern Datum pgstattuplebyid (PG_FUNCTION_ARGS );
40+
41+ static Datum pgstattuple_real (Relation rel );
3842
3943/* ----------
4044 * pgstattuple:
@@ -46,7 +50,7 @@ extern Datum pgstattuple(PG_FUNCTION_ARGS);
4650 * ----------
4751 */
4852
49- #define DUMMY_TUPLE "pgstattuple_type"
53+ #define DUMMY_TUPLE "public. pgstattuple_type"
5054#define NCOLUMNS 9
5155#define NCHARS 32
5256
@@ -56,6 +60,41 @@ pgstattuple(PG_FUNCTION_ARGS)
5660text * relname = PG_GETARG_TEXT_P (0 );
5761RangeVar * relrv ;
5862Relation rel ;
63+ Datum result ;
64+
65+ /* open relation */
66+ relrv = makeRangeVarFromNameList (textToQualifiedNameList (relname ,
67+ "pgstattuple" ));
68+ rel = heap_openrv (relrv ,AccessShareLock );
69+
70+ result = pgstattuple_real (rel );
71+
72+ PG_RETURN_DATUM (result );
73+ }
74+
75+ Datum
76+ pgstattuplebyid (PG_FUNCTION_ARGS )
77+ {
78+ Oid relid = PG_GETARG_OID (0 );
79+ Relation rel ;
80+ Datum result ;
81+
82+ /* open relation */
83+ rel = heap_open (relid ,AccessShareLock );
84+
85+ result = pgstattuple_real (rel );
86+
87+ PG_RETURN_DATUM (result );
88+ }
89+
90+ /*
91+ * pgstattuple_real
92+ *
93+ * The real work occurs here
94+ */
95+ static Datum
96+ pgstattuple_real (Relation rel )
97+ {
5998HeapScanDesc scan ;
6099HeapTuple tuple ;
61100BlockNumber nblocks ;
@@ -92,11 +131,6 @@ pgstattuple(PG_FUNCTION_ARGS)
92131 */
93132attinmeta = TupleDescGetAttInMetadata (tupdesc );
94133
95- /* open relation */
96- relrv = makeRangeVarFromNameList (textToQualifiedNameList (relname ,
97- "pgstattuple" ));
98- rel = heap_openrv (relrv ,AccessShareLock );
99-
100134nblocks = RelationGetNumberOfBlocks (rel );
101135scan = heap_beginscan (rel ,SnapshotAny ,0 ,NULL );
102136
@@ -187,5 +221,5 @@ pgstattuple(PG_FUNCTION_ARGS)
187221pfree (values [i ]);
188222pfree (values );
189223
190- PG_RETURN_DATUM (result );
224+ return (result );
191225}