Skip to content

Commit 50bc2c1

Browse files
committed
Merge branch 'DBTOOLS-1791_fix_pg_statistics' into 'master'
DBTOOLS-1791 fixed pg statistics See merge request codekeeper/pgcodekeeper-core!108
2 parents 60649d7 + 8fadea9 commit 50bc2c1

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1616
### Fixed
1717

1818
- Fixed an error when reading functions from the ClickHouse database.
19+
- Fixed a false difference between STATISTICS in PostgreSQL.
1920

2021
## [13.0.0] - 2025-11-12
2122

CHANGELOG.ru.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
### Исправлено
1717

1818
- Исправлена ошибка при чтении функций из базы данных ClickHouse.
19+
- Исправлено ложное различие для объекта STATISTICS в PostgreSQL.
1920

2021
## [13.0.0] - 2025-11-12
2122

src/main/java/org/pgcodekeeper/core/loader/jdbc/pg/StatisticsReader.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ protected void processResult(ResultSet res, AbstractSchema schema) throws SQLExc
6464
.parseStatistics(stat));
6565

6666
if (SupportedPgVersion.VERSION_14.isLE(loader.getVersion())) {
67-
stat.setStatistics(res.getInt("stxstattarget"));
67+
var statVal = res.getString("stxstattarget");
68+
if (null != statVal) {
69+
stat.setStatistics(Integer.parseInt(statVal));
70+
}
6871
}
6972

7073
loader.setOwner(stat, res.getLong("stxowner"));

src/main/java/org/pgcodekeeper/core/schema/pg/PgStatistics.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.pgcodekeeper.core.schema.pg;
2121

2222
import org.pgcodekeeper.core.PgDiffUtils;
23+
import org.pgcodekeeper.core.Utils;
2324
import org.pgcodekeeper.core.hasher.Hasher;
2425
import org.pgcodekeeper.core.schema.AbstractStatistics;
2526
import org.pgcodekeeper.core.schema.ObjectState;
@@ -69,7 +70,7 @@ public void getCreationSQL(SQLScript script) {
6970
sb.append(PgDiffUtils.getQuotedName(foreignTable));
7071
script.addStatement(sb);
7172

72-
if (statistics > 0) {
73+
if (statistics >= 0) {
7374
script.addStatement(appendStatistics(this));
7475
}
7576

@@ -158,7 +159,7 @@ public boolean compare(PgStatement obj) {
158159

159160
private boolean compareUnalterable(PgStatistics stat) {
160161
return Objects.equals(kinds, stat.kinds)
161-
&& Objects.equals(expressions, stat.expressions)
162+
&& Utils.setLikeEquals(expressions, stat.expressions)
162163
&& Objects.equals(stat.foreignSchema, foreignSchema)
163164
&& Objects.equals(stat.foreignTable, foreignTable);
164165
}

src/test/resources/org/pgcodekeeper/core/it/jdbc/pg/pg_statistics.sql

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ BEGIN
1414
END;
1515
$$;
1616

17-
--ORIGIN:
18-
--
19-
--CREATE STATISTICS second.s1 ON first.f1(b), a FROM first.t1;
20-
--
21-
--DIFF:
22-
23-
--CREATE STATISTICS second.s1 ON a, first.f1(b) FROM first.t1;
17+
CREATE STATISTICS second.s1 ON first.f1(b), a FROM first.t1;
2418

2519
CREATE STATISTICS second.s2 ON b, first.f1(a) FROM first.v1;
2620

@@ -40,4 +34,4 @@ ALTER MATERIALIZED VIEW first.v1 OWNER TO test;
4034

4135
ALTER STATISTICS second.s2 OWNER TO test;
4236

43-
--ALTER STATISTICS second.s1 OWNER TO test;
37+
ALTER STATISTICS second.s1 OWNER TO test;

0 commit comments

Comments
 (0)