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

Optimize constant arithmetic #28036

Open
roji opened this issue May 16, 2022 · 1 comment
Open

Optimize constant arithmetic #28036

roji opened this issue May 16, 2022 · 1 comment

Comments

@roji
Copy link
Member

roji commented May 16, 2022

Some function translations apply arithmetic to arguments/return values; when the operands happen to be constants, we can simply compute the result in post-translation and embed the result constant.

See #28031 for an example with SQL Server's string.IndexOf.

It may be a good idea to do some non-arithmatic evaluation as well (IIRC there's some logical optimization happening in SqlNullabilityProcessor, which may make more sense in a general optimizing visitor or something).

@roji
Copy link
Member Author

roji commented Aug 11, 2024

Note: we've starting some optimizations in SqlExpressionFactory, when expressions are originally constructed; this applies the optimization very early (good), possibly unlocking other optimizations. Constant arithmetic evaluation probably falls under this umbrella too: if the operands of the unary/binary expression happen to be constants, just evaluate and return the response.

/cc @ranma42

@roji roji changed the title Optimize constant arithmetic in post-translation Optimize constant arithmetic Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants