DEV Community

Michael
Michael

Posted on • Originally published at gbase.cn

Get Real Row Counts in GBase 8s Without UPDATE STATISTICS

The nrows column in systables is only updated when you run UPDATE STATISTICS, so it often shows 0 even right after bulk inserts. If you need the real, live row count — especially for fragmented tables — you can query sysmaster:sysptnhdr or use oncheck.

Non‑Fragmented Tables

Join systables.partnum with sysptnhdr.partnum in the sysmaster database. sysptnhdr.nrows gives the actual row count and npdata the number of used data pages.

SELECT t.tabname, t.partnum, t.nrows, p.nrows, p.npdata
FROM stores_demo@gbaseserver:systables t,
     sysmaster@gbaseserver:sysptnhdr p
WHERE t.partnum = p.partnum
  AND t.tabname = "customer";
Enter fullscreen mode Exit fullscreen mode

Fragmented Tables

Use sysfragments to get the partition number (partn) and join it with sysptnhdr.partnum to see per‑fragment row counts.

SELECT f.partn, p.nrows, p.npdata
FROM sysfragments f,
     sysmaster@gbaseserver:sysptnhdr p
WHERE f.partn = p.partnum
  AND f.tabname = "tab1";
Enter fullscreen mode Exit fullscreen mode

Quick Check with oncheck

The oncheck -pt command shows row and page counts for a table or fragment immediately, without any statistics update.

oncheck -pt stores_demo:tab1
Enter fullscreen mode Exit fullscreen mode

The output includes sections like Fragment ... Number of rows and Number of pages. It’s a handy operational tool for verifying data volumes in a gbase database.

Top comments (0)