PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pgpa_trove.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * pgpa_trove.h
4 * All of the advice given for a particular query, appropriately
5 * organized for convenient access.
6 *
7 * Copyright (c) 2016-2026, PostgreSQL Global Development Group
8 *
9 * contrib/pg_plan_advice/pgpa_trove.h
10 *
11 *-------------------------------------------------------------------------
12 */
13#ifndef PGPA_TROVE_H
14#define PGPA_TROVE_H
15
16#include "pgpa_ast.h"
17
18#include "nodes/bitmapset.h"
19
20typedef struct pgpa_trove pgpa_trove;
21
22/*
23 * Flags that can be set on a pgpa_trove_entry to indicate what happened when
24 * trying to plan using advice.
25 *
26 * PGPA_TE_MATCH_PARTIAL means that we found some part of the query that at
27 * least partially matched the target; e.g. given JOIN_ORDER(a b), this would
28 * be set if we ever saw any joinrel including either "a" or "b".
29 *
30 * PGPA_TE_MATCH_FULL means that we found an exact match for the target; e.g.
31 * given JOIN_ORDER(a b), this would be set if we saw a joinrel containing
32 * exactly "a" and "b" and nothing else.
33 *
34 * PGPA_TE_INAPPLICABLE means that the advice doesn't properly apply to the
35 * target; e.g. INDEX_SCAN(foo bar_idx) would be so marked if bar_idx does not
36 * exist on foo. The fact that this bit has been set does not mean that the
37 * advice had no effect.
38 *
39 * PGPA_TE_CONFLICTING means that a conflict was detected between what this
40 * advice wants and what some other plan advice wants; e.g. JOIN_ORDER(a b)
41 * would conflict with HASH_JOIN(a), because the former requires "a" to be the
42 * outer table while the latter requires it to be the inner table.
43 *
44 * PGPA_TE_FAILED means that the resulting plan did not conform to the advice.
45 */
46#define PGPA_TE_MATCH_PARTIAL 0x0001
47#define PGPA_TE_MATCH_FULL 0x0002
48#define PGPA_TE_INAPPLICABLE 0x0004
49#define PGPA_TE_CONFLICTING 0x0008
50#define PGPA_TE_FAILED 0x0010
51
52/*
53 * Each entry in a trove of advice represents the application of a tag to
54 * a single target.
55 */
62
63/*
64 * What kind of information does the caller want to find in a trove?
65 *
66 * PGPA_TROVE_LOOKUP_SCAN means we're looking for scan advice.
67 *
68 * PGPA_TROVE_LOOKUP_JOIN means we're looking for join-related advice.
69 * This includes join order advice, join method advice, and semijoin-uniqueness
70 * advice.
71 *
72 * PGPA_TROVE_LOOKUP_REL means we're looking for general advice about this
73 * a RelOptInfo that may correspond to either a scan or a join. This includes
74 * gather-related advice and partitionwise advice. Note that partitionwise
75 * advice might seem like join advice, but that's not a helpful way of viewing
76 * the matter because (1) partitionwise advice is also relevant at the scan
77 * level and (2) other types of join advice affect only what to do from
78 * join_path_setup_hook, but partitionwise advice affects what to do in
79 * joinrel_setup_hook.
80 */
87
88/*
89 * This struct is used to store the result of a trove lookup. For each member
90 * of "indexes", the entry at the corresponding offset within "entries" is one
91 * of the results.
92 */
98
100extern void pgpa_trove_lookup(pgpa_trove *trove,
102 int nrids,
103 pgpa_identifier *rids,
104 pgpa_trove_result *result);
105extern void pgpa_trove_lookup_all(pgpa_trove *trove,
107 pgpa_trove_entry **entries,
108 int *nentries);
109extern char *pgpa_cstring_trove_entry(pgpa_trove_entry *entry);
110extern void pgpa_trove_set_flags(pgpa_trove_entry *entries,
111 Bitmapset *indexes, int flags);
112extern void pgpa_trove_append_flags(StringInfo buf, int flags);
113
114#endif
static char buf[DEFAULT_XLOG_SEG_SIZE]
pgpa_advice_tag_type
Definition pgpa_ast.h:81
void pgpa_trove_set_flags(pgpa_trove_entry *entries, Bitmapset *indexes, int flags)
Definition pgpa_trove.c:326
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
pgpa_trove * pgpa_build_trove(List *advice_items)
Definition pgpa_trove.c:132
void pgpa_trove_append_flags(StringInfo buf, int flags)
Definition pgpa_trove.c:343
void pgpa_trove_lookup_all(pgpa_trove *trove, pgpa_trove_lookup_type type, pgpa_trove_entry **entries, int *nentries)
Definition pgpa_trove.c:275
char * pgpa_cstring_trove_entry(pgpa_trove_entry *entry)
Definition pgpa_trove.c:295
void pgpa_trove_lookup(pgpa_trove *trove, pgpa_trove_lookup_type type, int nrids, pgpa_identifier *rids, pgpa_trove_result *result)
Definition pgpa_trove.c:233
static int fb(int x)
Definition pg_list.h:54
Definition pgpa_trove.h:57
pgpa_advice_target * target
Definition pgpa_trove.h:59
pgpa_advice_tag_type tag
Definition pgpa_trove.h:58
int flags
Definition pgpa_trove.h:60
pgpa_trove_entry * entries
Definition pgpa_trove.h:95
Bitmapset * indexes
Definition pgpa_trove.h:96
const char * type