bool *partial_matches = NULL;
Pointer *extra_data = NULL;
bool *nullFlags = NULL;
+ GinNullCategory *categories;
int32 searchMode = GIN_SEARCH_MODE_DEFAULT;
/*
}
/*
- * If the extractQueryFn 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. While
- * at it, detect whether any null keys are present.
+ * Create GinNullCategory representation. If the extractQueryFn
+ * didn't create a nullFlags array, we assume everything is non-null.
+ * While at it, detect whether any null keys are present.
*/
- if (nullFlags == NULL)
- nullFlags = (bool *) palloc0(nQueryValues * sizeof(bool));
- else
+ categories = (GinNullCategory *) palloc0(nQueryValues * sizeof(GinNullCategory));
+ if (nullFlags)
{
int32 j;
{
if (nullFlags[j])
{
- nullFlags[j] = true; /* not any other nonzero value */
+ categories[j] = GIN_CAT_NULL_KEY;
hasNullQuery = true;
}
}
}
- /* now we can use the nullFlags as category codes */
ginFillScanKey(so, skey->sk_attno,
skey->sk_strategy, searchMode,
skey->sk_argument, nQueryValues,
- queryValues, (GinNullCategory *) nullFlags,
+ queryValues, categories,
partial_matches, extra_data);
}
/*
* 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.
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;
}
/*
* Category codes to distinguish placeholder nulls from ordinary NULL keys.
- * Note that the datatype size and the first two code values are chosen to be
- * compatible with the usual usage of bool isNull flags.
+ *
+ * The first two code values were chosen to be compatible with the usual usage
+ * of bool isNull flags. However, casting between bool and GinNullCategory is
+ * risky because of the possibility of different bit patterns and type sizes,
+ * so it is no longer done.
*
* GIN_CAT_EMPTY_QUERY is never stored in the index; and notice that it is
* chosen to sort before not after regular key values.