mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Use list_copy_head() instead of list_truncate(list_copy(...), ...)
Truncating off the end of a freshly copied List is not a very efficient
way of copying the first N elements of a List.
In many of the cases that are updated here, the pattern was only being
used to remove the final element of a List.  That's about the best case
for it, but there were many instances where the truncate trimming the List
down much further.
4cc832f94 added list_copy_head(), so let's use it in cases where it's
useful.
Author: David Rowley
Discussion: https://postgr.es/m/1986787.1657666922%40sss.pgh.pa.us
			
			
This commit is contained in:
		@@ -145,8 +145,7 @@ owningrel_does_not_exist_skipping(List *object, const char **msg, char **name)
 | 
			
		||||
	List	   *parent_object;
 | 
			
		||||
	RangeVar   *parent_rel;
 | 
			
		||||
 | 
			
		||||
	parent_object = list_truncate(list_copy(object),
 | 
			
		||||
								  list_length(object) - 1);
 | 
			
		||||
	parent_object = list_copy_head(object, list_length(object) - 1);
 | 
			
		||||
 | 
			
		||||
	if (schema_does_not_exist_skipping(parent_object, msg, name))
 | 
			
		||||
		return true;
 | 
			
		||||
@@ -419,8 +418,8 @@ does_not_exist_skipping(ObjectType objtype, Node *object)
 | 
			
		||||
			{
 | 
			
		||||
				msg = gettext_noop("trigger \"%s\" for relation \"%s\" does not exist, skipping");
 | 
			
		||||
				name = strVal(llast(castNode(List, object)));
 | 
			
		||||
				args = NameListToString(list_truncate(list_copy(castNode(List, object)),
 | 
			
		||||
													  list_length(castNode(List, object)) - 1));
 | 
			
		||||
				args = NameListToString(list_copy_head(castNode(List, object),
 | 
			
		||||
													   list_length(castNode(List, object)) - 1));
 | 
			
		||||
			}
 | 
			
		||||
			break;
 | 
			
		||||
		case OBJECT_POLICY:
 | 
			
		||||
@@ -428,8 +427,8 @@ does_not_exist_skipping(ObjectType objtype, Node *object)
 | 
			
		||||
			{
 | 
			
		||||
				msg = gettext_noop("policy \"%s\" for relation \"%s\" does not exist, skipping");
 | 
			
		||||
				name = strVal(llast(castNode(List, object)));
 | 
			
		||||
				args = NameListToString(list_truncate(list_copy(castNode(List, object)),
 | 
			
		||||
													  list_length(castNode(List, object)) - 1));
 | 
			
		||||
				args = NameListToString(list_copy_head(castNode(List, object),
 | 
			
		||||
													   list_length(castNode(List, object)) - 1));
 | 
			
		||||
			}
 | 
			
		||||
			break;
 | 
			
		||||
		case OBJECT_EVENT_TRIGGER:
 | 
			
		||||
@@ -441,8 +440,8 @@ does_not_exist_skipping(ObjectType objtype, Node *object)
 | 
			
		||||
			{
 | 
			
		||||
				msg = gettext_noop("rule \"%s\" for relation \"%s\" does not exist, skipping");
 | 
			
		||||
				name = strVal(llast(castNode(List, object)));
 | 
			
		||||
				args = NameListToString(list_truncate(list_copy(castNode(List, object)),
 | 
			
		||||
													  list_length(castNode(List, object)) - 1));
 | 
			
		||||
				args = NameListToString(list_copy_head(castNode(List, object),
 | 
			
		||||
													   list_length(castNode(List, object)) - 1));
 | 
			
		||||
			}
 | 
			
		||||
			break;
 | 
			
		||||
		case OBJECT_FDW:
 | 
			
		||||
 
 | 
			
		||||
@@ -1620,7 +1620,7 @@ process_owned_by(Relation seqrel, List *owned_by, bool for_identity)
 | 
			
		||||
		RangeVar   *rel;
 | 
			
		||||
 | 
			
		||||
		/* Separate relname and attr name */
 | 
			
		||||
		relname = list_truncate(list_copy(owned_by), nnames - 1);
 | 
			
		||||
		relname = list_copy_head(owned_by, nnames - 1);
 | 
			
		||||
		attrname = strVal(llast(owned_by));
 | 
			
		||||
 | 
			
		||||
		/* Open and lock rel to ensure it won't go away meanwhile */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user