pgtoolkit/tools/bigtables.py
changeset 103 24e94a3da209
parent 101 2a2d0d5df03b
--- a/pgtoolkit/tools/bigtables.py	Wed May 07 18:33:50 2014 +0200
+++ b/pgtoolkit/tools/bigtables.py	Mon May 26 18:18:21 2014 +0200
@@ -34,12 +34,12 @@
                 indexes = browser.list_indexes(table['name'], schema['name'])
                 for index in indexes:
                     all_indexes.append({'name': index['name'], 'table': table_name, 'size': index['size']})
-                all_tables.append({'name': table_name, 'size': table['size'], 'indexes': indexes})
+                size_with_indexes = table['size'] + sum(index['size'] for index in indexes)
+                all_tables.append({'name': table_name, 'size': table['size'], 'indexes': indexes, 'size_with_indexes': size_with_indexes})
 
         # print names and sizes of 20 largest tables
-        for table in sorted(all_tables, reverse=True, key=lambda x: x['size'])[:self.args.limit]:
-            size_of_indexes = sum(index['size'] for index in table['indexes'])
-            print(highlight(1) + prettysize_short(table['size'] + size_of_indexes, trailing_zeros=True).rjust(8) + highlight(0),
+        for table in sorted(all_tables, reverse=True, key=lambda x: x['size_with_indexes'])[:self.args.limit]:
+            print(highlight(1) + prettysize_short(table['size_with_indexes'], trailing_zeros=True).rjust(8) + highlight(0),
                   '(total)'.ljust(8),
                   highlight(1) + table['name'] + highlight(0), sep='  ')
             if self.args.details: