Skip to content

Fix rand() constant folding purity#6147

Open
officialasishkumar wants to merge 1 commit into
vesoft-inc:masterfrom
officialasishkumar:fix/rand-nonpure
Open

Fix rand() constant folding purity#6147
officialasishkumar wants to merge 1 commit into
vesoft-inc:masterfrom
officialasishkumar:fix/rand-nonpure

Conversation

@officialasishkumar
Copy link
Copy Markdown

What type of PR is this?

  • bug
  • feature
  • enhancement

What problem(s) does this PR solve?

Issue(s) number: #6016

Description:

rand() is registered as always pure, so constant folding may evaluate it once and replace expressions such as rand() < 0.1 with a fixed boolean. That makes random sampling predicates return either all rows or no rows.

How do you solve it?

Mark rand() as non-pure, consistent with rand32() and rand64(), so the optimizer does not fold it into a constant. Add a constant-folding unit test to keep rand() calls intact.

Special notes for your reviewer, ex. impact of this fix, design document, etc:

Local target build was blocked before reaching this change by an existing GCC 13 -Werror=interference-size warning in MemoryTracker.h. git diff --check passed.

Checklist:

Tests:

  • Unit test(positive and negative cases)
  • Function test
  • Performance test
  • N/A

Affects:

  • Documentation affected (Please add the label if documentation needs to be modified.)
  • Incompatibility (If it breaks the compatibility, please describe it and add the label.)
  • If it's needed to cherry-pick (If cherry-pick to some branches is required, please label the destination version(s).)
  • Performance impacted: Consumes more CPU/Memory

Release notes:

Please confirm whether to be reflected in release notes and how to describe:

Fixed rand() being incorrectly treated as a pure function during constant folding.

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.

1 participant