title: PostgreSQL default_statistics_target not improving row estimation
body: <p>I am trying to optimize our queries on Postgres which takes minutes sometimes using huge tables. Started looking at query plan and noticed close 1000x difference between estimated number of rows and actual rows on running with <code>EXPLAIN ANALYZE</code>.</p>
  <p>This lead me to the parameter <code>default_statistics_target</code> which controls the number rows sampled by <code>ANALYZE</code> command to collect stats used by query planner. As few blogs suggested, I experimented by increased value setting it to <code>1000</code> and event to max allowed value of <code>10000</code>.</p>
  <p>Ran <code>ANALYZE</code> every time to ensure it stats are updated. But surprisingly, this did not improve the rows estimation at all. In fact it reduced the estimated value a bit further which seems strange to understand.</p>
  <p>Also tested by reducing the value to <code>10</code>. Which seems to have improved the count a bit. So I am confused if the param actually does what I thought it does. Or if there is some other way to improve row estimation. Any help would be much appreciated.</p>
  <p><strong>Postgres version: 9.6</strong></p>
  <p><strong>Query plan</strong>: At the last index scan step, it has estimated 462 but actual is 1.9M.
  <a href="https://explain.depesz.com/s/GZY" rel="nofollow noreferrer">https://explain.depesz.com/s/GZY</a></p>
  <p>After changing <code>default_statistics_target = 1000</code>, rows at Index scan step were</p>
  <pre><code>-&gt;  (cost=0.57..120.42 rows=114 width=32) (actual time=248.999..157947.395 rows=1930518 loops=1)
  </code></pre>
  <p>And on setting it to <code>default_statistics_target = 10</code>, counts were:</p>
  <pre><code>-&gt;  (cost=0.57..2610.79 rows=2527 width=32) (actual time=390.437..62668.837 rows=1930518 loops=1)
  </code></pre>
  <p>P.S. Table under consideration has more than 100M rows.</p>