Skip to content

Commit d5aa7a9

Browse files
committed
Avoid unnecessary snapshot-acquisitions in BuildCachedPlan.
I had copied-and-pasted a claim that we couldn't reach this point when dealing with utility statements, but that was a leftover from when the caller was required to supply a plan to start with. We now will go through here at least once when handling a utility statement, so it seems worth a check to see whether a snapshot is actually needed. (Note that analyze_requires_snapshot is quite a cheap test.) Per suggestion from Yamamoto Takashi. I don't think I believe that this resolves his reported assertion failure; but it's worth changing anyway, just to save a cycle or two.
1 parent 2594ad7 commit d5aa7a9

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/backend/utils/cache/plancache.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "nodes/nodeFuncs.h"
5555
#include "optimizer/planmain.h"
5656
#include "optimizer/prep.h"
57+
#include "parser/analyze.h"
5758
#include "parser/parsetree.h"
5859
#include "storage/lmgr.h"
5960
#include "tcop/pquery.h"
@@ -756,14 +757,12 @@ BuildCachedPlan(CachedPlanSource *plansource, List *qlist,
756757
PushOverrideSearchPath(plansource->search_path);
757758

758759
/*
759-
* If a snapshot is already set (the normal case), we can just use
760-
* that for parsing/planning. But if it isn't, install one. Note: no
761-
* point in checking whether parse analysis requires a snapshot;
762-
* utility commands don't have invalidatable plans, so we'd not get
763-
* here for such a command.
760+
* If a snapshot is already set (the normal case), we can just use that
761+
* for planning. But if it isn't, and we need one, install one.
764762
*/
765763
snapshot_set = false;
766-
if (!ActiveSnapshotSet())
764+
if (!ActiveSnapshotSet() &&
765+
analyze_requires_snapshot(plansource->raw_parse_tree))
767766
{
768767
PushActiveSnapshot(GetTransactionSnapshot());
769768
snapshot_set = true;

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