Query to get total rows in a table in faster way.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kveerareddy
    New Member
    • Nov 2008
    • 4

    Query to get total rows in a table in faster way.

    How can i get the total rows of a table:

    If i use "select count(*) from <tablename>" it will take lot of time to get the total row count.

    for example in MSSQL we have "SELECT ROWS FROM sysindexes WHERE id = OBJECT_ID(<Tabl e name>) AND indid < 2"

    I am looking some system index tables which hold the total rows as a statistic values of the table so that i can query that table to get the total rows faster.

    My search observations:
    I refered this URL: PostgreSQL: Documentation: Manuals: PostgreSQL 8.3: The Statistics Collector

    we have "pg_stat_all_ta bles" it says that this table holds the number of rows information. But when i actually opened that table in the PGAdmin and looked into the columns of that table i did not find any of the columns to hold the Total rows.

    I also found that if we select a table in PGAdmin we get the properties in the right side pane, in that we have "rows (counted)" value. But i dont knwo how to retrieve that properties values.

    Can any one help me in getting the total rows of the table.

    Thanks
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    you can look into a table pg_class. There is a colum name reltuples wich stores total number of rows for each table in a database. But to be sure the number is correct you should first vacuum the table wich total number of rows you want to know. Column reltuples doesn't change dynamically, if i am right.

    Comment

    • dilipkakadiya
      New Member
      • Oct 2011
      • 9

      #3
      hope this help

      Comment

      Working...