Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mKuwV-0003M5-09 for pgsql-bugs@arkaria.postgresql.org; Tue, 31 Aug 2021 04:00:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mKuwT-0006SV-FU for pgsql-bugs@arkaria.postgresql.org; Tue, 31 Aug 2021 04:00:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mKuwT-0006SM-74 for pgsql-bugs@lists.postgresql.org; Tue, 31 Aug 2021 04:00:09 +0000 Received: from mail-lf1-x12c.google.com ([2a00:1450:4864:20::12c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mKuwN-0006fO-SK for pgsql-bugs@lists.postgresql.org; Tue, 31 Aug 2021 04:00:08 +0000 Received: by mail-lf1-x12c.google.com with SMTP id z2so35691171lft.1 for ; Mon, 30 Aug 2021 21:00:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=ykDm+LgoT21H9/QlhT9IAZlqk7I/aswe4+S7OjMTdgY=; b=DuFokFnxr24sm8XqjBbVZG5m7iIbUREKkQPrdUTZ5OL6xFNgWW3JhBD75o/HqzRaZ+ X4UoJXD3O51pHKev7bgq3P+NGYF9SlOwW3IXrtXJqfXPOEOvp80vaH7C3KEEQgCQ21t8 YuvmANdh4qKtTo+o+Ow3GKNfGPJe+dZRd87T3K+p2SfeOdZopWYfnK6hB0GuhiaOujTv 9svbBd0IpAlEtnIXLrcSZanPwHWdE6INiLKYajWdLGNDZHIJM+ZFy+8497/PgoiB035S R05hWnm9NFaWKJP1E91zXqk08lbgUCAgXNoK82AY0FR9TYZxEIcSCRVZlku5uZ2r8YEY 7PIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=ykDm+LgoT21H9/QlhT9IAZlqk7I/aswe4+S7OjMTdgY=; b=qVkSO9WEfzYV51t9xR3NyyRAAkhQ6X9HNK0qxemg+S7qwNBtwgHh8Hj2Sl/jlKGapZ zRajeCnAESH0bQR76oO/yjxc3DMKlEhHnEVCIbeVTggW1bRIIk9siZimnYE2E5gYJPSL REu4TjJQ8vn0QhKNsLoYShzxlsqiJuCxpzNXJOvTNmYcWANzjBS7MkWBnZNNtNbwqN4V ttoaNDSm7cMRp7oCdgFOLwbz2oulM1/L0ZMrradAW/VflCL7GBJ+zeoPzMULqXczgow1 SqoNfpIeftkiQrfS6qeSn2wrF9ZrOocAQRM+puLMgh2kH5vkJayGeo+b0T6qiH0Pj5Xi 7wsg== X-Gm-Message-State: AOAM533Ek5+GAErO+jLqQVPaonpR9+w5slUSECdbrSmfWbRA6C9So/Su sDotag8+1L/MtxhODKAOogJs6lEFB14= X-Google-Smtp-Source: ABdhPJzTSLlReaLhY0kr83fJLAZWVj51F1RLOA1vGZKF6SWdGec44r3YCT40n750rv/X0679WLmoQA== X-Received: by 2002:a05:6512:10ca:: with SMTP id k10mr20166562lfg.385.1630382402381; Mon, 30 Aug 2021 21:00:02 -0700 (PDT) Received: from [1.0.0.7] ([178.155.6.221]) by smtp.gmail.com with ESMTPSA id c10sm1597463lfm.271.2021.08.30.21.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Aug 2021 21:00:01 -0700 (PDT) Subject: Re: BUG #17161: Assert failed on opening a relation that exists in two schemas via the LANGUAGE SQL function To: Tom Lane Cc: pgsql-bugs@lists.postgresql.org, Peter Eisentraut References: <17161-048a1cdff8422800@postgresql.org> <25f71277-c45a-8ef2-ef9a-9054c3d6e0b0@gmail.com> <1568218.1630377575@sss.pgh.pa.us> From: Alexander Lakhin Message-ID: <042970a6-8d93-cbb0-0e55-1bfb82a99c1e@gmail.com> Date: Tue, 31 Aug 2021 07:00:00 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <1568218.1630377575@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 31.08.2021 05:39, Tom Lane wrote: > Alexander Lakhin writes: >> My initial conclusion was incorrect. Duplicate relation is not needed in >> the second schema. It's sufficient to just change search_path to another >> schema: > Actually, you don't need to mess with search_path at all: inlining of > set-returning SQL functions just plain does not work, if they are > new-style. The reason is that we forgot to apply AcquireRewriteLocks > in that code path. That leads to the assertion failure you show here. > Even without that, we risk problems with JOINs on dropped columns, which > is another thing that AcquireRewriteLocks is charged with cleaning up. Oops, sorry for the noisy reproduction and incorrect conclusions. I simplified an initial crashing script (thousand lines generated with a fuzzer) but was in hot haste and couldn't think of such a simple explanation. > The regression tests fail to show this problem because, while they do > test inlining of a new-style SRF, the solitary test case contains no > relation references. > > I looked around at other places that consult prosqlbody, and saw > that the only one that accounts for the lock issue is init_sql_fcache. > fmgr_sql_validator and print_function_sqlbody are also being cavalier > about this, and I doubt that either one of them is really safe. > (You could maybe argue that print_function_sqlbody doesn't need locks, > but in view of the dropped-JOIN-column issue, I don't think I believe > it. Likewise in fmgr_sql_validator, which wasn't applying the rewriter > at all, which I doubt is OK considering the older code path does it.) > > Proposed patch attached. This patch fixes the issue for me. Thank you! Best regards, Alexander