Skip to content

Commit

Permalink
Remove AUTHOID syscache access from _PG_init(). (#156)
Browse files Browse the repository at this point in the history
* Remove AUTHOID syscache access from _PG_init(). This causes problems for parallel workers. See BUG #15350 Getting invalid cache ID: 11 Errors

* Replace all occurences of GEOMETRYOID with ogrGetGeometryOid() to ensure we have always loaded the Oid for geometry before testing for it.
  • Loading branch information
mccuskk authored and pramsey committed Sep 3, 2018
1 parent 73571fa commit 2d6aa7a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
38 changes: 24 additions & 14 deletions ogr_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,6 @@ ogrErrorHandler(CPLErr eErrClass, int err_no, const char *msg)
void
_PG_init(void)
{
Oid typoid = TypenameGetTypid("geometry");
if (OidIsValid(typoid) && get_typisdefined(typoid))
{
GEOMETRYOID = typoid;
}
else
{
GEOMETRYOID = BYTEAOID;
}

on_proc_exit(&ogr_fdw_exit, PointerGetDatum(NULL));

Expand All @@ -220,6 +211,25 @@ ogr_fdw_exit(int code, Datum arg)
OGRCleanupAll();
}

/*
* Function to get the geometry OID if required
*/
Oid ogrGetGeometryOid(void)
{
if (GEOMETRYOID == InvalidOid) {
Oid typoid = TypenameGetTypid("geometry");
if (OidIsValid(typoid) && get_typisdefined(typoid))
{
GEOMETRYOID = typoid;
}
else
{
GEOMETRYOID = BYTEAOID;
}
}

return GEOMETRYOID;
}

/*
* Foreign-data wrapper handler function: return a struct with pointers
Expand Down Expand Up @@ -1175,7 +1185,7 @@ ogrReadColumnData(OgrFdwState *state)

/* If the OGR source has geometries, can we match them to Pg columns? */
/* We'll match to the first ones we find, irrespective of name */
if ( geom_count < ogr_geom_count && col.pgtype == GEOMETRYOID )
if ( geom_count < ogr_geom_count && col.pgtype == ogrGetGeometryOid() )
{
col.ogrvariant = OGR_GEOMETRY;
col.ogrfldtype = OFTBinary;
Expand Down Expand Up @@ -1256,7 +1266,7 @@ ogrLookupGeometryFunctionOid(const char *proname)
FuncCandidateList clist;

/* This only works if PostGIS is installed */
if ( GEOMETRYOID == InvalidOid || GEOMETRYOID == BYTEAOID )
if ( ogrGetGeometryOid() == InvalidOid || ogrGetGeometryOid() == BYTEAOID )
return InvalidOid;

names = stringToQualifiedNameList(proname);
Expand All @@ -1272,7 +1282,7 @@ ogrLookupGeometryFunctionOid(const char *proname)
int i;
for ( i = 0; i < clist->nargs; i++ )
{
if ( clist->args[i] == GEOMETRYOID )
if ( clist->args[i] == ogrGetGeometryOid() )
return clist->oid;
}
}
Expand Down Expand Up @@ -1485,7 +1495,7 @@ ogrFeatureToSlot(const OGRFeatureH feat, TupleTableSlot *slot, const OgrFdwExecS
nulls[i] = false;
values[i] = PointerGetDatum(varlena);
}
else if ( pgtype == GEOMETRYOID )
else if ( pgtype == ogrGetGeometryOid() )
{
/*
* For geometry we need to convert the varlena WKB data into a serialized
Expand Down Expand Up @@ -2619,7 +2629,7 @@ ogrImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
quote_identifier(server->servername),
launder_table_names,
launder_column_names,
GEOMETRYOID != BYTEAOID,
ogrGetGeometryOid() != BYTEAOID,
&buf
);

Expand Down
4 changes: 1 addition & 3 deletions ogr_fdw.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ typedef struct OgrFdwModifyState
/* Shared function signatures */
bool ogrDeparse(StringInfo buf, PlannerInfo *root, RelOptInfo *foreignrel, List *exprs, OgrFdwState *state, List **param);


/* Shared global value of the Geometry OId */
extern Oid GEOMETRYOID;
Oid ogrGetGeometryOid(void);

#endif /* _OGR_FDW_H */
18 changes: 9 additions & 9 deletions ogr_fdw_deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ogrStringFromDatum(Datum datum, Oid type)
initStringInfo(&result);

/* Special handling to convert a geometry to a bbox needed here */
if ( type == GEOMETRYOID )
if ( type == ogrGetGeometryOid() )
{
elog(ERROR, "got a GEOMETRY!");
return NULL;
Expand Down Expand Up @@ -128,7 +128,7 @@ ogrDeparseConst(Const* constant, OgrDeparseCtx *context)
appendStringInfoString(context->buf, "NULL");
}
/* Use geometry as a spatial filter? */
else if ( constant->consttype == GEOMETRYOID )
else if ( constant->consttype == ogrGetGeometryOid() )
{
/*
* For geometry we need to convert the gserialized constant into
Expand Down Expand Up @@ -355,7 +355,7 @@ ogrDeparseOpExpr(OpExpr* node, OgrDeparseCtx *context)
// else
// return false;

// if ( constant->consttype != GEOMETRYOID )
// if ( constant->consttype != ogrGetGeometryOid() )

ReleaseSysCache(tuple);

Expand Down Expand Up @@ -483,12 +483,12 @@ ogrDeparseNullTest(NullTest *node, OgrDeparseCtx *context)
{
StringInfo buf = context->buf;

appendStringInfoChar(buf, '(');
ogrDeparseExpr(node->arg, context);
if (node->nulltesttype == IS_NULL)
appendStringInfoString(buf, " IS NULL)");
else
appendStringInfoString(buf, " IS NOT NULL)");
appendStringInfoChar(buf, '(');
ogrDeparseExpr(node->arg, context);
if (node->nulltesttype == IS_NULL)
appendStringInfoString(buf, " IS NULL)");
else
appendStringInfoString(buf, " IS NOT NULL)");

return true;
}
Expand Down

0 comments on commit 2d6aa7a

Please sign in to comment.