Skip to content

Commit d2c2f10

Browse files
table_checksum uses "SELECT SUM(hashtext(t::text)) ..." (#337)
It fixes a problem with large tables ATTENTION: new checksum algorithm is used!
1 parent b78de51 commit d2c2f10

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/node.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,18 +2236,16 @@ def _table_checksum__use_cn(
22362236
assert cursor is not None
22372237

22382238
try:
2239-
cursor.execute("SELECT t::text FROM {} as t".format(
2239+
cursor.execute("SELECT SUM(hashtext(t::text)) FROM {} as t".format(
22402240
__class__._delim_sql_ident(table)
22412241
))
22422242

2243-
while True:
2244-
row = cursor.fetchone()
2245-
if row is None:
2246-
break
2247-
assert type(row) in [list, tuple] # noqa: E721
2248-
assert len(row) == 1
2249-
sum += hash(row[0])
2250-
continue
2243+
row = cursor.fetchone()
2244+
assert row is not None
2245+
assert type(row) in [list, tuple] # noqa: E721
2246+
assert len(row) == 1
2247+
v = row[0]
2248+
sum += int(v if v is not None else 0)
22512249
finally:
22522250
cursor.close()
22532251

tests/test_testgres_common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,7 +2102,7 @@ def test_node__table_checksum(
21022102

21032103
with cn.connection.cursor() as cursor:
21042104
assert cursor is not None
2105-
cursor.execute("SELECT t::text FROM \"t\" as t;")
2105+
cursor.execute("SELECT hashtext(t::text) FROM \"t\" as t;")
21062106

21072107
checksum1 = 0
21082108
record_count = 0
@@ -2113,7 +2113,7 @@ def test_node__table_checksum(
21132113
assert type(row) in [list, tuple] # noqa: E721
21142114
assert len(row) == 1
21152115
record_count += 1
2116-
checksum1 += hash(row[0])
2116+
checksum1 += int(row[0])
21172117
pass
21182118

21192119
assert record_count == table_checksum_test_data.record_count
@@ -2162,7 +2162,7 @@ def test_node__pgbench_table_checksums__one_table(
21622162

21632163
with cn.connection.cursor() as cursor:
21642164
assert cursor is not None
2165-
cursor.execute("SELECT t::text FROM \"t\" as t;")
2165+
cursor.execute("SELECT hashtext(t::text) FROM \"t\" as t;")
21662166

21672167
checksum1 = 0
21682168
record_count = 0
@@ -2173,7 +2173,7 @@ def test_node__pgbench_table_checksums__one_table(
21732173
assert type(row) in [list, tuple] # noqa: E721
21742174
assert len(row) == 1
21752175
record_count += 1
2176-
checksum1 += hash(row[0])
2176+
checksum1 += int(row[0])
21772177
pass
21782178

21792179
assert record_count == table_checksum_test_data.record_count

0 commit comments

Comments
 (0)