zbtzbtzbt opened a new pull request #6518: URL: https://github.com/apache/incubator-doris/pull/6518
## Proposed changes Fold const in compoundpredicate 'OR' 'AND' to hit prefix index Related PR: - [5623](https://github.com/apache/incubator-doris/pull/5623) - [6400](https://github.com/apache/incubator-doris/pull/6400) - [3616](https://github.com/apache/incubator-doris/pull/3616) ## Types of changes What types of changes does your code introduce to Doris? _Put an `x` in the boxes that apply_ - [ ] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Documentation Update (if none of the other choices apply) - [ ] Code refactor (Modify the code structure, format the code, etc...) - [x] Optimization. Including functional usability improvements and performance improvements. - [ ] Dependency. Such as changes related to third-party components. - [ ] Other. ## Checklist _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._ - [x] I have created an issue on (Fix #ISSUE) and described the bug/feature there in detail - [x] Compiling and unit tests pass locally with my changes - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] If these changes need document changes, I have updated the document - [ ] Any dependent changes have been merged ## Further comments If this is a relatively large or complex change, kick off the discussion at d...@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc... Todo: add some unit test of the rule ## Test ````` #create table1 CREATE TABLE table1 ( siteid INT DEFAULT '10', citycode SMALLINT, username VARCHAR(32) DEFAULT '', pv BIGINT SUM DEFAULT '0' ) AGGREGATE KEY(siteid, citycode, username) DISTRIBUTED BY HASH(siteid) BUCKETS 10 PROPERTIES("replication_num" = "1"); explain select * from table1 where 2=-2 OR citycode=0; #before:PREDICATES: (FALSE OR `citycode` = 0) #after:PREDICATES: `citycode` = 0 explain select * from table1 where (2=-2) OR (citycode=0 AND 1=1); #before:PREDICATES: (FALSE OR (`citycode` = 0 AND TRUE)) #after:PREDICATES: `citycode` = 0 explain select * from table1 where (-2=2 or citycode=2) and (-2=2 or siteid=2); #before PREDICATES: (FALSE OR `citycode` = 0) and (FALSE OR `siteid` = 2) #after PREDICATES: `citycode` = 2, `siteid` = 2 ````` After add the rewrite 'OR' 'AND' rule, here are partial test cases which have passed : Until now,the added rule passed all the test case and no err caused. ````` # (true AND expr1) or (false AND expr2) ==> expr1 explain select * from table1 where (-5=-5 AND citycode=0) OR (3=2 AND siteid=2); #PREDICATES: `citycode` = 0 explain select * from table1 where citycode=0 OR (false AND siteid=2); #PREDICATES: `citycode` = 0 explain select * from table1 where citycode=0 OR (2=2 AND siteid=2); # PREDICATES: (`citycode` = 0) OR (`siteid` = 2) explain select * from table1 where citycode=0 OR ( siteid=2 AND 3!=3); #PREDICATES: `citycode` = 0 # (false or expr1) and (expr2 or false) ==> expr1 and expr2 explain select * from table1 where (-2=2 OR citycode=0) and (siteid=2 OR 2=-2); #PREDICATES: `citycode` = 0, `siteid` = 2 # (true or expr1) and (expr2 or false) ==> expr2 explain select * from table1 where (-5=-5 OR citycode=0) and (siteid=2 OR 2=-2); #PREDICATES: `siteid` = 2 # (true or expr1) and (false or expr2) ==> expr2 explain select * from table1 where (-5=-5 OR citycode=0) and (3=2 OR siteid=2); #PREDICATES: `siteid` = 2 # (true AND expr1) or (true AND expr2) ==> expr1 or expr2 explain select * from table1 where (-5=-5 AND citycode=0) OR (2=2 AND siteid=2); #PREDICATES: (`citycode` = 0) OR (`siteid` = 2) # false OR expr ==> expr explain select * from table1 where 1-3=2 OR citycode=0; #PREDICATES: `citycode` = 0 # (false OR true) OR expr ==> true explain select * from table1 where (2+1=-2 OR 1=1) OR citycode=0; #NULL PREDICATES # false AND expr ==> false explain select * from table1 where (2-3=-2) AND citycode=0; #EMPTYSET ````` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org