psql tab completion broken for storage servers, tags, profiles and resource groups (pre-PG15 query format)

Đang mở Phù hợp với người mới
#2,316 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@allenvox đang làm issue này rồi.

Từ ngày 14/11/2026.

  • #2321 của @allenvox — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c, postgresql
Lĩnh vực
cli, databases

Hướng nghiên cứu

Bốn macro Query_for_list_of_tags, Query_for_list_of_resgroups, Query_for_list_of_storage_servers và Query_for_list_of_profiles nằm trong src/bin/psql/tab-complete.c. Hãy so sánh chúng với Query_for_list_of_servers, macro này đã dùng dạng PG16 với một LIKE '%s' duy nhất. Chuyển cả bốn sang dạng đó, build lại psql và kiểm tra rằng TAB sau ALTER TAG t_ hoặc ALTER STORAGE SERVER s_ hoàn thành tên mà không có ERROR nào từ coordinator. Các quy tắc liên quan đến COMMENT và DROP STORAGE SERVER là riêng biệt và có thể xử lý ở đây hoặc trong #2312.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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> and CREATE STORAGE USER MAPPING FOR u STORAGE SERVER <TAB> complete foreign servers (for example gp_exttable_server).
  • COMMENT ON STORAGE SERVER <TAB> completes IS instead of a server name.
  • ALTER STORAGE SERVER s <TAB> offers RENAME 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.

Ngôn ngữ chính
C
Star
1.4k
Fork
273
Merge trung bình
4 ngày 6 giờ
Pull request đã merge (30 ngày)
105

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/cloudberry

Tất cả issue của apache/cloudberry

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.