You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attempting to retrieve statistics for partitioned tables from PostgreSQL using Trino, an IllegalArgumentException is thrown if the rowCount is negative. This issue arises in the io.trino.plugin.postgresql.PostgreSqlClient.readTableStatistics method, specifically when the rowCount is less than zero, which is a valid scenario for partitioned tables that have not been vacuumed or analyzed.
Caused by: java.lang.IllegalArgumentException: rowCount must be greater than or equal to 0: -201.0
at io.trino.spi.statistics.TableStatistics.<init>(TableStatistics.java:43)
at io.trino.spi.statistics.TableStatistics$Builder.build(TableStatistics.java:118)
at io.trino.plugin.postgresql.PostgreSqlClient.readTableStatistics(PostgreSqlClient.java:1030)
at io.trino.plugin.postgresql.PostgreSqlClient.getTableStatistics(PostgreSqlClient.java:963)
The current check in the codebase is:
if (rowCount == -1) {
// Table has never yet been vacuumed or analyzedreturnTableStatistics.empty();
}
However, this does not account for partitioned tables, where the rowCount can be less than -1. A proposed change to accommodate this scenario is:
if (rowCount <= -1) {
// Table has never yet been vacuumed or analyzed:// -1 indicates non-partitioned tables, and values less than -1 indicate partitioned tablesreturnTableStatistics.empty();
}
What version of Postgres are you observing this with? And can you provide a simple reproduction - it'll make it possible for me to add a test and verify the fix.
What version of Postgres are you observing this with? And can you provide a simple reproduction - it'll make it possible for me to add a test and verify the fix.
Postgres: 15.4
Trino: 450
Steps to reproduce:
docker run --name postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
docker exec -it postgres psql -U postgres
CREATETABLEmeasurement (
city_id intnot null,
logdate datenot null,
peaktemp int,
unitsales int
) PARTITION BY RANGE (logdate);
CREATETABLEmeasurement_y2006m02 PARTITION OF measurement
FOR VALUESFROM ('2006-02-01') TO ('2006-03-01');
CREATETABLEmeasurement_y2006m03 PARTITION OF measurement
FOR VALUESFROM ('2006-03-01') TO ('2006-04-01');
SELECTSUM(child.reltuples)
FROM pg_inherits
JOIN pg_class parent ONpg_inherits.inhparent=parent.oidJOIN pg_class child ONpg_inherits.inhrelid=child.oidJOIN pg_namespace parent_ns ONparent_ns.oid=parent.relnamespaceJOIN pg_namespace child_ns ONchild_ns.oid=child.relnamespaceWHEREparent.oid='public.measurement'::regclass;
sum
------2
(1 row)
CREATETABLEmeasurement_y2024m03 PARTITION OF measurement
FOR VALUESFROM ('2024-03-01') TO ('2024-04-01');
SELECTSUM(child.reltuples)
FROM pg_inherits
JOIN pg_class parent ONpg_inherits.inhparent=parent.oidJOIN pg_class child ONpg_inherits.inhrelid=child.oidJOIN pg_namespace parent_ns ONparent_ns.oid=parent.relnamespaceJOIN pg_namespace child_ns ONchild_ns.oid=child.relnamespaceWHEREparent.oid='public.measurement'::regclass;
sum
------3
(1 row)
When attempting to retrieve statistics for partitioned tables from PostgreSQL using Trino, an IllegalArgumentException is thrown if the rowCount is negative. This issue arises in the io.trino.plugin.postgresql.PostgreSqlClient.readTableStatistics method, specifically when the rowCount is less than zero, which is a valid scenario for partitioned tables that have not been vacuumed or analyzed.
The current check in the codebase is:
However, this does not account for partitioned tables, where the rowCount can be less than -1. A proposed change to accommodate this scenario is:
Similar issue: #17061
Related PR: #17066
I can create a PR, but perhaps for such a simple case, someone could quickly fix it, so I don't need to submit a Contributor License Agreement (CLA)
The text was updated successfully, but these errors were encountered: