psql tab completion broken for storage servers, tags, profiles and resource groups (pre-PG15 query format)
维护者通常 2 天内回复
评估
调研方向
Query_for_list_of_tags、Query_for_list_of_resgroups、Query_for_list_of_storage_servers 和 Query_for_list_of_profiles 这四个宏位于 src/bin/psql/tab-complete.c。请将它们与已经采用 PG16 形式(单个 LIKE '%s')的 Query_for_list_of_servers 进行比较。把这四个宏改成该形式,重新构建 psql,并验证在 ALTER TAG t_ 或 ALTER STORAGE SERVER s_ 之后按 TAB 能补全名称,且没有 coordinator 报错。COMMENT 和 DROP STORAGE SERVER 的相关规则是独立的,可以在这里处理,也可以在 #2312 中处理。
由索引模型根据 Issue 内容生成。
描述
Apache Cloudberry version
main
What happened
psql tab completion of object names does not work for four Cloudberry-specific object types: storage servers, tags, profiles and resource groups. Pressing TAB after ALTER STORAGE SERVER , ALTER TAG , DROP TAG , ALTER PROFILE , ALTER RESOURCE GROUP , etc. offers nothing, even when matching objects exist. Each attempt also logs a server-side ERROR on the coordinator.
Root cause. These four query macros in src/bin/psql/tab-complete.c still use the pre-PG15 template form:
Query_for_list_of_tags ... WHERE substring(pg_catalog.quote_ident(tagname),1,%d)='%s'
Query_for_list_of_resgroups ... WHERE substring(pg_catalog.quote_ident(rsgname),1,%d)='%s'
Query_for_list_of_storage_servers ... WHERE substring(pg_catalog.quote_ident(srvname),1,%d)='%s'
Query_for_list_of_profiles ... WHERE substring(pg_catalog.quote_ident(profilename),1,%d)='%s'
Upstream commit 02b8048ba5d ("psql: improve tab-complete's handling of variant SQL names", PG15) changed the template contract. _complete_from_query() now does
appendPQExpBuffer(&query_buffer, simple_query, e_object_like, e_ref_object, e_ref_schema);
and expects a single LIKE '%s'. Upstream's own macros were converted when the PG16 code was merged, but these Cloudberry-specific ones were not. As a result, %d receives a char * (undefined behavior) and %s receives the NULL e_ref_object. The generated query looks like this:
ERROR: negative substring length not allowed
STATEMENT: SELECT pg_catalog.quote_ident(srvname) FROM pg_catalog.gp_storage_server
WHERE substring(pg_catalog.quote_ident(srvname),1,-1478678816)='(null)'
When the garbage length happens to be positive, the query runs but matches nothing.
What you think should happen instead
Object names should complete. Convert the four macros to the PG16 form, as Query_for_list_of_servers already does:
#define Query_for_list_of_storage_servers \
" SELECT srvname "\
" FROM pg_catalog.gp_storage_server "\
" WHERE srvname LIKE '%s'"
The other three need the same change. The storage-server conversion has been verified: with psql rebuilt and driven through a pty, ALTER STORAGE SERVER <TAB> lists the servers, and the coordinator ERROR disappears.
How to reproduce
CREATE TAG t_demo;
CREATE PROFILE p_demo;
CREATE STORAGE SERVER s_demo OPTIONS (endpoint 'x');
In interactive psql, press TAB after each of the following. None of them completes:
ALTER TAG t_ALTER PROFILE p_ALTER STORAGE SERVER s_ALTER RESOURCE GROUP admin_
The coordinator log gets one bad query per completion attempt, against gp_storage_server, pg_tag, pg_profile and pg_resgroup, all of the substring(...,1,<garbage>)='(null)' form.
Related completion bugs for storage servers (same area)
The single-word {"SERVER", Query_for_list_of_servers} entry in words_after_create, and the generic COMMENT ON X Y → IS rule, win over the multi-word "STORAGE SERVER". This gives:
DROP STORAGE SERVER <TAB>andCREATE STORAGE USER MAPPING FOR u STORAGE SERVER <TAB>complete foreign servers (for examplegp_exttable_server).COMMENT ON STORAGE SERVER <TAB>completesISinstead of a server name.ALTER STORAGE SERVER s <TAB>offersRENAME TO, but the grammar has no such form.
The following additions were verified to fix the first three cases (the user-mapping case still needs its own rule):
else if (Matches("COMMENT", "ON", "STORAGE", "SERVER"))
COMPLETE_WITH_QUERY(Query_for_list_of_storage_servers);
...
else if (Matches("DROP", "STORAGE", "SERVER") ||
Matches("DROP", "STORAGE", "SERVER", "IF", "EXISTS"))
COMPLETE_WITH_QUERY(Query_for_list_of_storage_servers);
Operating System
Linux (platform independent)
Anything else
Found while reviewing #2312. That PR touches the ALTER STORAGE SERVER <name> completion line but not the issues above. The storage-server part can be fixed there or here.
- 主要语言
- C
- 星标
- 1.4k
- 派生
- 273
- 平均合并
- 4 天 6 小时
- 30 天内合并 PR
- 105
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/cloudberry 的其他 Issue
-
isolation2 lockmodes fails on cassert builds: extra AccessShareLock on partition root可能已有人在做 @tuhaihe 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
apache/cloudberry#2356 ·
维护者通常 2 天内回复
-
[Bug] Expand fails to recognize user-defined tablespaces可能已有人在做 @nix-oss 于 92 天前认领。 未关闭type: Bug
难度 2/5 1-3 小时 新手友好度 76/100
apache/cloudberry#1885 · 2 个 reaction ·
维护者通常 2 天内回复
-
gpexpand first stage fails: 'SyncPackages' object has no attribute 'ret' (extension sync never runs; regression)可能已有人在做 @talmacschen-arch 于 153 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
apache/cloudberry#1825 ·
维护者通常 2 天内回复
-
type: Bug
难度 4/5 3-5 天 新手友好度 53/100
apache/cloudberry#2350 · 1 个 reaction ·
维护者通常 2 天内回复
-
难度 5/5 一周以上 新手友好度 15/100
apache/cloudberry#2348 · 1 条评论 ·
维护者通常 2 天内回复
查看 apache/cloudberry 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 86/100
-
难度 1/5 1-3 小时 新手友好度 78/100
crosspoint-reader/crosspoint-reader#4535 ·
维护者通常 1 天内回复
-
[core] Clients never advertise RNS_UD_CS_SUPPORT_ERRINFO_PDU, so a conforming server can't send them Set Error Info可能已有人在做 @akallabeth 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
FreeRDP/FreeRDP#14230 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
Genymobile/scrcpy#7178 ·
维护者通常 3 天内回复