I'm sorry, but I think I introduced a little bug with my last patch.
authorBruce Momjian
Fri, 24 Jul 1998 04:03:10 +0000 (04:03 +0000)
committerBruce Momjian
Fri, 24 Jul 1998 04:03:10 +0000 (04:03 +0000)
Everyone using an [NOT] EXISTS subquery will have noticed that
already.

The bug is in "subselect.c" in the function "SS_process_sublinks()".

Here the whole function as it *SHOULD BE*:

Stephan

src/backend/optimizer/plan/subselect.c
src/tools/backend/index.html

index 040c6732ccc1aa4b411fe8869f3385a5a8ea356e..b5e4b1d8c8437d8f32af21f38e2d1adab6f9be9c 100644 (file)
@@ -404,12 +404,20 @@ SS_process_sublinks(Node *expr)
        ((Expr *) expr)->args = (List *)
            SS_process_sublinks((Node *) ((Expr *) expr)->args);
    else if (IsA(expr, SubLink))/* got it! */
-     {
-       lfirst(((Expr *) lfirst(((SubLink *)expr)->oper))->args) = 
-                 lfirst(((SubLink *)expr)->lefthand);
-
+   {
+          /* Hack to make sure expr->oper->args points to the same VAR node
+           * as expr->lefthand does. Needed for subselects in the havingQual
+           * when used on views.
+           * Otherwise aggregate functions will fail later on (at execution 
+           * time!) Reason: The rewite System makes several copies of the
+           * VAR nodes and in this case it should not do so :-( */
+       if(expr->lefthand != NULL)
+       {
+           lfirst(((Expr *) lfirst(((SubLink *)expr)->oper))->args) = 
+           lfirst(((SubLink *)expr)->lefthand);
+       }
        expr = _make_subplan((SubLink *) expr);
-     }
+   }
    
    return (expr);
 }
index 300061deae1e37a8755af239c62565758d429e3c..e1538affc41e59e3fc3dedd60c8c879685267d78 100644 (file)
@@ -78,7 +78,7 @@ queries, like INSERT and UPDATE, specify the columns
 modified by the query.  These column references are converted to 
 HREF="../../include/nodes/primnodes.h">Resdom entries, which are
 placed in target list
-entries,I> and linked together to make up the target list of
+entries,A> and linked together to make up the target list of
 the query. The target list is stored in Query.targetList, which is
 generated by 
 HREF="../../backend/parser/parse_target.c">transformTargetList().