pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Lakhin <exclusion@gmail.com>
To: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18014: Releasing catcache entries makes schema_to_xmlschema() fail when parallel workers are used
Date: Fri, 21 Jul 2023 12:00:01 +0300
Message-ID: <1a2d5aba-df29-ab8d-65ac-6ffd54d1ac62@gmail.com> (raw)
In-Reply-To: <20230720.172924.535889842187000361.horikyota.ntt@gmail.com>
References: <b2dcd258-82f1-dfe3-498e-9f652a0c0c4b@gmail.com>
	<20230720.162802.905550494964943231.horikyota.ntt@gmail.com>
	<20230720.164459.2183367718473165651.horikyota.ntt@gmail.com>
	<20230720.172924.535889842187000361.horikyota.ntt@gmail.com>

Hello Horiguchi-san,

20.07.2023 11:29, Kyotaro Horiguchi wrote:
> At Thu, 20 Jul 2023 16:44:59 +0900 (JST), Kyotaro Horiguchi <horikyota.ntt@gmail.com> wrote in
>> Stupid. What we should do here would be ensuring the funtion doesn't
>> invoke parallel workers, maybe.
> So, for testing, I didn't see the error with applying the attached patch.
> There are other SPI calls but I didn't see them at all.
>

Thank you for looking into it!

I think that we need to determine the level where the problem that should
be fixed is:
1) test xmlmap fails sporadically due to the catalog changes caused by
  parallel tests activity
2) schema_to_xmlschemaX() can fail when parallel workers are used
3) has_table_privilegeX() can fail sporadically when executed within a
  parallel worker
4) SearchSysCacheX(RELOID, ...) can switch to a newer catalog snapshot,
  when repeated in a parallel worker

The patch proposed fixes the issue on level 2, but that error still can be
seen on level 3. For example, you can replace
SELECT schema_to_xmlschema('testxmlschema_$c', true, false, '');
in the above script with
SELECT oid FROM pg_catalog.pg_class WHERE relnamespace = 1 AND relkind IN ('r', 'm', 'v') AND 
pg_catalog.has_table_privilege (oid, 'SELECT');

Probably, similar errors can also occur with
"SELECT * FROM information_schema.tables" or with other
information_schema views, that call has_table_privilege().

But if it's okey to have sporadic errors on lower levels, then may be just
fix the issue on level 1. Please look at the patch attached, that makes
schema_get_xml_visible_tables(Oid nspid) isolated from changes in other
namespaces.

Best regards,
Alexander

Attachments:

isolate-schema_get_xml_visible_tables.patch (text/x-patch, 884B) download diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index 866d0d649a..5b6291c6c9 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -2723,12 +2723,13 @@ schema_get_xml_visible_tables(Oid nspid) StringInfoData query; initStringInfo(&query); - appendStringInfo(&query, "SELECT oid FROM pg_catalog.pg_class" + appendStringInfo(&query, "SELECT oid FROM " + " (SELECT oid, relname FROM pg_catalog.pg_class" " WHERE relnamespace = %u AND relkind IN (" CppAsString2(RELKIND_RELATION) "," CppAsString2(RELKIND_MATVIEW) "," - CppAsString2(RELKIND_VIEW) ")" - " AND pg_catalog.has_table_privilege (oid, 'SELECT')" + CppAsString2(RELKIND_VIEW) ") OFFSET 0) c" + " WHERE pg_catalog.has_table_privilege (oid, 'SELECT')" " ORDER BY relname;", nspid); return query_to_oid_list(query.data);

view thread (24+ messages)  latest in thread

Message-ID: <1a2d5aba-df29-ab8d-65ac-6ffd54d1ac62@gmail.com>
Permalink:  ../1a2d5aba-df29-ab8d-65ac-6ffd54d1ac62@gmail.com/
Also on:    postgresql.org/message-id/1a2d5aba-df29-ab8d-65ac-6ffd54d1ac62@gmail.com

 ·  · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: exclusion@gmail.com, horikyota.ntt@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18014: Releasing catcache entries makes schema_to_xmlschema() fail when parallel workers are used
  In-Reply-To: <1a2d5aba-df29-ab8d-65ac-6ffd54d1ac62@gmail.com>

* 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