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 1ncrBA-0003cF-Fz for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Apr 2022 16:09:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ncrB9-0006z3-CH for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Apr 2022 16:09:43 +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 1ncrB8-0006yu-1m for pgsql-hackers@lists.postgresql.org; Fri, 08 Apr 2022 16:09:43 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ncrB4-0003jU-Uv for pgsql-hackers@lists.postgresql.org; Fri, 08 Apr 2022 16:09:40 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id E75E05C0106; Fri, 8 Apr 2022 12:09:37 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 08 Apr 2022 12:09:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; bh=0jOJF4T6g2b9JG sCogZsUNilGhjzyW+DTHi1gbYsaV0=; b=UbtrTezlcymykGT8HhIWZOUHwux0lp iYsxg3v4o7HccXmUmAbmAXyQY3Q6cbLtt9lmtODX07K+0/9Ak+h1f2kOXKydd5ak q2ZWuEgFhvOQpg/pLYlzLszFit+Xr9J8Sv197vk3Uh77DvY5sYm+3LYzxo48ODRa PA799xfqAQFMDPk6bYAWCM1tZOfWVFvcEqDMxMqi4Lfk/oOvDayiflOF/HJSPbmZ RLJz2+fF3IP92EMMffdMBgOHwIAnZiDvFNkZgeo+cOPlx0j8abSGb9GDWTmqVWBp Azj7KDcMsUnv/R2e/MCkZ1iTnWtTS8oXcPjdQ1EGtVmVESaunDuBvd8g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=0jOJF4T6g2b9JGsCogZsUNilGhjzyW+DTHi1gbYsa V0=; b=B8J+uCp4mxGRAg6mr1PpuAReSjXAdWXI0H9Y41j9cqfFrXoGicv8zirN1 doKLgq236DcRP9fV8gg0FjJ743XaFj+C3CI4DiRjDPxar2aD3uXYGsi+mlxEuJLy Cfljon3m/cigwWUDodM581qu9bRUJlfQc1tSUl6SFHJNgRvv9l+zCLWDH/mkbSUw lOCJCHRTcjBygY4zQtEZnynWUm3Czz0Elpxq5R7SFc7PBcUl2i4p+6qg4Ap+NnFp ZkeKmNabbboYSTVQhPv1UmySKSwY1I+/50ZDCArG0cT3AS7+b+HboCfbp6tjH9ak KHZV/tIEjpefZu1D5WXNmsH3MOcAQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudektddgleehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffufggjfhfkgggtgfesthhqmhdttderjeenucfhrhhomheptehnughr vghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrf grthhtvghrnhepfedttdfhlefhfeehheekjeegheefhedvhffgtdeivedugeevkeelfefg vdeghedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh eprghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 8 Apr 2022 12:09:36 -0400 (EDT) Date: Fri, 08 Apr 2022 09:09:34 -0700 From: Andres Freund To: Matthias van de Meent CC: Nitin Jadhav , Bharath Rupireddy , Ashutosh Sharma , Julien Rouhaud , Bruce Momjian , Tom Lane , Magnus Hagander , PostgreSQL Hackers Subject: =?US-ASCII?Q?Re=3A_Size_of_pg=5Frewrite_=28Was=3A_Report_checkpoi?= =?US-ASCII?Q?nt_progress_with_pg=5Fstat=5Fprogress=5Fcheckpoint=29?= User-Agent: K-9 Mail for Android In-Reply-To: References: <20220319001556.atuqbmafvc73pa2k@alap3.anarazel.de> Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi,=20 On April 8, 2022 7:52:07 AM PDT, Matthias van de Meent wrote: >On Sat, 19 Mar 2022 at 01:15, Andres Freund wrote: >> pg_rewrite without pg_stat_progress_checkpoint: 745472, with: 753664 >> >> pg_rewrite is the second biggest relation in an empty database already= =2E=2E=2E > >Yeah, that's not great=2E Thanks for nerd-sniping me into looking into >how views and pg_rewrite rules work, that was very interesting and I >learned quite a lot=2E Thanks for looking! ># Immediately potential, limited to progress views > >I noticed that the CASE-WHEN (used in translating progress stage index >to stage names) in those progress reporting views can be more >efficiently described (althoug with slightly worse behaviour around >undefined values) using text array lookups (as attached)=2E That >resulted in somewhat smaller rewrite entries for the progress views >(toast compression was good old pglz): > >template1=3D# SELECT sum(octet_length(ev_action)), >SUM(pg_column_size(ev_action)) FROM pg_rewrite WHERE >ev_class::regclass::text LIKE '%progress%'; > >master: > sum | sum >-------+------- > 97277 | 19956 >patched: > sum | sum >-------+------- > 77069 | 18417 > >So this seems like a nice improvement of 20% uncompressed / 7% compressed= =2E > >I tested various cases of phase number to text translations: `CASE =2E=2E >WHEN`; `(ARRAY[]::text[])[index]` and `('{}'::text[])[index]`=2E See >results below: > >postgres=3D# create or replace view arrayliteral_view as select >(ARRAY['a','b','c','d','e','f']::text[])[index] as name from tst >s(index); >CREATE INDEX >postgres=3D# create or replace view stringcast_view as select >('{a,b,c,d,e,f}'::text[])[index] as name from tst s(index); >CREATE INDEX >postgres=3D# create or replace view split_stringcast_view as select >(('{a,b,' || 'c,d,e,f}')::text[])[index] as name from tst s(index); >CREATE VIEW >postgres=3D# create or replace view case_view as select case index when >0 then 'a' when 1 then 'b' when 2 then 'c' when 3 then 'd' when 4 then >'e' when 5 then 'f' end as name from tst s(index); >CREATE INDEX > > >postgres=3D# postgres=3D# select ev_class::regclass::text, >octet_length(ev_action), pg_column_size(ev_action) from pg_rewrite >where ev_class in ('arrayliteral_view'::regclass::oid, >'case_view'::regclass::oid, 'split_stringcast_view'::regclass::oid, >'stringcast_view'::regclass::oid); > ev_class | octet_length | pg_column_size >-----------------------+--------------+---------------- > arrayliteral_view | 3311 | 1322 > stringcast_view | 2610 | 1257 > case_view | 5170 | 1412 > split_stringcast_view | 2847 | 1350 > >It seems to me that we could consider replacing the CASE statements >with array literals and lookups if we really value our template >database size=2E But, as text literal concatenations don't seem to get >constant folded before storing them in the rules table, this rewrite >of the views would result in long lines in the system_views=2Esql file, >or we'd have to deal with the additional overhead of the append >operator and cast nodes=2E My inclination is that the mapping functions should be c functions=2E Ther= e's really no point in doing it in SQL and it comes at a noticable price=2E= And, if done in C, we can fix mistakes in minor releases, which we can't i= n SQL=2E ># Future work; nodeToString / readNode, all rewrite rules > >Additionally, we might want to consider other changes like default (or >empty value) elision in nodeToString, if that is considered a >reasonable option and if we really want to reduce the size of the >pg_rewrite table=2E > >I think a lot of space can be recovered from that: A manual removal of >what seemed to be fields with default values (and the removal of all >query location related fields) in the current definition of >pg_stat_progress_create_index reduces its uncompressed size from >23226B raw and 4204B compressed to 13821B raw and 2784B compressed, >for an on-disk space saving of 33% for this view's ev_action=2E > >Do note, however, that that would add significant branching in the >nodeToString and readNode code, which might slow down that code >significantly=2E I'm not planning on working on that; but in my opinion >that is a viable path to reducing the size of new database catalogs=2E We should definitely be careful about that=2E I do agree that there's a lo= t of efficiency to be gained in the serialization format=2E Once we have th= e automatic node func generation in place, we could have one representation= for human consumption, and one for density=2E=2E=2E Andres --=20 Sent from my Android device with K-9 Mail=2E Please excuse my brevity=2E