Thread: Getting list of tables used within a query

Getting list of tables used within a query

From
Marek Lewczuk
Date:
Hi,
for need of our application we need to get list of tables, that are
used within given SELECT query - we need them in order to track
changes of the data, that may be returned by the query - it is some
kind of caching mechanism, that checks db data modifications. Right
now we create a temporary view and after that we use
information_schema.view_table_usage - it works fine, but it has two
disadvantages - firstly is quite slow and secondly only owner of the
tables can do that, which means that application must use two types of
connections, one for normal operations and second for getting list of
tables. Is there any other way to achieve that without need of using
owner role and without creating a view ? Browsing the PG source I see
that include/parser/.. can be used, but its quite complicated
(especially for me as I'm not to good in C programming) - maybe anyone
has some examples how to use parser to achieve my goals or maybe
someone already has got working code that does similar things ?

Best wishes,
ML

Re: Getting list of tables used within a query

From
Pavel Stehule
Date:
Hello

you need analyze execution plan - parser does know nothing about table order.

look on EXPLAIN statement

regards
Pavel Stehule