Examples of StmtSubqueryScan


Examples of org.voltdb.planner.parseinfo.StmtSubqueryScan

            // In such a case, the table is valid for use by MP queries only and can only be joined with replicated tables
            // because it has no recognized partitioning join key.
            List<SchemaColumn> columnsNeedingCoverage = tableScan.getPartitioningColumns();

            if (tableScan instanceof StmtSubqueryScan) {
                StmtSubqueryScan subScan = (StmtSubqueryScan) tableScan;
                subScan.promoteSinglePartitionInfo(valueEquivalence, eqSets);

                if (subScan.hasReceiveNode()) {
                    if (subqueryHasReceiveNode) {
                        // Has found another subquery with receive node on the same level
                        // Not going to support this kind of subquery join with 2 fragment plan.
                        m_joinValid = false;

                        // Still needs to count the independent partition tables
                        break;
                    }
                    subqueryHasReceiveNode = true;

                    if (subScan.isTableAggregate()) {
                        // Partition Table Aggregate only return one aggregate row.
                        // It has been marked with receive node, any join or processing based on
                        // this table aggregate subquery should be done on coordinator.
                        // Joins: has to be replicated table
                        // Any process based on this subquery should require 1 fragment only.
View Full Code Here

Examples of org.voltdb.planner.parseinfo.StmtSubqueryScan

        StmtTableScan tableScan = m_tableAliasMap.get(tableAlias);
        if (tableScan == null) {
            if (subquery == null) {
                tableScan = new StmtTargetTableScan(getTableFromDB(tableName), tableAlias);
            } else {
                tableScan = new StmtSubqueryScan(subquery, tableAlias);
            }
            m_tableAliasMap.put(tableAlias, tableScan);
        }
        return tableScan;
    }
View Full Code Here

Examples of org.voltdb.planner.parseinfo.StmtSubqueryScan

        for (VoltXMLElement node : stmtNode.children) {
            if (node.name.equalsIgnoreCase("columns")) {
                parseTargetColumns(node, table, m_columns);
            }
            else if (node.name.equalsIgnoreCase(SELECT_NODE_NAME)) {
                m_subquery = new StmtSubqueryScan (parseSubquery(node), "__VOLT_INSERT_SUBQUERY__");
            }
            else if (node.name.equalsIgnoreCase(UNION_NODE_NAME)) {
                throw new PlanningErrorException(
                        "INSERT INTO ... SELECT is not supported for UNION or other set operations.");
            }
View Full Code Here

Examples of org.voltdb.planner.parseinfo.StmtSubqueryScan

        // End of recursion
        AbstractPlanNode scanNode = getAccessPlanForTable(joinNode);
        // Connect the sub-query tree if any
        if (joinNode instanceof SubqueryLeafNode) {
            StmtSubqueryScan tableScan = ((SubqueryLeafNode)joinNode).getSubqueryScan();
            CompiledPlan subQueryPlan = tableScan.getBestCostPlan();
            assert(subQueryPlan != null);
            assert(subQueryPlan.rootPlanGraph != null);
            // The sub-query best cost plan needs to be un-linked from the previous parent plan
            // it's the same child plan that gets re-attached to many parents one at a time
            subQueryPlan.rootPlanGraph.disconnectParents();
View Full Code Here

Examples of org.voltdb.planner.parseinfo.StmtSubqueryScan

        m_bestAndOnlyPlanWasGenerated = true;
        ParsedInsertStmt insertStmt = (ParsedInsertStmt)m_parsedStmt;
        Table targetTable = insertStmt.m_tableList.get(0);
        targetTable.getTypeName();
        StmtSubqueryScan subquery = insertStmt.getSubqueries().get(0);

        if (targetTable.getIsreplicated()) {
            // must not be single-partition insert if targeting a replicated table
            // setUpForNewPlans already validates this
            assert(! m_partitioning.wasSpecifiedAsSingle() && ! m_partitioning.isInferredSingle());

            // Cannot access any partitioned tables in subquery for replicated table
            if (! subquery.getIsReplicated()) {
                throw new PlanningErrorException("Subquery in "+ getSqlType() +" INTO ... SELECT statement may not access " +
                                                 "partitioned data for insertion into replicated table " + targetTable.getTypeName() + ".");
            }
        }
        else if (! m_partitioning.wasSpecifiedAsSingle()) {
            //        [assume that c1 is the partitioning column]
            //        INSERT INTO t1 (c1, c2, c3, ...)
            //        SELECT e1, e2, e3, ... FROM ...
            //
            //        can be analyzed as if it was
            //
            //        SELECT COUNT(*)
            //        FROM t1
            //          INNER JOIN
            //            (SELECT e1, e2, e3, ... FROM ...) AS insert_subquery
            //            ON t1.c1 = insert_subquery.e1;
            //
            // Build the corresponding data structures for analysis by StatementPartitioning.

            if (subquery.getBestCostPlan().rootPlanGraph.hasAnyNodeOfType(PlanNodeType.SEND)) {
                // What is the appropriate level of detail for this message?
                m_recentErrorMsg = getSqlType() +" INTO ... SELECT statement subquery is too complex.  " +
                    "Please either simplify the subquery or use a SELECT followed by an INSERT.";
                return null;
            }

            List<StmtTableScan> tables = new ArrayList<>();
            StmtTargetTableScan stmtTargetTableScan = new StmtTargetTableScan(targetTable, targetTable.getTypeName());
            tables.add(stmtTargetTableScan);
            tables.add(subquery);

            // Create value equivalence between the partitioning column of the target table
            // and the corresponding expression produced by the subquery.

            HashMap<AbstractExpression, Set<AbstractExpression>>  valueEquivalence = new HashMap<>();
            int i = 0;
            Column partitioningCol = targetTable.getPartitioncolumn();
            boolean setEquivalenceForPartitioningCol = false;
            for (Column col : insertStmt.m_columns.keySet()) {
                if (partitioningCol.compareTo(col) == 0) {
                    List<SchemaColumn> partitioningColumns = stmtTargetTableScan.getPartitioningColumns();
                    assert(partitioningColumns.size() == 1);
                    AbstractExpression targetPartitionColExpr = partitioningColumns.get(0).getExpression();
                    TupleValueExpression selectedExpr = subquery.getOutputExpression(i);
                    assert(!valueEquivalence.containsKey(targetPartitionColExpr));
                    assert(!valueEquivalence.containsKey(selectedExpr));

                    Set<AbstractExpression> equivSet = new HashSet<>();
                    equivSet.add(targetPartitionColExpr);
                    equivSet.add(selectedExpr);

                    valueEquivalence.put(targetPartitionColExpr,  equivSet);
                    valueEquivalence.put(selectedExpr,  equivSet);
                    setEquivalenceForPartitioningCol = true;

                }
                ++i;
            }

            if (!setEquivalenceForPartitioningCol) {
                // partitioning column of target table is not being set from value produced by the subquery.
                m_recentErrorMsg = "Partitioning column must be assigned a value " +
                    "produced by the subquery in an "+ getSqlType() +" INTO ... SELECT statement.";
                return null;
            }

            m_partitioning.analyzeForMultiPartitionAccess(tables, valueEquivalence);

            if (! m_partitioning.isJoinValid()) {
                m_recentErrorMsg = "Partitioning could not be determined for "+ getSqlType() +" INTO ... SELECT statement.  " +
                    "Please ensure that statement does not attempt to copy row data from one partition to another, " +
                    "which is unsupported.";
                return null;
            }
        }


        return subquery.getBestCostPlan().rootPlanGraph;
    }
View Full Code Here

Examples of org.voltdb.planner.parseinfo.StmtSubqueryScan

        //       the child node is the root of an arbitrary subplan.

        // figure out which table we're inserting into
        assert (m_parsedInsert.m_tableList.size() == 1);
        Table targetTable = m_parsedInsert.m_tableList.get(0);
        StmtSubqueryScan subquery = m_parsedInsert.isInsertWithSubquery() ?
                m_parsedInsert.getSubqueries().get(0) : null;

        CompiledPlan retval = null;
        if (subquery != null) {

            if (subquery.getBestCostPlan() == null) {
                // Seems like this should really be caught earlier
                // in getBestCostPlan, above.
                throw new PlanningErrorException("INSERT INTO ... SELECT subquery could not be planned: "
                        + m_recentErrorMsg);

            }

            InsertSubPlanAssembler subPlanAssembler =
                    new InsertSubPlanAssembler(m_catalogDb, m_parsedInsert, m_partitioning);
            AbstractPlanNode subplan = subPlanAssembler.nextPlan();
            if (subplan == null) {
                throw new PlanningErrorException(subPlanAssembler.m_recentErrorMsg);
            }
            assert(m_partitioning.isJoinValid());

            //  Use the subquery's plan as the basis for the insert plan.
            retval = subquery.getBestCostPlan();
        }
        else {
            retval = new CompiledPlan();
        }
        retval.setReadOnly(false);
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.