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 1nXOW1-0000aS-3E for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Mar 2022 14:32:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nXOVz-0006AH-Vn for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Mar 2022 14:32:39 +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 1nXOVz-0006A7-MZ for pgsql-hackers@lists.postgresql.org; Thu, 24 Mar 2022 14:32:39 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nXOVw-0004FY-Eg for pgsql-hackers@lists.postgresql.org; Thu, 24 Mar 2022 14:32:38 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 5EA925C01D2; Thu, 24 Mar 2022 10:32:35 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 24 Mar 2022 10:32:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=LQMEmmf4iOXrftutUp0IaHbz4X/j32v4dQKO7Zdz50Q=; b=onUmjLbw snj5xw/xkKKHYH6NgXC3P35oGtLKcUB6vQSJ8X7BjSJL9+rhdEdE6+5hKnA+HAQL iSeno6juRbTy+zZFu7gzFiGEH/As95HVsvbPelEocOaNJnZITIqMqNU78Qt29gyO x5CFWsUKfTTC2/gWRLZZ15RYfnomXTzKlQJ8NdBKYMmE6VMbJmrBba4lQDKFDCxJ rcLfH5t+g+Fmrfv/y/j8HAhWVnoCznB5xU6th/LQ2pv9wUvtOs7uzL7pGAa+JOws oaasjuYiyvzYcOiun1/f8RYQKYbvsK8yX7fkRuhjxaRiYlAlGb0JF00RqmgA1iu3 EC9BAcdHYqr/jw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudegledgieduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhvrghr ohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgqe enucggtffrrghtthgvrhhnpedujeevjeffjeevuddutedvkeeiueeitddvieelfeekveej udefgeeuvdejhfeuleenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhh vghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 24 Mar 2022 10:32:35 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 755CD2A08E0; Thu, 24 Mar 2022 11:32:49 -0300 (-03) Date: Thu, 24 Mar 2022 15:32:49 +0100 From: Alvaro Herrera To: Japin Li Cc: Michael Paquier , pgsql-hackers@lists.postgresql.org Subject: Re: turn fastgetattr and heap_getattr to inline functions Message-ID: <202203241432.mt44osd7kkyb@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2022-Mar-24, Japin Li wrote: > I want to know why we do not use the following style? > > +static inline Datum > +heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull) > +{ > + if (attnum > 0) > + { > + if (attnum > (int) HeapTupleHeaderGetNatts(tup->t_data)) > + return getmissingattr(tupleDesc, attnum, isnull); > + else > + return fastgetattr(tup, attnum, tupleDesc, isnull); > + } > + > + return heap_getsysattr(tup, attnum, tupleDesc, isnull); > +} That was the first thing I wrote, but I can't get myself to like it. For this one function the code flow is obvious enough; but if you apply the same idea to fastgetattr(), the result is not nice at all. If there are enough votes for doing it this way, I can do that. I guess we could do something like this instead, which seems somewhat less bad: if (attnum <= 0) return heap_getsysattr(...) if (likely(attnum <= HeapTupleHeaderGetNattrs(...))) return fastgetattr(...) return getmissingattr(...) but I still prefer the one in the v2 patch I posted. It's annoying that case 0 (InvalidAttrNumber) is not well handled anywhere. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/