Skip to content

fix(kingbase): list procedures from the plugin instead of the jdbc driver - #2956

Merged
openai0229 merged 2 commits into
mainfrom
fix/kingbase-procedure-list
Sep 23, 2026
Merged

openai0229 merged 2 commits into
mainfrom
fix/kingbase-procedure-list

Conversation

@openai0229

@openai0229 openai0229 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Related issue

No linked issue. The failure was reported directly from the desktop client's error payload
against a KingbaseES datasource (GET /api/rdb/procedure/list); searching the tracker for
kingbase, procedure, and operator does not exist found no existing report for it.

Summary

Opening the procedure list of a KingbaseES datasource failed with:

com.kingbase8.util.KSQLException: ERROR: operator does not exist: boolean || oid
  Position: 173
    at com.kingbase8.jdbc.KbDatabaseMetaData.getProcedures(KbDatabaseMetaData.java:1094)
    at ai.chat2db.spi.DefaultSQLExecutor.procedures(DefaultSQLExecutor.java:620)
    at ai.chat2db.spi.DefaultMetaService.procedures(DefaultMetaService.java:178)

KingBaseMetaData overrides functions() and the single procedure(), but never the
list-level procedures(), so the call fell through DefaultMetaService.procedures to
DefaultSQLExecutor.procedures, which asks the JDBC driver. The driver builds SPECIFIC_NAME
as p.proname || '_' || p.oid AS SPECIFIC_NAME; the reported Position: 173 lands on the
second ||, whose right operand is p.oid.

On a server running in MySQL compatibility mode || is a logical OR, so p.proname || '_'
is typed boolean and the second operator has no overload — exactly the reported
boolean || oid. Some driver builds detect that mode and switch to concat(p.proname,'_',p.oid);
the drivers this plugin ships, kingbase8-8.6.0.jar (default) and kingbase8-8.2.0.jar, have
no such branch, so the driver statement is sent as is. It is assembled inside the driver, so
the plugin layer is the only place to fix it — as the other PostgreSQL-family plugins (xugudb,
sundb, oscar) already do.

The plugin now lists procedures from sys_catalog.sys_proc the way its existing
FUNCTION_LIST_SQL lists functions: joined to sys_namespace, schema bound, extension-owned
objects excluded. Procedures are selected with prokind = 'p' OR (prokind = 'u' AND prorettype = 2278): V8R6 and later mark them 'p', while V8R3 tags every user routine 'u'
and distinguishes a procedure only by its void return type (2278 is void, a function returning
int is 23). Rows map to Procedure with the name trimmed and blank names dropped, keeping the
filtering the previous DefaultMetaService implementation applied.

Affected surfaces

  • Frontend / Web
  • Backend / API / Storage
  • Database plugin / Driver
  • JCEF / Desktop packaging
  • CI / Build / Release
  • Documentation only

Verification

  • Reproduced against a real KingbaseES V009R003C018 server in MySQL compatibility mode with
    the plugin's default driver kingbase8-8.6.0.jar: DatabaseMetaData#getProcedures throws
    com.kingbase8.util.KSQLException: ERROR: operator does not exist: boolean || oid, first frame
    com.kingbase8.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2679) —
    same class and same frame as the report.
  • The patched KingBaseMetaData#procedures then ran through the same connection and driver on
    that server and returned the schema's procedures instead of failing.
  • Checked again on KingbaseES V008R003C002B0290 (V8R3, driver kingbase8-8.2.0.jar, the only
    shipped driver that accepts that server): the plugin path returns the procedures and excludes a
    function of the same schema, while the driver path additionally lists that function as a
    procedure.
  • Module test set: mvn -B -f chat2db-community-server/pom.xml -pl :chat2db-community-kingbase -am -Dmaven.test.skip=false -DskipTests=false '-Dsurefire.includes=**/*Test.java' -Dmaven.test.failure.ignore=false test
    → BUILD SUCCESS, 0 failures (spi 191, postgresql 70, kingbase 28 including the new test).
  • mvn -B -f chat2db-community-server/pom.xml -pl :chat2db-community-kingbase -am -Dmaven.test.skip=true package → BUILD SUCCESS.
  • KingBaseProcedureListTest drives procedures() through a proxy connection and asserts the
    prepared statement is PROCEDURE_LIST_SQL, that the SQL carries no ||, that the schema is
    bound, and that names are trimmed and blank rows skipped. The proxy throws
    UnsupportedOperationException for anything but prepareStatement, so the driver path cannot
    return unnoticed.
  • Not covered: the reporter's own V8R6 server, and the Oracle/PostgreSQL compatibility modes of
    KingbaseES. The statement is compatibility-mode independent, and the two tested versions cover
    both prokind conventions.
  • UI evidence: N/A

Risk and compatibility

  • Public API or stored data: none. Same endpoint, same response model.
  • Database or driver compatibility: Kingbase plugin only; the JDBC driver is no longer used for
    this call. The sys_catalog names and the prokind/prorettype markers were checked on V8R3
    and V9R3.
  • Network, privacy, or security: none.
  • Community / Local / Pro boundary: community plugin only.
  • Backward compatibility: when schemaName is blank the new query returns an empty list, where
    the driver path returned search-path-visible procedures. Callers (schema tree, completion)
    pass a schema for Kingbase, and the plugin's functions() already behaves this way.

Reviewer map

  • Start here: chat2db-community-kingbase/src/main/java/ai/chat2db/plugin/kingbase/KingBaseMetaData.java (procedures) and .../constant/SqlConstant.java (PROCEDURE_LIST_SQL).
  • Failure condition: if the procedures() override is removed, the driver statement comes back and KingbaseES fails again with operator does not exist: boolean || oid.
  • Rollback or disable path: revert the two commits; the endpoint returns to the driver-based behaviour.

Contributor declaration

  • I linked the Issue that defines this change.
  • I tested the affected behavior and reported the actual results above.
  • I did not include credentials, private data, or generated build output.
  • I disclosed substantial AI assistance below, or this PR contains no substantial AI-generated code.

AI assistance: the change and its test were drafted with an AI coding agent. The failing statement
was traced through the shipped driver bytecode, reproduced and re-checked on real KingbaseES
instances of two versions, and the final diff was reviewed before submission.

…iver

KingBaseMetaData never overrode the list-level procedures(), so the call reached
KbDatabaseMetaData#getProcedures, whose SPECIFIC_NAME expression
"p.proname || '_' || p.oid" KingbaseES rejects with "operator does not exist:
boolean || oid". The other PostgreSQL-family plugins answer this list
themselves.

Query sys_catalog.sys_proc the way the existing function list does, filtered to
prokind = 'p', and map the rows to Procedure. KingBaseProcedureListTest drives
the plugin through a proxy connection and fails if the driver path returns.
V8R3 tags every user routine 'u' and distinguishes a procedure only by its
void return type, so the plain prokind = 'p' filter returned nothing there
(procedures come back with prorettype 2278, a function returning int with 23).
V8R6 and later keep using the 'p' marker, checked against KingbaseES V008R003
C002B0290 and V009R003C018.
@openai0229
openai0229 merged commit 4b20d89 into main Sep 23, 2026
18 of 21 checks passed
@openai0229
openai0229 deleted the fix/kingbase-procedure-list branch September 23, 2026 09:40
@openai0229 openai0229 moved this from In Review to Done in Chat2DB Community Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant