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 1kMMv0-0005Mv-DC for pgsql-hackers@arkaria.postgresql.org; Sun, 27 Sep 2020 03:00:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kMMuR-00021B-4J for pgsql-hackers@arkaria.postgresql.org; Sun, 27 Sep 2020 02:59:31 +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 1kMMuQ-000214-P3 for pgsql-hackers@lists.postgresql.org; Sun, 27 Sep 2020 02:59:30 +0000 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kMMuH-0002yQ-UD for pgsql-hackers@postgresql.org; Sun, 27 Sep 2020 02:59:29 +0000 Received: by mail-io1-xd41.google.com with SMTP id z25so7577782iol.10 for ; Sat, 26 Sep 2020 19:59:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-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=q7Ed5Jyf9ilD+flGTgIfu9EdTvworOAnc0/vEgL88ZE=; b=L3ZAO843TPhzhcTSrBfhX1hGJqBWdflzAUuKlFUDcbGiUvSq0KVxQ0li0KX5ZGt6ef A4gHAgYVcMVa2C+PEKknvvWDZEdBL1b26cTFF2H/XWE+oeL7LTHb11sBs+wv/EYtNppU 1pP1Ebk6bbXoSauQ2X83xLNnCCQ3HkxvcL/1Qg5hy/SlvE8iiJrGM/hjYb0xYidNHNP8 HU9ho9cnWOeIRWfvbf8NAxnlA8P3/TfwOv62/V4oiBu8ZG+aDQWNtdJoVTrEQhawiajj y8Q7E8SSNrPWZJbZGDm80DlPSgVWx1yLSGltO14rUUWrczXwB6h/wzpr20FJWI3O4ljX QiYg== 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=q7Ed5Jyf9ilD+flGTgIfu9EdTvworOAnc0/vEgL88ZE=; b=OMkvwSRF9h4u/aJ+2RhJvcg6mdXzlJ4UyXH/ONB/sjRQ+ZnVcmAttabjU31s10XzsT pFzYDhTvcgBEX/OYqLlVbaAaDJnDibMF2A4i2K504iuk3JTZOm9SCkhSESrI2P7G71Dq DbgZ8LuLS8c9QLDdH7d0Xn+7R8DEGRZ7z17gERrjAjukS1WSdt0RVMiP359G9OZceY3V S/pmuuCgupZbhYGWoZnK/YPInGgJrvCsuk2X/0ktLLCgr5EAv2tOafz0+m7T/dF58zwi pPmAuahko3CINdGFKX8Fn+E1pFeLIx+mPM5EL4sy29LXggOBZt+ZN5GN3uivL7fUnzfm cpgg== X-Gm-Message-State: AOAM532KVy/4Y4aUNs7Bpz51McoKtX8Z3oV6NNq6pAHFL6Yv6QEjBvN/ V79KujMuFhEabGfxlKV3T0XTr8FePjaOvg== X-Google-Smtp-Source: ABdhPJxPhQDFba6rFHvsFCb7XNLKB19OpGxXOIYnj8im5UhfO9x+1MQd3f6vvLjNq/gnnageH4mF4A== X-Received: by 2002:a02:9986:: with SMTP id a6mr4600843jal.28.1601175559394; Sat, 26 Sep 2020 19:59:19 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id r8sm3207967iot.51.2020.09.26.19.59.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Sep 2020 19:59:18 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 7E2D9800581; Sat, 26 Sep 2020 21:59:17 -0500 (CDT) Date: Sat, 26 Sep 2020 21:59:17 -0500 From: Justin Pryzby To: Antonin Houska Cc: pgsql-hackers@postgresql.org, Andres Freund Subject: Re: More efficient RI checks - take 2 Message-ID: <20200927025917.GB13816@telsasoft.com> References: <1813.1586363881@antos> <65467.1591370203@antos> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <65467.1591370203@antos> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Jun 05, 2020 at 05:16:43PM +0200, Antonin Houska wrote: > Antonin Houska wrote: > > > In general, the checks are significantly faster if there are many rows to > > process, and a bit slower when we only need to check a single row. > > Attached is a new version that uses the existing simple queries if there's > only one row to check. SPI is used for both single-row and bulk checks - as > discussed in this thread, it can perhaps be replaced with a different approach > if appears to be beneficial, at least for the single-row checks. > > I think using a separate query for the single-row check is more practicable > than convincing the planner that the bulk-check query should only check a > single row. So this patch version tries to show what it'd look like. I'm interested in testing this patch, however there's a lot of internals to digest. Are there any documentation updates or regression tests to add ? If FKs support "bulk" validation, users should know when that applies, and be able to check that it's working as intended. Even if the test cases are overly verbose or not stable, and not intended for commit, that would be a useful temporary addition. I think that calls=4 indicates this is using bulk validation. postgres=# begin; explain(analyze, timing off, costs off, summary off, verbose) DELETE FROM t WHERE i<999; rollback; BEGIN QUERY PLAN ----------------------------------------------------------------------- Delete on public.t (actual rows=0 loops=1) -> Index Scan using t_pkey on public.t (actual rows=998 loops=1) Output: ctid Index Cond: (t.i < 999) Trigger RI_ConstraintTrigger_a_16399 for constraint t_i_fkey: calls=4 I started thinking about this 1+ years ago wondering if a BRIN index could be used for (bulk) FK validation. So I would like to be able to see the *plan* for the query. I was able to show the plan and see that BRIN can be used like so: |SET auto_explain.log_nested_statements=on; SET client_min_messages=debug; SET auto_explain.log_min_duration=0; Should the plan be visible in explain (not auto-explain) ? BTW did you see this older thread ? https://www.postgresql.org/message-id/flat/CA%2BU5nMLM1DaHBC6JXtUMfcG6f7FgV5mPSpufO7GRnbFKkF2f7g%40mail.gmail.com -- Justin