From fa9be3ff1d5d93e22574414ce460654ec122e996 Mon Sep 17 00:00:00 2001 From: Julien Rouhaud Date: Mon, 8 Apr 2019 22:47:16 +0200 Subject: [PATCH] Split imported code in multiple files in a dedicated directory (cherry picked from commit b5e50e6429e889cb105a6e23c4712c5d45779b91) --- Makefile | 6 +- import/hypopg_import.c | 68 ++++++++++++++++++ .../hypopg_import_index.c | 70 ++++--------------- include/hypopg_import.h | 22 ++---- include/hypopg_import_index.h | 33 +++++++++ 5 files changed, 122 insertions(+), 77 deletions(-) create mode 100644 import/hypopg_import.c rename hypopg_import.c => import/hypopg_import_index.c (83%) create mode 100644 include/hypopg_import_index.h diff --git a/Makefile b/Makefile index d0a71e9..8fe9511 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/import/hypopg_import.c b/import/hypopg_import.c new file mode 100644 index 0000000..4b03663 --- /dev/null +++ b/import/hypopg_import.c @@ -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); +} diff --git a/hypopg_import.c b/import/hypopg_import_index.c similarity index 83% rename from hypopg_import.c rename to import/hypopg_import_index.c index 7b45baf..22d84db 100644 --- a/hypopg_import.c +++ b/import/hypopg_import_index.c @@ -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); -} diff --git a/include/hypopg_import.h b/include/hypopg_import.h index 6d44677..80a3d04 100644 --- a/include/hypopg_import.h +++ b/include/hypopg_import.h @@ -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_ */ diff --git a/include/hypopg_import_index.h b/include/hypopg_import_index.h new file mode 100644 index 0000000..4715771 --- /dev/null +++ b/include/hypopg_import_index.h @@ -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_ */