Skip to content

Commit

Permalink
Merge pull request #129 from igorkramaric/be-more-liberal-with-AND-ex…
Browse files Browse the repository at this point in the history
…istence-optimization

be less conservative with AND and existence optimization
  • Loading branch information
igorkramaric authored May 8, 2024
2 parents 525e31e + 6c62af3 commit 99f94ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions daffodil/hstore_predicate.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,29 @@ def forces_existence_optimizer(children):
)


def breaks_existence_optimizer(children):
def breaks_existence_optimizer(children, extra_unwanted=None):
def _breaks_existence_optimizer(expr):
if not isinstance(expr, ExpressionStr):
return True

return (
expr.daff_test in {"!=", "!in", "?="} or
(expr.daff_test == "=" and isinstance(expr.daff_val, str))
expr.daff_test in {"!=", "!in"} | extra_unwanted or
expr.daff_test in {"?="} and expr.daff_val == False
)

if extra_unwanted is None:
extra_unwanted = set()

return any(
_breaks_existence_optimizer(child_exp) for child_exp in children
)


def should_optimize_existence(children):
def should_optimize_any_existence(children):
if forces_existence_optimizer(children):
return True

if breaks_existence_optimizer(children):
if breaks_existence_optimizer(children, {"?="}):
return False

return True
Expand Down Expand Up @@ -85,7 +88,7 @@ cdef class HStoreQueryDelegate(BaseDaffodilDelegate):

sql_expr = " OR ".join(f"({child_exp})" for child_exp in children)

if should_optimize_existence(children):
if should_optimize_any_existence(children):
return self.optimize_existence(children, sql_expr, "?|", "OR")
return sql_expr

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

setup(
name='daffodil',
version='0.6.5',
version='0.6.6',
author='James Robert',
description='A Super-simple DSL for filtering datasets',
license='MIT',
Expand Down

0 comments on commit 99f94ef

Please sign in to comment.