Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w7uBP-0000o9-0Z for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Apr 2026 11:56:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w7uBN-00HG3R-2m for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Apr 2026 11:56:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w7uBN-00HG3I-1S for pgsql-hackers@lists.postgresql.org; Wed, 01 Apr 2026 11:56:25 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w7uBL-000000000H9-41n2 for pgsql-hackers@postgresql.org; Wed, 01 Apr 2026 11:56:24 +0000 Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-66dd1b5bb6aso1015767a12.2 for ; Wed, 01 Apr 2026 04:56:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775044582; cv=none; d=google.com; s=arc-20240605; b=CE5TDy4DPfFxWc0KAaqQYbfspOqhtqNAd5tbruE0zjSbJ28hwlr09S+sfD2nk1XaTj d4uq8WVbduc9zjqfZXO6/vDZs3rolTM/FHkd1KjeBL+iFM0mK7lOARc6eZ3ciS8tOth8 ETdW53Xflhk+TPRekCITX63wZA7lA5ChDo6R72JkRqgFFy9eA6Q5wm20nElUT7D5u8kx zr+lQbop4DSHa+fXaCpjuApdjfUdhaqABJ6MXPJSAgRppm7NxmF03FEF3tZCTecxFoQS Kzeqzw61r7SSlBEfNV7umpfsXvNDkIGSZGLlu19iwzBLu5nKQANFCEz4rbp/MJtPK2PS 8/8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=fmD8Iff7RkzI90k0cu+XlKIsxIgaZy0Owml6G0MvTOQ=; fh=FOANvtcxLlP16Jl9l46KPh32ftIrstwRvdvXT2edaIA=; b=VM6NKDBLAIKVKfHA66pmY2slAssBriZKSrO3+nhdawRfFh7K9uMc1SiFTRGgEoCPnR X77TD0/ozygLbwQavPq2kB/PKZcOEyHOBVxK+5HyhK4reNP1EbHeoWB8ctj8tOfT8C6E 8UW5mBaqAuyljzcJYXbvvD1ZHCzBhK1gllUSXLfxpJUziQNawk6XQa2nMh+Dh5GhG1b0 vt9PUSgLfC2IqHOEATxj3sULqYL5GSoFfXlS6cxAFkOFaTEHzReihK0ByMi+0WUxzBV/ Eu7wAuJ5sBiHacIBjLX5Ag49396jwg6lmEEGCTcWEAtvkhrLt4QXU7z7sI8TIdVUFqjt H3LQ==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775044582; x=1775649382; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=fmD8Iff7RkzI90k0cu+XlKIsxIgaZy0Owml6G0MvTOQ=; b=dckNwb49eVM1qDsd6mzZV1/5K29Ng59mztXPPiKBSx85BgUvq6xyaoNC48vDHoa0et X9YsQzwK/EddUxBIWIl8YbPSO2MsVzdqzvmlnFSXf2uAhgfRWT8kawYuxFFpGbnbAu1G oTln1g/wOhKNADVflvWePVXuRyH1luHIPUYi3pGLz/qvyIUCNcuh5g5hpGpkvJpw7zEN ph9JZfIm65MZ/49oYwebPzXUJwctth5e6Y/F4tj+VB8KtZ3ZgMYVkbPxq4TQKVpJHIIM xz9X91kBpCDrFOWK2V/O600sXdqJ0Cd6wFRELFOQvzFbh+Tcv7L8nrC8XdtQdT/jeg+h cZ8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775044582; x=1775649382; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=fmD8Iff7RkzI90k0cu+XlKIsxIgaZy0Owml6G0MvTOQ=; b=QWMHQxSFPAPNLOPMnVrmVfaLCLK6QLD+4ANb3xjrBQjs6/r/GaPMSxv6eGgRtVwa+D MwSAaJiALFFYckst2/MMMs/7/nrZJ5aukuO+kiDUZk7XhF2H4lLToXw8I7yRoGWinwZZ +IYm35dUluHnNRCzaWW9AHs9dHTEpMn6KwXK2LklEOu0oFx+rqHyTLzX+iywDvmwg5K4 8KXkE+X9njW0T886yNhyjUtBcwC+1SoIyrCByMLSJ1Obz55xwOkrbnshxqetPt9oqyfG 2p7ca2+xdjB2InyLH1bWouA+mKvttQn1/7lwhuv3X/BIMv4r1c9XIiUjvnDa6+pl/Vs8 Foeg== X-Forwarded-Encrypted: i=1; AJvYcCX4b3Xf3dWNlPTOou2gSVkRDimJJJr9PTqP4GrRkINVNflvFrz+MF9I95Vw0BhKDDYO/iF8F5yAmzwWki5a@postgresql.org X-Gm-Message-State: AOJu0Yy5pjbgrx5ufiFpkCdkOWZNxq1O7MQXlsTT+ay5MsaaGLM+DZAn TbuEYKjyjdSsrT+VyMsQddmenNaep8nccb+MCPk9KhIX4WBFZPlN7+26rptkIcjypEEDw8ToWYz mHBdDa4Qx0uvE0MwvNMbpvFtFNl1bzjA= X-Gm-Gg: ATEYQzwpbGAPNZB3RMLdRMZR5cs0dVvh8wGnGiXlQMjU5HdwvFYepoUk6sJrUnav0rc phkB6KKJNJrGbSbsXTYKolvc7AnYKOLSGl3UmXXD0vkDtPsXBDnOSWKYb4yOwPvEhEtaN0Kzkvd +zzoJQL6tCDAJgJ+F5ptMfWDM1aF49wTTVy+XTRlxXOBvREzrygtYdV558V/q6nVnIg+Lw3OGhp UQXcARft+qmS4lLE73JXPprUZ+3fsgwACQds8DrSx2uPb9FEhpECi01mKY1v1f38NryorWscsLh DfSoWahJZkmesFTXoJslWfuWG0qoVdcv57sUpy4ts4aOwnViI2fExdk4gW29aWf3jfLqagJAmXX PzkTx X-Received: by 2002:a05:6402:22f0:b0:66d:d077:d18a with SMTP id 4fb4d7f45d1cf-66dd077d35fmr965956a12.12.1775044582324; Wed, 01 Apr 2026 04:56:22 -0700 (PDT) MIME-Version: 1.0 References: <2BE661BA-D909-4093-BF78-DB9B0C099337@gmail.com> <77FA04FE-1F84-4DA1-8855-8BBFD8CC889A@gmail.com> In-Reply-To: From: Junwang Zhao Date: Wed, 1 Apr 2026 19:56:10 +0800 X-Gm-Features: AQROBzBqtuMzI7dJ1FK7rFurDmoavAl0CjwM2Kdw9UVAhr4bltzJjcadbmpn1xg Message-ID: Subject: Re: Eliminating SPI / SQL from some RI triggers - take 3 To: Amit Langote Cc: Chao Li , Haibo Yan , Pavel Stehule , PostgreSQL-development , Tomas Vondra Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Apr 1, 2026 at 5:51=E2=80=AFPM Amit Langote wrote: > > On Wed, Apr 1, 2026 at 5:51=E2=80=AFPM Amit Langote wrote: > > On Wed, Apr 1, 2026 at 12:54=E2=80=AFAM Junwang Zhao wrote: > > > + if (riinfo->fpmeta =3D=3D NULL) > > > + { > > > + /* Reload to ensure it's valid. */ > > > + riinfo =3D ri_LoadConstraintInfo(riinfo->constraint_i= d); > > > > > > I was thinking of wrapping the reload in a conditional check like > > > `!riinfo->valid`, since `riinfo` can be valid even when `fpmeta =3D= =3D NULL`. > > > However, `if (riinfo->fpmeta =3D=3D NULL)` should rarely be true, so= the > > > unconditional reload is harmless, and the code is cleaner. > > > > > > +1 to the fix. > > > > Thanks for checking. > > > > I have just pushed a slightly modified version of that. > > > > > > 0002 is the rebased batching patch. > > > > > > The change of RI_FastPathEntry from storing riinfo to fk_relid > > > makes sense to me. I'll do another review on 0002 tomorrow. > > > > Here's another version. > > > > This time, I have another fixup patch (0001) to make FastPathMeta > > self-contained by copying the FmgrInfo structs it needs out of > > RI_CompareHashEntry rather than storing pointers into it. This avoids > > any dependency on those cache entries remaining stable. I'll push > > that once the just committed patch has seen enough BF animals. > > Pushed. > > > 0002 is rebased over that. > > Rebased again. +static void +ri_FastPathBatchFlush(RI_FastPathEntry *fpentry, Relation fk_rel) +{ + /* Reload; may have been invalidated since last batch accumulation. */ + const RI_ConstraintInfo *riinfo =3D ri_LoadConstraintInfo(fpentry->conoid= ); ... + if (riinfo->fpmeta =3D=3D NULL) + { + /* Reload to ensure it's valid. */ + riinfo =3D ri_LoadConstraintInfo(riinfo->constraint_id); + ri_populate_fastpath_metadata((RI_ConstraintInfo *) riinfo, + fk_rel, idx_rel); + } ri_LoadConstraintInfo is currently invoked twice within ri_FastPathBatchFlush. Should we eliminate the second call? Alternatively, we could refactor ri_FastPathBatchFlush to accept an additional parameter, `const RI_ConstraintInfo *riinfo`, so we can remove the need for the first call. In that case, we need to call ri_LoadConstraintInfo in ri_FastPathEndBatch. > > -- > Thanks, Amit Langote --=20 Regards Junwang Zhao