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: switch QueryArguments, PlaceholderTypes to slices #33716

Merged
merged 2 commits into from
Jan 16, 2019

Conversation

RaduBerinde
Copy link
Member

sql: change QueryArguments map to a slice

Release note: None

sql: switch PlaceholderTypes to a slice

We switch PlaceholderTypes to a slice instead of a map.

We also fix the handling of cases where some placeholders are unused
(e.g. SELECT $2:::int) which now error out (before they would crash
during execution). Note that PG also errors out in this case.

Fixes #30086.

Release note (bug fix): Preparing queries with missing placeholders
(e.g. SELECT $2::int) now results in an error.

@RaduBerinde RaduBerinde requested review from knz, nvanbenschoten and a team January 14, 2019 17:49
@RaduBerinde RaduBerinde requested a review from a team as a code owner January 14, 2019 17:49
@RaduBerinde RaduBerinde requested review from a team January 14, 2019 17:49
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@RaduBerinde RaduBerinde force-pushed the placeholder-slices branch 2 times, most recently from 075c166 to e326962 Compare January 14, 2019 21:42
@RaduBerinde RaduBerinde requested a review from a team January 14, 2019 21:42
We switch `PlaceholderTypes` to a slice instead of a map.

We also fix the handling of cases where some placeholders are unused
(e.g. `SELECT $2:::int`) which now error out (before they would crash
during execution). Note that PG also errors out in this case.

Fixes cockroachdb#30086.

Release note (bug fix): Preparing queries with missing placeholders
(e.g. `SELECT $2::int`) now results in an error.
Copy link
Member

@jordanlewis jordanlewis left a comment

Choose a reason for hiding this comment

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

:lgtm: very good! Down with all maps.

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

@RaduBerinde
Copy link
Member Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jan 16, 2019

Build failed (retrying...)

craig bot pushed a commit that referenced this pull request Jan 16, 2019
33716: sql: switch QueryArguments, PlaceholderTypes to slices r=RaduBerinde a=RaduBerinde

#### sql: change QueryArguments map to a slice

Release note: None

#### sql: switch PlaceholderTypes to a slice

We switch `PlaceholderTypes` to a slice instead of a map.

We also fix the handling of cases where some placeholders are unused
(e.g. `SELECT $2:::int`) which now error out (before they would crash
during execution). Note that PG also errors out in this case.

Fixes #30086.

Release note (bug fix): Preparing queries with missing placeholders
(e.g. `SELECT $2::int`) now results in an error.


Co-authored-by: Radu Berinde <radu@cockroachlabs.com>
@craig
Copy link
Contributor

craig bot commented Jan 16, 2019

Build succeeded

@craig craig bot merged commit 651f11b into cockroachdb:master Jan 16, 2019
@RaduBerinde RaduBerinde deleted the placeholder-slices branch January 17, 2019 00:56
Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

LGTM! This is fantastic!

@@ -440,9 +440,6 @@ INSERT INTO add_default (a) VALUES (3)
statement error could not parse "foo" as type int
ALTER TABLE add_default ALTER COLUMN b SET DEFAULT 'foo'

statement error variable sub-expressions are not allowed in DEFAULT
ALTER TABLE add_default ALTER COLUMN b SET DEFAULT $1
Copy link
Member

Choose a reason for hiding this comment

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

Why remove these tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think they should be converted to prepare a(int) as alter table ...

Otherwise a naked $1 is not valid in a logic test.

Copy link
Member Author

Choose a reason for hiding this comment

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

This was meant to test the "variable sub-expressions" error for alter table. Using placeholders without prepare is not valid, and now we get a different (earlier) error that's not specific to alter table. There are other testcases for the same error below though.

Copy link
Member

Choose a reason for hiding this comment

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

👍 thanks for the explanation.

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.

sql: PlaceholderInfo should use slices indexed by placeholder name instead of maps
5 participants