Obtenir le nombre de lignes / documents (rapide)
Oracle
-- Statistics-based (fast, estimated):
SELECT num_rows FROM dba_tables WHERE table_name = 'CUSTOMER';
-- Exact: SELECT COUNT(*) FROM customer;num_rows reflète la dernière exécution d'ANALYZE/DBMS_STATS ; utilisez COUNT(*) pour une valeur exacte.
PostgreSQL
-- Estimated (instant):
SELECT reltuples::bigint FROM pg_class WHERE relname = 'customer';
-- Exact: SELECT count(*) FROM customer;reltuples est une estimation datant du dernier ANALYZE/VACUUM ; un COUNT complet est coûteux sur les grandes tables.
MySQL
-- Estimated (InnoDB):
SELECT table_rows FROM information_schema.tables
WHERE table_name = 'customer';
-- Exact: SELECT COUNT(*) FROM customer;Dans InnoDB, table_rows est une estimation et peut s'écarter jusqu'à 50 %.
SQL Server
SELECT SUM(row_count) AS rows
FROM sys.dm_db_partition_stats
WHERE object_id = OBJECT_ID('dbo.customer')
AND index_id IN (0, 1);index_id 0 (heap) ou 1 (clustered) donne le nombre de lignes ; bien plus rapide qu'un parcours COUNT(*).
MongoDB
// Fast (from metadata):
db.customer.estimatedDocumentCount()
// Exact (can count with a filter): db.customer.countDocuments({})estimatedDocumentCount lit les métadonnées (instantané) ; countDocuments effectue un parcours réel.
Redis
DBSIZE
# Specific pattern: count roughly with SCAN (do not use KEYS * in production)DBSIZE renvoie en O(1) le nombre total de clés de la base sélectionnée.