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

Remove unary operator inverses #27111

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

frankmcsherry
Copy link
Contributor

A better version of #27109

Motivation

Tips for reviewer

Checklist

@ggevay
Copy link
Contributor

ggevay commented May 16, 2024

So, could_error would need to be also added to the if? Unfortunately, that will exclude around 95+% of cases, but maybe not all cases, so we could still merge this with could_error. (Maybe future improvements to make could_error more precise will also help.)

But before merging, we need to fix some inverse annotations. This PR revealed that the inverse annotations on bytea_to_text and text_to_bytea are wrong, because bytea_to_text gives gibberish instead of actual text. E.g., the following slt is failing with this PR, because we get back the "hello" due to removing both casts:

query T
SELECT 'hello'::bytea::text
----
\x68656c6c6f

(I've checked that this output is consistent with Postgres.)
@frankmcsherry, could you please change these inverse annotations to #[inverse = None].

@ggevay ggevay self-requested a review May 16, 2024 09:56
@ggevay
Copy link
Contributor

ggevay commented May 16, 2024

Btw. I'm planning to extend test_smoketest_all_builtins to check the inverse annotation, which would have revealed this bug.

@ggevay ggevay mentioned this pull request May 16, 2024
5 tasks
@frankmcsherry
Copy link
Contributor Author

Well, this being green means it isn't doing anything on our test slts. I think there is at least one prod workload that would technically benefit from this, though no ideas if it unlocks any news plans.

@ggevay
Copy link
Contributor

ggevay commented May 23, 2024

@mgree could probably tell you how much this situation (or the generalized version, with other casts) occurs in customer plans.

@mgree
Copy link
Contributor

mgree commented May 29, 2024

So, could_error would need to be also added to the if? Unfortunately, that will exclude around 95+% of cases, but maybe not all cases, so we could still merge this with could_error. (Maybe future improvements to make could_error more precise will also help.)

I'm less certain about how bad the impact would be---if the could_error is on the outer function, we should be able to eliminate the cast. The idea is that erroring casts are left-inverses: text_to_varchar[k](varchar_to_text[k](s) == s for all s :: varchar(k), because we started from something known to be good. I discuss this a bit in the design doc.

@mgree could probably tell you how much this situation (or the generalized version, with other casts) occurs in customer plans.

Would you like me to run this analysis? Would probably only take a few minutes this afternoon.

@ggevay
Copy link
Contributor

ggevay commented May 29, 2024

if the could_error is on the outer function, we should be able to eliminate the cast.

Hmm, interesting! Responded there.

Would you like me to run this analysis? Would probably only take a few minutes this afternoon.

That would be great, thank you! It's hard for me to judge at the moment how often this might occur in customer plans, so it would be great to have actual data on this.

@mgree
Copy link
Contributor

mgree commented May 29, 2024

That would be great, thank you! It's hard for me to judge at the moment how often this might occur in customer plans, so it would be great to have actual data on this.

I ended up getting side-tracked with Frank today; I can take a look at this next time I'm online.

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.

None yet

3 participants