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 1w0MlS-001qb2-1w for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Mar 2026 16:50:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w0MlQ-00AFpA-2T for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Mar 2026 16:50:29 +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 1w0MlQ-00AFp2-18 for pgsql-hackers@lists.postgresql.org; Wed, 11 Mar 2026 16:50:28 +0000 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w0MlO-00000001dZX-40LP for pgsql-hackers@lists.postgresql.org; Wed, 11 Mar 2026 16:50:27 +0000 Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-464ba2bb3aeso70582b6e.1 for ; Wed, 11 Mar 2026 09:50:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773247826; cv=none; d=google.com; s=arc-20240605; b=PIhjF5j03zjHy8aF+EecODpx3t7eL5SHRt180cofT6W4ZfEYmiWKmodEOh2uKK1j3I 6Kd8lzKJoAkou015esZfbvZ2BC7sa2vnvR2OaWtHSLzew77WExrSZLwB4SuglAJRmMml LbIZDwhQ+5S8lJCNai27ahGezkijWstnubW11m3l8oW0+ramoq3ElgJYU9Wpr+ugmVZI 1L8cL0FGx1DPBN7D0uNUGBzc1EmD1IpqU4G8ocRBfvczbaO1p31RrJbggbGGu+nTHnT1 ARAgnRoX8lvrT0rk8PZwHfK0zN4eCob3Af0htsY7l8tHdHtAg4cUwZyXQNOKidctqs3s JF7g== 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=0Gsl1CNLlZd3lCIVh+2BGSa40ZDGlby2kCQqu/v2+LM=; fh=hEo+hMfaqBBAmLdHlhvmF9crG1Uf8FBJhiTDq+QQrTU=; b=FZHXaiH3pMLJncxl4NJUAGLm0EvgmwOZ/wBj31nXEhix41u6gtyY8vOERElpb78KQ0 RtVqrwFHgGu1Sj+FsKBaIzpHKXQeL2zGuk2i54knz6oVFtqNdItNqsYibCilWL3QUxMr YupwLUe20H9dHX/WQJeNWH2JRl4MUagUBpZu3GJhkEvRG0zIbKQigJO6qx4gwh9uQuzV y10mVoxb4vT9HNtJvBtdj++rFegcD2TkFkIsu/oKOFMOVRvvS1sc5sdexVgjXAM5MpyH UXnviBlJjcSYdVxeCUlUH86k33gKoBnefO92/hiaeOx305hm4vy1gszXp7BUmXAYiN5F p5bw==; 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=20230601; t=1773247826; x=1773852626; 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=0Gsl1CNLlZd3lCIVh+2BGSa40ZDGlby2kCQqu/v2+LM=; b=ZYvRz7H4/cvQQXwdMHBER4LeghETTE5cY+G7cmOFT45kHxLiHdyE/GjIxWZU9hBvOh HowXJNvBli97mUN3ZXYaLItyewuovDjHuAJDgIwHBK6Kb7KpEapGNnpd9pXaPd4z6tL6 t4/sTV/MZHETPP/26LEO2J+wyw+5LAQxdO9K/EbcZN9q0UH789IhGLv0fZg8EQVOusJG HM4buoe2M5iRjHASQ5jQo5IQv5WUYn9rz9GWngO3i5o22yirCGlSfb2WZv0Gu4TukYzP vdMEs5IFGRhXe7xp6sRKXsiTjEAWpSEngPJRjcc/oXNupZF/35aHv4PGxbFvJH3jVy43 oE9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773247826; x=1773852626; 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=0Gsl1CNLlZd3lCIVh+2BGSa40ZDGlby2kCQqu/v2+LM=; b=aY++lgoKQjZdqSVP03bS6AENgX7X8E3AnjjLmHS/WIviHgjrQwoS6CorAFJgeV3gaG ImRrkGxEMU8sqCJPEUi7qnjCzFMWlOqP4jf0XaOmgXoWv8PRfsC4vv6ftGCx/nHOwnxv 3ugfaN06Zofq74M6kX2/VhVxXuauPtYg08GrbnwKDUrY0Vi+7NvZcyXkIlIFyIXUPh2a P0UVLqNRCIY2SQRPZA4p5KT7I8CeVWL5Tbt8wp/MH7XjoK7s3GU+J36eNyJqHP56mzja O65yII9ISVTtwk/3viBuCi9c/LYVvBC82zJ/oZD6Eh8CZYGMsa7c4tv5pkzdf/stmh0a I1fw== X-Forwarded-Encrypted: i=1; AJvYcCWK3Xx4OtZZEUTbIjKJWQymKxJXcgMo7VyFbdhf6f7AmpiQchytz2Ix5cztv1BxuIA0Bi3JbkN840379Hmn@lists.postgresql.org X-Gm-Message-State: AOJu0YwuVTFsV7Rg3JZR9YSlEDkIgFpP78rWUeUrISsaZiKWJJ23MPoY xSFub21orG2S+pXp85Pw9OxZT0QNdDpc+/Yy/C1KOztcLpfk5179rjyjvt2H6gulXfj357voPAk W+8K+UYh0tWywTyOww7aYjVxYKuce58s= X-Gm-Gg: ATEYQzw0pX8Cma7GCuRZsejDM+2grDZcfc3uQjZhkrsu9BCrxqZChzi7SyHC7zfxFVv rr6z1xutDckhRJSMpyQR5Sqh817jPf8rFu/2AU+mm02uXgCmKAU8IddBfBlNhosxZsq5/93+YT+ iobe6JAPPYuRmPL2TFwcXx9fsWmfxj4GLsVL4I/EbhwYDFbGHVEU0RYzO+ATaVqyMOOqMJjA9rG LWMdZZjItoyP+E4vxqJKYzJE95Yv2kMhrkSJrcRNAjDvm3Ss8UiRyjOL145GDLrtQMSfeasd190 QGASa0rRkNN+GUVqNAi1SSMdCmAsMpKKs4yMNZ4fRw== X-Received: by 2002:a05:6808:23cf:b0:467:1643:8c92 with SMTP id 5614622812f47-467430393ebmr146813b6e.7.1773247826316; Wed, 11 Mar 2026 09:50:26 -0700 (PDT) MIME-Version: 1.0 References: <2422E6F1-685E-4349-AF8A-684C801567B1@gmail.com> In-Reply-To: <2422E6F1-685E-4349-AF8A-684C801567B1@gmail.com> From: shihao zhong Date: Wed, 11 Mar 2026 12:50:14 -0400 X-Gm-Features: AaiRm531a_cXxK4BIvwZrVL1vt_R-bmjIReUuLALkQ2AR3-F9LpzyTMamVzqP9g Message-ID: Subject: Re: [PATCH] Simplify ExecWithoutOverlapsNotEmpty by removing unused parameter To: Chao Li Cc: zengman , pgsql-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 Tue, Feb 24, 2026 at 5:43=E2=80=AFPM Chao Li wr= ote: > > > > > On Feb 24, 2026, at 23:09, zengman wrote: > > > > Hi all, > > > > I noticed that ExecWithoutOverlapsNotEmpty() accepts an atttypid parame= ter that isn't actually used. The function only needs typtype to distinguis= h between range and multirange types. > > Currently lookup_type_cache() is called just to extract typtype, but I = think using get_typtype() directly seems more appropriate. > > > > ``` > > static void ExecWithoutOverlapsNotEmpty(Relation rel, NameData attname,= Datum attval, > > - = char typtype, Oid atttypid); > > + = char typtype); > > > > /* ---------------------------------------------------------------- > > * ExecOpenIndices > > @@ -753,11 +754,10 @@ check_exclusion_or_unique_constraint(Relation hea= p, Relation index, > > { > > TupleDesc tupdesc =3D RelationGetDescr(hea= p); > > Form_pg_attribute att =3D TupleDescAttr(tupdesc,= attno - 1); > > - TypeCacheEntry *typcache =3D lookup_type_cache(= att->atttypid, 0); > > > > ExecWithoutOverlapsNotEmpty(heap, att->attname, > > = values[indnkeyatts - 1], > > - = typcache->typtype, att->atttypid); > > + = get_typtype(att->atttypid)); > > } > > } > > > > @@ -1149,7 +1149,7 @@ index_expression_changed_walker(Node *node, Bitma= pset *allUpdatedCols) > > * range or multirange in the given attribute. > > */ > > static void > > -ExecWithoutOverlapsNotEmpty(Relation rel, NameData attname, Datum attv= al, char typtype, Oid atttypid) > > +ExecWithoutOverlapsNotEmpty(Relation rel, NameData attname, Datum attv= al, char typtype) > > { > > bool isempty; > > RangeType *r; > > ``` > > > > -- > > regards, > > Man Zeng<0001-refactor-Simplify-ExecWithoutOverlapsNotEmpty-functi.patc= h> > > Removing the parameter atttypid from ExecWithoutOverlapsNotEmpty looks ok= ay as it=E2=80=99s a static function and is only called once. > > For the other change, I see a difference between lookup_type_cache and ge= t_typtype, where lookup_type_cache never returns NULL but ereport(ERROR) wh= en oid is invalid; while get_typtype will return =E2=80=98\0'. Though ExecW= ithoutOverlapsNotEmpty() will end up also elog(ERROR), the log message is c= hanged. > > I am not sure if there could be some edge cases where att->atttypid could= be invalid. If yes, then this change will lead to a small behavior change. > > Best regards, > -- > Chao Li (Evan) > HighGo Software Co., Ltd. > https://www.highgo.com/ > > > > > > That patch looks good to me. Thanks, Shihao