Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i7JAF-00082T-9d for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Sep 2019 12:53:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i7JAE-0000fc-5o for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Sep 2019 12:53:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i7JAD-0000dL-RT for pgsql-hackers@lists.postgresql.org; Mon, 09 Sep 2019 12:53:01 +0000 Received: from new2-smtp.messagingengine.com ([66.111.4.224]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i7JAA-0006M3-Rv for pgsql-hackers@postgresql.org; Mon, 09 Sep 2019 12:53:01 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 067D81BE1; Mon, 9 Sep 2019 08:52:57 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 09 Sep 2019 08:52:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=coD5VL20W2imqCxTo/kctE69BvZ6ToG4NJMIodM9NcY=; b=t5oMXXmm Ovb4Pt0uxzr8dr9+0/DjJQDo/ZfgAe+RusNgToXjmGG+cXwMmcGw50zuD5mzyGXB LG9wuvE4xxqYZt/fY61Ksx5YIdJLdljVYfkI7ST5Onfk0KFKc6I7w9UUnzEn53E+ X2zBbnNhW2RjDYVSHff0OiGg2Es5U+6Nton1gqyzdMa0DlJHhEuC48BcnCvDHUiM PuPAbHZu/afHQ76Z5AIKUC0W5axKeebxzydD1HH9Xgu8ovmzvZ6X892AHlnkbCed KD9YzZi4tS91eprUsFeMjSzVs/Vr3P8Ug75JzItx8Sws2ApQCz/A6c4WClkEkR2T oEeLvuxh55YTCA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrudekiedgheeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfggtggugfgjfgesthekredttderudenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruchfrhhomhcuvdhnugfsuhgrughrrghnthcuoegrlhhvhhgvrh hrvgesrghlvhhhrdhnohdqihhprdhorhhgqeenucffohhmrghinhepvdhnughquhgrughr rghnthdrtghomhenucfkphepudejledrheeirdehuddriedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgnecuvehluhhs thgvrhfuihiivgeptd X-ME-Proxy: Received: from nimloth.alvh.no-ip.org (unknown [179.56.51.60]) by mail.messagingengine.com (Postfix) with ESMTPA id 5A1FE8005C; Mon, 9 Sep 2019 08:52:55 -0400 (EDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id C3863120E34; Mon, 9 Sep 2019 09:52:51 -0300 (-03) Date: Mon, 9 Sep 2019 09:52:51 -0300 From: Alvaro Herrera from 2ndQuadrant To: Amit Kapila Cc: Masahiko Sawada , Michael Paquier , Craig Ringer , Ashutosh Sharma , Julien Rouhaud , Peter Geoghegan , PostgreSQL Hackers , Abhijit Menon-Sen , Peter Eisentraut , Pavan Deolasee Subject: Re: [HACKERS] [PATCH] pageinspect function to decode infomasks Message-ID: <20190909125251.GA21347@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Sep-08, Amit Kapila wrote: > On Thu, Sep 5, 2019 at 2:17 PM Masahiko Sawada wrote: > > > > Thanks. I hope the attached new patch fixes this issue. > * > +-- decode infomask flags as human readable flag names > +CREATE FUNCTION heap_infomask_flags( > + infomask integer, > + infomask2 integer, > + decode_combined boolean DEFAULT false) > +RETURNS text[] > +AS 'MODULE_PATHNAME', 'heap_infomask_flags' > > Isn't it better to name this function as tuple_infomask_flags or > something like that? The other functions that start their name with > heap take page as input. Also, I think the index-related functions > that start with index name take blk/page as input. I think that other table AMs are not necessarily going to use the same infomask flags, so I think we should keep a name that is somehow heapam-specific. Maybe "heapam_infomask_flags" would be okay? > + heap_infomask_flags(infomask integer, infomask2 > integer, decode_combined bool) returns text[] > I think it is better to use one example for this function as we do for > other functions in this doc. Agreed. > + > + If decode_combined is set, combination flags like > + HEAP_XMIN_FROZEN are output instead of raw > + flags, HEAP_XMIN_COMMITTED and > + HEAP_XMIN_INVALID. Default value is > + false. > + > > decode_combined should use parameter marker (like > decode_combined). Instead of saying > "decode_combined" is set, you can use true/false terminology as that > is what we use for this parameter. Agreed. > Some more comments: > * > +SELECT t_infomask, t_infomask2, flags > +FROM heap_page_items > (get_raw_page('test1', 0)), > + LATERAL heap_infomask_flags(t_infomask, > t_infomask2, true) m(flags); > > Do we really need a LATERAL clause in the above kind of queries? > AFAIU, the functions can reference the columns that exist in the FROM > list, but I might be missing some point. I think the spec allows the LATERAL keyword to be implicit in the case of functions, so this seems a matter of style. Putting LATERAL explicitly seems slightly clearer, to me. > +Datum > +heap_infomask_flags(PG_FUNCTION_ARGS) > +{ > + uint16 t_infomask = PG_GETARG_INT16(0); > + uint16 t_infomask2 = PG_GETARG_INT16(1); > + bool decode_combined = PG_GETARG_BOOL(2); > All the functions in this file are allowed only for superusers and > there is an explanation for the same as mentioned in the file header > comments. Is there a reason for this function to be different? The other functions can crash if fed arbitrary input. I don't think this one can crash, so it seems okay for it not to be superuser-only. > In any case, if you think that this function needs to behave > differently w.r.t superuser privileges, then it is better to add some > comments in the function header to explain the same. Yeah. > * > +Datum > +heap_infomask_flags(PG_FUNCTION_ARGS) > { > .. > + > + d = (Datum *) palloc0(sizeof(Datum) * bitcnt); > > It seems we don't free this memory before leaving this function. I > think it shouldn't be a big problem as this will be normally allocated > in ExprContext and shouldn't last for long, but if there is no strong > reason, I think it is better to free it. Agreed. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services