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

Commitba29122

Browse files
committed
reimplement pathman_config_params_trigger_func() in C language, fix bug in pathman_relcache_hook()
1 parent0de6b22 commitba29122

File tree

3 files changed

+51
-34
lines changed

3 files changed

+51
-34
lines changed

‎init.sql

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,8 @@ ALTER TABLE @extschema@.pathman_config_params ENABLE ROW LEVEL SECURITY;
8888
* Invalidate relcache every time someone changes parameters config.
8989
*/
9090
CREATEOR REPLACE FUNCTION @extschema@.pathman_config_params_trigger_func()
91-
RETURNS TRIGGERAS
92-
$$
93-
BEGIN
94-
IF TG_OPIN ('INSERT','UPDATE') THEN
95-
PERFORM @extschema@.invalidate_relcache(NEW.partrel);
96-
END IF;
97-
98-
IF TG_OPIN ('UPDATE','DELETE') THEN
99-
PERFORM @extschema@.invalidate_relcache(OLD.partrel);
100-
END IF;
101-
102-
IF TG_OP='DELETE' THEN
103-
RETURN OLD;
104-
ELSE
105-
RETURN NEW;
106-
END IF;
107-
END
108-
$$
109-
LANGUAGE plpgsql;
91+
RETURNS TRIGGERAS'pg_pathman','pathman_config_params_trigger_func'
92+
LANGUAGE C;
11093

11194
CREATETRIGGERpathman_config_params_trigger
11295
BEFORE INSERTORUPDATEORDELETEON @extschema@.pathman_config_params
@@ -750,11 +733,6 @@ CREATE OR REPLACE FUNCTION @extschema@.add_to_pathman_config(
750733
RETURNSBOOLEANAS'pg_pathman','add_to_pathman_config'
751734
LANGUAGE C;
752735

753-
CREATEOR REPLACE FUNCTION @extschema@.invalidate_relcache(
754-
OID)
755-
RETURNS VOIDAS'pg_pathman'
756-
LANGUAGE C STRICT;
757-
758736

759737
/*
760738
* Lock partitioned relation to restrict concurrent

‎src/hooks.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,11 @@ pathman_relcache_hook(Datum arg, Oid relid)
614614
/* Both syscache and pathman's cache say it isn't a partition */
615615
casePPS_ENTRY_NOT_FOUND:
616616
{
617-
if (partitioned_table!=InvalidOid)
618-
delay_invalidation_parent_rel(partitioned_table);
617+
Assert(partitioned_table==InvalidOid);
618+
619+
/* Which means that 'relid' might be parent */
620+
if (relid!=InvalidOid)
621+
delay_invalidation_parent_rel(relid);
619622
#ifdefNOT_USED
620623
elog(DEBUG2,"Invalidation message for relation %u [%u]",
621624
relid,MyProcPid);

‎src/pl_funcs.c

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
#include"access/htup_details.h"
1919
#include"access/nbtree.h"
20+
#include"access/xact.h"
2021
#include"catalog/indexing.h"
2122
#include"catalog/pg_type.h"
2223
#include"commands/tablespace.h"
24+
#include"commands/trigger.h"
2325
#include"funcapi.h"
2426
#include"miscadmin.h"
2527
#include"utils/builtins.h"
@@ -54,7 +56,7 @@ PG_FUNCTION_INFO_V1( is_date_type );
5456
PG_FUNCTION_INFO_V1(is_attribute_nullable );
5557

5658
PG_FUNCTION_INFO_V1(add_to_pathman_config );
57-
PG_FUNCTION_INFO_V1(invalidate_relcache );
59+
PG_FUNCTION_INFO_V1(pathman_config_params_trigger_func );
5860

5961
PG_FUNCTION_INFO_V1(lock_partitioned_relation );
6062
PG_FUNCTION_INFO_V1(prevent_relation_modification );
@@ -676,17 +678,51 @@ add_to_pathman_config(PG_FUNCTION_ARGS)
676678

677679

678680
/*
679-
* Invalidate relcachefor a specified relation.
681+
* Invalidate relcacheto refresh PartRelationInfo.
680682
*/
681683
Datum
682-
invalidate_relcache(PG_FUNCTION_ARGS)
684+
pathman_config_params_trigger_func(PG_FUNCTION_ARGS)
683685
{
684-
Oidrelid=PG_GETARG_OID(0);
685-
686-
if (check_relation_exists(relid))
687-
CacheInvalidateRelcacheByRelid(relid);
686+
TriggerData*trigdata= (TriggerData*)fcinfo->context;
687+
Oidpathman_config_params=get_pathman_config_params_relid();
688+
Oidpartrel;
689+
Datumpartrel_datum;
690+
boolpartrel_isnull;
691+
692+
/* Handle user calls */
693+
if (!CALLED_AS_TRIGGER(fcinfo))
694+
elog(ERROR,"this function should not be called directly");
695+
696+
/* Handle wrong fire mode */
697+
if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
698+
elog(ERROR,"%s: must be fired for row",
699+
trigdata->tg_trigger->tgname);
700+
701+
/* Handle wrong relation */
702+
if (RelationGetRelid(trigdata->tg_relation)!=pathman_config_params)
703+
elog(ERROR,"%s: must be fired for relation \"%s\"",
704+
trigdata->tg_trigger->tgname,
705+
get_rel_name(pathman_config_params));
706+
707+
/* Extract partitioned relation's Oid */
708+
partrel_datum=heap_getattr(trigdata->tg_trigtuple,
709+
Anum_pathman_config_params_partrel,
710+
RelationGetDescr(trigdata->tg_relation),
711+
&partrel_isnull);
712+
Assert(partrel_isnull== false);/* partrel should not be NULL! */
713+
714+
partrel=DatumGetObjectId(partrel_datum);
715+
716+
/* Finally trigger pg_pathman's cache invalidation event */
717+
if (check_relation_exists(partrel))
718+
CacheInvalidateRelcacheByRelid(partrel);
719+
720+
/* Return the tuple we've been given */
721+
if (trigdata->tg_event&TRIGGER_EVENT_UPDATE)
722+
PG_RETURN_POINTER(trigdata->tg_newtuple);
723+
else
724+
PG_RETURN_POINTER(trigdata->tg_trigtuple);
688725

689-
PG_RETURN_VOID();
690726
}
691727

692728

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp