Received: from orion.SAPserv.Hamburg.dsh.de (Tpolaris2.sapham.debis.de [53.2.131.8]) by hub.org (8.9.3/8.9.3) with SMTP id EAA04997 for ; Sat, 22 Apr 2000 04:51:54 -0400 (EDT) (envelope-from wieck@debis.com) Received: by orion.SAPserv.Hamburg.dsh.de for pgsql-sql@postgresql.org id m12ivXh-0003knC; Sat, 22 Apr 100 10:45 MET DST Message-Id: From: wieck@debis.com (Jan Wieck) Subject: Re: TOAST (was: BLOB) In-Reply-To: from Peter Eisentraut at "Apr 22, 2000 00:04:01 am" To: Peter Eisentraut Date: Sat, 22 Apr 2000 10:45:33 +0200 (CEST) CC: Jan Wieck , pgsql-sql@postgresql.org Reply-To: Jan Wieck X-Mailer: ELM [version 2.4ME+ PL68 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archive-Number: 200004/251 Peter Eisentraut wrote: > > clob is a user defined, very simple varsize datatype, I > > created for testing. > > Keep it, it's SQL3. We don't need it later. At the time text is toastable, we can simply create an alias for it and are done. And I think blob is bytea then, isn't it? > > Seems there's something wrong in our deadlock detection > > algorithm. > > Our deadlock detection "algorithm" is that when nothing happens for 1 sec > then that's a deadlock. Increasing that number might make those messages > go away but that's still far from an algorithm, of course. Really? I remember that someday it was "if I'm waiting 60 seconds for my lock, ...". What a change. What's the exact location of that parameter to change? > > I'll need alot of help to make all our existing types > > toastable, > > I'm wondering how transparent all of this will be. What is involved in > making existing types toastable? How does that affect user defined > datatypes now and in the future? Let's look at the input/output functions of clob: void * clob_in(char *s) { void *c; int32 l; if (s == NULL) return NULL; l = strlen(s); c = (void *)palloc(VARHDRSZ + l); VARATT_SIZEP(c) = l + VARHDRSZ; memcpy(VARATT_DATA(c), s, l); return c; } char * clob_out(void *c) { void *p; char *s; int32 l; if (c == NULL) { s = palloc(2); s[0] = '-'; s[1] = '\0'; return s; } VARATT_GETPLAIN(c, p); l = VARATT_SIZE(p) - VARHDRSZ; s = (char *)palloc(l + 1); memcpy(s, VARATT_DATA(p), l); s[l] = '\0'; VARATT_FREE(c, p); return s; } So the input function doesn't change at all. Only functions that have a toastable type as argument need to wrap around with a local variable and the VARATT_GETPLAIN(), VARATT_FREE() macros. VARATT_GETPLAIN(arg, ptr) places the plain value of arg in ptr. If the argument wasn't toasted, it's assigned as is. If compressed or stored external, the original value is reconstructed in palloc()'d memory and assigned to ptr. VARATT_FREE(arg, ptr) free()'s ptr if it is different from arg. It all ain't that complicated. Easy enough to use it in user defined types too (a must because today's user defined functions usually use our base types too). Only that there are hundreds of functions in utils/adt and contrib that need to be looked at. Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #========================================= wieck@debis.com (Jan Wieck) #