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 1iV3HT-0005b7-Em for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Nov 2019 00:46:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iV3HR-0001Sb-Dw for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Nov 2019 00:46:37 +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 1iV3HR-0001ST-18 for pgsql-hackers@lists.postgresql.org; Thu, 14 Nov 2019 00:46:37 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iV3HN-0004NF-UF for pgsql-hackers@lists.postgresql.org; Thu, 14 Nov 2019 00:46:36 +0000 Received: by mail-wm1-x343.google.com with SMTP id z19so4018642wmk.3 for ; Wed, 13 Nov 2019 16:46:33 -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=Dhw5RCKIpO1sDtnUacLXfw4SAcAG9uvuZX4TeCHQlo4=; b=pkAhKB8cWHfjeIhO/V654MV2l1h6XxFrprDauGyw2OGPyX0gCvAJCx03q1sRZZQvDn uVhUTSKOyVt6n4XafMzBnb1rnP7kh98KlFt2VajMVbhMaFs5x9Sbufi70nhFGmRiKje/ aBDIQYNjjto3HYSTnVUyb/L/U3aFx5gU41mxmQ3Qie934/xywALhUeCYi/bgdga+YomU VOKXbrsUPwV+Yj4zjJzQW4mF9BZVL1Y7r94mj79yVFDbczDnRaLcA+ua9AZKD631BP0D YidPVm+rM3h/Vsq+9zO+giCZ4VN0Mwi29t22990bm24yLXVClJOW2YxfLvGoo58Oy65P UwSw== 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=Dhw5RCKIpO1sDtnUacLXfw4SAcAG9uvuZX4TeCHQlo4=; b=diGhsIYXETz+uvQWtX4FZ1ZCSXtJ3WnjyMwRU41cDeJGP05fo3CSE0GVg1ReJft3Dx Sf5NKMWVEJ7o742DvED1ZY9D5yF7tJXaWg2UJtGgxpGi8NBv2FX4nP9YWnd/2EHc4Mgd W1R+sVg43XRAaYatNJEN9krO9RytlsvOjAOs7iZ/cNQgkmOHmSTCyr5OuiscXXt9vP9/ iOV3SjnviAXLIGL9p1CvOuh5fmq2+Fjd+m+3rT74QzXmCQFMsOQIQMbdGd11MMBVyR5/ FlJSSpc0z0Gtgfp/GO+Xi+tpYvXf96o3hm43XHr0sUWWaQpWs19xr0LH5yvsk8cSoYFr U1MA== X-Gm-Message-State: APjAAAVgUmNQjnCgaFZM02EP2lOw9mKK0QtUSY6auKL9QeVIgoMNMR8j PiVRF+EuUlhBvmRTpaPPsZpp/w== X-Google-Smtp-Source: APXvYqzLFp6LT7+MvkU66gElQatsOYiqq6EeCvh1eGD1K4O1NEm0YpEsgTWAWyW40QrKCr3W5tf+Ng== X-Received: by 2002:a1c:4606:: with SMTP id t6mr5060087wma.73.1573692392783; Wed, 13 Nov 2019 16:46:32 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id w81sm4866250wmg.5.2019.11.13.16.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Nov 2019 16:46:31 -0800 (PST) Date: Thu, 14 Nov 2019 01:46:31 +0100 From: Tomas Vondra To: Mark Dilger Cc: Tom Lane , pgsql-hackers@lists.postgresql.org Subject: Re: Missing dependency tracking for TableFunc nodes Message-ID: <20191114004631.z4mg5nucvrxiewxe@development> References: <18427.1573508501@sss.pgh.pa.us> <997cbcae-7739-f871-84a0-1192380abb54@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <997cbcae-7739-f871-84a0-1192380abb54@gmail.com> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Nov 13, 2019 at 03:00:03PM -0800, Mark Dilger wrote: > > >On 11/11/19 1:41 PM, Tom Lane wrote: >>I happened to notice that find_expr_references_walker has not >>been taught anything about TableFunc nodes, which means it will >>miss the type and collation OIDs embedded in such a node. >> >>This can be demonstrated to be a problem by the attached script, >>which will end up with a "cache lookup failed for type NNNNN" >>error because we allow dropping a type the XMLTABLE construct >>references. >> >>This isn't hard to fix, as per the attached patch, but it makes >>me nervous. I wonder what other dependencies we might be missing. > >I can consistently generate errors like the following in master: > > ERROR: cache lookup failed for statistics object 31041 > >This happens in a stress test in which multiple processes are making >changes to the schema. So far, all the sessions that report this >cache lookup error do so when performing one of ANALYZE, VACUUM >ANALYZE, UPDATE, DELETE or EXPLAIN ANALYZE on a table that has MCV >statistics. All processes running simultaneously are running the same >set of functions, which create and delete tables, indexes, and >statistics objects, insert, update, and delete rows in those tables, >etc. > >The fact that the statistics are of the MCV type might not be >relevant; I'm creating those on tables as part of testing Tomas >Vondra's MCV statistics patch, so all the tables have statistics of >that kind on them. > Hmmm, I don't know the details of the test, but this seems a bit like we're trying to use the stats during estimation but it got dropped meanwhile. If that's the case, it probably affects all stats types, not just MCV lists - there should no significant difference between different statistics types, I think. I've managed to reproduce this with a stress-test, and I do get these failures with both dependencies and mcv stats, although in slightly different places. And I think I see the issue - when dropping the statistics, we do RemoveObjects which however does not acquire any lock on the table. So we get the list of stats (without the serialized data), but before we get to load the contents, someone drops it. If that's the root cause, it's there since pg 10. I'm not sure what's the right solution. An straightforward option would be to lock the relation, but will that work after adding support for stats on joins? An alternative would be to just ignore those failures, but that kinda breaks the estimation (we should have picked a different stats in this case). >I can try to distill my test case a bit, but first I'd like to know if >you are interested. Currently, the patch is over 2.2MB, gzip'd. I'll >only bother distilling it if you don't already know about these cache >lookup failures. > Not sure. But I do wonder if we see the same issue. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services