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

ui: fix generated DROP INDEX statement on table details page #110429

Merged
merged 1 commit into from Sep 12, 2023

Conversation

zachlite
Copy link
Contributor

This commit does two things:

  1. Fixes the generated DROP INDEX statement by considering already quoted fully-qualified names.

  2. Adds unit tests for the QuoteIdentifier utility to clarify its intended usage and limitations.

Epic: none
Release note (bug fix): Fixed a UI issue where the DROP_UNUSED index recommendations produced by the
table details page produced an invalid DROP INDEX statement.

This commit does two things:
1. Fixes the generated `DROP INDEX` statement by considering
already quoted fully-qualified names.

2. Adds unit tests for the `QuoteIdentifier` utility to clarify
its intended usage and limitations.

Epic: none
Release note (bug fix): Fixed a UI issue where the
DROP_UNUSED index recommendations produced by the
table details page produced an invalid `DROP INDEX` statement.
@zachlite zachlite added the backport-23.1.x Flags PRs that need to be backported to 23.1 label Sep 12, 2023
@zachlite zachlite requested a review from a team September 12, 2023 13:33
@zachlite zachlite requested a review from a team as a code owner September 12, 2023 13:33
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@maryliag maryliag left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @zachlite)


pkg/ui/workspaces/cluster-ui/src/databaseTablePage/helperComponents.tsx line 189 at r1 (raw file):

    switch (recommendation.type) {
      case "DROP_UNUSED":
        // Here, `tableName` is a fully qualified name whose identifiers have already been quoted.

do you think it can be confusing to identify what has been quoted or not? Can the QuoteIdentifier do the check instead, and if already quotes does nothing? This way you don't risk calling it on things already quoted and you can always use it

Copy link
Contributor Author

@zachlite zachlite 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 @maryliag)


pkg/ui/workspaces/cluster-ui/src/databaseTablePage/helperComponents.tsx line 189 at r1 (raw file):

Previously, maryliag (Marylia Gutierrez) wrote…

do you think it can be confusing to identify what has been quoted or not? Can the QuoteIdentifier do the check instead, and if already quotes does nothing? This way you don't risk calling it on things already quoted and you can always use it

I agree it's confusing. I did what you're suggesting here initially, thinking that QuoteIdentifier should be idempotent. But the problem is that it becomes difficult (impossible?) to know what to do if the caller doesn't tell us the state of the argument.

For example, consider "tablename". Without the caller telling us, it's impossible to tell if the argument is already a quoted identifier, or if the argument should treated as a non-quoted identifier and it's chars need escaping. If the former, the result should be "tablename". If the latter, the result should be """tablename""".

My solution was to document this and write a unit test.. WDYT?

Copy link
Contributor Author

@zachlite zachlite 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 @maryliag)


pkg/ui/workspaces/cluster-ui/src/databaseTablePage/helperComponents.tsx line 189 at r1 (raw file):

Previously, zachlite wrote…

I agree it's confusing. I did what you're suggesting here initially, thinking that QuoteIdentifier should be idempotent. But the problem is that it becomes difficult (impossible?) to know what to do if the caller doesn't tell us the state of the argument.

For example, consider "tablename". Without the caller telling us, it's impossible to tell if the argument is already a quoted identifier, or if the argument should treated as a non-quoted identifier and it's chars need escaping. If the former, the result should be "tablename". If the latter, the result should be """tablename""".

My solution was to document this and write a unit test.. WDYT?

And QuoteIdentifier currently always assumes the latter.

Copy link
Contributor

@maryliag maryliag left a comment

Choose a reason for hiding this comment

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

:lgtm:

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


pkg/ui/workspaces/cluster-ui/src/databaseTablePage/helperComponents.tsx line 189 at r1 (raw file):

Previously, zachlite wrote…

And QuoteIdentifier currently always assumes the latter.

I see. Thanks for the explanation

@zachlite
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Sep 12, 2023

Build succeeded:

@craig craig bot merged commit 7463887 into cockroachdb:master Sep 12, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-23.1.x Flags PRs that need to be backported to 23.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants