Skip to content

Commit 3301383

Browse files
committed
Avoid segfaults on 1.5-upgraded installations before 10e6c71
1 parent afdf2f5 commit 3301383

File tree

6 files changed

+25
-13
lines changed

6 files changed

+25
-13
lines changed

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) */

src/init.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ pathman_config_contains_relation(Oid relid, Datum *values, bool *isnull,
620620
Snapshot snapshot;
621621
HeapTuple htup;
622622
bool contains_rel = false;
623+
TupleDesc tupleDescr;
623624

624625
ScanKeyInit(&key[0],
625626
Anum_pathman_config_partrel,
@@ -628,13 +629,15 @@ pathman_config_contains_relation(Oid relid, Datum *values, bool *isnull,
628629

629630
/* Open PATHMAN_CONFIG with latest snapshot available */
630631
rel = heap_open(get_pathman_config_relid(false), AccessShareLock);
632+
tupleDescr = RelationGetDescr(rel);
631633

632634
/* Check that 'partrel' column is of regclass type */
633-
Assert(TupleDescAttr(RelationGetDescr(rel),
635+
Assert(TupleDescAttr(tupleDescr,
634636
Anum_pathman_config_partrel - 1)->atttypid == REGCLASSOID);
635637

636638
/* Check that number of columns == Natts_pathman_config */
637-
Assert(RelationGetDescr(rel)->natts == Natts_pathman_config);
639+
Assert(tupleDescr->natts == Natts_pathman_config
640+
|| tupleDescr->natts == Natts_pathman_config_historic);
638641

639642
snapshot = RegisterSnapshot(GetLatestSnapshot());
640643
scan = heap_beginscan(rel, snapshot, 1, key);
@@ -647,7 +650,7 @@ pathman_config_contains_relation(Oid relid, Datum *values, bool *isnull,
647650
if (values && isnull)
648651
{
649652
htup = heap_copytuple(htup);
650-
heap_deform_tuple(htup, RelationGetDescr(rel), values, isnull);
653+
heap_deform_tuple(htup, tupleDescr, values, isnull);
651654

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

src/partition_creation.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ create_partitions_for_value_internal(Oid relid, Datum value, Oid value_type,
338338

339339
PG_TRY();
340340
{
341-
Datum values[Natts_pathman_config];
342-
bool isnull[Natts_pathman_config];
341+
Datum values[Natts_pathman_config_historic];
342+
bool isnull[Natts_pathman_config_historic];
343343

344344
/* Get both PartRelationInfo & PATHMAN_CONFIG contents for this relation */
345345
if (pathman_config_contains_relation(relid, values, isnull, NULL, NULL))
@@ -1842,8 +1842,8 @@ build_partitioning_expression(Oid parent_relid,
18421842
List **columns) /* ret val #2 */
18431843
{
18441844
/* Values extracted from PATHMAN_CONFIG */
1845-
Datum values[Natts_pathman_config];
1846-
bool isnull[Natts_pathman_config];
1845+
Datum values[Natts_pathman_config_historic];
1846+
bool isnull[Natts_pathman_config_historic];
18471847
char *expr_cstr;
18481848
Node *expr;
18491849

src/pl_funcs.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,8 @@ add_to_pathman_config(PG_FUNCTION_ARGS)
700700
uint32 children_count;
701701

702702
Relation pathman_config;
703-
Datum values[Natts_pathman_config];
704-
bool isnull[Natts_pathman_config];
703+
Datum values[Natts_pathman_config_historic];
704+
bool isnull[Natts_pathman_config_historic];
705705
HeapTuple htup;
706706

707707
Oid expr_type;
@@ -797,6 +797,14 @@ add_to_pathman_config(PG_FUNCTION_ARGS)
797797
values[Anum_pathman_config_expr - 1] = CStringGetTextDatum(expression);
798798
isnull[Anum_pathman_config_expr - 1] = false;
799799

800+
/*
801+
* In case of 1.5 update before 10e6c71 there is acutlly 5 attributes in
802+
* pathman_config description (inclusing cooked expression). To avoid
803+
* potential problems we allocate 5th attribute and initialize it with null.
804+
*/
805+
values[Natts_pathman_config_historic - 1] = (Datum)0;
806+
isnull[Natts_pathman_config_historic - 1] = true;
807+
800808
/* Insert new row into PATHMAN_CONFIG */
801809
pathman_config = heap_open(get_pathman_config_relid(false), RowExclusiveLock);
802810

src/pl_range_funcs.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ create_single_range_partition_pl(PG_FUNCTION_ARGS)
103103
RangeVar *partition_name_rv;
104104
char *tablespace;
105105

106-
Datum values[Natts_pathman_config];
107-
bool isnull[Natts_pathman_config];
106+
Datum values[Natts_pathman_config_historic];
107+
bool isnull[Natts_pathman_config_historic];
108108

109109

110110
/* Handle 'parent_relid' */

src/relation_info.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ get_pathman_relation_info(Oid relid)
336336
{
337337
PartRelationInfo *prel = NULL;
338338
ItemPointerData iptr;
339-
Datum values[Natts_pathman_config];
340-
bool isnull[Natts_pathman_config];
339+
Datum values[Natts_pathman_config_historic];
340+
bool isnull[Natts_pathman_config_historic];
341341
bool found;
342342

343343
/*

0 commit comments

Comments
 (0)