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 1xAzY8-00000002wSh-3IHQ for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Sep 2026 00:48:57 +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 1xAzY7-000000076P7-2cGf for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Sep 2026 00:48:55 +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 1xAzY7-000000076Oy-0sDx for pgsql-hackers@lists.postgresql.org; Mon, 28 Sep 2026 00:48:55 +0000 Received: from mail-dy2-x10.google.com ([2607:f8b0:4864:36::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 1xAzY4-00000001b24-2336 for pgsql-hackers@lists.postgresql.org; Mon, 28 Sep 2026 00:48:54 +0000 Received: by mail-dy2-x10.google.com with SMTP id 5a478bee46e88-33bc6ff6cadso302446eec.0 for ; Sun, 27 Sep 2026 17:48:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790556532; x=1791161332; darn=lists.postgresql.org; h=mime-version:content-transfer-encoding:content-type:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=k8DDSp4o2PKCDl/Kjvjz+G9b8S7ijJINVlCMm9sv3sk=; b=U0zgs4Yv9p4Yu9Qa2NTOeHySzVisQ9fi0O5KgpwlkEpbBPlxdRqbXuL5mFgXnk47Ra 4NIiSTy7f/ln+8bGKUhrC/e1gwOCu5LjPmGXyRP1fF0BHxmS7fc6z/2HF/1y2MOFkhGY 1UyTH0N/topAHPRhwh1gDfk3yoEr4PS8qZFFomAv6WDiDaZbujIhfGVY2uDHWfIGs2Xn 09CGlohh33WmD8P+T/PqJw9uZDlo2Tnld+8kvBJkM57eaaDxr9vV1Lfsc9/XabHEvTHs +jNdKItuhYjwKFpAIoWYSiAV9a4O0gltIQK0sqMa9DHO66D8wm/aERMb5swWgT+FV36D XnQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790556532; x=1791161332; h=mime-version:content-transfer-encoding:content-type:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=k8DDSp4o2PKCDl/Kjvjz+G9b8S7ijJINVlCMm9sv3sk=; b=KWfpi7Atf25Tp2ZxIb9l5+o7dIeNzgIwDFar4TswQWmwakDAM5X9lCZygZSbTAjCG5 fkC6B4t1bXzUKKV4LbH4gKZC0uj4+x247tUKyC90b2nlk1b630vyCFtfDI3DGyOnNCtq Jw9cfZZxaoUCwnLy653Z/wdwmah0/wIYmHyVbpSwASIw4ShR2ZX8PhhXGWGgMvO+VyiJ UjQvbnf4uUQ7wEuhEw86+tizPlnTedqAV+i6NGvMGk1BA019Rtylb5VppDP+W2pNTWU8 H8jXidZivMRX4umNrzt5nj73Fflg7HPM3j1SBunGZaD18b3dPehpi08/Zx/dArabcnBw TH2w== X-Gm-Message-State: AFq9FYL4/UgfLBVl9d53PtbJpL5/BGqFde52Rx+7tMTP3w+31EqOKr1M Z+zY5XTLIcQhl7np/ymYb3C/fMuEYzmlem1IXJV6kP7gIGZprQbAMn6A X-Gm-Gg: AYBFou2HM8du2lnBjhud2DKSW3Z5QfzZrto3Ub9nk9JltWNHkVp5CFSNrR8JyAtsDO5 H2db7kdotNKg+xdfE/KE96yHyxfy5r8xkaYop4HAbadzMFo7xhzqJJ6FCWWc21kI65TEv7omY7P OswKviJwL5rA5B1quakjP0yaw1EJew+A0oP1L5foQLYPVLU8wxknfG+mNruP5NOShDPvPxzg8Cu BADNjw5YwuM6BCGdI2GX4s6YW5LP7fdvhRaaDeCG3iV0LVIfcBPK9/eFfcSYTnStG1qd1VCwxNC DwgJFG0jaK2KyUVgTD49gnHeAfdXJklitfzmbjUTP2B0BhxDoXt3kOm2ZkIzfp4pXCjem+rbt+E qAMC7sScv0qfLQwY2RRUo1PwPjpgDVJXZzyf6kuZAoAP++u/wtc1cNcQPnMcftxs/we1J5E9ghp WYc7oRu0FraxbEzZqs5/rX2bCSg7acZ8tD/DnbVCrk7nfnYcTvvDor3OTygy5AANidCatotAGX5 3jQ3WpIKv5EJgRRB4Q/c5bZExyWCld1/XxVaB5BZSrsM/NrvAhU7cZNf/TYzrbVR4k7BlX7DmTo 8SItWVzzvb+w2MQwz9WAlN8Rkw== X-Received: by 2002:a05:7300:f64b:b0:33e:4e49:d08d with SMTP id 5a478bee46e88-34272b4bc81mr12509371eec.1.1790556531190; Sun, 27 Sep 2026 17:48:51 -0700 (PDT) Received: from 192.168.1.109 ([2803:3c90:cee:ea00:5c3c:7e70:29e3:7a55]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3433628f5basm15261906eec.18.2026.09.27.17.48.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Sep 2026 17:48:50 -0700 (PDT) From: Manu To: Midhush Karthic Cc: pgsql-hackers@lists.postgresql.org Subject: Re: [PATCH] Add target-column context for assignment coercion errors Date: Sun, 27 Sep 2026 21:48:48 -0300 Message-ID: <179055652844.1731473.3316469207633282016@gmail.com> In-Reply-To: References: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Midhush, Thanks for the patch. I built it (base vs patched at 82d31451606) and ran a differential review. One blocker; the rest holds up well. Blocker -- memory corruption on any coercion, under --enable-cassert -------------------------------------------------------------------- On a cassert build the patched tree writes past an allocated chunk on essentially any cast (MEMORY_CONTEXT_CHECKING catches it). Base is clean; the patch is the only difference: SELECT 1::bigint; WARNING: problem in alloc set MessageContext: detected write past chunk end in block ... chunk ... - Triggers on 1::bigint, 'ok'::varchar(2), 1.5::numeric(2,1), 'a'::char(1). Plain funcs/operators (abs, length, ||) do not, so it is specific to the coercion FuncExprs. - It fires at parse/plan with no execution (EXPLAIN (COSTS OFF) and PREPARE both warn), and on valid values too, so it is independent of the "value too long" path. - The coercion path runs across most of the regression suite, so the "all 239 tests pass" run was very likely without --enable-cassert; with cassert the warnings are immediate. My guess is the new FuncExpr fields or their handling on the parse/plan coercion path, rather than the runtime callback. I stopped the design pass here until that is root-caused; the rest of what I checked: Checks out ---------- - CONTEXT lands exactly where a destination column is known: varchar(n)/char(n)/numeric(p,s), UPDATE, DEFAULT, GENERATED STORED, PREPARE/const-fold, INSERT ... SELECT. - Renames resolve lazily to the new name (col_old -> col_new). Nice. - Source errors are not misattributed: INSERT ... VALUES (1/0) still reports "division by zero", with no column context. - equal_ignore / query_jumble_ignore on the new fields are correct -- equal()/CSE and pg_stat_statements stay unaffected. Your design questions --------------------- - Growing FuncExpr for every node in the system to carry Oid + AttrNumber, for a niche feature, is the main axis worth hashing out on-list -- it is what stalled the 2015 threads. A dedicated node or a side channel may be worth weighing against the per-node size. - Annotated coercions always route through the fusage helper, even with track_functions off. I measured the bulk path (2M INSERTs into a varchar(4) column, -O2, 10 samples each): base 1861 ms vs patched 1827 ms median, -1.8% [95% CI -9.7 .. +4.0] -- within noise. No measurable overhead, so the routing is fine on cost grounds. LLVM ---- Built and installed --with-llvm (LLVM 23): it compiles, links, and llvmjit.so loads, with JIT operational (a heavy query reports Functions: 6). Under jit=on the coercion error still prints the correct CONTEXT, and the corruption WARNING still fires too -- which reconfirms the fault is at parse/plan, i.e. JIT-independent. I could not get EXPLAIN to show the assignment-coercion projection itself being JIT-compiled (INSERT/UPDATE ModifyTable target projections were not JIT-compiled in the shapes I tried, which looks like a PG JIT behaviour rather than the patch). So the EEOP_FUNCEXPR_COERCION dispatch is confirmed by code review (referenced_functions[] in llvmjit_types.c, dispatched in llvmjit_expr.c to the same helper as the interpreter) plus the module building and loading, rather than by a captured JIT-of-the-coercion run. Happy to re-check once the cassert issue is sorted. Regards, Manu