COptClient.h 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//---------------------------------------------------------------------------
//	Greenplum Database
//	Copyright (C) 2012 EMC Corp.
//
//	@filename:
//		COptClient.h
//
//	@doc:
//		API for optimizer client
//
//	@test:
//
//
//---------------------------------------------------------------------------
#ifndef COptClient_H
#define COptClient_H

#include "gpos/base.h"

20
#include "naucrates/md/CSystemId.h"
21 22 23 24

// forward declarations
namespace gpopt
{
J
Jesse Zhang 已提交
25
class CMDAccessor;
26 27 28 29
}

namespace gpnaucrates
{
J
Jesse Zhang 已提交
30
class CCommunicator;
31 32 33 34
}

namespace gpmd
{
J
Jesse Zhang 已提交
35 36 37
class IMDProvider;
class CMDProviderCommProxy;
}  // namespace gpmd
38 39 40 41


namespace gpoptudfs
{
J
Jesse Zhang 已提交
42 43 44 45
using namespace gpos;
using namespace gpopt;
using namespace gpmd;
using namespace gpnaucrates;
46

J
Jesse Zhang 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
//---------------------------------------------------------------------------
//	@class:
//		COptClient
//
//	@doc:
//		Optimizer client;
//		passes optimization request to server, provides metadata and
//		builds planned statement from returned query plan;
//
//---------------------------------------------------------------------------
class COptClient
{
private:
	// struct containing optimization request parameters;
	// needs to be in sync with the argument passed by the client;
	struct SOptParams
	{
		// path where socket is initialized
		const char *m_path;
66

J
Jesse Zhang 已提交
67 68 69
		// input query
		Query *m_query;
	};
70

J
Jesse Zhang 已提交
71 72
	// input query
	Query *m_query;
73

J
Jesse Zhang 已提交
74 75
	// path where socket is initialized
	const char *m_path;
76

J
Jesse Zhang 已提交
77 78
	// memory pool
	CMemoryPool *m_mp;
79

J
Jesse Zhang 已提交
80 81
	// communicator
	CCommunicator *m_communicator;
82

J
Jesse Zhang 已提交
83 84
	// default id for the source system
	static const CSystemId m_default_sysid;
85

J
Jesse Zhang 已提交
86
	// error severity levels
87

J
Jesse Zhang 已提交
88 89
	// array mapping GPOS to elog() error severity
	static ULONG elog_to_severity_map[CException::ExsevSentinel][2];
90

J
Jesse Zhang 已提交
91 92 93 94 95 96 97 98 99 100
	// ctor
	COptClient(SOptParams *op)
		: m_query(op->m_query),
		  m_path(op->m_path),
		  m_mp(NULL),
		  m_communicator(NULL)
	{
		GPOS_ASSERT(NULL != m_query);
		GPOS_ASSERT(NULL != m_path);
	}
101

J
Jesse Zhang 已提交
102 103 104 105
	// dtor
	~COptClient()
	{
	}
106

J
Jesse Zhang 已提交
107 108
	// request optimization from server
	PlannedStmt *GPOPTOptimizedPlan();
109

J
Jesse Zhang 已提交
110 111
	// set traceflags
	void SetTraceflags();
112

J
Jesse Zhang 已提交
113 114
	// send query optimization request to server
	void SendRequest(CMDAccessor *md_accessor);
115

J
Jesse Zhang 已提交
116 117
	// retrieve DXL plan
	const CHAR *SzPlanDXL(IMDProvider *md_provider);
118

J
Jesse Zhang 已提交
119 120 121
	// send MD response
	void SendMDResponse(CMDProviderCommProxy *md_provider_proxy,
						const WCHAR *req);
122

J
Jesse Zhang 已提交
123 124 125
	// build planned statement from serialized plan
	PlannedStmt *ConstructPlanStmt(CMDAccessor *md_accessor,
								   const CHAR *serialized_plan);
126

J
Jesse Zhang 已提交
127 128
	// elog wrapper
	void Elog(ULONG severity, const WCHAR *msg);
129

J
Jesse Zhang 已提交
130 131 132
public:
	// invoke optimizer instance
	static void *Run(void *pv);
133

J
Jesse Zhang 已提交
134 135
};	// class COptClient
}  // namespace gpoptudfs
136

J
Jesse Zhang 已提交
137
#endif	// !COptClient_H
138 139 140


// EOF