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 1rj6Ja-003T0O-0M for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Mar 2024 23:41:18 +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 1rj6JW-002SoS-Nb for pgsql-hackers@arkaria.postgresql.org; Sat, 09 Mar 2024 23:41:15 +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 1rj6JW-002SoI-EY for pgsql-hackers@lists.postgresql.org; Sat, 09 Mar 2024 23:41:14 +0000 Received: from m15.mail.163.com ([45.254.50.220]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rj6JP-003hnv-S0 for pgsql-hackers@lists.postgresql.org; Sat, 09 Mar 2024 23:41:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=UvC1s4jr9wP519B1akglP0a2mnV075EXJHL3HZ8Wniw=; b=RtdwGwgy0JEA6VvpUVmUswQidNsMzD/v7XBH94fHqjCEdBYGZgjLWdhg/2jCy8 pGZU3lw43xzi0nKqx+tKKVm5/PT+tS0HhHFwMewcBG+FWhltN0YMTaBUMvATKUWx 5hkn+HSLyvV948oxgH23Hh4kEtFZTMSv/xQdYCuU3XS0M= Received: from 8235eee8a2a0 (unknown [140.205.118.89]) by gzga-smtp-mta-g0-3 (Coremail) with SMTP id _____wDn7+VV8+xlNioPBQ--.1114S3; Sun, 10 Mar 2024 07:40:06 +0800 (CST) References: <169880504467.94392.3769687331705514588.pgcf@coridan.postgresql.org> <87a5rry0bz.fsf@163.com> <87h6jpob9x.fsf@163.com> <87r0hmvuvr.fsf@163.com> <8102ff5b-b156-409e-a48f-e53e63a39b36@eisentraut.org> <8734t6c5rh.fsf@163.com> User-agent: mu4e 1.10.7; emacs 29.1 From: Andy Fan To: Andy Fan Cc: Peter Eisentraut , Amit Langote , Alvaro Herrera , jian he , Chapman Flack , pgsql-hackers@lists.postgresql.org Subject: Re: Extract numeric filed in JSONB more effectively Date: Sun, 10 Mar 2024 07:16:40 +0800 In-reply-to: <8734t6c5rh.fsf@163.com> Message-ID: <87o7bn7z56.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain X-CM-TRANSID:_____wDn7+VV8+xlNioPBQ--.1114S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7WrykJrW3WrW5KFW8KF4xXrb_yoW8ur45pa ySkryakrsrJr10yrn2vw1Fgr1IkrsYyrnxGa1Yg348W398WFyvgrWrtr4j9rWDuryrKw1f Xan8Z348AFZava7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0JU8OzcUUUUU= X-Originating-IP: [140.205.118.89] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/xtbBzxicU2V4IJd9KAAAsn List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk >> But I have a different question about this patch set. This has some >> overlap with the JSON_VALUE function that is being discussed at >> [0][1]. For example, if I apply the patch >> v39-0001-Add-SQL-JSON-query-functions.patch from that thread, I can run >> >> select count(*) from tb where json_value(a, '$.a' returning numeric) = 2; >> >> and I get a noticeable performance boost over >> >> select count(*) from tb where cast (a->'a' as numeric) = 2; > > Here is my test and profile about the above 2 queries. > .. > As we can see the patch here has the best performance (this result looks > be different from yours?). > > After I check the code, I am sure both patches *don't* have the problem > in master where it get a jsonbvalue first and convert it to jsonb and > then cast to numeric. > > Then I perf the result, and find the below stuff: > .. > JSONB_VALUE has a much longer way to get getKeyJsonValueFromContainer, > then I think JSON_VALUE probably is designed for some more complex path > which need to pay extra effort which bring the above performance > difference. Hello Peter, Thanks for highlight the JSON_VALUE patch! Here is the sistuation in my mind now. My patch is desigined to *not* introducing any new user-faced functions, but let some existing functions run faster. JSON_VALUE patch is designed to following more on SQL standard so introuduced one new function which has more flexibility on ERROR handling [1]. Both patches are helpful on the subject here, but my patch here has a better performance per my testing, I don't think I did anything better here, just because JSON_VALUE function is designed for some more generic purpose which has to pay some extra effort, and even if we have some chance to improve JSON_VALUE, I don't think it shoud not block the patch here (I'd like to learn more about this, it may takes some time!) So I think the my patch here can be go ahead again, what do you think? [1] https://www.postgresql.org/message-id/CACJufxGtetrn34Hwnb9D2if5D_HOPAh235MtEZ1meVYx-BiNtg%40mail.gmail.com -- Best Regards Andy Fan