From 0557e0fa82217b655abe416175b17b7491220e5b Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Fri, 30 Jan 2026 17:25:31 +0300 Subject: [PATCH] table_checksum uses "SELECT SUM(hashtext(t::text)) ..." It fixes a problem with large tables ATTENTION: new checksum algorithm is used! --- src/node.py | 16 +++++++--------- tests/test_testgres_common.py | 8 ++++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/node.py b/src/node.py index a1ed137c..57cf20c3 100644 --- a/src/node.py +++ b/src/node.py @@ -2236,18 +2236,16 @@ def _table_checksum__use_cn( assert cursor is not None try: - cursor.execute("SELECT t::text FROM {} as t".format( + cursor.execute("SELECT SUM(hashtext(t::text)) FROM {} as t".format( __class__._delim_sql_ident(table) )) - while True: - row = cursor.fetchone() - if row is None: - break - assert type(row) in [list, tuple] # noqa: E721 - assert len(row) == 1 - sum += hash(row[0]) - continue + row = cursor.fetchone() + assert row is not None + assert type(row) in [list, tuple] # noqa: E721 + assert len(row) == 1 + v = row[0] + sum += int(v if v is not None else 0) finally: cursor.close() diff --git a/tests/test_testgres_common.py b/tests/test_testgres_common.py index 8c338db0..e8d1f322 100644 --- a/tests/test_testgres_common.py +++ b/tests/test_testgres_common.py @@ -2102,7 +2102,7 @@ def test_node__table_checksum( with cn.connection.cursor() as cursor: assert cursor is not None - cursor.execute("SELECT t::text FROM \"t\" as t;") + cursor.execute("SELECT hashtext(t::text) FROM \"t\" as t;") checksum1 = 0 record_count = 0 @@ -2113,7 +2113,7 @@ def test_node__table_checksum( assert type(row) in [list, tuple] # noqa: E721 assert len(row) == 1 record_count += 1 - checksum1 += hash(row[0]) + checksum1 += int(row[0]) pass assert record_count == table_checksum_test_data.record_count @@ -2162,7 +2162,7 @@ def test_node__pgbench_table_checksums__one_table( with cn.connection.cursor() as cursor: assert cursor is not None - cursor.execute("SELECT t::text FROM \"t\" as t;") + cursor.execute("SELECT hashtext(t::text) FROM \"t\" as t;") checksum1 = 0 record_count = 0 @@ -2173,7 +2173,7 @@ def test_node__pgbench_table_checksums__one_table( assert type(row) in [list, tuple] # noqa: E721 assert len(row) == 1 record_count += 1 - checksum1 += hash(row[0]) + checksum1 += int(row[0]) pass assert record_count == table_checksum_test_data.record_count