Skip to content

Commit 2cdb2bd

Browse files
committed
Avoid segfaults on 1.5-upgraded installations before 10e6c71
1 parent bf0a84c commit 2cdb2bd

File tree

6 files changed

+27
-15
lines changed

6 files changed

+27
-15
lines changed

Diff for: src/include/pathman.h

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
*/
4747
#define PATHMAN_CONFIG "pathman_config"
4848
#define Natts_pathman_config 4
49+
#define Natts_pathman_config_historic 5
4950
#define Anum_pathman_config_partrel 1 /* partitioned relation (regclass) */
5051
#define Anum_pathman_config_expr 2 /* partition expression (original) */
5152
#define Anum_pathman_config_parttype 3 /* partitioning type (1|2) */

Diff for: src/init.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ pathman_config_contains_relation(Oid relid, Datum *values, bool *isnull,
648648
Snapshot snapshot;
649649
HeapTuple htup;
650650
bool contains_rel = false;
651+
TupleDesc tupleDescr;
651652

652653
ScanKeyInit(&key[0],
653654
Anum_pathman_config_partrel,
@@ -656,13 +657,15 @@ pathman_config_contains_relation(Oid relid, Datum *values, bool *isnull,
656657

657658
/* Open PATHMAN_CONFIG with latest snapshot available */
658659
rel = heap_open(get_pathman_config_relid(false), AccessShareLock);
660+
tupleDescr = RelationGetDescr(rel);
659661

660662
/* Check that 'partrel' column is of regclass type */
661-
Assert(TupleDescAttr(RelationGetDescr(rel),
663+
Assert(TupleDescAttr(tupleDescr,
662664
Anum_pathman_config_partrel - 1)->atttypid == REGCLASSOID);
663665

664666
/* Check that number of columns == Natts_pathman_config */
665-
Assert(RelationGetDescr(rel)->natts == Natts_pathman_config);
667+
Assert(tupleDescr->natts == Natts_pathman_config
668+
|| tupleDescr->natts == Natts_pathman_config_historic);
666669

667670
snapshot = RegisterSnapshot(GetLatestSnapshot());
668671
#if PG_VERSION_NUM >= 120000
@@ -679,7 +682,7 @@ pathman_config_contains_relation(Oid relid, Datum *values, bool *isnull,
679682
if (values && isnull)
680683
{
681684
htup = heap_copytuple(htup);
682-
heap_deform_tuple(htup, RelationGetDescr(rel), values, isnull);
685+
heap_deform_tuple(htup, tupleDescr, values, isnull);
683686

684687
/* Perform checks for non-NULL columns */
685688
Assert(!isnull[Anum_pathman_config_partrel - 1]);

Diff for: src/partition_creation.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ create_single_range_partition_internal(Oid parent_relid,
116116
init_callback_params callback_params;
117117
List *trigger_columns = NIL;
118118
Node *expr;
119-
Datum values[Natts_pathman_config];
120-
bool isnull[Natts_pathman_config];
119+
Datum values[Natts_pathman_config_historic];
120+
bool isnull[Natts_pathman_config_historic];
121121

122122

123123
/*
@@ -353,8 +353,8 @@ Oid
353353
create_partitions_for_value_internal(Oid relid, Datum value, Oid value_type)
354354
{
355355
Oid partid = InvalidOid; /* last created partition (or InvalidOid) */
356-
Datum values[Natts_pathman_config];
357-
bool isnull[Natts_pathman_config];
356+
Datum values[Natts_pathman_config_historic];
357+
bool isnull[Natts_pathman_config_historic];
358358

359359
/* Get both PartRelationInfo & PATHMAN_CONFIG contents for this relation */
360360
if (pathman_config_contains_relation(relid, values, isnull, NULL, NULL))
@@ -1914,8 +1914,8 @@ build_partitioning_expression(Oid parent_relid,
19141914
List **columns) /* ret val #2 */
19151915
{
19161916
/* Values extracted from PATHMAN_CONFIG */
1917-
Datum values[Natts_pathman_config];
1918-
bool isnull[Natts_pathman_config];
1917+
Datum values[Natts_pathman_config_historic];
1918+
bool isnull[Natts_pathman_config_historic];
19191919
char *expr_cstr;
19201920
Node *expr;
19211921

Diff for: src/pl_funcs.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,8 @@ add_to_pathman_config(PG_FUNCTION_ARGS)
751751
uint32 children_count;
752752

753753
Relation pathman_config;
754-
Datum values[Natts_pathman_config];
755-
bool isnull[Natts_pathman_config];
754+
Datum values[Natts_pathman_config_historic];
755+
bool isnull[Natts_pathman_config_historic];
756756
HeapTuple htup;
757757

758758
Oid expr_type;
@@ -851,6 +851,14 @@ add_to_pathman_config(PG_FUNCTION_ARGS)
851851
values[Anum_pathman_config_expr - 1] = CStringGetTextDatum(expression);
852852
isnull[Anum_pathman_config_expr - 1] = false;
853853

854+
/*
855+
* In case of 1.5 update before 10e6c71 there is acutlly 5 attributes in
856+
* pathman_config description (inclusing cooked expression). To avoid
857+
* potential problems we allocate 5th attribute and initialize it with null.
858+
*/
859+
values[Natts_pathman_config_historic - 1] = (Datum) 0;
860+
isnull[Natts_pathman_config_historic - 1] = true;
861+
854862
/* Insert new row into PATHMAN_CONFIG */
855863
pathman_config = heap_open(get_pathman_config_relid(false), RowExclusiveLock);
856864

Diff for: src/pl_range_funcs.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ create_single_range_partition_pl(PG_FUNCTION_ARGS)
110110
RangeVar *partition_name_rv;
111111
char *tablespace;
112112

113-
Datum values[Natts_pathman_config];
114-
bool isnull[Natts_pathman_config];
113+
Datum values[Natts_pathman_config_historic];
114+
bool isnull[Natts_pathman_config_historic];
115115

116116

117117
/* Handle 'parent_relid' */

Diff for: src/relation_info.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ get_pathman_relation_info(Oid relid)
350350
{
351351
PartRelationInfo *prel = NULL;
352352
ItemPointerData iptr;
353-
Datum values[Natts_pathman_config];
354-
bool isnull[Natts_pathman_config];
353+
Datum values[Natts_pathman_config_historic];
354+
bool isnull[Natts_pathman_config_historic];
355355
bool found;
356356

357357
/*

0 commit comments

Comments
 (0)