-
Notifications
You must be signed in to change notification settings - Fork 1
/
anchor2struct.h
executable file
·142 lines (123 loc) · 3.6 KB
/
anchor2struct.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*-------------------------------------------------------------------------
*
* anchor2struct.h
* prototypes for anchor2struct.c.
*
* Copyright (c) 2023, Damo Academy of Alibaba Group
*
*-------------------------------------------------------------------------
*/
#ifndef __ANCHOR_STRUCT__
#define __ANCHOR_STRUCT__
#include "utils/hashtable.h"
#include "utils/cson.h"
// init structs including anchor struct and pilottransdata struct
#define init_struct(anchor,type) anchor = (type*)palloc(sizeof(type)); \
memset(anchor,0,sizeof(*anchor));
// store string for num
// avoid redefinition caused by "#define"
#define store_string_for_num(num,store_var) if(1){\
char num_string[CHAR_LEN_FOR_NUM]; \
sprintf(num_string, "%.6f", num);\
int num_string_length = strlen(num_string);\
store_var = (char*)palloc((num_string_length+1)*sizeof(char)); \
strcpy(store_var,num_string);}
// store string
// avoid redefinition caused by "#define"
#define store_string(string_object,store_var) if(1)\
{\
int string_length = strlen(string_object);\
store_var = (char*)palloc((string_length+1)*sizeof(char)); \
strcpy(store_var,string_object);}
// realloc char**
#define relloc_string_array_object(string_array_object,new_size) string_array_object = (char**)realloc(string_array_object,new_size*sizeof(char*));
// back_to_psql
#define back_to_psql(message) ereport(ERROR,(errmsg(message)));
// change flag for anchor
#define change_flag_for_anchor(anchor_flag) anchor_flag = 0;\
anchor_num--;
// struct
typedef struct
{
char* sql;
char* physical_plan;
char* logical_plan;
char* execution_time;
char* tid;
char** subquery;
char** card;
size_t subquery_num;
size_t card_num;
char* parser_time;
char* http_time;
char** anchor_names;
char** anchor_times;
size_t anchor_names_num;
size_t anchor_times_num;
}PilotTransData;
typedef struct
{
int enable;
char* name;
}SubqueryCardFetcherAnchor;
typedef struct
{
int enable;
char* name;
char** subquery;
double* card;
size_t subquery_num;
size_t card_num;
}CardReplaceAnchor;
typedef struct
{
int enable;
char* name;
}ExecutionTimeFetchAnchor;
typedef struct
{
int enable;
char* name;
}RecordFetchAnchor;
// enumerate
typedef enum
{
SUBQUERY_CARD_FETCH_ANCHOR,
CARD_REPLACE_ANCHOR,
EXECUTION_TIME_FETCH_ANCHOR,
RECORD_FETCH_ANCHOR,
PHYSICAL_PLAN_FETCH_ANCHOR,
CostAnchorHandler,
HintAnchorHandler,
UNKNOWN_ANCHOR
}AnchorName;
// struct
extern PilotTransData* pilot_transdata;
extern SubqueryCardFetcherAnchor* subquery_card_fetcher_anchor;
extern CardReplaceAnchor* card_replace_anchor;
extern ExecutionTimeFetchAnchor* execution_time_fetch_anchor;
extern RecordFetchAnchor *record_fetch_anchor;
extern AnchorName* ANCHOR_NAME;
extern reflect_item_t Subquery_Card_Fetcher_Anchor_ref_tbl[];
extern reflect_item_t Card_Replace_Anchor_ref_tbl[];
extern reflect_item_t Execution_Time_Fetch_Anchor_ref_tbl[] ;
extern reflect_item_t Record_Fetch_Anchor_ref_tbl[];
// vars
extern int anchor_num;
extern int enableTerminate;
extern double subquerycardfetcher_time;
extern double cardreplace_time;
extern double executiontimefetch_time;
extern double parser_time_;
extern int enablePilotscope;
extern int anchor_time_num;
extern int subquery_count;
extern int port;
extern char* host;
extern int enableSend;
// function
extern void init_some_vars();
extern void end_anchor();
extern char* get_aimodel_subquery2card(Hashtable* table, const char* key);
extern void store_aimodel_subquery2card();
#endif