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 1rT5bC-000MMl-Pf for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jan 2024 19:41:19 +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 1rT5bA-002vNO-MG for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jan 2024 19:41:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rT5bA-002vNG-CS for pgsql-hackers@lists.postgresql.org; Thu, 25 Jan 2024 19:41:16 +0000 Received: from mail-qk1-x730.google.com ([2607:f8b0:4864:20::730]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rT5b7-003hVc-AB for pgsql-hackers@lists.postgresql.org; Thu, 25 Jan 2024 19:41:15 +0000 Received: by mail-qk1-x730.google.com with SMTP id af79cd13be357-783bc26b24aso77221285a.0 for ; Thu, 25 Jan 2024 11:41:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dunslane-net.20230601.gappssmtp.com; s=20230601; t=1706211671; x=1706816471; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=t6o+FE0VA0djMVnn8f/4uuWhoEUG0RpdJ1wTJNSePos=; b=Rxw92F1RJNBvD5biLo33FftVhqWJDhMzBkMMrcem9CUJXwKJFuYlhgBgi4CSEx+SQ0 zTzlSpSqoNtOKiEa8cTvBBYQ+KjeYwbODEqXuSj1BHmfpM7BFAj5LKaD6B8hbXpKf9Rt RZoT48qS0YTryWcltC0eaVWIpZrv9dkTPs8WMn9ZflCwSN3Mc4GKbK5qv04MDSng1vGa LOlDJ99t6xkktcIVNSnPF5rsvcs4LjsZekSAgbc4peovmEq8QiXY1Sx96jhnWwXop86o Q3QuSozuE5fNoRt24zLmkokJK+Qba+GbcuJbpGBaSEbNnXyXJ0O/dryLU0m9BfXaobD0 tRlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706211671; x=1706816471; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=t6o+FE0VA0djMVnn8f/4uuWhoEUG0RpdJ1wTJNSePos=; b=vALJEcWGcFn3BCgyMY04fQ8SZeJII34fF3xv8mHb+zaoLn+7mEAynPhL4U3q1oGxUW wgGvCFRJwNCGfPXKF4tPRGUD5YlpyUkFPQtwyKLdcgKdA/V1KU9ugnYgyuwrwQV9EE5u iuwULj7dz7TMoINQf4ESGdkBzmnt4Lp6quuM2SIiUT5GixCillcw8YtieLdLp9whQhAx ZDE2/O46j8bqwE8PhVZUIKqyBEndxiVDpKJe5fCeNIBZSh6m9k5sDUKebyWKU11W9qs2 hcwH6KvkxFVlJ/16S415sE1at9JtKRhML84LZQVuAHUolwCzOfFaRXl2u+up6kA15JYF C6bA== X-Gm-Message-State: AOJu0YzsQllCAkfWdMfvrt/z4/a/Pet/nz3vRHjRDQ1cCTZEKhMELe89 JZjol0GxqfqZYTF9IWYQp2/aNjRbDAMRE7QpbASra+nbAfHxNGdMjt0bPAfWj4Y= X-Google-Smtp-Source: AGHT+IFvys6UR+nKuBRPFXlXAFj8fbJOdjoVQRkxlcVdpNhfw3qrzEeZQahwr9I0l2+1qdLQzgmKlA== X-Received: by 2002:a05:6214:410:b0:686:595:2afa with SMTP id z16-20020a056214041000b0068605952afamr233300qvx.22.1706211669212; Thu, 25 Jan 2024 11:41:09 -0800 (PST) Received: from ?IPV6:2605:a601:91f3:1900::2bb? ([2605:a601:91f3:1900::2bb]) by smtp.googlemail.com with ESMTPSA id lv7-20020a056214578700b00684d2729709sm288564qvb.85.2024.01.25.11.41.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Jan 2024 11:41:08 -0800 (PST) Message-ID: <8076cbc9-c615-6693-f661-14275899f429@dunslane.net> Date: Thu, 25 Jan 2024 14:41:07 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: More new SQL/JSON item methods Content-Language: en-US To: Tom Lane Cc: Jeevan Chalke , Peter Eisentraut , PostgreSQL Hackers References: <1d092c02-8249-4e56-8b8e-ae4db95b8fde@eisentraut.org> <5d37428e-0753-e721-8e77-81cc4d0dc9f1@dunslane.net> <439811.1706211069@sss.pgh.pa.us> From: Andrew Dunstan In-Reply-To: <439811.1706211069@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-01-25 Th 14:31, Tom Lane wrote: > Andrew Dunstan writes: >> Thanks, I have pushed this. > The buildfarm is pretty widely unhappy, mostly failing on > > select jsonb_path_query('1.23', '$.string()'); > > On a guess, I tried running that under valgrind, and behold it said > > ==00:00:00:05.637 435530== Conditional jump or move depends on uninitialised value(s) > ==00:00:00:05.637 435530== at 0x8FD131: executeItemOptUnwrapTarget (jsonpath_exec.c:1547) > ==00:00:00:05.637 435530== by 0x8FED03: executeItem (jsonpath_exec.c:626) > ==00:00:00:05.637 435530== by 0x8FED03: executeNextItem (jsonpath_exec.c:1604) > ==00:00:00:05.637 435530== by 0x8FCA58: executeItemOptUnwrapTarget (jsonpath_exec.c:956) > ==00:00:00:05.637 435530== by 0x8FFDE4: executeItem (jsonpath_exec.c:626) > ==00:00:00:05.637 435530== by 0x8FFDE4: executeJsonPath.constprop.30 (jsonpath_exec.c:612) > ==00:00:00:05.637 435530== by 0x8FFF8C: jsonb_path_query_internal (jsonpath_exec.c:438) > > It's fairly obviously right about that: > > JsonbValue jbv; > ... > jb = &jbv; > Assert(tmp != NULL); /* We must have set tmp above */ > jb->val.string.val = (jb->type == jbvString) ? tmp : pstrdup(tmp); > ^^^^^^^^^^^^^^^^^^^^^ > > Presumably, this is a mistaken attempt to test the type > of the thing previously pointed to by "jb". > > On the whole, what I'd be inclined to do here is get rid > of this test altogether and demand that every path through > the preceding "switch" deliver a value that doesn't need > pstrdup(). The only path that doesn't do that already is > > case jbvBool: > tmp = (jb->val.boolean) ? "true" : "false"; > break; > > and TBH I'm not sure that we really need a pstrdup there > either. The constants are immutable enough. Is something > likely to try to pfree the pointer later? I tried > > @@ -1544,7 +1544,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, > > jb = &jbv; > Assert(tmp != NULL); /* We must have set tmp above */ > - jb->val.string.val = (jb->type == jbvString) ? tmp : pstrdup(tmp); > + jb->val.string.val = tmp; > jb->val.string.len = strlen(jb->val.string.val); > jb->type = jbvString; > > and that quieted valgrind for this particular query and still > passes regression. > > (The reported crashes seem to be happening later during a > recursive invocation, seemingly because JsonbType(jb) is > returning garbage. So there may be another bug after this one.) > > Argh! Will look, thanks. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com