Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitef51395

Browse files
committed
Revert due to Tom's concerns:
Add ProcessUtility_hook() to handle all DDL tocontrib/pg_stat_statements.
1 parentd85cb27 commitef51395

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/0101:08:45 momjian Exp $
17+
* $PostgreSQL: pgsql/contrib/pg_stat_statements/pg_stat_statements.c,v 1.7 2009/12/0102: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
staticExecutorStart_hook_typeprev_ExecutorStart=NULL;
116114
staticExecutorRun_hook_typeprev_ExecutorRun=NULL;
117115
staticExecutorEnd_hook_typeprev_ExecutorEnd=NULL;
118-
staticProcessUtility_hook_typeprev_ProcessUtility=NULL;
119116

120117
/* Links to shared memory state */
121118
staticpgssSharedState*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-
staticconststructconfig_enum_entrytrack_options[]=
134-
{
130+
staticconststructconfig_enum_entrytrack_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
staticintpgss_max;/* max # statements to track */
142138
staticintpgss_track;/* tracking level */
143-
staticboolpgss_track_ddl;/* whether to track ddl commands */
144139
staticboolpgss_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-
#ifdefNOT_USED
155149
void_PG_fini(void);
156-
#endif
157150

158151
Datumpg_stat_statements_reset(PG_FUNCTION_ARGS);
159152
Datumpg_stat_statements(PG_FUNCTION_ARGS);
@@ -168,12 +161,10 @@ static void pgss_ExecutorRun(QueryDesc *queryDesc,
168161
ScanDirectiondirection,
169162
longcount);
170163
staticvoidpgss_ExecutorEnd(QueryDesc*queryDesc);
171-
staticvoidpgss_ProcessUtility(Node*parsetree,
172-
constchar*queryString,ParamListInfoparams,boolisTopLevel,
173-
DestReceiver*dest,char*completionTag);
174164
staticuint32pgss_hash_fn(constvoid*key,Sizekeysize);
175165
staticintpgss_match_fn(constvoid*key1,constvoid*key2,Sizekeysize);
176-
staticvoidpgss_store(constchar*query,doubletotal_time,uint64rows);
166+
staticvoidpgss_store(constchar*query,
167+
constInstrumentation*instr,uint32rows);
177168
staticSizepgss_memsize(void);
178169
staticpgssEntry*entry_alloc(pgssHashKey*key);
179170
staticvoidentry_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-
#ifdefNOT_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-
staticvoid
580-
pgss_ProcessUtility(Node*parsetree,constchar*queryString,
581-
ParamListInfoparams,boolisTopLevel,
582-
DestReceiver*dest,char*completionTag)
583-
{
584-
if (pgss_track_ddl&&isTopLevel&&pgss_enabled())
585-
{
586-
instr_timestart;
587-
instr_timeduration;
588-
uint64rows=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-
elseif ((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
staticvoid
667-
pgss_store(constchar*query,doubletotal_time,uint64rows)
590+
pgss_store(constchar*query,constInstrumentation*instr,uint32rows)
668591
{
669592
pgssHashKeykey;
670593
doubleusage;
@@ -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/0101:08:46 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/pgstatstatements.sgml,v 1.4 2009/12/0102: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/0101:08:46 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.320 2009/12/0102: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_typeProcessUtility_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-
constchar*queryString,
279-
ParamListInfoparams,
280-
boolisTopLevel,
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/0101:08:46 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/tcop/utility.h,v 1.37 2009/12/0102: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-
typedefvoid (*ProcessUtility_hook_type) (Node*parsetree,
22-
constchar*queryString,ParamListInfoparams,boolisTopLevel,
23-
DestReceiver*dest,char*completionTag);
24-
externPGDLLIMPORTProcessUtility_hook_typeProcessUtility_hook;
25-
2620
externvoidProcessUtility(Node*parsetree,constchar*queryString,
2721
ParamListInfoparams,boolisTopLevel,
2822
DestReceiver*dest,char*completionTag);
29-
externvoidstandard_ProcessUtility(Node*parsetree,constchar*queryString,
30-
ParamListInfoparams,boolisTopLevel,
31-
DestReceiver*dest,char*completionTag);
3223

3324
externboolUtilityReturnsTuples(Node*parsetree);
3425

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp