<p dir="auto">this is standart superset time series bar chart:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/36520921/136579194-d97d2bbd-a971-44d9-bc02-fc982276b61b.png"><img src="https://user-images.githubusercontent.com/36520921/136579194-d97d2bbd-a971-44d9-bc02-fc982276b61b.png" alt="vivaldi_0MqYMCNKc7" style="max-width: 100%;"></a></p>
<p dir="auto">query:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="SELECT DATE(order_date, -strftime('%d', order_date) || ' days', '+1 day') AS __timestamp,
       deal_size AS deal_size,
       sum(sales) AS &quot;(Sales)&quot;
FROM &quot;Vehicle Sales&quot;
JOIN
  (SELECT deal_size AS deal_size__,
          sum(sales) AS mme_inner__
   FROM &quot;Vehicle Sales&quot;
   WHERE order_date &gt;= '2003-01-01 00:00:00.000000'
     AND order_date &lt; '2005-06-01 00:00:00.000000'
   GROUP BY deal_size
   ORDER BY mme_inner__ DESC
   LIMIT 100
   OFFSET 0) AS anon_1 ON deal_size = deal_size__
WHERE order_date &gt;= '2003-01-01 00:00:00.000000'
  AND order_date &lt; '2005-06-01 00:00:00.000000'
GROUP BY deal_size,
         DATE(order_date, -strftime('%d', order_date) || ' days', '+1 day')
ORDER BY &quot;(Sales)&quot; DESC
LIMIT 50000
OFFSET 0;"><pre class="notranslate"><code class="notranslate">SELECT DATE(order_date, -strftime('%d', order_date) || ' days', '+1 day') AS __timestamp,
       deal_size AS deal_size,
       sum(sales) AS "(Sales)"
FROM "Vehicle Sales"
JOIN
  (SELECT deal_size AS deal_size__,
          sum(sales) AS mme_inner__
   FROM "Vehicle Sales"
   WHERE order_date &gt;= '2003-01-01 00:00:00.000000'
     AND order_date &lt; '2005-06-01 00:00:00.000000'
   GROUP BY deal_size
   ORDER BY mme_inner__ DESC
   LIMIT 100
   OFFSET 0) AS anon_1 ON deal_size = deal_size__
WHERE order_date &gt;= '2003-01-01 00:00:00.000000'
  AND order_date &lt; '2005-06-01 00:00:00.000000'
GROUP BY deal_size,
         DATE(order_date, -strftime('%d', order_date) || ' days', '+1 day')
ORDER BY "(Sales)" DESC
LIMIT 50000
OFFSET 0;
</code></pre></div>
<p dir="auto">request that should have been:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="SELECT DATE(order_date, -strftime('%d', order_date) || ' days', '+1 day') AS __timestamp,
       deal_size AS deal_size,
       sum(sales) AS &quot;(Sales)&quot;
FROM &quot;Vehicle Sales&quot;
WHERE order_date &gt;= '2003-01-01 00:00:00.000000'
  AND order_date &lt; '2005-06-01 00:00:00.000000'
GROUP BY deal_size,
         DATE(order_date, -strftime('%d', order_date) || ' days', '+1 day')
ORDER BY &quot;(Sales)&quot; DESC
LIMIT 50000
OFFSET 0;"><pre class="notranslate"><code class="notranslate">SELECT DATE(order_date, -strftime('%d', order_date) || ' days', '+1 day') AS __timestamp,
       deal_size AS deal_size,
       sum(sales) AS "(Sales)"
FROM "Vehicle Sales"
WHERE order_date &gt;= '2003-01-01 00:00:00.000000'
  AND order_date &lt; '2005-06-01 00:00:00.000000'
GROUP BY deal_size,
         DATE(order_date, -strftime('%d', order_date) || ' days', '+1 day')
ORDER BY "(Sales)" DESC
LIMIT 50000
OFFSET 0;
</code></pre></div>
<p dir="auto">why does superset add this request?</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="JOIN
  (SELECT deal_size AS deal_size__,
          sum(sales) AS mme_inner__
   FROM &quot;Vehicle Sales&quot;
   WHERE order_date &gt;= '2003-01-01 00:00:00.000000'
     AND order_date &lt; '2005-06-01 00:00:00.000000'
   GROUP BY deal_size
   ORDER BY mme_inner__ DESC
   LIMIT 100
   OFFSET 0) AS anon_1 ON deal_size = deal_size__
"><pre class="notranslate"><code class="notranslate">JOIN
  (SELECT deal_size AS deal_size__,
          sum(sales) AS mme_inner__
   FROM "Vehicle Sales"
   WHERE order_date &gt;= '2003-01-01 00:00:00.000000'
     AND order_date &lt; '2005-06-01 00:00:00.000000'
   GROUP BY deal_size
   ORDER BY mme_inner__ DESC
   LIMIT 100
   OFFSET 0) AS anon_1 ON deal_size = deal_size__

</code></pre></div>
<p dir="auto">This JOIN increases the data loading time<br>
Old superset works fine</p>
<p dir="auto">First of all I have setup Superset with the current docker image (<a href="https://superset.apache.org/docs/installation/installing-superset-using-docker-compose" rel="nofollow">https://superset.apache.org/docs/installation/installing-superset-using-docker-compose</a>) on an AWS EC2 instance. I've also installed superset on my local laptop (<a href="https://hub.docker.com/r/apache/superset" rel="nofollow">https://hub.docker.com/r/apache/superset</a>) but had the same thing.</p>
<p dir="auto">After registering the AWS Athena driver and an dataset, I have created a simple time series diagram with a "group by". The query is working and data is visualized. Please see screenshot.</p>
<p dir="auto">When I look at the sql query executed by Athena you can see this: --&gt; ### Actual results</p>
<p dir="auto">There is a subquery included in the query which seems to be useless. The columns of the subquery are not used in the outer query. The join is useless.</p>
<p dir="auto">The disadvantage is, that the query takes much more time with this subquery - x*100% in comparision to the expected query.</p>
<h4 dir="auto">How to reproduce the bug</h4>
<p dir="auto">create a timeseries chart and group by an attribute.</p>
<h3 dir="auto">Expected results</h3>
<p dir="auto">SELECT date_trunc('day', CAST(date_parse(p_date, '%Y-%m-%d') AS TIMESTAMP)) AS "__timestamp",<br>
"c_jobid" AS "c_jobid",<br>
COUNT(*) AS "count"<br>
FROM "x"."y"<br>
WHERE "p_date" &gt;= '2021-10-01'<br>
GROUP BY "c_jobid",<br>
date_trunc('day', CAST(date_parse(p_date, '%Y-%m-%d') AS TIMESTAMP))<br>
ORDER BY "count" DESC<br>
LIMIT 1000</p>
<h3 dir="auto">Actual results</h3>
<p dir="auto">SELECT date_trunc('day', CAST(date_parse(p_date, '%Y-%m-%d') AS TIMESTAMP)) AS "<strong>timestamp",<br>
"c_jobid" AS "c_jobid",<br>
COUNT(*) AS "count"<br>
FROM "x"."y"<br>
JOIN<br>
(SELECT "c_jobid" AS "c_jobid</strong>",<br>
COUNT(*) AS "mme_inner__"<br>
FROM "vehicle_cdc2_cca_qual_pre"."te_mgu"<br>
WHERE "p_date" &gt;= '2021-10-01'<br>
GROUP BY "c_jobid"<br>
ORDER BY "mme_inner__" DESC<br>
LIMIT 100) AS "anon_1" ON "c_jobid" = "c_jobid__"<br>
WHERE "p_date" &gt;= '2021-10-01'<br>
GROUP BY "c_jobid",<br>
date_trunc('day', CAST(date_parse(p_date, '%Y-%m-%d') AS TIMESTAMP))<br>
ORDER BY "count" DESC<br>
LIMIT 1000</p>
<h4 dir="auto">Screenshots</h4>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/68276432/136579420-abbe922f-363d-41d6-86b6-51294f930c55.png"><img width="820" alt="grafik" src="https://user-images.githubusercontent.com/68276432/136579420-abbe922f-363d-41d6-86b6-51294f930c55.png" style="max-width: 100%;"></a></p>
<h3 dir="auto">Environment</h3>
<p dir="auto">(please complete the following information):</p>
<ul dir="auto">
<li>browser type and version: Firefox 88.0</li>
<li>superset version: Superset 0.0.0dev</li>
<li>python version: Python 3.8.12</li>
<li>node.js version: ? (docker exec -it superset node -v --&gt; node not on path)</li>
<li>any feature flags active: no</li>
</ul>
<h3 dir="auto">Checklist</h3>
<p dir="auto">Make sure to follow these steps before submitting your issue - thank you!</p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the superset logs for python stacktraces and included it here as text if there are any.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have reproduced the issue with at least the latest released version of superset.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the issue tracker for the same issue and I haven't found one similar.</li>
</ul>
<h3 dir="auto">Additional context</h3>