Re: query multiple schemas

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: query multiple schemas
Дата
Msg-id 2857958.1713733916@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: query multiple schemas  (Steve Baldwin <steve.baldwin@gmail.com>)
Ответы Re: query multiple schemas
Список pgsql-general
Steve Baldwin <steve.baldwin@gmail.com> writes:
> If the number of tenant schemas is reasonably static, you could write a
> plpgsql function to create a set of UNION ALL views with one view for each
> table in all tenant schemas. You could re-run the function each time a
> tenant schema is added. Having the set of views would allow you to query
> them as you would any of the underlying tables, and the query planner could
> likely optimise the query better. With your current function, if you needed
> to add a WHERE clause and the underlying tables were large, it would likely
> not perform as well as the UNION ALL view.

Another idea is to build a partitioned table comprising all the
individual tables.  This might require the tables to have all the
same owner (not sure about that) and it'd require you to store the
partition key, ie tenant, explicitly in every table which might
seem a bit wasteful.  But it'll likely outperform any other solution
for the union queries.  Notably, adding or deleting a partition would
be much less painful than redefining a UNION ALL view.

            regards, tom lane



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

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: error in trigger creation
Следующее
От: Tom Lane
Дата:
Сообщение: Re: error in trigger creation