Examples of LimitPlanNode


Examples of org.voltdb.plannodes.LimitPlanNode

                LOG.debug("SKIP - Does not contain any ReceivePlanNodes");
            return (Pair.of(false, root));
        }

        OrderByPlanNode orderby_node = null;
        LimitPlanNode limit_node = null;
       
        try {
            // If there is an OrderByPlanNode, then that we need to clone that too.
            if (orderby_nodes.size() != 0) {
                orderby_node = (OrderByPlanNode) CollectionUtil.first(orderby_nodes).clone(false, true);
                assert (orderby_node != null);
            }
            limit_node = (LimitPlanNode) CollectionUtil.first(limit_nodes).clone(false, true);
        } catch (CloneNotSupportedException ex) {
            throw new RuntimeException(ex);
        }
        assert (limit_node != null);

        if (debug.val) {
            LOG.debug("LIMIT:    " + PlanNodeUtil.debug(limit_node));
            LOG.debug("ORDER BY: " + PlanNodeUtil.debug(orderby_node));
            LOG.debug(PlanNodeUtil.getPlanNodes(root, AbstractScanPlanNode.class));
        }
        AbstractScanPlanNode scan_node = CollectionUtil.first(PlanNodeUtil.getPlanNodes(root, AbstractScanPlanNode.class));
        assert (scan_node != null) : "Unexpected PlanTree:\n" + PlanNodeUtil.debug(root);
        SendPlanNode send_node = (SendPlanNode) scan_node.getParent(0);
        assert (send_node != null);

        send_node.addIntermediary(limit_node);
        if (orderby_node != null) {
            limit_node.addIntermediary(orderby_node);
            // Need to make sure that the LIMIT has the proper output columns
            limit_node.setOutputColumns(orderby_node.getOutputColumnGUIDs());
            state.markDirty(orderby_node);
        } else {
            // Need to make sure that the LIMIT has the proper output columns
            limit_node.setOutputColumns(scan_node.getOutputColumnGUIDs());
        }
        state.markDirty(limit_node);
        if (debug.val)
            LOG.debug("PLANOPT - Added " + limit_node + " after " + scan_node);
View Full Code Here

Examples of org.voltdb.plannodes.LimitPlanNode

        Collection<LimitPlanNode> limit_nodes = PlanNodeUtil.getPlanNodes(root, LimitPlanNode.class);
        assertEquals(1, limit_nodes.size());

        Collection<SeqScanPlanNode> scan_nodes = PlanNodeUtil.getPlanNodes(root, SeqScanPlanNode.class);
        assertEquals(1, scan_nodes.size());
        LimitPlanNode inline_node = CollectionUtil.first(scan_nodes).getInlinePlanNode(PlanNodeType.LIMIT);
        assertNotNull(inline_node);
       
        // Get the Limit nodes output columns and make sure their valid
        for (LimitPlanNode limit_node : limit_nodes) {
            assertNotNull(limit_node);
View Full Code Here

Examples of org.voltdb.plannodes.LimitPlanNode

        // First check that our single scan node has an limit node
        Collection<LimitPlanNode> limit_nodes = PlanNodeUtil.getPlanNodes(root, LimitPlanNode.class);
        assertEquals(1, limit_nodes.size());

        // Get the Limit nodes output columns and make sure their valid
        LimitPlanNode limit_node = CollectionUtil.first(limit_nodes);
        assertNotNull(limit_node);
        for (int column_guid : limit_node.getOutputColumnGUIDs()) {
            PlanColumn column = PlannerContext.singleton().get(column_guid);
            // System.err.println(String.format("[%02d] %s", column_guid,
            // column));
            // System.err.println("==================");
            // System.err.println(PlannerContext.singleton().debug());
View Full Code Here

Examples of org.voltdb.plannodes.LimitPlanNode

        // First check that our single scan node has an limit node
        Collection<LimitPlanNode> limit_nodes = PlanNodeUtil.getPlanNodes(root, LimitPlanNode.class);
        assertEquals(1, limit_nodes.size());

        // Get the Limit nodes output columns and make sure their valid
        LimitPlanNode limit_node = CollectionUtil.first(limit_nodes);
        assertNotNull(limit_node);
        for (int column_guid : limit_node.getOutputColumnGUIDs()) {
            PlanColumn column = PlannerContext.singleton().get(column_guid);
            // System.err.println(String.format("[%02d] %s", column_guid,
            // column));
            // System.err.println("==================");
            // System.err.println(PlannerContext.singleton().debug());
View Full Code Here

Examples of org.voltdb.plannodes.LimitPlanNode

        }

        if ((m_parsedSelect.limit != -1) || (m_parsedSelect.limitParameterId != -1) ||
            (m_parsedSelect.offset > 0) || (m_parsedSelect.offsetParameterId != -1))
        {
            LimitPlanNode limit = new LimitPlanNode(m_context, getNextPlanNodeId());
            limit.setLimit((int) m_parsedSelect.limit);
            limit.setOffset((int) m_parsedSelect.offset);

            if (m_parsedSelect.offsetParameterId != -1) {
                ParameterInfo parameterInfo =
                    m_parsedSelect.paramsById.get(m_parsedSelect.offsetParameterId);
                limit.setOffsetParameterIndex(parameterInfo.index);
            }
            if (m_parsedSelect.limitParameterId != -1) {
                ParameterInfo parameterInfo =
                    m_parsedSelect.paramsById.get(m_parsedSelect.limitParameterId);
                limit.setLimitParameterIndex(parameterInfo.index);
            }
            limit.addAndLinkChild(root);
            limit.setOutputColumns(root.getOutputColumnGUIDs());
            root = limit;
        }
       
//        System.out.println(PlanNodeUtil.debug(root));
//        System.out.println();
View Full Code Here

Examples of org.voltdb.plannodes.LimitPlanNode

        // The coordinator's top limit graph fragment for a MP plan.
        // If planning "order by ... limit", getNextSelectPlan()
        // will have already added an order by to the coordinator frag.
        // This is the only limit node in a SP plan
        m_limitNodeTop = new LimitPlanNode();
        m_limitNodeTop.setLimit((int) m_limit);
        m_limitNodeTop.setOffset((int) m_offset);
        m_limitNodeTop.setLimitParameterIndex(limitParamIndex);
        m_limitNodeTop.setOffsetParameterIndex(offsetParamIndex);

        // check if limit can be pushed down
        m_limitCanPushdown = !m_distinct;
        if (m_limitCanPushdown) {
            for (ParsedColInfo col : m_displayColumns) {
                AbstractExpression rootExpr = col.expression;
                if (rootExpr instanceof AggregateExpression) {
                    if (((AggregateExpression)rootExpr).isDistinct()) {
                        m_limitCanPushdown = false;
                        break;
                    }
                }
            }
        }

        if (m_limitCanPushdown) {
            m_limitNodeDist = new LimitPlanNode();
            // Offset on a pushed-down limit node makes no sense, just defaults to 0
            // -- the original offset must be factored into the pushed-down limit as a pad on the limit.
            if (m_limit != -1) {
                m_limitNodeDist.setLimit((int) (m_limit + m_offset));
            }
View Full Code Here

Examples of org.voltdb.plannodes.LimitPlanNode

            // else let the parameterized forms of offset/limit default to unused/invalid.
        }
    }

    public LimitPlanNode getLimitNodeTop() {
        return new LimitPlanNode(m_limitNodeTop);
    }
View Full Code Here

Examples of org.voltdb.plannodes.LimitPlanNode

    public LimitPlanNode getLimitNodeTop() {
        return new LimitPlanNode(m_limitNodeTop);
    }

    public LimitPlanNode getLimitNodeDist() {
        return new LimitPlanNode(m_limitNodeDist);
    }
View Full Code Here

Examples of org.voltdb.plannodes.LimitPlanNode

        if (child.getPlanNodeType() == PlanNodeType.INDEXSCAN) {
            // Currently do not conflict with the optimized MIN/MAX
            // because of the big amount of tests changed.

            IndexScanPlanNode isp = (IndexScanPlanNode)child;
            LimitPlanNode limit = (LimitPlanNode)isp.getInlinePlanNode(PlanNodeType.LIMIT);
            if (limit != null && (aggplan.isTableMin() || aggplan.isTableMax())) {
                // Optimized MIN/MAX
                if (limit.getLimit() == 1 && limit.getOffset() == 0) {
                    return plan;
                }
            }
        }
View Full Code Here

Examples of org.voltdb.plannodes.LimitPlanNode

                if (sortDirection == SortDirectionType.ASC) {
                    assert(aggplan.isTableMin());
                    ispn.setSkipNullPredicate(0);
                }

                LimitPlanNode lpn = new LimitPlanNode();
                lpn.setLimit(1);
                lpn.setOffset(0);

                ispn.addInlinePlanNode(lpn);

                // remove old SeqScan node and link the new generated IndexScan node
                plan.clearChildren();
                plan.addAndLinkChild(ispn);

                return plan;
            }
        }

        if ((child instanceof IndexScanPlanNode) == false) {
            return plan;
        }

        // already have the IndexScanPlanNode
        IndexScanPlanNode ispn = (IndexScanPlanNode)child;

        // can do optimization only if it has no (post-)predicates
        // except those (post-)predicates are artifact predicates
        // we added for reverse scan purpose only
        if (((IndexScanPlanNode)child).getPredicate() != null &&
                !((IndexScanPlanNode)child).isPredicatesOptimizableForAggregate()) {
            return plan;
        }

        // Guard against (possible future?) cases of indexable subquery.
        if (((AbstractScanPlanNode)child).isSubQuery()) {
            return plan;
        }

        // 1. Handle ALL equality filters case.
        // In the IndexScanPlanNode:
        //      -- EQFilterExprs were put in searchkeyExpressions and endExpressions
        //      -- startCondition is only in searchKeyExpressions
        //      -- endCondition is only in endExpressions
        // So, if the lookup type is EQ, then all filters must be equality; or if
        // there are extra startCondition / endCondition, some filters are not equality
        // 2. Handle equality filters and one other comparison operator (<, <=, >, >=), see comments below
        if (ispn.getLookupType() != IndexLookupType.EQ &&
                Math.abs(ispn.getSearchKeyExpressions().size() - ExpressionUtil.uncombine(ispn.getEndExpression()).size()) > 1) {
            return plan;
        }

        // exprs will be used as filterExprs to check the index
        // For forward scan, the initial value is endExprs and might be changed in different values in variant cases
        // For reverse scan, the initial value is initialExprs which is the "old" endExprs
        List<AbstractExpression> exprs;
        int numOfSearchKeys = ispn.getSearchKeyExpressions().size();
        if (ispn.getLookupType() == IndexLookupType.LT || ispn.getLookupType() == IndexLookupType.LTE) {
            exprs = ExpressionUtil.uncombine(ispn.getInitialExpression());
            numOfSearchKeys -= 1;
        } else {
            exprs = ExpressionUtil.uncombine(ispn.getEndExpression());
        }
        int numberOfExprs = exprs.size();

        // If there is only 1 difference between searchkeyExprs and endExprs,
        // 1. trivial filters can be discarded, 2 possibilities:
        //      a. SELECT MIN(X) FROM T WHERE [other prefix filters] X < / <= ?
        //         <=> SELECT MIN(X) FROM T WHERE [other prefix filters] && the X < / <= ? filter
        //      b. SELECT MAX(X) FROM T WHERE X > / >= ?
        //         <=> SELECT MAX(X) FROM T with post-filter
        // 2. filter should act as equality filter, 2 possibilities
        //      SELECT MIN(X) FROM T WHERE [other prefix filters] X > / >= ?
        //      SELECT MAX(X) FROM T WHERE [other prefix filters] X < / <= ?

        // check if there is other filters for SELECT MAX(X) FROM T WHERE [other prefix filter AND ] X > / >= ?
        // but we should allow SELECT MAX(X) FROM T WHERE X = ?
        if (sortDirection == SortDirectionType.DESC && ispn.getSortDirection() == SortDirectionType.INVALID) {
            if (numberOfExprs > 1 ||
                    (numberOfExprs == 1 && aggExpr.bindingToIndexedExpression(exprs.get(0).getLeft()) == null)) {
                return plan;
            }
        }

        // have an upper bound: # of endingExpr is more than # of searchExpr
        if (numberOfExprs > numOfSearchKeys) {
            // check last ending condition, see whether it is
            //      SELECT MIN(X) FROM T WHERE [other prefix filters] X < / <= ? or
            // other filters will be checked later
            AbstractExpression lastEndExpr = exprs.get(numberOfExprs - 1);
            if ((lastEndExpr.getExpressionType() == ExpressionType.COMPARE_LESSTHAN ||
                 lastEndExpr.getExpressionType() == ExpressionType.COMPARE_LESSTHANOREQUALTO)
                    && lastEndExpr.getLeft().equals(aggExpr)) {
                exprs.remove(lastEndExpr);
            }
        }

        // do not aggressively evaluate all indexes, just examine the index currently in use;
        // because for all qualified indexes, one access plan must have been generated already,
        // and we can take advantage of that
        if (!checkIndex(ispn.getCatalogIndex(), aggExpr, exprs, ispn.getBindings(), ispn.getTargetTableAlias())) {
            return plan;
        } else {
            // we know which end we want to fetch, set the sort direction
            ispn.setSortDirection(sortDirection);

            // for SELECT MIN(X) FROM T WHERE [prefix filters] = ?
            if (numberOfExprs == numOfSearchKeys && sortDirection == SortDirectionType.ASC) {
                if (ispn.getLookupType() == IndexLookupType.GTE) {
                    assert(aggplan.isTableMin());
                    ispn.setSkipNullPredicate(numOfSearchKeys);
                }
            }

            // for SELECT MIN(X) FROM T WHERE [...] X < / <= ?
            // reset the IndexLookupType, remove "added" searchKey, add back to endExpression, and clear "added" predicate
            if (sortDirection == SortDirectionType.ASC &&
                    (ispn.getLookupType() == IndexLookupType.LT || ispn.getLookupType() == IndexLookupType.LTE)){
                ispn.setLookupType(IndexLookupType.GTE);
                ispn.removeLastSearchKey();
                ispn.addEndExpression(ExpressionUtil.uncombine(ispn.getInitialExpression()).get(numberOfExprs - 1));
                ispn.resetPredicate();
            }
            // add an inline LIMIT plan node to this index scan plan node
            LimitPlanNode lpn = new LimitPlanNode();
            lpn.setLimit(1);
            lpn.setOffset(0);
            ispn.addInlinePlanNode(lpn);

            // ENG-1565: For SELECT MAX(X) FROM T WHERE X > / >= ?, turn the pre-filter to post filter.
            // There are two choices:
            // AggregatePlanNode                AggregatePlanNode
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.