Change naming rule for ON SELECT rules of views: they're all just

_RETURN now, since there's no need to keep 'em unique anymore.
This commit is contained in:
Tom Lane 2002-04-19 23:13:54 +00:00
parent 201737168c
commit 6d6ca2166c
13 changed files with 50 additions and 97 deletions

View File

@ -1,5 +1,5 @@
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_rule.sgml,v 1.34 2002/04/19 16:36:08 tgl Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_rule.sgml,v 1.35 2002/04/19 23:13:53 tgl Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
@ -268,12 +268,12 @@ CREATE
report an error because the query cycled too many times: report an error because the query cycled too many times:
<programlisting> <programlisting>
CREATE RULE "_RETemp" AS CREATE RULE "_RETURN" AS
ON SELECT TO emp ON SELECT TO emp
DO INSTEAD DO INSTEAD
SELECT * FROM toyemp; SELECT * FROM toyemp;
CREATE RULE "_RETtoyemp" AS CREATE RULE "_RETURN" AS
ON SELECT TO toyemp ON SELECT TO toyemp
DO INSTEAD DO INSTEAD
SELECT * FROM emp; SELECT * FROM emp;

View File

@ -1,4 +1,4 @@
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/rules.sgml,v 1.22 2002/03/22 19:20:26 petere Exp $ --> <!-- $Header: /cvsroot/pgsql/doc/src/sgml/rules.sgml,v 1.23 2002/04/19 23:13:53 tgl Exp $ -->
<Chapter Id="rules"> <Chapter Id="rules">
<Title>The Rule System</Title> <Title>The Rule System</Title>
@ -289,7 +289,7 @@ CREATE VIEW myview AS SELECT * FROM mytab;
<ProgramListing> <ProgramListing>
CREATE TABLE myview (<Replaceable>same attribute list as for mytab</Replaceable>); CREATE TABLE myview (<Replaceable>same attribute list as for mytab</Replaceable>);
CREATE RULE "_RETmyview" AS ON SELECT TO myview DO INSTEAD CREATE RULE "_RETURN" AS ON SELECT TO myview DO INSTEAD
SELECT * FROM mytab; SELECT * FROM mytab;
</ProgramListing> </ProgramListing>
@ -517,7 +517,7 @@ SELECT shoelace.sl_name, shoelace.sl_avail,
range table and checks if there are rules in <Filename>pg_rewrite</Filename> range table and checks if there are rules in <Filename>pg_rewrite</Filename>
for any relation. When processing the range table entry for for any relation. When processing the range table entry for
<Filename>shoelace</Filename> (the only one up to now) it finds the <Filename>shoelace</Filename> (the only one up to now) it finds the
rule <literal>_RETshoelace</literal> with the parse tree <literal>_RETURN</literal> rule with the parse tree
<ProgramListing> <ProgramListing>
<emphasis>SELECT s.sl_name, s.sl_avail, <emphasis>SELECT s.sl_name, s.sl_avail,
@ -1494,7 +1494,7 @@ UPDATE shoelace_data SET
Again it's an INSTEAD rule and the previous parse tree is trashed. Again it's an INSTEAD rule and the previous parse tree is trashed.
Note that this query still uses the view <Filename>shoelace</Filename>. Note that this query still uses the view <Filename>shoelace</Filename>.
But the rule system isn't finished with this loop so it continues But the rule system isn't finished with this loop so it continues
and applies the rule <literal>_RETshoelace</literal> on it and we get and applies the <literal>_RETURN</literal> rule on it and we get
<ProgramListing> <ProgramListing>
UPDATE shoelace_data SET UPDATE shoelace_data SET

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.4 2002/04/19 16:36:08 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.5 2002/04/19 23:13:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -40,8 +40,6 @@
#include "parser/parse_expr.h" #include "parser/parse_expr.h"
#include "parser/parse_relation.h" #include "parser/parse_relation.h"
#include "parser/parse_type.h" #include "parser/parse_type.h"
#include "rewrite/rewriteDefine.h"
#include "rewrite/rewriteSupport.h"
#include "utils/acl.h" #include "utils/acl.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/fmgroids.h" #include "utils/fmgroids.h"
@ -2814,19 +2812,6 @@ renamerel(Oid relid, const char *newrelname)
if (relkind != RELKIND_INDEX) if (relkind != RELKIND_INDEX)
TypeRename(oldrelname, namespaceId, newrelname); TypeRename(oldrelname, namespaceId, newrelname);
/*
* If it's a view, must also rename the associated ON SELECT rule.
*/
if (relkind == RELKIND_VIEW)
{
char *oldrulename,
*newrulename;
oldrulename = MakeRetrieveViewRuleName(oldrelname);
newrulename = MakeRetrieveViewRuleName(newrelname);
RenameRewriteRule(relid, oldrulename, newrulename);
}
/* /*
* Update rel name in any RI triggers associated with the relation. * Update rel name in any RI triggers associated with the relation.
*/ */

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: view.c,v 1.62 2002/04/15 05:22:03 tgl Exp $ * $Id: view.c,v 1.63 2002/04/19 23:13:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -99,17 +99,14 @@ static RuleStmt *
FormViewRetrieveRule(const RangeVar *view, Query *viewParse) FormViewRetrieveRule(const RangeVar *view, Query *viewParse)
{ {
RuleStmt *rule; RuleStmt *rule;
char *rname;
/* /*
* Create a RuleStmt that corresponds to the suitable rewrite rule * Create a RuleStmt that corresponds to the suitable rewrite rule
* args for DefineQueryRewrite(); * args for DefineQueryRewrite();
*/ */
rname = MakeRetrieveViewRuleName(view->relname);
rule = makeNode(RuleStmt); rule = makeNode(RuleStmt);
rule->relation = copyObject((RangeVar *) view); rule->relation = copyObject((RangeVar *) view);
rule->rulename = pstrdup(rname); rule->rulename = pstrdup(ViewSelectRuleName);
rule->whereClause = NULL; rule->whereClause = NULL;
rule->event = CMD_SELECT; rule->event = CMD_SELECT;
rule->instead = true; rule->instead = true;

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.67 2002/04/18 20:01:09 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.68 2002/04/19 23:13:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -176,7 +176,6 @@ DefineQueryRewrite(RuleStmt *stmt)
{ {
List *tllist; List *tllist;
int i; int i;
char *expected_name;
/* /*
* So there cannot be INSTEAD NOTHING, ... * So there cannot be INSTEAD NOTHING, ...
@ -265,15 +264,26 @@ DefineQueryRewrite(RuleStmt *stmt)
} }
/* /*
* ... and finally the rule must be named _RETviewname. * ... and finally the rule must be named _RETURN.
*/ */
expected_name = MakeRetrieveViewRuleName(event_obj->relname); if (strcmp(stmt->rulename, ViewSelectRuleName) != 0)
if (strcmp(expected_name, stmt->rulename) != 0)
{ {
elog(ERROR, "view rule for \"%s\" must be named \"%s\"", /*
event_obj->relname, expected_name); * In versions before 7.3, the expected name was _RETviewname.
* For backwards compatibility with old pg_dump output, accept
* that and silently change it to _RETURN. Since this is just
* a quick backwards-compatibility hack, limit the number of
* characters checked to a few less than NAMEDATALEN; this
* saves having to worry about where a multibyte character might
* have gotten truncated.
*/
if (strncmp(stmt->rulename, "_RET", 4) != 0 ||
strncmp(stmt->rulename + 4, event_obj->relname,
NAMEDATALEN - 4 - 4) != 0)
elog(ERROR, "view rule for \"%s\" must be named \"%s\"",
event_obj->relname, ViewSelectRuleName);
stmt->rulename = pstrdup(ViewSelectRuleName);
} }
pfree(expected_name);
/* /*
* Are we converting a relation to a view? * Are we converting a relation to a view?
@ -418,9 +428,7 @@ setRuleCheckAsUser_walker(Node *node, Oid *context)
/* /*
* Rename an existing rewrite rule. * Rename an existing rewrite rule.
* *
* There is not currently a user command to invoke this directly * This is unused code at the moment.
* (perhaps there should be). But we need it anyway to rename the
* ON SELECT rule associated with a view, when the view is renamed.
*/ */
void void
RenameRewriteRule(Oid owningRel, const char *oldName, RenameRewriteRule(Oid owningRel, const char *oldName,

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.50 2002/04/18 20:01:09 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.51 2002/04/19 23:13:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -20,10 +20,6 @@
#include "rewrite/rewriteSupport.h" #include "rewrite/rewriteSupport.h"
#include "utils/syscache.h" #include "utils/syscache.h"
#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
#endif
/* /*
* Is there a rule by the given name? * Is there a rule by the given name?
@ -37,35 +33,6 @@ IsDefinedRewriteRule(Oid owningRel, const char *ruleName)
0, 0); 0, 0);
} }
/*
* makeViewRetrieveRuleName
*
* Given a view name, returns the name for the associated ON SELECT rule.
*
* XXX this is not the only place in the backend that knows about the _RET
* name-forming convention.
*/
char *
MakeRetrieveViewRuleName(const char *viewName)
{
char *buf;
int buflen,
maxlen;
buflen = strlen(viewName) + 5;
buf = palloc(buflen);
snprintf(buf, buflen, "_RET%s", viewName);
/* clip to less than NAMEDATALEN bytes, if necessary */
#ifdef MULTIBYTE
maxlen = pg_mbcliplen(buf, strlen(buf), NAMEDATALEN - 1);
#else
maxlen = NAMEDATALEN - 1;
#endif
if (maxlen < buflen)
buf[maxlen] = '\0';
return buf;
}
/* /*
* SetRelationRuleStatus * SetRelationRuleStatus

View File

@ -3,7 +3,7 @@
* back to source text * back to source text
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.97 2002/04/18 20:01:09 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.98 2002/04/19 23:13:54 tgl Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
@ -283,7 +283,6 @@ pg_do_getviewdef(Oid viewoid)
StringInfoData buf; StringInfoData buf;
int len; int len;
char *viewname; char *viewname;
char *name;
/* /*
* Connect to SPI manager * Connect to SPI manager
@ -313,9 +312,8 @@ pg_do_getviewdef(Oid viewoid)
* Get the pg_rewrite tuple for the view's SELECT rule * Get the pg_rewrite tuple for the view's SELECT rule
*/ */
viewname = get_rel_name(viewoid); viewname = get_rel_name(viewoid);
name = MakeRetrieveViewRuleName(viewname);
args[0] = ObjectIdGetDatum(viewoid); args[0] = ObjectIdGetDatum(viewoid);
args[1] = PointerGetDatum(name); args[1] = PointerGetDatum(ViewSelectRuleName);
nulls[0] = ' '; nulls[0] = ' ';
nulls[1] = ' '; nulls[1] = ' ';
spirc = SPI_execp(plan_getviewrule, args, nulls, 2); spirc = SPI_execp(plan_getviewrule, args, nulls, 2);
@ -338,7 +336,6 @@ pg_do_getviewdef(Oid viewoid)
VARATT_SIZEP(ruledef) = len; VARATT_SIZEP(ruledef) = len;
memcpy(VARDATA(ruledef), buf.data, buf.len); memcpy(VARDATA(ruledef), buf.data, buf.len);
pfree(buf.data); pfree(buf.data);
pfree(name);
/* /*
* Disconnect from SPI manager * Disconnect from SPI manager

View File

@ -27,7 +27,7 @@
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.149 2002/04/18 20:01:10 tgl Exp $ # $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.150 2002/04/19 23:13:54 tgl Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -695,7 +695,7 @@ CREATE VIEW pg_rules AS \
pg_get_ruledef(R.oid) AS definition \ pg_get_ruledef(R.oid) AS definition \
FROM (pg_rewrite R JOIN pg_class C ON (C.oid = R.ev_class)) \ FROM (pg_rewrite R JOIN pg_class C ON (C.oid = R.ev_class)) \
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) \ LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) \
WHERE R.rulename !~ '^_RET'; WHERE R.rulename != '_RETURN';
CREATE VIEW pg_views AS \ CREATE VIEW pg_views AS \
SELECT \ SELECT \

View File

@ -22,7 +22,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.249 2002/04/18 20:01:10 tgl Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.250 2002/04/19 23:13:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -2291,10 +2291,8 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs, const char *tablename)
"oid as view_oid" "oid as view_oid"
" from pg_rewrite where" " from pg_rewrite where"
" ev_class = '%s'::oid and" " ev_class = '%s'::oid and"
" rulename = ('_RET' || ", " rulename = '_RETURN';",
tblinfo[i].oid); tblinfo[i].oid);
formatStringLiteral(query, tblinfo[i].relname, CONV_ALL);
appendPQExpBuffer(query, ")::name;");
} }
res2 = PQexec(g_conn, query->data); res2 = PQexec(g_conn, query->data);
@ -5006,7 +5004,7 @@ dumpRules(Archive *fout, const char *tablename,
continue; continue;
/* /*
* Get all rules defined for this table * Get all rules defined for this table, except view select rules
*/ */
resetPQExpBuffer(query); resetPQExpBuffer(query);
@ -5036,7 +5034,7 @@ dumpRules(Archive *fout, const char *tablename,
"FROM pg_rewrite, pg_class " "FROM pg_rewrite, pg_class "
"WHERE pg_class.oid = '%s'::oid " "WHERE pg_class.oid = '%s'::oid "
" AND pg_rewrite.ev_class = pg_class.oid " " AND pg_rewrite.ev_class = pg_class.oid "
" AND pg_rewrite.rulename !~ '^_RET' " " AND pg_rewrite.rulename != '_RETURN' "
"ORDER BY pg_rewrite.oid", "ORDER BY pg_rewrite.oid",
tblinfo[t].oid); tblinfo[t].oid);
} }

View File

@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.49 2002/04/11 20:00:08 tgl Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.50 2002/04/19 23:13:54 tgl Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include "describe.h" #include "describe.h"
@ -385,9 +385,9 @@ objectDescription(const char *object)
/* Rule description (ignore rules for views) */ /* Rule description (ignore rules for views) */
"UNION ALL\n" "UNION ALL\n"
" SELECT r.oid as oid, r.tableoid as tableoid,\n" " SELECT r.oid as oid, r.tableoid as tableoid,\n"
" CAST(r.rulename AS text) as name, CAST('%s' AS text) as object\n" " CAST(r.rulename AS text) as name, CAST('%s' AS text) as object\n"
" FROM pg_rewrite r\n" " FROM pg_rewrite r\n"
" WHERE r.rulename !~ '^_RET'\n" " WHERE r.rulename != '_RETURN'\n"
/* Trigger description */ /* Trigger description */
"UNION ALL\n" "UNION ALL\n"
@ -704,8 +704,8 @@ describeTableDetails(const char *name, bool desc)
sprintf(buf, sprintf(buf,
"SELECT r.rulename\n" "SELECT r.rulename\n"
"FROM pg_rewrite r, pg_class c\n" "FROM pg_rewrite r, pg_class c\n"
"WHERE c.relname='%s' AND c.oid = r.ev_class\n" "WHERE c.relname = '%s' AND c.oid = r.ev_class\n"
"AND r.rulename NOT LIKE '_RET%%'", "AND r.rulename != '_RETURN'",
name); name);
result = PSQLexec(buf); result = PSQLexec(buf);
if (!result) if (!result)

View File

@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: catversion.h,v 1.119 2002/04/19 16:36:08 tgl Exp $ * $Id: catversion.h,v 1.120 2002/04/19 23:13:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -53,6 +53,6 @@
*/ */
/* yyyymmddN */ /* yyyymmddN */
#define CATALOG_VERSION_NO 200204182 #define CATALOG_VERSION_NO 200204191
#endif #endif

View File

@ -7,16 +7,17 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: rewriteSupport.h,v 1.21 2002/04/18 20:01:11 tgl Exp $ * $Id: rewriteSupport.h,v 1.22 2002/04/19 23:13:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef REWRITESUPPORT_H #ifndef REWRITESUPPORT_H
#define REWRITESUPPORT_H #define REWRITESUPPORT_H
extern bool IsDefinedRewriteRule(Oid owningRel, const char *ruleName); /* The ON SELECT rule of a view is always named this: */
#define ViewSelectRuleName "_RETURN"
extern char *MakeRetrieveViewRuleName(const char *view_name); extern bool IsDefinedRewriteRule(Oid owningRel, const char *ruleName);
extern void SetRelationRuleStatus(Oid relationId, bool relHasRules, extern void SetRelationRuleStatus(Oid relationId, bool relHasRules,
bool relIsBecomingView); bool relIsBecomingView);

View File

@ -1268,7 +1268,7 @@ SELECT viewname, definition FROM pg_views ORDER BY viewname;
--------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
iexit | SELECT ih.name, ih.thepath, interpt_pp(ih.thepath, r.thepath) AS exit FROM ihighway ih, ramp r WHERE (ih.thepath ## r.thepath); iexit | SELECT ih.name, ih.thepath, interpt_pp(ih.thepath, r.thepath) AS exit FROM ihighway ih, ramp r WHERE (ih.thepath ## r.thepath);
pg_indexes | SELECT c.relname AS tablename, i.relname AS indexname, pg_get_indexdef(x.indexrelid) AS indexdef FROM pg_index x, pg_class c, pg_class i WHERE ((((c.relkind = 'r'::"char") AND (i.relkind = 'i'::"char")) AND (c.oid = x.indrelid)) AND (i.oid = x.indexrelid)); pg_indexes | SELECT c.relname AS tablename, i.relname AS indexname, pg_get_indexdef(x.indexrelid) AS indexdef FROM pg_index x, pg_class c, pg_class i WHERE ((((c.relkind = 'r'::"char") AND (i.relkind = 'i'::"char")) AND (c.oid = x.indrelid)) AND (i.oid = x.indexrelid));
pg_rules | SELECT n.nspname AS schemaname, c.relname AS tablename, r.rulename, pg_get_ruledef(r.oid) AS definition FROM ((pg_rewrite r JOIN pg_class c ON ((c.oid = r.ev_class))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (r.rulename !~ '^_RET'::text); pg_rules | SELECT n.nspname AS schemaname, c.relname AS tablename, r.rulename, pg_get_ruledef(r.oid) AS definition FROM ((pg_rewrite r JOIN pg_class c ON ((c.oid = r.ev_class))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (r.rulename <> '_RETURN'::name);
pg_stat_activity | SELECT d.oid AS datid, d.datname, pg_stat_get_backend_pid(s.backendid) AS procpid, pg_stat_get_backend_userid(s.backendid) AS usesysid, u.usename, pg_stat_get_backend_activity(s.backendid) AS current_query FROM pg_database d, (SELECT pg_stat_get_backend_idset() AS backendid) s, pg_shadow u WHERE ((pg_stat_get_backend_dbid(s.backendid) = d.oid) AND (pg_stat_get_backend_userid(s.backendid) = u.usesysid)); pg_stat_activity | SELECT d.oid AS datid, d.datname, pg_stat_get_backend_pid(s.backendid) AS procpid, pg_stat_get_backend_userid(s.backendid) AS usesysid, u.usename, pg_stat_get_backend_activity(s.backendid) AS current_query FROM pg_database d, (SELECT pg_stat_get_backend_idset() AS backendid) s, pg_shadow u WHERE ((pg_stat_get_backend_dbid(s.backendid) = d.oid) AND (pg_stat_get_backend_userid(s.backendid) = u.usesysid));
pg_stat_all_indexes | SELECT c.oid AS relid, i.oid AS indexrelid, c.relname, i.relname AS indexrelname, pg_stat_get_numscans(i.oid) AS idx_scan, pg_stat_get_tuples_returned(i.oid) AS idx_tup_read, pg_stat_get_tuples_fetched(i.oid) AS idx_tup_fetch FROM pg_class c, pg_class i, pg_index x WHERE (((c.relkind = 'r'::"char") AND (x.indrelid = c.oid)) AND (x.indexrelid = i.oid)); pg_stat_all_indexes | SELECT c.oid AS relid, i.oid AS indexrelid, c.relname, i.relname AS indexrelname, pg_stat_get_numscans(i.oid) AS idx_scan, pg_stat_get_tuples_returned(i.oid) AS idx_tup_read, pg_stat_get_tuples_fetched(i.oid) AS idx_tup_fetch FROM pg_class c, pg_class i, pg_index x WHERE (((c.relkind = 'r'::"char") AND (x.indrelid = c.oid)) AND (x.indexrelid = i.oid));
pg_stat_all_tables | SELECT c.oid AS relid, c.relname, pg_stat_get_numscans(c.oid) AS seq_scan, pg_stat_get_tuples_returned(c.oid) AS seq_tup_read, sum(pg_stat_get_numscans(i.indexrelid)) AS idx_scan, sum(pg_stat_get_tuples_fetched(i.indexrelid)) AS idx_tup_fetch, pg_stat_get_tuples_inserted(c.oid) AS n_tup_ins, pg_stat_get_tuples_updated(c.oid) AS n_tup_upd, pg_stat_get_tuples_deleted(c.oid) AS n_tup_del FROM (pg_class c LEFT JOIN pg_index i ON ((c.oid = i.indrelid))) WHERE (c.relkind = 'r'::"char") GROUP BY c.oid, c.relname; pg_stat_all_tables | SELECT c.oid AS relid, c.relname, pg_stat_get_numscans(c.oid) AS seq_scan, pg_stat_get_tuples_returned(c.oid) AS seq_tup_read, sum(pg_stat_get_numscans(i.indexrelid)) AS idx_scan, sum(pg_stat_get_tuples_fetched(i.indexrelid)) AS idx_tup_fetch, pg_stat_get_tuples_inserted(c.oid) AS n_tup_ins, pg_stat_get_tuples_updated(c.oid) AS n_tup_upd, pg_stat_get_tuples_deleted(c.oid) AS n_tup_del FROM (pg_class c LEFT JOIN pg_index i ON ((c.oid = i.indrelid))) WHERE (c.relkind = 'r'::"char") GROUP BY c.oid, c.relname;