OSDN Git Service

Version 1.3.1
[pgstoreplans/pg_store_plans.git] / pgsp_json_int.h
1 /*-------------------------------------------------------------------------
2  *
3  * pgsp_json_int.h: Definitions for internal use for pgsp_json.c
4  *
5  * Copyright (c) 2012-2020, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
6  *
7  * IDENTIFICATION
8  *        pg_store_plans/pgsp_json_int.h
9  *
10  *-------------------------------------------------------------------------
11  */
12
13 typedef enum
14 {
15         PGSP_JSON_SHORTEN,
16         PGSP_JSON_INFLATE,
17         PGSP_JSON_TEXTIZE,
18         PGSP_JSON_YAMLIZE,
19         PGSP_JSON_XMLIZE,
20         PGSP_JSON_NORMALIZE
21 } pgsp_parser_mode;
22
23 typedef enum 
24 {
25         S_Invalid,
26         S_Plain,
27         S_Sorted,
28         S_Hashed,
29         S_Mixed
30 } pgsp_strategies;
31
32 typedef const char *(converter_t)(const char *src, pgsp_parser_mode mode);
33 typedef void (setter_t)(node_vals *vals, const char *val);
34
35 typedef enum
36 {
37         P_Invalid,
38         P_Plan,
39         P_Plans,
40         P_NodeType,
41         P_RelationShip,
42         P_ScanDir,
43         P_IndexName,
44         P_RelationName,
45         P_FunctioName,
46         P_CTEName,
47         P_Schema,
48         P_Alias,
49         P_Output,
50         P_MergeCond,
51         P_Strategy,
52         P_JoinType,
53         P_Command,
54         P_SortMethod,
55         P_SortKey,
56         P_GroupKey,
57         P_GroupKeys,
58         P_GroupSets,
59         P_HashKeys,
60         P_HashKey,
61         P_Filter,
62         P_JoinFilter,
63         P_HashCond,
64         P_IndexCond,
65         P_TidCond,
66         P_RecheckCond,
67         P_Operation,
68         P_SubplanName,
69         P_Triggers,
70         P_Trigger,
71         P_TriggerName,
72         P_TrgRelation,
73         P_ConstraintName,
74         P_Parallel,
75         P_PartialMode,
76         P_WorkersPlanned,
77
78         P_FunctionCall,
79         P_StartupCost,
80         P_TotalCost,
81         P_PlanRows,
82         P_PlanWidth,
83         P_ActualStartupTime,
84         P_ActualTotalTime,
85         P_ActualRows,
86         P_ActualLoops,
87         P_HeapFetches,
88         P_SharedHitBlks,
89         P_SharedReadBlks,
90         P_SharedDirtiedBlks,
91         P_SharedWrittenBlks,
92         P_LocalHitBlks,
93         P_LocalReadBlks,
94         P_LocalDirtiedBlks,
95         P_LocalWrittenBlks,
96         P_TempReadBlks,
97         P_TempWrittenBlks,
98         P_IOReadTime,
99         P_IOWwriteTime,
100         P_SortSpaceUsed,
101         P_SortSpaceType,
102         P_PeakMemoryUsage,
103         P_OrgHashBatches,
104         P_OrgHashBuckets,
105         P_HashBatches,
106         P_HashBuckets,
107         P_RowsFilterRmvd,
108         P_RowsIdxRchkRmvd,
109         P_TrgTime,
110         P_TrgCalls,
111         P_PlanTime,
112         P_ExecTime,
113         P_ExactHeapBlks,
114         P_LossyHeapBlks,
115         P_RowsJoinFltRemvd,
116         P_TargetTables,
117         P_ConfRes,
118         P_ConfArbitIdx,
119         P_TuplesInserted,
120         P_ConfTuples,
121         P_SamplingMethod,
122         P_SamplingParams,
123         P_RepeatableSeed,
124         P_Workers,
125         P_WorkersLaunched,
126         P_WorkerNumber,
127         P_InnerUnique,
128         P_TableFuncName
129 } pgsp_prop_tags;
130
131 typedef struct
132 {
133         int       tag;                          /* Tag to identify words */
134         char *shortname;                /* Property name for short-style JSON */
135         char *longname;                 /* Property name for long(normal)-style JSON */
136         char *textname;                 /* Property name for Text representation */
137         bool  normalize_use;    /* True means this word to be used for
138                                                            normalization, which makes difference of
139                                                            plan-id */
140         converter_t *converter; /* Converter function for the property name */
141         setter_t  *setter;              /* Converter function for the property value */
142 } word_table;
143
144 typedef struct
145 {
146         StringInfo      dest;                   /* Storage for parse result */
147         pgsp_parser_mode mode;          /* Tells what to do to the parser */
148         node_vals *nodevals;            /* Node value holder */
149         char       *org_string;         /* What to parse */
150
151         /* Working variables used internally in parser */
152         int                     level;                  /* Next (indent or object) level */
153         Bitmapset  *plan_levels;        /* Level list for Plan objects */
154         Bitmapset  *first;                      /* Bitmap set holds whether the first element
155                                                                  * has been processed for each level */
156         Bitmapset  *not_item;           /* Bitmap set holds whether the node name at
157                                                                    the level was literally "Item" or not. */
158         bool            remove;                 /* True if the current node is not shown in
159                                                                  * the result */
160         bool            last_elem_is_object; /* True if the last processed element
161                                                                  * was an object */
162         pgsp_prop_tags  section;        /* explain section under processing */
163         pgsp_prop_tags  current_list; /* current list tag that needs special treat*/
164         StringInfo work_str;            /* StringInfor for very-short term usage */
165         char       *list_fname;         /* the field name of the current_list */
166         char       *fname;                      /* Field name*/
167         char       *wbuf;                       /* Working buffer */
168         int                     wbuflen;                /* Length of the working buffer */
169         int                     wlist_level;    /* Nest level of list for Grouping Sets */
170         grouping_set *tmp_gset; /* Working area for grouping sets */
171
172         converter_t *valconverter;      /* field name converter for the current
173                                                                  * element */
174         setter_t    *setter;            /* value converter for the current element */
175 } pgspParserContext;
176
177
178 extern word_table nodetypes[];
179 extern word_table strategies[];
180 extern word_table propfields[];
181
182 extern void init_word_index(void);
183 extern word_table *search_word_table(word_table *tbl,
184                                                                                   const char *word, int mode);
185 extern const char *conv_nodetype(const char *src, pgsp_parser_mode mode);
186 extern const char *conv_operation(const char *src, pgsp_parser_mode mode);
187 extern const char *conv_scandir(const char *src, pgsp_parser_mode mode);
188 extern const char *conv_expression(const char *src, pgsp_parser_mode mode);
189 extern const char *conv_relasionship(const char *src, pgsp_parser_mode mode);
190 extern const char *conv_jointype(const char *src, pgsp_parser_mode mode);
191 extern const char *conv_strategy(const char *src, pgsp_parser_mode mode);
192 extern const char *conv_setsetopcommand(const char *src, pgsp_parser_mode mode);
193 extern const char *conv_sortmethod(const char *src, pgsp_parser_mode mode);
194 extern const char *conv_sortspacetype(const char *src, pgsp_parser_mode mode);
195 extern const char *conv_partialmode(const char *src, pgsp_parser_mode mode);
196
197 extern bool run_pg_parse_json(JsonLexContext *lex, JsonSemAction *sem);
198 extern void init_parser_context(pgspParserContext *ctx, int mode,
199                                                                    char *orgstr, char *buf,int buflen);
200 extern void init_json_lex_context(JsonLexContext *lex, char *json);
201