Skip site navigation (1) Skip section navigation (2)

Re: Dept of ugly hacks: eliminating padding space in system indexes

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Dept of ugly hacks: eliminating padding space in system indexes
Date: 2008-06-23 20:14:39
Message-ID: 200806232014.m5NKEdb04616@momjian.us (view raw or flat)
Thread:
Lists: pgsql-hackers
I would mention in the C comment that we are doing this for space
savings, but other than that, it seems fine.

---------------------------------------------------------------------------

Tom Lane wrote:
> I was thinking a bit about how we pad columns of type NAME to
> fixed-width, even though they're semantically equivalent to C strings.
> The reason for wasting that space is that it makes it possible to
> overlay a C struct onto the leading columns of most system catalogs.
> I don't wish to propose changing that (at least not today), but it
> struck me that there is no reason to overlay a C struct onto index
> entries, and that getting rid of the padding space would be even more
> useful in an index than in the catalog itself.  It turns out to be
> dead easy to implement this: effectively, we just decree that the
> index column storage type for NAME is always CSTRING.  Because the
> two types are effectively binary-compatible as long as you don't
> look at the padding, the attached ugly-but-impressively-short patch
> seems to accomplish this.  It passes the regression tests anyway.
> Here are some numbers about the space savings in a virgin database:
> 
> 						    CVS HEAD	w/patch	savings
> 
> pg_database_size('postgres')			    4439752	4071112	8.3%
> pg_relation_size('pg_class_relname_nsp_index')	    57344	40960	28%
> pg_relation_size('pg_proc_proname_args_nsp_index')  319488	204800	35%
> 
> Cutting a third off the size of a system index has got to be worth
> something, but is it worth a hack as ugly as this one?
> 
> 			regards, tom lane
> 
> 

Content-Description: index-name-as-cstring.patch

> Index: src/backend/catalog/index.c
> ===================================================================
> RCS file: /cvsroot/pgsql/src/backend/catalog/index.c,v
> retrieving revision 1.300
> diff -c -r1.300 index.c
> *** src/backend/catalog/index.c	19 Jun 2008 00:46:04 -0000	1.300
> --- src/backend/catalog/index.c	23 Jun 2008 19:34:54 -0000
> ***************
> *** 262,267 ****
> --- 262,278 ----
>   
>   			ReleaseSysCache(tuple);
>   		}
> + 
> + 		/*
> + 		 * For an index on NAME, force the index storage to be CSTRING,
> + 		 * rather than padded to fixed length.
> + 		 */
> + 		if (to->atttypid == NAMEOID)
> + 		{
> + 			to->atttypid = CSTRINGOID;
> + 			to->attlen = -2;
> + 			to->attalign = 'c';
> + 		}
>   	}
>   
>   	return indexTupDesc;

> 
> -- 
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers

-- 
  Bruce Momjian  <bruce(at)momjian(dot)us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

In response to

pgsql-hackers by date

Next:From: Bruce MomjianDate: 2008-06-23 20:21:01
Subject: Re: Remove hacks for old bad qsort() implementations?
Previous:From: Tom LaneDate: 2008-06-23 19:52:36
Subject: Dept of ugly hacks: eliminating padding space in system indexes

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group