From: Tom Lane <tgl@sss.pgh.pa.us>
To: ljw1001@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #11109: No Toast compression on JSON, JSONB columns
Date: Thu, 07 Aug 2014 17:42:15 -0400
Message-ID: <21178.1407447735@sss.pgh.pa.us> (raw)
In-Reply-To: <20140801182102.2696.87926@wrigleys.postgresql.org>
References: <20140801182102.2696.87926@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
ljw1001@gmail.com writes:
> if PG can, after compression, put an entire JSON or JSONB 'document' into
> one row/page in the toast table it does. However, if the document is too big
> to fit in one row after compression, it does no compression at all.
I can't reproduce this.
It does seem that JSONB is noticeably less compressible than the
equivalent plain-text representation, which is disappointing,
but I don't see it failing to compress at all.
I experimented with this SQL script:
create table bigjson(f1 jsonb);
-- alter table bigjson alter column f1 set storage external;
insert into bigjson values(
'{"junk":["124245etweetwet345gwtretwt43 qwrqwq qwre qwrsdflkas",
"q4535 wqrqwrqwrqw2 wrqwrqwrq32232w kswe sfasrssdfsd",
"124245etweetwet345gwtretwt43 qwrqwq qwre qw rsdflkas",
... 50000 repetitions of above two lines ...
"q4535wqrqwrqwrqw2 wrqwrqwrq32232w kswe sfasrssdfsd",
"124245etweetwet345gwtretwt43 qwrqwq qwre qw rsdflkas",
"foo"]}'
);
select pg_size_pretty(pg_table_size('bigjson'));
drop table bigjson;
I get about 568kB table size, versus 5640kB with the "external" option
uncommented, so it is compressing about 10-to-1. If I change the column
type to text (or json) then I get a table size of 120kB, which is better.
But on the other hand we should not put a lot of stock in the compression
rate achievable on such bogus data, so I'd not panic until I saw numbers
for more realistic test data.
What might be happening for you is that your actual test case triggers the
"first_success_by" filter in pglz_compress() because the first kilobyte of
input data isn't compressible. But since you didn't supply a fully
reproducible test case, that's just speculation.
> This is not the behavior observed with Text compression in Toast. For very
> large files Text compression works correctly. I got these results running
> similar tests on larger json files:
> Column Type - Storage - TOAST table size
> JSONB - EXTERNAL - 2448 MB
> JSONB - EXTENDED - 2448 MB
> JSON - EXTENDED - 2504 MB
> TEXT - EXTERNAL - 2409 MB
> TEXT - EXTENDED - 40 MB
json and text should (and do, for me) store exactly the same. So there's
something fishy going on here. Maybe you've changed the typstorage
values for json and jsonb in pg_type?
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, ljw1001@gmail.com
Subject: Re: BUG #11109: No Toast compression on JSON, JSONB columns
In-Reply-To: <21178.1407447735@sss.pgh.pa.us>
References: <20140801182102.2696.87926@wrigleys.postgresql.org> <21178.1407447735@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox