Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVNVi-0004LH-7q for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Nov 2019 22:22:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iVNVf-00078e-K4 for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Nov 2019 22:22:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVNVf-00078X-BY for pgsql-hackers@lists.postgresql.org; Thu, 14 Nov 2019 22:22:39 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVNVc-00008j-KW for pgsql-hackers@lists.postgresql.org; Thu, 14 Nov 2019 22:22:38 +0000 Received: by mail-wr1-x443.google.com with SMTP id s5so8672447wrw.2 for ; Thu, 14 Nov 2019 14:22:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=0JG1Z8e+YP08x2w5jhHKpeAQ8EPVnb09Mnn6ejZBFZc=; b=o7iQhvIZBUn2fy+DxEot/O2R3fDO9hWI0hQLcLyhXSU2hPgqDft1jrKxbg7hQxKODz DLWzAXR7u2FZc7wWeMtm9l6BwazHyQbOcZdMwDiNPP+oNp/FKSv4VVZoSK9GNdc0ORrd 8paJjocvUxS4LZMVf/AThxtbmzj1fkFpKjKrNoA0Dgo9PMmP7smqA4kfDaTqDHb36JBc 5/iMOBgZXGqoHNp2m+E7Iyr8L/knCWUUTzRL7NzBgCeBQ/PmzjRQ3cwBAv1+PmFUuVes uCGEV+H+LDe/V0wVYJOg3LUzzmSUe5Kxfc5OqpbazbUnRfM2gcq7ccNhRwq/P21FUpfQ KamA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=0JG1Z8e+YP08x2w5jhHKpeAQ8EPVnb09Mnn6ejZBFZc=; b=THI0PpkbrCMKbo6GFAYWab1R+6AfUqabdXBLSwwTcPtuWgf6RnKv0lZx1yYz28TZId 08ifF6PAjpDHhl4QUvRAPjYRjJtyfo4CUi6wlWU1JyyltZ+WF9Umd1KVuHDCcLsyH8ng +IbiLYEl1oprlc/o7piMa1WOZeeCwbtrDgrIwPB1edpQNOHayCtaRfpTjSx+DwV5gtw2 POHTYF8nVP4AYGhxENGnftPksD0I0FD9m5rmKSwaPBcoRGW0G5Ufynzyt2YXRkjb2OCF wcegwXmHeBS216T+v9qXYy0nKwFkztLvXTlWaIW789p/zgAP8ja8K5+3aE084v6nKQvG vpEw== X-Gm-Message-State: APjAAAUMLfLSJHNmz3haVvRzxvyzqNgLSrDg/keVEDIay7xV6fPz2CNY 2KvUcgLdi/RuVtvQ3FH4mUk8FQ== X-Google-Smtp-Source: APXvYqwJGAi05LUeZ2UNwzHqaSW/71sPwIdm7UhzXcI11v3calHrHnj1W72gIC0rQ6qDprzYzyrfAQ== X-Received: by 2002:adf:9185:: with SMTP id 5mr1506556wri.389.1573770155744; Thu, 14 Nov 2019 14:22:35 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id 13sm3897230wmk.1.2019.11.14.14.22.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2019 14:22:33 -0800 (PST) Date: Thu, 14 Nov 2019 23:22:32 +0100 From: Tomas Vondra To: Tom Lane Cc: Mark Dilger , pgsql-hackers@lists.postgresql.org Subject: Re: Missing dependency tracking for TableFunc nodes Message-ID: <20191114222232.o76u6jdvf53ozjjk@development> References: <18427.1573508501@sss.pgh.pa.us> <997cbcae-7739-f871-84a0-1192380abb54@gmail.com> <15228.1573695479@sss.pgh.pa.us> <20191114213124.i6xwx24y26iklzds@development> <14155.1573767414@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <14155.1573767414@sss.pgh.pa.us> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Nov 14, 2019 at 04:36:54PM -0500, Tom Lane wrote: >Tomas Vondra writes: >> On Wed, Nov 13, 2019 at 08:37:59PM -0500, Tom Lane wrote: >>> I concur with Tomas' suspicion that this must be a race condition >>> during DROP STATISTICS. If we're going to allow people to do that >>> separately from dropping the table(s), there has to be some kind of >>> locking around it, and it sounds like there's not :-( > >> I think the right thing to do is simply acquire AE lock on the relation >> in RemoveStatisticsById, per the attached patch. It's possible we'll >> need to do something more complicated once join stats are added, but >> for now this should be enough (and backpatchable). > >Hm. No, it's not enough, unless you add more logic to deal with the >possibility that the stats object is gone by the time you have the >table lock. Consider e.g. two concurrent DROP STATISTICS commands, >or a statistics drop that's cascading from something like a drop >of a relevant function and so has no earlier table lock. > Isn't that solved by RemoveObjects() doing this? /* Get an ObjectAddress for the object. */ address = get_object_address(stmt->removeType, object, &relation, AccessExclusiveLock, stmt->missing_ok); I've actually done some debugging before sending the patch, and I think this prevent the issue you describe. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services