Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitab61e1e

Browse files
committed
make functions get_pathman_config_params_relid() & get_pathman_config_relid() safer
1 parenta512504 commitab61e1e

File tree

6 files changed

+35
-16
lines changed

6 files changed

+35
-16
lines changed

‎src/hooks.c

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

594594
/* Invalidation event for PATHMAN_CONFIG table (probably DROP) */
595-
if (relid==get_pathman_config_relid())
595+
if (relid==get_pathman_config_relid(false))
596596
delay_pathman_shutdown();
597597

598598
/* Invalidate PartParentInfo cache if needed */

‎src/init.c

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

663663
/* Open PATHMAN_CONFIG with latest snapshot available */
664-
rel=heap_open(get_pathman_config_relid(),AccessShareLock);
664+
rel=heap_open(get_pathman_config_relid(false),AccessShareLock);
665665

666666
/* Check that 'partrel' column is if regclass type */
667667
Assert(RelationGetDescr(rel)->
@@ -735,7 +735,7 @@ read_pathman_params(Oid relid, Datum *values, bool *isnull)
735735
BTEqualStrategyNumber,F_OIDEQ,
736736
ObjectIdGetDatum(relid));
737737

738-
rel=heap_open(get_pathman_config_params_relid(),AccessShareLock);
738+
rel=heap_open(get_pathman_config_params_relid(false),AccessShareLock);
739739
snapshot=RegisterSnapshot(GetLatestSnapshot());
740740
scan=heap_beginscan(rel,snapshot,1,key);
741741

@@ -774,7 +774,7 @@ read_pathman_config(void)
774774
HeapTuplehtup;
775775

776776
/* Open PATHMAN_CONFIG with latest snapshot available */
777-
rel=heap_open(get_pathman_config_relid(),AccessShareLock);
777+
rel=heap_open(get_pathman_config_relid(false),AccessShareLock);
778778

779779
/* Check that 'partrel' column is if regclass type */
780780
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 Oidpathman_config_params_relid;
8585
/*
8686
* Just to clarify our intentions (return the corresponding relid).
8787
*/
88-
Oidget_pathman_config_relid(void);
89-
Oidget_pathman_config_params_relid(void);
88+
Oidget_pathman_config_relid(boolinvalid_is_ok);
89+
Oidget_pathman_config_params_relid(boolinvalid_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
@@ -1884,16 +1884,32 @@ generate_mergeappend_paths(PlannerInfo *root, RelOptInfo *rel,
18841884
* Get cached PATHMAN_CONFIG relation Oid.
18851885
*/
18861886
Oid
1887-
get_pathman_config_relid(void)
1887+
get_pathman_config_relid(boolinvalid_is_ok)
18881888
{
1889+
/* Raise ERROR if Oid is invalid */
1890+
if (!OidIsValid(pathman_config_relid)&& !invalid_is_ok)
1891+
elog(ERROR,
1892+
(!IsPathmanInitialized() ?
1893+
"pg_pathman is not initialized yet" :
1894+
"unexpected error in function "
1895+
CppAsString(get_pathman_config_relid)));
1896+
18891897
returnpathman_config_relid;
18901898
}
18911899

18921900
/*
18931901
* Get cached PATHMAN_CONFIG_PARAMS relation Oid.
18941902
*/
18951903
Oid
1896-
get_pathman_config_params_relid(void)
1904+
get_pathman_config_params_relid(boolinvalid_is_ok)
18971905
{
1906+
/* Raise ERROR if Oid is invalid */
1907+
if (!OidIsValid(pathman_config_relid)&& !invalid_is_ok)
1908+
elog(ERROR,
1909+
(!IsPathmanInitialized() ?
1910+
"pg_pathman is not initialized yet" :
1911+
"unexpected error in function "
1912+
CppAsString(get_pathman_config_params_relid)));
1913+
18981914
returnpathman_config_params_relid;
18991915
}

‎src/pl_funcs.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ show_partition_list_internal(PG_FUNCTION_ARGS)
285285
usercxt= (show_partition_list_cxt*)palloc(sizeof(show_partition_list_cxt));
286286

287287
/* Open PATHMAN_CONFIG with latest snapshot available */
288-
usercxt->pathman_config=heap_open(get_pathman_config_relid(),
288+
usercxt->pathman_config=heap_open(get_pathman_config_relid(false),
289289
AccessShareLock);
290290
usercxt->snapshot=RegisterSnapshot(GetLatestSnapshot());
291291
usercxt->pathman_config_scan=heap_beginscan(usercxt->pathman_config,
@@ -637,7 +637,7 @@ add_to_pathman_config(PG_FUNCTION_ARGS)
637637
isnull[Anum_pathman_config_range_interval-1]=PG_ARGISNULL(2);
638638

639639
/* Insert new row into PATHMAN_CONFIG */
640-
pathman_config=heap_open(get_pathman_config_relid(),RowExclusiveLock);
640+
pathman_config=heap_open(get_pathman_config_relid(false),RowExclusiveLock);
641641
htup=heap_form_tuple(RelationGetDescr(pathman_config),values,isnull);
642642
simple_heap_insert(pathman_config,htup);
643643
indstate=CatalogOpenIndexes(pathman_config);
@@ -685,14 +685,17 @@ Datum
685685
pathman_config_params_trigger_func(PG_FUNCTION_ARGS)
686686
{
687687
TriggerData*trigdata= (TriggerData*)fcinfo->context;
688-
Oidpathman_config_params=get_pathman_config_params_relid();
688+
Oidpathman_config_params;
689689
Oidpartrel;
690690
Datumpartrel_datum;
691691
boolpartrel_isnull;
692692

693-
/* Handle pg_pathman disabled case */
694-
if (!OidIsValid(pathman_config_params))
695-
goto_return;
693+
/* Fetch Oid of PATHMAN_CONFIG_PARAMS */
694+
pathman_config_params=get_pathman_config_params_relid(true);
695+
696+
/* Handle "pg_pathman.enabled = t" case */
697+
if (!OidIsValid(pathman_config_params))
698+
gotopathman_config_params_trigger_func_return;
696699

697700
/* Handle user calls */
698701
if (!CALLED_AS_TRIGGER(fcinfo))
@@ -722,8 +725,8 @@ pathman_config_params_trigger_func(PG_FUNCTION_ARGS)
722725
if (check_relation_exists(partrel))
723726
CacheInvalidateRelcacheByRelid(partrel);
724727

728+
pathman_config_params_trigger_func_return:
725729
/* Return the tuple we've been given */
726-
_return:
727730
if (trigdata->tg_event&TRIGGER_EVENT_UPDATE)
728731
PG_RETURN_POINTER(trigdata->tg_newtuple);
729732
else

‎src/relation_info.c

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

416416
/* Check that PATHMAN_CONFIG table has indeed been dropped */
417417
if (cur_pathman_config_relid==InvalidOid||
418-
cur_pathman_config_relid!=get_pathman_config_relid())
418+
cur_pathman_config_relid!=get_pathman_config_relid(true))
419419
{
420420
/* Ok, let's unload pg_pathman's config */
421421
unload_config();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp