pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Han Parker <parker.han@outlook.com>
Cc: Tatsuo Ishii <ishii@sraoss.co.jp>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: 回复: May "PostgreSQL server side GB18030 character set support" reconsidered?
Date: Mon, 05 Oct 2020 10:30:34 -0400
Message-ID: <1720141.1601908234@sss.pgh.pa.us> (raw)
In-Reply-To: <ME2PR01MB25323BFB2D3BA4AF8EC1040C8A0C0@ME2PR01MB2532.ausprd01.prod.outlook.com>
References: <201503061055293002598@pconline.com.cn>
	<CAG6W84JPmOJP5F2eKtL-LvvVA63fuyGVV521hwQns7nk1_BLHw@mail.gmail.com>
	<ME2PR01MB2532E72B514DC46ED0E10F798A0C0@ME2PR01MB2532.ausprd01.prod.outlook.com>
	<20201005.174109.1358847281635212616.t-ishii@sraoss.co.jp>
	<ME2PR01MB25323BFB2D3BA4AF8EC1040C8A0C0@ME2PR01MB2532.ausprd01.prod.outlook.com>

Han Parker <parker.han@outlook.com> writes:
> ·¢¼þÈË: Tatsuo Ishii <ishii@sraoss.co.jp>
>> Moving GB18030 to server side encoding requires a technical challenge:
>> currently PostgreSQL's SQL parser and perhaps in other parts of
>> backend assume that each byte in a string data is not confused with
>> ASCII byte. Since GB18030's second and fourth byte are in range of
>> 0x40 to 0x7e, backend will be confused. How do you resolve the
>> technical challenge exactly?

> I do not have an exact solution proposal yet.
> Maybe an investigation on MySQL's mechanism would be of help.

TBH, even if you came up with a complete patch, we'd probably
reject it as unmaintainable and a security hazard.  The problem
is that code may scan a string looking for certain ASCII characters
such as backslash (\), which up to now it's always been able to do
byte-by-byte without fear that non-ASCII characters could confuse it.
To support GB18030 (or other encodings with the same issue, such as
SJIS), every such loop would have to be modified to advance character
by character, thus roughly "p += pg_mblen(p)" instead of "p++".
Anyplace that neglected to do that would have a bug --- one that
could only be exposed by careful testing using GB18030 encoding.
What's more, such bugs could easily be security problems.
Mis-detecting a backslash, for example, could lead to wrong decisions
about where string literals end, allowing SQL-injection exploits.

> Most frequently used 20902 Chinese characters  and 984 symbols in GBK is encoded with 2 bytes, which is a subset of GB18030.
> Newly added not so frequently but indeed used characters and symbols in GB18030 use 4 bytes.

Any efficiency argument has to consider processing costs not just
storage costs.  As I showed above, catering for GB18030 would make
certain loops substantially slower, so that you might pay in CPU
cycles what you saved on disk space.  It doesn't help any that the
extra processing costs would be paid by every Postgres user on the
planet, whether they used GB18030 or not.

In short, I think this is very unlikely to happen.

			regards, tom lane





view thread (2+ messages)

Message-ID: <1720141.1601908234@sss.pgh.pa.us>
Permalink:  ../1720141.1601908234@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1720141.1601908234@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, parker.han@outlook.com, ishii@sraoss.co.jp
  Subject: Re: 回复: May "PostgreSQL server side GB18030 character set support" reconsidered?
  In-Reply-To: <1720141.1601908234@sss.pgh.pa.us>
  References: <201503061055293002598@pconline.com.cn> <CAG6W84JPmOJP5F2eKtL-LvvVA63fuyGVV521hwQns7nk1_BLHw@mail.gmail.com> <ME2PR01MB2532E72B514DC46ED0E10F798A0C0@ME2PR01MB2532.ausprd01.prod.outlook.com> <20201005.174109.1358847281635212616.t-ishii@sraoss.co.jp> <ME2PR01MB25323BFB2D3BA4AF8EC1040C8A0C0@ME2PR01MB2532.ausprd01.prod.outlook.com> <1720141.1601908234@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox