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

Optimizer: IS NULL optimization #1342

Open
Tracked by #2255
liukun4515 opened this issue Nov 20, 2021 · 4 comments
Open
Tracked by #2255

Optimizer: IS NULL optimization #1342

liukun4515 opened this issue Nov 20, 2021 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@liukun4515
Copy link
Contributor

liukun4515 commented Nov 20, 2021

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

The expr column is null can be optimize if the column is not null in the schema.

If a WHERE clause includes a col_name IS NULL condition for a column that is declared as NOT NULL, that expression is optimized away.

Describe the solution you'd like

In the PG database

  1. create table
create table t1(c1 int not null, c2 int not null);

  1. select with filter
select * from where c1 is null;

The expr c1 is null can be optimized as false away.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@liukun4515 liukun4515 added the enhancement New feature or request label Nov 20, 2021
@liukun4515
Copy link
Contributor Author

@Dandandan please assign this to me.

@alamb
Copy link
Contributor

alamb commented Nov 20, 2021

@liukun4515 note this optimization is only valid prior to any OUTER joins (and maybe other operators) -- you would have to check

So like if x is non null,

SELECT ... FROM foo WHERE x IS NOT NULL

Can be rewritten to

SELECT ... FROM foo 

However,

SELECT ... FROM foo LEFT JOIN bar ON (a=b AND  x IS NOT NULL)

Can NOT be rewritten to

SELECT ... FROM foo LEFT JOIN bar ON (a=b)

The same general pattern applies in the select list

@alamb
Copy link
Contributor

alamb commented Nov 20, 2021

@liukun4515
Copy link
Contributor Author

liukun4515 commented Nov 20, 2021

ote this optimization is only valid prior to any OUTER joins

@alamb

The idea is from is null optimize.
I think the is null optimization has no side effect if the column has not null constraint.
But the is not null optimization should be checked with more cases, I will do it in the followup pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants