title: select 10000 records take too long time in PostgreSQL
body: <p>my table contains 1 billion records. It is also partitioned by month.Id and datetime is the primary key for the table. When I select</p>
  <pre class="lang-sql prettyprint-override"><code>select col1,col2,..col8
  from mytable t 
  inner join cte on t.Id=cte.id and dtime&gt;'2020-01-01' and dtime&lt;'2020-10-01'
  </code></pre>
  <p>It uses index scan, but takes more than 5 minutes to select.
  Please suggest me.
  Note: I have set work_mem to 1GB. cte table results comes with in 3 seconds.</p>