postgresql/lightdb GBK支持(非正式参考)
首先来看下GB2312,GBK以及GB18030的区别。分几个方面:
1、收录汉字
GB2312:基本集共收入汉字6763个和非汉字图形字符682个。
GBK:共收录了21003个汉字。
GB18030 :共收录汉字70244个。
2、兼容性
GB2312:基本满足了汉字的计算机处理需要,对于人名、古汉语等方面出现的罕用字,GB 2312不能处理。
GBK:GBK 向下与 GB 2312 编码兼容,向上支持 ISO 10646.1国际标准。
GB18030 :对GB 2312-1980完全向后兼容,与GBK基本向后兼容,并支持Unicode(GB 13000)的所有码位。
3、发布时间
GB2312:由中国国家标准总局1980年发布,1981年5月1日开始实施。
GBK:1995年12月1日制订。
GB18030 :初版于2000年3月17日发布,现行版本于2005年11月8日发布,2006年5月1日实施。
4、编码
GB2312:通常采用EUC储存方法,以便兼容于ASCII。每个汉字及符号以两个字节来表示。
GBK:GBK是采用单双字节变长编码,英文使用单字节编码,完全兼容ASCII字符编码,中文部分采用双字节编码。
GB18030 :GB18030包含三种长度的编码:单字节的ASCII、双字节的GBK(略带扩展)、以及用于填补所有Unicode码位的四字节UTF区块。
https://doxygen.postgresql.org/utf8__and__gbk_8c.html
https://blog.csdn.net/pg_hgdb/article/details/79018246
https://darkathena.blog.csdn.net/article/details/124679023
https://blog.csdn.net/weixin_47308871/article/details/122152684
https://www.postgresql.org/docs/current/multibyte.html
https://www.cnblogs.com/kuang17/p/11378845.html postgresql中客户端与服务端编码以及乱码的原因分析(一篇足够)
mysql innodb表 utf8 gbk占用空间相同,但是在postgresql中,EUC_CN占用的空间比UTF-8还要大。
postgresql对GBK/GB18030的支持情况
开源pg(包括其它基于pg的二开,opengauss、人大金仓)并不支持服务端使用GBK/18030存储,但是客户端编码是支持GBK/18030的,这意味着存储只能用UTF-8格式兼容。
虽然ICU支持GBK/18030,但是pg也不支持它http://peter.eisentraut.org/blog/2022/09/26/icu-features-in-postgresql-15。
[zjh@hs-10-20-30-193 14203]$ export LANG=zh_CN.GB2312 [zjh@hs-10-20-30-193 14203]$ lt_initdb -D ~/stage/lightdb-x/gbk_data -E EUC_CN
[zjh@hs-10-20-30-193 14203]$ ltsql -p25433 ltsql (13.8-22.4) Type "help" for help. zjh@postgres=# create table foo_utf8(v varchar(32)); zjh@postgres=# insert into foo_utf8 select '中国人民' from generate_series(1,10000000); zjh@postgres=# select * from pg_relation_size('foo_utf8'); pg_relation_size ------------------ 574308352 (1 row)
[zjh@hs-10-20-30-193 14203]$ export LANG=zh_CN.UTF-8 [zjh@hs-10-20-30-193 14203]$ ltsql -p25432 ltsql (13.8-22.4) Type "help" for help. zjh@postgres=# show %encoding%; name | setting | description -----------------+---------+---------------------------------------------------- client_encoding | UTF8 | Sets the client's character set encoding. server_encoding | UTF8 | Sets the server (database) character set encoding. (2 rows) zjh@postgres=# select * from pg_relation_size('foo_utf8'); pg_relation_size ------------------ 442818560 (1 row)
就实现而言,存储可以相同编码(都用UTF-8也可以)、也可以不同,但是查询的时候反过来,即存储采用原生字符集的:不用运行时转换,统一UTF-8编码的,运行时需要用icov/icu转换为目标库、表、字段的字符集,然后进行比较。
按照人行电子化的测试,GB18030 2022是必须支持的,否则不算信创。
https://www.postgresql.org/docs/current/multibyte.html
https://www.cybertec-postgresql.com/en/case-insensitive-pattern-matching-in-postgresql/
http://blog.unicode.org/2023/06/icu-732-cldr-431-released-gb18030.html
Disruptive Changes in GB 18030-2022
https://icu-project.org/docs/papers/unicode-gb18030-faq.html
达梦数据库支持GB18030-2022中文编码字符集证明方法
如何配置达梦数据库使其支持GB18030-2022中文编码字符集
https://github.com/oceanbase/oceanbase/issues/1348