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 1wMPMe-0003lJ-01 for pgsql-hackers@arkaria.postgresql.org; Mon, 11 May 2026 12:04:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wMPMc-000gEB-2N for pgsql-hackers@arkaria.postgresql.org; Mon, 11 May 2026 12:03:58 +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 1wMPMc-000gE3-15 for pgsql-hackers@lists.postgresql.org; Mon, 11 May 2026 12:03:58 +0000 Received: from mail-vk1-xa35.google.com ([2607:f8b0:4864:20::a35]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wMPMZ-000000002DI-3btx for pgsql-hackers@lists.postgresql.org; Mon, 11 May 2026 12:03:57 +0000 Received: by mail-vk1-xa35.google.com with SMTP id 71dfb90a1353d-5752b27958fso1280362e0c.1 for ; Mon, 11 May 2026 05:03:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1778501035; cv=none; d=google.com; s=arc-20240605; b=B1ot6aYY7j4SMEC8X/4GL0Dw5bx2DJbqcFQ/GxD9cK9X1vEWaiZVrj7c995u6dtFFA zEM7JiWWZ89OgvmwUOzHys3obHGn8H4+7k1VEUuKOpylUnyFe9u66WwAaCHi3xlQcuoA c+tNnpCe29OrYkg4OoGceExOCcP/NkrgP95z7lsS5Uqi3NlfqRlTDgavBNQBRr/oiBEm v5z5iL2/l9vytLvZDfvGuPioijzgdVnQ6h5Ni7r2VS9qTejYlj+8ZR62nX7fifRqmcGc JbGn/8QhA+/2ib6eOnop3qHzkNuN1JILRkQmM7LSgPZ7UuK/OOTI9RUe4dfBT6QryuiY oMYA== 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=ZFbVzoX8PuTSFA57CqYmJYInpTeYSPaZF9an9gU9fOY=; fh=Rv57mx5ufJIyVfQLabdk2XeRZYnJH9TBlw1W2l4AzGA=; b=auBY+9kUz9ZA925OUtb5MAe+1QIAIUiktpQg2I7AveadeQ1M0OpXINYDDJOJ24byQT FOSRnYu/Hlju8ehMCeLIpDvsR+zi6r+b4EKiQ0SArfAH6+RK5bqKZp22VicGPTG1UzBJ 9HlYs/6xeCAoIsNP3rElWnCx67G3fgtM0D74uacwfQPtAZo++cmApaQhJ/62PCwhY1Y2 9K8smWN+EEPYIIpdHr3ofyQQKcUIeIB0q376DVagBAFOUVfpuPxKD3K3ehQj+ugOmZcT uKFRUb+aav44U1NJ3L4aDnx9zxMkxdIJL2DTPKdltOQoVsn85ghhe0dbeI+iCddR1PAW f+5A==; darn=lists.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=1778501035; x=1779105835; darn=lists.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=ZFbVzoX8PuTSFA57CqYmJYInpTeYSPaZF9an9gU9fOY=; b=pDcULjxBqi0hyqr0hL3tWa+OFUIeTBXX83FzBiyzq/PH4fh+2mew+tOTFZr7FTr1Xn puVExsfA7N+JmwftpAFuEy0l6TNXHerXjfoA5sAUDzga7Ad1shwppwbdqdM1fNQknmf2 rrz3X4S8pgOF0E7y8L5v98TiysvShMFuc9eSJc02madmXyCaAD1M9da/lY3N1WSBZ+aQ 9qiIaVXE3EvMYo22hz3OKyNUMNQvesnqX0EQzyv74hC0jJy6DdjqMfGdGKfVzC9ttGK3 urUCDKOYDCsZUbJEYxxv0rXDpaxFfto4WldUJc9r9cU+4eTn087IkqTTVo7/cUlCf2FD VhwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778501035; x=1779105835; 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=ZFbVzoX8PuTSFA57CqYmJYInpTeYSPaZF9an9gU9fOY=; b=KtGQcpQ+ID4FJY9t31xXw/Qkq8uEkHlWIBu3fZEoh6xg2cYSg0NkwhR7FiQQj25sZK lnLWu7t5o8sIlHmL3LsLx6t9IVM+hBllG/MbGhtVXKAAFdZbp2+SJFUQiEwtgJA16uNF 23nnaktSDtJiNupASDptEB9QR2Pr/IVeMoWpppu9Nf8KfldfshU336EWiKcAo4egYJWh kIAMBOHATaahxeWJ7rCmT+VH8bivgsaqM5nbNkcjNrLzMbaqb9yNSlIaZkFU+LCo5aCH ljfRscqMffRw/Mzsq1Xz3ytYsZsCHj/7oWlBVM5DL/3NsioWAU/asHiFjO00oi3CrO24 qQCg== X-Forwarded-Encrypted: i=1; AFNElJ+jEpPrYNDYmptqAaqZnLjyTxTAZbzCX7gAHL0R+BXhKZ+uIt6prvSMINxtWkJrXfZFD9i8MdmIuRiGMmwn@lists.postgresql.org X-Gm-Message-State: AOJu0YwpYPp70S15I5tHTwLS0i2CCie1XQmWfE+UGB4y2su0xJuL3WYx hA7nEGfN4vBEg6my+XegBhY/CabzjyQUGUOAio2UPnQmCUFouAt+Wh2aTV0r5BEwD6MNmibvYTI M7d3TWD8aaNrNUCO8tXzC3k/rsIBcJK1xdjMQzwpeLw== X-Gm-Gg: Acq92OFmLvRfyHdPqz8IDxfN2qom7umAeJjnRhNeBG1WkKwFJgODVyZGo7pY87BMPhf 4yBf3zueC2foSEg7+BOXAOKvy1vMdOUpZL8rZTwn9g/HajyqA2NwEvkC/NO/3R2vngLe0Ngyuz0 fY/c++X4u8Je/aYOGXuxraxb02yGoMAtcPnmhPA3R5RgRVhZRLU87vcyYrwrcW2/3I4F6vKbCe3 r0vs7ePwSm6Ww7QHexRFMLjLMH6GorXGleY/VXldECEe5NgkiXBmjEmYerYuKl7/WfHvzCrtraM 9yw6WnTKxmzqifbPoNe6wTW6/A0EXlNLqneMCUzyRnYlsqBEUuvYPnt2tp2rUwYEu3rn0KUmtm0 qxbDx9wwWgwV8dtOrG9BKnHpIhK3XZzD+luJdT5ApV4U9Uv8Ps/aEl0AWcLuDEoj98G/fR9LKW6 rJc/2ZpZD8GCqtRAoi0fsgo8U5KzZA4B0= X-Received: by 2002:a05:6122:8b0b:b0:575:1711:a9c4 with SMTP id 71dfb90a1353d-575596e4079mr8211335e0c.9.1778501035338; Mon, 11 May 2026 05:03:55 -0700 (PDT) MIME-Version: 1.0 References: <27BD5D23-19C9-4FD1-8935-9C788C3C9869@gmail.com> <66C1555B-CA54-4ED1-AB4F-0EE97D24A006@gmail.com> <91B35E0F-5DC1-4417-A1B9-FAF4A3DCD2BD@gmail.com> <74C1863C-2C2A-423A-BDE7-0228889F1D80@gmail.com> In-Reply-To: From: jian he Date: Mon, 11 May 2026 20:03:17 +0800 X-Gm-Features: AVHnY4IOVjVn6F1UcZJaylmaIgyf4aiv_KxKf48vIXB-paumxWgYvHYx4cFSIxo Message-ID: Subject: Re: FOR PORTION OF does not recompute GENERATED STORED columns that depend on the range column To: Paul A Jungwirth Cc: Chao Li , Peter Eisentraut , SATYANARAYANA NARLAPURAM , PostgreSQL Hackers 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 Fri, May 8, 2026 at 11:25=E2=80=AFPM Paul A Jungwirth wrote: > > On Fri, May 8, 2026 at 12:10=E2=80=AFAM Chao Li = wrote: > > > > > > > Thanks for updating the patch and making the separation. After reading = v11, I still have a few comments for 0001. > > > > ``` > > + if (relinfo->ri_forPortionOf) > > + { > > + AttrNumber rangeAttno =3D relinfo->ri_forPortionOf->fp= _rangeAttno; > > + > > + if (!bms_is_member(rangeAttno - FirstLowInvalidHeapAttr= ibuteNumber, > > + updatedCols)) > > + { > > + MemoryContext oldContext; > > + > > + oldContext =3D MemoryContextSwitchTo(estate->es= _query_cxt); > > + > > + updatedCols =3D bms_copy(updatedCols); > > + updatedCols =3D > > + bms_add_member(updatedCols, > > + rangeAttno -= FirstLowInvalidHeapAttributeNumber); > > + > > + MemoryContextSwitchTo(oldContext); > > + } > > } > > ``` > > > > 1. I don=E2=80=99t think we should unconditionally do bms_copy, only if= (updatedCols =3D=3D perminfo->updatedCols), we need to make the copy. > > You're saying we can skip the copy if execute_attr_map_cols already > made a new bms above. That's true. Since we're going to just use the > current memory context (see below), that seems safe. > > > 2. I doubt if we need to switch to estate->es_query_cxt. Because ExecGe= tUpdatedCols() is called by ExecGetAllUpdatedCols(), and its header comment= says the function runs in per-tuple memory context: > > ``` Switching to estate->es_query_cxt can actually save some cycles. See ExecGetExtraUpdatedCols->ExecInitGenerated /* * Make sure these data structures are built in the per-query memory * context so they'll survive throughout the query. */ oldContext =3D MemoryContextSwitchTo(estate->es_query_cxt); In ExecGetUpdatedCols, we can change it to the following to save some unnecessary bms_add_member cycle. `````` if (relinfo->ri_forPortionOf) { AttrNumber rangeAttno =3D relinfo->ri_forPortionOf->fp_rangeAttn= o; if (!bms_is_member(rangeAttno - FirstLowInvalidHeapAttributeNumber, updatedCols)) { MemoryContext oldContext; if (updatedCols !=3D perminfo->updatedCols) updatedCols =3D bms_add_member(updatedCols, rangeAttno - FirstLowInvalidHeapAttributeNumber); else { oldContext =3D MemoryContextSwitchTo(estate->es_query_cxt); updatedCols =3D bms_add_member(updatedCols, rangeAttno - FirstLowInvalidHeapAttributeNumber); MemoryContextSwitchTo(oldContext); } } } ``````