summaryrefslogtreecommitdiff
path: root/src/backend/utils/cache/evtcache.c
diff options
context:
space:
mode:
authorAlvaro Herrera2020-03-02 21:19:51 +0000
committerAlvaro Herrera2020-03-02 21:19:51 +0000
commit2f9661311b83dc481fc19f6e3bda015392010a40 (patch)
tree9a1aabe1d15ac894f7badbc886ae33f16bbfc3b6 /src/backend/utils/cache/evtcache.c
parent7b425a5283cb2c8a452c2e79d6218e41373fd641 (diff)
Represent command completion tags as structs
The backend was using strings to represent command tags and doing string comparisons in multiple places, but that's slow and unhelpful. Create a new command list with a supporting structure to use instead; this is stored in a tag-list-file that can be tailored to specific purposes with a caller-definable C macro, similar to what we do for WAL resource managers. The first first such uses are a new CommandTag enum and a CommandTagBehavior struct. Replace numerous occurrences of char *completionTag with a QueryCompletion struct so that the code no longer stores information about completed queries in a cstring. Only at the last moment, in EndCommand(), does this get converted to a string. EventTriggerCacheItem no longer holds an array of palloc’d tag strings in sorted order, but rather just a Bitmapset over the CommandTags. Author: Mark Dilger, with unsolicited help from Álvaro Herrera Reviewed-by: John Naylor, Tom Lane Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'src/backend/utils/cache/evtcache.c')
-rw-r--r--src/backend/utils/cache/evtcache.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/backend/utils/cache/evtcache.c b/src/backend/utils/cache/evtcache.c
index 1b63048a774..b9c1a0a5adb 100644
--- a/src/backend/utils/cache/evtcache.c
+++ b/src/backend/utils/cache/evtcache.c
@@ -20,6 +20,7 @@
#include "catalog/pg_event_trigger.h"
#include "catalog/pg_type.h"
#include "commands/trigger.h"
+#include "tcop/cmdtag.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/catcache.h"
@@ -51,7 +52,7 @@ static EventTriggerCacheStateType EventTriggerCacheState = ETCS_NEEDS_REBUILD;
static void BuildEventTriggerCache(void);
static void InvalidateEventCacheCallback(Datum arg,
int cacheid, uint32 hashvalue);
-static int DecodeTextArrayToCString(Datum array, char ***cstringp);
+static Bitmapset *DecodeTextArrayToBitmapset(Datum array);
/*
* Search the event cache by trigger event.
@@ -180,10 +181,7 @@ BuildEventTriggerCache(void)
evttags = heap_getattr(tup, Anum_pg_event_trigger_evttags,
RelationGetDescr(rel), &evttags_isnull);
if (!evttags_isnull)
- {
- item->ntags = DecodeTextArrayToCString(evttags, &item->tag);
- qsort(item->tag, item->ntags, sizeof(char *), pg_qsort_strcmp);
- }
+ item->tagset = DecodeTextArrayToBitmapset(evttags);
/* Add to cache entry. */
entry = hash_search(cache, &event, HASH_ENTER, &found);
@@ -215,18 +213,18 @@ BuildEventTriggerCache(void)
}
/*
- * Decode text[] to an array of C strings.
+ * Decode text[] to a Bitmapset of CommandTags.
*
* We could avoid a bit of overhead here if we were willing to duplicate some
* of the logic from deconstruct_array, but it doesn't seem worth the code
* complexity.
*/
-static int
-DecodeTextArrayToCString(Datum array, char ***cstringp)
+static Bitmapset *
+DecodeTextArrayToBitmapset(Datum array)
{
ArrayType *arr = DatumGetArrayTypeP(array);
Datum *elems;
- char **cstring;
+ Bitmapset *bms;
int i;
int nelems;
@@ -234,13 +232,17 @@ DecodeTextArrayToCString(Datum array, char ***cstringp)
elog(ERROR, "expected 1-D text array");
deconstruct_array(arr, TEXTOID, -1, false, 'i', &elems, NULL, &nelems);
- cstring = palloc(nelems * sizeof(char *));
- for (i = 0; i < nelems; ++i)
- cstring[i] = TextDatumGetCString(elems[i]);
+ for (bms = NULL, i = 0; i < nelems; ++i)
+ {
+ char *str = TextDatumGetCString(elems[i]);
+
+ bms = bms_add_member(bms, GetCommandTagEnum(str));
+ pfree(str);
+ }
pfree(elems);
- *cstringp = cstring;
- return nelems;
+
+ return bms;
}
/*