mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Stabilize pg_dump output order for similarly-named triggers and policies.
The code only compared two triggers' names and namespaces (the latter being the owning table's schema). This could result in falling back to an OID-based sort of similarly-named triggers on different tables. We prefer to avoid that, so add a comparison of the table names too. (The sort order is thus table namespace, trigger name, table name, which is a bit odd, but it doesn't seem worth contorting the code to work around that.) Likewise for policy objects, in 9.5 and up. Complaint and fix by Benjie Gillam. Back-patch to all supported branches. Discussion: https://postgr.es/m/CAMThMzEEt2mvBbPgCaZ1Ap1N-moGn=Edxmadddjq89WG4NpPtQ@mail.gmail.com
This commit is contained in:
		@@ -257,6 +257,7 @@ DOTypeNameCompare(const void *p1, const void *p2)
 | 
			
		||||
		FuncInfo   *fobj2 = *(FuncInfo *const *) p2;
 | 
			
		||||
		int			i;
 | 
			
		||||
 | 
			
		||||
		/* Sort by number of arguments, then argument type names */
 | 
			
		||||
		cmpval = fobj1->nargs - fobj2->nargs;
 | 
			
		||||
		if (cmpval != 0)
 | 
			
		||||
			return cmpval;
 | 
			
		||||
@@ -295,10 +296,33 @@ DOTypeNameCompare(const void *p1, const void *p2)
 | 
			
		||||
		AttrDefInfo *adobj1 = *(AttrDefInfo *const *) p1;
 | 
			
		||||
		AttrDefInfo *adobj2 = *(AttrDefInfo *const *) p2;
 | 
			
		||||
 | 
			
		||||
		/* Sort by attribute number */
 | 
			
		||||
		cmpval = (adobj1->adnum - adobj2->adnum);
 | 
			
		||||
		if (cmpval != 0)
 | 
			
		||||
			return cmpval;
 | 
			
		||||
	}
 | 
			
		||||
	else if (obj1->objType == DO_POLICY)
 | 
			
		||||
	{
 | 
			
		||||
		PolicyInfo *pobj1 = *(PolicyInfo *const *) p1;
 | 
			
		||||
		PolicyInfo *pobj2 = *(PolicyInfo *const *) p2;
 | 
			
		||||
 | 
			
		||||
		/* Sort by table name (table namespace was considered already) */
 | 
			
		||||
		cmpval = strcmp(pobj1->poltable->dobj.name,
 | 
			
		||||
						pobj2->poltable->dobj.name);
 | 
			
		||||
		if (cmpval != 0)
 | 
			
		||||
			return cmpval;
 | 
			
		||||
	}
 | 
			
		||||
	else if (obj1->objType == DO_TRIGGER)
 | 
			
		||||
	{
 | 
			
		||||
		TriggerInfo *tobj1 = *(TriggerInfo *const *) p1;
 | 
			
		||||
		TriggerInfo *tobj2 = *(TriggerInfo *const *) p2;
 | 
			
		||||
 | 
			
		||||
		/* Sort by table name (table namespace was considered already) */
 | 
			
		||||
		cmpval = strcmp(tobj1->tgtable->dobj.name,
 | 
			
		||||
						tobj2->tgtable->dobj.name);
 | 
			
		||||
		if (cmpval != 0)
 | 
			
		||||
			return cmpval;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* Usually shouldn't get here, but if we do, sort by OID */
 | 
			
		||||
	return oidcmp(obj1->catId.oid, obj2->catId.oid);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user