7 Replies Latest reply on Dec 20, 2017 9:28 AM by Gerardo Varela

    Why does custom SQL takes forever while the query itself only takes a minute to run

    Dian Jiao

      I have several data sources in my workbook that connects with a Postgres database in Amazon RDS. Each of them uses a custom SQL query to load data. While most of them work just fine, one of the queries takes literally forever to load. The query is essentially joining of few tables followed by a few groupbys.

      select [bunch of fields]
      from a
      inner join b on ..
      inner join c on ...
      inner join d on ...
      inner join e on ...
      inner join f on ...
      inner join g on ...
      group by [a bunch of fields]


      I ran the exactly same query in command line and it only takes less than 50 seconds to return ~40000 rows.


      Some of the columns are indexes for optimization already.


      I know custom SQL is slow, but it can't be this slow. I tried to load the data for this custom SQL overnight and the next morning the data is still not loaded but the connection is timed out. Tried to record the performance and it tells nothing rather than spending 36000 seconds "executing query".


      Why does it take such a long time to run this query in Tableau?