Performance issue with PostgresqlRow.getColumn(String name) when select many columns
yuki-teraoka opened this issue · comments
When selecting many fields, a lot of CPU is consumed because the fields are looped.
In one case I encountered, with a select of millions of records with about 700 fields, I forced the query to stop because it was consuming 100% CPU for several hours.
At this time, I checked Java's stack trace many times, and most of them were processing the following for statement.
r2dbc-postgresql/src/main/java/io/r2dbc/postgresql/PostgresqlRow.java
Lines 168 to 174 in d047276
Would it be possible to prepare field name and order mappings in advance?
This is possible. PGJDBC uses a lazy approach to create the column name to index map, see https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/jdbc/PgResultSet.java#L3108-L3136
Happy to merge a pull request.