1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-18 02:02:55 +03:00

Grab the low-hanging fruit from forcing USE_FLOAT8_BYVAL to true.

Remove conditionally-compiled code for the other case.

Replace uses of FLOAT8PASSBYVAL with constant "true", mainly because
it was quite confusing in cases where the type we were dealing with
wasn't float8.

I left the associated pg_control and Pg_magic_struct fields in place.
Perhaps we should get rid of them, but it would save little, so it
doesn't seem worth thinking hard about the compatibility implications.
I just labeled them "vestigial" in places where that seemed helpful.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Discussion: https://postgr.es/m/1749799.1752797397@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2025-08-13 17:18:13 -04:00
parent 6aebedc384
commit ee54046601
22 changed files with 100 additions and 313 deletions

View File

@@ -993,7 +993,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
case INT8OID:
att->attlen = 8;
att->attbyval = FLOAT8PASSBYVAL;
att->attbyval = true;
att->attalign = TYPALIGN_DOUBLE;
att->attstorage = TYPSTORAGE_PLAIN;
att->attcompression = InvalidCompressionMethod;

View File

@@ -986,11 +986,6 @@ index_store_float8_orderby_distances(IndexScanDesc scan, Oid *orderByTypes,
{
if (orderByTypes[i] == FLOAT8OID)
{
#ifndef USE_FLOAT8_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] = Float8GetDatum(distances[i].value);

View File

@@ -4390,7 +4390,7 @@ WriteControlFile(void)
ControlFile->toast_max_chunk_size = TOAST_MAX_CHUNK_SIZE;
ControlFile->loblksize = LOBLKSIZE;
ControlFile->float8ByVal = FLOAT8PASSBYVAL;
ControlFile->float8ByVal = true; /* vestigial */
/*
* Initialize the default 'char' signedness.
@@ -4651,23 +4651,7 @@ ReadControlFile(void)
"LOBLKSIZE", (int) LOBLKSIZE),
errhint("It looks like you need to recompile or initdb.")));
#ifdef USE_FLOAT8_BYVAL
if (ControlFile->float8ByVal != true)
ereport(FATAL,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
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,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
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
Assert(ControlFile->float8ByVal); /* vestigial, not worth an error msg */
wal_segment_size = ControlFile->xlog_seg_size;

View File

@@ -1054,8 +1054,7 @@ sub morph_row_for_schemapg
}
# Expand booleans from 'f'/'t' to 'false'/'true'.
# Some values might be other macros (eg FLOAT8PASSBYVAL),
# don't change.
# Some values might be other macros, if so don't change.
elsif ($atttype eq 'bool')
{
$row->{$attname} = 'true' if $row->{$attname} eq 't';

View File

@@ -410,7 +410,7 @@ build_minmax_path(PlannerInfo *root, MinMaxAggInfo *mminfo,
parse->limitCount = (Node *) makeConst(INT8OID, -1, InvalidOid,
sizeof(int64),
Int64GetDatum(1), false,
FLOAT8PASSBYVAL);
true);
/*
* Generate the best paths for this query, telling query_planner that we

View File

@@ -4915,7 +4915,7 @@ create_partial_distinct_paths(PlannerInfo *root, RelOptInfo *input_rel,
limitCount = (Node *) makeConst(INT8OID, -1, InvalidOid,
sizeof(int64),
Int64GetDatum(1), false,
FLOAT8PASSBYVAL);
true);
/*
* Apply a LimitPath onto the partial path to restrict the
@@ -5118,7 +5118,7 @@ create_final_distinct_paths(PlannerInfo *root, RelOptInfo *input_rel,
limitCount = (Node *) makeConst(INT8OID, -1, InvalidOid,
sizeof(int64),
Int64GetDatum(1), false,
FLOAT8PASSBYVAL);
true);
/*
* If the query already has a LIMIT clause, then we could

View File

@@ -408,7 +408,7 @@ make_const(ParseState *pstate, A_Const *aconst)
typeid = INT8OID;
typelen = sizeof(int64);
typebyval = FLOAT8PASSBYVAL; /* int8 and float8 alike */
typebyval = true;
}
}
else

View File

@@ -320,7 +320,7 @@ rewriteSearchAndCycle(CommonTableExpr *cte)
if (cte->search_clause->search_breadth_first)
{
search_col_rowexpr->args = lcons(makeConst(INT8OID, -1, InvalidOid, sizeof(int64),
Int64GetDatum(0), false, FLOAT8PASSBYVAL),
Int64GetDatum(0), false, true),
search_col_rowexpr->args);
search_col_rowexpr->colnames = lcons(makeString("*DEPTH*"), search_col_rowexpr->colnames);
texpr = (Expr *) search_col_rowexpr;

View File

@@ -3406,7 +3406,7 @@ construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
case FLOAT8OID:
elmlen = sizeof(float8);
elmbyval = FLOAT8PASSBYVAL;
elmbyval = true;
elmalign = TYPALIGN_DOUBLE;
break;
@@ -3424,7 +3424,7 @@ construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
case INT8OID:
elmlen = sizeof(int64);
elmbyval = FLOAT8PASSBYVAL;
elmbyval = true;
elmalign = TYPALIGN_DOUBLE;
break;
@@ -3718,7 +3718,7 @@ deconstruct_array_builtin(ArrayType *array,
case FLOAT8OID:
elmlen = sizeof(float8);
elmbyval = FLOAT8PASSBYVAL;
elmbyval = true;
elmalign = TYPALIGN_DOUBLE;
break;

View File

@@ -718,76 +718,29 @@ int8lcm(PG_FUNCTION_ARGS)
Datum
int8inc(PG_FUNCTION_ARGS)
{
/*
* When int8 is pass-by-reference, we provide this special case to avoid
* 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.)
*/
#ifndef USE_FLOAT8_BYVAL /* controls int8 too */
if (AggCheckCallContext(fcinfo, NULL))
{
int64 *arg = (int64 *) PG_GETARG_POINTER(0);
int64 arg = PG_GETARG_INT64(0);
int64 result;
if (unlikely(pg_add_s64_overflow(*arg, 1, arg)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
if (unlikely(pg_add_s64_overflow(arg, 1, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_POINTER(arg);
}
else
#endif
{
/* Not called as an aggregate, so just do it the dumb way */
int64 arg = PG_GETARG_INT64(0);
int64 result;
if (unlikely(pg_add_s64_overflow(arg, 1, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
PG_RETURN_INT64(result);
}
Datum
int8dec(PG_FUNCTION_ARGS)
{
/*
* When int8 is pass-by-reference, we provide this special case to avoid
* 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.)
*/
#ifndef USE_FLOAT8_BYVAL /* controls int8 too */
if (AggCheckCallContext(fcinfo, NULL))
{
int64 *arg = (int64 *) PG_GETARG_POINTER(0);
int64 arg = PG_GETARG_INT64(0);
int64 result;
if (unlikely(pg_sub_s64_overflow(*arg, 1, arg)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_POINTER(arg);
}
else
#endif
{
/* Not called as an aggregate, so just do it the dumb way */
int64 arg = PG_GETARG_INT64(0);
int64 result;
if (unlikely(pg_sub_s64_overflow(arg, 1, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
if (unlikely(pg_sub_s64_overflow(arg, 1, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
PG_RETURN_INT64(result);
}

View File

@@ -6362,6 +6362,7 @@ numeric_poly_stddev_pop(PG_FUNCTION_ARGS)
Datum
int2_sum(PG_FUNCTION_ARGS)
{
int64 oldsum;
int64 newval;
if (PG_ARGISNULL(0))
@@ -6374,43 +6375,22 @@ int2_sum(PG_FUNCTION_ARGS)
PG_RETURN_INT64(newval);
}
/*
* 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.)
*/
#ifndef USE_FLOAT8_BYVAL /* controls int8 too */
if (AggCheckCallContext(fcinfo, NULL))
{
int64 *oldsum = (int64 *) PG_GETARG_POINTER(0);
oldsum = PG_GETARG_INT64(0);
/* Leave the running sum unchanged in the new input is null */
if (!PG_ARGISNULL(1))
*oldsum = *oldsum + (int64) PG_GETARG_INT16(1);
/* Leave sum unchanged if new input is null. */
if (PG_ARGISNULL(1))
PG_RETURN_INT64(oldsum);
PG_RETURN_POINTER(oldsum);
}
else
#endif
{
int64 oldsum = PG_GETARG_INT64(0);
/* OK to do the addition. */
newval = oldsum + (int64) PG_GETARG_INT16(1);
/* Leave sum unchanged if new input is null. */
if (PG_ARGISNULL(1))
PG_RETURN_INT64(oldsum);
/* OK to do the addition. */
newval = oldsum + (int64) PG_GETARG_INT16(1);
PG_RETURN_INT64(newval);
}
PG_RETURN_INT64(newval);
}
Datum
int4_sum(PG_FUNCTION_ARGS)
{
int64 oldsum;
int64 newval;
if (PG_ARGISNULL(0))
@@ -6423,38 +6403,16 @@ int4_sum(PG_FUNCTION_ARGS)
PG_RETURN_INT64(newval);
}
/*
* 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.)
*/
#ifndef USE_FLOAT8_BYVAL /* controls int8 too */
if (AggCheckCallContext(fcinfo, NULL))
{
int64 *oldsum = (int64 *) PG_GETARG_POINTER(0);
oldsum = PG_GETARG_INT64(0);
/* Leave the running sum unchanged in the new input is null */
if (!PG_ARGISNULL(1))
*oldsum = *oldsum + (int64) PG_GETARG_INT32(1);
/* Leave sum unchanged if new input is null. */
if (PG_ARGISNULL(1))
PG_RETURN_INT64(oldsum);
PG_RETURN_POINTER(oldsum);
}
else
#endif
{
int64 oldsum = PG_GETARG_INT64(0);
/* OK to do the addition. */
newval = oldsum + (int64) PG_GETARG_INT32(1);
/* Leave sum unchanged if new input is null. */
if (PG_ARGISNULL(1))
PG_RETURN_INT64(oldsum);
/* OK to do the addition. */
newval = oldsum + (int64) PG_GETARG_INT32(1);
PG_RETURN_INT64(newval);
}
PG_RETURN_INT64(newval);
}
/*

View File

@@ -1007,7 +1007,7 @@ percentile_cont_float8_multi_final(PG_FUNCTION_ARGS)
FLOAT8OID,
/* hard-wired info on type float8 */
sizeof(float8),
FLOAT8PASSBYVAL,
true,
TYPALIGN_DOUBLE,
float8_lerp);
}

View File

@@ -397,7 +397,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);
stats->statypbyval[slot_idx] = FLOAT8PASSBYVAL;
stats->statypbyval[slot_idx] = true;
stats->statypalign[slot_idx] = 'd';
/* Store the fraction of empty ranges */

View File

@@ -1788,41 +1788,6 @@ OidSendFunctionCall(Oid functionId, Datum val)
}
/*-------------------------------------------------------------------------
* Support routines for standard maybe-pass-by-reference datatypes
*
* 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.)
*
* 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.
*-------------------------------------------------------------------------
*/
#ifndef USE_FLOAT8_BYVAL /* controls int8 too */
Datum
Int64GetDatum(int64 X)
{
int64 *retval = (int64 *) palloc(sizeof(int64));
*retval = X;
return PointerGetDatum(retval);
}
Datum
Float8GetDatum(float8 X)
{
float8 *retval = (float8 *) palloc(sizeof(float8));
*retval = X;
return PointerGetDatum(retval);
}
#endif /* USE_FLOAT8_BYVAL */
/*-------------------------------------------------------------------------
* Support routines for toastable datatypes
*-------------------------------------------------------------------------