From 05d8b4ee28bccef842e94f0367b1829002c4730c Mon Sep 17 00:00:00 2001 From: Chapman Flack Date: Mon, 26 May 2025 15:54:30 -0400 Subject: [PATCH] GetOldestSnapshot -> get_toast_snapshot When VarlenaWrapper wants to save a TOASTed value that may possibly be wanted later, it can use the least memory if it just retains the TOAST pointer and registers a current snapshot in which it is visible. In PG 9.6, a GetOldestSnapshot function appeared and made that possible. As of PG 18, with postgres/postgres@4d82750, that function has vanished, but there is a new one, get_toast_snapshot, that appears to fit the bill. It's only declared in access/toast_internals.h, though, which isn't otherwise needed. Addresses #524. --- pljava-so/src/main/c/VarlenaWrapper.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pljava-so/src/main/c/VarlenaWrapper.c b/pljava-so/src/main/c/VarlenaWrapper.c index cb1d9e7a5..25d690b1f 100644 --- a/pljava-so/src/main/c/VarlenaWrapper.c +++ b/pljava-so/src/main/c/VarlenaWrapper.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2023 Tada AB and other contributors, as listed below. + * Copyright (c) 2018-2025 Tada AB and other contributors, as listed below. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the The BSD 3-Clause License @@ -33,7 +33,11 @@ #include "pljava/JNICalls.h" #if PG_VERSION_NUM < 90600 -#define GetOldestSnapshot() NULL +#define get_toast_snapshot() NULL +#elif PG_VERSION_NUM < 180000 +#define get_toast_snapshot() GetOldestSnapshot() +#else +#include #endif #define _VL_TYPE struct varlena * @@ -145,7 +149,7 @@ jobject pljava_VarlenaWrapper_Input( goto justDetoastEagerly; if ( VARATT_IS_EXTERNAL_ONDISK(vl) ) { - pin = GetOldestSnapshot(); + pin = get_toast_snapshot(); if ( NULL == pin ) { /*