Skip to content

Commit f17843f

Browse files
authored
Support PostgreSQL 13.0 and Bug fixes
GridDB FDW v1.3 Support PostgreSQL 13.0 Bug fixes - Fix GridDB return fail when executing IN clause - Fix error hash table corrupted - Fix griddb GetForeignPlan failed - Fix row-key update
1 parent a27fe40 commit f17843f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+18119
-3608
lines changed

Jenkinsfile

+219-57
Large diffs are not rendered by default.

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GridDB Foreign Data Wrapper for PostgreSQL
22

3-
Copyright (c) 2018, TOSHIBA Corporation
3+
Copyright (c) 2020, TOSHIBA Corporation
44
Copyright (c) 2011 - 2016, EnterpriseDB Corporation
55

66
Permission to use, copy, modify, and distribute this software and its

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SHLIB_LINK = $(libpq) -L$(GRIDDB_LIBRARY) -lgridstore
1313
EXTENSION = griddb_fdw
1414
DATA = griddb_fdw--1.0.sql
1515

16-
REGRESS = griddb_fdw griddb_fdw_data_type
16+
REGRESS = griddb_fdw griddb_fdw_data_type float4 float8 int4 int8 numeric join limit aggregates prepare select_having select insert update griddb_fdw_post
1717

1818
ifdef USE_PGXS
1919
PG_CONFIG = pg_config

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# GridDB Foreign Data Wrapper for PostgreSQL
22

33
This PostgreSQL extension is a Foreign Data Wrapper (FDW) for [GridDB][1].
4-
This version of griddb_fdw can work for PostgreSQL 9.6, 10 and 11, 12.
5-
4+
This version of griddb_fdw can work for PostgreSQL 9.6, 10, 11, 12 and 13. It is confirmed in GridDB 4.5.
65

76
## 1. Installation
87
griddb_fdw requires GridDB's C client library. This library can be downloaded from the [GridDB][1] website on github[1].

compare.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* GridDB Foreign Data Wrapper
33
*
4-
* Portions Copyright (c) 2019, TOSHIBA CORPORATION
4+
* Portions Copyright (c) 2020, TOSHIBA CORPORATION
55
*
66
* IDENTIFICATION
77
* compare.c

connection.c

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* GridDB Foreign Data Wrapper
33
*
4-
* Portions Copyright (c) 2018, TOSHIBA CORPORATION
4+
* Portions Copyright (c) 2020, TOSHIBA CORPORATION
55
*
66
* IDENTIFICATION
77
* connection.c
@@ -49,7 +49,7 @@ typedef Oid ContCacheKey;
4949
*/
5050
typedef struct ContCacheEntry
5151
{
52-
ConnCacheKey key; /* hash key (must be first) */
52+
ContCacheKey key; /* hash key (must be first) */
5353
GSContainer *cont;
5454
} ContCacheEntry;
5555

@@ -264,7 +264,7 @@ griddb_get_container(UserMapping *user, Oid relid, GSGridStore * store)
264264
HASHCTL ctl;
265265

266266
MemSet(&ctl, 0, sizeof(ctl));
267-
ctl.keysize = sizeof(ConnCacheKey);
267+
ctl.keysize = sizeof(ContCacheKey);
268268
ctl.entrysize = sizeof(ContCacheEntry);
269269
conn_entry->cont_hash = hash_create("griddb_fdw containers", 8,
270270
&ctl,
@@ -432,17 +432,26 @@ griddb_end_xact(ConnCacheEntry *entry, bool isCommit, GSGridStore * store)
432432
GSResult ret;
433433
GSContainer *cont = cont_entry->cont;
434434

435-
if (isCommit)
436-
ret = gsCommit(cont);
437-
else
438-
ret = gsAbort(cont);
439-
if (!GS_SUCCEEDED(ret))
440-
griddb_REPORT_ERROR(ERROR, ret, cont);
435+
if (cont_entry->cont != NULL)
436+
{
437+
438+
if (isCommit)
439+
ret = gsCommit(cont);
440+
else
441+
ret = gsAbort(cont);
442+
if (!GS_SUCCEEDED(ret))
443+
griddb_REPORT_ERROR(ERROR, ret, cont);
441444

442-
gsCloseContainer(&cont, true);
443-
if (hash_search(entry->cont_hash, &cont_entry->key, HASH_REMOVE, NULL) == NULL)
444-
elog(ERROR, "hash table corrupted");
445+
gsCloseContainer(&cont, true);
446+
}
447+
448+
/* Remove container from the hash list even if it is NULL or not */
449+
hash_search(entry->cont_hash, &cont_entry->key, HASH_REMOVE, NULL);
445450
}
451+
452+
/* Destroy container hash list after use to avoid memory leak. */
453+
hash_destroy(entry->cont_hash);
454+
entry->cont_hash = NULL;
446455
}
447456

448457
/*

deparse.c

+88-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* GridDB Foreign Data Wrapper
33
*
4-
* Portions Copyright (c) 2018, TOSHIBA CORPORATION
4+
* Portions Copyright (c) 2020, TOSHIBA CORPORATION
55
*
66
* IDENTIFICATION
77
* deparse.c
@@ -32,6 +32,7 @@
3232
#include "utils/rel.h"
3333
#include "utils/relcache.h"
3434
#include "utils/syscache.h"
35+
#include "time.h"
3536

3637
/*
3738
* Global context for foreign_expr_walker's search of an expression tree.
@@ -180,7 +181,7 @@ griddb_deparse_select(StringInfo buf,
180181
* Core code already has some lock on each rel being planned, so we can
181182
* use NoLock here.
182183
*/
183-
rel = heap_open(rte->relid, NoLock);
184+
rel = table_open(rte->relid, NoLock);
184185

185186
appendStringInfoString(buf, "SELECT ");
186187
griddb_deparse_target_list(buf, root, baserel->relid, rel,
@@ -202,7 +203,7 @@ griddb_deparse_select(StringInfo buf,
202203
if (pathkeys)
203204
griddb_append_order_by_clause(pathkeys, &context);
204205

205-
heap_close(rel, NoLock);
206+
table_close(rel, NoLock);
206207
}
207208

208209
/*
@@ -582,7 +583,11 @@ griddb_deparse_func_expr(FuncExpr *node, deparse_expr_cxt *context)
582583
{
583584
if (!first)
584585
appendStringInfoString(buf, ", ");
586+
#if (PG_VERSION_NUM >= 130000)
587+
if (use_variadic && lnext(node->args, arg) == NULL)
588+
#else
585589
if (use_variadic && lnext(arg) == NULL)
590+
#endif
586591
elog(ERROR, "VARIADIC is not supported");
587592
deparseExpr((Expr *) lfirst(arg), context);
588593
first = false;
@@ -747,16 +752,31 @@ griddb_deparse_scalar_array_op_expr(ScalarArrayOpExpr *node, deparse_expr_cxt *c
747752
if (strcmp(opname, "<>") == 0)
748753
notIn = true;
749754

755+
arg1 = linitial(node->args);
750756
arg2 = lsecond(node->args);
751757
c = (Const *) arg2;
752758
Assert(nodeTag((Node *) arg2) == T_Const || c->constisnull);
753759

754760
getTypeOutputInfo(c->consttype,
755761
&typoutput, &typIsVarlena);
756762
extval = OidOutputFunctionCall(typoutput, c->constvalue);
757-
isstr = true;
758-
if (c->consttype == INT4ARRAYOID || c->consttype == OIDARRAYOID)
759-
isstr = false;
763+
switch (c->consttype)
764+
{
765+
case BOOLARRAYOID:
766+
case INT8ARRAYOID:
767+
case INT2ARRAYOID:
768+
case INT4ARRAYOID:
769+
case OIDARRAYOID:
770+
case FLOAT4ARRAYOID:
771+
case FLOAT8ARRAYOID:
772+
case TIMESTAMPARRAYOID:
773+
case TIMESTAMPTZARRAYOID:
774+
isstr = false;
775+
break;
776+
default:
777+
isstr = true;
778+
break;
779+
}
760780

761781
/* Deparse right operand. */
762782
deparseLeft = true;
@@ -772,7 +792,12 @@ griddb_deparse_scalar_array_op_expr(ScalarArrayOpExpr *node, deparse_expr_cxt *c
772792
/* Deparse left operand. */
773793
if (deparseLeft)
774794
{
775-
arg1 = linitial(node->args);
795+
/* No need deparse bool column */
796+
if (c->consttype == BOOLARRAYOID)
797+
{
798+
deparseLeft = false;
799+
continue;
800+
}
776801
deparseExpr(arg1, context);
777802
if (notIn)
778803
appendStringInfo(buf, " <> ");
@@ -812,9 +837,62 @@ griddb_deparse_scalar_array_op_expr(ScalarArrayOpExpr *node, deparse_expr_cxt *c
812837
appendStringInfo(buf, " AND ");
813838
else
814839
appendStringInfo(buf, " OR ");
840+
841+
/* No need deparse bool column */
842+
if (c->consttype == BOOLARRAYOID)
843+
{
844+
deparseLeft = false;
845+
continue;
846+
}
847+
815848
deparseLeft = true;
816849
continue;
817850
}
851+
852+
/* When compare with timestamp column, need to convert and cast to TIMESTAMP */
853+
if (c->consttype == TIMESTAMPARRAYOID || c->consttype == TIMESTAMPTZARRAYOID)
854+
{
855+
char timestamp[MAXDATELEN + 1];
856+
char chtime[MAXDATELEN + 1] = {0};
857+
struct tm tm;
858+
int j = 0;
859+
860+
for (;; valptr++)
861+
{
862+
if (*valptr == '\"' && !isEscape)
863+
{
864+
inString = !inString;
865+
break;
866+
}
867+
chtime[j] = *valptr;
868+
j++;
869+
}
870+
i += j;
871+
872+
/* Format of chtime is YYYY-MM-DD HH:MM:SS */
873+
strptime(chtime, "%Y-%m-%d %H:%M:%S", &tm);
874+
griddb_convert_pg2gs_timestamp_string(time_t_to_timestamptz(timegm(&tm)), timestamp);
875+
appendStringInfoString(buf, "TIMESTAMP(");
876+
griddb_deparse_string_literal(buf, timestamp);
877+
appendStringInfoString(buf, ")");
878+
continue;
879+
}
880+
881+
/*
882+
* GridDB not support compare bool column with true, false.
883+
* Only support column or NOT column
884+
*/
885+
if (c->consttype == BOOLARRAYOID)
886+
{
887+
appendStringInfoChar(buf, '(');
888+
if (ch == 'f')
889+
appendStringInfoString(buf, "NOT ");
890+
891+
deparseExpr(arg1, context);
892+
appendStringInfoChar(buf, ')');
893+
continue;
894+
}
895+
818896
appendStringInfoChar(buf, ch);
819897
}
820898
if (isstr)
@@ -1355,7 +1433,7 @@ foreign_expr_walker(Node *node,
13551433
* Returns true if given expr is safe to evaluate on the foreign server.
13561434
*/
13571435
bool
1358-
is_foreign_expr(PlannerInfo *root,
1436+
griddb_is_foreign_expr(PlannerInfo *root,
13591437
RelOptInfo *baserel,
13601438
Expr *expr)
13611439
{
@@ -1414,7 +1492,7 @@ griddb_append_order_by_clause(List *pathkeys, deparse_expr_cxt *context)
14141492
PathKey *pathkey = (PathKey *) lfirst(lcell);
14151493
Expr *em_expr;
14161494

1417-
em_expr = find_em_expr_for_rel(pathkey->pk_eclass, baserel);
1495+
em_expr = griddb_find_em_expr_for_rel(pathkey->pk_eclass, baserel);
14181496
Assert(em_expr != NULL);
14191497

14201498
appendStringInfoString(buf, delim);
@@ -1518,7 +1596,7 @@ griddb_classify_conditions(PlannerInfo *root,
15181596
{
15191597
RestrictInfo *ri = (RestrictInfo *) lfirst(lc);
15201598

1521-
if (is_foreign_expr(root, baserel, ri->clause))
1599+
if (griddb_is_foreign_expr(root, baserel, ri->clause))
15221600
*remote_conds = lappend(*remote_conds, ri);
15231601
else
15241602
*local_conds = lappend(*local_conds, ri);

0 commit comments

Comments
 (0)