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

Commit0e23588

Browse files
committed
Fix performance issue in EXPLAIN (ANALYZE, TIMING OFF).
Commitaf7914c, which added the TIMINGoption to EXPLAIN, had an oversight: if the TIMING option is disabledthen control in InstrStartNode() goes through an elog(DEBUG2) call, whichtypically does nothing but takes a noticeable amount of time to do it.Tweak the logic to avoid that.In HEAD, also change the elog(DEBUG2)'s in instrument.c to elog(ERROR).It's not very clear why they weren't like that to begin with, but thisepisode shows that not complaining more vociferously about misuse islikely to do little except allow bugs to remain hidden.While at it, adjust some code that was making possibly-dangerousassumptions about flag bits being in the rightmost byte of theinstrument_options word.Problem reported by Pavel Stehule (via Tomas Vondra).
1 parente9c4a62 commit0e23588

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

‎src/backend/executor/instrument.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ InstrAlloc(int n, int instrument_options)
3333
instr=palloc0(n*sizeof(Instrumentation));
3434
if (instrument_options& (INSTRUMENT_BUFFERS |INSTRUMENT_TIMER))
3535
{
36+
boolneed_buffers= (instrument_options&INSTRUMENT_BUFFERS)!=0;
37+
boolneed_timer= (instrument_options&INSTRUMENT_TIMER)!=0;
3638
inti;
37-
boolneed_buffers=instrument_options&INSTRUMENT_BUFFERS;
38-
boolneed_timer=instrument_options&INSTRUMENT_TIMER;
3939

4040
for (i=0;i<n;i++)
4141
{
@@ -51,10 +51,13 @@ InstrAlloc(int n, int instrument_options)
5151
void
5252
InstrStartNode(Instrumentation*instr)
5353
{
54-
if (instr->need_timer&&INSTR_TIME_IS_ZERO(instr->starttime))
55-
INSTR_TIME_SET_CURRENT(instr->starttime);
56-
else
57-
elog(DEBUG2,"InstrStartNode called twice in a row");
54+
if (instr->need_timer)
55+
{
56+
if (INSTR_TIME_IS_ZERO(instr->starttime))
57+
INSTR_TIME_SET_CURRENT(instr->starttime);
58+
else
59+
elog(DEBUG2,"InstrStartNode called twice in a row");
60+
}
5861

5962
/* save buffer usage totals at node entry, if needed */
6063
if (instr->need_bufusage)
@@ -73,7 +76,6 @@ InstrStopNode(Instrumentation *instr, double nTuples)
7376
/* let's update the time only if the timer was requested */
7477
if (instr->need_timer)
7578
{
76-
7779
if (INSTR_TIME_IS_ZERO(instr->starttime))
7880
{
7981
elog(DEBUG2,"InstrStopNode called without start");
@@ -84,7 +86,6 @@ InstrStopNode(Instrumentation *instr, double nTuples)
8486
INSTR_TIME_ACCUM_DIFF(instr->counter,endtime,instr->starttime);
8587

8688
INSTR_TIME_SET_ZERO(instr->starttime);
87-
8889
}
8990

9091
/* Add delta of buffer usage since entry to node's totals */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp