Remove configure --disable-float4-byval and --disable-float8-byval
AFAICT, these build options were only useful to maintain compatibility
for version-0 functions, but those are no longer supported, so these
options can be removed. There is a fair amount of code all over the
place to support these options, so the cleanup is quite significant.
The current behavior became the default in PG9.3. Note that this does
not affect on-disk storage. The only upgrade issue that I can see is
that pg_upgrade refuses to upgrade incompatible clusters if you have
contrib/isn installed. But hopefully everyone who is affected by that
will have upgraded at least once since PG9.2 already.
float4 is now always pass-by-value; the pass-by-reference code path is
completely removed.
float8 and related types are now hardcoded to pass-by-value or
pass-by-reference depending on whether the build is 64- or 32-bit, as
was previously also the default.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
0001-Remove-configure-disable-float4-byval-and-disable-fl.patchtext/plain; charset=UTF-8; name=0001-Remove-configure-disable-float4-byval-and-disable-fl.patch; x-mac-creator=0; x-mac-type=0Download
From e009755a160d3d67900c80c9bc17276e27f79baa Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Thu, 31 Oct 2019 09:21:38 +0100
Subject: [PATCH 1/3] Remove configure --disable-float4-byval and
--disable-float8-byval
These build options were only useful to maintain compatibility for version-0
functions, but those are no longer supported, so these options can be
removed.
float4 is now always pass-by-value; the pass-by-reference
code path is completely removed.
float8 and related types are now hardcoded to pass-by-value or
pass-by-reference depending on whether the build is 64- or 32-bit, as
was previously also the default.
---
configure | 118 ------------------------
configure.in | 33 -------
doc/src/sgml/func.sgml | 10 --
doc/src/sgml/installation.sgml | 28 ------
src/backend/access/index/indexam.c | 5 -
src/backend/access/transam/xlog.c | 35 -------
src/backend/bootstrap/bootstrap.c | 2 +-
src/backend/catalog/genbki.pl | 2 +-
src/backend/commands/analyze.c | 2 +-
src/backend/utils/adt/numeric.c | 5 +-
src/backend/utils/fmgr/dfmgr.c | 18 ----
src/backend/utils/fmgr/fmgr.c | 23 +----
src/backend/utils/misc/pg_controldata.c | 18 +---
src/bin/initdb/initdb.c | 3 -
src/bin/pg_controldata/pg_controldata.c | 4 -
src/bin/pg_resetwal/pg_resetwal.c | 6 --
src/bin/pg_upgrade/controldata.c | 7 ++
src/include/c.h | 15 +++
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_control.h | 6 +-
src/include/catalog/pg_proc.dat | 6 +-
src/include/catalog/pg_type.dat | 2 +-
src/include/fmgr.h | 4 -
src/include/pg_config.h.in | 15 ---
src/include/postgres.h | 23 +----
src/tools/msvc/Solution.pm | 25 -----
src/tools/msvc/config_default.pl | 5 -
27 files changed, 40 insertions(+), 382 deletions(-)
diff --git a/configure b/configure
index 6b1c779ee3..b38ad1526d 100755
--- a/configure
+++ b/configure
@@ -866,8 +866,6 @@ with_system_tzdata
with_zlib
with_gnu_ld
enable_largefile
-enable_float4_byval
-enable_float8_byval
'
ac_precious_vars='build_alias
host_alias
@@ -1525,8 +1523,6 @@ Optional Features:
--enable-cassert enable assertion checks (for debugging)
--disable-thread-safety disable thread-safety in client libraries
--disable-largefile omit support for large files
- --disable-float4-byval disable float4 passed by value
- --disable-float8-byval disable float8 passed by value
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
@@ -16801,120 +16797,6 @@ _ACEOF
-# Decide whether float4 is passed by value: user-selectable, enabled by default
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build with float4 passed by value" >&5
-$as_echo_n "checking whether to build with float4 passed by value... " >&6; }
-
-
-# Check whether --enable-float4-byval was given.
-if test "${enable_float4_byval+set}" = set; then :
- enableval=$enable_float4_byval;
- case $enableval in
- yes)
-
-$as_echo "#define USE_FLOAT4_BYVAL 1" >>confdefs.h
-
- float4passbyval=true
- ;;
- no)
- float4passbyval=false
- ;;
- *)
- as_fn_error $? "no argument expected for --enable-float4-byval option" "$LINENO" 5
- ;;
- esac
-
-else
- enable_float4_byval=yes
-
-$as_echo "#define USE_FLOAT4_BYVAL 1" >>confdefs.h
-
- float4passbyval=true
-fi
-
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_float4_byval" >&5
-$as_echo "$enable_float4_byval" >&6; }
-
-cat >>confdefs.h <<_ACEOF
-#define FLOAT4PASSBYVAL $float4passbyval
-_ACEOF
-
-
-# Decide whether float8 is passed by value.
-# Note: this setting also controls int8 and related types such as timestamp.
-# If sizeof(Datum) >= 8, this is user-selectable, enabled by default.
-# If not, trying to select it is an error.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build with float8 passed by value" >&5
-$as_echo_n "checking whether to build with float8 passed by value... " >&6; }
-if test $ac_cv_sizeof_void_p -ge 8 ; then
-
-
-# Check whether --enable-float8-byval was given.
-if test "${enable_float8_byval+set}" = set; then :
- enableval=$enable_float8_byval;
- case $enableval in
- yes)
- :
- ;;
- no)
- :
- ;;
- *)
- as_fn_error $? "no argument expected for --enable-float8-byval option" "$LINENO" 5
- ;;
- esac
-
-else
- enable_float8_byval=yes
-
-fi
-
-
-else
-
-
-# Check whether --enable-float8-byval was given.
-if test "${enable_float8_byval+set}" = set; then :
- enableval=$enable_float8_byval;
- case $enableval in
- yes)
- :
- ;;
- no)
- :
- ;;
- *)
- as_fn_error $? "no argument expected for --enable-float8-byval option" "$LINENO" 5
- ;;
- esac
-
-else
- enable_float8_byval=no
-
-fi
-
-
- if test "$enable_float8_byval" = yes ; then
- as_fn_error $? "--enable-float8-byval is not supported on 32-bit platforms." "$LINENO" 5
- fi
-fi
-if test "$enable_float8_byval" = yes ; then
-
-$as_echo "#define USE_FLOAT8_BYVAL 1" >>confdefs.h
-
- float8passbyval=true
-else
- float8passbyval=false
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_float8_byval" >&5
-$as_echo "$enable_float8_byval" >&6; }
-
-cat >>confdefs.h <<_ACEOF
-#define FLOAT8PASSBYVAL $float8passbyval
-_ACEOF
-
-
# Determine memory alignment requirements for the basic C data types.
# The cast to long int works around a bug in the HP C Compiler,
diff --git a/configure.in b/configure.in
index 2b9025cac3..73d55ae48d 100644
--- a/configure.in
+++ b/configure.in
@@ -1931,39 +1931,6 @@ AC_CHECK_SIZEOF([void *])
AC_CHECK_SIZEOF([size_t])
AC_CHECK_SIZEOF([long])
-# Decide whether float4 is passed by value: user-selectable, enabled by default
-AC_MSG_CHECKING([whether to build with float4 passed by value])
-PGAC_ARG_BOOL(enable, float4-byval, yes, [disable float4 passed by value],
- [AC_DEFINE([USE_FLOAT4_BYVAL], 1,
- [Define to 1 if you want float4 values to be passed by value. (--enable-float4-byval)])
- float4passbyval=true],
- [float4passbyval=false])
-AC_MSG_RESULT([$enable_float4_byval])
-AC_DEFINE_UNQUOTED([FLOAT4PASSBYVAL], [$float4passbyval], [float4 values are passed by value if 'true', by reference if 'false'])
-
-# Decide whether float8 is passed by value.
-# Note: this setting also controls int8 and related types such as timestamp.
-# If sizeof(Datum) >= 8, this is user-selectable, enabled by default.
-# If not, trying to select it is an error.
-AC_MSG_CHECKING([whether to build with float8 passed by value])
-if test $ac_cv_sizeof_void_p -ge 8 ; then
- PGAC_ARG_BOOL(enable, float8-byval, yes, [disable float8 passed by value])
-else
- PGAC_ARG_BOOL(enable, float8-byval, no, [disable float8 passed by value])
- if test "$enable_float8_byval" = yes ; then
- AC_MSG_ERROR([--enable-float8-byval is not supported on 32-bit platforms.])
- fi
-fi
-if test "$enable_float8_byval" = yes ; then
- AC_DEFINE([USE_FLOAT8_BYVAL], 1,
- [Define to 1 if you want float8, int8, etc values to be passed by value. (--enable-float8-byval)])
- float8passbyval=true
-else
- float8passbyval=false
-fi
-AC_MSG_RESULT([$enable_float8_byval])
-AC_DEFINE_UNQUOTED([FLOAT8PASSBYVAL], [$float8passbyval], [float8, int8, and related values are passed by value if 'true', by reference if 'false'])
-
# Determine memory alignment requirements for the basic C data types.
AC_CHECK_ALIGNOF(short)
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 28eb322f3f..e4ae12f874 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -19964,16 +19964,6 @@ <title><function>pg_control_init</function> Columns</title>
<entry><type>integer</type></entry>
</row>
- <row>
- <entry><literal>float4_pass_by_value</literal></entry>
- <entry><type>boolean</type></entry>
- </row>
-
- <row>
- <entry><literal>float8_pass_by_value</literal></entry>
- <entry><type>boolean</type></entry>
- </row>
-
<row>
<entry><literal>data_page_checksum_version</literal></entry>
<entry><type>integer</type></entry>
diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index d8494e293b..9c10a897f1 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -1204,34 +1204,6 @@ <title>Anti-Features</title>
</listitem>
</varlistentry>
- <varlistentry>
- <term><option>--disable-float4-byval</option></term>
- <listitem>
- <para>
- Disable passing float4 values <quote>by value</quote>, causing them
- to be passed <quote>by reference</quote> instead. This option costs
- performance, but may be needed for compatibility with very old
- user-defined functions written in C.
- </para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--disable-float8-byval</option></term>
- <listitem>
- <para>
- Disable passing float8 values <quote>by value</quote>, causing them
- to be passed <quote>by reference</quote> instead. This option costs
- performance, but may be needed for compatibility with very old
- user-defined functions written in C.
- Note that this option affects not only float8, but also int8 and some
- related types such as timestamp.
- On 32-bit platforms, <option>--disable-float8-byval</option> is the default
- and it is not allowed to select <option>--enable-float8-byval</option>.
- </para>
- </listitem>
- </varlistentry>
-
<varlistentry>
<term><option>--disable-spinlocks</option></term>
<listitem>
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index 9dfa0ddfbb..4af418287d 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -879,11 +879,6 @@ index_store_float8_orderby_distances(IndexScanDesc scan, Oid *orderByTypes,
else if (orderByTypes[i] == FLOAT4OID)
{
/* convert distance function's result to ORDER BY type */
-#ifndef USE_FLOAT4_BYVAL
- /* must free any old value to avoid memory leakage */
- if (!scan->xs_orderbynulls[i])
- pfree(DatumGetPointer(scan->xs_orderbyvals[i]));
-#endif
if (distances && !distances[i].isnull)
{
scan->xs_orderbyvals[i] = Float4GetDatum((float4) distances[i].value);
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 2e3cc51006..27f2c6bbe2 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -4516,9 +4516,6 @@ WriteControlFile(void)
ControlFile->toast_max_chunk_size = TOAST_MAX_CHUNK_SIZE;
ControlFile->loblksize = LOBLKSIZE;
- ControlFile->float4ByVal = FLOAT4PASSBYVAL;
- ControlFile->float8ByVal = FLOAT8PASSBYVAL;
-
/* Contents are protected with a CRC */
INIT_CRC32C(ControlFile->crc);
COMP_CRC32C(ControlFile->crc,
@@ -4720,38 +4717,6 @@ ReadControlFile(void)
ControlFile->loblksize, (int) LOBLKSIZE),
errhint("It looks like you need to recompile or initdb.")));
-#ifdef USE_FLOAT4_BYVAL
- if (ControlFile->float4ByVal != true)
- ereport(FATAL,
- (errmsg("database files are incompatible with server"),
- errdetail("The database cluster was initialized without USE_FLOAT4_BYVAL"
- " but the server was compiled with USE_FLOAT4_BYVAL."),
- errhint("It looks like you need to recompile or initdb.")));
-#else
- if (ControlFile->float4ByVal != false)
- ereport(FATAL,
- (errmsg("database files are incompatible with server"),
- errdetail("The database cluster was initialized with USE_FLOAT4_BYVAL"
- " but the server was compiled without USE_FLOAT4_BYVAL."),
- errhint("It looks like you need to recompile or initdb.")));
-#endif
-
-#ifdef USE_FLOAT8_BYVAL
- if (ControlFile->float8ByVal != true)
- ereport(FATAL,
- (errmsg("database files are incompatible with server"),
- errdetail("The database cluster was initialized without USE_FLOAT8_BYVAL"
- " but the server was compiled with USE_FLOAT8_BYVAL."),
- errhint("It looks like you need to recompile or initdb.")));
-#else
- if (ControlFile->float8ByVal != false)
- ereport(FATAL,
- (errmsg("database files are incompatible with server"),
- errdetail("The database cluster was initialized with USE_FLOAT8_BYVAL"
- " but the server was compiled without USE_FLOAT8_BYVAL."),
- errhint("It looks like you need to recompile or initdb.")));
-#endif
-
wal_segment_size = ControlFile->xlog_seg_size;
if (!IsValidWalSegSize(wal_segment_size))
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 9238fbe98d..8ea033610d 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -111,7 +111,7 @@ static const struct typinfo TypInfo[] = {
F_INT2IN, F_INT2OUT},
{"int4", INT4OID, 0, 4, true, 'i', 'p', InvalidOid,
F_INT4IN, F_INT4OUT},
- {"float4", FLOAT4OID, 0, 4, FLOAT4PASSBYVAL, 'i', 'p', InvalidOid,
+ {"float4", FLOAT4OID, 0, 4, true, 'i', 'p', InvalidOid,
F_FLOAT4IN, F_FLOAT4OUT},
{"name", NAMEOID, CHAROID, NAMEDATALEN, false, 'c', 'p', C_COLLATION_OID,
F_NAMEIN, F_NAMEOUT},
diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl
index 201d12d358..6eff045bd9 100644
--- a/src/backend/catalog/genbki.pl
+++ b/src/backend/catalog/genbki.pl
@@ -890,7 +890,7 @@ sub morph_row_for_schemapg
}
# Expand booleans from 'f'/'t' to 'false'/'true'.
- # Some values might be other macros (eg FLOAT4PASSBYVAL),
+ # Some values might be other macros (eg FLOAT8PASSBYVAL),
# don't change.
elsif ($atttype eq 'bool')
{
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 7accb950eb..71372ceb16 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -1496,7 +1496,7 @@ update_attstats(Oid relid, bool inh, int natts, VacAttrStats **vacattrstats)
/* XXX knows more than it should about type float4: */
arry = construct_array(numdatums, nnum,
FLOAT4OID,
- sizeof(float4), FLOAT4PASSBYVAL, 'i');
+ sizeof(float4), true, 'i');
values[i++] = PointerGetDatum(arry); /* stanumbersN */
}
else
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index a00db3ce7a..21cc9a8109 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -351,8 +351,9 @@ typedef struct NumericSumAccum
/*
* 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.
+ * USE_FLOAT8_BYVAL, which was previously build-time configurable. 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
diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c
index be684786d6..589371942f 100644
--- a/src/backend/utils/fmgr/dfmgr.c
+++ b/src/backend/utils/fmgr/dfmgr.c
@@ -365,24 +365,6 @@ incompatible_module_error(const char *libname,
magic_data.namedatalen,
module_magic_data->namedatalen);
}
- if (module_magic_data->float4byval != magic_data.float4byval)
- {
- if (details.len)
- appendStringInfoChar(&details, '\n');
- appendStringInfo(&details,
- _("Server has FLOAT4PASSBYVAL = %s, library has %s."),
- magic_data.float4byval ? "true" : "false",
- module_magic_data->float4byval ? "true" : "false");
- }
- if (module_magic_data->float8byval != magic_data.float8byval)
- {
- if (details.len)
- appendStringInfoChar(&details, '\n');
- appendStringInfo(&details,
- _("Server has FLOAT8PASSBYVAL = %s, library has %s."),
- magic_data.float8byval ? "true" : "false",
- module_magic_data->float8byval ? "true" : "false");
- }
if (details.len == 0)
appendStringInfoString(&details,
diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c
index 099ebd779b..c2eaa6178d 100644
--- a/src/backend/utils/fmgr/fmgr.c
+++ b/src/backend/utils/fmgr/fmgr.c
@@ -1683,13 +1683,7 @@ OidSendFunctionCall(Oid functionId, Datum val)
/*-------------------------------------------------------------------------
* Support routines for standard maybe-pass-by-reference datatypes
*
- * int8, float4, and float8 can be passed by value if Datum is wide enough.
- * (For backwards-compatibility reasons, we allow pass-by-ref to be chosen
- * at compile time even if pass-by-val is possible.)
- *
- * Note: there is only one switch controlling the pass-by-value option for
- * both int8 and float8; this is to avoid making things unduly complicated
- * for the timestamp types, which might have either representation.
+ * int8 and float8 can be passed by value if Datum is wide enough.
*-------------------------------------------------------------------------
*/
@@ -1703,21 +1697,6 @@ Int64GetDatum(int64 X)
*retval = X;
return PointerGetDatum(retval);
}
-#endif /* USE_FLOAT8_BYVAL */
-
-#ifndef USE_FLOAT4_BYVAL
-
-Datum
-Float4GetDatum(float4 X)
-{
- float4 *retval = (float4 *) palloc(sizeof(float4));
-
- *retval = X;
- return PointerGetDatum(retval);
-}
-#endif
-
-#ifndef USE_FLOAT8_BYVAL
Datum
Float8GetDatum(float8 X)
diff --git a/src/backend/utils/misc/pg_controldata.c b/src/backend/utils/misc/pg_controldata.c
index b42921800b..330c210407 100644
--- a/src/backend/utils/misc/pg_controldata.c
+++ b/src/backend/utils/misc/pg_controldata.c
@@ -264,8 +264,8 @@ pg_control_recovery(PG_FUNCTION_ARGS)
Datum
pg_control_init(PG_FUNCTION_ARGS)
{
- Datum values[12];
- bool nulls[12];
+ Datum values[10];
+ bool nulls[10];
TupleDesc tupdesc;
HeapTuple htup;
ControlFileData *ControlFile;
@@ -294,11 +294,7 @@ pg_control_init(PG_FUNCTION_ARGS)
INT4OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 9, "large_object_chunk_size",
INT4OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 10, "float4_pass_by_value",
- BOOLOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 11, "float8_pass_by_value",
- BOOLOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 12, "data_page_checksum_version",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 10, "data_page_checksum_version",
INT4OID, -1, 0);
tupdesc = BlessTupleDesc(tupdesc);
@@ -335,15 +331,9 @@ pg_control_init(PG_FUNCTION_ARGS)
values[8] = Int32GetDatum(ControlFile->loblksize);
nulls[8] = false;
- values[9] = BoolGetDatum(ControlFile->float4ByVal);
+ values[9] = Int32GetDatum(ControlFile->data_checksum_version);
nulls[9] = false;
- values[10] = BoolGetDatum(ControlFile->float8ByVal);
- nulls[10] = false;
-
- values[11] = Int32GetDatum(ControlFile->data_checksum_version);
- nulls[11] = false;
-
htup = heap_form_tuple(tupdesc, values, nulls);
PG_RETURN_DATUM(HeapTupleGetDatum(htup));
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 88a261d9bd..1f6d8939be 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -1399,9 +1399,6 @@ bootstrap_template1(void)
bki_lines = replace_token(bki_lines, "ALIGNOF_POINTER",
(sizeof(Pointer) == 4) ? "i" : "d");
- bki_lines = replace_token(bki_lines, "FLOAT4PASSBYVAL",
- FLOAT4PASSBYVAL ? "true" : "false");
-
bki_lines = replace_token(bki_lines, "FLOAT8PASSBYVAL",
FLOAT8PASSBYVAL ? "true" : "false");
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index b14767f8b6..a2611c253c 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -327,10 +327,6 @@ main(int argc, char *argv[])
/* This is no longer configurable, but users may still expect to see it: */
printf(_("Date/time type storage: %s\n"),
_("64-bit integers"));
- printf(_("Float4 argument passing: %s\n"),
- (ControlFile->float4ByVal ? _("by value") : _("by reference")));
- printf(_("Float8 argument passing: %s\n"),
- (ControlFile->float8ByVal ? _("by value") : _("by reference")));
printf(_("Data page checksum version: %u\n"),
ControlFile->data_checksum_version);
printf(_("Mock authentication nonce: %s\n"),
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index c4ee0168a9..201fcde2cd 100644
--- a/src/bin/pg_resetwal/pg_resetwal.c
+++ b/src/bin/pg_resetwal/pg_resetwal.c
@@ -722,8 +722,6 @@ GuessControlValues(void)
ControlFile.indexMaxKeys = INDEX_MAX_KEYS;
ControlFile.toast_max_chunk_size = TOAST_MAX_CHUNK_SIZE;
ControlFile.loblksize = LOBLKSIZE;
- ControlFile.float4ByVal = FLOAT4PASSBYVAL;
- ControlFile.float8ByVal = FLOAT8PASSBYVAL;
/*
* XXX eventually, should try to grovel through old XLOG to develop more
@@ -801,10 +799,6 @@ PrintControlValues(bool guessed)
/* This is no longer configurable, but users may still expect to see it: */
printf(_("Date/time type storage: %s\n"),
_("64-bit integers"));
- printf(_("Float4 argument passing: %s\n"),
- (ControlFile.float4ByVal ? _("by value") : _("by reference")));
- printf(_("Float8 argument passing: %s\n"),
- (ControlFile.float8ByVal ? _("by value") : _("by reference")));
printf(_("Data page checksum version: %u\n"),
ControlFile.data_checksum_version);
}
diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c
index 93f3c34b74..85e22283a6 100644
--- a/src/bin/pg_upgrade/controldata.c
+++ b/src/bin/pg_upgrade/controldata.c
@@ -202,6 +202,13 @@ get_control_data(ClusterInfo *cluster, bool live_check)
got_data_checksum_version = true;
}
+ /* This is no longer configurable. */
+ if (GET_MAJOR_VERSION(cluster->major_version) >= 1300)
+ {
+ cluster->controldata.float8_pass_by_value = FLOAT8PASSBYVAL;
+ got_float8_pass_by_value = true;
+ }
+
/* we have the result of cmd in "output". so parse it line by line now */
while (fgets(bufin, sizeof(bufin), output))
{
diff --git a/src/include/c.h b/src/include/c.h
index d752cc07dc..ab9cb73a4c 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -490,6 +490,21 @@ typedef signed int Offset;
typedef float float4;
typedef double float8;
+/*
+ * Decide whether 8-byte types are passed by value. This controls the titular
+ * float8 but also int8 and related types such as timestamp.
+ *
+ * This is defined here instead of, say, postgres.h, so that initdb.c can see
+ * it.
+ */
+#if SIZEOF_VOID_P >= 8
+#define FLOAT8PASSBYVAL true
+#define USE_FLOAT8_BYVAL 1
+#else
+#define FLOAT8PASSBYVAL false
+#undef USE_FLOAT8_BYVAL
+#endif
+
/*
* Oid, RegProcedure, TransactionId, SubTransactionId, MultiXactId,
* CommandId
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
index 1f6de76e9c..37c52ddd38 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 201910251
+#define CATALOG_VERSION_NO 201910311
#endif
diff --git a/src/include/catalog/pg_control.h b/src/include/catalog/pg_control.h
index ff98d9e91a..19208aefd8 100644
--- a/src/include/catalog/pg_control.h
+++ b/src/include/catalog/pg_control.h
@@ -22,7 +22,7 @@
/* Version identifier for this pg_control format */
-#define PG_CONTROL_VERSION 1201
+#define PG_CONTROL_VERSION 1202
/* Nonce key length, see below */
#define MOCK_AUTH_NONCE_LEN 32
@@ -214,10 +214,6 @@ typedef struct ControlFileData
uint32 toast_max_chunk_size; /* chunk size in TOAST tables */
uint32 loblksize; /* chunk size in pg_largeobject */
- /* flags indicating pass-by-value status of various types */
- bool float4ByVal; /* float4 pass-by-value? */
- bool float8ByVal; /* float8, int8, etc pass-by-value? */
-
/* Are data pages protected by checksums? Zero if no checksum version */
uint32 data_checksum_version;
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 58ea5b982b..4d4f119268 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -10660,9 +10660,9 @@
descr => 'pg_controldata init state information as a function',
proname => 'pg_control_init', provolatile => 'v', prorettype => 'record',
proargtypes => '',
- proallargtypes => '{int4,int4,int4,int4,int4,int4,int4,int4,int4,bool,bool,int4}',
- proargmodes => '{o,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{max_data_alignment,database_block_size,blocks_per_segment,wal_block_size,bytes_per_wal_segment,max_identifier_length,max_index_columns,max_toast_chunk_size,large_object_chunk_size,float4_pass_by_value,float8_pass_by_value,data_page_checksum_version}',
+ proallargtypes => '{int4,int4,int4,int4,int4,int4,int4,int4,int4,int4}',
+ proargmodes => '{o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{max_data_alignment,database_block_size,blocks_per_segment,wal_block_size,bytes_per_wal_segment,max_identifier_length,max_index_columns,max_toast_chunk_size,large_object_chunk_size,data_page_checksum_version}',
prosrc => 'pg_control_init' },
# collation management functions
diff --git a/src/include/catalog/pg_type.dat b/src/include/catalog/pg_type.dat
index be49e00114..d9b35af914 100644
--- a/src/include/catalog/pg_type.dat
+++ b/src/include/catalog/pg_type.dat
@@ -215,7 +215,7 @@
{ oid => '700', array_type_oid => '1021',
descr => 'single-precision floating point number, 4-byte storage',
- typname => 'float4', typlen => '4', typbyval => 'FLOAT4PASSBYVAL',
+ typname => 'float4', typlen => '4', typbyval => 't',
typcategory => 'N', typinput => 'float4in', typoutput => 'float4out',
typreceive => 'float4recv', typsend => 'float4send', typalign => 'i' },
{ oid => '701', array_type_oid => '1022',
diff --git a/src/include/fmgr.h b/src/include/fmgr.h
index 29ae4674cc..838d43875a 100644
--- a/src/include/fmgr.h
+++ b/src/include/fmgr.h
@@ -446,8 +446,6 @@ typedef struct
int funcmaxargs; /* FUNC_MAX_ARGS */
int indexmaxkeys; /* INDEX_MAX_KEYS */
int namedatalen; /* NAMEDATALEN */
- int float4byval; /* FLOAT4PASSBYVAL */
- int float8byval; /* FLOAT8PASSBYVAL */
} Pg_magic_struct;
/* The actual data block contents */
@@ -458,8 +456,6 @@ typedef struct
FUNC_MAX_ARGS, \
INDEX_MAX_KEYS, \
NAMEDATALEN, \
- FLOAT4PASSBYVAL, \
- FLOAT8PASSBYVAL \
}
/*
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 939245db39..97552d63d0 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -70,13 +70,6 @@
MSVC and with C++ compilers. */
#undef FLEXIBLE_ARRAY_MEMBER
-/* float4 values are passed by value if 'true', by reference if 'false' */
-#undef FLOAT4PASSBYVAL
-
-/* float8, int8, and related values are passed by value if 'true', by
- reference if 'false' */
-#undef FLOAT8PASSBYVAL
-
/* Define to 1 if gettimeofday() takes only 1 argument. */
#undef GETTIMEOFDAY_1ARG
@@ -898,14 +891,6 @@
/* Define to use /dev/urandom for random number generation */
#undef USE_DEV_URANDOM
-/* Define to 1 if you want float4 values to be passed by value.
- (--enable-float4-byval) */
-#undef USE_FLOAT4_BYVAL
-
-/* Define to 1 if you want float8, int8, etc values to be passed by value.
- (--enable-float8-byval) */
-#undef USE_FLOAT8_BYVAL
-
/* Define to build with ICU support. (--with-icu) */
#undef USE_ICU
diff --git a/src/include/postgres.h b/src/include/postgres.h
index 057a3413ac..f5b7c52f8a 100644
--- a/src/include/postgres.h
+++ b/src/include/postgres.h
@@ -659,11 +659,7 @@ extern Datum Int64GetDatum(int64 X);
/*
* DatumGetFloat4
* Returns 4-byte floating point value of a datum.
- *
- * Note: this macro hides whether float4 is pass by value or by reference.
*/
-
-#ifdef USE_FLOAT4_BYVAL
static inline float4
DatumGetFloat4(Datum X)
{
@@ -676,18 +672,11 @@ DatumGetFloat4(Datum X)
myunion.value = DatumGetInt32(X);
return myunion.retval;
}
-#else
-#define DatumGetFloat4(X) (* ((float4 *) DatumGetPointer(X)))
-#endif
/*
* Float4GetDatum
* Returns datum representation for a 4-byte floating point number.
- *
- * Note: if float4 is pass by reference, this function returns a reference
- * to palloc'd space.
*/
-#ifdef USE_FLOAT4_BYVAL
static inline Datum
Float4GetDatum(float4 X)
{
@@ -700,9 +689,6 @@ Float4GetDatum(float4 X)
myunion.value = X;
return Int32GetDatum(myunion.retval);
}
-#else
-extern Datum Float4GetDatum(float4 X);
-#endif
/*
* DatumGetFloat8
@@ -757,10 +743,9 @@ extern Datum Float8GetDatum(float8 X);
/*
* Int64GetDatumFast
* Float8GetDatumFast
- * Float4GetDatumFast
*
* These macros are intended to allow writing code that does not depend on
- * whether int64, float8, float4 are pass-by-reference types, while not
+ * whether int64 and float8 are pass-by-reference types, while not
* sacrificing performance when they are. The argument must be a variable
* that will exist and have the same value for as long as the Datum is needed.
* In the pass-by-ref case, the address of the variable is taken to use as
@@ -776,10 +761,4 @@ extern Datum Float8GetDatum(float8 X);
#define Float8GetDatumFast(X) PointerGetDatum(&(X))
#endif
-#ifdef USE_FLOAT4_BYVAL
-#define Float4GetDatumFast(X) Float4GetDatum(X)
-#else
-#define Float4GetDatumFast(X) PointerGetDatum(&(X))
-#endif
-
#endif /* POSTGRES_H */
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index a6958273ac..2423267b54 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -31,12 +31,6 @@ sub _new
$self->DeterminePlatform();
my $bits = $self->{platform} eq 'Win32' ? 32 : 64;
- $options->{float4byval} = 1
- unless exists $options->{float4byval};
- $options->{float8byval} = ($bits == 64)
- unless exists $options->{float8byval};
- die "float8byval not permitted on 32 bit platforms"
- if $options->{float8byval} && $bits == 32;
if ($options->{xslt} && !$options->{xml})
{
die "XSLT requires XML\n";
@@ -209,25 +203,6 @@ sub GenerateFiles
print $o "#define XLOG_BLCKSZ ",
1024 * $self->{options}->{wal_blocksize}, "\n";
- if ($self->{options}->{float4byval})
- {
- print $o "#define USE_FLOAT4_BYVAL 1\n";
- print $o "#define FLOAT4PASSBYVAL true\n";
- }
- else
- {
- print $o "#define FLOAT4PASSBYVAL false\n";
- }
- if ($self->{options}->{float8byval})
- {
- print $o "#define USE_FLOAT8_BYVAL 1\n";
- print $o "#define FLOAT8PASSBYVAL true\n";
- }
- else
- {
- print $o "#define FLOAT8PASSBYVAL false\n";
- }
-
if ($self->{options}->{uuid})
{
print $o "#define HAVE_UUID_OSSP\n";
diff --git a/src/tools/msvc/config_default.pl b/src/tools/msvc/config_default.pl
index 043df4c5e8..d5e010b18a 100644
--- a/src/tools/msvc/config_default.pl
+++ b/src/tools/msvc/config_default.pl
@@ -4,11 +4,6 @@
our $config = {
asserts => 0, # --enable-cassert
- # float4byval=>1, # --disable-float4-byval, on by default
-
- # float8byval=> $platformbits == 64, # --disable-float8-byval,
- # off by default on 32 bit platforms, on by default on 64 bit platforms
-
# blocksize => 8, # --with-blocksize, 8kB by default
# wal_blocksize => 8, # --with-wal-blocksize, 8kB by default
ldap => 1, # --with-ldap
base-commit: 73025140885c889410b9bfc4a30a3866396fc5db
--
2.23.0
0002-Replace-USE_FLOAT8_BYVAL-by-FLOAT8PASSBYVAL.patchtext/plain; charset=UTF-8; name=0002-Replace-USE_FLOAT8_BYVAL-by-FLOAT8PASSBYVAL.patch; x-mac-creator=0; x-mac-type=0Download
From 1c20d0217f0fb88a286a61532340b0c07d1a013a Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Thu, 31 Oct 2019 09:21:38 +0100
Subject: [PATCH 2/3] Replace USE_FLOAT8_BYVAL by FLOAT8PASSBYVAL
It's enough to have one macro for the same thing.
---
contrib/btree_gist/btree_time.c | 2 +-
contrib/btree_gist/btree_ts.c | 2 +-
src/backend/access/heap/heapam_handler.c | 2 +-
src/backend/access/index/indexam.c | 2 +-
src/backend/utils/adt/int8.c | 4 ++--
src/backend/utils/adt/numeric.c | 6 +++---
src/backend/utils/adt/rangetypes_typanalyze.c | 6 +-----
src/backend/utils/fmgr/fmgr.c | 2 +-
src/include/c.h | 2 --
src/include/postgres.h | 14 +++++++-------
10 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/contrib/btree_gist/btree_time.c b/contrib/btree_gist/btree_time.c
index 90cf6554ea..884ae21ff6 100644
--- a/contrib/btree_gist/btree_time.c
+++ b/contrib/btree_gist/btree_time.c
@@ -30,7 +30,7 @@ PG_FUNCTION_INFO_V1(gbt_time_penalty);
PG_FUNCTION_INFO_V1(gbt_time_same);
-#ifdef USE_FLOAT8_BYVAL
+#if FLOAT8PASSBYVAL
#define TimeADTGetDatumFast(X) TimeADTGetDatum(X)
#else
#define TimeADTGetDatumFast(X) PointerGetDatum(&(X))
diff --git a/contrib/btree_gist/btree_ts.c b/contrib/btree_gist/btree_ts.c
index 49d1849d88..30864465d2 100644
--- a/contrib/btree_gist/btree_ts.c
+++ b/contrib/btree_gist/btree_ts.c
@@ -33,7 +33,7 @@ PG_FUNCTION_INFO_V1(gbt_ts_penalty);
PG_FUNCTION_INFO_V1(gbt_ts_same);
-#ifdef USE_FLOAT8_BYVAL
+#if FLOAT8PASSBYVAL
#define TimestampGetDatumFast(X) TimestampGetDatum(X)
#else
#define TimestampGetDatumFast(X) PointerGetDatum(&(X))
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 2dd8821fac..1ae4258670 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -1858,7 +1858,7 @@ heapam_index_validate_scan(Relation heapRelation,
indexcursor = &decoded;
/* If int8 is pass-by-ref, free (encoded) TID Datum memory */
-#ifndef USE_FLOAT8_BYVAL
+#if !FLOAT8PASSBYVAL
pfree(DatumGetPointer(ts_val));
#endif
}
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index 4af418287d..6a4a1f935c 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -860,7 +860,7 @@ index_store_float8_orderby_distances(IndexScanDesc scan, Oid *orderByTypes,
{
if (orderByTypes[i] == FLOAT8OID)
{
-#ifndef USE_FLOAT8_BYVAL
+#if !FLOAT8PASSBYVAL
/* must free any old value to avoid memory leakage */
if (!scan->xs_orderbynulls[i])
pfree(DatumGetPointer(scan->xs_orderbyvals[i]));
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c
index 0ff9394a2f..165be75da8 100644
--- a/src/backend/utils/adt/int8.c
+++ b/src/backend/utils/adt/int8.c
@@ -679,7 +679,7 @@ int8inc(PG_FUNCTION_ARGS)
* (If int8 is pass-by-value, then of course this is useless as well as
* incorrect, so just ifdef it out.)
*/
-#ifndef USE_FLOAT8_BYVAL /* controls int8 too */
+#if !FLOAT8PASSBYVAL /* controls int8 too */
if (AggCheckCallContext(fcinfo, NULL))
{
int64 *arg = (int64 *) PG_GETARG_POINTER(0);
@@ -717,7 +717,7 @@ int8dec(PG_FUNCTION_ARGS)
* (If int8 is pass-by-value, then of course this is useless as well as
* incorrect, so just ifdef it out.)
*/
-#ifndef USE_FLOAT8_BYVAL /* controls int8 too */
+#if !FLOAT8PASSBYVAL /* controls int8 too */
if (AggCheckCallContext(fcinfo, NULL))
{
int64 *arg = (int64 *) PG_GETARG_POINTER(0);
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index 21cc9a8109..318c6a5494 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -351,7 +351,7 @@ typedef struct NumericSumAccum
/*
* We define our own macros for packing and unpacking abbreviated-key
* representations for numeric values in order to avoid depending on
- * USE_FLOAT8_BYVAL, which was previously build-time configurable. The type
+ * FLOAT8PASSBYVAL, which was previously build-time configurable. The type
* of abbreviation we use is based only on the size of a datum, not the
* argument-passing convention for float8.
*/
@@ -5301,7 +5301,7 @@ int2_sum(PG_FUNCTION_ARGS)
* then of course this is useless as well as incorrect, so just ifdef it
* out.)
*/
-#ifndef USE_FLOAT8_BYVAL /* controls int8 too */
+#if !FLOAT8PASSBYVAL /* controls int8 too */
if (AggCheckCallContext(fcinfo, NULL))
{
int64 *oldsum = (int64 *) PG_GETARG_POINTER(0);
@@ -5350,7 +5350,7 @@ int4_sum(PG_FUNCTION_ARGS)
* then of course this is useless as well as incorrect, so just ifdef it
* out.)
*/
-#ifndef USE_FLOAT8_BYVAL /* controls int8 too */
+#if !FLOAT8PASSBYVAL /* controls int8 too */
if (AggCheckCallContext(fcinfo, NULL))
{
int64 *oldsum = (int64 *) PG_GETARG_POINTER(0);
diff --git a/src/backend/utils/adt/rangetypes_typanalyze.c b/src/backend/utils/adt/rangetypes_typanalyze.c
index d01d3032cc..b438625951 100644
--- a/src/backend/utils/adt/rangetypes_typanalyze.c
+++ b/src/backend/utils/adt/rangetypes_typanalyze.c
@@ -325,11 +325,7 @@ compute_range_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
stats->numvalues[slot_idx] = num_hist;
stats->statypid[slot_idx] = FLOAT8OID;
stats->statyplen[slot_idx] = sizeof(float8);
-#ifdef USE_FLOAT8_BYVAL
- stats->statypbyval[slot_idx] = true;
-#else
- stats->statypbyval[slot_idx] = false;
-#endif
+ stats->statypbyval[slot_idx] = FLOAT8PASSBYVAL;
stats->statypalign[slot_idx] = 'd';
/* Store the fraction of empty ranges */
diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c
index c2eaa6178d..d73fe59a26 100644
--- a/src/backend/utils/fmgr/fmgr.c
+++ b/src/backend/utils/fmgr/fmgr.c
@@ -1687,7 +1687,7 @@ OidSendFunctionCall(Oid functionId, Datum val)
*-------------------------------------------------------------------------
*/
-#ifndef USE_FLOAT8_BYVAL /* controls int8 too */
+#if !FLOAT8PASSBYVAL /* controls int8 too */
Datum
Int64GetDatum(int64 X)
diff --git a/src/include/c.h b/src/include/c.h
index ab9cb73a4c..26d50495e6 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -499,10 +499,8 @@ typedef double float8;
*/
#if SIZEOF_VOID_P >= 8
#define FLOAT8PASSBYVAL true
-#define USE_FLOAT8_BYVAL 1
#else
#define FLOAT8PASSBYVAL false
-#undef USE_FLOAT8_BYVAL
#endif
/*
diff --git a/src/include/postgres.h b/src/include/postgres.h
index f5b7c52f8a..bf4b6223f3 100644
--- a/src/include/postgres.h
+++ b/src/include/postgres.h
@@ -601,7 +601,7 @@ typedef struct NullableDatum
* Note: this macro hides whether int64 is pass by value or by reference.
*/
-#ifdef USE_FLOAT8_BYVAL
+#if FLOAT8PASSBYVAL
#define DatumGetInt64(X) ((int64) (X))
#else
#define DatumGetInt64(X) (* ((int64 *) DatumGetPointer(X)))
@@ -615,7 +615,7 @@ typedef struct NullableDatum
* to palloc'd space.
*/
-#ifdef USE_FLOAT8_BYVAL
+#if FLOAT8PASSBYVAL
#define Int64GetDatum(X) ((Datum) (X))
#else
extern Datum Int64GetDatum(int64 X);
@@ -628,7 +628,7 @@ extern Datum Int64GetDatum(int64 X);
* Note: this macro hides whether int64 is pass by value or by reference.
*/
-#ifdef USE_FLOAT8_BYVAL
+#if FLOAT8PASSBYVAL
#define DatumGetUInt64(X) ((uint64) (X))
#else
#define DatumGetUInt64(X) (* ((uint64 *) DatumGetPointer(X)))
@@ -642,7 +642,7 @@ extern Datum Int64GetDatum(int64 X);
* to palloc'd space.
*/
-#ifdef USE_FLOAT8_BYVAL
+#if FLOAT8PASSBYVAL
#define UInt64GetDatum(X) ((Datum) (X))
#else
#define UInt64GetDatum(X) Int64GetDatum((int64) (X))
@@ -697,7 +697,7 @@ Float4GetDatum(float4 X)
* Note: this macro hides whether float8 is pass by value or by reference.
*/
-#ifdef USE_FLOAT8_BYVAL
+#if FLOAT8PASSBYVAL
static inline float8
DatumGetFloat8(Datum X)
{
@@ -722,7 +722,7 @@ DatumGetFloat8(Datum X)
* to palloc'd space.
*/
-#ifdef USE_FLOAT8_BYVAL
+#if FLOAT8PASSBYVAL
static inline Datum
Float8GetDatum(float8 X)
{
@@ -753,7 +753,7 @@ extern Datum Float8GetDatum(float8 X);
* macros.
*/
-#ifdef USE_FLOAT8_BYVAL
+#if FLOAT8PASSBYVAL
#define Int64GetDatumFast(X) Int64GetDatum(X)
#define Float8GetDatumFast(X) Float8GetDatum(X)
#else
--
2.23.0
0003-Convert-some-if-calls-to-compiler-if-s.patchtext/plain; charset=UTF-8; name=0003-Convert-some-if-calls-to-compiler-if-s.patch; x-mac-creator=0; x-mac-type=0Download
From 9c38db227b7f2154b5a06c4ff42a43f8835b9929 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Thu, 31 Oct 2019 09:21:38 +0100
Subject: [PATCH 3/3] Convert some #if calls to compiler if()s
This ensures that the contained code is looked at by the compiler and
does not bit rot. This is especially interesting as the affected code
is for the lesser-used 32-bit builds.
---
src/backend/access/heap/heapam_handler.c | 5 ++---
src/backend/access/index/indexam.c | 11 ++++++-----
src/backend/utils/adt/int8.c | 12 ++++--------
src/backend/utils/adt/numeric.c | 14 ++++----------
4 files changed, 16 insertions(+), 26 deletions(-)
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 1ae4258670..a002916a73 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -1858,9 +1858,8 @@ heapam_index_validate_scan(Relation heapRelation,
indexcursor = &decoded;
/* If int8 is pass-by-ref, free (encoded) TID Datum memory */
-#if !FLOAT8PASSBYVAL
- pfree(DatumGetPointer(ts_val));
-#endif
+ if (!FLOAT8PASSBYVAL)
+ pfree(DatumGetPointer(ts_val));
}
else
{
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index 6a4a1f935c..934c41c1be 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -860,11 +860,12 @@ index_store_float8_orderby_distances(IndexScanDesc scan, Oid *orderByTypes,
{
if (orderByTypes[i] == FLOAT8OID)
{
-#if !FLOAT8PASSBYVAL
- /* must free any old value to avoid memory leakage */
- if (!scan->xs_orderbynulls[i])
- pfree(DatumGetPointer(scan->xs_orderbyvals[i]));
-#endif
+ if (!FLOAT8PASSBYVAL)
+ {
+ /* must free any old value to avoid memory leakage */
+ if (!scan->xs_orderbynulls[i])
+ pfree(DatumGetPointer(scan->xs_orderbyvals[i]));
+ }
if (distances && !distances[i].isnull)
{
scan->xs_orderbyvals[i] = Float8GetDatum(distances[i].value);
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c
index 165be75da8..3f25ff6b64 100644
--- a/src/backend/utils/adt/int8.c
+++ b/src/backend/utils/adt/int8.c
@@ -677,10 +677,9 @@ int8inc(PG_FUNCTION_ARGS)
* palloc overhead for COUNT(): when called as an aggregate, we know that
* the argument is modifiable local storage, so just update it in-place.
* (If int8 is pass-by-value, then of course this is useless as well as
- * incorrect, so just ifdef it out.)
+ * incorrect.)
*/
-#if !FLOAT8PASSBYVAL /* controls int8 too */
- if (AggCheckCallContext(fcinfo, NULL))
+ if (!FLOAT8PASSBYVAL && AggCheckCallContext(fcinfo, NULL))
{
int64 *arg = (int64 *) PG_GETARG_POINTER(0);
@@ -692,7 +691,6 @@ int8inc(PG_FUNCTION_ARGS)
PG_RETURN_POINTER(arg);
}
else
-#endif
{
/* Not called as an aggregate, so just do it the dumb way */
int64 arg = PG_GETARG_INT64(0);
@@ -715,10 +713,9 @@ int8dec(PG_FUNCTION_ARGS)
* palloc overhead for COUNT(): when called as an aggregate, we know that
* the argument is modifiable local storage, so just update it in-place.
* (If int8 is pass-by-value, then of course this is useless as well as
- * incorrect, so just ifdef it out.)
+ * incorrect.)
*/
-#if !FLOAT8PASSBYVAL /* controls int8 too */
- if (AggCheckCallContext(fcinfo, NULL))
+ if (!FLOAT8PASSBYVAL && AggCheckCallContext(fcinfo, NULL))
{
int64 *arg = (int64 *) PG_GETARG_POINTER(0);
@@ -729,7 +726,6 @@ int8dec(PG_FUNCTION_ARGS)
PG_RETURN_POINTER(arg);
}
else
-#endif
{
/* Not called as an aggregate, so just do it the dumb way */
int64 arg = PG_GETARG_INT64(0);
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index 318c6a5494..d6eae74a35 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -5298,11 +5298,9 @@ int2_sum(PG_FUNCTION_ARGS)
* If we're invoked as an aggregate, we can cheat and modify our first
* parameter in-place to avoid palloc overhead. If not, we need to return
* the new value of the transition variable. (If int8 is pass-by-value,
- * then of course this is useless as well as incorrect, so just ifdef it
- * out.)
+ * then of course this is useless as well as incorrect.)
*/
-#if !FLOAT8PASSBYVAL /* controls int8 too */
- if (AggCheckCallContext(fcinfo, NULL))
+ if (!FLOAT8PASSBYVAL && AggCheckCallContext(fcinfo, NULL))
{
int64 *oldsum = (int64 *) PG_GETARG_POINTER(0);
@@ -5313,7 +5311,6 @@ int2_sum(PG_FUNCTION_ARGS)
PG_RETURN_POINTER(oldsum);
}
else
-#endif
{
int64 oldsum = PG_GETARG_INT64(0);
@@ -5347,11 +5344,9 @@ int4_sum(PG_FUNCTION_ARGS)
* If we're invoked as an aggregate, we can cheat and modify our first
* parameter in-place to avoid palloc overhead. If not, we need to return
* the new value of the transition variable. (If int8 is pass-by-value,
- * then of course this is useless as well as incorrect, so just ifdef it
- * out.)
+ * then of course this is useless as well as incorrect.)
*/
-#if !FLOAT8PASSBYVAL /* controls int8 too */
- if (AggCheckCallContext(fcinfo, NULL))
+ if (!FLOAT8PASSBYVAL && AggCheckCallContext(fcinfo, NULL))
{
int64 *oldsum = (int64 *) PG_GETARG_POINTER(0);
@@ -5362,7 +5357,6 @@ int4_sum(PG_FUNCTION_ARGS)
PG_RETURN_POINTER(oldsum);
}
else
-#endif
{
int64 oldsum = PG_GETARG_INT64(0);
--
2.23.0
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
float4 is now always pass-by-value; the pass-by-reference code path is
completely removed.
I think this is OK.
float8 and related types are now hardcoded to pass-by-value or
pass-by-reference depending on whether the build is 64- or 32-bit, as
was previously also the default.
I'm less happy with doing this. It makes it impossible to test the
pass-by-reference code paths without actually firing up a 32-bit
environment. It'd be fine to document --disable-float8-byval as
a developer-only option (it might be so already), but I don't want
to lose it completely. I fail to see any advantage in getting rid
of it, anyway, since we do still have to maintain both code paths.
regards, tom lane
On Thu, Oct 31, 2019 at 9:36 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
float8 and related types are now hardcoded to pass-by-value or
pass-by-reference depending on whether the build is 64- or 32-bit, as
was previously also the default.I'm less happy with doing this. It makes it impossible to test the
pass-by-reference code paths without actually firing up a 32-bit
environment. It'd be fine to document --disable-float8-byval as
a developer-only option (it might be so already), but I don't want
to lose it completely. I fail to see any advantage in getting rid
of it, anyway, since we do still have to maintain both code paths.
Could we get around this by making Datum 8 bytes everywhere?
Years ago, we got rid of INT64_IS_BUSTED, so we're relying on 64-bit
types working on all platforms. However, Datum on a system where
pointers are only 32 bits wide is also only 32 bits wide, so we can't
pass 64-bit quantities the same way we do elsewhere. But, why is the
width of a Datum equal to the width of a pointer, anyway? It would
surely cost something to widen 1, 2, and 4 byte quantities to 8 bytes
when packing them into datums on 32-bit platforms, but (1) we've long
since accepted that cost on 64-bit platforms, (2) it would save
palloc/pfree cycles when packing 8 byte quantities into 4-byte values,
(3) 32-bit platforms are now marginal and performance on those
platforms is not critical, and (4) it would simplify a lot of code and
reduce future bugs.
On a related note, why do we store typbyval in the catalog anyway
instead of inferring it from typlen and maybe typalign? It seems like
a bad idea to record on disk the way we pass around values in memory,
because it means that a change to how values are passed around in
memory has ramifications for on-disk compatibility.
rhaas=# select typname, typlen, typbyval, typalign from pg_type where
typlen in (1,2,4,8) != typbyval;
typname | typlen | typbyval | typalign
----------+--------+----------+----------
macaddr8 | 8 | f | i
(1 row)
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
On Fri, Nov 1, 2019 at 7:41 AM Robert Haas <robertmhaas@gmail.com> wrote:
Could we get around this by making Datum 8 bytes everywhere?
I really like that idea.
Even Raspberry Pi devices (which can cost as little as $35) use 64-bit
ARM processors. It's abundantly clear that 32-bit platforms do not
matter enough to justify keeping all the SIZEOF_DATUM crud around.
--
Peter Geoghegan
Peter Geoghegan <pg@bowt.ie> writes:
On Fri, Nov 1, 2019 at 7:41 AM Robert Haas <robertmhaas@gmail.com> wrote:
Could we get around this by making Datum 8 bytes everywhere?
I really like that idea.
Even Raspberry Pi devices (which can cost as little as $35) use 64-bit
ARM processors. It's abundantly clear that 32-bit platforms do not
matter enough to justify keeping all the SIZEOF_DATUM crud around.
This line of argument seems to me to be the moral equivalent of
"let's drop 32-bit support altogether". I'm not entirely on board
with that. Certainly, a lot of the world is 64-bit these days,
but people are still building small systems and they might want
a database; preferably one that hasn't been detuned to the extent
that it barely manages to run at all on such a platform. Making
a whole lot of internal APIs 64-bit would be a pretty big hit for
a 32-bit platform --- more instructions, more memory consumed for
things like Datum arrays, all in a memory space that's not that big.
It seems especially insane to conclude that we should pull the plug
on such use-cases just to get rid of one obscure configure option.
If we were expending any significant devel effort on supporting
32-bit platforms, I might be ready to drop support, but we're not.
(Robert's proposal looks to me like it's actually creating new work
to do, not saving work.)
regards, tom lane
On Fri, Nov 1, 2019 at 11:00 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
This line of argument seems to me to be the moral equivalent of
"let's drop 32-bit support altogether". I'm not entirely on board
with that.
I don't think that those two things are equivalent at all. There may
even be workloads that will benefit when run on 32-bit hardware.
Having to palloc() and pfree() with 8 byte integers is probably very
slow.
Certainly, a lot of the world is 64-bit these days,
but people are still building small systems and they might want
a database; preferably one that hasn't been detuned to the extent
that it barely manages to run at all on such a platform.
Even the very low end is 64-bit these days. $100 smartphones have
64-bit CPUs and 4GB of ram. AFAICT, anything still being produced that
is recognizable as a general purpose CPU (e.g. by having virtual
memory) is 64-bit. We're talking about a change that can't affect
users until late 2020 at the earliest.
I accept that there are some number of users that still have 32-bit
Postgres installations, probably because they happened to have a
32-bit machine close at hand. The economics of running a database
server on a 32-bit machine are already awful, though.
It seems especially insane to conclude that we should pull the plug
on such use-cases just to get rid of one obscure configure option.
If we were expending any significant devel effort on supporting
32-bit platforms, I might be ready to drop support, but we're not.
(Robert's proposal looks to me like it's actually creating new work
to do, not saving work.)
The mental burden of considering "SIZEOF_DATUM == 4" and
"USE_FLOAT8_BYVAL" is a real cost for us. We maintain non-trivial
32-bit only code for numeric abbreviated keys. We also have to worry
about pfree()'ing memory when USE_FLOAT8_BYVAL within
heapam_index_validate_scan(). How confident are we that there isn't
some place that leaks memory on !USE_FLOAT8_BYVAL builds because
somebody forgot to add a pfree() in an #ifdef block?
--
Peter Geoghegan
On Fri, Nov 1, 2019 at 3:15 PM Peter Geoghegan <pg@bowt.ie> wrote:
I don't think that those two things are equivalent at all. There may
even be workloads that will benefit when run on 32-bit hardware.
Having to palloc() and pfree() with 8 byte integers is probably very
slow.
Yeah! I mean, users who are using only 4-byte or smaller pass-by-value
quantities will be harmed, especially in cases where they are storing
a lot of them at the same time (e.g. sorting) and especially if they
double their space consumption and run out of their very limited
supply of memory. Those are all worthwhile considerations and perhaps
strong arguments against my proposal. But, people using 8-byte
oughta-be-pass-by-value quantities are certainly being harmed by the
present system. It's not a black-and-white thing, like, oh, 8-byte
datums on 32-bit system is awful all the time. Or at least, I don't
think it is.
The mental burden of considering "SIZEOF_DATUM == 4" and
"USE_FLOAT8_BYVAL" is a real cost for us. We maintain non-trivial
32-bit only code for numeric abbreviated keys. We also have to worry
about pfree()'ing memory when USE_FLOAT8_BYVAL within
heapam_index_validate_scan(). How confident are we that there isn't
some place that leaks memory on !USE_FLOAT8_BYVAL builds because
somebody forgot to add a pfree() in an #ifdef block?
Yeah, I've had to fight with this multiple times, and so have other
people. It's a nuisance, and it causes bugs, certainly in draft
patches, sometimes in committed ones. It's not "free." If it's a cost
worth paying, ok, but is it?
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
On Fri, Nov 1, 2019 at 1:19 PM Robert Haas <robertmhaas@gmail.com> wrote:
Yeah! I mean, users who are using only 4-byte or smaller pass-by-value
quantities will be harmed, especially in cases where they are storing
a lot of them at the same time (e.g. sorting) and especially if they
double their space consumption and run out of their very limited
supply of memory.
I think that you meant treble, not double. You're forgetting about the
palloc() header overhead. ;-)
Doing even slightly serious work on a 32-bit machine is penny wise and
pound foolish. I also believe that we should support minority
platforms reasonably well, including 32-bit platforms, because it's
always a good idea to try to meet people where they are. Your proposal
doesn't seem like it really gives up on that goal.
Those are all worthwhile considerations and perhaps
strong arguments against my proposal. But, people using 8-byte
oughta-be-pass-by-value quantities are certainly being harmed by the
present system. It's not a black-and-white thing, like, oh, 8-byte
datums on 32-bit system is awful all the time. Or at least, I don't
think it is.
Right.
Yeah, I've had to fight with this multiple times, and so have other
people. It's a nuisance, and it causes bugs, certainly in draft
patches, sometimes in committed ones. It's not "free." If it's a cost
worth paying, ok, but is it?
#ifdef crud is something that we should go out of our way to eliminate
on general principle. All good portable C codebases go to great
lengths to encapsulate platform differences, if necessary by adding a
compatibility layer. One of the worst things about the OpenSSL
codebase is that it makes writing portable code everybody's problem.
--
Peter Geoghegan
On Fri, Nov 01, 2019 at 02:00:10PM -0400, Tom Lane wrote:
Peter Geoghegan <pg@bowt.ie> writes:
Even Raspberry Pi devices (which can cost as little as $35) use 64-bit
ARM processors. It's abundantly clear that 32-bit platforms do not
matter enough to justify keeping all the SIZEOF_DATUM crud around.This line of argument seems to me to be the moral equivalent of
"let's drop 32-bit support altogether". I'm not entirely on board
with that. Certainly, a lot of the world is 64-bit these days,
but people are still building small systems and they might want
a database; preferably one that hasn't been detuned to the extent
that it barely manages to run at all on such a platform. Making
a whole lot of internal APIs 64-bit would be a pretty big hit for
a 32-bit platform --- more instructions, more memory consumed for
things like Datum arrays, all in a memory space that's not that big.
I don't agree as well with the line of arguments to just remove 32b
support. The newest models of PI indeed use 64b ARM processors, but
the first model, as well as the PI zero are on 32b if I recall
correctly, and I would like to believe that these are still widely
used.
--
Michael
On 2019-11-02 11:47:26 +0900, Michael Paquier wrote:
On Fri, Nov 01, 2019 at 02:00:10PM -0400, Tom Lane wrote:
Peter Geoghegan <pg@bowt.ie> writes:
Even Raspberry Pi devices (which can cost as little as $35) use 64-bit
ARM processors. It's abundantly clear that 32-bit platforms do not
matter enough to justify keeping all the SIZEOF_DATUM crud around.This line of argument seems to me to be the moral equivalent of
"let's drop 32-bit support altogether". I'm not entirely on board
with that. Certainly, a lot of the world is 64-bit these days,
but people are still building small systems and they might want
a database; preferably one that hasn't been detuned to the extent
that it barely manages to run at all on such a platform. Making
a whole lot of internal APIs 64-bit would be a pretty big hit for
a 32-bit platform --- more instructions, more memory consumed for
things like Datum arrays, all in a memory space that's not that big.I don't agree as well with the line of arguments to just remove 32b
support.
Nobody is actually proposing that, as far as I can tell? I mean, by all
means argue that the overhead is too high, but just claiming that
slowing down 32bit systems by a measurable fraction is morally
equivalent to removing 32bit support seems pointlessly facetious.
Greetings,
Andres Freund
On Fri, Nov 1, 2019 at 7:47 PM Michael Paquier <michael@paquier.xyz> wrote:
This line of argument seems to me to be the moral equivalent of
"let's drop 32-bit support altogether". I'm not entirely on board
with that. Certainly, a lot of the world is 64-bit these days,
but people are still building small systems and they might want
a database; preferably one that hasn't been detuned to the extent
that it barely manages to run at all on such a platform. Making
a whole lot of internal APIs 64-bit would be a pretty big hit for
a 32-bit platform --- more instructions, more memory consumed for
things like Datum arrays, all in a memory space that's not that big.I don't agree as well with the line of arguments to just remove 32b
support.
Clearly you didn't read what I actually wrote, Michael.
--
Peter Geoghegan
On 2019-10-31 14:36, Tom Lane wrote:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
float4 is now always pass-by-value; the pass-by-reference code path is
completely removed.I think this is OK.
OK, here is a patch for just this part, and we can continue the
discussion on the rest in the meantime.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
v2-0001-Remove-configure-disable-float4-byval.patchtext/plain; charset=UTF-8; name=v2-0001-Remove-configure-disable-float4-byval.patch; x-mac-creator=0; x-mac-type=0Download
From 117590e3e1bb74ce8bebbd4791fcfcb514e24136 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Sat, 2 Nov 2019 08:09:01 +0100
Subject: [PATCH v2] Remove configure --disable-float4-byval
This build option was only useful to maintain compatibility for
version-0 functions, but those are no longer supported, so this option
can be removed.
float4 is now always pass-by-value; the pass-by-reference code path is
completely removed.
Discussion: https://www.postgresql.org/message-id/flat/f3e1e576-2749-bbd7-2d57-3f9dcf75255a@2ndquadrant.com
---
configure | 42 -------------------------
configure.in | 10 ------
doc/src/sgml/func.sgml | 5 ---
doc/src/sgml/installation.sgml | 12 -------
src/backend/access/index/indexam.c | 5 ---
src/backend/access/transam/xlog.c | 17 ----------
src/backend/bootstrap/bootstrap.c | 2 +-
src/backend/catalog/genbki.pl | 2 +-
src/backend/commands/analyze.c | 2 +-
src/backend/utils/fmgr/dfmgr.c | 9 ------
src/backend/utils/fmgr/fmgr.c | 19 ++---------
src/backend/utils/misc/pg_controldata.c | 17 ++++------
src/bin/initdb/initdb.c | 3 --
src/bin/pg_controldata/pg_controldata.c | 2 --
src/bin/pg_resetwal/pg_resetwal.c | 3 --
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_control.h | 4 +--
src/include/catalog/pg_proc.dat | 6 ++--
src/include/catalog/pg_type.dat | 2 +-
src/include/fmgr.h | 2 --
src/include/pg_config.h.in | 7 -----
src/include/postgres.h | 23 +-------------
src/tools/msvc/Solution.pm | 11 -------
src/tools/msvc/config_default.pl | 1 -
24 files changed, 18 insertions(+), 190 deletions(-)
diff --git a/configure b/configure
index 6b1c779ee3..accd06c2e6 100755
--- a/configure
+++ b/configure
@@ -866,7 +866,6 @@ with_system_tzdata
with_zlib
with_gnu_ld
enable_largefile
-enable_float4_byval
enable_float8_byval
'
ac_precious_vars='build_alias
@@ -1525,7 +1524,6 @@ Optional Features:
--enable-cassert enable assertion checks (for debugging)
--disable-thread-safety disable thread-safety in client libraries
--disable-largefile omit support for large files
- --disable-float4-byval disable float4 passed by value
--disable-float8-byval disable float8 passed by value
Optional Packages:
@@ -16801,46 +16799,6 @@ _ACEOF
-# Decide whether float4 is passed by value: user-selectable, enabled by default
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build with float4 passed by value" >&5
-$as_echo_n "checking whether to build with float4 passed by value... " >&6; }
-
-
-# Check whether --enable-float4-byval was given.
-if test "${enable_float4_byval+set}" = set; then :
- enableval=$enable_float4_byval;
- case $enableval in
- yes)
-
-$as_echo "#define USE_FLOAT4_BYVAL 1" >>confdefs.h
-
- float4passbyval=true
- ;;
- no)
- float4passbyval=false
- ;;
- *)
- as_fn_error $? "no argument expected for --enable-float4-byval option" "$LINENO" 5
- ;;
- esac
-
-else
- enable_float4_byval=yes
-
-$as_echo "#define USE_FLOAT4_BYVAL 1" >>confdefs.h
-
- float4passbyval=true
-fi
-
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_float4_byval" >&5
-$as_echo "$enable_float4_byval" >&6; }
-
-cat >>confdefs.h <<_ACEOF
-#define FLOAT4PASSBYVAL $float4passbyval
-_ACEOF
-
-
# Decide whether float8 is passed by value.
# Note: this setting also controls int8 and related types such as timestamp.
# If sizeof(Datum) >= 8, this is user-selectable, enabled by default.
diff --git a/configure.in b/configure.in
index 2b9025cac3..e5ad3bf883 100644
--- a/configure.in
+++ b/configure.in
@@ -1931,16 +1931,6 @@ AC_CHECK_SIZEOF([void *])
AC_CHECK_SIZEOF([size_t])
AC_CHECK_SIZEOF([long])
-# Decide whether float4 is passed by value: user-selectable, enabled by default
-AC_MSG_CHECKING([whether to build with float4 passed by value])
-PGAC_ARG_BOOL(enable, float4-byval, yes, [disable float4 passed by value],
- [AC_DEFINE([USE_FLOAT4_BYVAL], 1,
- [Define to 1 if you want float4 values to be passed by value. (--enable-float4-byval)])
- float4passbyval=true],
- [float4passbyval=false])
-AC_MSG_RESULT([$enable_float4_byval])
-AC_DEFINE_UNQUOTED([FLOAT4PASSBYVAL], [$float4passbyval], [float4 values are passed by value if 'true', by reference if 'false'])
-
# Decide whether float8 is passed by value.
# Note: this setting also controls int8 and related types such as timestamp.
# If sizeof(Datum) >= 8, this is user-selectable, enabled by default.
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 28eb322f3f..8c8a568fd9 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -19964,11 +19964,6 @@ <title><function>pg_control_init</function> Columns</title>
<entry><type>integer</type></entry>
</row>
- <row>
- <entry><literal>float4_pass_by_value</literal></entry>
- <entry><type>boolean</type></entry>
- </row>
-
<row>
<entry><literal>float8_pass_by_value</literal></entry>
<entry><type>boolean</type></entry>
diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index d8494e293b..b4d222295e 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -1204,18 +1204,6 @@ <title>Anti-Features</title>
</listitem>
</varlistentry>
- <varlistentry>
- <term><option>--disable-float4-byval</option></term>
- <listitem>
- <para>
- Disable passing float4 values <quote>by value</quote>, causing them
- to be passed <quote>by reference</quote> instead. This option costs
- performance, but may be needed for compatibility with very old
- user-defined functions written in C.
- </para>
- </listitem>
- </varlistentry>
-
<varlistentry>
<term><option>--disable-float8-byval</option></term>
<listitem>
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index 9dfa0ddfbb..4af418287d 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -879,11 +879,6 @@ index_store_float8_orderby_distances(IndexScanDesc scan, Oid *orderByTypes,
else if (orderByTypes[i] == FLOAT4OID)
{
/* convert distance function's result to ORDER BY type */
-#ifndef USE_FLOAT4_BYVAL
- /* must free any old value to avoid memory leakage */
- if (!scan->xs_orderbynulls[i])
- pfree(DatumGetPointer(scan->xs_orderbyvals[i]));
-#endif
if (distances && !distances[i].isnull)
{
scan->xs_orderbyvals[i] = Float4GetDatum((float4) distances[i].value);
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 2e3cc51006..68134c5463 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -4516,7 +4516,6 @@ WriteControlFile(void)
ControlFile->toast_max_chunk_size = TOAST_MAX_CHUNK_SIZE;
ControlFile->loblksize = LOBLKSIZE;
- ControlFile->float4ByVal = FLOAT4PASSBYVAL;
ControlFile->float8ByVal = FLOAT8PASSBYVAL;
/* Contents are protected with a CRC */
@@ -4720,22 +4719,6 @@ ReadControlFile(void)
ControlFile->loblksize, (int) LOBLKSIZE),
errhint("It looks like you need to recompile or initdb.")));
-#ifdef USE_FLOAT4_BYVAL
- if (ControlFile->float4ByVal != true)
- ereport(FATAL,
- (errmsg("database files are incompatible with server"),
- errdetail("The database cluster was initialized without USE_FLOAT4_BYVAL"
- " but the server was compiled with USE_FLOAT4_BYVAL."),
- errhint("It looks like you need to recompile or initdb.")));
-#else
- if (ControlFile->float4ByVal != false)
- ereport(FATAL,
- (errmsg("database files are incompatible with server"),
- errdetail("The database cluster was initialized with USE_FLOAT4_BYVAL"
- " but the server was compiled without USE_FLOAT4_BYVAL."),
- errhint("It looks like you need to recompile or initdb.")));
-#endif
-
#ifdef USE_FLOAT8_BYVAL
if (ControlFile->float8ByVal != true)
ereport(FATAL,
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 9238fbe98d..8ea033610d 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -111,7 +111,7 @@ static const struct typinfo TypInfo[] = {
F_INT2IN, F_INT2OUT},
{"int4", INT4OID, 0, 4, true, 'i', 'p', InvalidOid,
F_INT4IN, F_INT4OUT},
- {"float4", FLOAT4OID, 0, 4, FLOAT4PASSBYVAL, 'i', 'p', InvalidOid,
+ {"float4", FLOAT4OID, 0, 4, true, 'i', 'p', InvalidOid,
F_FLOAT4IN, F_FLOAT4OUT},
{"name", NAMEOID, CHAROID, NAMEDATALEN, false, 'c', 'p', C_COLLATION_OID,
F_NAMEIN, F_NAMEOUT},
diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl
index 201d12d358..6eff045bd9 100644
--- a/src/backend/catalog/genbki.pl
+++ b/src/backend/catalog/genbki.pl
@@ -890,7 +890,7 @@ sub morph_row_for_schemapg
}
# Expand booleans from 'f'/'t' to 'false'/'true'.
- # Some values might be other macros (eg FLOAT4PASSBYVAL),
+ # Some values might be other macros (eg FLOAT8PASSBYVAL),
# don't change.
elsif ($atttype eq 'bool')
{
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 7accb950eb..71372ceb16 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -1496,7 +1496,7 @@ update_attstats(Oid relid, bool inh, int natts, VacAttrStats **vacattrstats)
/* XXX knows more than it should about type float4: */
arry = construct_array(numdatums, nnum,
FLOAT4OID,
- sizeof(float4), FLOAT4PASSBYVAL, 'i');
+ sizeof(float4), true, 'i');
values[i++] = PointerGetDatum(arry); /* stanumbersN */
}
else
diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c
index be684786d6..b67d68f8dd 100644
--- a/src/backend/utils/fmgr/dfmgr.c
+++ b/src/backend/utils/fmgr/dfmgr.c
@@ -365,15 +365,6 @@ incompatible_module_error(const char *libname,
magic_data.namedatalen,
module_magic_data->namedatalen);
}
- if (module_magic_data->float4byval != magic_data.float4byval)
- {
- if (details.len)
- appendStringInfoChar(&details, '\n');
- appendStringInfo(&details,
- _("Server has FLOAT4PASSBYVAL = %s, library has %s."),
- magic_data.float4byval ? "true" : "false",
- module_magic_data->float4byval ? "true" : "false");
- }
if (module_magic_data->float8byval != magic_data.float8byval)
{
if (details.len)
diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c
index 099ebd779b..2ce7a866c9 100644
--- a/src/backend/utils/fmgr/fmgr.c
+++ b/src/backend/utils/fmgr/fmgr.c
@@ -1683,7 +1683,7 @@ OidSendFunctionCall(Oid functionId, Datum val)
/*-------------------------------------------------------------------------
* Support routines for standard maybe-pass-by-reference datatypes
*
- * int8, float4, and float8 can be passed by value if Datum is wide enough.
+ * int8 and float8 can be passed by value if Datum is wide enough.
* (For backwards-compatibility reasons, we allow pass-by-ref to be chosen
* at compile time even if pass-by-val is possible.)
*
@@ -1703,21 +1703,6 @@ Int64GetDatum(int64 X)
*retval = X;
return PointerGetDatum(retval);
}
-#endif /* USE_FLOAT8_BYVAL */
-
-#ifndef USE_FLOAT4_BYVAL
-
-Datum
-Float4GetDatum(float4 X)
-{
- float4 *retval = (float4 *) palloc(sizeof(float4));
-
- *retval = X;
- return PointerGetDatum(retval);
-}
-#endif
-
-#ifndef USE_FLOAT8_BYVAL
Datum
Float8GetDatum(float8 X)
@@ -1727,7 +1712,7 @@ Float8GetDatum(float8 X)
*retval = X;
return PointerGetDatum(retval);
}
-#endif
+#endif /* USE_FLOAT8_BYVAL */
/*-------------------------------------------------------------------------
diff --git a/src/backend/utils/misc/pg_controldata.c b/src/backend/utils/misc/pg_controldata.c
index b42921800b..4d6282a802 100644
--- a/src/backend/utils/misc/pg_controldata.c
+++ b/src/backend/utils/misc/pg_controldata.c
@@ -264,8 +264,8 @@ pg_control_recovery(PG_FUNCTION_ARGS)
Datum
pg_control_init(PG_FUNCTION_ARGS)
{
- Datum values[12];
- bool nulls[12];
+ Datum values[11];
+ bool nulls[11];
TupleDesc tupdesc;
HeapTuple htup;
ControlFileData *ControlFile;
@@ -294,11 +294,9 @@ pg_control_init(PG_FUNCTION_ARGS)
INT4OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 9, "large_object_chunk_size",
INT4OID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 10, "float4_pass_by_value",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 10, "float8_pass_by_value",
BOOLOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 11, "float8_pass_by_value",
- BOOLOID, -1, 0);
- TupleDescInitEntry(tupdesc, (AttrNumber) 12, "data_page_checksum_version",
+ TupleDescInitEntry(tupdesc, (AttrNumber) 11, "data_page_checksum_version",
INT4OID, -1, 0);
tupdesc = BlessTupleDesc(tupdesc);
@@ -335,15 +333,12 @@ pg_control_init(PG_FUNCTION_ARGS)
values[8] = Int32GetDatum(ControlFile->loblksize);
nulls[8] = false;
- values[9] = BoolGetDatum(ControlFile->float4ByVal);
+ values[9] = BoolGetDatum(ControlFile->float8ByVal);
nulls[9] = false;
- values[10] = BoolGetDatum(ControlFile->float8ByVal);
+ values[10] = Int32GetDatum(ControlFile->data_checksum_version);
nulls[10] = false;
- values[11] = Int32GetDatum(ControlFile->data_checksum_version);
- nulls[11] = false;
-
htup = heap_form_tuple(tupdesc, values, nulls);
PG_RETURN_DATUM(HeapTupleGetDatum(htup));
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 88a261d9bd..1f6d8939be 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -1399,9 +1399,6 @@ bootstrap_template1(void)
bki_lines = replace_token(bki_lines, "ALIGNOF_POINTER",
(sizeof(Pointer) == 4) ? "i" : "d");
- bki_lines = replace_token(bki_lines, "FLOAT4PASSBYVAL",
- FLOAT4PASSBYVAL ? "true" : "false");
-
bki_lines = replace_token(bki_lines, "FLOAT8PASSBYVAL",
FLOAT8PASSBYVAL ? "true" : "false");
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index b14767f8b6..19e21ab491 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -327,8 +327,6 @@ main(int argc, char *argv[])
/* This is no longer configurable, but users may still expect to see it: */
printf(_("Date/time type storage: %s\n"),
_("64-bit integers"));
- printf(_("Float4 argument passing: %s\n"),
- (ControlFile->float4ByVal ? _("by value") : _("by reference")));
printf(_("Float8 argument passing: %s\n"),
(ControlFile->float8ByVal ? _("by value") : _("by reference")));
printf(_("Data page checksum version: %u\n"),
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index c4ee0168a9..2e286f6339 100644
--- a/src/bin/pg_resetwal/pg_resetwal.c
+++ b/src/bin/pg_resetwal/pg_resetwal.c
@@ -722,7 +722,6 @@ GuessControlValues(void)
ControlFile.indexMaxKeys = INDEX_MAX_KEYS;
ControlFile.toast_max_chunk_size = TOAST_MAX_CHUNK_SIZE;
ControlFile.loblksize = LOBLKSIZE;
- ControlFile.float4ByVal = FLOAT4PASSBYVAL;
ControlFile.float8ByVal = FLOAT8PASSBYVAL;
/*
@@ -801,8 +800,6 @@ PrintControlValues(bool guessed)
/* This is no longer configurable, but users may still expect to see it: */
printf(_("Date/time type storage: %s\n"),
_("64-bit integers"));
- printf(_("Float4 argument passing: %s\n"),
- (ControlFile.float4ByVal ? _("by value") : _("by reference")));
printf(_("Float8 argument passing: %s\n"),
(ControlFile.float8ByVal ? _("by value") : _("by reference")));
printf(_("Data page checksum version: %u\n"),
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
index 1f6de76e9c..1c75b1b4b5 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 201910251
+#define CATALOG_VERSION_NO 201911021
#endif
diff --git a/src/include/catalog/pg_control.h b/src/include/catalog/pg_control.h
index ff98d9e91a..4e5077078d 100644
--- a/src/include/catalog/pg_control.h
+++ b/src/include/catalog/pg_control.h
@@ -22,7 +22,7 @@
/* Version identifier for this pg_control format */
-#define PG_CONTROL_VERSION 1201
+#define PG_CONTROL_VERSION 1202
/* Nonce key length, see below */
#define MOCK_AUTH_NONCE_LEN 32
@@ -214,8 +214,6 @@ typedef struct ControlFileData
uint32 toast_max_chunk_size; /* chunk size in TOAST tables */
uint32 loblksize; /* chunk size in pg_largeobject */
- /* flags indicating pass-by-value status of various types */
- bool float4ByVal; /* float4 pass-by-value? */
bool float8ByVal; /* float8, int8, etc pass-by-value? */
/* Are data pages protected by checksums? Zero if no checksum version */
diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 58ea5b982b..970b08e4f0 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -10660,9 +10660,9 @@
descr => 'pg_controldata init state information as a function',
proname => 'pg_control_init', provolatile => 'v', prorettype => 'record',
proargtypes => '',
- proallargtypes => '{int4,int4,int4,int4,int4,int4,int4,int4,int4,bool,bool,int4}',
- proargmodes => '{o,o,o,o,o,o,o,o,o,o,o,o}',
- proargnames => '{max_data_alignment,database_block_size,blocks_per_segment,wal_block_size,bytes_per_wal_segment,max_identifier_length,max_index_columns,max_toast_chunk_size,large_object_chunk_size,float4_pass_by_value,float8_pass_by_value,data_page_checksum_version}',
+ proallargtypes => '{int4,int4,int4,int4,int4,int4,int4,int4,int4,bool,int4}',
+ proargmodes => '{o,o,o,o,o,o,o,o,o,o,o}',
+ proargnames => '{max_data_alignment,database_block_size,blocks_per_segment,wal_block_size,bytes_per_wal_segment,max_identifier_length,max_index_columns,max_toast_chunk_size,large_object_chunk_size,float8_pass_by_value,data_page_checksum_version}',
prosrc => 'pg_control_init' },
# collation management functions
diff --git a/src/include/catalog/pg_type.dat b/src/include/catalog/pg_type.dat
index be49e00114..d9b35af914 100644
--- a/src/include/catalog/pg_type.dat
+++ b/src/include/catalog/pg_type.dat
@@ -215,7 +215,7 @@
{ oid => '700', array_type_oid => '1021',
descr => 'single-precision floating point number, 4-byte storage',
- typname => 'float4', typlen => '4', typbyval => 'FLOAT4PASSBYVAL',
+ typname => 'float4', typlen => '4', typbyval => 't',
typcategory => 'N', typinput => 'float4in', typoutput => 'float4out',
typreceive => 'float4recv', typsend => 'float4send', typalign => 'i' },
{ oid => '701', array_type_oid => '1022',
diff --git a/src/include/fmgr.h b/src/include/fmgr.h
index 29ae4674cc..724ee73bde 100644
--- a/src/include/fmgr.h
+++ b/src/include/fmgr.h
@@ -446,7 +446,6 @@ typedef struct
int funcmaxargs; /* FUNC_MAX_ARGS */
int indexmaxkeys; /* INDEX_MAX_KEYS */
int namedatalen; /* NAMEDATALEN */
- int float4byval; /* FLOAT4PASSBYVAL */
int float8byval; /* FLOAT8PASSBYVAL */
} Pg_magic_struct;
@@ -458,7 +457,6 @@ typedef struct
FUNC_MAX_ARGS, \
INDEX_MAX_KEYS, \
NAMEDATALEN, \
- FLOAT4PASSBYVAL, \
FLOAT8PASSBYVAL \
}
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 939245db39..6d363a157e 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -70,9 +70,6 @@
MSVC and with C++ compilers. */
#undef FLEXIBLE_ARRAY_MEMBER
-/* float4 values are passed by value if 'true', by reference if 'false' */
-#undef FLOAT4PASSBYVAL
-
/* float8, int8, and related values are passed by value if 'true', by
reference if 'false' */
#undef FLOAT8PASSBYVAL
@@ -898,10 +895,6 @@
/* Define to use /dev/urandom for random number generation */
#undef USE_DEV_URANDOM
-/* Define to 1 if you want float4 values to be passed by value.
- (--enable-float4-byval) */
-#undef USE_FLOAT4_BYVAL
-
/* Define to 1 if you want float8, int8, etc values to be passed by value.
(--enable-float8-byval) */
#undef USE_FLOAT8_BYVAL
diff --git a/src/include/postgres.h b/src/include/postgres.h
index 057a3413ac..f5b7c52f8a 100644
--- a/src/include/postgres.h
+++ b/src/include/postgres.h
@@ -659,11 +659,7 @@ extern Datum Int64GetDatum(int64 X);
/*
* DatumGetFloat4
* Returns 4-byte floating point value of a datum.
- *
- * Note: this macro hides whether float4 is pass by value or by reference.
*/
-
-#ifdef USE_FLOAT4_BYVAL
static inline float4
DatumGetFloat4(Datum X)
{
@@ -676,18 +672,11 @@ DatumGetFloat4(Datum X)
myunion.value = DatumGetInt32(X);
return myunion.retval;
}
-#else
-#define DatumGetFloat4(X) (* ((float4 *) DatumGetPointer(X)))
-#endif
/*
* Float4GetDatum
* Returns datum representation for a 4-byte floating point number.
- *
- * Note: if float4 is pass by reference, this function returns a reference
- * to palloc'd space.
*/
-#ifdef USE_FLOAT4_BYVAL
static inline Datum
Float4GetDatum(float4 X)
{
@@ -700,9 +689,6 @@ Float4GetDatum(float4 X)
myunion.value = X;
return Int32GetDatum(myunion.retval);
}
-#else
-extern Datum Float4GetDatum(float4 X);
-#endif
/*
* DatumGetFloat8
@@ -757,10 +743,9 @@ extern Datum Float8GetDatum(float8 X);
/*
* Int64GetDatumFast
* Float8GetDatumFast
- * Float4GetDatumFast
*
* These macros are intended to allow writing code that does not depend on
- * whether int64, float8, float4 are pass-by-reference types, while not
+ * whether int64 and float8 are pass-by-reference types, while not
* sacrificing performance when they are. The argument must be a variable
* that will exist and have the same value for as long as the Datum is needed.
* In the pass-by-ref case, the address of the variable is taken to use as
@@ -776,10 +761,4 @@ extern Datum Float8GetDatum(float8 X);
#define Float8GetDatumFast(X) PointerGetDatum(&(X))
#endif
-#ifdef USE_FLOAT4_BYVAL
-#define Float4GetDatumFast(X) Float4GetDatum(X)
-#else
-#define Float4GetDatumFast(X) PointerGetDatum(&(X))
-#endif
-
#endif /* POSTGRES_H */
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index a6958273ac..0aba79843c 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -31,8 +31,6 @@ sub _new
$self->DeterminePlatform();
my $bits = $self->{platform} eq 'Win32' ? 32 : 64;
- $options->{float4byval} = 1
- unless exists $options->{float4byval};
$options->{float8byval} = ($bits == 64)
unless exists $options->{float8byval};
die "float8byval not permitted on 32 bit platforms"
@@ -209,15 +207,6 @@ sub GenerateFiles
print $o "#define XLOG_BLCKSZ ",
1024 * $self->{options}->{wal_blocksize}, "\n";
- if ($self->{options}->{float4byval})
- {
- print $o "#define USE_FLOAT4_BYVAL 1\n";
- print $o "#define FLOAT4PASSBYVAL true\n";
- }
- else
- {
- print $o "#define FLOAT4PASSBYVAL false\n";
- }
if ($self->{options}->{float8byval})
{
print $o "#define USE_FLOAT8_BYVAL 1\n";
diff --git a/src/tools/msvc/config_default.pl b/src/tools/msvc/config_default.pl
index 043df4c5e8..62188c78e7 100644
--- a/src/tools/msvc/config_default.pl
+++ b/src/tools/msvc/config_default.pl
@@ -4,7 +4,6 @@
our $config = {
asserts => 0, # --enable-cassert
- # float4byval=>1, # --disable-float4-byval, on by default
# float8byval=> $platformbits == 64, # --disable-float8-byval,
# off by default on 32 bit platforms, on by default on 64 bit platforms
base-commit: dc816e5815913e2b2ae2327a4d3e4d4416ed6898
--
2.23.0
On 2019-11-01 15:41, Robert Haas wrote:
On a related note, why do we store typbyval in the catalog anyway
instead of inferring it from typlen and maybe typalign? It seems like
a bad idea to record on disk the way we pass around values in memory,
because it means that a change to how values are passed around in
memory has ramifications for on-disk compatibility.
This sounds interesting. It would remove a pg_upgrade hazard (in the
long run).
There is some backward compatibility to be concerned about. This change
would require extension authors to change their code to insert #ifdef
USE_FLOAT8_BYVAL or similar, where currently their code might only
support one method or the other.
rhaas=# select typname, typlen, typbyval, typalign from pg_type where
typlen in (1,2,4,8) != typbyval;
There are also typlen=6 types. Who knew. ;-)
typname | typlen | typbyval | typalign
----------+--------+----------+----------
macaddr8 | 8 | f | i
(1 row)
This might be a case of the above issue: It's easier to just make it
pass by reference always than deal with a bunch of #ifdefs.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
On 2019-11-01 15:41, Robert Haas wrote:
On a related note, why do we store typbyval in the catalog anyway
instead of inferring it from typlen and maybe typalign? It seems like
a bad idea to record on disk the way we pass around values in memory,
because it means that a change to how values are passed around in
memory has ramifications for on-disk compatibility.
This sounds interesting. It would remove a pg_upgrade hazard (in the
long run).
There is some backward compatibility to be concerned about.
Yeah. The point here is that typbyval specifies what the C functions
concerned with the datatype are expecting. We can't just up and say
"we're going to decide that for you".
I do get the point that supporting two different typbyval options
for float8 and related types is a nontrivial cost.
regards, tom lane
Hi,
On 2019-11-02 08:46:12 +0100, Peter Eisentraut wrote:
On 2019-11-01 15:41, Robert Haas wrote:
On a related note, why do we store typbyval in the catalog anyway
instead of inferring it from typlen and maybe typalign? It seems like
a bad idea to record on disk the way we pass around values in memory,
because it means that a change to how values are passed around in
memory has ramifications for on-disk compatibility.This sounds interesting. It would remove a pg_upgrade hazard (in the long
run).There is some backward compatibility to be concerned about. This change
would require extension authors to change their code to insert #ifdef
USE_FLOAT8_BYVAL or similar, where currently their code might only support
one method or the other.
I think we really ought to remove the difference behind macros. That is,
for types that could be either, provide macros that fetch function
arguments into local memory, independent of whether the argument is a
byval or byref type. I.e. instead of having separate #ifdef
USE_FLOAT8_BYVALs for DatumGetFloat8(), DatumGetInt64(), ... we should
provide that logic in one centralized set of macros.
The fact that USE_FLOAT8_BYVAL has to creep into various functions imo
is the reasons why people are unhappy about it.
One way to do this would be something roughly like this sketch:
/* allow to force types to be byref, for testing purposes */
#if USE_FLOAT8_BYVAL
#define DatumForTypeIsByval(type) (sizeof(type) <= SIZEOF_DATUM)
#else
#define DatumForTypeIsByval(type) (sizeof(type) <= sizeof(int))
#endif
/* yes, I dream of being C++ once grown up */
#define DefineSmallFixedWidthDatumTypeConversions(type, TypeToDatumName, DatumToTypeName) \
static inline type \
TypeToDatumName (type value) \
{ \
if (DatumForTypeIsByval(type)) \
{ \
Datum tmp; \
\
/* ensure correct conversion, consider e.g. float */ \
memcpy(&tmp, &value, sizeof(type)); \
\
return tmp; \
} \
else \
{ \
type *tmp = (type *) palloc(sizeof(datum)); \
*tmp = value;
return PointerGetDatum(tmp); \
} \
} \
\
static inline type \
DatumToTypeName (Datum datum) \
{ \
if (DatumForTypeIsByval(type)) \
{ \
type tmp; \
\
/* ensure correct conversion */ \
memcpy(&tmp, &datum, sizeof(type)); \
\
return tmp; \
} \
else \
return *(type *) DatumGetPointer(type); \
} \
And then have
DefineSmallFixedWidthDatumTypeConversions(
float8,
Float8GetDatum,
DatumGetFloat8);
DefineSmallFixedWidthDatumTypeConversions(
int64,
Int64GetDatum,
DatumGetInt64);
And now also
DefineSmallFixedWidthDatumTypeConversions(
macaddr,
Macaddr8GetDatum,
DatumGetMacaddr8);
(there's probably plenty of bugs in the above, it's just a sketch)
We don't have to break types / extensions with inferring byval for fixed
width types. Instead we can change CREATE TYPE's PASSEDBYVALUE to accept
an optional parameter 'auto', allowing to opt in.
rhaas=# select typname, typlen, typbyval, typalign from pg_type where
typlen in (1,2,4,8) != typbyval;There are also typlen=6 types. Who knew. ;-)
There's a recent thread about them :)
typname | typlen | typbyval | typalign
----------+--------+----------+----------
macaddr8 | 8 | f | i
(1 row)This might be a case of the above issue: It's easier to just make it pass by
reference always than deal with a bunch of #ifdefs.
Indeed. And that's a bad sign imo.
Greetings,
Andres Freund
On Fri, Nov 01, 2019 at 09:41:58PM -0700, Peter Geoghegan wrote:
On Fri, Nov 1, 2019 at 7:47 PM Michael Paquier <michael@paquier.xyz> wrote:
I don't agree as well with the line of arguments to just remove 32b
support.Clearly you didn't read what I actually wrote, Michael.
Sorry, that was an misunderstanding from my side.
--
Michael
On Sat, Nov 2, 2019 at 8:00 PM Andres Freund <andres@anarazel.de> wrote:
I think we really ought to remove the difference behind macros. That is,
for types that could be either, provide macros that fetch function
arguments into local memory, independent of whether the argument is a
byval or byref type. I.e. instead of having separate #ifdef
USE_FLOAT8_BYVALs for DatumGetFloat8(), DatumGetInt64(), ... we should
provide that logic in one centralized set of macros.The fact that USE_FLOAT8_BYVAL has to creep into various functions imo
is the reasons why people are unhappy about it.
I think I'm *more* unhappy about the fact that it affects a bunch of
things that are not about whether float8 is passed byval. I mean, you
mention DatumGetInt64() above, but why in the world does a setting
with "float8" in the name affect how we pass int64? The thing is like
kudzu, getting into all sorts of things that it has no business
affecting - at least if you judge by the name - and for no really
clear reason.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
On 2019-11-02 08:39, Peter Eisentraut wrote:
On 2019-10-31 14:36, Tom Lane wrote:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
float4 is now always pass-by-value; the pass-by-reference code path is
completely removed.I think this is OK.
OK, here is a patch for just this part, and we can continue the
discussion on the rest in the meantime.
I have committed this part.
I will rebase and continue developing the rest of the patches based on
the discussion so far.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
On Thu, Nov 21, 2019 at 07:20:28PM +0100, Peter Eisentraut wrote:
I have committed this part.
I will rebase and continue developing the rest of the patches based on the
discussion so far.
Based on that I am marking the patch as committed in the CF. The rest
of the patch set could have a new entry.
--
Michael
My revised proposal is to remove --disable-float8-byval as a configure
option but keep it as an option in pg_config_manual.h. It is no longer
useful as a user-facing option, but as was pointed out, it is somewhat
useful for developers, so pg_config_manual.h seems like the right place.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
v3-0001-Move-configure-disable-float8-byval-to-pg_config_.patchtext/plain; charset=UTF-8; name=v3-0001-Move-configure-disable-float8-byval-to-pg_config_.patch; x-mac-creator=0; x-mac-type=0Download
From 8ae788d3dd6bfea1b386955b8f161897691d6100 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Tue, 26 Nov 2019 21:15:25 +0100
Subject: [PATCH v3] Move configure --disable-float8-byval to
pg_config_manual.h
This build option was once useful to maintain compatibility with
version-0 functions, but those are no longer supported, so this option
is no longer useful for end users. We keep the option available to
developers in pg_config_manual.h so that it is easy to test the
pass-by-reference code paths without having to fire up a 32-bit
machine.
Discussion: https://www.postgresql.org/message-id/flat/f3e1e576-2749-bbd7-2d57-3f9dcf75255a@2ndquadrant.com
---
configure | 76 --------------------------------
configure.in | 23 ----------
doc/src/sgml/installation.sgml | 16 -------
src/include/c.h | 6 +++
src/include/pg_config.h.in | 8 ----
src/include/pg_config_manual.h | 13 ++++++
src/tools/msvc/Solution.pm | 15 -------
src/tools/msvc/config_default.pl | 3 --
8 files changed, 19 insertions(+), 141 deletions(-)
diff --git a/configure b/configure
index b06a95dabc..1d88983b34 100755
--- a/configure
+++ b/configure
@@ -866,7 +866,6 @@ with_system_tzdata
with_zlib
with_gnu_ld
enable_largefile
-enable_float8_byval
'
ac_precious_vars='build_alias
host_alias
@@ -1524,7 +1523,6 @@ Optional Features:
--enable-cassert enable assertion checks (for debugging)
--disable-thread-safety disable thread-safety in client libraries
--disable-largefile omit support for large files
- --disable-float8-byval disable float8 passed by value
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
@@ -16745,80 +16743,6 @@ _ACEOF
-# Decide whether float8 is passed by value.
-# Note: this setting also controls int8 and related types such as timestamp.
-# If sizeof(Datum) >= 8, this is user-selectable, enabled by default.
-# If not, trying to select it is an error.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build with float8 passed by value" >&5
-$as_echo_n "checking whether to build with float8 passed by value... " >&6; }
-if test $ac_cv_sizeof_void_p -ge 8 ; then
-
-
-# Check whether --enable-float8-byval was given.
-if test "${enable_float8_byval+set}" = set; then :
- enableval=$enable_float8_byval;
- case $enableval in
- yes)
- :
- ;;
- no)
- :
- ;;
- *)
- as_fn_error $? "no argument expected for --enable-float8-byval option" "$LINENO" 5
- ;;
- esac
-
-else
- enable_float8_byval=yes
-
-fi
-
-
-else
-
-
-# Check whether --enable-float8-byval was given.
-if test "${enable_float8_byval+set}" = set; then :
- enableval=$enable_float8_byval;
- case $enableval in
- yes)
- :
- ;;
- no)
- :
- ;;
- *)
- as_fn_error $? "no argument expected for --enable-float8-byval option" "$LINENO" 5
- ;;
- esac
-
-else
- enable_float8_byval=no
-
-fi
-
-
- if test "$enable_float8_byval" = yes ; then
- as_fn_error $? "--enable-float8-byval is not supported on 32-bit platforms." "$LINENO" 5
- fi
-fi
-if test "$enable_float8_byval" = yes ; then
-
-$as_echo "#define USE_FLOAT8_BYVAL 1" >>confdefs.h
-
- float8passbyval=true
-else
- float8passbyval=false
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_float8_byval" >&5
-$as_echo "$enable_float8_byval" >&6; }
-
-cat >>confdefs.h <<_ACEOF
-#define FLOAT8PASSBYVAL $float8passbyval
-_ACEOF
-
-
# Determine memory alignment requirements for the basic C data types.
# The cast to long int works around a bug in the HP C Compiler,
diff --git a/configure.in b/configure.in
index 56a177ba10..a2cb20b5e3 100644
--- a/configure.in
+++ b/configure.in
@@ -1941,29 +1941,6 @@ AC_CHECK_SIZEOF([void *])
AC_CHECK_SIZEOF([size_t])
AC_CHECK_SIZEOF([long])
-# Decide whether float8 is passed by value.
-# Note: this setting also controls int8 and related types such as timestamp.
-# If sizeof(Datum) >= 8, this is user-selectable, enabled by default.
-# If not, trying to select it is an error.
-AC_MSG_CHECKING([whether to build with float8 passed by value])
-if test $ac_cv_sizeof_void_p -ge 8 ; then
- PGAC_ARG_BOOL(enable, float8-byval, yes, [disable float8 passed by value])
-else
- PGAC_ARG_BOOL(enable, float8-byval, no, [disable float8 passed by value])
- if test "$enable_float8_byval" = yes ; then
- AC_MSG_ERROR([--enable-float8-byval is not supported on 32-bit platforms.])
- fi
-fi
-if test "$enable_float8_byval" = yes ; then
- AC_DEFINE([USE_FLOAT8_BYVAL], 1,
- [Define to 1 if you want float8, int8, etc values to be passed by value. (--enable-float8-byval)])
- float8passbyval=true
-else
- float8passbyval=false
-fi
-AC_MSG_RESULT([$enable_float8_byval])
-AC_DEFINE_UNQUOTED([FLOAT8PASSBYVAL], [$float8passbyval], [float8, int8, and related values are passed by value if 'true', by reference if 'false'])
-
# Determine memory alignment requirements for the basic C data types.
AC_CHECK_ALIGNOF(short)
diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index b4d222295e..9c10a897f1 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -1204,22 +1204,6 @@ <title>Anti-Features</title>
</listitem>
</varlistentry>
- <varlistentry>
- <term><option>--disable-float8-byval</option></term>
- <listitem>
- <para>
- Disable passing float8 values <quote>by value</quote>, causing them
- to be passed <quote>by reference</quote> instead. This option costs
- performance, but may be needed for compatibility with very old
- user-defined functions written in C.
- Note that this option affects not only float8, but also int8 and some
- related types such as timestamp.
- On 32-bit platforms, <option>--disable-float8-byval</option> is the default
- and it is not allowed to select <option>--enable-float8-byval</option>.
- </para>
- </listitem>
- </varlistentry>
-
<varlistentry>
<term><option>--disable-spinlocks</option></term>
<listitem>
diff --git a/src/include/c.h b/src/include/c.h
index 802a731267..00e41ac546 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -491,6 +491,12 @@ typedef signed int Offset;
typedef float float4;
typedef double float8;
+#ifdef USE_FLOAT8_BYVAL
+#define FLOAT8PASSBYVAL true
+#else
+#define FLOAT8PASSBYVAL false
+#endif
+
/*
* Oid, RegProcedure, TransactionId, SubTransactionId, MultiXactId,
* CommandId
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 6f8549bc03..c208dcdfc7 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -70,10 +70,6 @@
MSVC and with C++ compilers. */
#undef FLEXIBLE_ARRAY_MEMBER
-/* float8, int8, and related values are passed by value if 'true', by
- reference if 'false' */
-#undef FLOAT8PASSBYVAL
-
/* Define to 1 if gettimeofday() takes only 1 argument. */
#undef GETTIMEOFDAY_1ARG
@@ -898,10 +894,6 @@
/* Define to use /dev/urandom for random number generation */
#undef USE_DEV_URANDOM
-/* Define to 1 if you want float8, int8, etc values to be passed by value.
- (--enable-float8-byval) */
-#undef USE_FLOAT8_BYVAL
-
/* Define to build with ICU support. (--with-icu) */
#undef USE_ICU
diff --git a/src/include/pg_config_manual.h b/src/include/pg_config_manual.h
index 743401cb96..61b667d166 100644
--- a/src/include/pg_config_manual.h
+++ b/src/include/pg_config_manual.h
@@ -56,6 +56,19 @@
*/
#define PARTITION_MAX_KEYS 32
+/*
+ * Decide whether built-in 8-byte types, including float8, int8, and
+ * timestamp, are passed by value. This is on by default if sizeof(Datum) >=
+ * 8 (that is, on 64-bit platforms). If sizeof(Datum) < 8 (32-bit platforms),
+ * this must be off. We keep this here as an option so that it is easy to
+ * test the pass-by-reference code paths on 64-bit platforms.
+ *
+ * Changing this requires an initdb.
+ */
+#if SIZEOF_VOID_P >= 8
+#define USE_FLOAT8_BYVAL 1
+#endif
+
/*
* When we don't have native spinlocks, we use semaphores to simulate them.
* Decreasing this value reduces consumption of OS resources; increasing it
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index e4ea62e80b..5f72530c72 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -29,12 +29,7 @@ sub _new
bless($self, $classname);
$self->DeterminePlatform();
- my $bits = $self->{platform} eq 'Win32' ? 32 : 64;
- $options->{float8byval} = ($bits == 64)
- unless exists $options->{float8byval};
- die "float8byval not permitted on 32 bit platforms"
- if $options->{float8byval} && $bits == 32;
if ($options->{xslt} && !$options->{xml})
{
die "XSLT requires XML\n";
@@ -207,16 +202,6 @@ sub GenerateFiles
print $o "#define XLOG_BLCKSZ ",
1024 * $self->{options}->{wal_blocksize}, "\n";
- if ($self->{options}->{float8byval})
- {
- print $o "#define USE_FLOAT8_BYVAL 1\n";
- print $o "#define FLOAT8PASSBYVAL true\n";
- }
- else
- {
- print $o "#define FLOAT8PASSBYVAL false\n";
- }
-
if ($self->{options}->{uuid})
{
print $o "#define HAVE_UUID_OSSP\n";
diff --git a/src/tools/msvc/config_default.pl b/src/tools/msvc/config_default.pl
index 62188c78e7..2ef2cfc4e9 100644
--- a/src/tools/msvc/config_default.pl
+++ b/src/tools/msvc/config_default.pl
@@ -5,9 +5,6 @@
our $config = {
asserts => 0, # --enable-cassert
- # float8byval=> $platformbits == 64, # --disable-float8-byval,
- # off by default on 32 bit platforms, on by default on 64 bit platforms
-
# blocksize => 8, # --with-blocksize, 8kB by default
# wal_blocksize => 8, # --with-wal-blocksize, 8kB by default
ldap => 1, # --with-ldap
base-commit: 0dc8ead46363fec6f621a12c7e1f889ba73b55a9
--
2.24.0
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
My revised proposal is to remove --disable-float8-byval as a configure
option but keep it as an option in pg_config_manual.h. It is no longer
useful as a user-facing option, but as was pointed out, it is somewhat
useful for developers, so pg_config_manual.h seems like the right place.
OK, works for me.
regards, tom lane
On 2019-11-26 21:33, Tom Lane wrote:
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
My revised proposal is to remove --disable-float8-byval as a configure
option but keep it as an option in pg_config_manual.h. It is no longer
useful as a user-facing option, but as was pointed out, it is somewhat
useful for developers, so pg_config_manual.h seems like the right place.OK, works for me.
done
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
On Fri, Nov 1, 2019 at 1:19 PM Robert Haas <robertmhaas@gmail.com> wrote:
On Fri, Nov 1, 2019 at 3:15 PM Peter Geoghegan <pg@bowt.ie> wrote:
I don't think that those two things are equivalent at all. There may
even be workloads that will benefit when run on 32-bit hardware.
Having to palloc() and pfree() with 8 byte integers is probably very
slow.Yeah! I mean, users who are using only 4-byte or smaller pass-by-value
quantities will be harmed, especially in cases where they are storing
a lot of them at the same time (e.g. sorting) and especially if they
double their space consumption and run out of their very limited
supply of memory.
Apparently Linux has almost no upstream resources for testing 32-bit
x86, and it shows:
https://lwn.net/ml/oss-security/CALCETrW1z0gCLFJz-1Jwj_wcT3+axXkP_wOCxY8JkbSLzV80GA@mail.gmail.com/
I think that this kind of thing argues for minimizing the amount of
code that can only be tested on a small minority of the computers that
are in general use today. If no Postgres hacker regularly runs the
code, then its chances of having bugs are far higher. Having coverage
in the buildfarm certainly helps, but it's no substitute.
Sticking with the !USE_FLOAT8_BYVAL example, it's easy to imagine
somebody forgetting to add a !USE_FLOAT8_BYVAL block, that contains
the required pfree(). Now you have a memory leak that only affects a
small minority of platforms. How likely is it that buildfarm coverage
will help somebody detect that problem?
--
Peter Geoghegan
On 2019-12-12 23:06, Peter Geoghegan wrote:
Apparently Linux has almost no upstream resources for testing 32-bit
x86, and it shows:
But isn't 32-bit Windows still a thing? Or does that work differently?
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
On Fri, Dec 13, 2019 at 6:33 AM Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:
On 2019-12-12 23:06, Peter Geoghegan wrote:
Apparently Linux has almost no upstream resources for testing 32-bit
x86, and it shows:But isn't 32-bit Windows still a thing? Or does that work differently?
Well, again, I think the proposal here is not get rid of 32-bit
support, but to have less code that only gets regularly tested on
32-bit machines. If we made datums 8 bytes everywhere, we would have
less such code, and very likely fewer bugs. And as pointed out
upthread, although some things might perform worse for the remaining
supply of 32-bit users, other things might perform better. I'm not
100% sure that it would work out to a win overall, but I think there's
a good chance, especially when you factor in the reduced bug surface.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Robert Haas <robertmhaas@gmail.com> writes:
Well, again, I think the proposal here is not get rid of 32-bit
support, but to have less code that only gets regularly tested on
32-bit machines.
That seems like generally a good plan. But as to the specific idea...
If we made datums 8 bytes everywhere, we would have
less such code, and very likely fewer bugs.
... it's not entirely clear to me that it'd be possible to do this
without causing a storm of "cast from pointer to integer of different
size" (and vice versa) warnings on 32-bit machines. That would be a
deal-breaker independently of any performance considerations, IMO.
So if anyone wants to pursue this, finding a way around that might be
the first thing to look at.
regards, tom lane