pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Davis <pgsql@j-davis.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: Erik Wienhold <ewie@ewie.name>
Cc: Murat Efendioğlu <mrtdmrts001@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: Error when setting default_text_search_config
Date: Sun, 06 Oct 2024 14:51:17 -0700
Message-ID: <dac9094eac03d8eaff9e310aba336ec01fa3cf47.camel@j-davis.com> (raw)
In-Reply-To: <1381066.1728239990@sss.pgh.pa.us>
References: <CACbCzujQ4zS8MM1bx-==+tr+D3Hk5G1cjN4XkUQ+Q=cEpwhzqg@mail.gmail.com>
	<26c28873-85ca-4360-a5e9-1cc691a05451@ewie.name>
	<9c480df9-720b-4419-85c6-09113f5d6f0a@ewie.name>
	<1381066.1728239990@sss.pgh.pa.us>

On Sun, 2024-10-06 at 14:39 -0400, Tom Lane wrote:
> I suppose we could just move the InitializeSearchPath call up
> a bit (the comments in postinit.c are misleading about what it
> actually does), but I wonder whether the cache-is-valid assumptions
> in namespace.c ought to be rethought.  It seems unduly fragile
> as-is.

I attached a patch which fixes the observed problem and is hopefully
more robust to similar issues.

The test for use_cache in check_search_path() is also somewhat
indirect. The goal there is to avoid calling GetUserId() before
CurrentUserId is valid, but that could probably be solved other ways or
commented better. I will look into it.

Regards,
	Jeff Davis

Attachments:

v1-0001-Fix-search_path-cache-approach-2.patch (text/x-patch, 2.1K) download From df415145408f98354618fe950e42eb03a3e05523 Mon Sep 17 00:00:00 2001 From: Jeff Davis <jeff@j-davis.com> Date: Sun, 6 Oct 2024 13:40:31 -0700 Subject: [PATCH v1] Fix search_path cache approach 2. --- src/backend/catalog/namespace.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index 43b707699d..ceed7eb70c 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -305,17 +305,32 @@ static SearchPathCacheEntry *LastSearchPathCacheEntry = NULL; static void spcache_init(void) { - Assert(SearchPathCacheContext); - - if (SearchPathCache && searchPathCacheValid && + if (searchPathCacheValid && SearchPathCache->members < SPCACHE_RESET_THRESHOLD) return; - /* make sure we don't leave dangling pointers if nsphash_create fails */ + searchPathCacheValid = false; + baseSearchPathValid = false; + + /* + * Make sure we don't leave dangling pointers if a failure happens during + * initialization. + */ SearchPathCache = NULL; LastSearchPathCacheEntry = NULL; - MemoryContextReset(SearchPathCacheContext); + if (SearchPathCacheContext == NULL) + { + /* Make the context we'll keep search path cache hashtable in */ + SearchPathCacheContext = AllocSetContextCreate(TopMemoryContext, + "search_path processing cache", + ALLOCSET_DEFAULT_SIZES); + } + else + { + MemoryContextReset(SearchPathCacheContext); + } + /* arbitrary initial starting size of 16 elements */ SearchPathCache = nsphash_create(SearchPathCacheContext, 16, NULL); searchPathCacheValid = true; @@ -4742,11 +4757,6 @@ InitializeSearchPath(void) } else { - /* Make the context we'll keep search path cache hashtable in */ - SearchPathCacheContext = AllocSetContextCreate(TopMemoryContext, - "search_path processing cache", - ALLOCSET_DEFAULT_SIZES); - /* * In normal mode, arrange for a callback on any syscache invalidation * that will affect the search_path cache. -- 2.34.1

view thread (10+ messages)  latest in thread

Message-ID: <dac9094eac03d8eaff9e310aba336ec01fa3cf47.camel@j-davis.com>
Permalink:  ../dac9094eac03d8eaff9e310aba336ec01fa3cf47.camel@j-davis.com/
Also on:    postgresql.org/message-id/dac9094eac03d8eaff9e310aba336ec01fa3cf47.camel@j-davis.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: pgsql@j-davis.com, tgl@sss.pgh.pa.us, ewie@ewie.name, mrtdmrts001@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: Error when setting default_text_search_config
  In-Reply-To: <dac9094eac03d8eaff9e310aba336ec01fa3cf47.camel@j-davis.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