diff options
author | Robert Haas <rhaas@postgresql.org> | 2015-04-03 22:34:37 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2015-04-03 22:34:37 -0400 |
commit | 368b7c601e3a7ce927602b5399e4b117d71bae31 (patch) | |
tree | e1084f79c960f7537b78e2db7b6f60a3fd1e15fa /src/backend/utils/adt/numeric.c | |
parent | b7e1652d5de8b618c0204588969c8b59d12e9361 (diff) | |
download | postgresql-368b7c601e3a7ce927602b5399e4b117d71bae31.tar.gz postgresql-368b7c601e3a7ce927602b5399e4b117d71bae31.zip |
Fix numeric abbreviation for --disable-float8-byval.
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.
Diffstat (limited to 'src/backend/utils/adt/numeric.c')
-rw-r--r-- | src/backend/utils/adt/numeric.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c index dd108c8b591..3cef3048eb3 100644 --- a/src/backend/utils/adt/numeric.c +++ b/src/backend/utils/adt/numeric.c @@ -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 */ |