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

sql: support #typeHints greater than #placeholders for prepare stmt #87535

Merged
merged 1 commit into from
Sep 19, 2022

Conversation

ZhouXing19
Copy link
Collaborator

@ZhouXing19 ZhouXing19 commented Sep 7, 2022

Previous, we only support pgwire prepare stmt with the number of typehints equal or smaller than the number of the placeholders in the query. E.g. the following usage are not supported:

Parse {"Name": "s2", "Query": "select $1", "ParameterOIDs":[1043, 1043, 1043]}

Where there is 1 placeholder in the query, but 3 type hints.

This commit is to allow mismatching #typeHints and #placeholders. The former can be larger than the latter now.

This feature is needed for CRDB's support for Hasura GraphQL Engine.

Release justification: Low risk, high benefit changes to existing functionality

Release note: For pgwire-level prepare statements, add support for the case where the number of the type hints is greater than the number of placeholders in the given query.

@ZhouXing19 ZhouXing19 requested review from a team September 7, 2022 21:58
@ZhouXing19 ZhouXing19 requested review from a team as code owners September 7, 2022 21:58
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@ZhouXing19 ZhouXing19 changed the title sql: support #typeHints greater than #placeholders for prepare stmt sql: support #typeHints greater than #placeholders for prepare stmt Sep 7, 2022
@ZhouXing19
Copy link
Collaborator Author

The failed tests in CI don't seem related so RFAL!

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code looks good! just had testing questions

pkg/sql/pgwire/testdata/pgtest/prepare Show resolved Hide resolved
pkg/sql/pgwire/testdata/pgtest/prepare Show resolved Hide resolved
@@ -38,11 +38,6 @@ describe('select', () => {

describe('error cases', () => {
const cases = [{
name: 'not enough params',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you confirm that postgres does not expect this behavior?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test here to verify.

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rafiss and @ZhouXing19)


pkg/acceptance/testdata/node/base-test.js line 42 at r2 (raw file):

  const cases = [{
    name: 'not enough params',
    query: { text: 'SELECT 3', values: ['foo'] },

hm actually i tried running this against postgres (using the node-pg driver), and it does fail. i think this is a pgtest to reproduce it:

Parse {"Name": "s", "Query": "select 3"}
Bind {"DestinationPortal": "p", "PreparedStatement": "s", "ParameterFormatCodes": [0], "Parameters": [{"text":"foo"}]}
Describe {"ObjectType": "P", "Name": "p"}
Execute {"Portal": "p"}
Sync

pkg/sql/conn_executor_prepare.go line 389 at r2 (raw file):

			return retErr(
				pgwirebase.NewProtocolViolationErrorf(
					"expected %d arguments, got %d", numQArgs, len(bindCmd.Args)))

i see in revision 2 this was added back in. are there already tests for it?

Previous, we only support pgwire prepare stmt with the number of typehints
equal or smaller than the number of the placeholders in the query. E.g. the
following usage are not supported:

```
Parse {"Name": "s2", "Query": "select $1", "ParameterOIDs":[1043, 1043, 1043]}
```
Where there are 1 placeholder in the query, but 3 type hints.

This commit is to allow mismatching #typeHints and #placeholders. The former
can be larger than the latter now.

Release justification: Low risk, high benefit changes to existing functionality

Release note (sql change): For pgwire-level prepare statements, support the case
where the number of the type hints is greater than the number of placeholders
in the given query.
Copy link
Collaborator Author

@ZhouXing19 ZhouXing19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rafiss)


pkg/sql/conn_executor_prepare.go line 389 at r2 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

i see in revision 2 this was added back in. are there already tests for it?

Yes, it was because removing this part made this test pass:

Bind {"DestinationPortal": "p2", "PreparedStatement": "s2", "ParameterFormatCodes": [0], "Parameters": [{"text":"whitebear"}]}
Execute {"Portal": "p2"}
Sync

which is incorrect. I've added this test to the pgtest too.


pkg/acceptance/testdata/node/base-test.js line 42 at r2 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

hm actually i tried running this against postgres (using the node-pg driver), and it does fail. i think this is a pgtest to reproduce it:

Parse {"Name": "s", "Query": "select 3"}
Bind {"DestinationPortal": "p", "PreparedStatement": "s", "ParameterFormatCodes": [0], "Parameters": [{"text":"foo"}]}
Describe {"ObjectType": "P", "Name": "p"}
Execute {"Portal": "p"}
Sync

Yeah good point, I added this one to the pgtest, and put back what we had here.

@ZhouXing19 ZhouXing19 requested a review from rafiss September 17, 2022 04:11
Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the fix!

Reviewed 11 of 14 files at r1, 1 of 2 files at r2, 2 of 2 files at r3, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rafiss)

@ZhouXing19
Copy link
Collaborator Author

TFTR!
bors r=rafiss

@craig
Copy link
Contributor

craig bot commented Sep 19, 2022

Build succeeded:

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.

3 participants