Re: pg_restore depending on user functions

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: pg_restore depending on user functions
Дата
Msg-id 3317884.1637439947@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: pg_restore depending on user functions  (Дмитрий Иванов <firstdismay@gmail.com>)
Ответы Re: pg_restore depending on user functions  (Дмитрий Иванов <firstdismay@gmail.com>)
Список pgsql-bugs
=?UTF-8?B?0JTQvNC40YLRgNC40Lkg0JjQstCw0L3QvtCy?= <firstdismay@gmail.com> writes:
> I hope this helps you.

Okay, that's better.

The problem seems to be that the view using the cast is itself depended
on (indirectly through another view) by another function a_ext_by_id(),
which is using the intermediate view's rowtype as its output type.
So that causes the dependency sort to hoist those two views above the
function a_ext_by_id(), and now they're ahead of the cast, which is
just left at its initial priority-driven location.

I think we can fix this by adjusting the sort priority order as per
the attached patch.  This fixes this toy test case anyway.  Can you
check to see if it fixes your real database?

(Note that as given, the patch will only apply to v14 not earlier
branches.)

            regards, tom lane

diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c
index 410d1790ee..5399ec1cd9 100644
--- a/src/bin/pg_dump/pg_dump_sort.c
+++ b/src/bin/pg_dump/pg_dump_sort.c
@@ -34,6 +34,15 @@
  * restore state).  If you think to change this, see also the RestorePass
  * mechanism in pg_backup_archiver.c.
  *
+ * On the other hand, casts are intentionally sorted earlier than you might
+ * expect; logically they should come after functions, since they usually
+ * depend on those.  This works around the backend's habit of recording
+ * views that use casts as dependent on the cast's underlying function.
+ * We initially sort casts first, and then any functions used by casts
+ * will be hoisted above the casts, and in turn views that those functions
+ * depend on will be hoisted above the functions.  But views not used that
+ * way won't be hoisted.
+ *
  * NOTE: object-type priorities must match the section assignments made in
  * pg_dump.c; that is, PRE_DATA objects must sort before DO_PRE_DATA_BOUNDARY,
  * POST_DATA objects must sort after DO_POST_DATA_BOUNDARY, and DATA objects
@@ -49,12 +58,12 @@ enum dbObjectTypePriorities
     PRIO_TRANSFORM,
     PRIO_EXTENSION,
     PRIO_TYPE,                    /* used for DO_TYPE and DO_SHELL_TYPE */
+    PRIO_CAST,
     PRIO_FUNC,
     PRIO_AGG,
     PRIO_ACCESS_METHOD,
     PRIO_OPERATOR,
     PRIO_OPFAMILY,                /* used for DO_OPFAMILY and DO_OPCLASS */
-    PRIO_CAST,
     PRIO_CONVERSION,
     PRIO_TSPARSER,
     PRIO_TSTEMPLATE,

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: BUG #17294: spgist doesn't support varchar, only text type fields.
Следующее
От: Juan José Santamaría Flecha
Дата:
Сообщение: Re: BUG #17288: PSQL bug with COPY command (Windows)