Обсуждение: pgsql: Fix bug in Tid scan.

Поиск
Список
Период
Сортировка

pgsql: Fix bug in Tid scan.

От
Fujii Masao
Дата:
Fix bug in Tid scan.

Commit 147e3722f7 changed Tid scan so that it calls table_beginscan()
and uses the scan option for seq scan. This change caused two issues.

(1) The change caused Tid scan to take a predicate lock on the entire
       relation in serializable transaction even when relation-level
       lock is not necessary. This could lead to an unexpected
       serialization error.

(2) The change caused Tid scan to increment the number of seq_scan
       in pg_stat_*_tables views even though it's not seq scan. This
       could confuse the users.

This commit adds the scan option for Tid scan and makes Tid scan
use it, to avoid those issues.

Back-patch to v12, where the bug was introduced.

Author: Tatsuhito Kasahara
Reviewed-by: Kyotaro Horiguchi, Masahiko Sawada, Fujii Masao
Discussion: https://postgr.es/m/CAP0=ZVKy+gTbFmB6X_UW0pP3WaeJ-fkUWHoD-pExS=at3CY76g@mail.gmail.com

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/598b466e80d9f46aa1472d4f1adb1df90be8c260

Modified Files
--------------
src/backend/executor/nodeTidscan.c    |  5 ++---
src/backend/utils/adt/tid.c           |  4 ++--
src/include/access/tableam.h          | 24 +++++++++++++++++++-----
src/test/regress/expected/tidscan.out | 16 ++++++++++++++++
src/test/regress/sql/tidscan.sql      |  7 +++++++
5 files changed, 46 insertions(+), 10 deletions(-)


Re: pgsql: Fix bug in Tid scan.

От
Tom Lane
Дата:
Fujii Masao <fujii@postgresql.org> writes:
> Fix bug in Tid scan.

AFAICS, this patch has caused an ABI break in v12.  Do we really
believe that no extension references the values of the ScanOptions
enum?

            regards, tom lane



Re: pgsql: Fix bug in Tid scan.

От
Fujii Masao
Дата:
On Sat, Feb 8, 2020 at 4:25 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Fujii Masao <fujii@postgresql.org> writes:
> > Fix bug in Tid scan.
>
> AFAICS, this patch has caused an ABI break in v12.  Do we really
> believe that no extension references the values of the ScanOptions
> enum?

Yes, you are right. Some extensions may depend on it.
It's better not to add new ScanOption not to break ABI.

So I'm thinking to apply the attached patch only to v12.
Which fixes the issue without adding new ScanOption.

Regards,

-- 
Fujii Masao

Вложения

Re: pgsql: Fix bug in Tid scan.

От
Tom Lane
Дата:
Fujii Masao <masao.fujii@gmail.com> writes:
> On Sat, Feb 8, 2020 at 4:25 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> AFAICS, this patch has caused an ABI break in v12.  Do we really
>> believe that no extension references the values of the ScanOptions
>> enum?

> Yes, you are right. Some extensions may depend on it.
> It's better not to add new ScanOption not to break ABI.

I think it's okay to add a new value of ScanOption; what you can't
do is change the codes assigned to the existing values.  So I'd
just revert those code changes and give SO_TYPE_TIDSCAN a value
that's out-of-order.

            regards, tom lane



Re: pgsql: Fix bug in Tid scan.

От
Fujii Masao
Дата:
On Sat, Feb 8, 2020 at 10:04 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Fujii Masao <masao.fujii@gmail.com> writes:
> > On Sat, Feb 8, 2020 at 4:25 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >> AFAICS, this patch has caused an ABI break in v12.  Do we really
> >> believe that no extension references the values of the ScanOptions
> >> enum?
>
> > Yes, you are right. Some extensions may depend on it.
> > It's better not to add new ScanOption not to break ABI.
>
> I think it's okay to add a new value of ScanOption; what you can't
> do is change the codes assigned to the existing values.  So I'd
> just revert those code changes and give SO_TYPE_TIDSCAN a value
> that's out-of-order.

So you are thinking to apply something like the attached to
both master and v12? That sounds better to me.

Regards,

-- 
Fujii Masao

Вложения

Re: pgsql: Fix bug in Tid scan.

От
Tom Lane
Дата:
Fujii Masao <masao.fujii@gmail.com> writes:
> On Sat, Feb 8, 2020 at 10:04 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I think it's okay to add a new value of ScanOption; what you can't
>> do is change the codes assigned to the existing values.  So I'd
>> just revert those code changes and give SO_TYPE_TIDSCAN a value
>> that's out-of-order.

> So you are thinking to apply something like the attached to
> both master and v12? That sounds better to me.

No, you can leave HEAD alone --- renumbering the enum values in
master is fine, since we force extensions to recompile against
new major versions.  We just need to hold the values steady in
released branches.

Personally I'd keep SO_TYPE_TIDSCAN physically adjacent to the other
SO_TYPE_xxxSCAN entries in the list, but of course that's just cosmetic.

            regards, tom lane



Re: pgsql: Fix bug in Tid scan.

От
Fujii Masao
Дата:
On Sat, Feb 8, 2020 at 11:08 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Fujii Masao <masao.fujii@gmail.com> writes:
> > On Sat, Feb 8, 2020 at 10:04 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >> I think it's okay to add a new value of ScanOption; what you can't
> >> do is change the codes assigned to the existing values.  So I'd
> >> just revert those code changes and give SO_TYPE_TIDSCAN a value
> >> that's out-of-order.
>
> > So you are thinking to apply something like the attached to
> > both master and v12? That sounds better to me.
>
> No, you can leave HEAD alone --- renumbering the enum values in
> master is fine, since we force extensions to recompile against
> new major versions.  We just need to hold the values steady in
> released branches.

Yeah, you're right.

> Personally I'd keep SO_TYPE_TIDSCAN physically adjacent to the other
> SO_TYPE_xxxSCAN entries in the list, but of course that's just cosmetic.

+1. So I will apply the latest patch (adding SO_TYPE_TIDSCAN just after
SO_TYPE_ANALYZE) only to v12.

Regards,

-- 
Fujii Masao



Re: pgsql: Fix bug in Tid scan.

От
Tom Lane
Дата:
Fujii Masao <masao.fujii@gmail.com> writes:
> On Sat, Feb 8, 2020 at 11:08 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Personally I'd keep SO_TYPE_TIDSCAN physically adjacent to the other
>> SO_TYPE_xxxSCAN entries in the list, but of course that's just cosmetic.

> +1. So I will apply the latest patch (adding SO_TYPE_TIDSCAN just after
> SO_TYPE_ANALYZE) only to v12.

Works for me.

            regards, tom lane



Re: pgsql: Fix bug in Tid scan.

От
Fujii Masao
Дата:
On Sat, Feb 8, 2020 at 12:05 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> Fujii Masao <masao.fujii@gmail.com> writes:
> > On Sat, Feb 8, 2020 at 11:08 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >> Personally I'd keep SO_TYPE_TIDSCAN physically adjacent to the other
> >> SO_TYPE_xxxSCAN entries in the list, but of course that's just cosmetic.
>
> > +1. So I will apply the latest patch (adding SO_TYPE_TIDSCAN just after
> > SO_TYPE_ANALYZE) only to v12.
>
> Works for me.

Pushed! Thanks a lot!!

Regards,

-- 
Fujii Masao