This is an automated email from the ASF dual-hosted git repository.

chenjinbao1989 pushed a commit to branch cbdb-postgres-merge
in repository https://gitbox.apache.org/repos/asf/cloudberry.git


The following commit(s) were added to refs/heads/cbdb-postgres-merge by this 
push:
     new f914cbc0967 Fix errors on matview
f914cbc0967 is described below

commit f914cbc0967559d7c33a91e0c8eb5dbbe570005f
Author: Jinbao Chen <[email protected]>
AuthorDate: Sun Nov 23 21:24:38 2025 +0800

    Fix errors on matview
---
 src/backend/catalog/index.c                    |  5 ----
 src/backend/catalog/oid_dispatch.c             | 18 ++++++++++++++
 src/backend/catalog/pg_publication.c           |  7 ++++--
 src/backend/nodes/outfast.c                    |  6 +++++
 src/backend/nodes/outfuncs.c                   | 27 ++++++++++++++++++++
 src/backend/nodes/readfast.c                   |  6 +++++
 src/backend/nodes/readfuncs.c                  | 29 ++++++++++++++++++++++
 src/include/catalog/oid_dispatch.h             |  2 ++
 src/test/regress/expected/lock.out             | 28 +++++++++++++++++++--
 src/test/regress/expected/matview.out          | 34 ++++++++------------------
 src/test/regress/expected/replica_identity.out |  3 ---
 src/test/regress/serial_schedule               | 10 ++++----
 src/test/regress/sql/matview.sql               |  7 ------
 src/test/regress/sql/replica_identity.sql      |  3 ---
 14 files changed, 134 insertions(+), 51 deletions(-)

diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 62e52e12425..0f4a13c2cc7 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -3057,11 +3057,6 @@ index_update_stats(Relation rel,
 
        if (reltuples >= 0 && Gp_role != GP_ROLE_DISPATCH)
        {
-               BlockNumber relpages;
-               BlockNumber relallvisible;
-
-               relpages = RelationGetNumberOfBlocks(rel);
-
                /*
                 * GPDB: We don't maintain relallvisible for AO/CO tables.
                 */
diff --git a/src/backend/catalog/oid_dispatch.c 
b/src/backend/catalog/oid_dispatch.c
index 6e958551d31..888c66b6a73 100644
--- a/src/backend/catalog/oid_dispatch.c
+++ b/src/backend/catalog/oid_dispatch.c
@@ -110,6 +110,7 @@
 #include "catalog/pg_profile.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_publication.h"
+#include "catalog/pg_publication_namespace.h"
 #include "catalog/pg_publication_rel.h"
 #include "catalog/pg_resqueue.h"
 #include "catalog/pg_resqueuecapability.h"
@@ -1362,6 +1363,23 @@ GetNewOidForPublicationRel(Relation relation, Oid 
indexId, AttrNumber oidcolumn,
        return GetNewOrPreassignedOid(relation, indexId, oidcolumn, &key);
 }
 
+Oid
+GetNewOidForPublicationNameSpace(Relation relation, Oid indexId, AttrNumber 
oidcolumn,
+                                                                Oid 
prschemaid, Oid prpubid)
+{
+       OidAssignment key;
+
+       Assert(RelationGetRelid(relation) == PublicationNamespaceRelationId);
+       Assert(indexId == PublicationNamespaceObjectIndexId);
+       Assert(oidcolumn == Anum_pg_publication_namespace_oid);
+
+       memset(&key, 0, sizeof(OidAssignment));
+       key.type = T_OidAssignment;
+       key.keyOid1 = prschemaid;
+       key.keyOid2 = prpubid;
+       return GetNewOrPreassignedOid(relation, indexId, oidcolumn, &key);
+}
+
 /*
  * We also use the oid assignment list to remember the index names chosen for
  * partitioned indexes. This is slightly different from the normal use to
diff --git a/src/backend/catalog/pg_publication.c 
b/src/backend/catalog/pg_publication.c
index 47f7e45bd83..e429d857475 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -650,8 +650,11 @@ publication_add_schema(Oid pubid, Oid schemaid, bool 
if_not_exists)
        memset(values, 0, sizeof(values));
        memset(nulls, false, sizeof(nulls));
 
-       psschid = GetNewOidWithIndex(rel, PublicationNamespaceObjectIndexId,
-                                                                
Anum_pg_publication_namespace_oid);
+//     psschid = GetNewOidWithIndex(rel, PublicationNamespaceObjectIndexId,
+//                                                              
Anum_pg_publication_namespace_oid);
+       psschid = GetNewOidForPublicationNameSpace(rel, 
PublicationNamespaceObjectIndexId, 
+                                                                               
           Anum_pg_publication_namespace_oid,
+                                                                               
           schemaid, pubid);
        values[Anum_pg_publication_namespace_oid - 1] = 
ObjectIdGetDatum(psschid);
        values[Anum_pg_publication_namespace_pnpubid - 1] =
                ObjectIdGetDatum(pubid);
diff --git a/src/backend/nodes/outfast.c b/src/backend/nodes/outfast.c
index 54bab2b6f8c..c6e12f02d04 100644
--- a/src/backend/nodes/outfast.c
+++ b/src/backend/nodes/outfast.c
@@ -1961,6 +1961,12 @@ _outNode(StringInfo str, void *obj)
                        case T_MergeAction:
                                _outMergeAction(str, obj);
                                break;
+                       case T_PublicationObjSpec:
+                               _outPublicationObjSpec(str, obj);
+                               break;
+                       case T_PublicationTable:
+                               _outPublicationTable(str, obj);
+                               break;
                        default:
                                elog(ERROR, "could not serialize unrecognized 
node type: %d",
                                                 (int) nodeTag(obj));
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
index 0afcfdcf28c..09f0397a974 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -4316,6 +4316,27 @@ _outMergeAction(StringInfo str, const MergeAction *node)
        WRITE_NODE_FIELD(updateColnos);
 }
 
+static void
+_outPublicationObjSpec(StringInfo str, const PublicationObjSpec *node)
+{
+       WRITE_NODE_TYPE("PUBLICATIONOBJSPEC");
+
+       WRITE_ENUM_FIELD(pubobjtype, PublicationObjSpecType);
+       WRITE_STRING_FIELD(name);
+       WRITE_NODE_FIELD(pubtable);
+       WRITE_LOCATION_FIELD(location);
+}
+
+static void
+_outPublicationTable(StringInfo str, const PublicationTable *node)
+{
+       WRITE_NODE_TYPE("PUBLICATIONTABLE");
+
+       WRITE_NODE_FIELD(relation);
+       WRITE_NODE_FIELD(whereClause);
+       WRITE_NODE_FIELD(columns);
+}
+
 #include "outfuncs_common.c"
 #ifndef COMPILING_BINARY_FUNCS
 /*
@@ -5518,6 +5539,12 @@ outNode(StringInfo str, const void *obj)
                        case T_MergeAction:
                                _outMergeAction(str, obj);
                                break;
+                       case T_PublicationObjSpec:
+                               _outPublicationObjSpec(str, obj);
+                               break;
+                       case T_PublicationTable:
+                               _outPublicationTable(str, obj);
+                               break;
                        default:
 
                                /*
diff --git a/src/backend/nodes/readfast.c b/src/backend/nodes/readfast.c
index ccd091ecbf0..d47894570d9 100644
--- a/src/backend/nodes/readfast.c
+++ b/src/backend/nodes/readfast.c
@@ -2967,6 +2967,12 @@ readNodeBinary(void)
                        case T_MergeAction:
                                return_value = _readMergeAction();
                                break;
+                       case T_PublicationObjSpec:
+                               return_value = _readPublicationObjSpec();
+                               break;
+                       case T_PublicationTable:
+                               return_value = _readPublicationTable();
+                               break;
                        default:
                                return_value = NULL; /* keep the compiler 
silent */
                                elog(ERROR, "could not deserialize unrecognized 
node type: %d",
diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c
index 75e952d53b4..080c599474a 100644
--- a/src/backend/nodes/readfuncs.c
+++ b/src/backend/nodes/readfuncs.c
@@ -2953,6 +2953,31 @@ _readMergeAction(void)
        READ_DONE();
 }
 
+static PublicationObjSpec *
+_readPublicationObjSpec(void)
+{
+       READ_LOCALS(PublicationObjSpec);
+
+       READ_ENUM_FIELD(pubobjtype, PublicationObjSpecType);
+       READ_STRING_FIELD(name);
+       READ_NODE_FIELD(pubtable);
+       READ_LOCATION_FIELD(location);
+
+       READ_DONE();
+}
+
+static PublicationTable *
+_readPublicationTable(void)
+{
+       READ_LOCALS(PublicationTable);
+
+       READ_NODE_FIELD(relation);
+       READ_NODE_FIELD(whereClause);
+       READ_NODE_FIELD(columns);
+
+       READ_DONE();
+}
+
 #include "readfuncs_common.c"
 #ifndef COMPILING_BINARY_FUNCS
 /*
@@ -3476,6 +3501,10 @@ parseNodeString(void)
                return_value = _readGpPolicy();
        else if (MATCHX("MERGEACTION"))
                return_value = _readMergeAction();
+       else if (MATCHX("PUBLICATIONOBJSPEC"))
+               return_value = _readPublicationObjSpec();
+       else if (MATCHX("PUBLICATIONTABLE"))
+               return_value = _readPublicationTable();
        else
        {
         ereport(ERROR,
diff --git a/src/include/catalog/oid_dispatch.h 
b/src/include/catalog/oid_dispatch.h
index 4a7f713783e..6ccd20ac4bd 100644
--- a/src/include/catalog/oid_dispatch.h
+++ b/src/include/catalog/oid_dispatch.h
@@ -121,6 +121,8 @@ extern Oid GetNewOidForPublication(Relation relation, Oid 
indexId, AttrNumber oi
                                                                   char 
*pubname);
 extern Oid GetNewOidForPublicationRel(Relation relation, Oid indexId, 
AttrNumber oidcolumn,
                                                                          Oid 
prrelid, Oid prpubid);
+extern Oid GetNewOidForPublicationNameSpace(Relation relation, Oid indexId, 
AttrNumber oidcolumn,
+                                                                               
        Oid prschemaid, Oid prpubid);
 
 extern char *GetPreassignedIndexNameForChildIndex(Oid parentIdxOid, Oid 
childRelId);
 extern void RememberPreassignedIndexNameForChildIndex(Oid parentIdxOid, Oid 
childRelId,
diff --git a/src/test/regress/expected/lock.out 
b/src/test/regress/expected/lock.out
index 2da953c019f..f569c11d439 100644
--- a/src/test/regress/expected/lock.out
+++ b/src/test/regress/expected/lock.out
@@ -228,10 +228,22 @@ select relname from pg_locks l, pg_class c
   relname   
 ------------
  lock_tbl1
+ lock_tbl1
+ lock_tbl1
+ lock_tbl1
+ lock_tbl2
  lock_tbl2
+ lock_tbl2
+ lock_tbl2
+ lock_tbl3
  lock_tbl3
+ lock_tbl3
+ lock_tbl3
+ lock_view1
  lock_view1
-(4 rows)
+ lock_view1
+ lock_view1
+(16 rows)
 
 ROLLBACK;
 RESET ROLE;
@@ -264,10 +276,22 @@ select relname from pg_locks l, pg_class c
   relname   
 ------------
  lock_tbl1
+ lock_tbl1
+ lock_tbl1
+ lock_tbl1
+ lock_tbl2
  lock_tbl2
+ lock_tbl2
+ lock_tbl2
+ lock_tbl3
  lock_tbl3
+ lock_tbl3
+ lock_tbl3
+ lock_view8
  lock_view8
-(4 rows)
+ lock_view8
+ lock_view8
+(16 rows)
 
 ROLLBACK;
 RESET ROLE;
diff --git a/src/test/regress/expected/matview.out 
b/src/test/regress/expected/matview.out
index b3cba83fdb4..9f74bd0f56f 100644
--- a/src/test/regress/expected/matview.out
+++ b/src/test/regress/expected/matview.out
@@ -119,12 +119,8 @@ View definition:
  SELECT type,
     totamt
    FROM mvtest_tv
-<<<<<<< HEAD
-  ORDER BY mvtest_tv.type;
-Distributed by: (type)
-=======
   ORDER BY type;
->>>>>>> REL_16_9
+Distributed by: (type)
 
 \d+ mvtest_tvm
                            Materialized view "public.mvtest_tvm"
@@ -136,12 +132,8 @@ View definition:
  SELECT type,
     totamt
    FROM mvtest_tv
-<<<<<<< HEAD
-  ORDER BY mvtest_tv.type;
-Distributed by: (type)
-=======
   ORDER BY type;
->>>>>>> REL_16_9
+Distributed by: (type)
 
 \d+ mvtest_tvvm
                            Materialized view "public.mvtest_tvvm"
@@ -192,12 +184,8 @@ View definition:
  SELECT type,
     totamt
    FROM mvtest_tv
-<<<<<<< HEAD
-  ORDER BY mvtest_tv.type;
-Distributed by: (type)
-=======
   ORDER BY type;
->>>>>>> REL_16_9
+Distributed by: (type)
 
 -- modify the underlying table data
 INSERT INTO mvtest_t VALUES (6, 'z', 13);
@@ -568,6 +556,7 @@ View definition:
     'foo'::text AS u,
     'foo'::text AS u2,
     NULL::text AS n;
+Distributed by: (i)
 
 SELECT * FROM mv_unspecified_types;
  i  | num  |  u  | u2  | n 
@@ -615,17 +604,10 @@ SET ROLE regress_user_mvtest;
 -- duplicate all the aliases used in those queries
 CREATE TABLE mvtest_foo_data AS SELECT i,
   i+1 AS tid,
-<<<<<<< HEAD
-  md5(random()::text) AS mv,
-  md5(random()::text) AS newdata,
-  md5(random()::text) AS newdata2,
-  md5(random()::text) AS diff
-=======
   fipshash(random()::text) AS mv,
   fipshash(random()::text) AS newdata,
   fipshash(random()::text) AS newdata2,
   fipshash(random()::text) AS diff
->>>>>>> REL_16_9
   FROM generate_series(1, 10) i;
 CREATE MATERIALIZED VIEW mvtest_mv_foo AS SELECT * FROM mvtest_foo_data 
distributed by(i);
 CREATE MATERIALIZED VIEW mvtest_mv_foo AS SELECT * FROM mvtest_foo_data 
distributed by(i);
@@ -649,11 +631,15 @@ END;
 $$ LANGUAGE plpgsql;
 CREATE MATERIALIZED VIEW drop_idx_matview AS
   SELECT 1 as i WHERE mvtest_drop_the_index();
-NOTICE:  index "mvtest_drop_idx" does not exist, skipping
+ERROR:  function cannot execute on a QE slice because it issues a non-SELECT 
statement  (seg2 slice1 127.0.1.1:7004 pid=1719927)
+CONTEXT:  SQL statement "DROP INDEX IF EXISTS mvtest_drop_idx"
+PL/pgSQL function mvtest_drop_the_index() line 3 at EXECUTE
 CREATE UNIQUE INDEX mvtest_drop_idx ON drop_idx_matview (i);
+ERROR:  relation "drop_idx_matview" does not exist
 REFRESH MATERIALIZED VIEW CONCURRENTLY drop_idx_matview;
-ERROR:  could not find suitable unique index on materialized view
+ERROR:  relation "drop_idx_matview" does not exist
 DROP MATERIALIZED VIEW drop_idx_matview; -- clean up
+ERROR:  materialized view "drop_idx_matview" does not exist
 -- make sure that create WITH NO DATA works via SPI
 BEGIN;
 CREATE FUNCTION mvtest_func()
diff --git a/src/test/regress/expected/replica_identity.out 
b/src/test/regress/expected/replica_identity.out
index f0701673982..58b4fca9926 100644
--- a/src/test/regress/expected/replica_identity.out
+++ b/src/test/regress/expected/replica_identity.out
@@ -239,8 +239,6 @@ Indexes:
 -- used as replica identity.
 ALTER TABLE test_replica_identity3 ALTER COLUMN id DROP NOT NULL;
 ERROR:  column "id" is in index used as replica identity
-<<<<<<< HEAD
-=======
 --
 -- Test that replica identity can be set on an index that's not yet valid.
 -- (This matches the way pg_dump will try to dump a partitioned table.)
@@ -277,7 +275,6 @@ Indexes:
     "test_replica_identity4_pkey" PRIMARY KEY, btree (id) REPLICA IDENTITY
 Partitions: test_replica_identity4_1 FOR VALUES IN (1)
 
->>>>>>> REL_16_9
 DROP TABLE test_replica_identity;
 DROP TABLE test_replica_identity2;
 DROP TABLE test_replica_identity3;
diff --git a/src/test/regress/serial_schedule b/src/test/regress/serial_schedule
index c0061f931bd..a64936e87fd 100644
--- a/src/test/regress/serial_schedule
+++ b/src/test/regress/serial_schedule
@@ -112,11 +112,11 @@ test: privileges
 test: init_privs
 test: security_label
 test: collate
-# test: matview
-# test: lock
-# test: replica_identity
-# test: rowsecurity
-# test: object_address
+test: matview
+test: lock
+test: replica_identity
+test: rowsecurity
+test: object_address
 # test: tablesample
 # test: task
 # test: appendonly_sample
diff --git a/src/test/regress/sql/matview.sql b/src/test/regress/sql/matview.sql
index dcc819a9934..58090f9bd0d 100644
--- a/src/test/regress/sql/matview.sql
+++ b/src/test/regress/sql/matview.sql
@@ -221,17 +221,10 @@ SET ROLE regress_user_mvtest;
 -- duplicate all the aliases used in those queries
 CREATE TABLE mvtest_foo_data AS SELECT i,
   i+1 AS tid,
-<<<<<<< HEAD
-  md5(random()::text) AS mv,
-  md5(random()::text) AS newdata,
-  md5(random()::text) AS newdata2,
-  md5(random()::text) AS diff
-=======
   fipshash(random()::text) AS mv,
   fipshash(random()::text) AS newdata,
   fipshash(random()::text) AS newdata2,
   fipshash(random()::text) AS diff
->>>>>>> REL_16_9
   FROM generate_series(1, 10) i;
 CREATE MATERIALIZED VIEW mvtest_mv_foo AS SELECT * FROM mvtest_foo_data 
distributed by(i);
 CREATE MATERIALIZED VIEW mvtest_mv_foo AS SELECT * FROM mvtest_foo_data 
distributed by(i);
diff --git a/src/test/regress/sql/replica_identity.sql 
b/src/test/regress/sql/replica_identity.sql
index 318124b3891..26ee7423614 100644
--- a/src/test/regress/sql/replica_identity.sql
+++ b/src/test/regress/sql/replica_identity.sql
@@ -106,8 +106,6 @@ ALTER TABLE test_replica_identity3 ALTER COLUMN id TYPE 
bigint;
 -- used as replica identity.
 ALTER TABLE test_replica_identity3 ALTER COLUMN id DROP NOT NULL;
 
-<<<<<<< HEAD
-=======
 --
 -- Test that replica identity can be set on an index that's not yet valid.
 -- (This matches the way pg_dump will try to dump a partitioned table.)
@@ -127,7 +125,6 @@ ALTER INDEX test_replica_identity4_pkey
   ATTACH PARTITION test_replica_identity4_1_pkey;
 \d+ test_replica_identity4
 
->>>>>>> REL_16_9
 DROP TABLE test_replica_identity;
 DROP TABLE test_replica_identity2;
 DROP TABLE test_replica_identity3;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to