Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lX59O-0004Ln-4a for pgsql-general@arkaria.postgresql.org; Thu, 15 Apr 2021 16:47:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lX59N-0001mg-1q for pgsql-general@arkaria.postgresql.org; Thu, 15 Apr 2021 16:47:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lX59M-0001mM-QL for pgsql-general@lists.postgresql.org; Thu, 15 Apr 2021 16:47:28 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lX59K-0003Vk-RA for pgsql-general@postgresql.org; Thu, 15 Apr 2021 16:47:27 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 13FGlPPG3785443; Thu, 15 Apr 2021 12:47:25 -0400 From: Tom Lane To: Dmitry Dolgov <9erthalion6@gmail.com> cc: Mitar , pgsql-general@postgresql.org Subject: Re: Why is writing JSONB faster than just JSON? In-reply-to: <20210415154311.t3meozbednmsfhxx@localhost> References: <20210414084845.rkbe525twb4jr4fw@localhost> <3488585.1618410383@sss.pgh.pa.us> <20210415154311.t3meozbednmsfhxx@localhost> Comments: In-reply-to Dmitry Dolgov <9erthalion6@gmail.com> message dated "Thu, 15 Apr 2021 17:43:11 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3785441.1618505245.1@sss.pgh.pa.us> Date: Thu, 15 Apr 2021 12:47:25 -0400 Message-ID: <3785442.1618505245@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dmitry Dolgov <9erthalion6@gmail.com> writes: > On Wed, Apr 14, 2021 at 10:26:23AM -0400, Tom Lane wrote: >> My own guess about this, without having tried to reproduce it, is that >> JSONB might end up physically smaller than JSON, resulting in less work >> to push the toasted datum out to disk. This'd depend a lot on your >> formatting habits for JSON, of course. But in any case, it'd be worth >> comparing pg_column_size() results to see what's up with that. > Oh, of course I've missed that the input I was using was indeed > formatted, without formatting both cases perform equally well and I > can't reproduce the issue. Although if I understand correctly the > original code in question doesn't actually do any formatting. My point was that for JSON, after validating that the input is syntactically correct, we just store it as-received. So in particular the amount of whitespace in the value would depend on how the client had chosen to format the JSON. This'd affect the stored size of course, and I think it would have an effect on compression time too. regards, tom lane