Re: BUG #4812: statistics not available on tables containing only hstore column - Mailing list pgsql-bugs

From Heikki Linnakangas
Subject Re: BUG #4812: statistics not available on tables containing only hstore column
Date
Msg-id 4A114AA1.2020300@enterprisedb.com
Whole thread Raw
In response to BUG #4812: statistics not available on tables containing only hstore column  ("George Su" <george.su@efrontier.com>)
Responses Re: BUG #4812: statistics not available on tables containing only hstore column  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
George Su wrote:
> If I create a table containing only hstore columns, then no statistics on
> row count and page count is available even after analyzing.

(As a work-around, running VACUUM on the table will update those stats.)

Hmm, we intentionally skip analyze on tables that have no analyzable
columns, but ISTM as well that relpages and reltuples in pg_class should
still be updated. We have this in analyze.c:

    /*
     * Quit if no analyzable columns
     */
    if (attr_cnt <= 0 && !analyzableindex)
    {
        /*
         * We report that the table is empty; this is just so that the
         * autovacuum code doesn't go nuts trying to get stats about a
         * zero-column table.
         */
        if (update_reltuples)
            pgstat_report_analyze(onerel, 0, 0);
        goto cleanup;
    }

ISTM we should not skip the analyze if run as a stand-alone ANALYZE. I'm
not sure what problem the author of that comment envisioned with
autovacuum, but resetting the live and dead tuple counters doesn't seem
right to me. In the worst case, autovacuum launches auto-analyze on the
table whenever there has been enough update/delete activity, and you
never reach the auto*vacuum* threshold because the dead tuple counter is
always cleared.

Does anyone see a problem with the attached patch, changing the code
above so that in a stand-alone ANALYZE (including auto-analyze), the
table is analyzed to update relpages and reltuples even if there's no
analyzable columns?

--
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com
Index: src/backend/commands/analyze.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/commands/analyze.c,v
retrieving revision 1.136
diff -c -r1.136 analyze.c
*** src/backend/commands/analyze.c    5 May 2009 18:02:11 -0000    1.136
--- src/backend/commands/analyze.c    18 May 2009 11:43:05 -0000
***************
*** 363,381 ****
      }

      /*
!      * Quit if no analyzable columns
       */
!     if (attr_cnt <= 0 && !analyzableindex)
!     {
!         /*
!          * We report that the table is empty; this is just so that the
!          * autovacuum code doesn't go nuts trying to get stats about a
!          * zero-column table.
!          */
!         if (update_reltuples)
!             pgstat_report_analyze(onerel, 0, 0);
          goto cleanup;
-     }

      /*
       * Determine how many rows we need to sample, using the worst case from
--- 363,372 ----
      }

      /*
!      * Quit if no analyzable columns and no pg_class update needed.
       */
!     if (attr_cnt <= 0 && !analyzableindex && !update_reltuples)
          goto cleanup;

      /*
       * Determine how many rows we need to sample, using the worst case from

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #4814: Segmentation fault when using indexed prefix FT search
Next
From: Tom Lane
Date:
Subject: Re: BUG #4812: statistics not available on tables containing only hstore column