Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hztVi-0000g9-4E for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Aug 2019 02:04:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hztVg-0004hB-WC for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Aug 2019 02:04:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hztVg-0004h4-Il for pgsql-hackers@lists.postgresql.org; Tue, 20 Aug 2019 02:04:32 +0000 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hztVd-0006Kk-T6 for pgsql-hackers@postgresql.org; Tue, 20 Aug 2019 02:04:32 +0000 Received: by mail-io1-xd42.google.com with SMTP id j5so8774491ioj.8 for ; Mon, 19 Aug 2019 19:04:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=oo3LQujiQ22XhLUV5ergX/y76GdxD7+zlwui3nd1h/4=; b=azIiO5F/hAR1OM028yyA3rftOYJ05oIBZ92TPeduIyGO+cV8mH0+ly5Y2F3rw2Gz3j dabdDim8P6yngs4pRDz12Pplk+6k6sKwf4Nh9WLVM1dRZ102USHKmyXTouqnLmdPC2aU 2IkbRXk4O380B4ZLEu2HMS790dfz5PxNhIRzHGjNzXFL0e7jcJeUURfIRqouLTh5W3Uf Rcb+heHKP0bm9Wru70FvdIf6dmaknj5mq7blRSp6dj1rJdKtUIuffQSqXYkTsFmyyabW cGNeDkrHhlPdiM44ifZ8FQpXn2NlFQvYQ7kQHPAI+HiCXO+aS5pMjrvdN0ob6iOBbj93 7cKQ== 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:user-agent; bh=oo3LQujiQ22XhLUV5ergX/y76GdxD7+zlwui3nd1h/4=; b=ZSa3JVT3bzLwVct8YnE5DcRyej0rKU2Sus73Z5aAoFBYubbThNfkfss9x25kiBOIJg PCagcPlk7dNDC+DlBdMOxQjjM+M5BeP5oBqE715HXpH6h4I4boT6ZW9Ojj2hlUjI5vP1 Q9DAYzYYB5lRfJovo1cH7hZ5PZpWALTQfSc23sb8d5x/fj1a8Cy+EIWkm41bShU/L+ok MUggrI2mcClhakf13qlUhGv2g1I7ZYTcmn3kclGyhHMI9gvy8KTqu7ScWxbkaBGtNKFW slAJXmi83tpf1ZtZUx7umu03BGZIo88owukBz2fQXSmt/6XRUxjj2GUG3sAnhznnAaPd dIjA== X-Gm-Message-State: APjAAAXxgcMnccUUDZLtQ/ZHGmrsWtur44pIbjUF1OwkKVaW0bQu7NqU JgCuTGR5lqrjzDZd5JMWhP2fuA== X-Google-Smtp-Source: APXvYqwoKqk+wF16br1H1fjySixPqTgdw12HQneFSGlh0lVqkjc7P+ymGpPmM2/+XFSPQYmyMVfzSw== X-Received: by 2002:a5e:c911:: with SMTP id z17mr990882iol.119.1566266668186; Mon, 19 Aug 2019 19:04:28 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id t2sm27809455iod.81.2019.08.19.19.04.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Aug 2019 19:04:27 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 9ADA7800DAB; Mon, 19 Aug 2019 21:04:25 -0500 (CDT) Date: Mon, 19 Aug 2019 21:04:25 -0500 From: Justin Pryzby To: Alexandra Wang Cc: Heikki Linnakangas , Ashwin Agrawal , Ashutosh Sharma , PostgreSQL mailing lists Subject: Re: Zedstore - compressed in-core columnar storage Message-ID: <20190820020425.GX11185@telsasoft.com> References: <5ceff1bd.1c69fb81.704ee.a5b1SMTPIN_ADDED_BROKEN@mx.google.com> <20190818193533.GL11185@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Aug 19, 2019 at 04:15:30PM -0700, Alexandra Wang wrote: > On Sun, Aug 18, 2019 at 12:35 PM Justin Pryzby wrote: > > > . I was missing a way to check for compression ratio; > > Here are the ways to check compression ratio for zedstore: > > Table level: > SELECT sum(uncompressedsz::numeric)/sum(totalsz) AS compratio FROM pg_zs_btree_pages(); postgres=# SELECT sum(uncompressedsz::numeric)/sum(totalsz) AS compratio FROM pg_zs_btree_pages('child.cdrs_huawei_pgwrecord_2019_07_01'); compratio | 4.2730304163521529 For a fair test, I created a separate ZFS tablspace for storing just a copy of that table. ts=# CREATE TABLE test TABLESPACE testcomp AS SELECT * FROM child.cdrs_huawei_pgwrecord_2019_07_01; SELECT 39933381 Time: 882417.775 ms (14:42.418) zfs/testJTP20190819 compressratio 6.01x - zfs/testJTP20190819 compression gzip-1 inherited from zfs > Per column level: > select attno, count(*), sum(uncompressedsz::numeric)/sum(totalsz) as compratio from pg_zs_btree_pages() group by attno order by attno; Order by 3; I see we have SOME highly compressed columns. It's still surprising to me that's as low as it is, given their content: phone numbers and IPv4 addresses in text form, using characters limited to [[:digit:].] (I realize we can probably save space using inet type.) 0 | 4743 | 1.00000000000000000000 32 | 21912 | 1.05953637381493823513 80 | 36441 | 1.2416446300175039 4 | 45059 | 1.3184106811322728 83 | 45059 | 1.3184106811322728 52 | 39208 | 1.3900788061770992 ... 74 | 3464 | 10.8258665101057364 17 | 3535 | 10.8776086243096534 3 | 7092 | 11.0388009154683678 11 | 3518 | 11.4396055611832109 65 | 3333 | 14.6594723104237634 35 | 14077 | 15.1642131499381887 ... 43 | 1601 | 21.4200106784573211 79 | 1599 | 21.4487670806076829 89 | 1934 | 23.6292134031933401 33 | 1934 | 23.6292134031933401 It seems clear the columns with high n_distinct have low compress ratio, and columns with high compress ratio are those with n_distinct=1... CREATE TEMP TABLE zs AS SELECT zs.*, n_distinct, avg_width, a.attname FROM (SELECT 'child.cdrs_huawei_pgwrecord_2019_07_01'::regclass t)t , LATERAL (SELECT attno, count(*), sum(uncompressedsz::numeric)/sum(totalsz) AS compratio FROM pg_zs_btree_pages(t) GROUP BY attno)zs , pg_attribute a, pg_class c, pg_stats s WHERE a.attrelid=t AND a.attnum=zs.attno AND c.oid=a.attrelid AND c.relname=s.tablename AND s.attname=a.attname; n_distinct | compratio ------------+------------------------ 217141 | 1.2416446300175039 154829 | 1.5306062496764190 144486 | 1.3900788061770992 128334 | 1.5395022739568842 121324 | 1.4005533187886683 86341 | 1.6262709389296389 84073 | 4.4379336418590519 65413 | 5.1890181028038757 63703 | 5.5029855093836425 63637 | 5.3648468796642262 46450 | 1.3184106811322728 46450 | 1.3184106811322728 43029 | 1.8003513772661308 39363 | 1.5845730687475706 36720 | 1.4751147557399539 36445 | 1.8403087513759131 36445 | 1.5453935268318613 11455 | 1.05953637381493823513 2862 | 9.8649823666870671 2625 | 2.3573614181847621 1376 | 1.7895024285340428 1335 | 2.2812551964262787 807 | 7.1192324141359373 610 | 7.9373623460089360 16 | 11.4396055611832109 10 | 5.5429763442365557 7 | 5.0440578041440675 7 | 5.2000132813261135 4 | 6.9741514753325536 4 | 4.2872818036896340 3 | 1.9080838412634827 3 | 2.9915954457453485 3 | 2.3056387009407882 2 | 10.8776086243096534 2 | 5.5950929307378287 2 | 18.5796576388128741 2 | 10.8258665101057364 2 | 9.1112820658021406 2 | 3.4986057630739795 2 | 4.6250999234025238 2 | 11.0388009154683678 1 | 15.1642131499381887 1 | 2.8855860118178798 1 | 23.6292134031933401 1 | 21.4200106784573211 [...] > > it looks like zedstore > > with lz4 gets ~4.6x for our largest customer's largest table. zfs using > > compress=gzip-1 gives 6x compression across all their partitioned > > tables, > > and I'm surprised it beats zedstore . > > > > What kind of tables did you use? Is it possible to give us the schema > of the table? Did you perform 'INSERT INTO ... SELECT' or COPY? I did this: |time ~/src/postgresql.bin/bin/pg_restore /srv/cdrperfbackup/ts/final/child.cdrs_huawei_pgwrecord_2019_07_01 -f- |PGOPTIONS='-cdefault_table_access_method=zedstore' psql --port 5678 postgres --host /tmp ... COPY 39933381 ... real 100m25.764s child | cdrs_huawei_pgwrecord_2019_07_01 | table | pryzbyj | permanent | 8277 MB | postgres=# SELECT array_to_string(array_agg(format_type(atttypid, atttypmod) ||CASE WHEN attnotnull THEN ' not null' ELSE '' END ORDER BY attnum),',') FROM pg_attribute WHERE attrelid='child.cdrs_huawei_pgwrecord_2019_07_01'::regclass AND attnum>0; array_to_string | text not null,text,text not null,text not null,text not null,text,text,text,boolean,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,timestamp without time zone not null,bigint not null,text not null,text,text,text,text,text,text,text,text,text,text not null,text,boolean,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,text,timestamp with time zone,timestamp with time zone,text,text,boolean,text,text,boolean,boolean,text not null,text not null