yugabyte/yugabyte-db
在 GitHub 查看[YSQL] Improve error text when create index using an unsupported key type
Open
#23,244 创建于 2024年7月18日
area/ysqlgood first issuekind/enhancementpriority/medium
仓库指标
- Star
- (8,229 star)
- PR 合并指标
- (平均合并 17天 21小时) (30 天内合并 92 个 PR)
描述
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.