PostgreSQL Source Code  git master
delay_execution.c File Reference
#include "postgres.h"
#include <limits.h>
#include "optimizer/planner.h"
#include "utils/builtins.h"
#include "utils/guc.h"
#include "utils/inval.h"
Include dependency graph for delay_execution.c:

Go to the source code of this file.

Functions

static PlannedStmtdelay_execution_planner (Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams)
 
void _PG_init (void)
 

Variables

 PG_MODULE_MAGIC
 
static int post_planning_lock_id = 0
 
static planner_hook_type prev_planner_hook = NULL
 

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 75 of file delay_execution.c.

76 {
77  /* Set up the GUC to control which lock is used */
78  DefineCustomIntVariable("delay_execution.post_planning_lock_id",
79  "Sets the advisory lock ID to be locked/unlocked after planning.",
80  "Zero disables the delay.",
82  0,
83  0, INT_MAX,
85  0,
86  NULL,
87  NULL,
88  NULL);
89 
90  MarkGUCPrefixReserved("delay_execution");
91 
92  /* Install our hook */
95 }
static PlannedStmt * delay_execution_planner(Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams)
static planner_hook_type prev_planner_hook
static int post_planning_lock_id
void MarkGUCPrefixReserved(const char *className)
Definition: guc.c:5102
void DefineCustomIntVariable(const char *name, const char *short_desc, const char *long_desc, int *valueAddr, int bootValue, int minValue, int maxValue, GucContext context, int flags, GucIntCheckHook check_hook, GucIntAssignHook assign_hook, GucShowHook show_hook)
Definition: guc.c:4981
@ PGC_USERSET
Definition: guc.h:75
planner_hook_type planner_hook
Definition: planner.c:77

References DefineCustomIntVariable(), delay_execution_planner(), MarkGUCPrefixReserved(), PGC_USERSET, planner_hook, post_planning_lock_id, and prev_planner_hook.

◆ delay_execution_planner()

static PlannedStmt* delay_execution_planner ( Query parse,
const char *  query_string,
int  cursorOptions,
ParamListInfo  boundParams 
)
static

Definition at line 42 of file delay_execution.c.

44 {
45  PlannedStmt *result;
46 
47  /* Invoke the planner, possibly via a previous hook user */
49  result = prev_planner_hook(parse, query_string, cursorOptions,
50  boundParams);
51  else
52  result = standard_planner(parse, query_string, cursorOptions,
53  boundParams);
54 
55  /* If enabled, delay by taking and releasing the specified lock */
56  if (post_planning_lock_id != 0)
57  {
62 
63  /*
64  * Ensure that we notice any pending invalidations, since the advisory
65  * lock functions don't do this.
66  */
68  }
69 
70  return result;
71 }
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1794
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:642
void AcceptInvalidationMessages(void)
Definition: inval.c:746
Datum pg_advisory_unlock_int8(PG_FUNCTION_ARGS)
Definition: lockfuncs.c:850
Datum pg_advisory_lock_int8(PG_FUNCTION_ARGS)
Definition: lockfuncs.c:704
PlannedStmt * standard_planner(Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams)
Definition: planner.c:286
static struct subre * parse(struct vars *v, int stopper, int type, struct state *init, struct state *final)
Definition: regcomp.c:717

References AcceptInvalidationMessages(), DirectFunctionCall1, Int64GetDatum(), parse(), pg_advisory_lock_int8(), pg_advisory_unlock_int8(), post_planning_lock_id, prev_planner_hook, and standard_planner().

Referenced by _PG_init().

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 31 of file delay_execution.c.

◆ post_planning_lock_id

int post_planning_lock_id = 0
static

Definition at line 34 of file delay_execution.c.

Referenced by _PG_init(), and delay_execution_planner().

◆ prev_planner_hook

planner_hook_type prev_planner_hook = NULL
static

Definition at line 37 of file delay_execution.c.

Referenced by _PG_init(), and delay_execution_planner().