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 1jRJ0p-00020n-EF for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Apr 2020 17:18:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jRJ0o-0004mX-9w for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Apr 2020 17:18:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jRJ0n-0004mQ-T7 for pgsql-hackers@lists.postgresql.org; Wed, 22 Apr 2020 17:18:14 +0000 Received: from mail-qv1-xf43.google.com ([2607:f8b0:4864:20::f43]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jRJ0l-0002O3-8o for pgsql-hackers@postgresql.org; Wed, 22 Apr 2020 17:18:13 +0000 Received: by mail-qv1-xf43.google.com with SMTP id t8so1272396qvw.5 for ; Wed, 22 Apr 2020 10:18:10 -0700 (PDT) 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:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=zzE9oqHqs1NYtkEP7Ruf37gUA6HvgXls1t8h/miSF08=; b=qT2H6yKvmQmCV+XWvheIdwlfwWsa5OmoDNP54IZ/aX6KjDU1h2+gDWxE6ORTKCU55P nhkyRk35gQ0sGugmLr5jdHOhNAUXtmEvUD0u33D3QH1x82d5lUTLWyXAYegATwDSC1f0 1nmdXJPBW13lCX+mv/gQf6mVQh97ytw9D4qSFqCkWguasPIOIchNZSApz3uilvmCovLq KZzPXQFk5CqEJcL5LgAV+lxxur1TubrpClOkKsw1LlPSFsDoTUelwVOw0HZ0qRfXqP9Q HwfRaAVhku7bzMRMD+qNNyu6HBl+OKwL1HIxgwcehbmV6m3e/pj67/KG9hp4rNAL/ZXM sR8g== 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:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=zzE9oqHqs1NYtkEP7Ruf37gUA6HvgXls1t8h/miSF08=; b=CYXxUiY/VeKOsicvwhkNASvBude9UJOXsuf7m6gGRLdbkAcSI0AOUIa7ly8EKCCTyH xSpEjdXOkexHyGN5j5yXgMtF6Mm3LW0P6aCypOW4JmAUaYdizUvsCU1g6UDc7Jwkt+PP FWo/rBhijspGoIv+q2pthrFD9aMQMcRwJ+cfQzgMbtKZiSZqJMX3d7Fi6Op+AURGYezG ywLyYlhbqLeeAX/Rt6r2WumJfUn27+VW7At5CxUyEkTpGXBN8qL80L6H0XsK+ODoaUKa kSBtBeljfWxcYk6cFnYAehVvDBNOfkvh9+EwQ8xncHFv7lRxppomZNAb9H+s4V0/osYO DvKA== X-Gm-Message-State: AGi0PuYCeIVw4SqGYKRjvQs6SsCxMHhIfNGTG3Do2kXUR4oN0/ZBOc8G FC5Kv1SKUVH6g/hk1RhRbKE9aw== X-Google-Smtp-Source: APiQypJJZHKYroHeDgLPY4B9Q8DQ58AG8jwv/QmUBEqDzQ8TVI0rlr4ITLVrBQvFL2RbHQTHX5SyLA== X-Received: by 2002:a0c:99e9:: with SMTP id y41mr15258810qve.164.1587575889503; Wed, 22 Apr 2020 10:18:09 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id b201sm4304161qkg.32.2020.04.22.10.18.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2020 10:18:08 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id BE76330142C; Wed, 22 Apr 2020 13:18:06 -0400 (-04) Date: Wed, 22 Apr 2020 13:18:06 -0400 From: Alvaro Herrera To: Andres Freund Cc: Corey Huinker , Antonin Houska , Pavel Stehule , PostgreSQL Hackers Subject: Re: More efficient RI checks - take 2 Message-ID: <20200422171806.GA12435@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200422154231.6shz4kdor4yb5w5b@alap3.anarazel.de> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-Apr-22, Andres Freund wrote: > I assume that with constructing plans "manually" you don't mean to > create a plan tree, but to invoke parser/planner directly? I think > that'd likely be better than going through SPI, and there's precedent > too. Well, I was actually thinking in building ready-made execution trees, bypassing the planner altogether. But apparently no one thinks that this is a good idea, and we don't have any code that does that already, so maybe it's not a great idea. However: > But honestly, my gut feeling is that for a lot of cases it'd be best > just bypass parser, planner *and* executor. And just do manual > systable_beginscan() style checks. For most cases we exactly know what > plan shape we expect, and going through the overhead of creating a query > string, parsing, planning, caching the previous steps, and creating an > executor tree for every check is a lot. Even just the amount of memory > for caching the plans can be substantial. Avoiding the executor altogether scares me, but I can't say exactly why. Foe example, you couldn't use foreign tables at either side of the FK -- but we don't allow FKs on those tables and we'd have to use some specific executor node for such a thing anyway. So this not a real argument against going that route. > Side note: I for one would appreciate a setting that just made all RI > actions requiring a seqscan error out... Hmm, interesting thought. I guess there are actual cases where it's not strictly necessary, for example where the referencing table is really tiny -- not the *referenced* table, note, since you need the UNIQUE index on that side in any case. I suppose that's not a really interesting case. I don't think this is implementable when going through SPI. > I think it's actually a good case where we will commonly be able to do > *better* than generic planning. The infrastructure for efficient > partition pruning exists (for COPY etc) - but isn't easily applicable to > generic plans. True. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services