GitHub user leskin-in reopened a pull request:

    https://github.com/apache/hawq/pull/1369

    HAWQ-1617. Incorrect processing of boolean operators in pushdown

    When accessing external tables, the pushdown feature sometimes works 
incorrect. Consider the following query:
    ```
    SELECT * FROM table_ex WHERE bool1=false AND id1=60003;
    ```
    When this query is executed, an error "stack is not empty ..." happens.
    
    Turns out that such query is transformed into a list of three items that 
represents the constraints: `BoolExpr`, `Var` and `OpExpr` (this is equal to a 
query `WHERE NOT(bool1 = true) AND (id1 = 60003)`). Note that the list does not 
contain (implicit) AND operators.
    
    Then, the list is processed by a [piece of code in 
pxffilters.c](https://github.com/apache/incubator-hawq/blob/master/src/backend/access/external/pxffilters.c#L1259),
 where there is a check of presence of `BoolExpr`. If expression items of this 
kind are detected, no implicit AND operators are added.
    
    In the case described, one 'BoolExpr' element is present, and no implicit 
AND operators are added. This leads to the error mentioned above.
    
    This commit changes the signatures of `enrich_trivial_expression()` and 
`pxf_free_expression_items_list()` from 
[pxffilters.c](https://github.com/apache/incubator-hawq/blob/master/src/backend/access/external/pxffilters.c)
 in order to fix the bug:
    * A number of impicit AND operators to be added is now passed to 
`add_extra_and_expression_items()`
    * `add_extra_and_expression_items()` now requires the pointer to pointer to 
`Node` object to store the pointer to an expression item for the implicit AND 
that it creates (before, it was stored in the expression item itself; however, 
due to the presence of other logical operators, we cannot rely on this 
mechanism)
    * `pxf_free_expression_items_list()` simplifies, due to the changes in the 
way how the pointer to `Node` object is stored
    
    The current mechanism of implicit AND expressions addition works well only 
while the
    OR operators are not supported (or not present in a query). When the OR 
operators appear, the implicit ANDs must be added in different parts of a 
query, not only to the end, as done now.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/arenadata/incubator-hawq HAWQ-1617

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/hawq/pull/1369.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1369
    
----
commit 3ec3d0f4d74b07581d98d0021ef66ae6efc78bea
Author: Ivan Leskin <leskin.in@...>
Date:   2018-05-25T13:19:36Z

    Fix implicit AND expression addition
    
    Fix implicit addition of extra 'BoolExpr' to a list of expression items.
    
    Before, there was a check that the expression items list did not contain 
logical operators
    (and if it did, no extra implicit AND operators were added).
    
    This behaviour is incorrect. Consider the following query:
    
    SELECT * FROM table_ex WHERE bool1=false AND id1=60003;
    
    Such query will be translated as a list of three items: 'BoolExpr', 'Var' 
and 'OpExpr'.
    Due to the presence of a 'BoolExpr', extra implicit 'BoolExpr' will not be 
added, and
    we get an error "stack is not empty ...".
    
    This commit changes the signatures of some internal functions in 
pxffilters.c to fix this error.
    We pass a number of required extra 'BoolExpr's to 
'add_extra_and_expression_items'.
    
    As 'BoolExpr's of different origin may be present in the list of expression 
items,
    the mechanism of freeing the BoolExpr node changes.
    
    The current mechanism of implicit AND expressions addition is suitable only 
before
    OR operators are introduced (in that case, we will have to add ANDs to 
different parts
    of a list, not just the end, as done now).

commit 545cb98f655d678afacfe90257079afbadcdf2ef
Author: Ivan Leskin <leskin.in@...>
Date:   2018-08-31T13:37:13Z

    Fix handling of implicit AND expressions
    
    Co-authored-by: Alex Denissov <[email protected]>
    Co-authored-by: Shivram Mani <[email protected]>
    
    Modify 'pxf_make_expression_items_list()' and 
'add_extra_and_expression_items()' so that the latter procedure processes the 
expression list completely, without any interference with 
'pxf_make_expression_items_list()'.
    
    This is identical to 
https://github.com/greenplum-db/gpdb/commit/3ac93fb4259436c87b6c1705bdb05c003ca93423;
 see also https://github.com/greenplum-db/gpdb/pull/5470.

commit 483c79cd93118425b1aaa70421f94cd922383bb1
Author: Ivan Leskin <leskin.in@...>
Date:   2018-09-03T09:47:48Z

    Fix function calls from unit tests
    
    Fix calls to 'pxf_free_expression_items_list' from unit tests (the 2nd 
parameter is always true)

----


---

Reply via email to