Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: improve performance of PgResultSet getByte/getShort/getInt/getLong for float-typed columns #2634

Merged
merged 1 commit into from Oct 8, 2022

Conversation

john9x
Copy link
Contributor

@john9x john9x commented Oct 5, 2022

Hi!

When we call PgResultSet.getInt for float-typed columns fast number parser (getFastInt) fails on dot symbol and then we go to very slow path: Integer.parseInt throw new NumberFormatException (with stacktrace) that immediately swallowed and finally we parse integer through BigDecimal/BigInteger.
I propose to not fail fast parsing or fraction part but just discard it.

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Changes to Existing Features:

  • Does this break existing behaviour? If so please explain.
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully run tests with your changes locally?

@davecramer
Copy link
Member

Thanks for the PR!
Can you add a test for this condition please ?

@john9x
Copy link
Contributor Author

john9x commented Oct 5, 2022

Can you add a test for this condition please ?

Ok, to this class org.postgresql.test.jdbc2.ResultSetTest ?

@john9x
Copy link
Contributor Author

john9x commented Oct 5, 2022

Tests in org.postgresql.test.jdbc2.ResultSetTest

testgetLong
testgetInt
testgetShort
testgetByte

already covers this conditions

@davecramer
Copy link
Member

@john9x Is there a way to test for the specific thing you are fixing ?

@john9x
Copy link
Contributor Author

john9x commented Oct 7, 2022

@davecramer "getByte/getShort/getInt/getLong from numeric column with fraction part" is not so specific thing :) And it is already tested!

org.postgresql.test.jdbc2.ResultSetTest
...
setUp() throws Exception {
TestUtil.createTable(con, "testnumeric", "a numeric");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('1.0')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('0.0')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('-1.0')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('1.2')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('-2.5')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('0.000000000000000000000000000990')");
...
}

testgetInt() throws SQLException {
    ResultSet rs = con.createStatement().executeQuery("select * from testnumeric");
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    assertTrue(rs.next());
    assertEquals(0, rs.getInt(1));
    assertTrue(rs.next());
    assertEquals(-1, rs.getInt(1));
    assertTrue(rs.next());
    assertEquals(1, rs.getInt(1));
    assertTrue(rs.next());
    assertEquals(-2, rs.getInt(1));
    assertTrue(rs.next());
    assertEquals(0, rs.getInt(1));
...
}

@davecramer davecramer merged commit 075fd8a into pgjdbc:master Oct 8, 2022
@john9x john9x deleted the fast-get-int branch October 16, 2022 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants