|
17 | 17 |
|
18 | 18 | #include "access/htup_details.h"
|
19 | 19 | #include "access/nbtree.h"
|
| 20 | +#include "access/xact.h" |
20 | 21 | #include "catalog/indexing.h"
|
21 | 22 | #include "catalog/pg_type.h"
|
22 | 23 | #include "commands/tablespace.h"
|
| 24 | +#include "commands/trigger.h" |
23 | 25 | #include "funcapi.h"
|
24 | 26 | #include "miscadmin.h"
|
25 | 27 | #include "utils/builtins.h"
|
@@ -54,7 +56,7 @@ PG_FUNCTION_INFO_V1( is_date_type );
|
54 | 56 | PG_FUNCTION_INFO_V1( is_attribute_nullable );
|
55 | 57 |
|
56 | 58 | 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 ); |
58 | 60 |
|
59 | 61 | PG_FUNCTION_INFO_V1( lock_partitioned_relation );
|
60 | 62 | PG_FUNCTION_INFO_V1( prevent_relation_modification );
|
@@ -676,17 +678,51 @@ add_to_pathman_config(PG_FUNCTION_ARGS)
|
676 | 678 |
|
677 | 679 |
|
678 | 680 | /*
|
679 |
| - * Invalidate relcache for a specified relation. |
| 681 | + * Invalidate relcache to refresh PartRelationInfo. |
680 | 682 | */
|
681 | 683 | Datum
|
682 |
| -invalidate_relcache(PG_FUNCTION_ARGS) |
| 684 | +pathman_config_params_trigger_func(PG_FUNCTION_ARGS) |
683 | 685 | {
|
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); |
688 | 725 |
|
689 |
| - PG_RETURN_VOID(); |
690 | 726 | }
|
691 | 727 |
|
692 | 728 |
|
|
0 commit comments