PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pgpa_trove.h File Reference
#include "pgpa_ast.h"
#include "nodes/bitmapset.h"
Include dependency graph for pgpa_trove.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pgpa_trove_entry
 
struct  pgpa_trove_result
 

Macros

#define PGPA_TE_MATCH_PARTIAL   0x0001
 
#define PGPA_TE_MATCH_FULL   0x0002
 
#define PGPA_TE_INAPPLICABLE   0x0004
 
#define PGPA_TE_CONFLICTING   0x0008
 
#define PGPA_TE_FAILED   0x0010
 

Typedefs

typedef struct pgpa_trove pgpa_trove
 
typedef struct pgpa_trove_entry pgpa_trove_entry
 
typedef enum pgpa_trove_lookup_type pgpa_trove_lookup_type
 
typedef struct pgpa_trove_result pgpa_trove_result
 

Enumerations

enum  pgpa_trove_lookup_type { PGPA_TROVE_LOOKUP_JOIN , PGPA_TROVE_LOOKUP_REL , PGPA_TROVE_LOOKUP_SCAN }
 

Functions

pgpa_trovepgpa_build_trove (List *advice_items)
 
void pgpa_trove_lookup (pgpa_trove *trove, pgpa_trove_lookup_type type, int nrids, pgpa_identifier *rids, pgpa_trove_result *result)
 
void pgpa_trove_lookup_all (pgpa_trove *trove, pgpa_trove_lookup_type type, pgpa_trove_entry **entries, int *nentries)
 
charpgpa_cstring_trove_entry (pgpa_trove_entry *entry)
 
void pgpa_trove_set_flags (pgpa_trove_entry *entries, Bitmapset *indexes, int flags)
 
void pgpa_trove_append_flags (StringInfo buf, int flags)
 

Macro Definition Documentation

◆ PGPA_TE_CONFLICTING

#define PGPA_TE_CONFLICTING   0x0008

Definition at line 49 of file pgpa_trove.h.

◆ PGPA_TE_FAILED

#define PGPA_TE_FAILED   0x0010

Definition at line 50 of file pgpa_trove.h.

◆ PGPA_TE_INAPPLICABLE

#define PGPA_TE_INAPPLICABLE   0x0004

Definition at line 48 of file pgpa_trove.h.

◆ PGPA_TE_MATCH_FULL

#define PGPA_TE_MATCH_FULL   0x0002

Definition at line 47 of file pgpa_trove.h.

◆ PGPA_TE_MATCH_PARTIAL

#define PGPA_TE_MATCH_PARTIAL   0x0001

Definition at line 46 of file pgpa_trove.h.

Typedef Documentation

◆ pgpa_trove

Definition at line 20 of file pgpa_trove.h.

◆ pgpa_trove_entry

◆ pgpa_trove_lookup_type

◆ pgpa_trove_result

Enumeration Type Documentation

◆ pgpa_trove_lookup_type

Enumerator
PGPA_TROVE_LOOKUP_JOIN 
PGPA_TROVE_LOOKUP_REL 
PGPA_TROVE_LOOKUP_SCAN 

Definition at line 81 of file pgpa_trove.h.

82{
pgpa_trove_lookup_type
Definition pgpa_trove.h:82
@ PGPA_TROVE_LOOKUP_SCAN
Definition pgpa_trove.h:85
@ PGPA_TROVE_LOOKUP_JOIN
Definition pgpa_trove.h:83
@ PGPA_TROVE_LOOKUP_REL
Definition pgpa_trove.h:84

Function Documentation

◆ pgpa_build_trove()

pgpa_trove * pgpa_build_trove ( List advice_items)
extern

Definition at line 132 of file pgpa_trove.c.

133{
135
137 pgpa_init_trove_slice(&trove->rel);
139
141 {
142 switch (item->tag)
143 {
145 {
146 pgpa_advice_target *target;
147
148 /*
149 * For most advice types, each element in the top-level
150 * list is a separate target, but it's most convenient to
151 * regard the entirety of a JOIN_ORDER specification as a
152 * single target. Since it wasn't represented that way
153 * during parsing, build a surrogate object now.
154 */
157 target->children = item->targets;
158
160 item->tag, target);
161 }
162 break;
163
169
170 /*
171 * Scan advice.
172 */
173 foreach_ptr(pgpa_advice_target, target, item->targets)
174 {
175 /*
176 * For now, all of our scan types target single relations,
177 * but in the future this might not be true, e.g. a custom
178 * scan could replace a join.
179 */
180 Assert(target->ttype == PGPA_TARGET_IDENTIFIER);
182 item->tag, target);
183 }
184 break;
185
195
196 /*
197 * Join strategy advice.
198 */
199 foreach_ptr(pgpa_advice_target, target, item->targets)
200 {
202 item->tag, target);
203 }
204 break;
205
207 case PGPA_TAG_GATHER:
210
211 /*
212 * Advice about a RelOptInfo relevant to both scans and joins.
213 */
214 foreach_ptr(pgpa_advice_target, target, item->targets)
215 {
217 item->tag, target);
218 }
219 break;
220 }
221 }
222
223 return trove;
224}
#define Assert(condition)
Definition c.h:927
#define palloc_object(type)
Definition fe_memutils.h:74
#define palloc0_object(type)
Definition fe_memutils.h:75
#define foreach_ptr(type, var, lst)
Definition pg_list.h:469
@ 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
@ PGPA_TARGET_IDENTIFIER
Definition pgpa_ast.h:27
@ PGPA_TARGET_ORDERED_LIST
Definition pgpa_ast.h:28
static void pgpa_init_trove_slice(pgpa_trove_slice *tslice)
Definition pgpa_trove.c:431
static void pgpa_trove_add_to_slice(pgpa_trove_slice *tslice, pgpa_advice_tag_type tag, pgpa_advice_target *target)
Definition pgpa_trove.c:366
static int fb(int x)
pgpa_target_type ttype
Definition pgpa_ast.h:49
pgpa_trove_slice rel
Definition pgpa_trove.c:53
pgpa_trove_slice join
Definition pgpa_trove.c:52
pgpa_trove_slice scan
Definition pgpa_trove.c:54

References Assert, pgpa_advice_target::children, fb(), foreach_ptr, pgpa_trove::join, palloc0_object, palloc_object, pgpa_init_trove_slice(), PGPA_TAG_BITMAP_HEAP_SCAN, PGPA_TAG_FOREIGN_JOIN, PGPA_TAG_GATHER, PGPA_TAG_GATHER_MERGE, PGPA_TAG_HASH_JOIN, PGPA_TAG_INDEX_ONLY_SCAN, PGPA_TAG_INDEX_SCAN, PGPA_TAG_JOIN_ORDER, PGPA_TAG_MERGE_JOIN_MATERIALIZE, PGPA_TAG_MERGE_JOIN_PLAIN, PGPA_TAG_NESTED_LOOP_MATERIALIZE, PGPA_TAG_NESTED_LOOP_MEMOIZE, PGPA_TAG_NESTED_LOOP_PLAIN, PGPA_TAG_NO_GATHER, PGPA_TAG_PARTITIONWISE, PGPA_TAG_SEMIJOIN_NON_UNIQUE, PGPA_TAG_SEMIJOIN_UNIQUE, PGPA_TAG_SEQ_SCAN, PGPA_TAG_TID_SCAN, PGPA_TARGET_IDENTIFIER, PGPA_TARGET_ORDERED_LIST, pgpa_trove_add_to_slice(), pgpa_trove::rel, pgpa_trove::scan, and pgpa_advice_target::ttype.

Referenced by pgpa_planner_setup().

◆ pgpa_cstring_trove_entry()

char * pgpa_cstring_trove_entry ( pgpa_trove_entry entry)
extern

Definition at line 295 of file pgpa_trove.c.

296{
298
301
302 /* JOIN_ORDER tags are transformed by pgpa_build_trove; undo that here */
303 if (entry->tag != PGPA_TAG_JOIN_ORDER)
305 else
307
309
310 if (entry->target->itarget != NULL)
311 {
314 }
315
316 if (entry->tag != PGPA_TAG_JOIN_ORDER)
318
319 return buf.data;
320}
static char buf[DEFAULT_XLOG_SEG_SIZE]
char * pgpa_cstring_advice_tag(pgpa_advice_tag_type advice_tag)
Definition pgpa_ast.c:29
void pgpa_format_advice_target(StringInfo str, pgpa_advice_target *target)
Definition pgpa_ast.c:164
void pgpa_format_index_target(StringInfo str, pgpa_index_target *itarget)
Definition pgpa_ast.c:200
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void appendStringInfoChar(StringInfo str, char ch)
Definition stringinfo.c:242
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
pgpa_index_target * itarget
Definition pgpa_ast.h:64
pgpa_advice_target * target
Definition pgpa_trove.h:59
pgpa_advice_tag_type tag
Definition pgpa_trove.h:58

References appendStringInfo(), appendStringInfoChar(), Assert, buf, fb(), initStringInfo(), pgpa_advice_target::itarget, pgpa_cstring_advice_tag(), pgpa_format_advice_target(), pgpa_format_index_target(), PGPA_TAG_JOIN_ORDER, PGPA_TARGET_ORDERED_LIST, pgpa_trove_entry::tag, pgpa_trove_entry::target, and pgpa_advice_target::ttype.

Referenced by pgpa_planner_append_feedback().

◆ pgpa_trove_append_flags()

void pgpa_trove_append_flags ( StringInfo  buf,
int  flags 
)
extern

Definition at line 343 of file pgpa_trove.c.

344{
345 if ((flags & PGPA_TE_MATCH_FULL) != 0)
346 {
347 Assert((flags & PGPA_TE_MATCH_PARTIAL) != 0);
348 appendStringInfo(buf, "matched");
349 }
350 else if ((flags & PGPA_TE_MATCH_PARTIAL) != 0)
351 appendStringInfo(buf, "partially matched");
352 else
353 appendStringInfo(buf, "not matched");
354 if ((flags & PGPA_TE_INAPPLICABLE) != 0)
355 appendStringInfo(buf, ", inapplicable");
356 if ((flags & PGPA_TE_CONFLICTING) != 0)
357 appendStringInfo(buf, ", conflicting");
358 if ((flags & PGPA_TE_FAILED) != 0)
359 appendStringInfo(buf, ", failed");
360}
#define PGPA_TE_INAPPLICABLE
Definition pgpa_trove.h:48
#define PGPA_TE_MATCH_FULL
Definition pgpa_trove.h:47
#define PGPA_TE_MATCH_PARTIAL
Definition pgpa_trove.h:46
#define PGPA_TE_CONFLICTING
Definition pgpa_trove.h:49
#define PGPA_TE_FAILED
Definition pgpa_trove.h:50

References appendStringInfo(), Assert, buf, PGPA_TE_CONFLICTING, PGPA_TE_FAILED, PGPA_TE_INAPPLICABLE, PGPA_TE_MATCH_FULL, and PGPA_TE_MATCH_PARTIAL.

Referenced by pg_plan_advice_explain_feedback(), and pgpa_planner_feedback_warning().

◆ pgpa_trove_lookup()

void pgpa_trove_lookup ( pgpa_trove trove,
pgpa_trove_lookup_type  type,
int  nrids,
pgpa_identifier rids,
pgpa_trove_result result 
)
extern

Definition at line 233 of file pgpa_trove.c.

235{
237 Bitmapset *indexes;
238
239 Assert(nrids > 0);
240
242 tslice = &trove->scan;
243 else if (type == PGPA_TROVE_LOOKUP_JOIN)
244 tslice = &trove->join;
245 else
246 tslice = &trove->rel;
247
248 indexes = pgpa_trove_slice_lookup(tslice, &rids[0]);
249 for (int i = 1; i < nrids; ++i)
250 {
252
253 /*
254 * If the caller is asking about two relations that aren't part of the
255 * same subquery, they've messed up.
256 */
257 Assert(strings_equal_or_both_null(rids[0].plan_name,
258 rids[i].plan_name));
259
261 indexes = bms_union(indexes, other_indexes);
262 }
263
264 result->entries = tslice->entries;
265 result->indexes = indexes;
266}
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition bitmapset.c:251
int i
Definition isn.c:77
static bool strings_equal_or_both_null(const char *a, const char *b)
static Bitmapset * pgpa_trove_slice_lookup(pgpa_trove_slice *tslice, pgpa_identifier *rid)
Definition pgpa_trove.c:482
pgpa_trove_entry * entries
Definition pgpa_trove.h:95
Bitmapset * indexes
Definition pgpa_trove.h:96
const char * type

References Assert, bms_union(), pgpa_trove_result::entries, fb(), i, pgpa_trove_result::indexes, pgpa_trove::join, PGPA_TROVE_LOOKUP_JOIN, PGPA_TROVE_LOOKUP_SCAN, pgpa_trove_slice_lookup(), pgpa_trove::rel, pgpa_trove::scan, strings_equal_or_both_null(), and type.

Referenced by pgpa_build_simple_rel(), and pgpa_get_join_state().

◆ pgpa_trove_lookup_all()

void pgpa_trove_lookup_all ( pgpa_trove trove,
pgpa_trove_lookup_type  type,
pgpa_trove_entry **  entries,
int nentries 
)
extern

Definition at line 275 of file pgpa_trove.c.

277{
279
281 tslice = &trove->scan;
282 else if (type == PGPA_TROVE_LOOKUP_JOIN)
283 tslice = &trove->join;
284 else
285 tslice = &trove->rel;
286
287 *entries = tslice->entries;
288 *nentries = tslice->nused;
289}

References fb(), pgpa_trove::join, PGPA_TROVE_LOOKUP_JOIN, PGPA_TROVE_LOOKUP_SCAN, pgpa_trove::rel, pgpa_trove::scan, and type.

Referenced by pgpa_planner_append_feedback().

◆ pgpa_trove_set_flags()

void pgpa_trove_set_flags ( pgpa_trove_entry entries,
Bitmapset indexes,
int  flags 
)
extern

Definition at line 326 of file pgpa_trove.c.

327{
328 int i = -1;
329
330 while ((i = bms_next_member(indexes, i)) >= 0)
331 {
332 pgpa_trove_entry *entry = &entries[i];
333
334 entry->flags |= flags;
335 }
336}
int bms_next_member(const Bitmapset *a, int prevbit)
Definition bitmapset.c:1290
Definition pgpa_trove.h:57
int flags
Definition pgpa_trove.h:60

References bms_next_member(), pgpa_trove_entry::flags, and i.

Referenced by pgpa_planner_apply_join_path_advice(), pgpa_planner_apply_joinrel_advice(), and pgpa_planner_apply_scan_advice().