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 1jRU4U-00076m-LP for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Apr 2020 05:06:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jRU4T-0007Vh-Gd for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Apr 2020 05:06:45 +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 1jRU4T-0007Va-4b for pgsql-hackers@lists.postgresql.org; Thu, 23 Apr 2020 05:06:45 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jRU4Q-000862-Fq for pgsql-hackers@postgresql.org; Thu, 23 Apr 2020 05:06:44 +0000 Received: by mail-wm1-x32e.google.com with SMTP id r26so5086205wmh.0 for ; Wed, 22 Apr 2020 22:06:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:in-reply-to:references:comments:mime-version :content-id:date:message-id; bh=wT7NidoIfoLmOlZGUJe19sEdCnIA+Qq7dRnKqa+5Ehc=; b=lrkbHuQRBIlrAM4EiM03n1rO1UKhL7RVjDsbRQvlbLWiLNClrcaaARPJtoEA8xFOJi U1YVIK63I4BrBQxPnzeCfSWGEzKdyiLF/PLnsWmvMDWIIvo1c0UP8Lmd4orBqQHuGShy qvuRaPoeTHm3IH9QFH53AVV88+oTem4m+VwCbIHlFfYp53LCkuTYCrGpXFWOAdqI/b1k bEw75XiAOntMhpRIik1chtEKd3cRs3zZmE2eMXzW4TtXPfoF4Q/RgWghjMG5hHwz3jLV CixN/+z75sx6xUailiIVOsfUZCYG1wLXNt/g/0K1N0kC7VJhgPNRwjxE7Q0bvIJ26Ie4 4Lpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references :comments:mime-version:content-id:date:message-id; bh=wT7NidoIfoLmOlZGUJe19sEdCnIA+Qq7dRnKqa+5Ehc=; b=gdSoxCvXjke/qdNoJzjbBjWz5/+4itTrR7yZqIXvYPnTFT1MQf2O92ngYh90nRW0kN tmq74KHK9A9Fq8uEqc+D/gnPPTwEqLhESCPswMg1HllGN+TxzPlsHEDy03HR7kv5jCVb G+N7kvfL0ZIs0zYs7M83XLMvPqFI5ybzGFO6GFgrs/4/XtJTC64l8WyRBClUKF7b7I4d poFpkY551VQ0Ck0EUXeTUgxdbaITHXl6WXyNDjQqq+PYOiqRpyydm+hZfY7BAJUpiZN+ jKe33Kiurs2d0f1advA4Mdi8FztdCcWB8CwpPQwxQ/OuUDwlpsaxZgPjtgrLwUZSyiC4 KYTw== X-Gm-Message-State: AGi0PubbsWSTNq/+PILHVeOOiCaFHNqL2SuxGB0gmd/dAWp8PrkIfLKb fp1lJ5OqS9nUzAZqVAm9rzDDcA== X-Google-Smtp-Source: APiQypKqfu0BJ7jk/lL91iUUAcGkwpbKEjO0I5GVTBMYBIOQR0Tj3FUmh7Ns6xBpodJRCBxA1En6+Q== X-Received: by 2002:a05:600c:1008:: with SMTP id c8mr1969028wmc.14.1587618401128; Wed, 22 Apr 2020 22:06:41 -0700 (PDT) Received: from antos ([77.87.240.5]) by smtp.gmail.com with ESMTPSA id s17sm1762332wmc.48.2020.04.22.22.06.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2020 22:06:40 -0700 (PDT) From: Antonin Houska To: Tom Lane cc: Robert Haas , Andres Freund , Alvaro Herrera , Corey Huinker , Pavel Stehule , PostgreSQL Hackers Subject: Re: More efficient RI checks - take 2 In-reply-to: <6442.1587595207@sss.pgh.pa.us> References: <20200422154231.6shz4kdor4yb5w5b@alap3.anarazel.de> <20200422171806.GA12435@alvherre.pgsql> <20200422183600.tpl5745dfbnozi6t@alap3.anarazel.de> <6442.1587595207@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Wed, 22 Apr 2020 18:40:07 -0400." X-Mailer: MH-E 8.6+git; nmh 1.7; GNU Emacs 26.3.50 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <28825.1587618482.1@antos> Date: Thu, 23 Apr 2020 07:08:02 +0200 Message-ID: <28826.1587618482@antos> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Tom Lane wrote: > Robert Haas writes: > > Right -- the idea I was talking about was to create a Plan tree > > without using the main planner. So it wouldn't bother costing an index > > scan on each index, and a sequential scan, on the target table - it > > would just make an index scan plan, or maybe an index path that it > > would then convert to an index plan. Or something like that. > > Consing up a Path tree and then letting create_plan() make it into > an executable plan might not be a terrible idea. There's a whole > boatload of finicky details that you could avoid that way, like > everything in setrefs.c. > > But it's not entirely clear to me that we know the best plan for a > statement-level RI action with sufficient certainty to go that way. > Is it really the case that the plan would not vary based on how > many tuples there are to check, for example? I'm concerned about that too. With my patch the checks become a bit slower if only a single row is processed. The problem seems to be that the planner is not entirely convinced about that the number of input rows, so it can still build a plan that expects many rows. For example (as I mentioned elsewhere in the thread), a hash join where the hash table only contains one tuple. Or similarly a sort node for a single input tuple. -- Antonin Houska Web: https://www.cybertec-postgresql.com