You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by ch...@apache.org on 2025/07/17 12:32:16 UTC

(cloudberry) branch cbdb-postgres-merge updated: Fix conflict for heap.c storage.c in catalog

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 e659cd59ec5 Fix conflict for heap.c storage.c in catalog
e659cd59ec5 is described below

commit e659cd59ec5e5847fa6819cb9558eee8e5c07f5a
Author: Jinbao Chen <ch...@gmail.com>
AuthorDate: Thu Jul 17 20:32:03 2025 +0800

    Fix conflict for heap.c storage.c in catalog
---
 src/backend/catalog/heap.c       | 415 ++-------------------------------------
 src/backend/catalog/pg_attrdef.c |  36 +++-
 src/backend/catalog/storage.c    | 186 ++----------------
 src/include/catalog/storage.h    |   3 +-
 4 files changed, 62 insertions(+), 578 deletions(-)

diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index dbc7ce60990..edc96112b61 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -3,13 +3,9 @@
  * heap.c
  *	  code to create and destroy POSTGRES heap relations
  *
-<<<<<<< HEAD
  * Portions Copyright (c) 2005-2010, Greenplum inc
  * Portions Copyright (c) 2012-Present VMware, Inc. or its affiliates.
- * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
-=======
  * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
->>>>>>> REL_16_9
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
@@ -40,7 +36,6 @@
 #include "access/relation.h"
 #include "access/table.h"
 #include "access/tableam.h"
-<<<<<<< HEAD
 #include "access/toast_compression.h"
 #include "access/transam.h"
 #include "access/reloptions.h"
@@ -50,10 +45,6 @@
 #include "catalog/catalog.h"
 #include "catalog/dependency.h"
 #include "catalog/gp_distribution_policy.h"
-=======
-#include "catalog/binary_upgrade.h"
-#include "catalog/catalog.h"
->>>>>>> REL_16_9
 #include "catalog/heap.h"
 #include "catalog/index.h"
 #include "catalog/namespace.h"
@@ -79,11 +70,8 @@
 #include "catalog/pg_tablespace.h"
 #include "catalog/pg_type.h"
 #include "catalog/storage.h"
-<<<<<<< HEAD
 #include "catalog/storage_directory_table.h"
 #include "catalog/storage_xlog.h"
-=======
->>>>>>> REL_16_9
 #include "commands/tablecmds.h"
 #include "commands/typecmds.h"
 #include "miscadmin.h"
@@ -118,10 +106,15 @@
 #include "utils/relcache.h"
 #include "utils/timestamp.h"
 
-<<<<<<< HEAD
 #include "catalog/gp_indexing.h"
 #include "catalog/gp_matview_aux.h"
 
+/* Potentially set by pg_upgrade_support functions */
+Oid			binary_upgrade_next_heap_pg_class_oid = InvalidOid;
+Oid			binary_upgrade_next_toast_pg_class_oid = InvalidOid;
+RelFileNumber binary_upgrade_next_heap_pg_class_relfilenumber = InvalidRelFileNumber;
+RelFileNumber binary_upgrade_next_toast_pg_class_relfilenumber = InvalidRelFileNumber;
+
 static void MetaTrackAddUpdInternal(Oid			classid,
 									Oid			objoid,
 									Oid			relowner,
@@ -129,13 +122,6 @@ static void MetaTrackAddUpdInternal(Oid			classid,
 									char*		subtype,
 									Relation	rel,
 									HeapTuple	old_tuple);
-=======
-/* Potentially set by pg_upgrade_support functions */
-Oid			binary_upgrade_next_heap_pg_class_oid = InvalidOid;
-Oid			binary_upgrade_next_toast_pg_class_oid = InvalidOid;
-RelFileNumber binary_upgrade_next_heap_pg_class_relfilenumber = InvalidRelFileNumber;
-RelFileNumber binary_upgrade_next_toast_pg_class_relfilenumber = InvalidRelFileNumber;
->>>>>>> REL_16_9
 
 static void AddNewRelationTuple(Relation pg_class_desc,
 								Relation new_rel_desc,
@@ -427,7 +413,6 @@ heap_create(const char *relname,
 		create_storage = false;
 	else
 	{
-<<<<<<< HEAD
 		create_storage = true;
 		/*
 		 * In PostgreSQL, the relation OID is used as the relfilenode initially.
@@ -435,15 +420,8 @@ heap_create(const char *relname,
 		 * to RelationBuildLocalRelation() to signal that it should assign a
 		 * a new value.
 		 */
-		relfilenode = 1;
-=======
-		/*
-		 * If relfilenumber is unspecified by the caller then create storage
-		 * with oid same as relid.
-		 */
 		if (!RelFileNumberIsValid(relfilenumber))
-			relfilenumber = relid;
->>>>>>> REL_16_9
+			relfilenumber = 1;
 	}
 
 	/*
@@ -482,50 +460,9 @@ heap_create(const char *relname,
 	 */
 	if (create_storage)
 	{
-<<<<<<< HEAD
 		RelationOpenSmgr(rel);
 
-		switch (rel->rd_rel->relkind)
-		{
-			case RELKIND_VIEW:
-			case RELKIND_COMPOSITE_TYPE:
-			case RELKIND_FOREIGN_TABLE:
-			case RELKIND_PARTITIONED_TABLE:
-			case RELKIND_PARTITIONED_INDEX:
-				Assert(false);
-				break;
 
-			case RELKIND_INDEX:
-			case RELKIND_SEQUENCE:
-				RelationCreateStorage(rel->rd_node, relpersistence, SMGR_MD, rel);
-				break;
-
-			case RELKIND_RELATION:
-			case RELKIND_TOASTVALUE:
-			case RELKIND_MATVIEW:
-			case RELKIND_DIRECTORY_TABLE:
-				table_relation_set_new_filenode(rel, &rel->rd_node,
-												relpersistence,
-												relfrozenxid, relminmxid);
-				break;
-
-			case RELKIND_AOSEGMENTS:
-			case RELKIND_AOVISIMAP:
-			case RELKIND_AOBLOCKDIR:
-				Assert(rel->rd_tableam);
-				table_relation_set_new_filenode(rel, &rel->rd_node,
-												relpersistence,
-												relfrozenxid, relminmxid);
-				break;
-		}
-
-		/*
-		 * AO tables don't use the buffer manager, better to not keep the
-		 * smgr open for it.
-		 */
-		if (RelationStorageIsAO(rel))
-			RelationCloseSmgr(rel);
-=======
 		if (RELKIND_HAS_TABLE_AM(rel->rd_rel->relkind))
 			table_relation_set_new_filelocator(rel, &rel->rd_locator,
 											   relpersistence,
@@ -534,7 +471,13 @@ heap_create(const char *relname,
 			RelationCreateStorage(rel->rd_locator, relpersistence, true);
 		else
 			Assert(false);
->>>>>>> REL_16_9
+
+		/*
+		 * AO tables don't use the buffer manager, better to not keep the
+		 * smgr open for it.
+		 */
+		if (RelationStorageIsAO(rel))
+			RelationCloseSmgr(rel);
 	}
 
 	/*
@@ -695,7 +638,6 @@ CheckAttributeType(const char *attname,
 	char		att_typtype = get_typtype(atttypid);
 	Oid			att_typelem;
 
-<<<<<<< HEAD
 	if (Gp_role == GP_ROLE_EXECUTE)
 	{
 		/*
@@ -704,10 +646,9 @@ CheckAttributeType(const char *attname,
 		 */
 		return;
 	}
-=======
+
 	/* since this function recurses, it could be driven to stack overflow */
 	check_stack_depth();
->>>>>>> REL_16_9
 
 	if (att_typtype == TYPTYPE_PSEUDO)
 	{
@@ -1404,36 +1345,8 @@ AddNewRelationTuple(Relation pg_class_desc,
 	/* Sequences always have a known size */
 	if (relkind == RELKIND_SEQUENCE)
 	{
-<<<<<<< HEAD
-		case RELKIND_RELATION:
-		case RELKIND_MATVIEW:
-		case RELKIND_INDEX:
-		case RELKIND_TOASTVALUE:
-		case RELKIND_AOSEGMENTS:
-		case RELKIND_AOBLOCKDIR:
-		case RELKIND_AOVISIMAP:
-		case RELKIND_DIRECTORY_TABLE:
-			/* The relation is real, but as yet empty */
-			new_rel_reltup->relpages = 0;
-			new_rel_reltup->reltuples = -1;
-			new_rel_reltup->relallvisible = 0;
-			break;
-		case RELKIND_SEQUENCE:
-			/* Sequences always have a known size */
-			new_rel_reltup->relpages = 1;
-			new_rel_reltup->reltuples = 1;
-			new_rel_reltup->relallvisible = 0;
-			break;
-		default:
-			/* Views, etc, have no disk storage */
-			new_rel_reltup->relpages = 0;
-			new_rel_reltup->reltuples = -1;
-			new_rel_reltup->relallvisible = 0;
-			break;
-=======
 		new_rel_reltup->relpages = 1;
 		new_rel_reltup->reltuples = 1;
->>>>>>> REL_16_9
 	}
 
 	/* Initialize relfrozenxid and relminmxid */
@@ -1633,7 +1546,6 @@ heap_create_with_catalog(const char *relname,
 	/*
 	 * Allocate an OID for the relation, unless we were told what to use.
 	 *
-<<<<<<< HEAD
 	 * In PostgreSQL, the OID will be the relfilenode as well, but in GPDB
 	 * that is assigned separately.
 	 */
@@ -1641,66 +1553,6 @@ heap_create_with_catalog(const char *relname,
 	{
 		relid = GetNewOidForRelation(pg_class_desc, ClassOidIndexId, Anum_pg_class_oid,
 									 pstrdup(relname), relnamespace);
-=======
-	 * The OID will be the relfilenumber as well, so make sure it doesn't
-	 * collide with either pg_class OIDs or existing physical files.
-	 */
-	if (!OidIsValid(relid))
-	{
-		/* Use binary-upgrade override for pg_class.oid and relfilenumber */
-		if (IsBinaryUpgrade)
-		{
-			/*
-			 * Indexes are not supported here; they use
-			 * binary_upgrade_next_index_pg_class_oid.
-			 */
-			Assert(relkind != RELKIND_INDEX);
-			Assert(relkind != RELKIND_PARTITIONED_INDEX);
-
-			if (relkind == RELKIND_TOASTVALUE)
-			{
-				/* There might be no TOAST table, so we have to test for it. */
-				if (OidIsValid(binary_upgrade_next_toast_pg_class_oid))
-				{
-					relid = binary_upgrade_next_toast_pg_class_oid;
-					binary_upgrade_next_toast_pg_class_oid = InvalidOid;
-
-					if (!RelFileNumberIsValid(binary_upgrade_next_toast_pg_class_relfilenumber))
-						ereport(ERROR,
-								(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-								 errmsg("toast relfilenumber value not set when in binary upgrade mode")));
-
-					relfilenumber = binary_upgrade_next_toast_pg_class_relfilenumber;
-					binary_upgrade_next_toast_pg_class_relfilenumber = InvalidRelFileNumber;
-				}
-			}
-			else
-			{
-				if (!OidIsValid(binary_upgrade_next_heap_pg_class_oid))
-					ereport(ERROR,
-							(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-							 errmsg("pg_class heap OID value not set when in binary upgrade mode")));
-
-				relid = binary_upgrade_next_heap_pg_class_oid;
-				binary_upgrade_next_heap_pg_class_oid = InvalidOid;
-
-				if (RELKIND_HAS_STORAGE(relkind))
-				{
-					if (!RelFileNumberIsValid(binary_upgrade_next_heap_pg_class_relfilenumber))
-						ereport(ERROR,
-								(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-								 errmsg("relfilenumber value not set when in binary upgrade mode")));
-
-					relfilenumber = binary_upgrade_next_heap_pg_class_relfilenumber;
-					binary_upgrade_next_heap_pg_class_relfilenumber = InvalidRelFileNumber;
-				}
-			}
-		}
-
-		if (!OidIsValid(relid))
-			relid = GetNewRelFileNumber(reltablespace, pg_class_desc,
-										relpersistence);
->>>>>>> REL_16_9
 	}
 
 	/*
@@ -1979,13 +1831,7 @@ heap_create_with_catalog(const char *relname,
 		 * No need to add an explicit dependency for the toast table, as the
 		 * main table depends on it.
 		 */
-<<<<<<< HEAD
-		if (relkind == RELKIND_RELATION ||
-			relkind == RELKIND_DIRECTORY_TABLE ||
-			relkind == RELKIND_MATVIEW)
-=======
 		if (RELKIND_HAS_TABLE_AM(relkind) && relkind != RELKIND_TOASTVALUE)
->>>>>>> REL_16_9
 		{
 			ObjectAddressSet(referenced, AccessMethodRelationId, accessmtd);
 			add_exact_object_address(&referenced, addrs);
@@ -2485,9 +2331,8 @@ heap_drop_with_catalog(Oid relid)
 	 */
 	if (rel->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
 	{
-<<<<<<< HEAD
-		Relation	rel;
-		HeapTuple	tuple;
+		Relation	ftrel;
+		HeapTuple	fttuple;
 		ScanKeyData	ftkey;
 		SysScanDesc	ftscan;
 
@@ -2508,10 +2353,6 @@ heap_drop_with_catalog(Oid relid)
 
 		systable_endscan(ftscan);
 		table_close(rel, RowExclusiveLock);
-=======
-		Relation	ftrel;
-		HeapTuple	fttuple;
->>>>>>> REL_16_9
 
 		ftrel = table_open(ForeignTableRelationId, RowExclusiveLock);
 
@@ -2851,223 +2692,6 @@ SetAttrMissing(Oid relid, char *attname, char *value)
 }
 
 /*
-<<<<<<< HEAD
- * Store a default expression for column attnum of relation rel.
- *
- * Returns the OID of the new pg_attrdef tuple.
- *
- * add_column_mode must be true if we are storing the default for a new
- * attribute, and false if it's for an already existing attribute. The reason
- * for this is that the missing value must never be updated after it is set,
- * which can only be when a column is added to the table. Otherwise we would
- * in effect be changing existing tuples.
- *
- * In GPDB in add_column_mode, the QD evaluates the default expression, and
- * the QEs must use the pre-computed value. In QD, this function evaluates
- * the value - like in upstream - and returns it in
- * *missingval_p/missingIsNull_p. In the QE, the caller is expected to pass
- * the pre-computed values in missingval/missingIsNull.
- */
-Oid
-StoreAttrDefault(Relation rel, AttrNumber attnum,
-				 Node *expr,
-				 bool *cookedMissingVal,
-				 Datum *missingval_p,
-				 bool *missingIsNull_p,
-				 bool is_internal, bool add_column_mode)
-{
-	char	   *adbin;
-	Relation	adrel;
-	HeapTuple	tuple;
-	Datum		values[4];
-	static bool nulls[4] = {false, false, false, false};
-	Relation	attrrel;
-	HeapTuple	atttup;
-	Form_pg_attribute attStruct;
-	char		attgenerated;
-	Oid			attrdefOid;
-	ObjectAddress colobject,
-				defobject;
-
-	adrel = table_open(AttrDefaultRelationId, RowExclusiveLock);
-
-	/*
-	 * Flatten expression to string form for storage.
-	 */
-	adbin = nodeToString(expr);
-
-	/*
-	 * Make the pg_attrdef entry.
-	 */
-	attrdefOid = GetNewOidForAttrDefault(adrel, AttrDefaultOidIndexId,
-										 Anum_pg_attrdef_oid,
-										 RelationGetRelid(rel),
-										 attnum);
-	values[Anum_pg_attrdef_oid - 1] = ObjectIdGetDatum(attrdefOid);
-	values[Anum_pg_attrdef_adrelid - 1] = RelationGetRelid(rel);
-	values[Anum_pg_attrdef_adnum - 1] = attnum;
-	values[Anum_pg_attrdef_adbin - 1] = CStringGetTextDatum(adbin);
-
-	tuple = heap_form_tuple(adrel->rd_att, values, nulls);
-	CatalogTupleInsert(adrel, tuple);
-
-	defobject.classId = AttrDefaultRelationId;
-	defobject.objectId = attrdefOid;
-	defobject.objectSubId = 0;
-
-	table_close(adrel, RowExclusiveLock);
-
-	/* now can free some of the stuff allocated above */
-	pfree(DatumGetPointer(values[Anum_pg_attrdef_adbin - 1]));
-	heap_freetuple(tuple);
-	pfree(adbin);
-
-	/*
-	 * Update the pg_attribute entry for the column to show that a default
-	 * exists.
-	 */
-	attrrel = table_open(AttributeRelationId, RowExclusiveLock);
-	atttup = SearchSysCacheCopy2(ATTNUM,
-								 ObjectIdGetDatum(RelationGetRelid(rel)),
-								 Int16GetDatum(attnum));
-	if (!HeapTupleIsValid(atttup))
-		elog(ERROR, "cache lookup failed for attribute %d of relation %u",
-			 attnum, RelationGetRelid(rel));
-	attStruct = (Form_pg_attribute) GETSTRUCT(atttup);
-	attgenerated = attStruct->attgenerated;
-	if (!attStruct->atthasdef)
-	{
-		Form_pg_attribute defAttStruct;
-
-		ExprState  *exprState;
-		Expr	   *expr2 = (Expr *) expr;
-		EState	   *estate = NULL;
-		ExprContext *econtext;
-		Datum		valuesAtt[Natts_pg_attribute];
-		bool		nullsAtt[Natts_pg_attribute];
-		bool		replacesAtt[Natts_pg_attribute];
-		Datum		missingval = (Datum) 0;
-		bool		missingIsNull = true;
-
-		MemSet(valuesAtt, 0, sizeof(valuesAtt));
-		MemSet(nullsAtt, false, sizeof(nullsAtt));
-		MemSet(replacesAtt, false, sizeof(replacesAtt));
-		valuesAtt[Anum_pg_attribute_atthasdef - 1] = true;
-		replacesAtt[Anum_pg_attribute_atthasdef - 1] = true;
-
-		if ((rel->rd_rel->relkind == RELKIND_RELATION || rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) &&
-			add_column_mode && !attgenerated && cookedMissingVal && *cookedMissingVal)
-		{
-			missingval = *missingval_p;
-			missingIsNull = *missingIsNull_p;
-		}
-		else if ((rel->rd_rel->relkind == RELKIND_RELATION || rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) &&
-			add_column_mode && !attgenerated)
-		{
-			expr2 = expression_planner(expr2);
-			estate = CreateExecutorState();
-			exprState = ExecPrepareExpr(expr2, estate);
-			econtext = GetPerTupleExprContext(estate);
-
-			missingval = ExecEvalExpr(exprState, econtext,
-									  &missingIsNull);
-
-			FreeExecutorState(estate);
-
-			defAttStruct = TupleDescAttr(rel->rd_att, attnum - 1);
-
-			if (missingIsNull)
-			{
-				/* if the default evaluates to NULL, just store a NULL array */
-				missingval = (Datum) 0;
-			}
-			else
-			{
-				/* otherwise make a one-element array of the value */
-				missingval = PointerGetDatum(construct_array(&missingval,
-															 1,
-															 defAttStruct->atttypid,
-															 defAttStruct->attlen,
-															 defAttStruct->attbyval,
-															 defAttStruct->attalign));
-			}
-		}
-		if (add_column_mode && !attgenerated)
-		{
-			valuesAtt[Anum_pg_attribute_atthasmissing - 1] = !missingIsNull;
-			replacesAtt[Anum_pg_attribute_atthasmissing - 1] = true;
-			valuesAtt[Anum_pg_attribute_attmissingval - 1] = missingval;
-			replacesAtt[Anum_pg_attribute_attmissingval - 1] = true;
-			nullsAtt[Anum_pg_attribute_attmissingval - 1] = missingIsNull;
-
-			*cookedMissingVal = true;
-			*missingval_p = missingval;
-			*missingIsNull_p = missingIsNull;
-		}
-		atttup = heap_modify_tuple(atttup, RelationGetDescr(attrrel),
-								   valuesAtt, nullsAtt, replacesAtt);
-
-		CatalogTupleUpdate(attrrel, &atttup->t_self, atttup);
-
-		/* GPDB: don't free it, it's returned to the caller */
-		//if (!missingIsNull)
-		//	pfree(DatumGetPointer(missingval));
-
-	}
-	table_close(attrrel, RowExclusiveLock);
-	heap_freetuple(atttup);
-
-	/*
-	 * Make a dependency so that the pg_attrdef entry goes away if the column
-	 * (or whole table) is deleted.
-	 */
-	colobject.classId = RelationRelationId;
-	colobject.objectId = RelationGetRelid(rel);
-	colobject.objectSubId = attnum;
-
-	recordDependencyOn(&defobject, &colobject, DEPENDENCY_AUTO);
-
-	/*
-	 * Record dependencies on objects used in the expression, too.
-	 */
-	if (attgenerated)
-	{
-		/*
-		 * Generated column: Dropping anything that the generation expression
-		 * refers to automatically drops the generated column.
-		 */
-		recordDependencyOnSingleRelExpr(&colobject, expr, RelationGetRelid(rel),
-										DEPENDENCY_AUTO,
-										DEPENDENCY_AUTO, false);
-	}
-	else
-	{
-		/*
-		 * Normal default: Dropping anything that the default refers to
-		 * requires CASCADE and drops the default only.
-		 */
-		recordDependencyOnSingleRelExpr(&defobject, expr, RelationGetRelid(rel),
-										DEPENDENCY_NORMAL,
-										DEPENDENCY_NORMAL, false);
-	}
-
-	/*
-	 * Post creation hook for attribute defaults.
-	 *
-	 * XXX. ALTER TABLE ALTER COLUMN SET/DROP DEFAULT is implemented with a
-	 * couple of deletion/creation of the attribute's default entry, so the
-	 * callee should check existence of an older version of this entry if it
-	 * needs to distinguish.
-	 */
-	InvokeObjectPostCreateHookArg(AttrDefaultRelationId,
-								  RelationGetRelid(rel), attnum, is_internal);
-
-	return attrdefOid;
-}
-
-/*
-=======
->>>>>>> REL_16_9
  * Store a check-constraint expression for the given relation.
  *
  * Caller is responsible for updating the count of constraints
@@ -3335,7 +2959,6 @@ AddRelationNewConstraints(Relation rel,
 			 castNode(Const, expr)->constisnull))
 			continue;
 
-<<<<<<< HEAD
 		/* If the DEFAULT is volatile we cannot use a missing value */
 		if (colDef->missingMode && contain_volatile_functions((Node *) expr))
 			colDef->missingMode = false;
@@ -3346,10 +2969,6 @@ AddRelationNewConstraints(Relation rel,
 								  &colDef->missingIsNull,
 								  is_internal,
 								  colDef->missingMode);
-=======
-		defOid = StoreAttrDefault(rel, colDef->attnum, expr, is_internal,
-								  false);
->>>>>>> REL_16_9
 
 		cooked = (CookedConstraint *) palloc(sizeof(CookedConstraint));
 		cooked->contype = CONSTR_DEFAULT;
diff --git a/src/backend/catalog/pg_attrdef.c b/src/backend/catalog/pg_attrdef.c
index 1adec07009c..6498520645f 100644
--- a/src/backend/catalog/pg_attrdef.c
+++ b/src/backend/catalog/pg_attrdef.c
@@ -21,6 +21,7 @@
 #include "catalog/dependency.h"
 #include "catalog/indexing.h"
 #include "catalog/objectaccess.h"
+#include "catalog/oid_dispatch.h"
 #include "catalog/pg_attrdef.h"
 #include "executor/executor.h"
 #include "optimizer/optimizer.h"
@@ -44,7 +45,11 @@
  */
 Oid
 StoreAttrDefault(Relation rel, AttrNumber attnum,
-				 Node *expr, bool is_internal, bool add_column_mode)
+				 Node *expr,
+				 bool *cookedMissingVal,
+				 Datum *missingval_p,
+				 bool *missingIsNull_p,
+				 bool is_internal, bool add_column_mode)
 {
 	char	   *adbin;
 	Relation	adrel;
@@ -69,8 +74,10 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
 	/*
 	 * Make the pg_attrdef entry.
 	 */
-	attrdefOid = GetNewOidWithIndex(adrel, AttrDefaultOidIndexId,
-									Anum_pg_attrdef_oid);
+	attrdefOid = GetNewOidForAttrDefault(adrel, AttrDefaultOidIndexId,
+										 Anum_pg_attrdef_oid,
+										 RelationGetRelid(rel),
+										 attnum);
 	values[Anum_pg_attrdef_oid - 1] = ObjectIdGetDatum(attrdefOid);
 	values[Anum_pg_attrdef_adrelid - 1] = RelationGetRelid(rel);
 	values[Anum_pg_attrdef_adnum - 1] = attnum;
@@ -126,8 +133,14 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
 		 * it in back branches on the slight chance that some extension is
 		 * depending on it.
 		 */
-		if (rel->rd_rel->relkind == RELKIND_RELATION && add_column_mode &&
-			!attgenerated)
+		if ((rel->rd_rel->relkind == RELKIND_RELATION || rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) &&
+			add_column_mode && !attgenerated && cookedMissingVal && *cookedMissingVal)
+		{
+			missingval = *missingval_p;
+			missingIsNull = *missingIsNull_p;
+		}
+		else if ((rel->rd_rel->relkind == RELKIND_RELATION || rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE) &&
+			add_column_mode && !attgenerated)
 		{
 			expr2 = expression_planner(expr2);
 			estate = CreateExecutorState();
@@ -157,19 +170,28 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
 															 defAttStruct->attalign));
 			}
 
+
+		}
+		if (add_column_mode && !attgenerated)
+		{
 			valuesAtt[Anum_pg_attribute_atthasmissing - 1] = !missingIsNull;
 			replacesAtt[Anum_pg_attribute_atthasmissing - 1] = true;
 			valuesAtt[Anum_pg_attribute_attmissingval - 1] = missingval;
 			replacesAtt[Anum_pg_attribute_attmissingval - 1] = true;
 			nullsAtt[Anum_pg_attribute_attmissingval - 1] = missingIsNull;
+
+			*cookedMissingVal = true;
+			*missingval_p = missingval;
+			*missingIsNull_p = missingIsNull;
 		}
 		atttup = heap_modify_tuple(atttup, RelationGetDescr(attrrel),
 								   valuesAtt, nullsAtt, replacesAtt);
 
 		CatalogTupleUpdate(attrrel, &atttup->t_self, atttup);
 
-		if (!missingIsNull)
-			pfree(DatumGetPointer(missingval));
+		/* GPDB: don't free it, it's returned to the caller */
+//		if (!missingIsNull)
+//			pfree(DatumGetPointer(missingval));
 	}
 	table_close(attrrel, RowExclusiveLock);
 	heap_freetuple(atttup);
diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c
index 60cd554b54a..06190e942d1 100644
--- a/src/backend/catalog/storage.c
+++ b/src/backend/catalog/storage.c
@@ -40,8 +40,6 @@
 /* GUC variables */
 int			wal_skip_threshold = 2048;	/* in kilobytes */
 
-<<<<<<< HEAD
-=======
 /*
  * We keep a list of all relations (represented as RelFileLocator values)
  * that have been created or deleted in the current transaction.  When
@@ -62,16 +60,6 @@ int			wal_skip_threshold = 2048;	/* in kilobytes */
  * but I'm being paranoid.
  */
 
-typedef struct PendingRelDelete
-{
-	RelFileLocator rlocator;	/* relation that may need to be deleted */
-	BackendId	backend;		/* InvalidBackendId if not a temp rel */
-	bool		atCommit;		/* T=delete at commit; F=delete at abort */
-	int			nestLevel;		/* xact nesting level of request */
-	struct PendingRelDelete *next;	/* linked-list link */
-} PendingRelDelete;
->>>>>>> REL_16_9
-
 typedef struct PendingRelSync
 {
 	RelFileLocator rlocator;
@@ -155,12 +143,7 @@ AddPendingSync(const RelFileLocator *rlocator)
  * pass register_delete = false.
  */
 SMgrRelation
-<<<<<<< HEAD
-RelationCreateStorage(RelFileNode rnode, char relpersistence, SMgrImpl smgr_which, Relation rel)
-=======
-RelationCreateStorage(RelFileLocator rlocator, char relpersistence,
-					  bool register_delete)
->>>>>>> REL_16_9
+RelationCreateStorage(RelFileLocator rlocator, char relpersistence, bool register_delete, SMgrImpl smgr_which, Relation rel)
 {
 	SMgrRelation srel;
 	BackendId	backend;
@@ -187,24 +170,6 @@ RelationCreateStorage(RelFileLocator rlocator, char relpersistence,
 			return NULL;		/* placate compiler */
 	}
 
-<<<<<<< HEAD
-	srel = smgropen(rnode, backend, smgr_which, rel);
-	smgrcreate(srel, MAIN_FORKNUM, false);
-
-	if (needs_wal)
-		log_smgrcreate(&srel->smgr_rnode.node, MAIN_FORKNUM, smgr_which);
-
-	/* Add the relation to the list of stuff to delete at abort */
-	pending = (PendingRelDelete *)
-		MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete));
-	pending->relnode.node = rnode;
-	pending->relnode.isTempRelation = backend == TempRelBackendId;
-	pending->atCommit = false;	/* delete if abort */
-	pending->nestLevel = GetCurrentTransactionNestLevel();
-	pending->relnode.smgr_which = smgr_which;
-	pending->action = &storage_pending_rel_deletes_action;
-	RegisterPendingDelete(pending);
-=======
 	srel = smgropen(rlocator, backend);
 	smgrcreate(srel, MAIN_FORKNUM, false);
 
@@ -221,14 +186,15 @@ RelationCreateStorage(RelFileLocator rlocator, char relpersistence,
 
 		pending = (PendingRelDelete *)
 			MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete));
-		pending->rlocator = rlocator;
+		pending->rlocator.node = rlocator;
+		pending->rlocator.isTempRelation = backend == TempRelBackendId;
 		pending->backend = backend;
 		pending->atCommit = false;	/* delete if abort */
 		pending->nestLevel = GetCurrentTransactionNestLevel();
-		pending->next = pendingDeletes;
-		pendingDeletes = pending;
+		pending->rlocator.smgr_which = smgr_which;
+		pending->action = &storage_pending_rel_deletes_action;
+		RegisterPendingDelete(pending);
 	}
->>>>>>> REL_16_9
 
 	if (relpersistence == RELPERSISTENCE_PERMANENT && !XLogIsNeeded())
 	{
@@ -243,11 +209,7 @@ RelationCreateStorage(RelFileLocator rlocator, char relpersistence,
  * Perform XLogInsert of an XLOG_SMGR_CREATE record to WAL.
  */
 void
-<<<<<<< HEAD
-log_smgrcreate(const RelFileNode *rnode, ForkNumber forkNum, SMgrImpl impl)
-=======
-log_smgrcreate(const RelFileLocator *rlocator, ForkNumber forkNum)
->>>>>>> REL_16_9
+log_smgrcreate(const RelFileLocator *rlocator, ForkNumber forkNum, SMgrImpl impl)
 {
 	xl_smgr_create xlrec;
 
@@ -275,16 +237,12 @@ RelationDropStorage(Relation rel)
 	/* Add the relation to the list of stuff to delete at commit */
 	pending = (PendingRelDelete *)
 		MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete));
-<<<<<<< HEAD
-	pending->relnode.node = rel->rd_node;
-	pending->relnode.isTempRelation = rel->rd_backend == TempRelBackendId;
-=======
-	pending->rlocator = rel->rd_locator;
+	pending->rlocator.node = rel->rd_locator;
 	pending->backend = rel->rd_backend;
->>>>>>> REL_16_9
+	pending->rlocator.isTempRelation = rel->rd_backend == TempRelBackendId;
 	pending->atCommit = true;	/* delete if commit */
 	pending->nestLevel = GetCurrentTransactionNestLevel();
-	pending->relnode.smgr_which = smgr_get_impl(rel);
+	pending->rlocator.smgr_which = smgr_get_impl(rel);
 	pending->action = &storage_pending_rel_deletes_action;
 	RegisterPendingDelete(pending);
 
@@ -329,17 +287,13 @@ RelationPreserveStorage(RelFileLocator rlocator, bool atCommit)
 	for (pending = pendingDeletes; pending != NULL; pending = next)
 	{
 		next = pending->next;
-<<<<<<< HEAD
 		Assert(pending->action);
 		if (!(pending->action->flags & PENDING_REL_DELETE_NEED_PRESERVE))
 		{
 			continue;
 		}
 
-		if (RelFileNodeEquals(rnode, pending->relnode.node)
-=======
-		if (RelFileLocatorEquals(rlocator, pending->rlocator)
->>>>>>> REL_16_9
+		if (RelFileLocatorEquals(rlocator, pending->rlocator.node)
 			&& pending->atCommit == atCommit)
 		{
 			/* unlink and delete list entry */
@@ -422,24 +376,16 @@ RelationTruncate(Relation rel, BlockNumber nblocks)
 	RelationPreTruncate(rel);
 
 	/*
-<<<<<<< HEAD
-	 * Make sure that a concurrent checkpoint can't complete while truncation
-	 * is in progress.
-	 *
-	 * The truncation operation might drop buffers that the checkpoint
-=======
 	 * The code which follows can interact with concurrent checkpoints in two
 	 * separate ways.
 	 *
 	 * First, the truncation operation might drop buffers that the checkpoint
->>>>>>> REL_16_9
 	 * otherwise would have flushed. If it does, then it's essential that the
 	 * files actually get truncated on disk before the checkpoint record is
 	 * written. Otherwise, if reply begins from that checkpoint, the
 	 * to-be-truncated blocks might still exist on disk but have older
 	 * contents than expected, which can cause replay to fail. It's OK for the
 	 * blocks to not exist on disk at all, but not for them to have the wrong
-<<<<<<< HEAD
 	 * contents.
 	 */
 	Assert(!MyProc->delayChkptEnd);
@@ -453,22 +399,6 @@ RelationTruncate(Relation rel, BlockNumber nblocks)
 	 * would be worse than the disease. It would turn a usually harmless
 	 * failure to truncate, that might spell trouble at WAL replay, into a
 	 * certain PANIC.
-=======
-	 * contents. For this reason, we need to set DELAY_CHKPT_COMPLETE while
-	 * this code executes.
-	 *
-	 * Second, the call to smgrtruncate() below will in turn call
-	 * RegisterSyncRequest(). We need the sync request created by that call to
-	 * be processed before the checkpoint completes. CheckPointGuts() will
-	 * call ProcessSyncRequests(), but if we register our sync request after
-	 * that happens, then the WAL record for the truncation could end up
-	 * preceding the checkpoint record, while the actual sync doesn't happen
-	 * until the next checkpoint. To prevent that, we need to set
-	 * DELAY_CHKPT_START here. That way, if the XLOG_SMGR_TRUNCATE precedes
-	 * the redo pointer of a concurrent checkpoint, we're guaranteed that the
-	 * corresponding sync request will be processed before the checkpoint
-	 * completes.
->>>>>>> REL_16_9
 	 */
 	Assert((MyProc->delayChkptFlags & (DELAY_CHKPT_START | DELAY_CHKPT_COMPLETE)) == 0);
 	MyProc->delayChkptFlags |= DELAY_CHKPT_START | DELAY_CHKPT_COMPLETE;
@@ -486,8 +416,6 @@ RelationTruncate(Relation rel, BlockNumber nblocks)
 	 *
 	 * (See also pg_visibilitymap.c if changing this code.)
 	 */
-	START_CRIT_SECTION();
-
 	if (RelationNeedsWAL(rel))
 	{
 		/*
@@ -522,16 +450,7 @@ RelationTruncate(Relation rel, BlockNumber nblocks)
 	 * longer exist after truncation is complete, and then truncate the
 	 * corresponding files on disk.
 	 */
-<<<<<<< HEAD
 	smgrtruncate(rel->rd_smgr, forks, nforks, blocks);
-=======
-	smgrtruncate2(RelationGetSmgr(rel), forks, nforks, old_blocks, blocks);
-
-	END_CRIT_SECTION();
-
-	/* We've done all the critical work, so checkpoints are OK now. */
-	MyProc->delayChkptFlags &= ~(DELAY_CHKPT_START | DELAY_CHKPT_COMPLETE);
->>>>>>> REL_16_9
 
 	/* We've done all the critical work, so checkpoints are OK now. */
 	MyProc->delayChkptEnd = false;
@@ -623,7 +542,6 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst,
 
 		smgrread(src, forkNum, blkno, buf.data);
 
-<<<<<<< HEAD
 		if (!PageIsVerifiedExtended(page, forkNum,
 									blkno, PIV_LOG_WARNING | PIV_REPORT_STAT))
 			ereport(ERROR,
@@ -633,28 +551,6 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst,
 							relpathbackend(src->smgr_rnode.node,
 										   src->smgr_rnode.backend,
 										   forkNum))));
-=======
-		if (!PageIsVerifiedExtended(page, blkno,
-									PIV_LOG_WARNING | PIV_REPORT_STAT))
-		{
-			/*
-			 * For paranoia's sake, capture the file path before invoking the
-			 * ereport machinery.  This guards against the possibility of a
-			 * relcache flush caused by, e.g., an errcontext callback.
-			 * (errcontext callbacks shouldn't be risking any such thing, but
-			 * people have been known to forget that rule.)
-			 */
-			char	   *relpath = relpathbackend(src->smgr_rlocator.locator,
-												 src->smgr_rlocator.backend,
-												 forkNum);
-
-			ereport(ERROR,
-					(errcode(ERRCODE_DATA_CORRUPTED),
-					 errmsg("invalid page in block %u of relation %s",
-							blkno, relpath)));
-		}
-
->>>>>>> REL_16_9
 		/*
 		 * WAL-log the copied page. Unfortunately we don't know what kind of a
 		 * page this is, so we have to log the full page including any unused
@@ -753,15 +649,10 @@ SerializePendingSyncs(Size maxSize, char *startAddress)
 
 	/* remove deleted rnodes */
 	for (delete = pendingDeletes; delete != NULL; delete = delete->next)
-<<<<<<< HEAD
 	{
 		Assert(delete->action);
 		if (delete->atCommit || !(delete->action->flags & PENDING_REL_DELETE_NEED_SYNC))
 			(void) hash_search(tmphash, (void *) &delete->relnode,
-=======
-		if (delete->atCommit)
-			(void) hash_search(tmphash, &delete->rlocator,
->>>>>>> REL_16_9
 							   HASH_REMOVE, NULL);
 	}
 	hash_seq_init(&scan, tmphash);
@@ -840,29 +731,9 @@ smgrDoPendingDeletes(bool isCommit)
 			/* do deletion if called for */
 			if (pending->atCommit == isCommit)
 			{
-<<<<<<< HEAD
 				Assert(pending->action);
 				Assert(pending->action->do_pending_rel_delete);
 				pending->action->do_pending_rel_delete(pending);
-=======
-				SMgrRelation srel;
-
-				srel = smgropen(pending->rlocator, pending->backend);
-
-				/* allocate the initial array, or extend it, if needed */
-				if (maxrels == 0)
-				{
-					maxrels = 8;
-					srels = palloc(sizeof(SMgrRelation) * maxrels);
-				}
-				else if (maxrels <= nrels)
-				{
-					maxrels *= 2;
-					srels = repalloc(srels, sizeof(SMgrRelation) * maxrels);
-				}
-
-				srels[nrels++] = srel;
->>>>>>> REL_16_9
 			}
 
 			/* must explicitly free the list entry */
@@ -913,15 +784,10 @@ smgrDoPendingSyncs(bool isCommit, bool isParallelWorker)
 	 * the no need sync pending delete item.
 	 */
 	for (pending = pendingDeletes; pending != NULL; pending = pending->next)
-<<<<<<< HEAD
 	{
 		Assert(pending->action);
 		if (pending->atCommit || !(pending->action->flags & PENDING_REL_DELETE_NEED_SYNC))
-			(void) hash_search(pendingSyncHash, (void *) &pending->relnode,
-=======
-		if (pending->atCommit)
 			(void) hash_search(pendingSyncHash, &pending->rlocator,
->>>>>>> REL_16_9
 							   HASH_REMOVE, NULL);
 	}
 	hash_seq_init(&scan, pendingSyncHash);
@@ -932,11 +798,7 @@ smgrDoPendingSyncs(bool isCommit, bool isParallelWorker)
 		uint64		total_blocks = 0;
 		SMgrRelation srel;
 
-<<<<<<< HEAD
-		srel = smgropen(pendingsync->rnode, InvalidBackendId, SMGR_MD, NULL);
-=======
-		srel = smgropen(pendingsync->rlocator, InvalidBackendId);
->>>>>>> REL_16_9
+		srel = smgropen(pendingsync->rlocator, InvalidBackendId, SMGR_MD, NULL);
 
 		/*
 		 * We emit newpage WAL records for smaller relations.
@@ -1051,19 +913,11 @@ smgrDoPendingSyncs(bool isCommit, bool isParallelWorker)
  * dropped at the end of COMMIT phase.
  */
 int
-<<<<<<< HEAD
 smgrGetPendingDeletes(bool forCommit, RelFileNodePendingDelete **ptr)
 {
 	int			nestLevel = GetCurrentTransactionNestLevel();
 	int			nrels;
 	RelFileNodePendingDelete *rptr;
-=======
-smgrGetPendingDeletes(bool forCommit, RelFileLocator **ptr)
-{
-	int			nestLevel = GetCurrentTransactionNestLevel();
-	int			nrels;
-	RelFileLocator *rptr;
->>>>>>> REL_16_9
 	PendingRelDelete *pending;
 
 	nrels = 0;
@@ -1090,11 +944,7 @@ smgrGetPendingDeletes(bool forCommit, RelFileLocator **ptr)
 		*ptr = NULL;
 		return 0;
 	}
-<<<<<<< HEAD
 	rptr = (RelFileNodePendingDelete *) palloc(nrels * sizeof(RelFileNodePendingDelete));
-=======
-	rptr = (RelFileLocator *) palloc(nrels * sizeof(RelFileLocator));
->>>>>>> REL_16_9
 	*ptr = rptr;
 	for (pending = pendingDeletes; pending != NULL; pending = pending->next)
 	{
@@ -1203,11 +1053,7 @@ smgr_redo(XLogReaderState *record)
 		xl_smgr_create *xlrec = (xl_smgr_create *) XLogRecGetData(record);
 		SMgrRelation reln;
 
-<<<<<<< HEAD
-		reln = smgropen(xlrec->rnode, InvalidBackendId, xlrec->impl, NULL);
-=======
-		reln = smgropen(xlrec->rlocator, InvalidBackendId);
->>>>>>> REL_16_9
+		reln = smgropen(xlrec->rlocator, InvalidBackendId, xlrec->impl, NULL);
 		smgrcreate(reln, xlrec->forkNum, true);
 	}
 	else if (info == XLOG_SMGR_TRUNCATE)
@@ -1221,16 +1067,12 @@ smgr_redo(XLogReaderState *record)
 		int			nforks = 0;
 		bool		need_fsm_vacuum = false;
 
-<<<<<<< HEAD
 		/*
 		 * AO-specific implementation of SMGR is not needed because truncate
 		 * for AO takes a different code path, it does not involve emitting
 		 * SMGR_TRUNCATE WAL record.
 		 */
-		reln = smgropen(xlrec->rnode, InvalidBackendId, SMGR_MD, NULL);
-=======
-		reln = smgropen(xlrec->rlocator, InvalidBackendId);
->>>>>>> REL_16_9
+		reln = smgropen(xlrec->rlocator, InvalidBackendId, SMGR_MD, NULL);
 
 		/*
 		 * Forcibly create relation if it doesn't exist (which suggests that
diff --git a/src/include/catalog/storage.h b/src/include/catalog/storage.h
index 56358dcf512..a921ab22e45 100644
--- a/src/include/catalog/storage.h
+++ b/src/include/catalog/storage.h
@@ -46,8 +46,9 @@ typedef struct PendingRelDelete
 {
 	struct PendingRelDeleteAction *action;	/* The action is to do pending
 											 * delete */
-	RelFileNodePendingDelete relnode;	/* relation that may need to be
+	RelFileNodePendingDelete rlocator;	/* relation that may need to be
 										 * deleted */
+	BackendId	backend;                /* InvalidBackendId if not a temp rel */
 	bool		atCommit;		/* T=delete at commit; F=delete at abort */
 	int			nestLevel;		/* xact nesting level of request */
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org