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

expression: move random_bytes from deferred to unfoldable functions #53795

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kennytm
Copy link
Contributor

@kennytm kennytm commented Jun 4, 2024

What problem does this PR solve?

Issue Number: close #37412

Problem Summary: RANDOM_BYTES was marked as deferred by #16367. However, this is insufficient to prevent const-folding across rows.

What changed and how does it work?

Mark RANDOM_BYTES to unfoldable rather than deferred, in the same league as RAND and UUID.

(Thanks to suggestion from @‌unconsolable)

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

When a query involving RANDOM_BYTES() returned multiple rows, the function is re-evaluated for every row in every invocation, ensuring randomness across the entire result set.

@kennytm kennytm added type/bugfix This PR fixes a bug. component/expression sig/execution SIG execution labels Jun 4, 2024
@ti-chi-bot ti-chi-bot bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jun 4, 2024
@sre-bot
Copy link
Contributor

sre-bot commented Jun 4, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

ti-chi-bot bot commented Jun 4, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign xuhuaiyu for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 4, 2024
Copy link

tiprow bot commented Jun 4, 2024

Hi @kennytm. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kennytm
Copy link
Contributor Author

kennytm commented Jun 4, 2024

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Jun 4, 2024
Copy link

codecov bot commented Jun 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.8941%. Comparing base (74034d4) to head (443cb6e).

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #53795        +/-   ##
================================================
- Coverage   73.3645%   72.8941%   -0.4705%     
================================================
  Files          1624       1675        +51     
  Lines        448069     526378     +78309     
================================================
+ Hits         328724     383699     +54975     
- Misses        99207     120871     +21664     
- Partials      20138      21808      +1670     
Flag Coverage Δ
integration 48.8924% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.8766% <ø> (-0.0713%) ⬇️
parser ∅ <ø> (∅)
br 47.6277% <ø> (+2.1147%) ⬆️

fix #37412

Signed-off-by: kennytm <kennytm@gmail.com>
@kennytm
Copy link
Contributor Author

kennytm commented Jun 4, 2024

🤔 The failure is legit. The typeinfer_test requires that:

  • RANDOM_BYTES(5) has type VARBINARY(1024) NOT NULL
  • RANDOM_BYTES('123') has type VARBINARY(1024) NOT NULL
  • RANDOM_BYTES('abc') has type VARBINARY(1024) NULL

Because this PR removed the const-folding, #23172 is not triggered and thus cannot mark RANDOM_BYTES(5) and RANDOM_BYTES('123') as NOT NULL (note that on MySQL the type is always BLOB NULL).

There are two paths to go next:

  1. We declare that RANDOM_BYTES() always return VARBINARY(1024) NULL and change the test case
    • Because RANDOM_BYTES(NULL) is a thing, we cannot declare the function return type to be VARBINARY(1024) NOT NULL always.
  2. We maintain the test case, which in turn requires creating a new category between "unfoldable" and "deferred" --- the type information is foldable but the value is not.

@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 25, 2024
@ti-chi-bot ti-chi-bot bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 25, 2024
@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 6, 2024
@ti-chi-bot ti-chi-bot bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 7, 2024
@hawkingrei
Copy link
Member

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 29, 2024
Copy link

tiprow bot commented Oct 2, 2024

@kennytm: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
fast_test_tiprow 443cb6e link true /test fast_test_tiprow

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Copy link

ti-chi-bot bot commented Oct 2, 2024

@kennytm: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
idc-jenkins-ci-tidb/build 443cb6e link true /test build
idc-jenkins-ci-tidb/check_dev_2 443cb6e link true /test check-dev2
idc-jenkins-ci-tidb/unit-test 443cb6e link true /test unit-test

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@ti-chi-bot ti-chi-bot bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression ok-to-test Indicates a PR is ready to be tested. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/execution SIG execution size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RANDOM_BYTES function is not random
3 participants