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

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

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 78 of file delay_execution.c.

79 {
80  /* Set up the GUC to control which lock is used */
81  DefineCustomIntVariable("delay_execution.post_planning_lock_id",
82  "Sets the advisory lock ID to be locked/unlocked after planning.",
83  "Zero disables the delay.",
85  0,
86  0, INT_MAX,
88  0,
89  NULL,
90  NULL,
91  NULL);
92 
93  MarkGUCPrefixReserved("delay_execution");
94 
95  /* Install our hook */
98 }
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:9625
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:9504
@ PGC_USERSET
Definition: guc.h:76
planner_hook_type planner_hook
Definition: planner.c:74

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 45 of file delay_execution.c.

47 {
48  PlannedStmt *result;
49 
50  /* Invoke the planner, possibly via a previous hook user */
52  result = prev_planner_hook(parse, query_string, cursorOptions,
53  boundParams);
54  else
55  result = standard_planner(parse, query_string, cursorOptions,
56  boundParams);
57 
58  /* If enabled, delay by taking and releasing the specified lock */
59  if (post_planning_lock_id != 0)
60  {
65 
66  /*
67  * Ensure that we notice any pending invalidations, since the advisory
68  * lock functions don't do this.
69  */
71  }
72 
73  return result;
74 }
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1683
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:631
void AcceptInvalidationMessages(void)
Definition: inval.c:746
Datum pg_advisory_unlock_int8(PG_FUNCTION_ARGS)
Definition: lockfuncs.c:830
Datum pg_advisory_lock_int8(PG_FUNCTION_ARGS)
Definition: lockfuncs.c:684
PlannedStmt * standard_planner(Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams)
Definition: planner.c:282
static struct subre * parse(struct vars *, int, int, struct state *, struct state *)
Definition: regcomp.c:673

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().