-
get the most recent recv time for peers
SELECT peer.id, peer.kad_id, peer.ip, peer.udp_port, b.recv_time FROM peer JOIN (SELECT source_peer, MAX(recv_time) recv_time FROM report GROUP BY source_peer) b ON b.source_peer = peer.id;
1b. get most recent recv but don't filter peers without recvs
SELECT peer.*, b.recv_time FROM peer LEFT OUTER JOIN (SELECT source_peer, MAX(recv_time) recv_time FROM report GROUP BY source_peer) b ON b.source_peer = peer.id;
-
get number of peers never recv'd
SELECT count(*) FROM peer LEFT OUTER JOIN report ON (report.source_peer = peer.id) WHERE report.source_peer IS NULL;
-
number of peers recv'd
SELECT count(DISTINCT source_peer) FROM report;
-
number of unqiue ips recv'd
SELECT count(*) FROM (SELECT DISTINCT peer.ip FROM peer JOIN (SELECT DISTINCT source_peer FROM report) b ON peer.id = b.source_peer);
-
ips with more than 1 peer
SELECT ip, count() FROM peer GROUP BY ip HAVING count() > 1;
-
kad ids with more than 1 peer
SELECT a.* FROM peer a JOIN (SELECT kad_id, COUNT() FROM peer GROUP BY kad_id HAVING count() > 1) b ON a.kad_id = b.kad_id ORDER BY kad_id;
SELECT count(*) FROM (SELECT DISTINCT a.id FROM peer a INNER JOIN peer b ON a.id <> b.id AND a.kad_id = b.kad_id ORDER BY a.kad_id);
-
compare number of unique kad_ids with number of ips with number of unique peers
SELECT COUNT(DISTINCT kad_id), COUNT(DISTINCT ip), COUNT(*) FROM peer;