Skip to content

Commit 0c2f5df

Browse files
committed
Intermediate commit for many efforts saving: exchange node (without transport) + planner base rules
1 parent 678ac3d commit 0c2f5df

29 files changed

+2533
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ lib*.pc
4444
/tmp_install/
4545
/.cproject
4646
/.project
47+
/.gdb_history
4748
/.settings/

contrib/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ SUBDIRS = \
3030
pageinspect \
3131
passwordcheck \
3232
pg_buffercache \
33+
pg_exchange \
3334
pg_execplan \
3435
pg_freespacemap \
3536
pg_prewarm \

contrib/pg_exchange/LICENSE

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ParGRES is released under the PostgreSQL License, a liberal Open Source license, similar to the BSD or MIT licenses.
2+
3+
Copyright (c) 2018-2019, Postgres Professional
4+
Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
5+
Portions Copyright (c) 1994, The Regents of the University of California
6+
7+
Permission to use, copy, modify, and distribute this software and its documentation for any purpose, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and this paragraph and the following two paragraphs appear in all copies.
8+
9+
IN NO EVENT SHALL POSTGRES PROFESSIONAL BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF POSTGRES PROFESSIONAL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10+
11+
POSTGRES PROFESSIONAL SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND POSTGRES PROFESSIONAL HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

contrib/pg_exchange/Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# contrib/pg_exchange/Makefile
2+
3+
MODULE_big = pg_exchange
4+
EXTENSION = pg_exchange
5+
EXTVERSION = 0.1
6+
PGFILEDESC = "pg_exchange - an exchange custom node and rules for the planner"
7+
MODULES = pg_exchange
8+
OBJS = pg_exchange.o exchange.o connection.o hooks.o common.o nodeDummyscan.o nodeDistPlanExec.o $(WIN32RES)
9+
10+
fdw_srcdir = $(top_srcdir)/contrib/postgres_fdw/
11+
12+
PG_CPPFLAGS = -I$(libpq_srcdir) -I$(fdw_srcdir) -L$(fdw_srcdir)
13+
SHLIB_LINK_INTERNAL = $(libpq)
14+
15+
DATA_built = $(EXTENSION)--$(EXTVERSION).sql
16+
17+
ifdef USE_PGXS
18+
PG_CONFIG = pg_config
19+
PGXS := $(shell $(PG_CONFIG) --pgxs)
20+
include $(PGXS)
21+
else
22+
EXTRA_INSTALL = contrib/postgres_fdw
23+
SHLIB_PREREQS = submake-libpq
24+
subdir = contrib/pg_exchange
25+
top_builddir = ../..
26+
include $(top_builddir)/src/Makefile.global
27+
include $(top_srcdir)/contrib/contrib-global.mk
28+
endif
29+
30+
$(EXTENSION)--$(EXTVERSION).sql: init.sql
31+
cat $^ > $@

contrib/pg_exchange/common.c

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/* ------------------------------------------------------------------------
2+
*
3+
* common.c
4+
* Common code for ParGRES extension
5+
*
6+
* Copyright (c) 2018, Postgres Professional
7+
*
8+
* ------------------------------------------------------------------------
9+
*/
10+
11+
#include "postgres.h"
12+
13+
#include "access/heapam.h"
14+
#include "access/htup_details.h"
15+
#include "access/genam.h"
16+
#include "access/sysattr.h"
17+
#include "access/xact.h"
18+
#include "catalog/indexing.h"
19+
#include "catalog/pg_extension.h"
20+
#include "commands/extension.h"
21+
#include "utils/fmgroids.h"
22+
23+
#include "common.h"
24+
25+
26+
/* GUC variables */
27+
int node_number;
28+
int nodes_at_cluster;
29+
char *pargres_hosts_string = NULL;
30+
char *pargres_ports_string = NULL;
31+
int eports_pool_size = 100;
32+
33+
int CoordNode = -1;
34+
bool PargresInitialized = false;
35+
PortStack *PORTS;
36+
37+
38+
Oid
39+
get_pargres_schema(void)
40+
{
41+
Oid result;
42+
Relation rel;
43+
SysScanDesc scandesc;
44+
HeapTuple tuple;
45+
ScanKeyData entry[1];
46+
Oid ext_oid;
47+
48+
/* It's impossible to fetch pg_pathman's schema now */
49+
if (!IsTransactionState())
50+
return InvalidOid;
51+
52+
ext_oid = get_extension_oid("pargres", true);
53+
if (ext_oid == InvalidOid)
54+
return InvalidOid; /* exit if pg_pathman does not exist */
55+
56+
ScanKeyInit(&entry[0],
57+
ObjectIdAttributeNumber,
58+
BTEqualStrategyNumber, F_OIDEQ,
59+
ObjectIdGetDatum(ext_oid));
60+
61+
rel = heap_open(ExtensionRelationId, AccessShareLock);
62+
scandesc = systable_beginscan(rel, ExtensionOidIndexId, true,
63+
NULL, 1, entry);
64+
65+
tuple = systable_getnext(scandesc);
66+
67+
/* We assume that there can be at most one matching tuple */
68+
if (HeapTupleIsValid(tuple))
69+
result = ((Form_pg_extension) GETSTRUCT(tuple))->extnamespace;
70+
else
71+
result = InvalidOid;
72+
73+
systable_endscan(scandesc);
74+
75+
heap_close(rel, AccessShareLock);
76+
77+
return result;
78+
}
79+
80+
void
81+
STACK_Init(PortStack *stack, int range_min, int size)
82+
{
83+
int i;
84+
85+
LWLockAcquire(&stack->lock, LW_EXCLUSIVE);
86+
87+
stack->size = size;
88+
stack->index = 0;
89+
for (i = 0; i < stack->size; i++)
90+
stack->values[i] = range_min + i;
91+
92+
LWLockRelease(&stack->lock);
93+
}
94+
95+
int
96+
STACK_Pop(PortStack *stack)
97+
{
98+
int value;
99+
100+
LWLockAcquire(&stack->lock, LW_EXCLUSIVE);
101+
102+
Assert(stack->index < stack->size);
103+
value = stack->values[stack->index++];
104+
105+
LWLockRelease(&stack->lock);
106+
return value;
107+
}
108+
109+
void
110+
STACK_Push(PortStack *stack, int value)
111+
{
112+
LWLockAcquire(&stack->lock, LW_EXCLUSIVE);
113+
114+
Assert(stack->index > 0);
115+
stack->values[--stack->index] = value;
116+
117+
LWLockRelease(&stack->lock);
118+
}

contrib/pg_exchange/common.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* common.h
4+
* Common code for ParGRES extension
5+
*
6+
* Copyright (c) 2018, PostgreSQL Global Development Group
7+
* Author: Andrey Lepikhov <a.lepikhov@postgrespro.ru>
8+
*
9+
* IDENTIFICATION
10+
* contrib/pargres/common.h
11+
*
12+
*-------------------------------------------------------------------------
13+
*/
14+
15+
#ifndef COMMON_H_
16+
#define COMMON_H_
17+
18+
#include "nodes/pg_list.h"
19+
#include "storage/lock.h"
20+
21+
22+
typedef struct
23+
{
24+
LWLock lock;
25+
int size;
26+
int index;
27+
int values[FLEXIBLE_ARRAY_MEMBER];
28+
} PortStack;
29+
30+
31+
/* GUC variables */
32+
extern int node_number;
33+
extern int nodes_at_cluster;
34+
extern char *pargres_hosts_string;
35+
extern char *pargres_ports_string;
36+
extern int eports_pool_size;
37+
38+
extern PortStack *PORTS;
39+
extern int CoordNode;
40+
extern bool PargresInitialized;
41+
42+
43+
extern Oid get_pargres_schema(void);
44+
extern void STACK_Init(PortStack *stack, int range_min, int size);
45+
int STACK_Pop(PortStack *stack);
46+
void STACK_Push(PortStack *stack, int value);
47+
48+
#endif /* COMMON_H_ */

0 commit comments

Comments
 (0)