funcs.cpp 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//---------------------------------------------------------------------------
//	Greenplum Database
//	Copyright (C) 2011 EMC Greenplum, Inc.
//
//	@filename:
//		funcs.cpp
//
//	@doc:
//		API for invoking optimizer using GPDB udfs
//
//	@test:
//
//
//---------------------------------------------------------------------------

#include <sys/stat.h>

H
Heikki Linnakangas 已提交
18 19 20 21 22 23
extern "C" {
#include "postgres.h"
#include "fmgr.h"
#include "utils/builtins.h"
}

24
#include "gpopt/utils/COptTasks.h"
25

26 27
#include "gpos/_api.h"
#include "gpopt/gpdbwrappers.h"
28

29 30
#include "gpopt/version.h"
#include "xercesc/util/XercesVersion.hpp"
31 32 33 34 35 36 37 38 39 40 41 42 43 44

//---------------------------------------------------------------------------
//	@function:
//		DisableXform
//
//	@doc:
//		Takes transformation name as input, and disables this transformation.
//
//---------------------------------------------------------------------------

extern "C" {
Datum
DisableXform(PG_FUNCTION_ARGS)
{
45
	char *szXform = text_to_cstring(PG_GETARG_TEXT_P(0));
46 47 48 49 50 51 52 53 54 55 56 57 58
	bool fResult = COptTasks::FSetXform(szXform, true /*fDisable*/);

	StringInfoData str;
	initStringInfo(&str);

	if (fResult)
	{
		appendStringInfo(&str, "%s is disabled", szXform);
	}
	else
	{
		appendStringInfo(&str, "%s is not recognized", szXform);
	}
59
	text *result = cstring_to_text(str.data);
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

	PG_RETURN_TEXT_P(result);
}
}

//---------------------------------------------------------------------------
//	@function:
//		EnableXform
//
//	@doc:
//		Takes transformation name as input, and enables this transformation.
//
//---------------------------------------------------------------------------

extern "C" {
Datum
EnableXform(PG_FUNCTION_ARGS)
{
78
	char *szXform = text_to_cstring(PG_GETARG_TEXT_P(0));
79 80 81 82 83 84 85 86 87 88 89 90 91
	bool fResult = COptTasks::FSetXform(szXform, false /*fDisable*/);

	StringInfoData str;
	initStringInfo(&str);

	if (fResult)
	{
		appendStringInfo(&str, "%s is enabled", szXform);
	}
	else
	{
		appendStringInfo(&str, "%s is not recognized", szXform);
	}
92
	text *result = cstring_to_text(str.data);
93 94 95 96 97 98 99 100 101 102 103

	PG_RETURN_TEXT_P(result);
}
}


//---------------------------------------------------------------------------
//	@function:
//		LibraryVersion
//
//	@doc:
H
Haisheng Yuan 已提交
104
//		Returns the optimizer and xerces library versions as a message
105 106 107 108 109 110 111 112
//
//---------------------------------------------------------------------------
extern "C" {
Datum
LibraryVersion()
{
	StringInfoData str;
	initStringInfo(&str);
H
Haisheng Yuan 已提交
113
	appendStringInfo(&str, "GPOPT version: %s", GPORCA_VERSION_STRING);
114
	appendStringInfo(&str, ", Xerces version: %s", XERCES_FULLVERSIONDOT);
115
	text *result = cstring_to_text(str.data);
116 117 118 119 120 121 122 123 124 125

	PG_RETURN_TEXT_P(result);
}
}

extern "C" {
StringInfo
OptVersion()
{
	StringInfo str = gpdb::SiMakeStringInfo();
H
Haisheng Yuan 已提交
126
	appendStringInfo(str, "%s", GPORCA_VERSION_STRING);
127 128 129 130

	return str;
}
}