Skip to content

Conversation

@ggevay
Copy link
Contributor

@ggevay ggevay commented Feb 18, 2025

Char and Varchar can involve a length. Additionally, the cast functions text_to_char and text_to_varchar involve a fail_on_len option. We were not printing these extra fields in EXPLAIN and in error msgs, causing confusion in various situations, e.g.,
https://github.com/MaterializeInc/database-issues/issues/8807#issuecomment-2518662460
https://github.com/MaterializeInc/database-issues/issues/1291
#27029

The first commit attends to text_to_varchar and text_to_char.

The second commit attends to the type names, changing them in EXPLAIN, error msgs, and pg_typeof.

The third commit reverts the change for pg_typeof, to keep Postgres compatibility.

Nightly: https://buildkite.com/materialize/nightly/builds/11207

Motivation

Tips for reviewer

Checklist

  • This PR has adequate test coverage / QA involvement has been duly considered. (trigger-ci for additional test/nightly runs)
  • This PR has an associated up-to-date design doc, is a design doc (template), or is sufficiently small to not require a design.
  • If this PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way), then it is tagged with a T-proto label.
  • If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label (example).
  • If this PR includes major user-facing behavior changes, I have pinged the relevant PM to schedule a changelog post.

@ggevay ggevay requested review from a team as code owners February 18, 2025 15:57
@ggevay ggevay requested a review from ParkMyCar February 18, 2025 15:57
@ggevay ggevay added the A-CLUSTER Topics related to the CLUSTER layer label Feb 18, 2025
@ggevay ggevay changed the title Fix EXPLAIN around Char Varchar Fix EXPLAIN around Char and Varchar Feb 18, 2025
@ggevay
Copy link
Contributor Author

ggevay commented Feb 18, 2025

There is a problem: The output of pg_typeof is changing with this PR, e.g. from

character varying

to

varchar(1)

This might be a problem, because maybe some external tools rely on these being exactly what Postgres says. In that case, I'll have to separate the pg_typeof code path from the EXPLAIN code path. I'll ask the SQL council.

@ggevay ggevay marked this pull request as draft February 18, 2025 17:09
@ggevay
Copy link
Contributor Author

ggevay commented Feb 18, 2025

Will tweak the PR to not change pg_typeof. Council discussion.

@ggevay ggevay force-pushed the char-varchar-printing branch 3 times, most recently from 3defdae to a846d48 Compare February 19, 2025 13:10
@ggevay ggevay marked this pull request as ready for review February 19, 2025 13:53
@ggevay ggevay requested a review from mgree February 19, 2025 14:59
Copy link
Contributor

@mgree mgree left a comment

Choose a reason for hiding this comment

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

Looks good to me. I like the new, clearer output. There's some risk of using non postgres_compat output in error messages leading people to get confused about type names. Not a huge risk, likely better this way.

self.fail_on_len
)
}
None => f.write_str("text_to_char[len=None]"),
Copy link
Contributor

Choose a reason for hiding this comment

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

The None is a Rust-ism:

Suggested change
None => f.write_str("text_to_char[len=None]"),
None => f.write_str("text_to_char[len=unbounded]"),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, unbounded is indeed better!

Ok(elem_type) => elem_type,
Err(elem_type) => bail_unsupported!(
format!("array_fill on {}", ecx.humanize_scalar_type(&elem_type))
format!("array_fill on {}", ecx.humanize_scalar_type(&elem_type, false))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
format!("array_fill on {}", ecx.humanize_scalar_type(&elem_type, false))
// This will be used in error msgs, therefore we call with `postgres_compat` false.
format!("array_fill on {}", ecx.humanize_scalar_type(&elem_type, false))

... and probably similar at other uses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed this one. Generally, I didn't add this comment to all call sites, only to those where it was not immediately clear whether it's only used in an error msg.

# Fixes database-issues#5222

query error db error: ERROR: coalesce could not convert type "char" to character
query error db error: ERROR: coalesce could not convert type "char" to char
Copy link
Contributor

Choose a reason for hiding this comment

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

Oof, tough error message!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, life is just harsh! :D

But one thing we could possibly do here is to print it more verbosely when postgres_compat is off. For example, we could print it as "char" aka PgLegacyChar. See this comment. What do you think @mgree ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry to miss this. I think we can let it be confusing for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. We can do it in a follow-up PR if we think so later.

@ggevay ggevay force-pushed the char-varchar-printing branch from a846d48 to 377a61e Compare February 20, 2025 11:19
@ggevay ggevay enabled auto-merge February 20, 2025 11:21
@ggevay
Copy link
Contributor Author

ggevay commented Feb 20, 2025

Thanks for the review! Merging.

If we decide to do something about the could not convert type "char" to char error msg, then I'll open a follow-up PR for that.

(The Nightly failure is unrelated.)

@ggevay ggevay merged commit c962d78 into MaterializeInc:main Feb 20, 2025
80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLUSTER Topics related to the CLUSTER layer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants