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

PgDatabaseMetaData.getIndexInfo() cast operands to smallint #2242

Merged
merged 1 commit into from Sep 13, 2021
Merged

PgDatabaseMetaData.getIndexInfo() cast operands to smallint #2242

merged 1 commit into from Sep 13, 2021

Conversation

jsyrjala
Copy link
Contributor

@jsyrjala jsyrjala commented Sep 7, 2021

It is possible to break method PgDatabaseMetaData.getIndexInfo() by adding certain custom operators.
This PR casts operands in a query so that PgDatabaseMetaData.getIndexInfo() works in presence
of such operator config.

Creating this operator triggers this issue:

CREATE OR REPLACE FUNCTION f6(numeric, integer) returns integer as 'BEGIN return $1::integer & $2;END;' language plpgsql immutable;
CREATE OPERATOR & (LEFTARG = numeric, RIGHTARG = integer, PROCEDURE = f6);

Fixes #2241

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

adding an operator like this to the test cases would be useful

@jsyrjala
Copy link
Contributor Author

jsyrjala commented Sep 7, 2021

What would be the right place to add the test case? There are several DatabaseMetaDataTest classes. Only one of those calling getIndexInfo() is jdbc2.

./java/org/postgresql/test/jdbc42/DatabaseMetaDataTest.java
./java/org/postgresql/test/jdbc4/DatabaseMetaDataTest.java
./java/org/postgresql/test/jdbc3/DatabaseMetaDataTest.java
./java/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java

@davecramer
Copy link
Member

it's pretty fundamental so jdbc2 is fine.

It is possible to break method PgDatabaseMetaData.getIndexInfo() by adding certain custom operators.
This PR casts operands in a query so that PgDatabaseMetaData.getIndexInfo() works in presence
of such operator config.

Creating this operator triggers this issue:

CREATE OR REPLACE FUNCTION f6(numeric, integer) returns integer as 'BEGIN return $1::integer & $2;END;' language plpgsql immutable;
CREATE OPERATOR & (LEFTARG = numeric, RIGHTARG = integer, PROCEDURE = f6);

Fixes #2241
@jsyrjala
Copy link
Contributor Author

jsyrjala commented Sep 8, 2021

Added the operator creation to ./java/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java. Having the operator makes a couple of tests in DatabaseMetaDataTest fail with code from master branch. Doing the casts in getIndexInfo() makes the tests pass again.

@davecramer
Copy link
Member

Thx!

@jsyrjala
Copy link
Contributor Author

jsyrjala commented Sep 9, 2021

I guess this PR is now directed against upcoming 43.x development version? Would it possible get this fix also to 42.2.x?

@davecramer
Copy link
Member

yes, of course

@jsyrjala
Copy link
Contributor Author

Should I do an another PR with the same content against release/42.2 branch?

@davecramer davecramer merged commit 3a2bbd7 into pgjdbc:master Sep 13, 2021
@davecramer
Copy link
Member

Yes, please

davecramer pushed a commit that referenced this pull request Sep 13, 2021
…2253)

It is possible to break method PgDatabaseMetaData.getIndexInfo() by adding certain custom operators.
This PR casts operands in a query so that PgDatabaseMetaData.getIndexInfo() works in presence
of such operator config.

Creating this operator triggers this issue:

CREATE OR REPLACE FUNCTION f6(numeric, integer) returns integer as 'BEGIN return $1::integer & $2;END;' language plpgsql immutable;
CREATE OPERATOR & (LEFTARG = numeric, RIGHTARG = integer, PROCEDURE = f6);

Fixes #2241
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.

PgDatabaseMetaData.getIndexInfo breaks with certain custom operator configuration
2 participants