Skip to content

Commit 06ce38b

Browse files
committed
Merge branch 'rel_1_3_beta' into rel_future_beta
2 parents b78e4a7 + a93a846 commit 06ce38b

File tree

7 files changed

+250
-23
lines changed

7 files changed

+250
-23
lines changed

src/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ pathman_relcache_hook(Datum arg, Oid relid)
605605
return;
606606

607607
/* Invalidation event for PATHMAN_CONFIG table (probably DROP) */
608-
if (relid == get_pathman_config_relid())
608+
if (relid == get_pathman_config_relid(false))
609609
delay_pathman_shutdown();
610610

611611
/* Invalidate PartParentInfo cache if needed */

src/init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ pathman_config_contains_relation(Oid relid, Datum *values, bool *isnull,
693693
ObjectIdGetDatum(relid));
694694

695695
/* Open PATHMAN_CONFIG with latest snapshot available */
696-
rel = heap_open(get_pathman_config_relid(), AccessShareLock);
696+
rel = heap_open(get_pathman_config_relid(false), AccessShareLock);
697697

698698
/* Check that 'partrel' column is if regclass type */
699699
Assert(RelationGetDescr(rel)->
@@ -767,7 +767,7 @@ read_pathman_params(Oid relid, Datum *values, bool *isnull)
767767
BTEqualStrategyNumber, F_OIDEQ,
768768
ObjectIdGetDatum(relid));
769769

770-
rel = heap_open(get_pathman_config_params_relid(), AccessShareLock);
770+
rel = heap_open(get_pathman_config_params_relid(false), AccessShareLock);
771771
snapshot = RegisterSnapshot(GetLatestSnapshot());
772772
scan = heap_beginscan(rel, snapshot, 1, key);
773773

@@ -806,7 +806,7 @@ read_pathman_config(void)
806806
HeapTuple htup;
807807

808808
/* Open PATHMAN_CONFIG with latest snapshot available */
809-
rel = heap_open(get_pathman_config_relid(), AccessShareLock);
809+
rel = heap_open(get_pathman_config_relid(false), AccessShareLock);
810810

811811
/* Check that 'partrel' column is if regclass type */
812812
Assert(RelationGetDescr(rel)->

src/pathman.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ extern Oid pathman_config_params_relid;
8585
/*
8686
* Just to clarify our intentions (return the corresponding relid).
8787
*/
88-
Oid get_pathman_config_relid(void);
89-
Oid get_pathman_config_params_relid(void);
88+
Oid get_pathman_config_relid(bool invalid_is_ok);
89+
Oid get_pathman_config_params_relid(bool invalid_is_ok);
9090

9191
/*
9292
* pg_pathman's global state structure.

src/pg_pathman.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,16 +1930,32 @@ generate_mergeappend_paths(PlannerInfo *root, RelOptInfo *rel,
19301930
* Get cached PATHMAN_CONFIG relation Oid.
19311931
*/
19321932
Oid
1933-
get_pathman_config_relid(void)
1933+
get_pathman_config_relid(bool invalid_is_ok)
19341934
{
1935+
/* Raise ERROR if Oid is invalid */
1936+
if (!OidIsValid(pathman_config_relid) && !invalid_is_ok)
1937+
elog(ERROR,
1938+
(!IsPathmanInitialized() ?
1939+
"pg_pathman is not initialized yet" :
1940+
"unexpected error in function "
1941+
CppAsString(get_pathman_config_relid)));
1942+
19351943
return pathman_config_relid;
19361944
}
19371945

19381946
/*
19391947
* Get cached PATHMAN_CONFIG_PARAMS relation Oid.
19401948
*/
19411949
Oid
1942-
get_pathman_config_params_relid(void)
1950+
get_pathman_config_params_relid(bool invalid_is_ok)
19431951
{
1952+
/* Raise ERROR if Oid is invalid */
1953+
if (!OidIsValid(pathman_config_relid) && !invalid_is_ok)
1954+
elog(ERROR,
1955+
(!IsPathmanInitialized() ?
1956+
"pg_pathman is not initialized yet" :
1957+
"unexpected error in function "
1958+
CppAsString(get_pathman_config_params_relid)));
1959+
19441960
return pathman_config_params_relid;
19451961
}

src/pl_funcs.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ show_partition_list_internal(PG_FUNCTION_ARGS)
288288
usercxt = (show_partition_list_cxt *) palloc(sizeof(show_partition_list_cxt));
289289

290290
/* Open PATHMAN_CONFIG with latest snapshot available */
291-
usercxt->pathman_config = heap_open(get_pathman_config_relid(),
291+
usercxt->pathman_config = heap_open(get_pathman_config_relid(false),
292292
AccessShareLock);
293293
usercxt->snapshot = RegisterSnapshot(GetLatestSnapshot());
294294
usercxt->pathman_config_scan = heap_beginscan(usercxt->pathman_config,
@@ -649,7 +649,7 @@ add_to_pathman_config(PG_FUNCTION_ARGS)
649649
isnull[Anum_pathman_config_range_interval - 1] = PG_ARGISNULL(2);
650650

651651
/* Insert new row into PATHMAN_CONFIG */
652-
pathman_config = heap_open(get_pathman_config_relid(), RowExclusiveLock);
652+
pathman_config = heap_open(get_pathman_config_relid(false), RowExclusiveLock);
653653
htup = heap_form_tuple(RelationGetDescr(pathman_config), values, isnull);
654654
simple_heap_insert(pathman_config, htup);
655655
indstate = CatalogOpenIndexes(pathman_config);
@@ -697,11 +697,18 @@ Datum
697697
pathman_config_params_trigger_func(PG_FUNCTION_ARGS)
698698
{
699699
TriggerData *trigdata = (TriggerData *) fcinfo->context;
700-
Oid pathman_config_params = get_pathman_config_params_relid();
700+
Oid pathman_config_params;
701701
Oid partrel;
702702
Datum partrel_datum;
703703
bool partrel_isnull;
704704

705+
/* Fetch Oid of PATHMAN_CONFIG_PARAMS */
706+
pathman_config_params = get_pathman_config_params_relid(true);
707+
708+
/* Handle "pg_pathman.enabled = t" case */
709+
if (!OidIsValid(pathman_config_params))
710+
goto pathman_config_params_trigger_func_return;
711+
705712
/* Handle user calls */
706713
if (!CALLED_AS_TRIGGER(fcinfo))
707714
elog(ERROR, "this function should not be called directly");
@@ -730,6 +737,7 @@ pathman_config_params_trigger_func(PG_FUNCTION_ARGS)
730737
if (check_relation_exists(partrel))
731738
CacheInvalidateRelcacheByRelid(partrel);
732739

740+
pathman_config_params_trigger_func_return:
733741
/* Return the tuple we've been given */
734742
if (trigdata->tg_event & TRIGGER_EVENT_UPDATE)
735743
PG_RETURN_POINTER(trigdata->tg_newtuple);

src/relation_info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ finish_delayed_invalidation(void)
422422

423423
/* Check that PATHMAN_CONFIG table has indeed been dropped */
424424
if (cur_pathman_config_relid == InvalidOid ||
425-
cur_pathman_config_relid != get_pathman_config_relid())
425+
cur_pathman_config_relid != get_pathman_config_relid(true))
426426
{
427427
/* Ok, let's unload pg_pathman's config */
428428
unload_config();

0 commit comments

Comments
 (0)