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: add voting_replicas, non_voting_replicas columns to SHOW RANGES #93513

Merged
merged 1 commit into from
Dec 16, 2022
Merged

sql: add voting_replicas, non_voting_replicas columns to SHOW RANGES #93513

merged 1 commit into from
Dec 16, 2022

Conversation

ecwall
Copy link
Contributor

@ecwall ecwall commented Dec 13, 2022

Fixes #93508

Some of the multitenant admin functions accept VOTERS, NONVOTERS as input.

Add voting_replicas, non_voting_replicas columns to SHOW RANGE(S) to make working with the admin functions easier.

Release note (sql change): Add voting_replicas, non_voting_replicas columns to output of SHOW RANGE(S) statements.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

Assuming the powers who decide what columns are added to SHOW RANGES are happy with this, the change itself looks sane.

Reviewed 3 of 4 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @ecwall, @knz, and @rafiss)


pkg/sql/show_ranges_test.go line 148 at r1 (raw file):

}

func TestShowRangesColumns(t *testing.T) {

Could we write this using a LogicTest instead?

Copy link
Contributor Author

@ecwall ecwall 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 @ajwerner, @arulajmani, @knz, and @rafiss)


pkg/sql/show_ranges_test.go line 148 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Could we write this using a LogicTest instead?

Done.

Copy link
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r3, 1 of 2 files at r4, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @ecwall, @knz, and @rafiss)


pkg/sql/logictest/logic.go line 3410 at r5 (raw file):

				for i, v := range vals {
					colT := query.colTypes[i]
					// Ignore column - useful for non-deterministic output

Do we need this? Could we not instead construct the query such that the column isn't included?


pkg/sql/sqltestutils/sql_test_utils.go line 129 at r5 (raw file):

}

func ArrayStringToSlice(t *testing.T, array string, message ...string) []string {

nit: comment


pkg/sql/logictest/testdata/logic_test/ranges line 155 at r5 (raw file):

ALTER INDEX d.c@c_i_idx SPLIT AT VALUES (0)

# hex encode start_key, end_key so that text is UTF-8 compatible

What's the motivation behind this?

Copy link
Contributor Author

@ecwall ecwall 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 @ajwerner, @arulajmani, @knz, and @rafiss)


pkg/sql/logictest/logic.go line 3410 at r5 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Do we need this? Could we not instead construct the query such that the column isn't included?

I think it is useful to have the tests I added in this PR fail if columns are added/removed to indicate that the existing test case should be updated instead of adding something new.


pkg/sql/sqltestutils/sql_test_utils.go line 129 at r5 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

nit: comment

Added.

Code quote:

ArrayStringToSlice

pkg/sql/logictest/testdata/logic_test/ranges line 155 at r5 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

What's the motivation behind this?

git (including GitHub) can't diff this file because it has non-UTF-8 characters in it (these don't render in reviewable, but you can see them in GoLand). The problem still exists in this PR because the "before" file still contains these characters, but it will be fixed going forward.

diff --git a/pkg/sql/logictest/testdata/logic_test/ranges b/pkg/sql/logictest/testdata/logic_test/ranges
index b1b1342c71..9b4fb03bbd 100644
Binary files a/pkg/sql/logictest/testdata/logic_test/ranges and b/pkg/sql/logictest/testdata/logic_test/ranges differ

Copy link
Contributor Author

@ecwall ecwall 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 @ajwerner, @arulajmani, @knz, and @rafiss)


pkg/sql/logictest/testdata/logic_test/ranges line 155 at r5 (raw file):

Previously, ecwall (Evan Wall) wrote…

git (including GitHub) can't diff this file because it has non-UTF-8 characters in it (these don't render in reviewable, but you can see them in GoLand). The problem still exists in this PR because the "before" file still contains these characters, but it will be fixed going forward.

diff --git a/pkg/sql/logictest/testdata/logic_test/ranges b/pkg/sql/logictest/testdata/logic_test/ranges
index b1b1342c71..9b4fb03bbd 100644
Binary files a/pkg/sql/logictest/testdata/logic_test/ranges and b/pkg/sql/logictest/testdata/logic_test/ranges differ

image.png

Copy link
Collaborator

@arulajmani arulajmani 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 @ajwerner, @ecwall, @knz, and @rafiss)


pkg/sql/logictest/logic.go line 3410 at r5 (raw file):

Previously, ecwall (Evan Wall) wrote…

I think it is useful to have the tests I added in this PR fail if columns are added/removed to indicate that the existing test case should be updated instead of adding something new.

Even then, if all you want to do is verify column names, couldn't you achieve the same thing by doing something like:

SELECT * FROM [SHOW RANGES FROM TABLE tbl;] LIMIT 0;

pkg/sql/logictest/testdata/logic_test/ranges line 155 at r5 (raw file):

Previously, ecwall (Evan Wall) wrote…

image.png

I see, thanks for making the change! Consider saying the same in the comment, given it's not completely obvious why we're doing this.

Copy link
Contributor Author

@ecwall ecwall 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 @ajwerner, @arulajmani, @knz, and @rafiss)


pkg/sql/logictest/logic.go line 3410 at r5 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Even then, if all you want to do is verify column names, couldn't you achieve the same thing by doing something like:

SELECT * FROM [SHOW RANGES FROM TABLE tbl;] LIMIT 0;

I thought it would be useful to have a row also to make sure it is populated.

For some reason SHOW RANGES FROM DATABASE does not show any rows even if a table is added to it so I left it as is. There is a comment above that it is populated async so I don't think it should be verified here.


pkg/sql/logictest/testdata/logic_test/ranges line 155 at r5 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

I see, thanks for making the change! Consider saying the same in the comment, given it's not completely obvious why we're doing this.

Good idea, added.

Copy link
Collaborator

@arulajmani arulajmani 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 @ajwerner, @ecwall, @knz, and @rafiss)


pkg/sql/logictest/logic.go line 3410 at r5 (raw file):

For some reason SHOW RANGES FROM DATABASE does not show any rows even if a table is added to it so I left it as is.

Isn't that because there's no table inside the database?

There is a comment above that it is populated async so I don't think it should be verified here.

Yeah, given this, I'm not sure it's worth adding this new "_" symbol to the logic test grammar. It doesn't seem generally valuable, given one could just decide to omit columns they're not interested in fetching.

For our particular test case, all we're deterministically testing is the column names, which we can do using a LIMIT 0. If all we care about is this command returns rows, then we should just do a count(*).

If you feel strongly about adding this '_' symbol however, I won't stand in your way. Just add a comment about it up top in logic.go where the other symbols are described.

Copy link
Contributor

@knz knz 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 @ajwerner, @arulajmani, and @rafiss)


pkg/sql/logictest/logic.go line 3410 at r5 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

For some reason SHOW RANGES FROM DATABASE does not show any rows even if a table is added to it so I left it as is.

Isn't that because there's no table inside the database?

There is a comment above that it is populated async so I don't think it should be verified here.

Yeah, given this, I'm not sure it's worth adding this new "_" symbol to the logic test grammar. It doesn't seem generally valuable, given one could just decide to omit columns they're not interested in fetching.

For our particular test case, all we're deterministically testing is the column names, which we can do using a LIMIT 0. If all we care about is this command returns rows, then we should just do a count(*).

If you feel strongly about adding this '_' symbol however, I won't stand in your way. Just add a comment about it up top in logic.go where the other symbols are described.

SHOW RANGES FROM DATABASE is broken currently. I'm working on it.

Copy link
Contributor Author

@ecwall ecwall 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 @ajwerner, @arulajmani, and @rafiss)


pkg/sql/logictest/logic.go line 3410 at r5 (raw file):

Isn't that because there's no table inside the database?

Even after I added a table it did not have any records until I added a split to the table. SHOW RANGES FROM TABLE shows a record for a table even without a split.

If you feel strongly about adding this '_' symbol however, I won't stand in your way. Just add a comment about it up top in logic.go where the other symbols are described.

Comment added.

Fixes #93508

Some of the multitenant admin functions accept VOTERS, NONVOTERS as input.

Add voting_replicas, non_voting_replicas columns to SHOW RANGE(S) to make
working with the admin functions easier.

Release note (sql change): Add voting_replicas, non_voting_replicas columns to
output of SHOW RANGE(S) statements.
@craig
Copy link
Contributor

craig bot commented Dec 15, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Dec 16, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Dec 16, 2022

Build failed (retrying...):

@ecwall
Copy link
Contributor Author

ecwall commented Dec 16, 2022

bors r=arulajmani

@craig
Copy link
Contributor

craig bot commented Dec 16, 2022

Already running a review

@craig
Copy link
Contributor

craig bot commented Dec 16, 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.

sql: add voting_replicas, non_voting_replicas columns to SHOW RANGES
4 participants