Skip to content

Commit 2d49398

Browse files
committed
check for delay_pathman_shutdown() every time hook is called, refactoring, more comments, fix TODO regarding the collation Oid
1 parent 0a1e171 commit 2d49398

File tree

6 files changed

+42
-28
lines changed

6 files changed

+42
-28
lines changed

src/hooks.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ pathman_relcache_hook(Datum arg, Oid relid)
498498
if (!IsPathmanReady())
499499
return;
500500

501+
/* Invalidation event for PATHMAN_CONFIG table (probably DROP) */
502+
if (relid == get_pathman_config_relid())
503+
delay_pathman_shutdown();
504+
501505
/* Invalidate PartParentInfo cache if needed */
502506
partitioned_table = forget_parent_of_partition(relid, &search);
503507

@@ -517,11 +521,11 @@ pathman_relcache_hook(Datum arg, Oid relid)
517521
/* Both syscache and pathman's cache say it isn't a partition */
518522
case PPS_ENTRY_NOT_FOUND:
519523
{
524+
/* NOTE: Remove NOT_USED when it's time */
525+
#ifdef NOT_USED
520526
elog(DEBUG2, "Invalidation message for relation %u [%u]",
521527
relid, MyProcPid);
522-
523-
if (relid == get_pathman_config_relid())
524-
delay_pathman_shutdown();
528+
#endif
525529
}
526530
break;
527531

src/init.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,11 @@ fill_prel_with_partitions(const Oid *partitions,
269269
if (prel->parttype == PT_RANGE)
270270
{
271271
MemoryContext old_mcxt;
272-
TypeCacheEntry *tce = lookup_type_cache(prel->atttype,
273-
TYPECACHE_CMP_PROC_FINFO);
274272

275273
/* Sort partitions by RangeEntry->min asc */
276274
qsort_arg((void *) prel->ranges, PrelChildrenCount(prel),
277275
sizeof(RangeEntry), cmp_range_entries,
278-
(void *) &tce->cmp_proc_finfo);
276+
(void *) &prel->cmp_proc);
279277

280278
/* Initialize 'prel->children' array */
281279
for (i = 0; i < PrelChildrenCount(prel); i++)
@@ -620,9 +618,10 @@ cmp_range_entries(const void *p1, const void *p2, void *arg)
620618
{
621619
const RangeEntry *v1 = (const RangeEntry *) p1;
622620
const RangeEntry *v2 = (const RangeEntry *) p2;
623-
FmgrInfo *cmp_proc = (FmgrInfo *) arg;
624621

625-
return FunctionCall2(cmp_proc, v1->min, v2->min);
622+
Oid cmp_proc_oid = *(Oid *) arg;
623+
624+
return OidFunctionCall2(cmp_proc_oid, v1->min, v2->min);
626625
}
627626

628627
/*

src/nodes_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ append_part_attr_to_tlist(List *tlist, Index relno, PartRelationInfo *prel)
160160
prel->attnum,
161161
prel->atttype,
162162
prel->atttypmod,
163-
InvalidOid,
163+
prel->attcollid,
164164
0);
165165

166166
Index last_item = list_length(tlist) + 1;

src/pathman.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050
*/
5151
#define PATHMAN_CONFIG "pathman_config"
5252
#define Natts_pathman_config 5
53-
#define Anum_pathman_config_id 1
54-
#define Anum_pathman_config_partrel 2
55-
#define Anum_pathman_config_attname 3
56-
#define Anum_pathman_config_parttype 4
57-
#define Anum_pathman_config_range_interval 5
53+
#define Anum_pathman_config_id 1 /* primary key */
54+
#define Anum_pathman_config_partrel 2 /* partitioned relation (regclass) */
55+
#define Anum_pathman_config_attname 3 /* partitioned column (text) */
56+
#define Anum_pathman_config_parttype 4 /* partitioning type (1|2) */
57+
#define Anum_pathman_config_range_interval 5 /* interval for RANGE pt. (text) */
5858

5959
/* type modifier (typmod) for 'range_interval' */
6060
#define PATHMAN_CONFIG_interval_typmod -1

src/relation_info.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static Oid get_parent_of_partition_internal(Oid partition,
6060
* refresh\invalidate\get\remove PartRelationInfo functions.
6161
*/
6262

63-
/* Create or update PartRelationInfo in local cache. */
63+
/* Create or update PartRelationInfo in local cache. Might emit ERROR. */
6464
PartRelationInfo *
6565
refresh_pathman_relation_info(Oid relid,
6666
PartType partitioning_type,
@@ -109,16 +109,23 @@ refresh_pathman_relation_info(Oid relid,
109109

110110
/* Initialize PartRelationInfo using syscache & typcache */
111111
prel->attnum = get_attnum(relid, part_column_name);
112-
prel->atttype = get_atttype(relid, prel->attnum);
113-
prel->atttypmod = get_atttypmod(relid, prel->attnum);
114112

115-
/* Fetch HASH & CMP fuctions for atttype */
113+
/* Attribute number sanity check */
114+
if (prel->attnum == InvalidAttrNumber)
115+
elog(ERROR, "Relation \"%s\" has no column \"%s\"",
116+
get_rel_name_or_relid(relid), part_column_name);
117+
118+
/* Fetch atttypid, atttypmod, and attcollation in a single cache lookup */
119+
get_atttypetypmodcoll(relid, prel->attnum,
120+
&prel->atttype, &prel->atttypmod, &prel->attcollid);
121+
122+
/* Fetch HASH & CMP fuctions and other stuff from type cache */
116123
typcache = lookup_type_cache(prel->atttype,
117124
TYPECACHE_CMP_PROC | TYPECACHE_HASH_PROC);
118125

119-
prel->attbyval = typcache->typbyval;
120-
prel->attlen = typcache->typlen;
121-
prel->attalign = typcache->typalign;
126+
prel->attbyval = typcache->typbyval;
127+
prel->attlen = typcache->typlen;
128+
prel->attalign = typcache->typalign;
122129

123130
prel->cmp_proc = typcache->cmp_proc;
124131
prel->hash_proc = typcache->hash_proc;
@@ -152,7 +159,7 @@ refresh_pathman_relation_info(Oid relid,
152159
return prel;
153160
}
154161

155-
/* Invalidate PartRelationInfo cache entry. Create new entry if 'found' is NULL */
162+
/* Invalidate PartRelationInfo cache entry. Create new entry if 'found' is NULL. */
156163
void
157164
invalidate_pathman_relation_info(Oid relid, bool *found)
158165
{
@@ -215,7 +222,8 @@ get_pathman_relation_info(Oid relid)
215222

216223
/* Refresh partitioned table cache entry */
217224
/* TODO: possible refactoring, pass found 'prel' instead of searching */
218-
refresh_pathman_relation_info(relid, part_type, attname);
225+
prel = refresh_pathman_relation_info(relid, part_type, attname);
226+
Assert(PrelIsValid(prel)); /* it MUST be valid if we got here */
219227
}
220228
/* Else clear remaining cache entry */
221229
else remove_pathman_relation_info(relid);
@@ -400,7 +408,7 @@ forget_parent_of_partition(Oid partition, PartParentSearch *status)
400408
return get_parent_of_partition_internal(partition, status, HASH_REMOVE);
401409
}
402410

403-
/* Peturn partition parent's Oid */
411+
/* Return partition parent's Oid */
404412
Oid
405413
get_parent_of_partition(Oid partition, PartParentSearch *status)
406414
{
@@ -546,11 +554,13 @@ try_perform_parent_refresh(Oid parent)
546554
parttype = DatumGetPartType(values[Anum_pathman_config_parttype - 1]);
547555
attname = DatumGetTextP(values[Anum_pathman_config_attname - 1]);
548556

549-
if (!refresh_pathman_relation_info(parent, parttype, text_to_cstring(attname)))
557+
/* If anything went wrong, return false (actually, it might throw ERROR) */
558+
if (!PrelIsValid(refresh_pathman_relation_info(parent, parttype,
559+
text_to_cstring(attname))))
550560
return false;
551561
}
552-
else
553-
return false;
562+
/* Not a partitioned relation */
563+
else return false;
554564

555565
return true;
556566
}

src/relation_info.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ typedef struct
5757
int32 atttypmod; /* partitioned column type modifier */
5858
bool attbyval; /* is partitioned column stored by value? */
5959
int16 attlen; /* length of the partitioned column's type */
60-
int attalign;
60+
int attalign; /* alignment of the part column's type */
61+
Oid attcollid; /* collation of the partitioned column */
6162

6263
Oid cmp_proc, /* comparison fuction for 'atttype' */
6364
hash_proc; /* hash function for 'atttype' */

0 commit comments

Comments
 (0)