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.98.2) (envelope-from ) id 1xAcgF-00000002kqQ-2Zj6 for pgsql-hackers@arkaria.postgresql.org; Sun, 27 Sep 2026 00:23:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xAcgD-00000005JTR-2pmB for pgsql-hackers@arkaria.postgresql.org; Sun, 27 Sep 2026 00:23:45 +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.98.2) (envelope-from ) id 1xAcgD-00000005JTI-0TWA for pgsql-hackers@lists.postgresql.org; Sun, 27 Sep 2026 00:23:45 +0000 Received: from mail-ej2-x10.google.com ([2a00:1450:4864:34::10]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1xAcgA-00000001QR5-0uTn for pgsql-hackers@lists.postgresql.org; Sun, 27 Sep 2026 00:23:43 +0000 Received: by mail-ej2-x10.google.com with SMTP id a640c23a62f3a-c2940ff2313so126733066b.1 for ; Sat, 26 Sep 2026 17:23:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790468619; x=1791073419; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:content-type:from:to:cc :subject:date:message-id:reply-to:content-type; bh=VUkzISyQzdSiUS0y+TDaikZ8GaIzITKf2amRamUtxEM=; b=GrwMIMvR1vv5z0wpiY+vr0ygedmD3Nh/VuzF2vC2mpzHmr2QlT7efwR3BlXfCLV+Vk XRnKpkTYdV0V9fyqm+4yX5yztn6qwZi5EZO5YyYl4JWdSCgMVrufEolQfc6jpDUVInZB yND4QOz6By9xcHKaAB+YYQJt9112jOkbung4U+ebOUv2u6vjXLp9uuf0ivFASBUFjZRu YozUTjIUaP+5B6z+bSU6O71NH302k9bcshTJqD8JdUs5km9Zwv3uZmlrSGceQz/mY/YU Q5bLQxSNqazqcb4QFfNeHWIUaUN4bL4SobJ/kPivuXBdyfodvuqqP++dSa5Gt8LdMyBW aUqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790468619; x=1791073419; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=VUkzISyQzdSiUS0y+TDaikZ8GaIzITKf2amRamUtxEM=; b=s8CczUJsS7cP8y1nkBQUMvWT41+ZgByuOFJxkfQgzKkWt8QH3/BpwgrA78jyn8phs7 2iSEIObO3VmMp4b1wIw7WtI4TgxHxjpE+lk10fwMqT5sCrNOntpSKT3BRQVJ86L6anma 9f84+V0mqCGjc/MjQ38JFMiEEnweFLonzh6Li5ehQGt4NuB7FfDApa6ATk6Y5UAmHPYA PDSd8/LOlDyQgh+2s/LXBcPC4sbujkD5afIvSjmWAee2440R7vgECXZvSrVNg6H62Ne6 dEWrtdcgxvinAr4EMUqYoAMWEbVmNmKtRt9zjNCpNAvR9Wi2S2Y/ApSz6d4rNXgxW59U BpTw== X-Forwarded-Encrypted: i=1; AKwUvBzvdhBiphMXAMvk0rznvErczPRT3qb4VFWCdZIl1+3aUd1jG+khm0fF77Nyjq70KVaSDtFaFy+iHHMAE/mL@lists.postgresql.org X-Gm-Message-State: AFuF++nEDk0IQcDiRE4I7JDwzVRNETXCWa1Tba8OMzPGhTnFLcbL1FM2 /vVkFgQ332sDT/genQwdwQd3/nGrvsHpmgDB8aLBrMyyOuSFpnvzqpw3 X-Gm-Gg: AYBFou2ag64D8UfUonXukxEF3BC4IjPdvbW7tQoZLu7givsIHum4RVdKtyAihcI73UR oV+ktaBTkUvcsrbS89H27kRNdA4Onm8FwpbQpJQ5dSyhRzPK5kfshQFzsxBJ0aUe8zOpUs+xYx1 IyI/BTGl/PEEmuCoaO4HAVsrtX6yqVPwPCTrNcEB5j/QjLVgjGnPbtOgg/B1sr0qzd9upshMtO1 gGCmBbwiQEn5xf9/WKYldKm/ySZjWqJCw02syXicf5hrka2o1PcEUpSsyoM8aNIdBA16BoCPM+Q aI2iazEqe6pOUEZBuS+y9d//uo8WxnmsWO+xBxs+Zc8PTURHUtd0p0O+C1ZJ9dN7PCvY/9U+NpH jUmPTPW9IXVgrS1LXZXlo5iT1iblWfgHKOrJnuoOHcgAkTBtTDI50VoteoOT+Ip+DnGVpTzoIUf MjIM0rSek1NvCry7t+LEaa76KqxF0/P14GHqpHx4Xb05wuxYI/SqeXd5HDwmhxi69ttWEWmInke DP5Hep2V1J+9DPLc3oU X-Received: by 2002:a17:907:97d0:b0:c29:58ae:8327 with SMTP id a640c23a62f3a-c2ac2363538mr897926266b.19.1790468618978; Sat, 26 Sep 2026 17:23:38 -0700 (PDT) Received: from smtpclient.apple ([109.36.159.125]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c2dc70bb213sm53392966b.43.2026.09.26.17.23.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Sep 2026 17:23:37 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.700.51.1.1\)) Subject: Re: COMMENTS are not being copied in CREATE TABLE LIKE From: Alex Liapychev In-Reply-To: Date: Sun, 27 Sep 2026 02:23:25 +0200 Cc: matheusssilv97 , Chao Li , "masao.fujii" , "david.g.johnston" , tgl , "huseyin.d3r" , pgsql-hackers , chochoforwork@gmail.com, 44973863@qq.com Content-Transfer-Encoding: quoted-printable Message-Id: References: <2d41978b-3bca-4756-b0a0-b6e707ad7793@uni-muenster.de> <88b16128-d6f4-4a7b-a29a-fa0cd1c2084f@uni-muenster.de> <65963A8C-C1EE-431E-9513-C4AD16AEE789@gmail.com> <223a6be3-3917-47a4-9b5d-51720c60ad58@vondra.me> To: Jim Jones , tomas@vondra.me X-Mailer: Apple Mail (2.3864.700.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Jim and Tomas, everyone, Thank you Tomas for stepping in and putting things into perspective.=20 Thank you Jim for making the changes so quickly. We did a recheck of the new version v4 of the patch on September 26, = 2026. Branch cf/6482 (commit: 47ed4119) rebased over master (commit: = f25c50fd). Tests on both master alone and with cf/6482 on top completed = successfully. V4 is a complete rewrite. Author fixed all issues pointed by Tomas and by us (see 3 previous = messages). I will list notable changes briefly: 1. Docs: create_table.sgml:695 - replaced =E2=80=9Ctable=E2=80=9D for = =E2=80=9Csource relation=E2=80=9D, because it could be other types of = relations. 2. Tests: added INCLUDING ALL test case; test cases for concatenation = corner cases; foreign and temporary table as copy target cases; type as = a source case. 3. Code review of a file parse_utilcmd.c: 3.1. Includes are now sorted in alphabetical order. 3.2. Case when concatenated comment exceeds MaxAllocSize: >>> 1. Corner case: concatenation of big comments, whose total size = exceeds MaxAllocSize, fails with an error. >> I'd just reject such cases, with an ERROR that says the comment would = be >> too long. It's cleaner than just silently start discarding user >> information. The number of people hitting this is about 0 anyway. Who >> would even have comments of this size? Implemented on L:1369-1374, error ERRCODE_PROGRAM_LIMIT_EXCEEDED is = returned with clear message. 3.3. Memory allocation and freeing: >> FWIW if we really are worried about very long comments, then maybe >> expandTableLikeClause should be more careful about freeing comments >> during the concatenation? Right now it keeps all the comments and = then >> also the intermediate strings during concatenation. (I think.) I tried to trace memory allocations, there are 2 scopes where = allocations happen: 3.3.a. The local scope, where comment of each LIKE relation is read: - allocated: in GetComment (L:1348 or 1352); - freed: pfree(tblcomment) at L:1379; Seems good. 3.3.b. Scope of transformCreateStmt function: - defined: Variable cxt (CreateStmtContext) is created on stack (at = L:176), inside is new field tablecomment (StringInfo).=20 - - It is NULLed before first use at L:257. - allocated: Field cxt->tablecomment is initialised at L:1361 via = makeStringInfo(), which does 2 palloc=E2=80=99s internally. - read: cxt.tablecomment->data is stored into cstmt->comment at L:321. - freed: NEVER.=20 destroyStringInfo is not called from parse_utilcmd.c.=20 Which seems correct, because we pass data to outside of a function. But probably we should call pfree for cxt.tablecomment (StringInfo = struct itself) to balance 1st palloc from makeStringInfo. 3.3.c. (bonus) Scope where de-allocation also might happen: Comment produced in transformCreateStmt function then reaches code from = file comment.c, where it is stored to target relation. I could not find any pfree for stmt->comment inside the file comment.c, = where it is consumed. Which should exist to balance 2nd palloc from makeStringInfo. I don=E2=80=99t know if this palloc'd memory is freed somehow = automagically at some later point. But to my understanding it may be a memory leak, which spans past this = specific patch scope. 4. The question if we should concat comments at all: >> That being said, I'm not convinced we actually want to concatenate >> comments like this. It feels a bit weird, and it can probably lead to >> weird stuff like "duplicate" comments, etc. Do we have any precedent = for >> this behavior? Are we concatenating comments (or other stuff) = anywhere? >> I couldn't find such place, but maybe I missed something. >=20 > Neither am I. I'm just not sure that ignoring the comments when using > multiple tables is a better alternative. I can live with it, but so = far > I didn't find enough arguments to remove it. The alternatives I see = are: >=20 > 1) concatenate with a (\n) separator (current behaviour) > 2) concatenate without a separator > 3) first one wins > 4) last one wins > 5) ignore it altogether when multiple comments are detected (my least > favourite) > 6) your idea? :) >=20 > WDYT? I think from perspective of semantics of INCLUDING COMMENTS/ALL it seems = right to copy comments of a table. But for such complicated scenario, where there are few source relations = - not sure. Maybe "last one wins" would be the easiest to implement and least = counter-intuitive for users? This concatenation code works, but what consequences it may have to = support it over years? Kind regards, Alex Liapychev