Fix numeric abbreviation for --disable-float8-byval.
authorRobert Haas <rhaas@postgresql.org>
Sat, 4 Apr 2015 02:34:37 +0000 (22:34 -0400)
committerRobert Haas <rhaas@postgresql.org>
Sat, 4 Apr 2015 02:34:37 +0000 (22:34 -0400)
When committing abd94bcac4582903765be7be959d1dbc121df0d0, I tried to make
it decide what kind of abbreviation to use based only on SIZEOF_DATUM,
without regard to USE_FLOAT8_BYVAL.  That attempt was a few bricks short
of a load, so try to fix it, and add a comment explaining what we're
about.

Patch by me; review (but not a full endorsement) by Andrew Gierth.

src/backend/utils/adt/numeric.c

index dd108c8b5917b327689a6c34a77098e8092a09a7..3cef3048eb3521ab5d8635e67ba853db960f3dfb 100644 (file)
@@ -296,13 +296,21 @@ typedef struct
    hyperLogLogState abbr_card; /* cardinality estimator */
 } NumericSortSupport;
 
+/*
+ * We define our own macros for packing and unpacking abbreviated-key
+ * representations for numeric values in order to avoid depending on
+ * USE_FLOAT8_BYVAL.  The type of abbreviation we use is based only on
+ * the size of a datum, not the argument-passing convention for float8.
+ */
 #define NUMERIC_ABBREV_BITS (SIZEOF_DATUM * BITS_PER_BYTE)
 #if SIZEOF_DATUM == 8
-#define DatumGetNumericAbbrev(d) ((int64) d)
-#define NUMERIC_ABBREV_NAN Int64GetDatum(PG_INT64_MIN)
+#define NumericAbbrevGetDatum(X) ((Datum) SET_8_BYTES(X))
+#define DatumGetNumericAbbrev(X) ((int64) GET_8_BYTES(X))
+#define NUMERIC_ABBREV_NAN      NumericAbbrevGetDatum(PG_INT64_MIN)
 #else
-#define DatumGetNumericAbbrev(d) ((int32) d)
-#define NUMERIC_ABBREV_NAN Int32GetDatum(PG_INT32_MIN)
+#define NumericAbbrevGetDatum(X) ((Datum) SET_4_BYTES(X))
+#define DatumGetNumericAbbrev(X) ((int32) GET_4_BYTES(X))
+#define NUMERIC_ABBREV_NAN      NumericAbbrevGetDatum(PG_INT32_MIN)
 #endif
 
 
@@ -1883,7 +1891,7 @@ numeric_abbrev_convert_var(NumericVar *var, NumericSortSupport *nss)
        addHyperLogLog(&nss->abbr_card, DatumGetUInt32(hash_uint32(tmp)));
    }
 
-   return Int64GetDatum(result);
+   return NumericAbbrevGetDatum(result);
 }
 
 #endif   /* NUMERIC_ABBREV_BITS == 64 */
@@ -1960,7 +1968,7 @@ numeric_abbrev_convert_var(NumericVar *var, NumericSortSupport *nss)
        addHyperLogLog(&nss->abbr_card, DatumGetUInt32(hash_uint32(tmp)));
    }
 
-   return Int32GetDatum(result);
+   return NumericAbbrevGetDatum(result);
 }
 
 #endif   /* NUMERIC_ABBREV_BITS == 32 */