diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 6f1a429c7e..d238dd78da 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -164,6 +164,7 @@ typedef struct AlteredTableInfo
 	List	   *newvals;		/* List of NewColumnValue */
 	bool		new_notnull;	/* T if we added new NOT NULL constraints */
 	int			rewrite;		/* Reason for forced rewrite, if any */
+	bool		check_toast;	/* check for toast table */
 	Oid			newTableSpace;	/* new tablespace; 0 means no change */
 	bool		chgPersistence; /* T if SET LOGGED/UNLOGGED is used */
 	char		newrelpersistence;	/* if above is true */
@@ -3793,15 +3794,7 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode)
 	{
 		AlteredTableInfo *tab = (AlteredTableInfo *) lfirst(ltab);
 
-		/*
-		 * If the table is source table of ATTACH PARTITION command, we did
-		 * not modify anything about it that will change its toasting
-		 * requirement, so no need to check.
-		 */
-		if (((tab->relkind == RELKIND_RELATION ||
-			  tab->relkind == RELKIND_PARTITIONED_TABLE) &&
-			 tab->partition_constraint == NULL) ||
-			tab->relkind == RELKIND_MATVIEW)
+		if (tab->check_toast)
 			AlterTableCreateToastTable(tab->relid, (Datum) 0, lockmode);
 	}
 }
@@ -4653,6 +4646,15 @@ ATGetQueueEntry(List **wqueue, Relation rel)
 	tab->newrelpersistence = RELPERSISTENCE_PERMANENT;
 	tab->chgPersistence = false;
 
+	/* We don't check for toast table of mapped relations */
+	if ((tab->relkind == RELKIND_MATVIEW ||
+		 tab->relkind == RELKIND_RELATION ||
+		 tab->relkind == RELKIND_PARTITIONED_TABLE) &&
+		!RelationIsMapped(rel))
+		tab->check_toast = true;
+	else
+		tab->check_toast = false;
+
 	*wqueue = lappend(*wqueue, tab);
 
 	return tab;
@@ -13794,6 +13796,13 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
 			tab = ATGetQueueEntry(wqueue, part_rel);
 			tab->partition_constraint = (Expr *) linitial(my_partconstr);
 
+			/*
+			 * If the table is source table of ATTACH PARTITION command, we did
+			 * not modify anything about it that will change its toasting
+			 * requirement, so no need to check.
+			 */
+			tab->check_toast = false;
+
 			/* keep our lock until commit */
 			if (part_rel != attachrel)
 				heap_close(part_rel, NoLock);
