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

Rework sql type gathering to use OID instead of typname. #1949

Merged

Conversation

MMeent
Copy link
Contributor

@MMeent MMeent commented Nov 10, 2020

This is more stable, and has the added benefit of fixing #1948.

I'd like to remove the pgNameToSQLType map too, but that's used for the public api of getPGTypeNamesWithSQLTypes() - I'm not certain I can just remove that and be done with it...

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • I believe so

Changes to Existing Features:

  • Does this break existing behaviour? If so please explain.
    • It alters the API of TypeInfoCache to prefer OID type lookups over named lookups, to correctly determine the type of data of which the OID is known, and only a qualified path is known (e.g. off-path types)
  • 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?
  • yes

@davecramer
Copy link
Member

There is a small fix required to appease checkstyle, otherwise looks fine. I would like a test where the a type of the same name is created in a different schema just for completeness

@MMeent MMeent force-pushed the fix/issue-1948-off-path-type-discovery branch from 14fc3cc to c9e274e Compare November 10, 2020 22:29
@MMeent
Copy link
Contributor Author

MMeent commented Nov 10, 2020

I've cleaned up the code a bit, and made it into one commit that follows the commit style guide.

@codecov-io
Copy link

Codecov Report

Merging #1949 (c9e274e) into master (18cb3f6) will increase coverage by 3.97%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##             master    #1949      +/-   ##
============================================
+ Coverage     65.35%   69.33%   +3.97%     
- Complexity     3955     4226     +271     
============================================
  Files           197      197              
  Lines         18006    18012       +6     
  Branches       2919     2920       +1     
============================================
+ Hits          11768    12488     +720     
+ Misses         4878     4167     -711     
+ Partials       1360     1357       -3     

@davecramer
Copy link
Member

"Special has been given to the oid of Oid.UNSPECIFIED, as that needs to be mapped to Types.OTHER without needing to query the database." Can you fix this up ?

@MMeent
Copy link
Contributor Author

MMeent commented Nov 11, 2020

What do you mean with 'fix up'? Should I remove it from the commit message, or did you mean something else?

@davecramer
Copy link
Member

It doesn't read properly I presume you mean Special consideration ?

…es not have the issue of name shadowing / qual-names, and has the added benefit of fixing pgjdbc#1948.

Types that are not on the search path (e.g. they are shadowed, or in a schema that is not included in the search path) are stored in the caches as fully qualified type names and OIDs. As we cannot easily query the pg_type catalog using qualified type names, we replace the pgTypeName with the oid of the type name to query properties of the type.

Testcases are added to improve coverage of correctly detecting SQL types that are not on the path, but are available through OID or qualified lookup. These types are stored internally as a fully qualified type, but we cannot use this name for lookup in pg_type.

Special consideration has been given to Oid.UNSPECIFIED, as that needs to be mapped to Types.OTHER without first hitting the database. That mapping is static, but is not in `types` because it is not an actual type.

Fixes pgjdbc#1948
@MMeent MMeent force-pushed the fix/issue-1948-off-path-type-discovery branch from c9e274e to d56817f Compare November 11, 2020 14:26
@MMeent
Copy link
Contributor Author

MMeent commented Nov 11, 2020

Ah, yes, I indeed messed that up, and read over that mistake thrice already? I believe that's fixed.

@davecramer davecramer merged commit 375cb37 into pgjdbc:master Nov 11, 2020
@MMeent MMeent deleted the fix/issue-1948-off-path-type-discovery branch November 11, 2020 15:52
@MMeent
Copy link
Contributor Author

MMeent commented Dec 9, 2020

@davecramer I wouldn't want to come across as impatient, but at what timeframe could I expect this to be released? Is there some release schedule I could lookup for pgjdbc?

@davecramer
Copy link
Member

I wouldn't expect to see a release before the end of the year. I know I'm going to be pinned, not sure about @vlsi ?

davecramer added a commit to davecramer/pgjdbc that referenced this pull request Jul 5, 2021
Fix: Rework sql type gathering to use OID instead of typname. This do…
…es not have the issue of name shadowing / qual-names, and has the added benefit of fixing pgjdbc#1948.

Types that are not on the search path (e.g. they are shadowed, or in a schema that is not included in the search path) are stored in the caches as fully qualified type names and OIDs. As we cannot easily query the pg_type catalog using qualified type names, we replace the pgTypeName with the oid of the type name to query properties of the type.

Testcases are added to improve coverage of correctly detecting SQL types that are not on the path, but are available through OID or qualified lookup. These types are stored internally as a fully qualified type, but we cannot use this name for lookup in pg_type.

Special consideration has been given to Oid.UNSPECIFIED, as that needs to be mapped to Types.OTHER without first hitting the database. That mapping is static, but is not in `types` because it is not an actual type.

Fixes pgjdbc#1948
davecramer added a commit that referenced this pull request Jul 5, 2021
Fix: Rework sql type gathering to use OID instead of typname. This does not have the issue of name shadowing / qual-names, and has the added benefit of fixing #1948.

Types that are not on the search path (e.g. they are shadowed, or in a schema that is not included in the search path) are stored in the caches as fully qualified type names and OIDs. As we cannot easily query the pg_type catalog using qualified type names, we replace the pgTypeName with the oid of the type name to query properties of the type.

Testcases are added to improve coverage of correctly detecting SQL types that are not on the path, but are available through OID or qualified lookup. These types are stored internally as a fully qualified type, but we cannot use this name for lookup in pg_type.

Special consideration has been given to Oid.UNSPECIFIED, as that needs to be mapped to Types.OTHER without first hitting the database. That mapping is static, but is not in `types` because it is not an actual type.

Fixes #1948
@davecramer
Copy link
Member

So this has caused a fair bit of a regression as we are now querying the database for almost every type. Changes startup times considerably see issue #2236

davecramer added a commit to davecramer/pgjdbc that referenced this pull request Sep 21, 2021
… all types by OID, we can return types for well known types
davecramer added a commit that referenced this pull request Sep 21, 2021
…ypes by OID, we can return types for well known types (#2257)

* fix startup regressions caused by PR #1949. Instead of checking all types by OID, we can return types for well known types

* clarifiy code, add any new types to the pgNameToSQLType cache
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

3 participants