Looker Over Complex Queries

Hi, I'm having an issue right now in looker where I have an explore based on one table let's just call it "amount". Then I have another explore that I join the "amount" table to which we can call "accounts". If I use the amount measure from the amount table, looker generates a simple query like -> 

COALESCE(SUM(( "amount" ) ), 0) AS "Amount"

However in the second "accounts" explore, when I join the "amount" table in and attempt to use the same measure, Looker generates a very complex query to achieve the same effect ->

COALESCE(CAST( ( SUM(DISTINCT (CAST(FLOOR(COALESCE( ( amount ) ,0)*(1000000*1.0)) AS DECIMAL(38,0))) + (TO_NUMBER(MD5( concat((amount."H"),'9',(amount."HP"),'9',(amount."IB"),'9',(TO_CHAR(TO_DATE(amount."U" ), 'YYYY-MM-DD'))) ), 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') % 1.0e27)::NUMERIC(38, 0) ) - SUM(DISTINCT (TO_NUMBER(MD5( concat((amount."H"),'9',(amount."HP"),'9',(amount."IB"),'9',(TO_CHAR(TO_DATE(amount."U" ), 'YYYY-MM-DD'))) ), 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') % 1.0e27)::NUMERIC(38, 0)) ) AS DOUBLE PRECISION) / CAST((1000000*1.0) AS DOUBLE PRECISION), 0) AS "Amount"

No matter how I change the join to the explore or other joins in the explore, Looker produces this query which essentially changes the run time from 5 seconds to longer than 5 minutes. I haven't actually been able to get it to run successfully. 

Using SQL Runner and subbing in the original simpler query in place, I'm able to get a result instantly. Has anyone else deal with this kind of issue /  how were you able to resolve it?

The measure type is sum and not sum_distinct just for reference. 

0 3 1,428
3 REPLIES 3
Top Labels in this Space
Top Solution Authors