londiste: added --count-only to compare command
authormartinko <gamato@users.sf.net>
Tue, 12 Feb 2013 07:37:04 +0000 (08:37 +0100)
committermartinko <gamato@users.sf.net>
Tue, 12 Feb 2013 07:37:04 +0000 (08:37 +0100)
For quickly checking whether tables have same number of rows,
without comparing tables' contents (data).

python/londiste.py
python/londiste/compare.py

index fb230f235de83d68459fd870637a68d9a1ad42d3..e95fa25df48026fe04b1f622fec4148bc654cbfe 100755 (executable)
@@ -154,6 +154,8 @@ class Londiste(skytools.DBScript):
                 help = "add: ignore table differences, repair: ignore lag")
         g.add_option("--apply", action = "store_true",
                 help="repair: apply fixes automatically")
+        p.add_option("--count-only", action="store_true",
+                help="compare: just count rows, do not compare data")
         p.add_option_group(g)
 
         return p
@@ -161,4 +163,3 @@ class Londiste(skytools.DBScript):
 if __name__ == '__main__':
     script = Londiste(sys.argv[1:])
     script.start()
-
index a92ae51312c1075e72836ef1498f744bb5018b28..83dac2e4a7615e6f54dbe6d2133a92c6a1e3cef6 100644 (file)
@@ -35,7 +35,9 @@ class Comparator(Syncer):
         # get sane query
         v1 = src_db.server_version
         v2 = dst_db.server_version
-        if v1 < 80300 or v2 < 80300:
+        if self.options.count_only:
+            q = "select count(1) as cnt from only _TABLE_"
+        elif v1 < 80300 or v2 < 80300:
             # 8.2- does not have record to text and text to bit casts, so we need to use a bit of evil hackery
             q = "select count(1) as cnt, sum(bit_in(textout('x'||substr(md5(textin(record_out(_COLS_))),1,16)), 0, 64)::bigint) as chksum from only _TABLE_"
         elif (v1 < 80400 or v2 < 80400) and v1 != v2:
@@ -54,7 +56,9 @@ class Comparator(Syncer):
         if dst_where:
             dst_q = dst_q + " WHERE " + dst_where
 
-        f = "%(cnt)d rows, checksum=%(chksum)s"
+        f = "%(cnt)d rows"
+        if not self.options.count_only:
+            f += ", checksum=%(chksum)s"
         f = self.cf.get('compare_fmt', f)
 
         self.log.debug("srcdb: " + src_q)
@@ -111,6 +115,12 @@ class Comparator(Syncer):
 
         return common
 
+    def init_optparse(self, p=None):
+        """Initialize cmdline switches."""
+        p = super(Comparator, self).init_optparse(p)
+        p.add_option("--count-only", action="store_true", help="just count rows, do not compare data")
+        return p
+
 if __name__ == '__main__':
     script = Comparator(sys.argv[1:])
     script.start()