Skip to content

Commit ad49922

Browse files
committed
move get_rel_persistence() to pg_compat, fix warnings (do_we_hold_the_lock())
1 parent 5157e6c commit ad49922

File tree

6 files changed

+105
-85
lines changed

6 files changed

+105
-85
lines changed

src/compat/pg_compat.c

Lines changed: 83 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "compat/pg_compat.h"
1515

16+
#include "access/htup_details.h"
1617
#include "catalog/pg_proc.h"
1718
#include "foreign/fdwapi.h"
1819
#include "optimizer/clauses.h"
@@ -21,60 +22,11 @@
2122
#include "port.h"
2223
#include "utils.h"
2324
#include "utils/lsyscache.h"
25+
#include "utils/syscache.h"
2426

2527
#include <math.h>
2628

2729

28-
/* Common code */
29-
void
30-
set_append_rel_size_compat(PlannerInfo *root, RelOptInfo *rel, Index rti)
31-
{
32-
double parent_rows = 0;
33-
double parent_size = 0;
34-
ListCell *l;
35-
36-
foreach(l, root->append_rel_list)
37-
{
38-
AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(l);
39-
Index childRTindex,
40-
parentRTindex = rti;
41-
RelOptInfo *childrel;
42-
43-
/* append_rel_list contains all append rels; ignore others */
44-
if (appinfo->parent_relid != parentRTindex)
45-
continue;
46-
47-
childRTindex = appinfo->child_relid;
48-
49-
childrel = find_base_rel(root, childRTindex);
50-
Assert(childrel->reloptkind == RELOPT_OTHER_MEMBER_REL);
51-
52-
/*
53-
* Accumulate size information from each live child.
54-
*/
55-
Assert(childrel->rows > 0);
56-
57-
parent_rows += childrel->rows;
58-
59-
#if PG_VERSION_NUM >= 90600
60-
parent_size += childrel->reltarget->width * childrel->rows;
61-
#else
62-
parent_size += childrel->width * childrel->rows;
63-
#endif
64-
}
65-
66-
/* Set 'rows' for append relation */
67-
rel->rows = parent_rows;
68-
69-
#if PG_VERSION_NUM >= 90600
70-
rel->reltarget->width = rint(parent_size / parent_rows);
71-
#else
72-
rel->width = rint(parent_size / parent_rows);
73-
#endif
74-
75-
rel->tuples = parent_rows;
76-
}
77-
7830

7931
/*
8032
* ----------
@@ -84,7 +36,6 @@ set_append_rel_size_compat(PlannerInfo *root, RelOptInfo *rel, Index rti)
8436

8537
#if PG_VERSION_NUM >= 90600
8638

87-
8839
/*
8940
* make_result
9041
* Build a Result plan node
@@ -320,7 +271,6 @@ create_plain_partial_paths(PlannerInfo *root, RelOptInfo *rel)
320271

321272
#else /* PG_VERSION_NUM >= 90500 */
322273

323-
324274
/*
325275
* set_dummy_rel_pathlist
326276
* Build a dummy path for a relation that's been excluded by constraints
@@ -350,4 +300,85 @@ set_dummy_rel_pathlist(RelOptInfo *rel)
350300
}
351301

352302

303+
/*
304+
* Returns the relpersistence associated with a given relation.
305+
*
306+
* NOTE: this function is implemented in 9.6
307+
*/
308+
char
309+
get_rel_persistence(Oid relid)
310+
{
311+
HeapTuple tp;
312+
Form_pg_class reltup;
313+
char result;
314+
315+
tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
316+
if (!HeapTupleIsValid(tp))
317+
elog(ERROR, "cache lookup failed for relation %u", relid);
318+
319+
reltup = (Form_pg_class) GETSTRUCT(tp);
320+
result = reltup->relpersistence;
321+
ReleaseSysCache(tp);
322+
323+
return result;
324+
}
325+
326+
353327
#endif /* PG_VERSION_NUM >= 90600 */
328+
329+
330+
331+
/*
332+
* -------------
333+
* Common code
334+
* -------------
335+
*/
336+
337+
void
338+
set_append_rel_size_compat(PlannerInfo *root, RelOptInfo *rel, Index rti)
339+
{
340+
double parent_rows = 0;
341+
double parent_size = 0;
342+
ListCell *l;
343+
344+
foreach(l, root->append_rel_list)
345+
{
346+
AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(l);
347+
Index childRTindex,
348+
parentRTindex = rti;
349+
RelOptInfo *childrel;
350+
351+
/* append_rel_list contains all append rels; ignore others */
352+
if (appinfo->parent_relid != parentRTindex)
353+
continue;
354+
355+
childRTindex = appinfo->child_relid;
356+
357+
childrel = find_base_rel(root, childRTindex);
358+
Assert(childrel->reloptkind == RELOPT_OTHER_MEMBER_REL);
359+
360+
/*
361+
* Accumulate size information from each live child.
362+
*/
363+
Assert(childrel->rows > 0);
364+
365+
parent_rows += childrel->rows;
366+
367+
#if PG_VERSION_NUM >= 90600
368+
parent_size += childrel->reltarget->width * childrel->rows;
369+
#else
370+
parent_size += childrel->width * childrel->rows;
371+
#endif
372+
}
373+
374+
/* Set 'rows' for append relation */
375+
rel->rows = parent_rows;
376+
377+
#if PG_VERSION_NUM >= 90600
378+
rel->reltarget->width = rint(parent_size / parent_rows);
379+
#else
380+
rel->width = rint(parent_size / parent_rows);
381+
#endif
382+
383+
rel->tuples = parent_rows;
384+
}

src/include/compat/pg_compat.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
#include "optimizer/paths.h"
2121

2222

23-
void set_append_rel_size_compat(PlannerInfo *root, RelOptInfo *rel, Index rti);
24-
23+
/*
24+
* ----------
25+
* Variants
26+
* ----------
27+
*/
2528

2629
#if PG_VERSION_NUM >= 90600
2730

28-
2931
/* adjust_appendrel_attrs() */
3032
#define adjust_rel_targetlist_compat(root, dst_rel, src_rel, appinfo) \
3133
do { \
@@ -91,7 +93,6 @@ extern void set_rel_consider_parallel(PlannerInfo *root,
9193

9294
#else /* PG_VERSION_NUM >= 90500 */
9395

94-
9596
/* adjust_appendrel_attrs() */
9697
#define adjust_rel_targetlist_compat(root, dst_rel, src_rel, appinfo) \
9798
do { \
@@ -145,7 +146,19 @@ extern void set_rel_consider_parallel(PlannerInfo *root,
145146
void set_dummy_rel_pathlist(RelOptInfo *rel);
146147

147148

149+
/* get_rel_persistence() */
150+
char get_rel_persistence(Oid relid);
151+
148152
#endif /* PG_VERSION_NUM */
149153

150154

155+
/*
156+
* -------------
157+
* Common code
158+
* -------------
159+
*/
160+
161+
void set_append_rel_size_compat(PlannerInfo *root, RelOptInfo *rel, Index rti);
162+
163+
151164
#endif /* PG_COMPAT_H */

src/include/utils.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ List * list_reverse(List *l);
4040
Oid get_rel_owner(Oid relid);
4141
char * get_rel_name_or_relid(Oid relid);
4242
Oid get_attribute_type(Oid relid, const char *attname, bool missing_ok);
43-
#if PG_VERSION_NUM < 90600
44-
char get_rel_persistence(Oid relid);
45-
#endif
4643

4744
/*
4845
* Operator-related stuff.

src/pl_funcs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* ------------------------------------------------------------------------
99
*/
1010

11+
#include "compat/pg_compat.h"
12+
1113
#include "init.h"
1214
#include "utils.h"
1315
#include "pathman.h"

src/utils.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "catalog/pg_type.h"
1919
#include "catalog/pg_extension.h"
2020
#include "catalog/pg_operator.h"
21-
#include "catalog/pg_inherits.h"
2221
#include "commands/extension.h"
2322
#include "miscadmin.h"
2423
#include "optimizer/var.h"
@@ -230,31 +229,6 @@ get_attribute_type(Oid relid, const char *attname, bool missing_ok)
230229
return InvalidOid;
231230
}
232231

233-
#if PG_VERSION_NUM < 90600
234-
/*
235-
* Returns the relpersistence associated with a given relation.
236-
*
237-
* NOTE: this function is implemented in 9.6
238-
*/
239-
char
240-
get_rel_persistence(Oid relid)
241-
{
242-
HeapTuple tp;
243-
Form_pg_class reltup;
244-
char result;
245-
246-
tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
247-
if (!HeapTupleIsValid(tp))
248-
elog(ERROR, "cache lookup failed for relation %u", relid);
249-
250-
reltup = (Form_pg_class) GETSTRUCT(tp);
251-
result = reltup->relpersistence;
252-
ReleaseSysCache(tp);
253-
254-
return result;
255-
}
256-
#endif
257-
258232

259233

260234
/*

src/xact_handling.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ xact_object_is_visible(TransactionId obj_xmin)
171171
/*
172172
* Do we hold the specified lock?
173173
*/
174+
#ifdef __GNUC__
175+
__attribute__((unused))
176+
#endif
174177
static inline bool
175178
do_we_hold_the_lock(Oid relid, LOCKMODE lockmode)
176179
{

0 commit comments

Comments
 (0)