Skip to content

Commit 2729986

Browse files
committed
refactoring & code cleansing, reformat pg_pathman.c
1 parent 1c1ffaf commit 2729986

File tree

6 files changed

+866
-897
lines changed

6 files changed

+866
-897
lines changed

src/hooks.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "hooks.h"
1616
#include "init.h"
1717
#include "partition_filter.h"
18+
#include "pathman_workers.h"
1819
#include "planner_tree_modification.h"
1920
#include "runtimeappend.h"
2021
#include "runtime_merge_append.h"
@@ -591,7 +592,7 @@ pathman_shmem_startup_hook(void)
591592

592593
/* Allocate shared memory objects */
593594
LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE);
594-
init_shmem_config();
595+
init_concurrent_part_task_slots();
595596
LWLockRelease(AddinShmemInitLock);
596597
}
597598

src/include/init.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,15 @@ extern PathmanInitState pg_pathman_init_state;
9494
#define DEFAULT_INIT_CALLBACK InvalidOid
9595
#define DEFAULT_SPAWN_USING_BGW false
9696

97+
/* Other default values (for GUCs etc) */
98+
#define DEFAULT_PATHMAN_ENABLE true
99+
#define DEFAULT_OVERRIDE_COPY true
100+
97101

98102
/* Lowest version of Pl/PgSQL frontend compatible with internals (0xAA_BB_CC) */
99103
#define LOWEST_COMPATIBLE_FRONT 0x010300
100104

101-
/* Current version on native C library (0xAA_BB_CC) */
105+
/* Current version of native C library (0xAA_BB_CC) */
102106
#define CURRENT_LIB_VERSION 0x010300
103107

104108

@@ -118,9 +122,10 @@ void restore_pathman_init_state(const PathmanInitState *temp_init_state);
118122
*/
119123
void init_main_pathman_toggles(void);
120124

125+
/*
126+
* Shared & local config.
127+
*/
121128
Size estimate_pathman_shmem_size(void);
122-
void init_shmem_config(void);
123-
124129
bool load_config(void);
125130
void unload_config(void);
126131

src/include/pathman.h

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -88,49 +88,15 @@ extern Oid pathman_config_params_relid;
8888
Oid get_pathman_config_relid(bool invalid_is_ok);
8989
Oid get_pathman_config_params_relid(bool invalid_is_ok);
9090

91-
/*
92-
* pg_pathman's global state structure.
93-
*/
94-
typedef struct PathmanState
95-
{
96-
LWLock *dsm_init_lock; /* unused */
97-
} PathmanState;
98-
99-
100-
/*
101-
* Result of search_range_partition_eq().
102-
*/
103-
typedef enum
104-
{
105-
SEARCH_RANGEREL_OUT_OF_RANGE = 0,
106-
SEARCH_RANGEREL_GAP,
107-
SEARCH_RANGEREL_FOUND
108-
} search_rangerel_result;
109-
110-
111-
/*
112-
* pg_pathman's global state.
113-
*/
114-
extern PathmanState *pmstate;
115-
116-
117-
int append_child_relation(PlannerInfo *root, Relation parent_relation,
118-
Index parent_rti, int ir_index, Oid child_oid,
119-
List *wrappers);
120-
121-
search_rangerel_result search_range_partition_eq(const Datum value,
122-
FmgrInfo *cmp_func,
123-
const PartRelationInfo *prel,
124-
RangeEntry *out_re);
12591

126-
uint32 hash_to_part_index(uint32 value, uint32 partitions);
127-
128-
/* copied from allpaths.h */
129-
void set_append_rel_size(PlannerInfo *root, RelOptInfo *rel,
130-
Index rti, RangeTblEntry *rte);
13192
void set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti,
13293
PathKey *pathkeyAsc, PathKey *pathkeyDesc);
13394

95+
Index append_child_relation(PlannerInfo *root, Relation parent_relation,
96+
Index parent_rti, int ir_index, Oid child_oid,
97+
List *wrappers);
98+
99+
134100
typedef struct
135101
{
136102
const Node *orig; /* examined expression */
@@ -148,9 +114,7 @@ typedef struct
148114
bool for_insert; /* are we in PartitionFilter now? */
149115
} WalkerContext;
150116

151-
/*
152-
* Usual initialization procedure for WalkerContext.
153-
*/
117+
/* Usual initialization procedure for WalkerContext */
154118
#define InitWalkerContext(context, prel_vno, prel_info, ecxt, for_ins) \
155119
do { \
156120
(context)->prel_varno = (prel_vno); \
@@ -162,15 +126,37 @@ typedef struct
162126
/* Check that WalkerContext contains ExprContext (plan execution stage) */
163127
#define WcxtHasExprContext(wcxt) ( (wcxt)->econtext )
164128

129+
/* Examine expression in order to select partitions */
130+
WrapperNode *walk_expr_tree(Expr *expr, WalkerContext *context);
131+
132+
165133
void select_range_partitions(const Datum value,
166134
FmgrInfo *cmp_func,
167135
const RangeEntry *ranges,
168136
const int nranges,
169137
const int strategy,
170138
WrapperNode *result);
171139

172-
/* Examine expression in order to select partitions. */
173-
WrapperNode *walk_expr_tree(Expr *expr, WalkerContext *context);
140+
/* Result of search_range_partition_eq() */
141+
typedef enum
142+
{
143+
SEARCH_RANGEREL_OUT_OF_RANGE = 0,
144+
SEARCH_RANGEREL_GAP,
145+
SEARCH_RANGEREL_FOUND
146+
} search_rangerel_result;
147+
148+
search_rangerel_result search_range_partition_eq(const Datum value,
149+
FmgrInfo *cmp_func,
150+
const PartRelationInfo *prel,
151+
RangeEntry *out_re);
152+
153+
154+
/* Convert hash value to the partition index */
155+
static inline uint32
156+
hash_to_part_index(uint32 value, uint32 partitions)
157+
{
158+
return value % partitions;
159+
}
174160

175161

176162
/*

src/include/utils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ void extract_op_func_and_ret_type(char *opname,
5151
Oid *op_func,
5252
Oid *op_ret_type);
5353

54-
5554
/*
5655
* Print values and cast types.
5756
*/

src/init.c

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ init_main_pathman_toggles(void)
163163
"Enables pg_pathman's optimizations during the planner stage",
164164
NULL,
165165
&pg_pathman_init_state.pg_pathman_enable,
166-
true,
166+
DEFAULT_PATHMAN_ENABLE,
167167
PGC_SUSET,
168168
0,
169169
NULL,
@@ -187,7 +187,7 @@ init_main_pathman_toggles(void)
187187
"Override COPY statement handling",
188188
NULL,
189189
&pg_pathman_init_state.override_copy,
190-
true,
190+
DEFAULT_OVERRIDE_COPY,
191191
PGC_SUSET,
192192
0,
193193
NULL,
@@ -259,8 +259,7 @@ unload_config(void)
259259
Size
260260
estimate_pathman_shmem_size(void)
261261
{
262-
return estimate_concurrent_part_task_slots_size() +
263-
MAXALIGN(sizeof(PathmanState));
262+
return estimate_concurrent_part_task_slots_size();
264263
}
265264

266265
/*
@@ -358,33 +357,6 @@ fini_local_cache(void)
358357
parent_cache = NULL;
359358
}
360359

361-
/*
362-
* Initializes pg_pathman's global state (PathmanState) & locks.
363-
*/
364-
void
365-
init_shmem_config(void)
366-
{
367-
bool found;
368-
369-
/* Check if module was initialized in postmaster */
370-
pmstate = ShmemInitStruct("pg_pathman's global state",
371-
sizeof(PathmanState), &found);
372-
if (!found)
373-
{
374-
/*
375-
* Initialize locks in postmaster
376-
*/
377-
if (!IsUnderPostmaster)
378-
{
379-
/* NOTE: dsm_array is redundant, hence the commented code */
380-
/* pmstate->dsm_init_lock = LWLockAssign(); */
381-
}
382-
}
383-
384-
/* Allocate some space for concurrent part slots */
385-
init_concurrent_part_task_slots();
386-
}
387-
388360
/*
389361
* Fill PartRelationInfo with partition-related info.
390362
*/

0 commit comments

Comments
 (0)