Skip to content

Commit 2f5804f

Browse files
committed
refactoring for PartitionFilter custom node (extract ResultRelInfo cache), introduce copy_stmt_hooking subsystem
1 parent 9476927 commit 2f5804f

File tree

8 files changed

+284
-137
lines changed

8 files changed

+284
-137
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
MODULE_big = pg_pathman
44
OBJS = src/init.o src/relation_info.o src/utils.o src/partition_filter.o src/runtimeappend.o \
55
src/runtime_merge_append.o src/pg_pathman.o src/dsm_array.o src/rangeset.o src/pl_funcs.o \
6-
src/pathman_workers.o src/hooks.o src/nodes_common.o src/xact_handling.o $(WIN32RES)
6+
src/pathman_workers.o src/hooks.o src/nodes_common.o src/xact_handling.o src/copy_stmt_hooking.o \
7+
$(WIN32RES)
78

89
EXTENSION = pg_pathman
910
EXTVERSION = 1.0

src/copy_stmt_hooking.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "copy_stmt_hooking.h"
2+
#include "relation_info.h"
3+
4+
#include "catalog/namespace.h"
5+
#include "commands/copy.h"
6+
7+
8+
/*
9+
* Is pg_pathman supposed to handle this COPY stmt?
10+
*/
11+
bool
12+
is_pathman_related_copy(Node *parsetree)
13+
{
14+
CopyStmt *copy_stmt = (CopyStmt *) parsetree;
15+
Oid partitioned_table;
16+
17+
/* Check that it's a CopyStmt */
18+
if (!IsA(parsetree, CopyStmt))
19+
return false;
20+
21+
/* Also check that stmt->relation exists */
22+
if (!copy_stmt->relation)
23+
return false;
24+
25+
/* TODO: select appropriate lock for COPY */
26+
partitioned_table = RangeVarGetRelid(copy_stmt->relation, NoLock, false);
27+
28+
/* Check that relation is partitioned */
29+
if (get_pathman_relation_info(partitioned_table))
30+
return true;
31+
32+
return false;
33+
}

src/copy_stmt_hooking.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef COPY_STMT_HOOKING_H
2+
#define COPY_STMT_HOOKING_H
3+
4+
5+
#include "postgres.h"
6+
#include "commands/copy.h"
7+
#include "nodes/nodes.h"
8+
9+
10+
bool is_pathman_related_copy(Node *parsetree);
11+
12+
#endif

src/hooks.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* ------------------------------------------------------------------------
99
*/
1010

11+
#include "copy_stmt_hooking.h"
1112
#include "hooks.h"
1213
#include "init.h"
1314
#include "partition_filter.h"
@@ -27,6 +28,7 @@ set_rel_pathlist_hook_type set_rel_pathlist_hook_next = NULL;
2728
planner_hook_type planner_hook_next = NULL;
2829
post_parse_analyze_hook_type post_parse_analyze_hook_next = NULL;
2930
shmem_startup_hook_type shmem_startup_hook_next = NULL;
31+
ProcessUtility_hook_type process_utility_hook_next = NULL;
3032

3133

3234
/* Take care of joins */
@@ -574,3 +576,32 @@ pathman_relcache_hook(Datum arg, Oid relid)
574576
break;
575577
}
576578
}
579+
580+
/*
581+
* Utility function invoker hook.
582+
*/
583+
void
584+
pathman_process_utility_hook(Node *parsetree,
585+
const char *queryString,
586+
ProcessUtilityContext context,
587+
ParamListInfo params,
588+
DestReceiver *dest,
589+
char *completionTag)
590+
{
591+
/* Call hooks set by other extensions */
592+
if (process_utility_hook_next)
593+
process_utility_hook_next(parsetree, queryString,
594+
context, params,
595+
dest, completionTag);
596+
597+
/* Override standard COPY statements if needed */
598+
if (is_pathman_related_copy(parsetree))
599+
{
600+
elog(INFO, "copy!");
601+
}
602+
603+
/* Call internal implementation */
604+
standard_ProcessUtility(parsetree, queryString,
605+
context, params,
606+
dest, completionTag);
607+
}

src/hooks.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
#include "optimizer/paths.h"
1717
#include "parser/analyze.h"
1818
#include "storage/ipc.h"
19+
#include "tcop/utility.h"
1920

2021

2122
extern set_join_pathlist_hook_type set_join_pathlist_next;
2223
extern set_rel_pathlist_hook_type set_rel_pathlist_hook_next;
2324
extern planner_hook_type planner_hook_next;
2425
extern post_parse_analyze_hook_type post_parse_analyze_hook_next;
2526
extern shmem_startup_hook_type shmem_startup_hook_next;
27+
extern ProcessUtility_hook_type process_utility_hook_next;
2628

2729

2830
void pathman_join_pathlist_hook(PlannerInfo *root,
@@ -50,4 +52,11 @@ void pathman_shmem_startup_hook(void);
5052

5153
void pathman_relcache_hook(Datum arg, Oid relid);
5254

55+
void pathman_process_utility_hook(Node *parsetree,
56+
const char *queryString,
57+
ProcessUtilityContext context,
58+
ParamListInfo params,
59+
DestReceiver *dest,
60+
char *completionTag);
61+
5362
#endif

0 commit comments

Comments
 (0)