Split imported code in multiple files in a dedicated directory

(cherry picked from commit b5e50e6429)
This commit is contained in:
Julien Rouhaud 2019-04-08 22:47:16 +02:00
parent b3a84ff16a
commit fa9be3ff1d
5 changed files with 122 additions and 77 deletions

View file

@ -7,7 +7,11 @@ REGRESS_OPTS = --inputdir=test
PG_CONFIG = pg_config
MODULE_big = hypopg
OBJS = hypopg.o hypopg_import.o hypopg_index.o
OBJS = hypopg.o \
hypopg_index.o \
import/hypopg_import.o \
import/hypopg_import_index.o
all:

68
import/hypopg_import.c Normal file
View file

@ -0,0 +1,68 @@
/*-------------------------------------------------------------------------
*
* hypopg_import.c: Import of some PostgreSQL private fuctions.
*
* This program is open source, licensed under the PostgreSQL license.
* For license terms, see the LICENSE file.
*
* Copyright (c) 2008-2018, PostgreSQL Global Development Group
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#if PG_VERSION_NUM >= 90300
#include "access/htup_details.h"
#endif
#include "catalog/namespace.h"
#include "catalog/pg_opclass.h"
#include "commands/defrem.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
#include "include/hypopg_import.h"
/*
* Copied from src/backend/utils/adt/ruleutils.c, not exported.
*
* get_opclass_name - fetch name of an index operator class
*
* The opclass name is appended (after a space) to buf.
*
* Output is suppressed if the opclass is the default for the given
* actual_datatype. (If you don't want this behavior, just pass
* InvalidOid for actual_datatype.)
*/
void
get_opclass_name(Oid opclass, Oid actual_datatype,
StringInfo buf)
{
HeapTuple ht_opc;
Form_pg_opclass opcrec;
char *opcname;
char *nspname;
ht_opc = SearchSysCache1(CLAOID, ObjectIdGetDatum(opclass));
if (!HeapTupleIsValid(ht_opc))
elog(ERROR, "cache lookup failed for opclass %u", opclass);
opcrec = (Form_pg_opclass) GETSTRUCT(ht_opc);
if (!OidIsValid(actual_datatype) ||
GetDefaultOpClass(actual_datatype, opcrec->opcmethod) != opclass)
{
/* Okay, we need the opclass name. Do we need to qualify it? */
opcname = NameStr(opcrec->opcname);
if (OpclassIsVisible(opclass))
appendStringInfo(buf, " %s", quote_identifier(opcname));
else
{
nspname = get_namespace_name(opcrec->opcnamespace);
appendStringInfo(buf, " %s.%s",
quote_identifier(nspname),
quote_identifier(opcname));
}
}
ReleaseSysCache(ht_opc);
}

View file

@ -1,6 +1,7 @@
/*-------------------------------------------------------------------------
*
* hypopg_import.c: Import of some PostgreSQL private fuctions.
* hypopg_import_index.c: Import of some PostgreSQL private fuctions, used for
* hypothetical index.
*
* This program is open source, licensed under the PostgreSQL license.
* For license terms, see the LICENSE file.
@ -9,10 +10,7 @@
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#if PG_VERSION_NUM >= 90300
#include "access/htup_details.h"
#endif
@ -20,20 +18,20 @@
#include "catalog/namespace.h"
#include "catalog/pg_opclass.h"
#include "commands/defrem.h"
#if PG_VERSION_NUM < 90500
#include "lib/stringinfo.h"
#endif
#include "commands/vacuum.h"
#include "nodes/makefuncs.h"
#include "nodes/pg_list.h"
#include "optimizer/clauses.h"
#include "optimizer/planner.h"
#include "optimizer/pathnode.h"
#if PG_VERSION_NUM >= 110000
#include "partitioning/partbounds.h"
#endif
#include "parser/parse_coerce.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/syscache.h"
#include "include/hypopg_import.h"
#include "include/hypopg.h"
/* Copied from src/backend/optimizer/util/plancat.c, not exported.
*
@ -66,7 +64,7 @@ build_index_tlist(PlannerInfo *root, IndexOptInfo *index,
if (indexkey < 0)
att_tup = SystemAttributeDefinition(indexkey,
heapRelation->rd_rel->relhasoids);
heapRelation->rd_rel->relhasoids);
else
#if PG_VERSION_NUM >= 110000
att_tup = TupleDescAttr(heapRelation->rd_att, indexkey - 1);
@ -210,7 +208,7 @@ GetIndexOpClass(List *opclass, Oid attrType,
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("operator class \"%s\" does not accept data type %s",
NameListToString(opclass), format_type_be(attrType))));
NameListToString(opclass), format_type_be(attrType))));
ReleaseSysCache(tuple);
@ -244,7 +242,7 @@ CheckPredicate(Expr *predicate)
if (CheckMutability(predicate))
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("functions in index predicate must be marked IMMUTABLE")));
errmsg("functions in index predicate must be marked IMMUTABLE")));
}
/*
@ -297,47 +295,3 @@ get_am_name(Oid amOid)
return result;
}
#endif
/*
* Copied from src/backend/utils/adt/ruleutils.c, not exported.
*
* get_opclass_name - fetch name of an index operator class
*
* The opclass name is appended (after a space) to buf.
*
* Output is suppressed if the opclass is the default for the given
* actual_datatype. (If you don't want this behavior, just pass
* InvalidOid for actual_datatype.)
*/
void
get_opclass_name(Oid opclass, Oid actual_datatype,
StringInfo buf)
{
HeapTuple ht_opc;
Form_pg_opclass opcrec;
char *opcname;
char *nspname;
ht_opc = SearchSysCache1(CLAOID, ObjectIdGetDatum(opclass));
if (!HeapTupleIsValid(ht_opc))
elog(ERROR, "cache lookup failed for opclass %u", opclass);
opcrec = (Form_pg_opclass) GETSTRUCT(ht_opc);
if (!OidIsValid(actual_datatype) ||
GetDefaultOpClass(actual_datatype, opcrec->opcmethod) != opclass)
{
/* Okay, we need the opclass name. Do we need to qualify it? */
opcname = NameStr(opcrec->opcname);
if (OpclassIsVisible(opclass))
appendStringInfo(buf, " %s", quote_identifier(opcname));
else
{
nspname = get_namespace_name(opcrec->opcnamespace);
appendStringInfo(buf, " %s.%s",
quote_identifier(nspname),
quote_identifier(opcname));
}
}
ReleaseSysCache(ht_opc);
}

View file

@ -12,27 +12,13 @@
#ifndef _HYPOPG_IMPORT_H_
#define _HYPOPG_IMPORT_H_
#include "commands/vacuum.h"
#include "lib/stringinfo.h"
#include "nodes/pg_list.h"
#include "optimizer/planner.h"
#include "utils/rel.h"
#include "include/hypopg_import_index.h"
/* adapted from nbtinsert.h */
#define HYPO_BTMaxItemSize \
MAXALIGN_DOWN((BLCKSZ - \
MAXALIGN(SizeOfPageHeaderData + 3*sizeof(ItemIdData)) - \
MAXALIGN(sizeof(BTPageOpaqueData))) / 3)
extern List *build_index_tlist(PlannerInfo *root, IndexOptInfo *index,
Relation heapRelation);
extern Oid GetIndexOpClass(List *opclass, Oid attrType,
char *accessMethodName, Oid accessMethodId);
extern void CheckPredicate(Expr *predicate);
extern bool CheckMutability(Expr *expr);
#if PG_VERSION_NUM < 90500
extern char *get_am_name(Oid amOid);
#endif
extern void get_opclass_name(Oid opclass, Oid actual_datatype, StringInfo buf);
#endif
#endif /* _HYPOPG_IMPORT_H_ */

View file

@ -0,0 +1,33 @@
/*-------------------------------------------------------------------------
*
* hypopg_import_index.h: Import of some PostgreSQL private fuctions, used for
* hypothetical index.
*
* This program is open source, licensed under the PostgreSQL license.
* For license terms, see the LICENSE file.
*
* Copyright (c) 2008-2018, PostgreSQL Global Development Group
*
*-------------------------------------------------------------------------
*/
#ifndef _HYPOPG_IMPORT_INDEX_H_
#define _HYPOPG_IMPORT_INDEX_H_
/* adapted from nbtinsert.h */
#define HYPO_BTMaxItemSize \
MAXALIGN_DOWN((BLCKSZ - \
MAXALIGN(SizeOfPageHeaderData + 3*sizeof(ItemIdData)) - \
MAXALIGN(sizeof(BTPageOpaqueData))) / 3)
extern List *build_index_tlist(PlannerInfo *root, IndexOptInfo *index,
Relation heapRelation);
extern Oid GetIndexOpClass(List *opclass, Oid attrType,
char *accessMethodName, Oid accessMethodId);
extern void CheckPredicate(Expr *predicate);
extern bool CheckMutability(Expr *expr);
#if PG_VERSION_NUM < 90500
extern char *get_am_name(Oid amOid);
#endif
#endif /* _HYPOPG_IMPORT_INDEX_H_ */