Replies: 1 comment 1 reply
-
Another solution will be implementing cache inside user functions. This way functions have full control over cache implementation. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
few month ago, I send PR about common sub-expr climinate (CSE) .
I post a idea to implement common sub-expr eliminate, i.e. analysis common sub-expr in compile phase and real-time checking common sub-expr already used and reused result of common sub-expr in-flight. in this way, vm need to make new buffer for cache result of sub-expr in each running. In this PR, antonmedv think should done on the compile spec with AST transformation (i.g.
foo[0].bar.baz == 2 && foo[0].bar.goz == 3
=>let tmp = foo[0].bar; tmp.baz == 2 && tmp.goz == 3
). At that time, I also agreed with his idea, util I found CSE issue in datafusion. Datafusion also extract common sub-expr from original expr in optimize phase. but in this way, optimizer breaks the order of expr computing in short-circuit expr. Let me use two examples to illustrate the shortcomings of AST transformation CSE solutions.example1:
expr:
(condition1 ? sub-expr1 : sub-expr2) or sub-expr1
,sub-expr1
will be extracted from original expr. It will ignore whethercondition1
istrue
. it may cause some panic, becausesub-expr1
should is executed whencondition1
istrue
.example2:
expr:
sub-expr2 and (sub-expr1 or sub-expr3) and (sub-expr1 or sub-expr4)
,sub-expr1
will be extracted from original expr. It will ignore result ofsub-expr2
.sub-expr2
may befalse
. evaluatingsub-expr1
ahead of time will make running time longer.Now, datafusion package already prevent short-circuit expr to be eliminated. However with this kind of restriction, it is almost impossible to eliminate any common expressions.
So I think my approach is more robust and more safe (i.e. make sure correct answer and computing faster)
Beta Was this translation helpful? Give feedback.
All reactions