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

Do not consider non-deterministic expressions as invariants in pre-filters #7853

Merged
merged 3 commits into from
Dec 14, 2023

Conversation

dyemanov
Copy link
Member

Related to my prior commit for #1708. Even if the boolean does not access table fields it may still be non-deterministic, in this case it should not be treated as invariant and evaluated just once.

Example:

select count(*) from employee where rand() > 0.5

The condition is not correlated with any data but still produces a different result per every invocation. Prior to v5, it returned (approximately) half rows of the result set. In v5, it returns either zero rows or a half of them, depending on what was the result of RAND() during its first invocation.

Tested with constant expressions, RAND() and SQL functions defined as deterministic and non-deterministic. This patch does not detect determinism too deeply (e.g. whether a field references stream from the current scope or the outer one), only to the level currently needed for the optimizer.

{
const MetaName funcName(name);

return (funcName != "GEN_UUID" &&
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be defined in table at SysFunction::functions.

@dyemanov dyemanov merged commit f0b7429 into v5.0-release Dec 14, 2023
42 of 44 checks passed
@dyemanov dyemanov deleted the work/invariant-vs-deterministic branch December 14, 2023 17:07
@pavel-zotov
Copy link

Only 5.x is checked now.
FB 6.x has not yet improved, test will fail on it.
Waiting for front-port.

dyemanov added a commit that referenced this pull request Nov 16, 2024
…lters (#7853)

* Do not consider non-deterministic expressions as invariants in pre-filters

* Follow Adriano's suggestion

* Allow deterministic uncorrelated subqueries to be considered as invariants
@dyemanov
Copy link
Member Author

Frontported to v6.

@pavel-zotov
Copy link

QA note: removed upper bound for version after this feature was front-ported to 6.x. Checked on 6.0.0.532.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants