From: Oskari Saarenmaa <os@aiven.io>
To: Peter Geoghegan <pg@heroku.com>
To: Andres Freund <andres@anarazel.de>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: Peter Tripp <peter@chartio.com>
Cc: Virendra Negi <virendra@idyllic-software.com>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #14150: Attempted to delete invisible tuple
Date: Thu, 7 Jul 2016 22:43:59 +0300
Message-ID: <6e259534-eb94-0319-dace-ee83d9535a86@aiven.io> (raw)
In-Reply-To: <CAM3SWZQ_8aPcxRKm9Bsy5m46WqVoirmf7PMOw6-APe-k9MfSrw@mail.gmail.com>
References: <20160519123338.12513.20271@wrigleys.postgresql.org>
<CAM3SWZTZGRwo40ONo8g+ePmyjjhTgkYockn_iRY4PX9Wfz045Q@mail.gmail.com>
<CACOLnRWad2M9wA70vvjQ2GMOZMrfNkVOYVtq8+=au6JJX1oKjw@mail.gmail.com>
<CAM3SWZT0-XQv5R1vR+Ji5V6F-GOjJbUXKV2owCaPTGhJujY0HA@mail.gmail.com>
<CAB7nPqQSZVh==94uv8YS_WhNuaW+F1LFeA0vG+zSfxoBt5L88w@mail.gmail.com>
<CAM3SWZRE3eYZyrJz78mTNB5nG0sB47=z+S-T8HSq3h-_2PzcYQ@mail.gmail.com>
<CAB7nPqT4BSnyT+jK9Ys=yuHOe_v5KQ6e-yD7mzrsLC7=A2nfQA@mail.gmail.com>
<88248a24-47d1-d575-a63f-2b56a09f82e2@aiven.io>
<62f3793f-13d6-567c-e512-f29d1fd76d00@aiven.io>
<20160706214024.4bl2q3skcio4eoqk@alap3.anarazel.de>
<CAM3SWZQ_8aPcxRKm9Bsy5m46WqVoirmf7PMOw6-APe-k9MfSrw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
07.07.2016, 05:15, Peter Geoghegan kirjoitti:
> Maybe heap_abort_speculative() should be refactored to call another
> function, and keep only the parts that specifically expect a
> HeapTupleHeaderIsSpeculative() tuple. The function that it is made to
> call (that consists of the majority of the current
> heap_abort_speculative() implementation) could also be called by a
> special super deletion variant of toast_delete(). No need to spread
> knowledge about speculative insertion any further this way, AFAICT.
> The UPSERT commit did modify two HeapTupleSatisfies* routines, but
> that didn't include HeapTupleSatisfiesUpdate() (just
> HeapTupleSatisfiesDirty(), and the aforementioned defensive code in
> HeapTupleSatisfiesToast()).
>
> What do you think of this outline, Oskari and Andres?
Something like the attached patch? It still modifies the toast_delete
API, but we could also implement a new speculative-tuple-aware version
of it if that's a concern.
/ Oskari
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:heap_delete_speculative.patch (text/x-patch, 4.9K) downloaddiff --git src/backend/access/heap/heapam.c src/backend/access/heap/heapam.cindex 57da57a..00de8ae 100644--- src/backend/access/heap/heapam.c+++ src/backend/access/heap/heapam.c@@ -3335,7 +3335,7 @@ l1:
Assert(!HeapTupleHasExternal(&tp));
}
else if (HeapTupleHasExternal(&tp))
- toast_delete(relation, &tp);+ toast_delete(relation, &tp, false);
/*
* Mark tuple for invalidation from system caches at next command
@@ -5894,8 +5894,15 @@ heap_finish_speculative(Relation relation, HeapTuple tuple)
void
heap_abort_speculative(Relation relation, HeapTuple tuple)
{
- TransactionId xid = GetCurrentTransactionId();
ItemPointer tid = &(tuple->t_self);
++ heap_delete_speculative(relation, tid, false);+}++void+heap_delete_speculative(Relation relation, ItemPointer tid, bool is_toast)+{+ TransactionId xid = GetCurrentTransactionId();
ItemId lp;
HeapTupleData tp;
Page page;
@@ -5930,7 +5937,7 @@ heap_abort_speculative(Relation relation, HeapTuple tuple)
*/
if (tp.t_data->t_choice.t_heap.t_xmin != xid)
elog(ERROR, "attempted to kill a tuple inserted by another transaction");
- if (!HeapTupleHeaderIsSpeculative(tp.t_data))+ if (!(is_toast || HeapTupleHeaderIsSpeculative(tp.t_data)))
elog(ERROR, "attempted to kill a non-speculative tuple");
Assert(!HeapTupleHeaderIsHeapOnly(tp.t_data));
@@ -5999,8 +6006,8 @@ heap_abort_speculative(Relation relation, HeapTuple tuple)
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
- if (HeapTupleHasExternal(&tp))- toast_delete(relation, &tp);+ if (!is_toast && HeapTupleHasExternal(&tp))+ toast_delete(relation, &tp, true);
/*
* Never need to mark tuple for invalidation, since catalogs don't support
diff --git src/backend/access/heap/tuptoaster.c src/backend/access/heap/tuptoaster.cindex 4cffd21..a657330 100644--- src/backend/access/heap/tuptoaster.c+++ src/backend/access/heap/tuptoaster.c@@ -66,7 +66,7 @@ typedef struct toast_compress_header
#define TOAST_COMPRESS_SET_RAWSIZE(ptr, len) \
(((toast_compress_header *) (ptr))->rawsize = (len))
-static void toast_delete_datum(Relation rel, Datum value);+static void toast_delete_datum(Relation rel, Datum value, bool is_speculative);
static Datum toast_save_datum(Relation rel, Datum value,
struct varlena * oldexternal, int options);
static bool toastrel_valueid_exists(Relation toastrel, Oid valueid);
@@ -459,7 +459,7 @@ toast_datum_size(Datum value)
* ----------
*/
void
-toast_delete(Relation rel, HeapTuple oldtup)+toast_delete(Relation rel, HeapTuple oldtup, bool is_speculative)
{
TupleDesc tupleDesc;
Form_pg_attribute *att;
@@ -506,7 +506,7 @@ toast_delete(Relation rel, HeapTuple oldtup)
if (toast_isnull[i])
continue;
else if (VARATT_IS_EXTERNAL_ONDISK(PointerGetDatum(value)))
- toast_delete_datum(rel, value);+ toast_delete_datum(rel, value, is_speculative);
}
}
}
@@ -1062,7 +1062,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
if (need_delold)
for (i = 0; i < numAttrs; i++)
if (toast_delold[i])
- toast_delete_datum(rel, toast_oldvalues[i]);+ toast_delete_datum(rel, toast_oldvalues[i], false);
return result_tuple;
}
@@ -1654,7 +1654,7 @@ toast_save_datum(Relation rel, Datum value,
* ----------
*/
static void
-toast_delete_datum(Relation rel, Datum value)+toast_delete_datum(Relation rel, Datum value, bool is_speculative)
{
struct varlena *attr = (struct varlena *) DatumGetPointer(value);
struct varatt_external toast_pointer;
@@ -1703,7 +1703,10 @@ toast_delete_datum(Relation rel, Datum value)
/*
* Have a chunk, delete it
*/
- simple_heap_delete(toastrel, &toasttup->t_self);+ if (is_speculative)+ heap_delete_speculative(toastrel, &toasttup->t_self, true);+ else+ simple_heap_delete(toastrel, &toasttup->t_self);
}
/*
diff --git src/include/access/heapam.h src/include/access/heapam.hindex b3a595c..ca0c87d 100644--- src/include/access/heapam.h+++ src/include/access/heapam.h@@ -157,6 +157,7 @@ extern HTSU_Result heap_delete(Relation relation, ItemPointer tid,
HeapUpdateFailureData *hufd);
extern void heap_finish_speculative(Relation relation, HeapTuple tuple);
extern void heap_abort_speculative(Relation relation, HeapTuple tuple);
+extern void heap_delete_speculative(Relation relation, ItemPointer tid, bool is_toast);
extern HTSU_Result heap_update(Relation relation, ItemPointer otid,
HeapTuple newtup,
CommandId cid, Snapshot crosscheck, bool wait,
diff --git src/include/access/tuptoaster.h src/include/access/tuptoaster.hindex 7b5ae62..011f5c1 100644--- src/include/access/tuptoaster.h+++ src/include/access/tuptoaster.h@@ -142,7 +142,7 @@ extern HeapTuple toast_insert_or_update(Relation rel,
* Called by heap_delete().
* ----------
*/
-extern void toast_delete(Relation rel, HeapTuple oldtup);+extern void toast_delete(Relation rel, HeapTuple oldtup, bool is_speculative);
/* ----------
* heap_tuple_fetch_attr() -
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: os@aiven.io, pg@heroku.com, andres@anarazel.de, michael.paquier@gmail.com, peter@chartio.com, virendra@idyllic-software.com
Subject: Re: BUG #14150: Attempted to delete invisible tuple
In-Reply-To: <6e259534-eb94-0319-dace-ee83d9535a86@aiven.io>
References: <20160519123338.12513.20271@wrigleys.postgresql.org> <CAM3SWZTZGRwo40ONo8g+ePmyjjhTgkYockn_iRY4PX9Wfz045Q@mail.gmail.com> <CACOLnRWad2M9wA70vvjQ2GMOZMrfNkVOYVtq8+=au6JJX1oKjw@mail.gmail.com> <CAM3SWZT0-XQv5R1vR+Ji5V6F-GOjJbUXKV2owCaPTGhJujY0HA@mail.gmail.com> <CAB7nPqQSZVh==94uv8YS_WhNuaW+F1LFeA0vG+zSfxoBt5L88w@mail.gmail.com> <CAM3SWZRE3eYZyrJz78mTNB5nG0sB47=z+S-T8HSq3h-_2PzcYQ@mail.gmail.com> <CAB7nPqT4BSnyT+jK9Ys=yuHOe_v5KQ6e-yD7mzrsLC7=A2nfQA@mail.gmail.com> <88248a24-47d1-d575-a63f-2b56a09f82e2@aiven.io> <62f3793f-13d6-567c-e512-f29d1fd76d00@aiven.io> <20160706214024.4bl2q3skcio4eoqk@alap3.anarazel.de> <CAM3SWZQ_8aPcxRKm9Bsy5m46WqVoirmf7PMOw6-APe-k9MfSrw@mail.gmail.com> <6e259534-eb94-0319-dace-ee83d9535a86@aiven.io>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox