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 1opUdx-0008Ja-2v for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Oct 2022 13:15:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1opUdv-0000yf-Ve for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Oct 2022 13:15:55 +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 1opUdv-0000wW-Le for pgsql-hackers@lists.postgresql.org; Mon, 31 Oct 2022 13:15:55 +0000 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1opUdt-0003lb-E0 for pgsql-hackers@lists.postgresql.org; Mon, 31 Oct 2022 13:15:54 +0000 Received: by mail-lf1-x12e.google.com with SMTP id d25so18754997lfb.7 for ; Mon, 31 Oct 2022 06:15:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=B7zpiBPLMl8QCcDGkt7l++SZ3hIhghDoJ8ynaHOtb3Y=; b=QDmkZmY+8MwoKYbT/9zcb6U8puI2g/A98djj0eNWhWYskaE137cWXv1N7KiHaEPOUL Y+jLq501RrfI23TyHuJf80dR/5MxE/vK5UWTa4YSrSUNDSY/nd/2oKeLOKkofrQ8Zjn1 RAixXd2YE0CjLeLbDC/dVHBko1Nb9CwPo5bvDdBwovhn/sCHTJQJaK5WNP+s8UYXwQYI uZiHWbImLTb2yD7t7nsVqIylSeo5j7h7dKzr9s6bdVL3o5uSgkOSP9Ape9QJW4HF9qCk mQPXJtSZ7tpwXDoCiBXzx3AuNHETXSkgxkfr1L6pQb9iuTlievjM6GUDqI/1f3+eV3xf OGOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=B7zpiBPLMl8QCcDGkt7l++SZ3hIhghDoJ8ynaHOtb3Y=; b=OnJCLncVstAtPdXn1Ne5Efqjnw2CCBrrpHgaLcGPnpS4gfjkMg53xsdG2TFv0RGqOP xV/T0WEC9DGntNv5KGhJ025vU3rhZONRJB+ns6jRcnbMEMjp7+KqlikWho2K/dQKL3sX GksGEtAtXsCJk3ZiMO4IE92wu3pN/7uJuFYNJJP7bhcBXqc3MiiizAWAEuZET4+6qq// IpzxnWGxeK6t2rAwGJMvqttctP1FY3jovPNS8jQKzWMKENlNowrpwTLS3xV+Eyg/4bm4 LgUcqGzVv1931xoNqO4owSySF8rHQu78RW7uNZNzfjIbuk3DIUk6dEuBt5aZHgMseat6 SKpw== X-Gm-Message-State: ACrzQf0dPJHvZhWVBLSPFfigxRv+GtEogBV/ipytRqdZXP0ubodArBFQ 93zUP2SH7vMP/rgeK7XrHNScr61le8CSAA== X-Google-Smtp-Source: AMsMyM6zlW7WvYd5xZWBEYP5drXt+7NhF7mHBZD9MXzAAZdYdPFKenOSnZuB4lWQKj7csnY6+hWaeQ== X-Received: by 2002:a05:6512:3502:b0:493:e21:b77d with SMTP id h2-20020a056512350200b004930e21b77dmr5232017lfs.580.1667222151836; Mon, 31 Oct 2022 06:15:51 -0700 (PDT) Received: from [192.168.28.144] (cyclops.postgrespro.ru. [93.174.131.138]) by smtp.gmail.com with ESMTPSA id m15-20020a0565120a8f00b004947984b385sm1279610lfu.87.2022.10.31.06.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 06:15:51 -0700 (PDT) Message-ID: <44d2ac16d32f671d2e7df0d4903bbf7cf03c21c7.camel@gmail.com> Subject: Re: Segfault on logical replication to partitioned table with foreign children From: ilya.v.gladyshev@gmail.com To: Tom Lane , Dilip Kumar Cc: pgsql-hackers@lists.postgresql.org Date: Mon, 31 Oct 2022 17:15:48 +0400 In-Reply-To: <188734.1667137161@sss.pgh.pa.us> References: <6b93e3748ba43298694f376ca8797279d7945e29.camel@gmail.com> <188734.1667137161@sss.pgh.pa.us> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.3-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, 2022-10-30 at 09:39 -0400, Tom Lane wrote: > Dilip Kumar writes: > > Yes, this looks like a bug and your fix seems correct to me.  It > > would > > be nice to add a test case for this scenario. > > A test case doesn't seem that exciting to me.  If we were trying to > make it actually work, then yeah, but throwing an error isn't that > useful to test.  The code will be exercised by replication to a > regular partitioned table (I assume we do have tests for that). > > What I'm wondering about is whether we can refactor this code > to avoid so many usually-useless catalog lookups.  Pulling the > namespace name, in particular, is expensive and we generally > are not going to need the result.  In the child-rel case it'd > be much better to pass the opened relation and let the error-check > subroutine work from that.  Maybe we should just do it like that > at the start of the recursion, too?  Or pass the relid and let > the subroutine look up the names only in the error case. Sure, I think passing in the opened relation is a good idea. > A completely different line of thought is that this doesn't seem > like a terribly bulletproof fix, since children could get added to > a partitioned table after we look.  Maybe it'd be better to check > the relkind at the last moment before we do something that depends > on a child table being a relation. These checks are run both on subscription DDL commands, which is good to get some early feedback, and inside logical_rel_open(), right before something useful is about to get done to the relation, so we should be good here. I think some tests would actually be nice to verify this, but I don't really have a strong opinion about it. I'll refactor the patch and post a bit later.