Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5b5ed47

Browse files
committed
Ensure pg_dump_sort.c sorts null vs non-null namespace consistently.
The original coding here (which is, I believe, my fault) supposed thatit didn't need to concern itself with the possibility that one objectof a given type-priority has a namespace while another doesn't. Butthat's not reliably true anymore, if it ever was; and if it does happenthen it's possible that DOTypeNameCompare returns self-inconsistentcomparison results. That leads to unspecified behavior in qsort()and a resultant weird output order from pg_dump.This should end up being only a cosmetic problem, because any orderingconstraints that actually matter should be enforced by the laterdependency-based sort. Still, it's a bug, so back-patch.Report and fix by Jacob Champion, though I editorialized on hispatch to the extent of making NULL sort after non-NULL, for consistencywith our usual sorting definitions.Discussion:https://postgr.es/m/CABAq_6Hw+V-Kj7PNfD5tgOaWT_-qaYkc+SRmJkPLeUjYXLdxwQ@mail.gmail.com
1 parente0ee930 commit5b5ed47

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

‎src/bin/pg_dump/pg_dump_sort.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,25 +223,32 @@ DOTypeNameCompare(const void *p1, const void *p2)
223223
DumpableObject*obj2=*(DumpableObject*const*)p2;
224224
intcmpval;
225225

226-
/* Sort by type */
226+
/* Sort by type's priority */
227227
cmpval=dbObjectTypePriority[obj1->objType]-
228228
dbObjectTypePriority[obj2->objType];
229229

230230
if (cmpval!=0)
231231
returncmpval;
232232

233233
/*
234-
* Sort by namespace.Note thatall objects of the sametype should
235-
* either have or not have a namespace link,so we needn't be fancy about
236-
*cases where one link is null and the other not.
234+
* Sort by namespace.Typically,all objects of the samepriority would
235+
* either have or not have a namespace link,but there are exceptions.
236+
*Sort NULL namespace after non-NULL in such cases.
237237
*/
238-
if (obj1->namespace&&obj2->namespace)
238+
if (obj1->namespace)
239239
{
240-
cmpval=strcmp(obj1->namespace->dobj.name,
241-
obj2->namespace->dobj.name);
242-
if (cmpval!=0)
243-
returncmpval;
240+
if (obj2->namespace)
241+
{
242+
cmpval=strcmp(obj1->namespace->dobj.name,
243+
obj2->namespace->dobj.name);
244+
if (cmpval!=0)
245+
returncmpval;
246+
}
247+
else
248+
return-1;
244249
}
250+
elseif (obj2->namespace)
251+
return1;
245252

246253
/* Sort by name */
247254
cmpval=strcmp(obj1->name,obj2->name);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp