Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Tableau run queries on Redshift? (And/or why can't Redshift display Tableau queries?)

I'm kicking tires on BI tools, including, of course, Tableau. Part of my evaluation includes correlating the SQL generated by the BI tool with my actions in the tool.

Tableau has me mystified. My database has 2 billion things; however, no matter what I do in Tableau, the query Redshift reports as having been run is "Fetch 10000 in SQL_CURxyz", i.e. a cursor operation. In the screenshot below, you can see the cursor ids change, indicating new queries are being run -- but you don't see the original queries.

Is this a Redshift or Tableau quirk? Any idea how to see what's actually running under the hood? And why is Tableau always operating on 10000 records at a time?

Redshift console

like image 950
user717847 Avatar asked Jul 15 '14 18:07

user717847


2 Answers

I just ran into the same problem and wrote this simple query to get all queries for currently active cursors:

SELECT
    usr.usename                                     AS username
  , min(cur.starttime)                              AS start_time
  , DATEDIFF(second, min(cur.starttime), getdate()) AS run_time
  , min(cur.row_count)                           AS row_count
  , min(cur.fetched_rows)                           AS fetched_rows
  , listagg(util_text.text)
    WITHIN GROUP (ORDER BY sequence)                AS query
FROM STV_ACTIVE_CURSORS cur
  JOIN stl_utilitytext util_text
    ON cur.pid = util_text.pid AND cur.xid = util_text.xid
  JOIN pg_user usr
    ON usr.usesysid = cur.userid
GROUP BY usr.usename, util_text.xid;
like image 127
Jan Zeiseweis Avatar answered Sep 28 '22 04:09

Jan Zeiseweis


Ah, this has already been asked on the AWS forums.

https://forums.aws.amazon.com/thread.jspa?threadID=152473

Redshift's console apparently doesn't display the query behind cursors. To get that, you can query STV_ACTIVE_CURSORS: http://docs.aws.amazon.com/redshift/latest/dg/r_STV_ACTIVE_CURSORS.html

like image 23
user717847 Avatar answered Sep 28 '22 04:09

user717847