funcs.cpp 2.8 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 31
#include "gpos/version.h"
#include "gpopt/version.h"
#include "xercesc/util/XercesVersion.hpp"
32 33 34 35 36 37 38 39 40 41 42 43 44 45

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

extern "C" {
Datum
DisableXform(PG_FUNCTION_ARGS)
{
46
	char *szXform = text_to_cstring(PG_GETARG_TEXT_P(0));
47 48 49 50 51 52 53 54 55 56 57 58 59
	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);
	}
60
	text *result = cstring_to_text(str.data);
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

	PG_RETURN_TEXT_P(result);
}
}

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

extern "C" {
Datum
EnableXform(PG_FUNCTION_ARGS)
{
79
	char *szXform = text_to_cstring(PG_GETARG_TEXT_P(0));
80 81 82 83 84 85 86 87 88 89 90 91 92
	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);
	}
93
	text *result = cstring_to_text(str.data);
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113

	PG_RETURN_TEXT_P(result);
}
}


//---------------------------------------------------------------------------
//	@function:
//		LibraryVersion
//
//	@doc:
//		Returns the optimizer and gpos library versions as a message
//
//---------------------------------------------------------------------------
extern "C" {
Datum
LibraryVersion()
{
	StringInfoData str;
	initStringInfo(&str);
114 115 116
	appendStringInfo(&str, "GPOPT version: %d.%d", GPORCA_VERSION_MAJOR, GPORCA_VERSION_MINOR);
	appendStringInfo(&str, ", GPOS version: %d.%d", GPOS_VERSION_MAJOR, GPOS_VERSION_MINOR);
	appendStringInfo(&str, ", Xerces version: %s", XERCES_FULLVERSIONDOT);
117
	text *result = cstring_to_text(str.data);
118 119 120 121 122 123 124 125 126 127

	PG_RETURN_TEXT_P(result);
}
}

extern "C" {
StringInfo
OptVersion()
{
	StringInfo str = gpdb::SiMakeStringInfo();
128
	appendStringInfo(str, "%d.%d", GPORCA_VERSION_MAJOR, GPORCA_VERSION_MINOR);
129 130 131 132

	return str;
}
}