Skip to content

Commit ef51395

Browse files
committed
Revert due to Tom's concerns:
Add ProcessUtility_hook() to handle all DDL to contrib/pg_stat_statements.
1 parent d85cb27 commit ef51395

File tree

4 files changed

+11
-135
lines changed

4 files changed

+11
-135
lines changed

contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 8 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Copyright (c) 2008-2009, PostgreSQL Global Development Group
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/contrib/pg_stat_statements/pg_stat_statements.c,v 1.6 2009/12/01 01:08:45 momjian Exp $
17+
* $PostgreSQL: pgsql/contrib/pg_stat_statements/pg_stat_statements.c,v 1.7 2009/12/01 02:31:11 momjian Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -24,7 +24,6 @@
2424

2525
#include "access/hash.h"
2626
#include "catalog/pg_type.h"
27-
#include "commands/copy.h"
2827
#include "executor/executor.h"
2928
#include "executor/instrument.h"
3029
#include "mb/pg_wchar.h"
@@ -33,7 +32,6 @@
3332
#include "storage/fd.h"
3433
#include "storage/ipc.h"
3534
#include "storage/spin.h"
36-
#include "tcop/utility.h"
3735
#include "utils/builtins.h"
3836
#include "utils/hsearch.h"
3937
#include "utils/guc.h"
@@ -115,7 +113,6 @@ static shmem_startup_hook_type prev_shmem_startup_hook = NULL;
115113
static ExecutorStart_hook_type prev_ExecutorStart = NULL;
116114
static ExecutorRun_hook_type prev_ExecutorRun = NULL;
117115
static ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
118-
static ProcessUtility_hook_type prev_ProcessUtility = NULL;
119116

120117
/* Links to shared memory state */
121118
static pgssSharedState *pgss = NULL;
@@ -127,11 +124,10 @@ typedef enum
127124
{
128125
PGSS_TRACK_NONE, /* track no statements */
129126
PGSS_TRACK_TOP, /* only top level statements */
130-
PGSS_TRACK_ALL /* all statements, including nested ones */
127+
PGSS_TRACK_ALL, /* all statements, including nested ones */
131128
} PGSSTrackLevel;
132129

133-
static const struct config_enum_entry track_options[] =
134-
{
130+
static const struct config_enum_entry track_options[] = {
135131
{"none", PGSS_TRACK_NONE, false},
136132
{"top", PGSS_TRACK_TOP, false},
137133
{"all", PGSS_TRACK_ALL, false},
@@ -140,7 +136,6 @@ static const struct config_enum_entry track_options[] =
140136

141137
static int pgss_max; /* max # statements to track */
142138
static int pgss_track; /* tracking level */
143-
static bool pgss_track_ddl; /* whether to track ddl commands */
144139
static bool pgss_save; /* whether to save stats across shutdown */
145140

146141

@@ -151,9 +146,7 @@ static bool pgss_save; /* whether to save stats across shutdown */
151146
/*---- Function declarations ----*/
152147

153148
void _PG_init(void);
154-
#ifdef NOT_USED
155149
void _PG_fini(void);
156-
#endif
157150

158151
Datum pg_stat_statements_reset(PG_FUNCTION_ARGS);
159152
Datum pg_stat_statements(PG_FUNCTION_ARGS);
@@ -168,12 +161,10 @@ static void pgss_ExecutorRun(QueryDesc *queryDesc,
168161
ScanDirection direction,
169162
long count);
170163
static void pgss_ExecutorEnd(QueryDesc *queryDesc);
171-
static void pgss_ProcessUtility(Node *parsetree,
172-
const char *queryString, ParamListInfo params, bool isTopLevel,
173-
DestReceiver *dest, char *completionTag);
174164
static uint32 pgss_hash_fn(const void *key, Size keysize);
175165
static int pgss_match_fn(const void *key1, const void *key2, Size keysize);
176-
static void pgss_store(const char *query, double total_time, uint64 rows);
166+
static void pgss_store(const char *query,
167+
const Instrumentation *instr, uint32 rows);
177168
static Size pgss_memsize(void);
178169
static pgssEntry *entry_alloc(pgssHashKey *key);
179170
static void entry_dealloc(void);
@@ -223,16 +214,6 @@ _PG_init(void)
223214
NULL,
224215
NULL);
225216

226-
DefineCustomBoolVariable("pg_stat_statements.track_ddl",
227-
"Selects whether DDL commands are tracked by pg_stat_statements.",
228-
NULL,
229-
&pgss_track_ddl,
230-
true,
231-
PGC_SUSET,
232-
0,
233-
NULL,
234-
NULL);
235-
236217
DefineCustomBoolVariable("pg_stat_statements.save",
237218
"Save pg_stat_statements statistics across server shutdowns.",
238219
NULL,
@@ -264,11 +245,8 @@ _PG_init(void)
264245
ExecutorRun_hook = pgss_ExecutorRun;
265246
prev_ExecutorEnd = ExecutorEnd_hook;
266247
ExecutorEnd_hook = pgss_ExecutorEnd;
267-
prev_ProcessUtility = ProcessUtility_hook;
268-
ProcessUtility_hook = pgss_ProcessUtility;
269248
}
270249

271-
#ifdef NOT_USED
272250
/*
273251
* Module unload callback
274252
*/
@@ -279,10 +257,8 @@ _PG_fini(void)
279257
ExecutorStart_hook = prev_ExecutorStart;
280258
ExecutorRun_hook = prev_ExecutorRun;
281259
ExecutorEnd_hook = prev_ExecutorEnd;
282-
ProcessUtility_hook = prev_ProcessUtility;
283260
shmem_startup_hook = prev_shmem_startup_hook;
284261
}
285-
#endif
286262

287263
/*
288264
* shmem_startup hook: allocate or attach to shared memory,
@@ -563,7 +539,7 @@ pgss_ExecutorEnd(QueryDesc *queryDesc)
563539
InstrEndLoop(queryDesc->totaltime);
564540

565541
pgss_store(queryDesc->sourceText,
566-
queryDesc->totaltime->total,
542+
queryDesc->totaltime,
567543
queryDesc->estate->es_processed);
568544
}
569545

@@ -573,59 +549,6 @@ pgss_ExecutorEnd(QueryDesc *queryDesc)
573549
standard_ExecutorEnd(queryDesc);
574550
}
575551

576-
/*
577-
* ProcessUtility hook
578-
*/
579-
static void
580-
pgss_ProcessUtility(Node *parsetree, const char *queryString,
581-
ParamListInfo params, bool isTopLevel,
582-
DestReceiver *dest, char *completionTag)
583-
{
584-
if (pgss_track_ddl && isTopLevel && pgss_enabled())
585-
{
586-
instr_time start;
587-
instr_time duration;
588-
uint64 rows = 0;
589-
590-
INSTR_TIME_SET_CURRENT(start);
591-
592-
nested_level++;
593-
PG_TRY();
594-
{
595-
if (prev_ProcessUtility)
596-
prev_ProcessUtility(parsetree, queryString, params, isTopLevel, dest, completionTag);
597-
else if ((nodeTag(parsetree)) == T_CopyStmt)
598-
{
599-
rows = DoCopy((CopyStmt *) parsetree, queryString);
600-
if (completionTag)
601-
snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
602-
"COPY " UINT64_FORMAT, rows);
603-
}
604-
else
605-
standard_ProcessUtility(parsetree, queryString, params, isTopLevel, dest, completionTag);
606-
nested_level--;
607-
}
608-
PG_CATCH();
609-
{
610-
nested_level--;
611-
PG_RE_THROW();
612-
}
613-
PG_END_TRY();
614-
615-
INSTR_TIME_SET_CURRENT(duration);
616-
INSTR_TIME_SUBTRACT(duration, start);
617-
618-
pgss_store(queryString, INSTR_TIME_GET_DOUBLE(duration), rows);
619-
}
620-
else
621-
{
622-
if (prev_ProcessUtility)
623-
prev_ProcessUtility(parsetree, queryString, params, isTopLevel, dest, completionTag);
624-
else
625-
standard_ProcessUtility(parsetree, queryString, params, isTopLevel, dest, completionTag);
626-
}
627-
}
628-
629552
/*
630553
* Calculate hash value for a key
631554
*/
@@ -664,7 +587,7 @@ pgss_match_fn(const void *key1, const void *key2, Size keysize)
664587
* Store some statistics for a statement.
665588
*/
666589
static void
667-
pgss_store(const char *query, double total_time, uint64 rows)
590+
pgss_store(const char *query, const Instrumentation *instr, uint32 rows)
668591
{
669592
pgssHashKey key;
670593
double usage;
@@ -708,7 +631,7 @@ pgss_store(const char *query, double total_time, uint64 rows)
708631

709632
SpinLockAcquire(&e->mutex);
710633
e->counters.calls += 1;
711-
e->counters.total_time += total_time;
634+
e->counters.total_time += instr->total;
712635
e->counters.rows += rows;
713636
e->counters.usage += usage;
714637
SpinLockRelease(&e->mutex);

doc/src/sgml/pgstatstatements.sgml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgstatstatements.sgml,v 1.3 2009/12/01 01:08:46 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgstatstatements.sgml,v 1.4 2009/12/01 02:31:11 momjian Exp $ -->
22

33
<sect1 id="pgstatstatements">
44
<title>pg_stat_statements</title>
@@ -174,23 +174,6 @@
174174
</listitem>
175175
</varlistentry>
176176

177-
<varlistentry>
178-
<term>
179-
<varname>pg_stat_statements.track_ddl</varname> (<type>boolean</type>)
180-
</term>
181-
182-
<listitem>
183-
<para>
184-
<varname>pg_stat_statements.track_ddl</varname> controls whether DDL
185-
commands are counted by the module.
186-
Specify <literal>on</> to track DDL commands, which excludes <command>SELECT</>,
187-
<command>INSERT</>, <command>UPDATE</> and <command>DELETE</> statements.
188-
The default value is <literal>on</>.
189-
Only superusers can change this setting.
190-
</para>
191-
</listitem>
192-
</varlistentry>
193-
194177
<varlistentry>
195178
<term>
196179
<varname>pg_stat_statements.save</varname> (<type>boolean</type>)

src/backend/tcop/utility.c

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.319 2009/12/01 01:08:46 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.320 2009/12/01 02:31:12 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -58,9 +58,6 @@
5858
#include "utils/syscache.h"
5959

6060

61-
/* Hooks for plugins to get control in ProcessUtility() */
62-
ProcessUtility_hook_type ProcessUtility_hook = NULL;
63-
6461
/*
6562
* Verify user has ownership of specified relation, else ereport.
6663
*
@@ -247,10 +244,6 @@ check_xact_readonly(Node *parsetree)
247244
* completionTag is only set nonempty if we want to return a nondefault status.
248245
*
249246
* completionTag may be NULL if caller doesn't want a status string.
250-
*
251-
* We provide a function hook variable that lets loadable plugins
252-
* get control when ProcessUtility is called. Such a plugin would
253-
* normally call standard_ProcessUtility().
254247
*/
255248
void
256249
ProcessUtility(Node *parsetree,
@@ -267,20 +260,6 @@ ProcessUtility(Node *parsetree,
267260
if (completionTag)
268261
completionTag[0] = '\0';
269262

270-
if (ProcessUtility_hook)
271-
(*ProcessUtility_hook) (parsetree, queryString, params, isTopLevel, dest, completionTag);
272-
else
273-
standard_ProcessUtility(parsetree, queryString, params, isTopLevel, dest, completionTag);
274-
}
275-
276-
void
277-
standard_ProcessUtility(Node *parsetree,
278-
const char *queryString,
279-
ParamListInfo params,
280-
bool isTopLevel,
281-
DestReceiver *dest,
282-
char *completionTag)
283-
{
284263
switch (nodeTag(parsetree))
285264
{
286265
/*

src/include/tcop/utility.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/tcop/utility.h,v 1.36 2009/12/01 01:08:46 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/tcop/utility.h,v 1.37 2009/12/01 02:31:13 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -17,18 +17,9 @@
1717
#include "tcop/tcopprot.h"
1818

1919

20-
/* Hook for plugins to get control in ProcessUtility() */
21-
typedef void (*ProcessUtility_hook_type) (Node *parsetree,
22-
const char *queryString, ParamListInfo params, bool isTopLevel,
23-
DestReceiver *dest, char *completionTag);
24-
extern PGDLLIMPORT ProcessUtility_hook_type ProcessUtility_hook;
25-
2620
extern void ProcessUtility(Node *parsetree, const char *queryString,
2721
ParamListInfo params, bool isTopLevel,
2822
DestReceiver *dest, char *completionTag);
29-
extern void standard_ProcessUtility(Node *parsetree, const char *queryString,
30-
ParamListInfo params, bool isTopLevel,
31-
DestReceiver *dest, char *completionTag);
3223

3324
extern bool UtilityReturnsTuples(Node *parsetree);
3425

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