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 1rVpBx-001XZh-QL for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Feb 2024 08:46:34 +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 1rVpBw-00BXn5-OJ for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Feb 2024 08:46:32 +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 1rVpBv-00BXmx-KI for pgsql-hackers@lists.postgresql.org; Fri, 02 Feb 2024 08:46:32 +0000 Received: from mail.clear-code.com ([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 1rVpBs-004fbq-1S for pgsql-hackers@postgresql.org; Fri, 02 Feb 2024 08:46:30 +0000 Received: from localhost (unknown [IPv6:2404:7a80:89c1:1200:6af9:2266:1443:f149]) by mail.clear-code.com (Postfix) with ESMTPSA id 650EE61471A; Fri, 2 Feb 2024 17:46:20 +0900 (JST) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.clear-code.com 650EE61471A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=clear-code.com; s=default; t=1706863580; bh=AWUKVZoqYAhayItwx2akZ8svHKfCQjzcTEmeha/gTXY=; h=Date:To:Cc:Subject:From:In-Reply-To:References:From; b=ojto574BBt1q4RD+ql7FJTe+6JO5OJHf0OKlJejkUIhbBIAA2xRojfGtq9yd5RMqH IltbIFkubHzMEdTUp5aca74MhW0DxWwJIcXAOqIExejb0FLo1lCf1NP8AnUwah1c/i R4qbaYYLqearnvmu2V05K/U2u7CdSbZoWuYrSsCA= Date: Fri, 02 Feb 2024 17:46:18 +0900 (JST) Message-Id: <20240202.174618.349091157390883477.kou@clear-code.com> To: michael@paquier.xyz Cc: sawada.mshk@gmail.com, zhjwpku@gmail.com, andrew@dunslane.net, nathandbossart@gmail.com, pgsql-hackers@postgresql.org Subject: Re: Make COPY format extendable: Extract COPY TO format implementations From: Sutou Kouhei In-Reply-To: References: <20240202.163319.975394400703526633.kou@clear-code.com> 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: 650EE61471A X-Rspamd-Server: mail.clear-code.com X-Spamd-Result: default: False [2.90 / 999.00]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; ASN(0.00)[asn:2518, ipnet:2404:7a80::/29, country:JP]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; TAGGED_RCPT(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; URIBL_BLOCKED(0.00)[localhost:helo,paquier.xyz:email]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_CC(0.00)[gmail.com,dunslane.net,postgresql.org]; RCPT_COUNT_FIVE(0.00)[6]; FROM_HAS_DN(0.00)[]; TO_DN_NONE(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; SURBL_MULTI_FAIL(0.00)[paquier.xyz: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 "Re: Make COPY format extendable: Extract COPY TO format implementations" on Fri, 2 Feb 2024 17:04:28 +0900, Michael Paquier wrote: > One idea I was considering is whether we should use a special value in > the "format" DefElem, say "custom:$my_custom_format" where it would be > possible to bypass the formay check when processing options and find > the routines after processing all the options. I'm not wedded to > that, but attaching the routines to the state data is IMO the correct > thing, because this has nothing to do with CopyFormatOptions. Thanks for sharing your idea. Let's discuss how to support custom options after we complete the current performance changes. >> I'm OK with the approach. But how about adding the extra >> callbacks to Copy{From,To}StateData not >> Copy{From,To}Routines like CopyToStateData::data_dest_cb and >> CopyFromStateData::data_source_cb? They are only needed for >> "text" and "csv". So we don't need to add them to >> Copy{From,To}Routines to keep required callback minimum. > > And set them in cstate while we are in the Start routine, right? I imagined that it's done around the following part: @@ -1418,6 +1579,9 @@ BeginCopyFrom(ParseState *pstate, /* Extract options from the statement node tree */ ProcessCopyOptions(pstate, &cstate->opts, true /* is_from */ , options); + /* Set format routine */ + cstate->routine = CopyFromGetRoutine(cstate->opts); + /* Process the target relation */ cstate->rel = rel; Example1: /* Set format routine */ cstate->routine = CopyFromGetRoutine(cstate->opts); if (!cstate->opts.binary) if (cstate->opts.csv_mode) cstate->copy_read_attributes = CopyReadAttributesCSV; else cstate->copy_read_attributes = CopyReadAttributesText; Example2: static void CopyFromSetRoutine(CopyFromState cstate) { if (cstate->opts.csv_mode) { cstate->routine = &CopyFromRoutineCSV; cstate->copy_read_attributes = CopyReadAttributesCSV; } else if (cstate.binary) cstate->routine = &CopyFromRoutineBinary; else { cstate->routine = &CopyFromRoutineText; cstate->copy_read_attributes = CopyReadAttributesText; } } BeginCopyFrom() { /* Set format routine */ CopyFromSetRoutine(cstate); } But I don't object your original approach. If we have the extra callbacks in Copy{From,To}Routines, I just don't use them for my custom format extension. >> What is the better next action for us? Do you want to >> complete the WIP v11 patch set by yourself (and commit it)? >> Or should I take over it? > > I was planning to work on that, but wanted to be sure how you felt > about the problem with text and csv first. OK. My opinion is the above. I have an idea how to implement it but it's not a strong idea. You can choose whichever you like. Thanks, -- kou