示例#1
0
        // locate subqueries or SRF in given expr and create plan for each
        // subquery, no change on the expr itself.
        //
        LogicNode setReturningExprCreatePlan(LogicNode root, Expr expr)
        {
            var newroot  = root;
            var subplans = new List <NamedQuery>();

            expr.VisitEachT <Expr>(e =>
            {
                if (e is SubqueryExpr x)
                {
                    Debug.Assert(expr.HasSubQuery());
                    x.query_.CreatePlan();
                    subplans.Add(new NamedQuery(x.query_, null));

                    // functionally we don't have to do rewrite since above
                    // plan is already runnable
                    if (queryOpt_.optimize_.enable_subquery_unnest_)
                    {
                        // use the plan 'root' containing the subexpr 'x'
                        var replacement = oneSubqueryToJoin(root, x);
                        newroot         = (LogicNode)newroot.SearchAndReplace(root,
                                                                              replacement);
                    }
                }
                else if (e is FuncExpr f && f.isSRF_)
                {
                    var newchild      = new LogicProjectSet(root.child_());
                    root.children_[0] = newchild;
                }
            });

            subQueries_.AddRange(subplans);
            return(newroot);
        }
示例#2
0
        // locate subqueries or SRF in given expr and create plan for each
        // subquery, no change on the expr itself.
        //
        LogicNode setReturningExprCreatePlan(LogicNode root, Expr expr)
        {
            var newroot  = root;
            var subplans = new List <NamedQuery>();

            expr.VisitEachT <Expr>(e =>
            {
                if (e is SubqueryExpr x)
                {
                    Debug.Assert(expr.HasSubQuery());
                    x.query_.cteInfo_ = this.cteInfo_;
                    x.query_.CreatePlan();
                    subplans.Add(new NamedQuery(x.query_, null, NamedQuery.QueryType.UNSURE));

                    // functionally we don't have to do rewrite since above
                    // plan is already runnable
                    if (queryOpt_.optimize_.enable_subquery_unnest_)
                    {
                        // use the plan 'root' containing the subexpr 'x'
                        bool canReplaceRoot = false;
                        var replacement     = oneSubqueryToJoin(root, x, ref canReplaceRoot);
                        newroot             = (LogicNode)newroot.SearchAndReplace(root,
                                                                                  replacement);
                        // consider  mark@1 or @2 , @2 is not unnested yet,
                        // so it can't be push down i.e. it keep as a root
                        if (canReplaceRoot)
                        {
                            root = newroot;
                        }
                    }
                }
                else if (e is FuncExpr f && f.isSRF_)
                {
                    var newchild      = new LogicProjectSet(root.child_());
                    root.children_[0] = newchild;
                }
            });

            subQueries_.AddRange(subplans);
            return(newroot);
        }