charset/collation in values

Started by Dennis Bjorklundabout 21 years ago15 messages
#1Dennis Bjorklund
db@zigo.dhs.org

I've looked into storing charset/collation in the string values. This
means that we change varchar/text/BpChar to be structures that have a
charset oid field and a collation oid field, the rest of the Datum is the
string data.

Coercability I think one don't need to put in the Datum and it can be
stored in the Nodes. Charset/Collation need to be in the Datum since we
send that into functions as arguments.

Since we are changing what's stored in the Datum and the normal code saves
that on disk then we will end up with charset/collation stored on disk for
each value. If we want to avoid storing charset/collation both in the
column type and in each row, we would need an extra layer that transforms
the Datums before they are stored. As a first implementation it's easier
to just store everything.

For each type we need to have convertion functions to and from strings.
Any suggestion of how to represent these as strings now when it's a string
plus two oid's? This is a though one..

I have more comments/questions later on, but these are enough for one
mail.

--
/Dennis Bj�rklund

#2Thomas Hallgren
thhal@mailblocks.com
In reply to: Dennis Bjorklund (#1)
Re: charset/collation in values

Dennis Bjorklund wrote:

I've looked into storing charset/collation in the string values. This
means that we change varchar/text/BpChar to be structures that have a
charset oid field and a collation oid field, the rest of the Datum is the
string data.

I think the number of charset/collation combinations will be relatively
few so perhaps it would be space efficient to maintain a table where
each combination is given an oid and have string values store that
rather than two separate oid's?

Regards,
Thomas Hallgren

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thomas Hallgren (#2)
Re: charset/collation in values

Thomas Hallgren <thhal@mailblocks.com> writes:

I think the number of charset/collation combinations will be relatively
few so perhaps it would be space efficient to maintain a table where
each combination is given an oid and have string values store that
rather than two separate oid's?

In fact, we should do our best to get the overhead down to 1 or 2 bytes.
Two OIDs (8 bytes) is ridiculous.

I'm not sure if 1 byte is enough or not --- there might be more than 256
charsets/collations to support. 2 ought to be plenty though.

regards, tom lane

#4Dennis Bjorklund
db@zigo.dhs.org
In reply to: Tom Lane (#3)
Re: charset/collation in values

On Mon, 1 Nov 2004, Tom Lane wrote:

I think the number of charset/collation combinations will be relatively
few so perhaps it would be space efficient to maintain a table where
each combination is given an oid and have string values store that
rather than two separate oid's?

In fact, we should do our best to get the overhead down to 1 or 2 bytes.
Two OIDs (8 bytes) is ridiculous.

Just to be clear, we don't want to store it on disk no matter what since
it should be enough to store it once for each column. As a first solution
we could store it just to keep it simple until we have tried it out.

--
/Dennis Bj�rklund

#5Tatsuo Ishii
t-ishii@sra.co.jp
In reply to: Dennis Bjorklund (#4)
Re: charset/collation in values

On Mon, 1 Nov 2004, Tom Lane wrote:

I think the number of charset/collation combinations will be relatively
few so perhaps it would be space efficient to maintain a table where
each combination is given an oid and have string values store that
rather than two separate oid's?

In fact, we should do our best to get the overhead down to 1 or 2 bytes.
Two OIDs (8 bytes) is ridiculous.

Just to be clear, we don't want to store it on disk no matter what since
it should be enough to store it once for each column. As a first solution
we could store it just to keep it simple until we have tried it out.

Right. AFAIK nobody has proposed charsets/collations onto disk.
--
Tatsuo Ishii

#6Thomas Hallgren
thhal@mailblocks.com
In reply to: Tatsuo Ishii (#5)
Re: charset/collation in values

Tatsuo Ishii wrote:

Right. AFAIK nobody has proposed charsets/collations onto disk.
--

My apologies in that case. I triggered on Dennis wording "If we want to
avoid storing charset/collation both in the column type and in each row,
we would need an extra layer that transforms the Datums before they are
stored. As a first implementation it's easier to just store everything."

Regards,
Thomas Hallgren

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tatsuo Ishii (#5)
Re: charset/collation in values

Tatsuo Ishii <t-ishii@sra.co.jp> writes:

Right. AFAIK nobody has proposed charsets/collations onto disk.

Oh?

Personally, I'd much sooner eat those few bytes than try to impose a
regime where in-memory representation is different from on-disk.

regards, tom lane

#8Peter Eisentraut
peter_e@gmx.net
In reply to: Dennis Bjorklund (#1)
Re: charset/collation in values

Am Montag, 1. November 2004 07:41 schrieb Dennis Bjorklund:

For each type we need to have convertion functions to and from strings.
Any suggestion of how to represent these as strings now when it's a string
plus two oid's? This is a though one..

A collation implies a character set, so you only need to store one piece of
information anyway.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#9Dennis Bjorklund
db@zigo.dhs.org
In reply to: Peter Eisentraut (#8)
Re: charset/collation in values

On Tue, 2 Nov 2004, Peter Eisentraut wrote:

A collation implies a character set, so you only need to store one piece of
information anyway.

No, a collation implies a character repertoire like UCS (unicode), it can
apply to several character sets like UTF8 and UTF16.

One can enumerate all combinations if one want to, as suggested
previously.

--
/Dennis Bj�rklund

#10Tatsuo Ishii
t-ishii@sra.co.jp
In reply to: Peter Eisentraut (#8)
Re: charset/collation in values

Am Montag, 1. November 2004 07:41 schrieb Dennis Bjorklund:

For each type we need to have convertion functions to and from strings.
Any suggestion of how to represent these as strings now when it's a string
plus two oid's? This is a though one..

A collation implies a character set, so you only need to store one piece of
information anyway.

In my understanding the relation between charset and collation is
1:N. Thus storing only a collation is sufficient to determine the
charset. However a charset cannot determine a collation.
--
Tatsuo Ishii

#11Peter Eisentraut
peter_e@gmx.net
In reply to: Dennis Bjorklund (#9)
Re: charset/collation in values

Am Dienstag, 2. November 2004 13:15 schrieb Dennis Bjorklund:

On Tue, 2 Nov 2004, Peter Eisentraut wrote:

A collation implies a character set, so you only need to store one piece
of information anyway.

No, a collation implies a character repertoire like UCS (unicode), it can
apply to several character sets like UTF8 and UTF16.

For the theoretical specification of a collation, it might suffice to know the
character repertoire. But I think in practice, the implementation of a
collation will require knowing the specific character encoding.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#12Peter Eisentraut
peter_e@gmx.net
In reply to: Tatsuo Ishii (#10)
Re: charset/collation in values

Am Dienstag, 2. November 2004 13:53 schrieb Tatsuo Ishii:

In my understanding the relation between charset and collation is
1:N. Thus storing only a collation is sufficient to determine the
charset. However a charset cannot determine a collation.

Exactly.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#13Dennis Bjorklund
db@zigo.dhs.org
In reply to: Peter Eisentraut (#11)
Re: charset/collation in values

On Tue, 2 Nov 2004, Peter Eisentraut wrote:

For the theoretical specification of a collation, it might suffice to
know the character repertoire. But I think in practice, the
implementation of a collation will require knowing the specific
character encoding.

The named entity that is called a collation works for a character
repertoire. It would need to handle different charsets for that repertoire
of course. So there would be one collation called say ucs_sv and not
utf8_sv, utf16_sv, utf32_sv.

Anyway, this is not a problem.

--
/Dennis Bj�rklund

#14Peter Eisentraut
peter_e@gmx.net
In reply to: Dennis Bjorklund (#13)
Re: charset/collation in values

Dennis Bjorklund wrote:

The named entity that is called a collation works for a character
repertoire. It would need to handle different charsets for that
repertoire of course. So there would be one collation called say
ucs_sv and not utf8_sv, utf16_sv, utf32_sv.

Again, theoretically, this might work, but I doubt that this is a
practical implementation. Moreover, since Unicode is more or less the
only chararacter repertoire that have more than one encoding in use,
and neither UTF-16 nor UTF-32 can be used inside the PostgreSQL server
(embedded zero bytes etc.), this is really a nonissue.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/

#15Tatsuo Ishii
t-ishii@sra.co.jp
In reply to: Peter Eisentraut (#14)
Re: charset/collation in values

Dennis Bjorklund wrote:

The named entity that is called a collation works for a character
repertoire. It would need to handle different charsets for that
repertoire of course. So there would be one collation called say
ucs_sv and not utf8_sv, utf16_sv, utf32_sv.

Again, theoretically, this might work, but I doubt that this is a
practical implementation. Moreover, since Unicode is more or less the
only chararacter repertoire that have more than one encoding in use,
and neither UTF-16 nor UTF-32 can be used inside the PostgreSQL server
(embedded zero bytes etc.), this is really a nonissue.

I agree with Peter.
--
Tatsuo Ishii