Bug? relpages, reltuples resets to zero - Mailing list pgsql-hackers

From jwieck@debis.com (Jan Wieck)
Subject Bug? relpages, reltuples resets to zero
Date
Msg-id m0zWQUJ-000EBPC@orion.SAPserv.Hamburg.dsh.de
Whole thread Raw
Responses Re: [HACKERS] Bug? relpages, reltuples resets to zero
Re: [HACKERS] Bug? relpages, reltuples resets to zero
pg_indexes
List pgsql-hackers
Hi,

    there  seems  to be a problem with the relation statistics in
    pg_class. Could someone explain why this happens?

        doc=> vacuum;
        VACUUM
        doc=> select relname, relpages, reltuples from pg_class
        doc-> where relname = 'doc_wordref';
        relname    |relpages|reltuples
        -----------+--------+---------
        doc_wordref|    1099|   136027
        (1 row)

        -- ******** That's right

        doc=> explain select distinct refpage from doc_wordref
        doc-> where refword ~ '^a';
        NOTICE:  QUERY PLAN:

        Unique
          ->  Sort
             ->  Index Scan using doc_wordref_word_idx on doc_wordref

        EXPLAIN

        -- ******** As expected

        doc=> select distinct refpage from doc_wordref
        doc-> where refword ~ '^a';
        refpage
        -------
              2
              3
        ...
        (164 rows)

        doc=> select relname, relpages, reltuples from pg_class
        doc-> where relname = 'doc_wordref';
        relname    |relpages|reltuples
        -----------+--------+---------
        doc_wordref|       0|        0
        (1 row)

        -- ******** Ooops - where are they gone?

        doc=> explain select distinct refpage from doc_wordref
        dos-> where refword ~ '^a';
        NOTICE:  QUERY PLAN:

        Unique
          ->  Sort
             ->  Index Scan using doc_wordref_word_idx on doc_wordref

        -- ******** Doesn't matter in the same connection, so reconnect

        EXPLAIN
        doc=> \c -
        connecting to new database: doc
        doc=> explain select distinct refpage from doc_wordref
        dos-> where refword ~ '^a';
        NOTICE:  QUERY PLAN:

        Unique
          ->  Sort
             ->  Seq Scan on doc_wordref

        -- ******** Boom

        EXPLAIN
        doc=>

    Why does the SELECT throw  away  the  information  about  the
    number  of pages and tuples from pg_class? Is this a bug or a
    feature?  If it's a feature, how can  I  disable  it?  It  is
    reproduceable.


Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#======================================== jwieck@debis.com (Jan Wieck) #

pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] Re: y2k
Next
From: darcy@druid.net (D'Arcy J.M. Cain)
Date:
Subject: Re: [HACKERS] Re: y2k