OSDN Git Service

Remove sjson2testsql.pl
[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-2021, 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         P_PresortedKey,
130         P_FullsortGroups,
131         P_SortMethodsUsed,
132         P_SortSpaceMemory,
133         P_GroupCount,
134         P_AvgSortSpcUsed,
135         P_PeakSortSpcUsed,
136         P_PreSortedGroups
137 } pgsp_prop_tags;
138
139 typedef struct
140 {
141         int       tag;                          /* Tag to identify words */
142         char *shortname;                /* Property name for short-style JSON */
143         char *longname;                 /* Property name for long(normal)-style JSON */
144         char *textname;                 /* Property name for Text representation */
145         bool  normalize_use;    /* True means this word to be used for
146                                                            normalization, which makes difference of
147                                                            plan-id */
148         converter_t *converter; /* Converter function for the property name */
149         setter_t  *setter;              /* Converter function for the property value */
150 } word_table;
151
152 typedef struct
153 {
154         StringInfo      dest;                   /* Storage for parse result */
155         pgsp_parser_mode mode;          /* Tells what to do to the parser */
156         node_vals *nodevals;            /* Node value holder */
157         char       *org_string;         /* What to parse */
158
159         /* Working variables used internally in parser */
160         int                     level;                  /* Next (indent or object) level */
161         Bitmapset  *plan_levels;        /* Level list for Plan objects */
162         Bitmapset  *first;                      /* Bitmap set holds whether the first element
163                                                                  * has been processed for each level */
164         Bitmapset  *not_item;           /* Bitmap set holds whether the node name at
165                                                                    the level was literally "Item" or not. */
166         bool            remove;                 /* True if the current node is not shown in
167                                                                  * the result */
168         bool            last_elem_is_object; /* True if the last processed element
169                                                                  * was an object */
170         pgsp_prop_tags  section;        /* explain section under processing */
171         pgsp_prop_tags  current_list; /* current list tag that needs special treat*/
172         StringInfo work_str;            /* StringInfor for very-short term usage */
173         char       *list_fname;         /* the field name of the current_list */
174         char       *fname;                      /* Field name*/
175         char       *wbuf;                       /* Working buffer */
176         int                     wbuflen;                /* Length of the working buffer */
177         int                     wlist_level;    /* Nest level of list for Grouping Sets */
178         grouping_set *tmp_gset; /* Working area for grouping sets */
179
180         converter_t *valconverter;      /* field name converter for the current
181                                                                  * element */
182         setter_t    *setter;            /* value converter for the current element */
183 } pgspParserContext;
184
185
186 extern word_table nodetypes[];
187 extern word_table strategies[];
188 extern word_table propfields[];
189
190 extern void init_word_index(void);
191 extern word_table *search_word_table(word_table *tbl,
192                                                                                   const char *word, int mode);
193 extern const char *conv_nodetype(const char *src, pgsp_parser_mode mode);
194 extern const char *conv_operation(const char *src, pgsp_parser_mode mode);
195 extern const char *conv_scandir(const char *src, pgsp_parser_mode mode);
196 extern const char *conv_expression(const char *src, pgsp_parser_mode mode);
197 extern const char *conv_relasionship(const char *src, pgsp_parser_mode mode);
198 extern const char *conv_jointype(const char *src, pgsp_parser_mode mode);
199 extern const char *conv_strategy(const char *src, pgsp_parser_mode mode);
200 extern const char *conv_setsetopcommand(const char *src, pgsp_parser_mode mode);
201 extern const char *conv_sortmethod(const char *src, pgsp_parser_mode mode);
202 extern const char *conv_sortspacetype(const char *src, pgsp_parser_mode mode);
203 extern const char *conv_partialmode(const char *src, pgsp_parser_mode mode);
204
205 extern bool run_pg_parse_json(JsonLexContext *lex, JsonSemAction *sem);
206 extern void init_parser_context(pgspParserContext *ctx, int mode,
207                                                                    char *orgstr, char *buf,int buflen);
208 extern void init_json_lex_context(JsonLexContext *lex, char *json);
209