Re: [PATCH] Improve error message when trying to lock virtual tuple. - Mailing list pgsql-hackers

From Aleksander Alekseev
Subject Re: [PATCH] Improve error message when trying to lock virtual tuple.
Date
Msg-id CAJ7c6TOx+0K-k3PNuDniC=8a+j+skm+KZDEmEv+1Hw0rGVY4-Q@mail.gmail.com
Whole thread Raw
In response to [PATCH] Improve error message when trying to lock virtual tuple.  (Sven Klemm <sven@timescale.com>)
List pgsql-hackers
Hi,

> When currently trying to lock a virtual tuple the returned error
> will be a misleading `could not read block 0`. This patch adds a
> check for the tuple table slot being virtual to produce a clearer
> error.
>
> This can be triggered by extensions returning virtual tuples.
> While this is of course an error in those extensions the resulting
> error is very misleading.

```
+    /*
+     * If the slot is virtual, we can't lock it. This should never happen, but
+     * this will lead to a misleading could not read block error
later otherwise.
+     */
```

I suggest dropping or rephrasing the "this should never happen" part.
If this never happened we didn't need this check. Maybe "If the slot
is virtual, we can't lock it. Fail early in order to provide an
appropriate error message", or just "If the slot is virtual, we can't
lock it".

```
elog(ERROR, "cannot lock virtual tuple");
```

For some reason I thought that ereport() is the preferred way of
throwing errors, but I see elog() used many times in ExecLockRows() so
this is probably fine.

-- 
Best regards,
Aleksander Alekseev



pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: using extended statistics to improve join estimates
Next
From: Andrew Dunstan
Date:
Subject: Re: RFC: adding pytest as a supported test framework