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

Commit69949ea

Browse files
committed
Adjust pg_dump's priority ordering for casts.
When a stored expression depends on a user-defined cast, the backendrecords the dependency as being on the cast's implementation function--- or indeed, if there's no cast function involved but justRelabelType or CoerceViaIO, no dependency is recorded at all. Thisis problematic for pg_dump, which is at risk of dumping things in thewrong order leading to restore failures. Given the lack of previousreports, the risk isn't that high, but it can be demonstrated if thecast is used in some view whose rowtype is then used as an input orresult type for some other function. (That results in the viewgetting hoisted into the functions portion of the dump, ahead ofthe cast.)A logically bulletproof fix for this would require including thecast's OID in the parsed form of the expression, whence it could beextracted by dependency.c, and then the stored dependency would forcepg_dump to do the right thing. Such a change would be fairly invasive,and certainly not back-patchable. Moreover, since we'd prefer thatan expression using cast syntax be equal() to one doing the samething by explicit function call, the cast OID field would have tohave special ignored-by-comparisons semantics, making things messy.So, let's instead fix this by a very simple hack in pg_dump: changethe object-type priority order so that casts are initially sortedbefore functions, immediately after types. This fixes the problemin a fairly direct way for casts that have no implementation function.For those that do, the implementation function will be hoisted to justbefore the cast by the dependency sorting step, so that we still havea valid dump order. (I'm not sure that this provides a full guaranteeof no problems; but since it's been like this for many years withoutany previous reports, this is probably enough to fix it in practice.)Per report from Дмитрий Иванов.Back-patch to all supported branches.Discussion:https://postgr.es/m/CAPL5KHoGa3uvyKp6z6m48LwCnTsK+LRQ_mcA4uKGfqAVSEjV_A@mail.gmail.com
1 parent7258253 commit69949ea

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

‎src/bin/pg_dump/pg_dump_sort.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@
3535
* restore state). If you think to change this, see also the RestorePass
3636
* mechanism in pg_backup_archiver.c.
3737
*
38+
* On the other hand, casts are intentionally sorted earlier than you might
39+
* expect; logically they should come after functions, since they usually
40+
* depend on those. This works around the backend's habit of recording
41+
* views that use casts as dependent on the cast's underlying function.
42+
* We initially sort casts first, and then any functions used by casts
43+
* will be hoisted above the casts, and in turn views that those functions
44+
* depend on will be hoisted above the functions. But views not used that
45+
* way won't be hoisted.
46+
*
3847
* NOTE: object-type priorities must match the section assignments made in
3948
* pg_dump.c; that is, PRE_DATA objects must sort before DO_PRE_DATA_BOUNDARY,
4049
* POST_DATA objects must sort after DO_POST_DATA_BOUNDARY, and DATA objects
@@ -46,12 +55,12 @@ static const int dbObjectTypePriority[] =
4655
4,/* DO_EXTENSION */
4756
5,/* DO_TYPE */
4857
5,/* DO_SHELL_TYPE */
49-
6,/* DO_FUNC */
50-
7,/* DO_AGG */
51-
8,/* DO_OPERATOR */
52-
8,/* DO_ACCESS_METHOD */
53-
9,/* DO_OPCLASS */
54-
9,/* DO_OPFAMILY */
58+
7,/* DO_FUNC */
59+
8,/* DO_AGG */
60+
9,/* DO_OPERATOR */
61+
9,/* DO_ACCESS_METHOD */
62+
10,/* DO_OPCLASS */
63+
10,/* DO_OPFAMILY */
5564
3,/* DO_COLLATION */
5665
11,/* DO_CONVERSION */
5766
18,/* DO_TABLE */
@@ -64,7 +73,7 @@ static const int dbObjectTypePriority[] =
6473
27,/* DO_CONSTRAINT */
6574
33,/* DO_FK_CONSTRAINT */
6675
2,/* DO_PROCLANG */
67-
10,/* DO_CAST */
76+
6,/* DO_CAST */
6877
23,/* DO_TABLE_DATA */
6978
24,/* DO_SEQUENCE_SET */
7079
19,/* DO_DUMMY_TYPE */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp