Skip to content

Commit

Permalink
Fix boolean expression handling in query document building.
Browse files Browse the repository at this point in the history
Reported on GitHub through issue #58 by simon-wolf.

FDW-631, Vaibhav Dalvi, reviewed by Jeevan Chalke.
  • Loading branch information
jeevanchalke committed Jul 6, 2023
1 parent d5d8084 commit d742be9
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 2 deletions.
3 changes: 1 addition & 2 deletions deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,7 @@ mongo_append_bool_expr(BoolExpr *node, BSON *child_doc, pipeline_cxt *context)
break;
case NOT_EXPR:
op = "$not";
mongo_append_expr(linitial(node->args), child_doc, context);
return;
break;
}

bsonAppendStartObject(child_doc, psprintf("%d", context->arrayIndex), &expr);
Expand Down
37 changes: 37 additions & 0 deletions expected/pushdown.out
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,43 @@ SELECT c1, c4 FROM f_test_tbl1

ALTER SERVER mongo_server OPTIONS (SET enable_order_by_pushdown 'true');
ALTER FOREIGN TABLE f_test_tbl1 OPTIONS (SET enable_order_by_pushdown 'true');
-- FDW-631: Test pushdown of boolean expression
EXPLAIN (VERBOSE, COSTS FALSE)
SELECT name, pass FROM f_test_tbl3 WHERE pass = false ORDER BY name;
QUERY PLAN
--------------------------------------------------------
Sort
Output: name, pass
Sort Key: f_test_tbl3.name
-> Foreign Scan on public.f_test_tbl3
Output: name, pass
Foreign Namespace: mongo_fdw_regress.test_tbl3
(6 rows)

SELECT name, pass FROM f_test_tbl3 WHERE pass = false ORDER BY name;
name | pass
------+------
dvd | f
(1 row)

EXPLAIN (VERBOSE, COSTS FALSE)
SELECT name, pass FROM f_test_tbl3 WHERE pass = true ORDER BY name;
QUERY PLAN
--------------------------------------------------------
Sort
Output: name, pass
Sort Key: f_test_tbl3.name
-> Foreign Scan on public.f_test_tbl3
Output: name, pass
Foreign Namespace: mongo_fdw_regress.test_tbl3
(6 rows)

SELECT name, pass FROM f_test_tbl3 WHERE pass = true ORDER BY name;
name | pass
------+------
vdd | t
(1 row)

-- Cleanup
DELETE FROM f_mongo_test WHERE a != 0;
DELETE FROM f_test_tbl2 WHERE c1 IS NULL;
Expand Down
39 changes: 39 additions & 0 deletions expected/pushdown_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,45 @@ ALTER SERVER mongo_server OPTIONS (SET enable_order_by_pushdown 'true');
ERROR: option "enable_order_by_pushdown" not found
ALTER FOREIGN TABLE f_test_tbl1 OPTIONS (SET enable_order_by_pushdown 'true');
ERROR: option "enable_order_by_pushdown" not found
-- FDW-631: Test pushdown of boolean expression
EXPLAIN (VERBOSE, COSTS FALSE)
SELECT name, pass FROM f_test_tbl3 WHERE pass = false ORDER BY name;
QUERY PLAN
--------------------------------------------------------
Sort
Output: name, pass
Sort Key: f_test_tbl3.name
-> Foreign Scan on public.f_test_tbl3
Output: name, pass
Filter: (NOT f_test_tbl3.pass)
Foreign Namespace: mongo_fdw_regress.test_tbl3
(7 rows)

SELECT name, pass FROM f_test_tbl3 WHERE pass = false ORDER BY name;
name | pass
------+------
dvd | f
(1 row)

EXPLAIN (VERBOSE, COSTS FALSE)
SELECT name, pass FROM f_test_tbl3 WHERE pass = true ORDER BY name;
QUERY PLAN
--------------------------------------------------------
Sort
Output: name, pass
Sort Key: f_test_tbl3.name
-> Foreign Scan on public.f_test_tbl3
Output: name, pass
Filter: f_test_tbl3.pass
Foreign Namespace: mongo_fdw_regress.test_tbl3
(7 rows)

SELECT name, pass FROM f_test_tbl3 WHERE pass = true ORDER BY name;
name | pass
------+------
vdd | t
(1 row)

-- Cleanup
DELETE FROM f_mongo_test WHERE a != 0;
DELETE FROM f_test_tbl2 WHERE c1 IS NULL;
Expand Down
8 changes: 8 additions & 0 deletions sql/pushdown.sql
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,14 @@ SELECT c1, c4 FROM f_test_tbl1
ALTER SERVER mongo_server OPTIONS (SET enable_order_by_pushdown 'true');
ALTER FOREIGN TABLE f_test_tbl1 OPTIONS (SET enable_order_by_pushdown 'true');

-- FDW-631: Test pushdown of boolean expression
EXPLAIN (VERBOSE, COSTS FALSE)
SELECT name, pass FROM f_test_tbl3 WHERE pass = false ORDER BY name;
SELECT name, pass FROM f_test_tbl3 WHERE pass = false ORDER BY name;
EXPLAIN (VERBOSE, COSTS FALSE)
SELECT name, pass FROM f_test_tbl3 WHERE pass = true ORDER BY name;
SELECT name, pass FROM f_test_tbl3 WHERE pass = true ORDER BY name;

-- Cleanup
DELETE FROM f_mongo_test WHERE a != 0;
DELETE FROM f_test_tbl2 WHERE c1 IS NULL;
Expand Down

0 comments on commit d742be9

Please sign in to comment.