Skip to content

Commit ee54046

Browse files
committed
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
1 parent 6aebedc commit ee54046

File tree

22 files changed

+100
-313
lines changed

22 files changed

+100
-313
lines changed

contrib/btree_gist/btree_time.c

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,15 @@ PG_FUNCTION_INFO_V1(gbt_time_sortsupport);
3131
PG_FUNCTION_INFO_V1(gbt_timetz_sortsupport);
3232

3333

34-
#ifdef USE_FLOAT8_BYVAL
35-
#define TimeADTGetDatumFast(X) TimeADTGetDatum(X)
36-
#else
37-
#define TimeADTGetDatumFast(X) PointerGetDatum(&(X))
38-
#endif
39-
40-
4134
static bool
4235
gbt_timegt(const void *a, const void *b, FmgrInfo *flinfo)
4336
{
4437
const TimeADT *aa = (const TimeADT *) a;
4538
const TimeADT *bb = (const TimeADT *) b;
4639

4740
return DatumGetBool(DirectFunctionCall2(time_gt,
48-
TimeADTGetDatumFast(*aa),
49-
TimeADTGetDatumFast(*bb)));
41+
TimeADTGetDatum(*aa),
42+
TimeADTGetDatum(*bb)));
5043
}
5144

5245
static bool
@@ -56,8 +49,8 @@ gbt_timege(const void *a, const void *b, FmgrInfo *flinfo)
5649
const TimeADT *bb = (const TimeADT *) b;
5750

5851
return DatumGetBool(DirectFunctionCall2(time_ge,
59-
TimeADTGetDatumFast(*aa),
60-
TimeADTGetDatumFast(*bb)));
52+
TimeADTGetDatum(*aa),
53+
TimeADTGetDatum(*bb)));
6154
}
6255

6356
static bool
@@ -67,8 +60,8 @@ gbt_timeeq(const void *a, const void *b, FmgrInfo *flinfo)
6760
const TimeADT *bb = (const TimeADT *) b;
6861

6962
return DatumGetBool(DirectFunctionCall2(time_eq,
70-
TimeADTGetDatumFast(*aa),
71-
TimeADTGetDatumFast(*bb)));
63+
TimeADTGetDatum(*aa),
64+
TimeADTGetDatum(*bb)));
7265
}
7366

7467
static bool
@@ -78,8 +71,8 @@ gbt_timele(const void *a, const void *b, FmgrInfo *flinfo)
7871
const TimeADT *bb = (const TimeADT *) b;
7972

8073
return DatumGetBool(DirectFunctionCall2(time_le,
81-
TimeADTGetDatumFast(*aa),
82-
TimeADTGetDatumFast(*bb)));
74+
TimeADTGetDatum(*aa),
75+
TimeADTGetDatum(*bb)));
8376
}
8477

8578
static bool
@@ -89,8 +82,8 @@ gbt_timelt(const void *a, const void *b, FmgrInfo *flinfo)
8982
const TimeADT *bb = (const TimeADT *) b;
9083

9184
return DatumGetBool(DirectFunctionCall2(time_lt,
92-
TimeADTGetDatumFast(*aa),
93-
TimeADTGetDatumFast(*bb)));
85+
TimeADTGetDatum(*aa),
86+
TimeADTGetDatum(*bb)));
9487
}
9588

9689
static int
@@ -100,9 +93,9 @@ gbt_timekey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
10093
timeKEY *ib = (timeKEY *) (((const Nsrt *) b)->t);
10194
int res;
10295

103-
res = DatumGetInt32(DirectFunctionCall2(time_cmp, TimeADTGetDatumFast(ia->lower), TimeADTGetDatumFast(ib->lower)));
96+
res = DatumGetInt32(DirectFunctionCall2(time_cmp, TimeADTGetDatum(ia->lower), TimeADTGetDatum(ib->lower)));
10497
if (res == 0)
105-
return DatumGetInt32(DirectFunctionCall2(time_cmp, TimeADTGetDatumFast(ia->upper), TimeADTGetDatumFast(ib->upper)));
98+
return DatumGetInt32(DirectFunctionCall2(time_cmp, TimeADTGetDatum(ia->upper), TimeADTGetDatum(ib->upper)));
10699

107100
return res;
108101
}
@@ -115,8 +108,8 @@ gbt_time_dist(const void *a, const void *b, FmgrInfo *flinfo)
115108
Interval *i;
116109

117110
i = DatumGetIntervalP(DirectFunctionCall2(time_mi_time,
118-
TimeADTGetDatumFast(*aa),
119-
TimeADTGetDatumFast(*bb)));
111+
TimeADTGetDatum(*aa),
112+
TimeADTGetDatum(*bb)));
120113
return fabs(INTERVAL_TO_SEC(i));
121114
}
122115

@@ -279,14 +272,14 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
279272
double res2;
280273

281274
intr = DatumGetIntervalP(DirectFunctionCall2(time_mi_time,
282-
TimeADTGetDatumFast(newentry->upper),
283-
TimeADTGetDatumFast(origentry->upper)));
275+
TimeADTGetDatum(newentry->upper),
276+
TimeADTGetDatum(origentry->upper)));
284277
res = INTERVAL_TO_SEC(intr);
285278
res = Max(res, 0);
286279

287280
intr = DatumGetIntervalP(DirectFunctionCall2(time_mi_time,
288-
TimeADTGetDatumFast(origentry->lower),
289-
TimeADTGetDatumFast(newentry->lower)));
281+
TimeADTGetDatum(origentry->lower),
282+
TimeADTGetDatum(newentry->lower)));
290283
res2 = INTERVAL_TO_SEC(intr);
291284
res2 = Max(res2, 0);
292285

@@ -297,8 +290,8 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
297290
if (res > 0)
298291
{
299292
intr = DatumGetIntervalP(DirectFunctionCall2(time_mi_time,
300-
TimeADTGetDatumFast(origentry->upper),
301-
TimeADTGetDatumFast(origentry->lower)));
293+
TimeADTGetDatum(origentry->upper),
294+
TimeADTGetDatum(origentry->lower)));
302295
*result += FLT_MIN;
303296
*result += (float) (res / (res + INTERVAL_TO_SEC(intr)));
304297
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
@@ -334,8 +327,8 @@ gbt_timekey_ssup_cmp(Datum x, Datum y, SortSupport ssup)
334327

335328
/* for leaf items we expect lower == upper, so only compare lower */
336329
return DatumGetInt32(DirectFunctionCall2(time_cmp,
337-
TimeADTGetDatumFast(arg1->lower),
338-
TimeADTGetDatumFast(arg2->lower)));
330+
TimeADTGetDatum(arg1->lower),
331+
TimeADTGetDatum(arg2->lower)));
339332
}
340333

341334
Datum

contrib/btree_gist/btree_ts.c

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@ PG_FUNCTION_INFO_V1(gbt_ts_same);
3333
PG_FUNCTION_INFO_V1(gbt_ts_sortsupport);
3434

3535

36-
#ifdef USE_FLOAT8_BYVAL
37-
#define TimestampGetDatumFast(X) TimestampGetDatum(X)
38-
#else
39-
#define TimestampGetDatumFast(X) PointerGetDatum(&(X))
40-
#endif
41-
42-
4336
/* define for comparison */
4437

4538
static bool
@@ -49,8 +42,8 @@ gbt_tsgt(const void *a, const void *b, FmgrInfo *flinfo)
4942
const Timestamp *bb = (const Timestamp *) b;
5043

5144
return DatumGetBool(DirectFunctionCall2(timestamp_gt,
52-
TimestampGetDatumFast(*aa),
53-
TimestampGetDatumFast(*bb)));
45+
TimestampGetDatum(*aa),
46+
TimestampGetDatum(*bb)));
5447
}
5548

5649
static bool
@@ -60,8 +53,8 @@ gbt_tsge(const void *a, const void *b, FmgrInfo *flinfo)
6053
const Timestamp *bb = (const Timestamp *) b;
6154

6255
return DatumGetBool(DirectFunctionCall2(timestamp_ge,
63-
TimestampGetDatumFast(*aa),
64-
TimestampGetDatumFast(*bb)));
56+
TimestampGetDatum(*aa),
57+
TimestampGetDatum(*bb)));
6558
}
6659

6760
static bool
@@ -71,8 +64,8 @@ gbt_tseq(const void *a, const void *b, FmgrInfo *flinfo)
7164
const Timestamp *bb = (const Timestamp *) b;
7265

7366
return DatumGetBool(DirectFunctionCall2(timestamp_eq,
74-
TimestampGetDatumFast(*aa),
75-
TimestampGetDatumFast(*bb)));
67+
TimestampGetDatum(*aa),
68+
TimestampGetDatum(*bb)));
7669
}
7770

7871
static bool
@@ -82,8 +75,8 @@ gbt_tsle(const void *a, const void *b, FmgrInfo *flinfo)
8275
const Timestamp *bb = (const Timestamp *) b;
8376

8477
return DatumGetBool(DirectFunctionCall2(timestamp_le,
85-
TimestampGetDatumFast(*aa),
86-
TimestampGetDatumFast(*bb)));
78+
TimestampGetDatum(*aa),
79+
TimestampGetDatum(*bb)));
8780
}
8881

8982
static bool
@@ -93,8 +86,8 @@ gbt_tslt(const void *a, const void *b, FmgrInfo *flinfo)
9386
const Timestamp *bb = (const Timestamp *) b;
9487

9588
return DatumGetBool(DirectFunctionCall2(timestamp_lt,
96-
TimestampGetDatumFast(*aa),
97-
TimestampGetDatumFast(*bb)));
89+
TimestampGetDatum(*aa),
90+
TimestampGetDatum(*bb)));
9891
}
9992

10093
static int
@@ -104,9 +97,9 @@ gbt_tskey_cmp(const void *a, const void *b, FmgrInfo *flinfo)
10497
tsKEY *ib = (tsKEY *) (((const Nsrt *) b)->t);
10598
int res;
10699

107-
res = DatumGetInt32(DirectFunctionCall2(timestamp_cmp, TimestampGetDatumFast(ia->lower), TimestampGetDatumFast(ib->lower)));
100+
res = DatumGetInt32(DirectFunctionCall2(timestamp_cmp, TimestampGetDatum(ia->lower), TimestampGetDatum(ib->lower)));
108101
if (res == 0)
109-
return DatumGetInt32(DirectFunctionCall2(timestamp_cmp, TimestampGetDatumFast(ia->upper), TimestampGetDatumFast(ib->upper)));
102+
return DatumGetInt32(DirectFunctionCall2(timestamp_cmp, TimestampGetDatum(ia->upper), TimestampGetDatum(ib->upper)));
110103

111104
return res;
112105
}
@@ -122,8 +115,8 @@ gbt_ts_dist(const void *a, const void *b, FmgrInfo *flinfo)
122115
return get_float8_infinity();
123116

124117
i = DatumGetIntervalP(DirectFunctionCall2(timestamp_mi,
125-
TimestampGetDatumFast(*aa),
126-
TimestampGetDatumFast(*bb)));
118+
TimestampGetDatum(*aa),
119+
TimestampGetDatum(*bb)));
127120
return fabs(INTERVAL_TO_SEC(i));
128121
}
129122

@@ -404,8 +397,8 @@ gbt_ts_ssup_cmp(Datum x, Datum y, SortSupport ssup)
404397

405398
/* for leaf items we expect lower == upper, so only compare lower */
406399
return DatumGetInt32(DirectFunctionCall2(timestamp_cmp,
407-
TimestampGetDatumFast(arg1->lower),
408-
TimestampGetDatumFast(arg2->lower)));
400+
TimestampGetDatum(arg1->lower),
401+
TimestampGetDatum(arg2->lower)));
409402
}
410403

411404
Datum

src/backend/access/common/tupdesc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
993993

994994
case INT8OID:
995995
att->attlen = 8;
996-
att->attbyval = FLOAT8PASSBYVAL;
996+
att->attbyval = true;
997997
att->attalign = TYPALIGN_DOUBLE;
998998
att->attstorage = TYPSTORAGE_PLAIN;
999999
att->attcompression = InvalidCompressionMethod;

src/backend/access/index/indexam.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -986,11 +986,6 @@ index_store_float8_orderby_distances(IndexScanDesc scan, Oid *orderByTypes,
986986
{
987987
if (orderByTypes[i] == FLOAT8OID)
988988
{
989-
#ifndef USE_FLOAT8_BYVAL
990-
/* must free any old value to avoid memory leakage */
991-
if (!scan->xs_orderbynulls[i])
992-
pfree(DatumGetPointer(scan->xs_orderbyvals[i]));
993-
#endif
994989
if (distances && !distances[i].isnull)
995990
{
996991
scan->xs_orderbyvals[i] = Float8GetDatum(distances[i].value);

src/backend/access/transam/xlog.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4390,7 +4390,7 @@ WriteControlFile(void)
43904390
ControlFile->toast_max_chunk_size = TOAST_MAX_CHUNK_SIZE;
43914391
ControlFile->loblksize = LOBLKSIZE;
43924392

4393-
ControlFile->float8ByVal = FLOAT8PASSBYVAL;
4393+
ControlFile->float8ByVal = true; /* vestigial */
43944394

43954395
/*
43964396
* Initialize the default 'char' signedness.
@@ -4651,23 +4651,7 @@ ReadControlFile(void)
46514651
"LOBLKSIZE", (int) LOBLKSIZE),
46524652
errhint("It looks like you need to recompile or initdb.")));
46534653

4654-
#ifdef USE_FLOAT8_BYVAL
4655-
if (ControlFile->float8ByVal != true)
4656-
ereport(FATAL,
4657-
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4658-
errmsg("database files are incompatible with server"),
4659-
errdetail("The database cluster was initialized without USE_FLOAT8_BYVAL"
4660-
" but the server was compiled with USE_FLOAT8_BYVAL."),
4661-
errhint("It looks like you need to recompile or initdb.")));
4662-
#else
4663-
if (ControlFile->float8ByVal != false)
4664-
ereport(FATAL,
4665-
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
4666-
errmsg("database files are incompatible with server"),
4667-
errdetail("The database cluster was initialized with USE_FLOAT8_BYVAL"
4668-
" but the server was compiled without USE_FLOAT8_BYVAL."),
4669-
errhint("It looks like you need to recompile or initdb.")));
4670-
#endif
4654+
Assert(ControlFile->float8ByVal); /* vestigial, not worth an error msg */
46714655

46724656
wal_segment_size = ControlFile->xlog_seg_size;
46734657

src/backend/catalog/genbki.pl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,8 +1054,7 @@ sub morph_row_for_schemapg
10541054
}
10551055

10561056
# Expand booleans from 'f'/'t' to 'false'/'true'.
1057-
# Some values might be other macros (eg FLOAT8PASSBYVAL),
1058-
# don't change.
1057+
# Some values might be other macros, if so don't change.
10591058
elsif ($atttype eq 'bool')
10601059
{
10611060
$row->{$attname} = 'true' if $row->{$attname} eq 't';

src/backend/optimizer/plan/planagg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ build_minmax_path(PlannerInfo *root, MinMaxAggInfo *mminfo,
410410
parse->limitCount = (Node *) makeConst(INT8OID, -1, InvalidOid,
411411
sizeof(int64),
412412
Int64GetDatum(1), false,
413-
FLOAT8PASSBYVAL);
413+
true);
414414

415415
/*
416416
* Generate the best paths for this query, telling query_planner that we

src/backend/optimizer/plan/planner.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4915,7 +4915,7 @@ create_partial_distinct_paths(PlannerInfo *root, RelOptInfo *input_rel,
49154915
limitCount = (Node *) makeConst(INT8OID, -1, InvalidOid,
49164916
sizeof(int64),
49174917
Int64GetDatum(1), false,
4918-
FLOAT8PASSBYVAL);
4918+
true);
49194919

49204920
/*
49214921
* Apply a LimitPath onto the partial path to restrict the
@@ -5118,7 +5118,7 @@ create_final_distinct_paths(PlannerInfo *root, RelOptInfo *input_rel,
51185118
limitCount = (Node *) makeConst(INT8OID, -1, InvalidOid,
51195119
sizeof(int64),
51205120
Int64GetDatum(1), false,
5121-
FLOAT8PASSBYVAL);
5121+
true);
51225122

51235123
/*
51245124
* If the query already has a LIMIT clause, then we could

src/backend/parser/parse_node.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ make_const(ParseState *pstate, A_Const *aconst)
408408

409409
typeid = INT8OID;
410410
typelen = sizeof(int64);
411-
typebyval = FLOAT8PASSBYVAL; /* int8 and float8 alike */
411+
typebyval = true;
412412
}
413413
}
414414
else

src/backend/rewrite/rewriteSearchCycle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ rewriteSearchAndCycle(CommonTableExpr *cte)
320320
if (cte->search_clause->search_breadth_first)
321321
{
322322
search_col_rowexpr->args = lcons(makeConst(INT8OID, -1, InvalidOid, sizeof(int64),
323-
Int64GetDatum(0), false, FLOAT8PASSBYVAL),
323+
Int64GetDatum(0), false, true),
324324
search_col_rowexpr->args);
325325
search_col_rowexpr->colnames = lcons(makeString("*DEPTH*"), search_col_rowexpr->colnames);
326326
texpr = (Expr *) search_col_rowexpr;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

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

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


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy