PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pgpa_ast.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * pgpa_ast.h
4 * abstract syntax trees for plan advice, plus parser/scanner support
5 *
6 * Copyright (c) 2016-2026, PostgreSQL Global Development Group
7 *
8 * contrib/pg_plan_advice/pgpa_ast.h
9 *
10 *-------------------------------------------------------------------------
11 */
12#ifndef PGPA_AST_H
13#define PGPA_AST_H
14
15#include "pgpa_identifier.h"
16
17#include "nodes/pg_list.h"
18
19/*
20 * Advice items generally take the form SOME_TAG(item [...]), where an item
21 * can take various forms. The simplest case is a relation identifier, but
22 * some tags allow sublists, and JOIN_ORDER() allows both ordered and unordered
23 * sublists.
24 */
25typedef enum
26{
27 PGPA_TARGET_IDENTIFIER, /* relation identifier */
28 PGPA_TARGET_ORDERED_LIST, /* (item ...) */
29 PGPA_TARGET_UNORDERED_LIST /* {item ...} */
31
32/*
33 * An index specification.
34 */
35typedef struct pgpa_index_target
36{
37 /* Index schema and name */
39 char *indname;
41
42/*
43 * A single item about which advice is being given, which could be either
44 * a relation identifier that we want to break out into its constituent fields,
45 * or a sublist of some kind.
46 */
47typedef struct pgpa_advice_target
48{
50
51 /*
52 * This field is meaningful when ttype is PGPA_TARGET_IDENTIFIER.
53 *
54 * All identifiers must have an alias name and an occurrence number; the
55 * remaining fields can be NULL. Note that it's possible to specify a
56 * partition name without a partition schema, but not the reverse.
57 */
59
60 /*
61 * This field is set when ttype is PGPA_TARGET_IDENTIFIER and the advice
62 * tag is PGPA_TAG_INDEX_SCAN or PGPA_TAG_INDEX_ONLY_SCAN.
63 */
65
66 /*
67 * When the ttype is PGPA_TARGET_<anything>_LIST, this field contains a
68 * list of additional pgpa_advice_target objects. Otherwise, it is unused.
69 */
72
73/*
74 * These are all the kinds of advice that we know how to parse. If a keyword
75 * is found at the top level, it must be in this list.
76 *
77 * If you change anything here, also update pgpa_parse_advice_tag and
78 * pgpa_cstring_advice_tag.
79 */
102
103/*
104 * An item of advice, meaning a tag and the list of all targets to which
105 * it is being applied.
106 *
107 * "targets" is a list of pgpa_advice_target objects.
108 *
109 * The List returned from pgpa_yyparse is list of pgpa_advice_item objects.
110 */
116
117/*
118 * Result of comparing an array of pgpa_relation_identifier objects to a
119 * pgpa_advice_target.
120 *
121 * PGPA_ITM_EQUAL means all targets are matched by some identifier, and
122 * all identifiers were matched to a target.
123 *
124 * PGPA_ITM_KEYS_ARE_SUBSET means that all identifiers matched to a target,
125 * but there were leftover targets. Generally, this means that the advice is
126 * looking to apply to all of the rels we have plus some additional ones that
127 * we don't have.
128 *
129 * PGPA_ITM_TARGETS_ARE_SUBSET means that all targets are matched by
130 * identifiers, but there were leftover identifiers. Generally, this means
131 * that the advice is looking to apply to some but not all of the rels we have.
132 *
133 * PGPA_ITM_INTERSECTING means that some identifiers and targets were matched,
134 * but neither all identifiers nor all targets could be matched to items in
135 * the other set.
136 *
137 * PGPA_ITM_DISJOINT means that no matches between identifiers and targets were
138 * found.
139 */
148
149/* for pgpa_scanner.l and pgpa_parser.y */
150union YYSTYPE;
151#ifndef YY_TYPEDEF_YY_SCANNER_T
152#define YY_TYPEDEF_YY_SCANNER_T
153typedef void *yyscan_t;
154#endif
155
156/* in pgpa_scanner.l */
157extern int pgpa_yylex(union YYSTYPE *yylval_param, List **result,
158 char **parse_error_msg_p, yyscan_t yyscanner);
159extern void pgpa_yyerror(List **result, char **parse_error_msg_p,
160 yyscan_t yyscanner,
161 const char *message);
162extern void pgpa_scanner_init(const char *str, yyscan_t *yyscannerp);
163extern void pgpa_scanner_finish(yyscan_t yyscanner);
164
165/* in pgpa_parser.y */
166extern int pgpa_yyparse(List **result, char **parse_error_msg_p,
167 yyscan_t yyscanner);
168extern List *pgpa_parse(const char *advice_string, char **error_p);
169
170/* in pgpa_ast.c */
173 pgpa_advice_target *target);
175 pgpa_identifier *rids,
176 pgpa_advice_target *target);
179extern pgpa_advice_tag_type pgpa_parse_advice_tag(const char *tag, bool *fail);
181 pgpa_advice_target *target);
183 pgpa_index_target *itarget);
184
185#endif
void * yyscan_t
Definition cubedata.h:65
const char * str
char * pgpa_cstring_advice_tag(pgpa_advice_tag_type advice_tag)
Definition pgpa_ast.c:29
void pgpa_scanner_finish(yyscan_t yyscanner)
void * yyscan_t
Definition pgpa_ast.h:153
bool pgpa_identifier_matches_target(pgpa_identifier *rid, pgpa_advice_target *target)
Definition pgpa_ast.c:229
pgpa_advice_tag_type
Definition pgpa_ast.h:81
@ PGPA_TAG_INDEX_SCAN
Definition pgpa_ast.h:88
@ PGPA_TAG_NESTED_LOOP_MATERIALIZE
Definition pgpa_ast.h:92
@ PGPA_TAG_MERGE_JOIN_PLAIN
Definition pgpa_ast.h:91
@ PGPA_TAG_GATHER_MERGE
Definition pgpa_ast.h:85
@ PGPA_TAG_GATHER
Definition pgpa_ast.h:84
@ PGPA_TAG_NESTED_LOOP_MEMOIZE
Definition pgpa_ast.h:93
@ PGPA_TAG_SEMIJOIN_NON_UNIQUE
Definition pgpa_ast.h:97
@ PGPA_TAG_BITMAP_HEAP_SCAN
Definition pgpa_ast.h:82
@ PGPA_TAG_PARTITIONWISE
Definition pgpa_ast.h:96
@ PGPA_TAG_NO_GATHER
Definition pgpa_ast.h:95
@ PGPA_TAG_INDEX_ONLY_SCAN
Definition pgpa_ast.h:87
@ PGPA_TAG_SEQ_SCAN
Definition pgpa_ast.h:99
@ PGPA_TAG_HASH_JOIN
Definition pgpa_ast.h:86
@ PGPA_TAG_SEMIJOIN_UNIQUE
Definition pgpa_ast.h:98
@ PGPA_TAG_JOIN_ORDER
Definition pgpa_ast.h:89
@ PGPA_TAG_TID_SCAN
Definition pgpa_ast.h:100
@ PGPA_TAG_FOREIGN_JOIN
Definition pgpa_ast.h:83
@ PGPA_TAG_NESTED_LOOP_PLAIN
Definition pgpa_ast.h:94
@ PGPA_TAG_MERGE_JOIN_MATERIALIZE
Definition pgpa_ast.h:90
List * pgpa_parse(const char *advice_string, char **error_p)
void pgpa_yyerror(List **result, char **parse_error_msg_p, yyscan_t yyscanner, const char *message)
void pgpa_format_advice_target(StringInfo str, pgpa_advice_target *target)
Definition pgpa_ast.c:164
void pgpa_scanner_init(const char *str, yyscan_t *yyscannerp)
pgpa_advice_tag_type pgpa_parse_advice_tag(const char *tag, bool *fail)
Definition pgpa_ast.c:85
void pgpa_format_index_target(StringInfo str, pgpa_index_target *itarget)
Definition pgpa_ast.c:200
bool pgpa_index_targets_equal(pgpa_index_target *i1, pgpa_index_target *i2)
Definition pgpa_ast.c:212
pgpa_target_type
Definition pgpa_ast.h:26
@ PGPA_TARGET_UNORDERED_LIST
Definition pgpa_ast.h:29
@ PGPA_TARGET_IDENTIFIER
Definition pgpa_ast.h:27
@ PGPA_TARGET_ORDERED_LIST
Definition pgpa_ast.h:28
int pgpa_yyparse(List **result, char **parse_error_msg_p, yyscan_t yyscanner)
pgpa_itm_type pgpa_identifiers_match_target(int nrids, pgpa_identifier *rids, pgpa_advice_target *target)
Definition pgpa_ast.c:277
int pgpa_yylex(union YYSTYPE *yylval_param, List **result, char **parse_error_msg_p, yyscan_t yyscanner)
pgpa_itm_type
Definition pgpa_ast.h:141
@ PGPA_ITM_EQUAL
Definition pgpa_ast.h:142
@ PGPA_ITM_DISJOINT
Definition pgpa_ast.h:146
@ PGPA_ITM_KEYS_ARE_SUBSET
Definition pgpa_ast.h:143
@ PGPA_ITM_TARGETS_ARE_SUBSET
Definition pgpa_ast.h:144
@ PGPA_ITM_INTERSECTING
Definition pgpa_ast.h:145
static int fb(int x)
int YYSTYPE
Definition pg_list.h:54
pgpa_advice_tag_type tag
Definition pgpa_ast.h:113
pgpa_identifier rid
Definition pgpa_ast.h:58
pgpa_target_type ttype
Definition pgpa_ast.h:49
pgpa_index_target * itarget
Definition pgpa_ast.h:64
char * indnamespace
Definition pgpa_ast.h:38