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 1sUmuL-005ffu-5u for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jul 2024 12:40:21 +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 1sUmuH-00FsnV-PZ for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jul 2024 12:40:18 +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 1sUmuH-00FsnM-F8 for pgsql-hackers@lists.postgresql.org; Fri, 19 Jul 2024 12:40:17 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sUmu9-000Mws-IH for pgsql-hackers@postgresql.org; Fri, 19 Jul 2024 12:40:15 +0000 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5a2ffc34677so757843a12.2 for ; Fri, 19 Jul 2024 05:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1721392808; x=1721997608; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=bphWICORZmanbYNrM3tQlANgoVdrQZKfACJ73zMoOuI=; b=M/Vx/cgnae/jOognJP0+9XuPYtZVBqUxdzvKZnQC+geuwF8UOZxpb5ZGRFSLyyg5ZB s4orGaCqC8kgTgLzraKVTLuqCvFkbYJQRVe+MpV++3ZJGBWQxAMbI7S9eXDQpP8/EuoL xX+opYrYs9tw+jOrjgycac0gxwBSWjcpW4T9OxZ10t3BK8k05Qoh4HTcZrg+k3jMVUbx 1TF+z1AybuY2OTdADwcE1paezaYE5/uORHKEp39NquSfEG+8Mt40/9Eh5lp+XKnHKSv5 zTQvPIoo8+sZmO3Sqs2LmWDlZ5yGCjzIF3Dh8nJMAB0S3+amYQbddI3h7cbsSW/2xBU9 HSNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721392808; x=1721997608; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bphWICORZmanbYNrM3tQlANgoVdrQZKfACJ73zMoOuI=; b=GRvYt1ZlManCAq2Yy4RPBK/Z6RWgkgb8Ejp8YfR8d3AjETpYMnvE/dWPw/Wx9skxmJ Lw8GegTeF9o4sC/sYYqXlClhlFDX/X6KOrf4gbkOKMxn01gLTNpfZdJueH4DU072Bg3J I997Ycm9Z9LXmRh9Qnit4pqQC5U1XZLLpIQeNkBnEpQdpQw70291cqkdAssvKFRTzUr1 FKJQnQWzV+xP8JThFry967DJ05vnV4Hp53xal2bfDjkb9oXNmtpkd37ZM9GMxiHmn8qQ a0PmYO6AgR9udOHaMRoyJd8kFhVp471Dyh2wBv6wRWlxpHm/na2Sa0pF6bklelXEf6zZ mqLA== X-Forwarded-Encrypted: i=1; AJvYcCWi0rnJY9ixOZFem3BUS9YiBsQf1s0O8yAtBhoHonUXVI5i0I3fpjZgwm+sxd83cODJx2LL9g0Oo8B9yvNQKNJCDAfFP8KQtC/g+n0i X-Gm-Message-State: AOJu0YxdTVU0epz3W1bmfgnIDVFbq0IbGCVDmo1KajB1Se5YiPOpVnop AsCp7OxjrTUGystmWZPRXyJVD4GHzfFRT4TWkkx2i0eY3A6YlRgNf0pXxEQHJQ== X-Google-Smtp-Source: AGHT+IFDNQ/LCdC3J2vFeshB5pB1pDuWPoZQudDk2k2E1o1W3Vs2j1cPuTGPBFTCfkm3VAlEI8cV0w== X-Received: by 2002:a50:99db:0:b0:5a2:9b09:449b with SMTP id 4fb4d7f45d1cf-5a2ba5bb71emr1615823a12.4.1721392807617; Fri, 19 Jul 2024 05:40:07 -0700 (PDT) Received: from [10.137.0.18] (ip-86-49-229-30.bb.vodafone.cz. [86.49.229.30]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5a30a4d6fadsm1140900a12.6.2024.07.19.05.40.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Jul 2024 05:40:07 -0700 (PDT) Message-ID: <257d5573-07da-48c3-ac07-e047e7a65e99@enterprisedb.com> Date: Fri, 19 Jul 2024 14:40:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Make COPY format extendable: Extract COPY TO format implementations To: Sutou Kouhei , andres@anarazel.de Cc: michael@paquier.xyz, sawada.mshk@gmail.com, zhjwpku@gmail.com, andrew@dunslane.net, nathandbossart@gmail.com, pgsql-hackers@postgresql.org References: <20240308.092254.359611633589181574.kou@clear-code.com> <20240320.232732.488684985873786799.kou@clear-code.com> <20240410.171626.772425261553816667.kou@clear-code.com> Content-Language: en-US From: Tomas Vondra In-Reply-To: <20240410.171626.772425261553816667.kou@clear-code.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello Kouhei-san, I think it'd be helpful if you could post a patch status, i.e. a message re-explaininig what it aims to achieve, summary of the discussion so far, and what you think are the open questions. Otherwise every reviewer has to read the whole thread to learn this. FWIW I realize there are other related patches, and maybe some of the discussion is happening on those threads. But that's just another reason to post the summary here - as a reviewer I'm not going to read random other patches that "might" have relevant info. ----- The way I understand it, the ultimate goal is to allow extensions to define formats using CREATE XYZ. And I agree that would be a very valuable feature. But the proposed patch does not do that, right? It only does some basic things at the C level, there's no DDL etc. Per the commit message, none of the existing formats (text/csv/binary) is implemented as "copy routine". IMHO that's a bit strange, because that's exactly what I'd expect this patch to do - to define all the infrastructure (catalogs, ...) and switch the existing formats to it. Yes, the patch will be larger, but it'll also simplify some of the code (right now there's a bunch of branches to handle these "old" formats). How would you even know the new code is correct, when there's nothing using using the "copy routine" branch? In fact, doesn't this mean that the benchmarks presented earlier are not very useful? We still use the old code, except there are a couple "if" branches that are never taken? I don't think this measures the new approach would not be slower once everything gets to be copy routine. Or what am I missing? Also, how do we know this API is suitable for the alternative formats? For example you mentioned Arrow, and I suppose people will want to add support for other column-oriented formats. I assume that will require stashing a batch of rows (or some other internal state) somewhere, but does the proposed API plan for that? My guess would be we'll need to add a "private_data" pointer to the CopyFromStateData/CopyToStateData structs, but maybe I'm wrong. Also, won't the alternative formats require custom parameters. For example, for column-oriented-formats it might be useful to specify a stripe size (rows per batch), etc. I'm not saying this patch needs to implement that, but maybe the API should expect it? ----- To sum this up, what I think needs to happen for this patch to move forward: 1) Switch the existing formats to the new API, to validate the API works at least for them, allow testing and benchmarking the code. 2) Try implementing some of the more exotic formats (column-oriented) to test the API works for those too. 3) Maybe try implementing a PoC version to do the DDL, so that it actually is extensible. It's not my intent to "move the goalposts" - I think it's fine if the patches (2) and (3) are just PoC, to validate (1) goes in the right direction. For example, it's fine if (2) just hard-codes the new format next to the build-in ones - that's not something we'd commit, I think, but for validation of (1) it's good enough. Most of the DDL stuff can probably be "copied" from FDW handlers. It's pretty similar, and the "routine" idea is what FDW does too. It probably also shows a good way to "initialize" the routine, etc. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company