Re: how to use query_tree_walker to get all relations used in a query

Поиск
Список
Период
Сортировка
От Julien Rouhaud
Тема Re: how to use query_tree_walker to get all relations used in a query
Дата
Msg-id 20230820025301.4sre5chx6jelc2ry@jrouhaud
обсуждение исходный текст
Ответ на how to use query_tree_walker to get all relations used in a query  (Pierre Forstmann <pierre.forstmann@gmail.com>)
Список pgsql-general
Hi,

On Sat, Aug 19, 2023 at 03:26:06PM +0200, Pierre Forstmann wrote:
>
> I am trying to get the list of all relations used in a SELECT query using
> the post parse analyze hook.
>
> I can get all relations from top level FROM clause but I cannot get them
> for a simple subquery like:
>
> select * from t1 where x1=(select max(x2) from t2);

You're missing at least the sublinks.  Since you're looking at
AcquireRewriteLocks() as an example, look at how acquireLocksOnSubLinks() is
being called.

In general, if you're not sure of how some constructs are represented in a
Query the easiest way to get a good overview is to simply do something like

static void pgds_build_rel_array(Query *query)
{
[...]
    elog(WARNING, "found %s", nodeToString(query));

You will get a textual representation of the query (or any specific node if
needed) in the client and server log, so you can easily look for a given relid,
Var or anything and identify what you were missing and adapt your walker
function.



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

Предыдущее
От: Justin Clift
Дата:
Сообщение: Re: PG minor version in data directory?
Следующее
От: Kristjan Mustkivi
Дата:
Сообщение: Logical Streaming Replication stuck at specific LSN