This is an automated email from the ASF dual-hosted git repository.
gfphoenix78 pushed a commit to branch sync-with-upstream
in repository https://gitbox.apache.org/repos/asf/cloudberry-gpbackup.git
The following commit(s) were added to refs/heads/sync-with-upstream by this
push:
new d8f3b943 Fix: Normalize operator class storagetype for different DB
versions (#33)
d8f3b943 is described below
commit d8f3b943ff04f2b0974f414d2644c07a2f76c4ac
Author: Robert Mu <[email protected]>
AuthorDate: Fri Sep 5 14:37:43 2025 +0800
Fix: Normalize operator class storagetype for different DB versions (#33)
This commit addresses a test failure in the `GetOperatorClasses` integration
tests, which was observed on newer database versions like Cloudberry
(based on PG14).
The investigation revealed an inconsistency in how Greenplum 7 (based on
PG12)
and Cloudberry handle the `storagetype` for operator classes. When an
operator
class's `STORAGE` type is the same as its `FOR TYPE` and `opckeytype` is
not 0:
- In GPDB7, the expression `opckeytype::regtype` evaluates to "-".
- In CBDB, the same expression evaluates to the actual type name (e.g.,
"integer").
This change introduces a `CASE` statement to explicitly check if
`opcintype` equals `opckeytype`. This normalizes the behavior across
both database versions, ensuring that `storagetype` is consistently
represented as "-" when the storage type is the same as the input type,
which allows the failing test to pass.
---
backup/queries_operators.go | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/backup/queries_operators.go b/backup/queries_operators.go
index dd4c932e..8b0e76bb 100644
--- a/backup/queries_operators.go
+++ b/backup/queries_operators.go
@@ -171,7 +171,21 @@ func GetOperatorClasses(connectionPool *dbconn.DBConn)
[]OperatorClass {
(SELECT amname FROM pg_catalog.pg_am WHERE oid = opcmethod) AS
indexmethod,
opcintype::pg_catalog.regtype AS type,
opcdefault AS default,
- opckeytype::pg_catalog.regtype AS storagetype
+ /*
+ * GPDB7 (PG12) and CBDB (PG14) have different behaviors when
casting
+ * opckeytype to a regtype when the STORAGE type is the same as
the
+ * FOR TYPE and the opckeytype is not 0.
+ *
+ * In GPDB7, the expression opckeytype::regtype evaluates to "-"
+ * in this case.
+ *
+ * In CBDB, the same expression evaluates to the type name
(e.g., "integer").
+ *
+ * This CASE statement explicitly checks if the types are the
same to
+ * normalize this behavior, ensuring the output is always "-"
when the
+ * storage type is the same as the input type.
+ */
+ CASE WHEN opcintype = opckeytype THEN '-' ELSE
opckeytype::pg_catalog.regtype END AS storagetype
FROM pg_catalog.pg_opclass c
LEFT JOIN pg_catalog.pg_opfamily f ON f.oid = opcfamily
JOIN pg_catalog.pg_namespace cls_ns ON cls_ns.oid = opcnamespace
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]