Skip to content

Commit 368b7c6

Browse files
committed
Fix numeric abbreviation for --disable-float8-byval.
When committing abd94bc, 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.
1 parent b7e1652 commit 368b7c6

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/backend/utils/adt/numeric.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,21 @@ typedef struct
296296
hyperLogLogState abbr_card; /* cardinality estimator */
297297
} NumericSortSupport;
298298

299+
/*
300+
* We define our own macros for packing and unpacking abbreviated-key
301+
* representations for numeric values in order to avoid depending on
302+
* USE_FLOAT8_BYVAL. The type of abbreviation we use is based only on
303+
* the size of a datum, not the argument-passing convention for float8.
304+
*/
299305
#define NUMERIC_ABBREV_BITS (SIZEOF_DATUM * BITS_PER_BYTE)
300306
#if SIZEOF_DATUM == 8
301-
#define DatumGetNumericAbbrev(d) ((int64) d)
302-
#define NUMERIC_ABBREV_NAN Int64GetDatum(PG_INT64_MIN)
307+
#define NumericAbbrevGetDatum(X) ((Datum) SET_8_BYTES(X))
308+
#define DatumGetNumericAbbrev(X) ((int64) GET_8_BYTES(X))
309+
#define NUMERIC_ABBREV_NAN NumericAbbrevGetDatum(PG_INT64_MIN)
303310
#else
304-
#define DatumGetNumericAbbrev(d) ((int32) d)
305-
#define NUMERIC_ABBREV_NAN Int32GetDatum(PG_INT32_MIN)
311+
#define NumericAbbrevGetDatum(X) ((Datum) SET_4_BYTES(X))
312+
#define DatumGetNumericAbbrev(X) ((int32) GET_4_BYTES(X))
313+
#define NUMERIC_ABBREV_NAN NumericAbbrevGetDatum(PG_INT32_MIN)
306314
#endif
307315

308316

@@ -1883,7 +1891,7 @@ numeric_abbrev_convert_var(NumericVar *var, NumericSortSupport *nss)
18831891
addHyperLogLog(&nss->abbr_card, DatumGetUInt32(hash_uint32(tmp)));
18841892
}
18851893

1886-
return Int64GetDatum(result);
1894+
return NumericAbbrevGetDatum(result);
18871895
}
18881896

18891897
#endif /* NUMERIC_ABBREV_BITS == 64 */
@@ -1960,7 +1968,7 @@ numeric_abbrev_convert_var(NumericVar *var, NumericSortSupport *nss)
19601968
addHyperLogLog(&nss->abbr_card, DatumGetUInt32(hash_uint32(tmp)));
19611969
}
19621970

1963-
return Int32GetDatum(result);
1971+
return NumericAbbrevGetDatum(result);
19641972
}
19651973

19661974
#endif /* NUMERIC_ABBREV_BITS == 32 */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy