table($table)->count(); } try { $row = $conn->selectOne( 'SELECT TABLE_ROWS AS approx FROM information_schema.tables WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? LIMIT 1', [$table] ); } catch (\Throwable) { $row = null; } $approx = $row?->approx ?? null; if ($approx === null || (int) $approx <= 0) { // Fall back to exact count on tables InnoDB hasn't analyzed yet // or that are small enough that the approximation is meaningless. return (int) $conn->table($table)->count(); } return (int) $approx; } private static function supportsInformationSchema(ConnectionInterface $conn): bool { $driver = method_exists($conn, 'getDriverName') ? $conn->getDriverName() : null; return in_array($driver, ['mysql', 'mariadb'], true); } }