Skip to content

sql: report unit for some session variables #146430

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

Merged
merged 1 commit into from
Jun 13, 2025

Conversation

Guilherme1Rocha
Copy link
Contributor

@Guilherme1Rocha Guilherme1Rocha commented May 9, 2025

Previously, we never populated the unit column of pg_settings
virtual table deviating from PostgreSQL. We now report the unit for
time-based and memory-based settings.

AFAIU the unit defines the default unit of the value which allows these
settings take in integer numbers with the unit providing the necessary
measurement dimension.

Fixes: #30717
Release note: None

@Guilherme1Rocha Guilherme1Rocha requested a review from a team as a code owner May 9, 2025 09:48
Copy link

blathers-crl bot commented May 9, 2025

Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR.

Before a member of our team reviews your PR, I have some potential action items for you:

  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl blathers-crl bot added the O-community Originated from the community label May 9, 2025
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link

cockroachlabs-cla-agent bot commented May 9, 2025

CLA assistant check
All committers have signed the CLA.

@Guilherme1Rocha
Copy link
Contributor Author

@yuzefovich, sorry to bother you, would you mind taking a look at this PR?

I've added a map for time-related units, allowing developers to customize which unit to use. However, since PostgreSQL often normalizes time-based values to milliseconds I'm not sure how useful this mapping actually is.

If you see anything that could be improved or adjusted, please let me know. Thanks!

Copy link
Member

@yuzefovich yuzefovich 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 looking into this!

This seems reasonable to me, but I do have two high-level suggestions that should improve / simplify the change:

  • first, rather than including another return parameter into sessionVar.Get function, I think it'd be cleaner if we introduced another function GetUnit func(evalCtx *extendeEvalContext) string that would return the unit. This field can remain unset for vast majority of session variables, and the caller of sessionVar.GetUnit will be required to check that the function is non-nil. (Sorry, you had to do all the plumbing with the current approach - I hope you were able to automate it using AI tools so that not a of time / effort was spent on that.)
  • for testing, I'd be a bit cleaner to use the logic test framework. In fact, we already have a query in pkg/sql/logictest/testdata/logic_test/pg_catalog that shows the unit. I think that should be sufficient - you'll need to do something like ./dev testlogic base --files=pg_catalog --config=local --rewrite -v to update the expected output given the new behavior.

Please let me know if this makes sense and / or more details would be helpful.

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

Copy link

blathers-crl bot commented May 31, 2025

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • We notice you have more than one commit in your PR. We try break logical changes into separate commits, but commits such as "fix typo" or "address review commits" should be squashed into one commit and pushed with --force
  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@Guilherme1Rocha Guilherme1Rocha force-pushed the pkg/sql/pg_settings_unit branch from 6656445 to ce0911d Compare May 31, 2025 17:17
Copy link

blathers-crl bot commented May 31, 2025

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • We notice you have more than one commit in your PR. We try break logical changes into separate commits, but commits such as "fix typo" or "address review commits" should be squashed into one commit and pushed with --force
  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

1 similar comment
Copy link

blathers-crl bot commented May 31, 2025

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • We notice you have more than one commit in your PR. We try break logical changes into separate commits, but commits such as "fix typo" or "address review commits" should be squashed into one commit and pushed with --force
  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@yuzefovich yuzefovich force-pushed the pkg/sql/pg_settings_unit branch from c7c9422 to 072aadb Compare June 2, 2025 06:05
@yuzefovich yuzefovich requested a review from a team as a code owner June 2, 2025 06:05
@yuzefovich yuzefovich requested review from yuzefovich and removed request for a team June 2, 2025 06:05
@yuzefovich yuzefovich changed the title Fix #30717: pg_settings doesn't report unit column properly sql: report unit for some session variables Jun 2, 2025
Copy link
Member

@yuzefovich yuzefovich 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 update! I cleaned up a couple of nits and pushed the update to kick off the CI.

I still need to review this change more carefully since I find the behavior of PG somewhat non-intuitive, but there is no action needed on your part (at least for now). For example, this is a bit confusing:

yuzefovich=# select name,setting,unit from pg_settings where name = 'work_mem';
   name   | setting | unit 
----------+---------+------
 work_mem | 4096    | kB
(1 row)

yuzefovich=# show work_mem;
 work_mem 
----------
 4MB
(1 row)

Reviewed 6 of 12 files at r2, 6 of 6 files at r3, 10 of 10 files at r4, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @Guilherme1Rocha)

@yuzefovich yuzefovich force-pushed the pkg/sql/pg_settings_unit branch from 072aadb to 398111b Compare June 3, 2025 23:34
Previously, we never populated the `unit` column of `pg_settings`
virtual table deviating from PostgreSQL. We now report the unit for
time-based and memory-based settings.

AFAIU the unit defines the default unit of the value which allows these
settings take in integer numbers with the unit providing the necessary
measurement dimension.

Release note: None
@yuzefovich yuzefovich force-pushed the pkg/sql/pg_settings_unit branch from 398111b to 50c74c2 Compare June 3, 2025 23:42
Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

I refactored the change a bit to be closer to behavior of PG. @Guilherme1Rocha thanks for your contribution! :lgtm:

Reviewed 6 of 8 files at r5, 3 of 3 files at r6, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @Guilherme1Rocha)

@yuzefovich yuzefovich requested review from a team and DrewKimball and removed request for a team June 3, 2025 23:46
@yuzefovich
Copy link
Member

@DrewKimball could you please take a look at this with fresh eyes?

@yuzefovich
Copy link
Member

Friendly ping @DrewKimball (or maybe someone else from @cockroachdb/sql-queries-prs).

@DrewKimball
Copy link
Collaborator

Sorry about that, missed the initial ping. I'll take a look.

Copy link
Collaborator

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

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

:lgtm: Nice!

Reviewed 7 of 10 files at r4, 5 of 8 files at r5, 3 of 3 files at r6, all commit messages.
Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @Guilherme1Rocha)

@yuzefovich
Copy link
Member

Thanks for taking a look!

bors r=yuzefovich,drewkimball

@craig
Copy link
Contributor

craig bot commented Jun 13, 2025

@craig craig bot merged commit be2cc31 into cockroachdb:master Jun 13, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-community Originated from the community v25.3.0-prerelease
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: pg_settings doesn't report unit column properly
4 participants