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.94.2) (envelope-from ) id 1rbcgu-00GD3z-4t for pgsql-hackers@arkaria.postgresql.org; Sun, 18 Feb 2024 08:38:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rbcgs-009MN1-OX for pgsql-hackers@arkaria.postgresql.org; Sun, 18 Feb 2024 08:38: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.94.2) (envelope-from ) id 1rbcgr-009MMs-Kt for pgsql-hackers@lists.postgresql.org; Sun, 18 Feb 2024 08:38:26 +0000 Received: from mail.clear-code.com ([2401:2500:102:3039:153:126:206:245]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rbcgn-007L2A-Tw for pgsql-hackers@postgresql.org; Sun, 18 Feb 2024 08:38:24 +0000 Received: from localhost (unknown [IPv6:2404:7a80:89c1:1200:6af9:2266:1443:f149]) by mail.clear-code.com (Postfix) with ESMTPSA id 67E5E5F47E0; Sun, 18 Feb 2024 17:38:13 +0900 (JST) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.clear-code.com 67E5E5F47E0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=clear-code.com; s=default; t=1708245493; bh=pfxb96mtA85fbbqoKhRLlq60BYHNHq1lEw17pOPQiX0=; h=Date:To:Cc:Subject:From:In-Reply-To:References:From; b=dPOt0+jJCu8VwP4jX+XBYiF2zt6aabyBeb0ezrEeu3GPQPQrrtgECHeGM3d2IvAzN 7B3Fub042MZ9iU7AzFoItz81xgDIBRYwC/Ia3HvbOBTNsdBjWG65gLETbka6E+AXwX G+XZypx4udxiF6zIhaTgW+mTi5s1OUZ3uizz7x/s= Date: Sun, 18 Feb 2024 17:38:09 +0900 (JST) Message-Id: <20240218.173809.707692226756628288.kou@clear-code.com> To: andres@anarazel.de Cc: robertmhaas@gmail.com, laurenz.albe@cybertec.at, tgl@sss.pgh.pa.us, jack@jncsoftware.com, david@fetter.org, jeff.janes@gmail.com, pgsql-hackers@postgresql.org Subject: Re: Why is pq_begintypsend so slow? From: Sutou Kouhei In-Reply-To: <20240218015955.rmw5mcmobt5hbene@awork3.anarazel.de> References: <20200731170008.dp2q5467zlskh6ra@alap3.anarazel.de> <20240218015955.rmw5mcmobt5hbene@awork3.anarazel.de> X-Mailer: Mew version 6.8 on Emacs 29.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 67E5E5F47E0 X-Rspamd-Server: mail.clear-code.com X-Spamd-Result: default: False [3.90 / 999.00]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; SUBJECT_ENDS_QUESTION(1.00)[]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; ASN(0.00)[asn:2518, ipnet:2404:7a80::/29, country:JP]; ARC_NA(0.00)[]; RCPT_COUNT_SEVEN(0.00)[8]; RCVD_COUNT_ZERO(0.00)[0]; TAGGED_RCPT(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; URIBL_BLOCKED(0.00)[anarazel.de:email,localhost:helo,postgresql.org:url]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[gmail.com,cybertec.at,sss.pgh.pa.us,jncsoftware.com,fetter.org,postgresql.org]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; SURBL_MULTI_FAIL(0.00)[anarazel.de:server fail,postgresql.org:server fail,localhost:server fail] X-Rspamd-Action: no action List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, In <20240218015955.rmw5mcmobt5hbene@awork3.anarazel.de> "Re: Why is pq_begintypsend so slow?" on Sat, 17 Feb 2024 17:59:55 -0800, Andres Freund wrote: > v3-0008-wip-make-in-out-send-recv-calls-in-copy.c-cheaper.patch It seems that this is an alternative approach of [1]. [1] https://www.postgresql.org/message-id/flat/20240215.153421.96888103784986803.kou%40clear-code.com#34df359e6d255795d16814ce138cc995 +typedef struct CopyInAttributeInfo +{ + AttrNumber num; + const char *name; + + Oid typioparam; + int32 typmod; + + FmgrInfo in_finfo; + union + { + FunctionCallInfoBaseData fcinfo; + char fcinfo_data[SizeForFunctionCallInfo(3)]; + } in_fcinfo; Do we need one FunctionCallInfoBaseData for each attribute? How about sharing one FunctionCallInfoBaseData by all attributes like [1]? @@ -956,20 +956,47 @@ NextCopyFrom(CopyFromState cstate, ExprContext *econtext, values[m] = ExecEvalExpr(defexprs[m], econtext, &nulls[m]); } - - /* - * If ON_ERROR is specified with IGNORE, skip rows with soft - * errors - */ - else if (!InputFunctionCallSafe(&in_functions[m], - string, - typioparams[m], - att->atttypmod, - (Node *) cstate->escontext, - &values[m])) Inlining InputFuncallCallSafe() here to use pre-initialized fcinfo will decrease maintainability. Because we abstract InputFunctionCall family in fmgr.c. If we define a InputFunctionCall variant here, we need to change both of fmgr.c and here when InputFunctionCall family is changed. How about defining details in fmgr.c and call it here instead like [1]? + fcinfo->args[0].value = CStringGetDatum(string); + fcinfo->args[0].isnull = false; + fcinfo->args[1].value = ObjectIdGetDatum(attr->typioparam); + fcinfo->args[1].isnull = false; + fcinfo->args[2].value = Int32GetDatum(attr->typmod); + fcinfo->args[2].isnull = false; I think that "fcinfo->isnull = false;" is also needed like [1]. @@ -1966,7 +1992,7 @@ CopyReadBinaryAttribute(CopyFromState cstate, FmgrInfo *flinfo, if (fld_size == -1) { *isnull = true; - return ReceiveFunctionCall(flinfo, NULL, typioparam, typmod); + return ReceiveFunctionCall(fcinfo->flinfo, NULL, attr->typioparam, attr->typmod); Why pre-initialized fcinfo isn't used here? Thanks, -- kou