make_numericdata_private.patch
application/octet-stream
Filename: make_numericdata_private.patch
Type: application/octet-stream
Part: 0
Message:
Re: reducing NUMERIC size for 9.1
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| contrib/btree_gist/btree_numeric.c | 2 | 2 |
| src/backend/utils/adt/numeric.c | 42 | 0 |
| src/include/utils/numeric.h | 3 | 33 |
diff --git a/contrib/btree_gist/btree_numeric.c b/contrib/btree_gist/btree_numeric.c
index 373d12e..f8c0f60 100644
--- a/contrib/btree_gist/btree_numeric.c
+++ b/contrib/btree_gist/btree_numeric.c
@@ -185,9 +185,9 @@ gbt_numeric_penalty(PG_FUNCTION_ARGS)
NumericGetDatum(os)
));
- if (NUMERIC_IS_NAN(us))
+ if (numeric_is_nan(us))
{
- if (NUMERIC_IS_NAN(os))
+ if (numeric_is_nan(os))
*result = 0.0;
else
*result = 1.0;
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index 5766a8b..6f18639 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -35,6 +35,37 @@
#include "utils/int8.h"
#include "utils/numeric.h"
+/*
+ * Sign values and macros to deal with packing/unpacking n_sign_dscale
+ */
+#define NUMERIC_SIGN_MASK 0xC000
+#define NUMERIC_POS 0x0000
+#define NUMERIC_NEG 0x4000
+#define NUMERIC_NAN 0xC000
+#define NUMERIC_DSCALE_MASK 0x3FFF
+#define NUMERIC_SIGN(n) ((n)->n_sign_dscale & NUMERIC_SIGN_MASK)
+#define NUMERIC_DSCALE(n) ((n)->n_sign_dscale & NUMERIC_DSCALE_MASK)
+#define NUMERIC_IS_NAN(n) (NUMERIC_SIGN(n) != NUMERIC_POS && \
+ NUMERIC_SIGN(n) != NUMERIC_NEG)
+
+
+/*
+ * The Numeric data type stored in the database
+ *
+ * NOTE: by convention, values in the packed form have been stripped of
+ * all leading and trailing zero digits (where a "digit" is of base NBASE).
+ * In particular, if the value is zero, there will be no digits at all!
+ * The weight is arbitrary in that case, but we normally set it to zero.
+ */
+struct NumericData
+{
+ int32 vl_len_; /* varlena header (do not touch directly!) */
+ uint16 n_sign_dscale; /* Sign + display scale */
+ int16 n_weight; /* Weight of 1st digit */
+ char n_data[1]; /* Digits (really array of NumericDigit) */
+};
+
+
/* ----------
* Uncomment the following to enable compilation of dump_numeric()
* and dump_var() and to get a dump of any result produced by make_result().
@@ -428,6 +459,17 @@ numeric_out(PG_FUNCTION_ARGS)
}
/*
+ * numeric_is_nan() -
+ *
+ * Is Numeric value a NaN?
+ */
+bool
+numeric_is_nan(Numeric num)
+{
+ return NUMERIC_IS_NAN(num);
+}
+
+/*
* numeric_out_sci() -
*
* Output function for numeric data type in scientific notation.
diff --git a/src/include/utils/numeric.h b/src/include/utils/numeric.h
index 73c1ee1..0145f0c 100644
--- a/src/include/utils/numeric.h
+++ b/src/include/utils/numeric.h
@@ -37,41 +37,10 @@
*/
#define NUMERIC_MIN_SIG_DIGITS 16
-
-/*
- * Sign values and macros to deal with packing/unpacking n_sign_dscale
- */
-#define NUMERIC_SIGN_MASK 0xC000
-#define NUMERIC_POS 0x0000
-#define NUMERIC_NEG 0x4000
-#define NUMERIC_NAN 0xC000
-#define NUMERIC_DSCALE_MASK 0x3FFF
-#define NUMERIC_SIGN(n) ((n)->n_sign_dscale & NUMERIC_SIGN_MASK)
-#define NUMERIC_DSCALE(n) ((n)->n_sign_dscale & NUMERIC_DSCALE_MASK)
-#define NUMERIC_IS_NAN(n) (NUMERIC_SIGN(n) != NUMERIC_POS && \
- NUMERIC_SIGN(n) != NUMERIC_NEG)
-
-
-/*
- * The Numeric data type stored in the database
- *
- * NOTE: by convention, values in the packed form have been stripped of
- * all leading and trailing zero digits (where a "digit" is of base NBASE).
- * In particular, if the value is zero, there will be no digits at all!
- * The weight is arbitrary in that case, but we normally set it to zero.
- */
-typedef struct NumericData
-{
- int32 vl_len_; /* varlena header (do not touch directly!) */
- uint16 n_sign_dscale; /* Sign + display scale */
- int16 n_weight; /* Weight of 1st digit */
- char n_data[1]; /* Digits (really array of NumericDigit) */
-} NumericData;
-
-typedef NumericData *Numeric;
-
#define NUMERIC_HDRSZ (VARHDRSZ + sizeof(uint16) + sizeof(int16))
+struct NumericData;
+typedef struct NumericData *Numeric;
/*
* fmgr interface macros
@@ -87,6 +56,7 @@ typedef NumericData *Numeric;
/*
* Utility functions in numeric.c
*/
+extern bool numeric_is_nan(Numeric num);
extern char *numeric_out_sci(Numeric num, int scale);
#endif /* _PG_NUMERIC_H_ */