sql - Is it possible to get the number of rows from a table in O(1) time? -
in sql server, 1 way of getting number of rows in table is
select count(*) mytable
but assume that's o(n)
time n
number of rows. there metadata can access has number of rows stored?
yes, can use sys.partitions
, might not exact number, it's extremely fast:
select sum(rows) sys.partitions [object_id] = object_id('dbo.mytable') , index_id in (0,1);
Comments
Post a Comment