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 1lX7Os-0000cm-Fv for pgsql-general@arkaria.postgresql.org; Thu, 15 Apr 2021 19:11:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lX7Oq-0007lj-5k for pgsql-general@arkaria.postgresql.org; Thu, 15 Apr 2021 19:11:36 +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 <9erthalion6@gmail.com>) id 1lX7Op-0007kB-Rc for pgsql-general@lists.postgresql.org; Thu, 15 Apr 2021 19:11:35 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1lX7Ok-0004fU-0h for pgsql-general@postgresql.org; Thu, 15 Apr 2021 19:11:34 +0000 Received: by mail-ed1-x530.google.com with SMTP id o20so3116981edc.7 for ; Thu, 15 Apr 2021 12:11:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Ryg/lFnhxDm3MmWo4k5IVuasvq4tG9QXQmhGNtRovVA=; b=adhWNsqlg3hZWtcVZ06L/9LW28K6QZYrtt7VgsXOKsqZPKUjCxYK9F1kMsUdAyF2a2 /lt6JWXG7jAJJuRHL9y8xc6vOR32PJW6i/NXhMJ4ePw8afTWBuJfi0VMi88yrGTnLqdW pjmq7SfDG25y4S15b1f9SQXcsVSVpD/tgPRj5sD/PQux0WtiFkvG5syPE6z26uO9CM7U bZRTsmebPSlv6qchNk6YPu1UUG6JZIWmcKQGXEgcCNClJomQxbV0cjWMlis6hkDo3App LSKbxavgKuZxYcAEpLco04UbapSCIyq1w3YVa9xXQteWb0Lk/OnAPT/yLzRi41aZPM7D iB7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Ryg/lFnhxDm3MmWo4k5IVuasvq4tG9QXQmhGNtRovVA=; b=KUUoB7TnUtx40qfBRYarekWjMOw6FwR/d9hpBlPNzOJH6Tsr9zS/64wiwP4fJGZypm 0TglCIhUYt8MtDPzTEFkrxf3UjeK7OpCBBb6PpM9bOaG0cTRygSnh8giSShOQ+FsltuK LV/n6EAEtfPmH8Nxb2ptjhRu6s7iX12ICtHibwy2jGZGUJbPWUHWgAcc102xkx+NJtEL ClLFQy+nNVF63oFFIyI7+uWNsCop/uGX6/p7unr6AAKwnOyM3SLOZAU9dShcVb0CRm+D 4buKgqs1vfXEYFy/i7VA3nuwrDlrg5gtviu1X19/ynKiygKa6Un6BSZw29QtK96FmXFP 7jgA== X-Gm-Message-State: AOAM5314r0lSDu6WaqTmcSweLY/PHLcVmG/9g2rd8htVA3DoNu8WHuW3 bQ14EPhqqpRK0kvBHIQ+BIaCZs5jhgk= X-Google-Smtp-Source: ABdhPJwf0ogKHFYcBzaKyPFPWif7C9F+AQQBPOzSI7SIq47YNC8It1qGLYgXHB97iK6Dv49uCJ7r7g== X-Received: by 2002:a05:6402:31ad:: with SMTP id dj13mr5955841edb.167.1618513888281; Thu, 15 Apr 2021 12:11:28 -0700 (PDT) Received: from localhost (dslb-178-012-047-165.178.012.pools.vodafone-ip.de. [178.12.47.165]) by smtp.gmail.com with ESMTPSA id lv10sm1951112ejb.118.2021.04.15.12.11.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Apr 2021 12:11:27 -0700 (PDT) Date: Thu, 15 Apr 2021 21:11:40 +0200 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Tom Lane Cc: Mitar , pgsql-general@postgresql.org Subject: Re: Why is writing JSONB faster than just JSON? Message-ID: <20210415191140.pu4jukp6245wkzit@localhost> References: <20210414084845.rkbe525twb4jr4fw@localhost> <3488585.1618410383@sss.pgh.pa.us> <20210415154311.t3meozbednmsfhxx@localhost> <3785442.1618505245@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3785442.1618505245@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Thu, Apr 15, 2021 at 12:47:25PM -0400, Tom Lane wrote: > 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. Yes, I got it and just wanted to confirm you were right - this was the reason I've observed slowdown trying to reproduce the report.