Skip to content

Commit 9d3fcff

Browse files
committed
Merge branch 'rel_1_2_beta' of github.com:postgrespro/pg_pathman into rel_1_2_beta
2 parents 4e86365 + c453ce4 commit 9d3fcff

File tree

4 files changed

+67
-34
lines changed

4 files changed

+67
-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
CREATE OR REPLACE FUNCTION @extschema@.pathman_config_params_trigger_func()
91-
RETURNS TRIGGER AS
92-
$$
93-
BEGIN
94-
IF TG_OP IN ('INSERT', 'UPDATE') THEN
95-
PERFORM @extschema@.invalidate_relcache(NEW.partrel);
96-
END IF;
97-
98-
IF TG_OP IN ('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 TRIGGER AS 'pg_pathman', 'pathman_config_params_trigger_func'
92+
LANGUAGE C;
11093

11194
CREATE TRIGGER pathman_config_params_trigger
11295
BEFORE INSERT OR UPDATE OR DELETE ON @extschema@.pathman_config_params
@@ -750,11 +733,6 @@ CREATE OR REPLACE FUNCTION @extschema@.add_to_pathman_config(
750733
RETURNS BOOLEAN AS 'pg_pathman', 'add_to_pathman_config'
751734
LANGUAGE C;
752735

753-
CREATE OR REPLACE FUNCTION @extschema@.invalidate_relcache(
754-
relid OID)
755-
RETURNS VOID AS 'pg_pathman'
756-
LANGUAGE C STRICT;
757-
758736

759737
/*
760738
* Lock partitioned relation to restrict concurrent

pg_pathman--1.1--1.2.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ DROP FUNCTION @extschema@.get_sequence_name(TEXT, TEXT);
2323
DROP FUNCTION @extschema@.create_single_range_partition(REGCLASS, ANYELEMENT, ANYELEMENT, TEXT, TEXT);
2424
DROP FUNCTION @extschema@.check_overlap(REGCLASS, ANYELEMENT, ANYELEMENT);
2525
DROP FUNCTION @extschema@.split_range_partition(REGCLASS, ANYELEMENT, TEXT, OUT ANYARRAY);
26+
DROP FUNCTION @extschema@.invalidate_relcache(OID);
27+
28+
/* drop trigger and its function (PATHMAN_CONFIG_PARAMS) */
29+
DROP TRIGGER pathman_config_params_trigger;
30+
DROP FUNCTION @extschema@.pathman_config_params_trigger_func();
31+
2632

2733
/* ------------------------------------------------------------------------
2834
* Alter functions' modifiers
@@ -1265,6 +1271,16 @@ RETURNS VOID AS 'pg_pathman', 'check_range_available_pl'
12651271
LANGUAGE C;
12661272

12671273

1274+
/* Finally create function and trigger (PATHMAN_CONFIG_PARAMS) */
1275+
CREATE OR REPLACE FUNCTION @extschema@.pathman_config_params_trigger_func()
1276+
RETURNS TRIGGER AS 'pg_pathman', 'pathman_config_params_trigger_func'
1277+
LANGUAGE C;
1278+
1279+
CREATE TRIGGER pathman_config_params_trigger
1280+
BEFORE INSERT OR UPDATE OR DELETE ON @extschema@.pathman_config_params
1281+
FOR EACH ROW EXECUTE PROCEDURE @extschema@.pathman_config_params_trigger_func();
1282+
1283+
12681284
/* ------------------------------------------------------------------------
12691285
* Alter tables
12701286
* ----------------------------------------------------------------------*/

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
case PPS_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
#ifdef NOT_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 relcache for a specified relation.
681+
* Invalidate relcache to refresh PartRelationInfo.
680682
*/
681683
Datum
682-
invalidate_relcache(PG_FUNCTION_ARGS)
684+
pathman_config_params_trigger_func(PG_FUNCTION_ARGS)
683685
{
684-
Oid relid = PG_GETARG_OID(0);
685-
686-
if (check_relation_exists(relid))
687-
CacheInvalidateRelcacheByRelid(relid);
686+
TriggerData *trigdata = (TriggerData *) fcinfo->context;
687+
Oid pathman_config_params = get_pathman_config_params_relid();
688+
Oid partrel;
689+
Datum partrel_datum;
690+
bool partrel_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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy