| From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> | 
|---|---|
| To: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> | 
| Cc: | Peter Eisentraut <peter_e(at)gmx(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org> | 
| Subject: | Re: OCTET_LENGTH is wrong | 
| Date: | 2001-11-19 18:28:31 | 
| Message-ID: | 200111191828.fAJISVP07644@candle.pha.pa.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
OK, I have applied this patch so text octet_length returns
non-compressed length of data, to match octet_length of other types.
I also removed the XXX comments added by Tom.
---------------------------------------------------------------------------
> > I think "the value of S" implies "the user-accessible representation of
> > the value of S", in the sense, "How much memory do I need to allocate to
> > store this value".
> > 
> > Furthermore, the size of the TOAST representation that is returned now is
> > just one particular of several intermediate representations.  For
> > instance, it does not include the VARHDRSZ and it does not include the
> > size of the tuple headers when it's stored externally.  Thus, this size is
> > heavily skewed toward low numbers and doesn't tell you much about either
> > the disk end or the user's end.
> 
> Yes, good arguments.  If we want to implement storage_length at some
> later time, I think the compressed length may be appropriate, but for
> general use, I think we need to return the uncompressed length,
> especially considering that multibyte makes the ordinary 2length return
> number of characters, so users need a way to get byte length.
> 
> Attached is a patch that makes text return the same value type as char()
> and varchar() already do.  As Tatsuo pointed out, they were
> inconsistent.  All the other octet_length() functions look fine so it
> was only text that had this problem.
> 
> -- 
>   Bruce Momjian                        |  http://candle.pha.pa.us
>   pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 853-3000
>   +  If your life is a hard drive,     |  830 Blythe Avenue
>   +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
> Index: src/backend/utils/adt/varlena.c
> ===================================================================
> RCS file: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v
> retrieving revision 1.74
> diff -c -r1.74 varlena.c
> *** src/backend/utils/adt/varlena.c	2001/10/25 05:49:46	1.74
> --- src/backend/utils/adt/varlena.c	2001/11/18 19:11:52
> ***************
> *** 273,284 ****
>   Datum
>   textoctetlen(PG_FUNCTION_ARGS)
>   {
> ! 	struct varattrib *t = (struct varattrib *) PG_GETARG_RAW_VARLENA_P(0);
>   
> ! 	if (!VARATT_IS_EXTERNAL(t))
> ! 		PG_RETURN_INT32(VARATT_SIZE(t) - VARHDRSZ);
> ! 
> ! 	PG_RETURN_INT32(t->va_content.va_external.va_extsize);
>   }
>   
>   /*
> --- 273,281 ----
>   Datum
>   textoctetlen(PG_FUNCTION_ARGS)
>   {
> ! 	text    *arg = PG_GETARG_VARCHAR_P(0);
>   
> ! 	PG_RETURN_INT32(VARSIZE(arg) - VARHDRSZ);
>   }
>   
>   /*
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2001-11-19 18:38:03 | Re: OCTET_LENGTH is wrong | 
| Previous Message | F Harvell | 2001-11-19 18:00:11 | Re: [HACKERS] bug or change in functionality in 7.2? |