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)
 
void _PG_fini (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_fini()

void _PG_fini ( void  )

Definition at line 101 of file delay_execution.c.

References planner_hook, and prev_planner_hook.

102 {
104 }
static planner_hook_type prev_planner_hook
planner_hook_type planner_hook
Definition: planner.c:74

◆ _PG_init()

void _PG_init ( void  )

Definition at line 79 of file delay_execution.c.

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

80 {
81  /* Set up the GUC to control which lock is used */
82  DefineCustomIntVariable("delay_execution.post_planning_lock_id",
83  "Sets the advisory lock ID to be locked/unlocked after planning.",
84  "Zero disables the delay.",
86  0,
87  0, INT_MAX,
89  0,
90  NULL,
91  NULL,
92  NULL);
93 
94  /* Install our hook */
97 }
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:8920
static PlannedStmt * delay_execution_planner(Query *parse, const char *query_string, int cursorOptions, ParamListInfo boundParams)
static planner_hook_type prev_planner_hook
planner_hook_type planner_hook
Definition: planner.c:74
static int post_planning_lock_id

◆ delay_execution_planner()

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

Definition at line 46 of file delay_execution.c.

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

Referenced by _PG_init().

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

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_fini(), _PG_init(), and delay_execution_planner().