yugabyte / yugabyte-db

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.
https://www.yugabyte.com
Other
9.01k stars 1.08k forks source link

[YSQL] Cannot load a database after using collation with partitioned table #24149

Open stefanoric opened 1 month ago

stefanoric commented 1 month ago

Jira Link: DB-13038

Description

The following error is thrown after changing to a database where a partitioned table exist and a collation is defined for the partition column:

FATAL: encoding "SQL_ASCII" not supported by ICU

Steps to reproduce (assuming 2 tablespaces already exist):

CREATE DATABASE a;
CREATE DATABASE
test=# \c a;
You are now connected to database "a" as user "yugabyte".
a=# CREATE COLLATION numeric (provider = icu, locale = 'en-u-kn-true');
CREATE COLLATION
a=# CREATE TABLE t(a text NOT NULL collate numeric) PARTITION BY RANGE(a);
CREATE TABLE
a=# CREATE TABLE t_n PARTITION of t (a, PRIMARY KEY (a HASH)) FOR VALUES FROM ('A') TO ('Lzzzzz') TABLESPACE n_tablespace;
CREATE TABLE
a=# CREATE TABLE t_e PARTITION of t (a, PRIMARY KEY (a HASH)) FOR VALUES FROM ('M') TO ('Zzzzzz') TABLESPACE e_tablespace;
CREATE TABLE
a=# \c a
FATAL:  encoding "SQL_ASCII" not supported by ICU

Issue Type

kind/bug

Warning: Please confirm that this issue does not contain any sensitive information

myang2021 commented 1 month ago

I took a look, the relevant code

    /*
     * It's now possible to do real access to the system catalogs.
     *
     * Load relcache entries for the system catalogs.  This must create at
     * least the minimum set of "nailed-in" cache entries.
     */
    RelationCacheInitializePhase3();

    /* set up ACL framework (so CheckMyDatabase can check permissions) */
    initialize_acl();

    /*
     * Re-read the pg_database row for our database, check permissions and set
     * up database-specific GUC settings.  We can't do this until all the
     * database-access infrastructure is up.  (Also, it wants to know if the
     * user is a superuser, so the above stuff has to happen first.)
     */
    if (!bootstrap)
        CheckMyDatabase(dbname, am_superuser,
                        (flags & INIT_PG_OVERRIDE_ALLOW_CONNS) != 0);

CheckMyDatabase is called after RelationCacheInitializePhase3, CheckMyDatabase sets up database encoding to UTF8 by calling SetDatabaseEncoding(dbform->encoding) Before that, the database encoding is initialized to SQL_ASCII. There are some YB specific code in doing catalog cache preloading to populate the cache in RelationCacheInitializePhase3, as a result SQL_ASCII is used instead of UTF8. Perhaps we should update YB specific code to SetDatabaseEncoding(dbform->encoding) to get things right.

myang2021 commented 1 month ago

The fix typo change that was backported to 2024.1 and 2024.2 need not be backported to 2.20 because the original fix when backported to 2.20 had the typo fixed.