diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2017-12-26 13:47:18 -0500 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2018-01-02 12:20:56 -0500 |
commit | 438036264a3b71eaf39b2d2eeca67237ed38ca51 (patch) | |
tree | c4fe35152c6ab32a3b661b8676b291a32f22304d /src/backend/access/gin/ginutil.c | |
parent | 93ea78b17c4743c2b63edb5998fb5796ae57e289 (diff) | |
download | postgresql-438036264a3b71eaf39b2d2eeca67237ed38ca51.tar.gz postgresql-438036264a3b71eaf39b2d2eeca67237ed38ca51.zip |
Don't cast between GinNullCategory and bool
The original idea was that we could use an isNull-style bool array
directly as a GinNullCategory array. However, the existing code already
acknowledges that that doesn't really work, because of the possibility
that bool as currently defined can have arbitrary bit patterns for true
values. So it has to loop through the nullFlags array to set each bool
value to an acceptable value. But if we are looping through the whole
array anyway, we might as well build a proper GinNullCategory array
instead and abandon the type casting. That makes the code much safer in
case bool is ever changed to something else.
Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
Diffstat (limited to 'src/backend/access/gin/ginutil.c')
-rw-r--r-- | src/backend/access/gin/ginutil.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/backend/access/gin/ginutil.c b/src/backend/access/gin/ginutil.c index d9c64834374..41d4b4fb6ff 100644 --- a/src/backend/access/gin/ginutil.c +++ b/src/backend/access/gin/ginutil.c @@ -529,19 +529,10 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum, /* * If the extractValueFn didn't create a nullFlags array, create one, - * assuming that everything's non-null. Otherwise, run through the array - * and make sure each value is exactly 0 or 1; this ensures binary - * compatibility with the GinNullCategory representation. + * assuming that everything's non-null. */ if (nullFlags == NULL) nullFlags = (bool *) palloc0(*nentries * sizeof(bool)); - else - { - for (i = 0; i < *nentries; i++) - nullFlags[i] = (nullFlags[i] ? true : false); - } - /* now we can use the nullFlags as category codes */ - *categories = (GinNullCategory *) nullFlags; /* * If there's more than one key, sort and unique-ify. @@ -600,6 +591,13 @@ ginExtractEntries(GinState *ginstate, OffsetNumber attnum, pfree(keydata); } + /* + * Create GinNullCategory representation from nullFlags. + */ + *categories = (GinNullCategory *) palloc0(*nentries * sizeof(GinNullCategory)); + for (i = 0; i < *nentries; i++) + (*categories)[i] = (nullFlags[i] ? GIN_CAT_NULL_KEY : GIN_CAT_NORM_KEY); + return entries; } |