yugabyte/yugabyte-db

[YSQL] Improve error text when create index using an unsupported key type

Open

#23 244 ouverte le 18 juil. 2024

Voir sur GitHub
 (2 commentaires) (0 réactions) (1 assigné)C (1 003 forks)batch import
area/ysqlgood first issuekind/enhancementpriority/medium

Métriques du dépôt

Stars
 (8 229 stars)
Métriques de merge PR
 (Merge moyen 17j 21h) (92 PRs mergées en 30 j)

Description

Jira Link: DB-12176

Description

yugabyte=# CREATE TABLE users (advertiser_text text[], advertiser_char char[], advertiser_varchar varchar[], advertiser_date date[], advertiser_int int[], advertiser_numeric numeric[], advertiser_json json[]);
CREATE TABLE

yugabyte=# CREATE UNIQUE INDEX index_users_on_advertiser_ids ON public.users (advertiser_text);
ERROR:  INDEX on column of type 'TEXTARRAY' not yet supported

yugabyte=# CREATE UNIQUE INDEX index_users_on_advertiser_ids ON public.users (advertiser_char);
ERROR:  INDEX on column of type 'user_defined_type' not yet supported

yugabyte=# CREATE UNIQUE INDEX index_users_on_advertiser_ids ON public.users (advertiser_varchar);
ERROR:  INDEX on column of type 'user_defined_type' not yet supported

yugabyte=# CREATE UNIQUE INDEX index_users_on_advertiser_ids ON public.users (advertiser_date);
ERROR:  INDEX on column of type 'user_defined_type' not yet supported

yugabyte=# CREATE UNIQUE INDEX index_users_on_advertiser_ids ON public.users (advertiser_int);
ERROR:  INDEX on column of type 'INT4ARRAY' not yet supported

yugabyte=# CREATE UNIQUE INDEX index_users_on_advertiser_ids ON public.users (advertiser_numeric);
ERROR:  INDEX on column of type 'user_defined_type' not yet supported

yugabyte=# CREATE UNIQUE INDEX index_users_on_advertiser_ids ON public.users (advertiser_json);
ERROR:  INDEX on column of type 'user_defined_type' not yet supported

Some of these error has user_defined_type even though the type is a builtin array type. We should improve the error text to be more specific on these types. One example is char[] should be reported as BPCHARARRAYOID.

The relevant code is

if (is_key)
        {
            if (!YbDataTypeIsValidForKey(att->atttypid))
                ereport(ERROR,
                        (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                         errmsg("INDEX on column of type '%s' not yet supported",
                                YBPgTypeOidToStr(att->atttypid))));
        }

The function YBPgTypeOidToStr has a switch statement

const char*
YBPgTypeOidToStr(Oid type_id) {
    switch (type_id) {
        case BOOLOID: return "BOOL";
        case BYTEAOID: return "BYTEA";
        case CHAROID: return "CHAR";
        case NAMEOID: return "NAME";
......
        case TEXTARRAYOID: return "TEXTARRAY";
......
        default: return "user_defined_type";
}

Some cases (e.g., BPCHARARRAYOID) are missing so the default type is returned. If we want to get a better error we just need to add those type ids there.

Issue Type

kind/enhancement

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

  • I confirm this issue does not contain any sensitive information.

Guide contributeur