Package org.voltdb.planner

Examples of org.voltdb.planner.StatementPartitioning


        VoltType partitionParamType = null;
        Object partitionParamValue = null;
        assert(work.sqlStatements != null);
        // Take advantage of the planner optimization for inferring single partition work
        // when the batch has one statement.
        StatementPartitioning partitioning = null;
        boolean inferSP = (work.sqlStatements.length == 1) && work.inferPartitioning;
        for (final String sqlStatement : work.sqlStatements) {
            if (inferSP) {
                partitioning = StatementPartitioning.inferPartitioning();
            }
View Full Code Here


            }
        }
    }

    public AdHocPlannedStatement planSqlForTest(String sqlIn) {
        StatementPartitioning infer = StatementPartitioning.inferPartitioning();
        return planSql(sqlIn, infer);
    }
View Full Code Here

            // add the statement to the catalog
            Statement catalogStmt = procedure.getStatements().add(stmtName);

            // compile the statement
            StatementPartitioning partitioning =
                info.singlePartition ? StatementPartitioning.forceSP() :
                                       StatementPartitioning.forceMP();
            StatementCompiler.compile(compiler, hsql, catalog, db,
                    estimates, catalogStmt, stmt.getText(), stmt.getJoinOrder(),
                    detMode, partitioning);

            if (partitioning.wasSpecifiedAsSingle()) {
                procWantsCommonPartitioning = false; // Don't try to infer what's already been asserted.
                // The planner does not currently attempt to second-guess a plan declared as single-partition, maybe some day.
                // In theory, the PartitioningForStatement would confirm the use of (only) a parameter as a partition key --
                // or if the partition key was determined to be some other constant (expression?) it might display an informational
                // message that the passed parameter is assumed to be equal to the hard-coded partition key constant (expression).

                // Validate any inferred statement partitioning given the statement's possible usage, until a contradiction is found.
            }
            else if (procWantsCommonPartitioning) {
                // Only consider statements that are capable of running SP with a partitioning parameter that does not seem to
                // conflict with the partitioning of prior statements.
                if (partitioning.getCountOfIndependentlyPartitionedTables() == 1) {
                    AbstractExpression statementPartitionExpression = partitioning.singlePartitioningExpressionForReport();
                    if (statementPartitionExpression != null) {
                        if (commonPartitionExpression == null) {
                            commonPartitionExpression = statementPartitionExpression;
                            exampleSPstatement = stmt.getText();
                            exampleSPvalue = partitioning.getInferredPartitioningValue();
                        }
                        else if (commonPartitionExpression.equals(statementPartitionExpression) ||
                                   (statementPartitionExpression instanceof ParameterValueExpression &&
                                    commonPartitionExpression instanceof ParameterValueExpression)) {
                            // Any constant used for partitioning would have to be the same for all statements, but
                            // any statement parameter used for partitioning MIGHT come from the same proc parameter as
                            // any other statement's parameter used for partitioning.
                        }
                        else {
                            procWantsCommonPartitioning = false; // appears to be different partitioning for different statements
                        }
                    }
                    else {
                        // There is a statement with a partitioned table whose partitioning column is
                        // not equality filtered with a constant or param. Abandon all hope.
                        procWantsCommonPartitioning = false;
                    }

                // Usually, replicated-only statements in a mix with others have no effect on the MP/SP decision
                }
                else if (partitioning.getCountOfPartitionedTables() == 0) {
                    // but SP is strictly forbidden for DML, to maintain the consistency of the replicated data.
                    if (partitioning.getIsReplicatedTableDML()) {
                        procWantsCommonPartitioning = false;
                    }

                }
                else {
View Full Code Here

        // add the statement to the catalog
        Statement catalogStmt = procedure.getStatements().add(VoltDB.ANON_STMT_NAME);

        // compile the statement
        StatementPartitioning partitioning =
            info.singlePartition ? StatementPartitioning.forceSP() :
                                   StatementPartitioning.forceMP();
        // default to FASTER detmode because stmt procs can't feed read output into writes
        StatementCompiler.compile(compiler, hsql, catalog, db,
                estimates, catalogStmt, procedureDescriptor.m_singleStmt,
                procedureDescriptor.m_joinOrder, DeterminismMode.FASTER, partitioning);

        // if the single stmt is not read only, then the proc is not read only
        boolean procHasWriteStmts = (catalogStmt.getReadonly() == false);

        // set the read onlyness of a proc
        procedure.setReadonly(procHasWriteStmts == false);

        int seqs = catalogStmt.getSeqscancount();
        procedure.setHasseqscans(seqs > 0);

        // set procedure parameter types
        CatalogMap<ProcParameter> params = procedure.getParameters();
        CatalogMap<StmtParameter> stmtParams = catalogStmt.getParameters();

        // set the procedure parameter types from the statement parameter types
        int paramCount = 0;
        for (StmtParameter stmtParam : CatalogUtil.getSortedCatalogItems(stmtParams, "index")) {
            // name each parameter "param1", "param2", etc...
            ProcParameter procParam = params.add("param" + String.valueOf(paramCount));
            procParam.setIndex(stmtParam.getIndex());
            procParam.setIsarray(stmtParam.getIsarray());
            procParam.setType(stmtParam.getJavatype());
            paramCount++;
        }

        // parse the procinfo
        procedure.setSinglepartition(info.singlePartition);
        if (info.singlePartition) {
            parsePartitionInfo(compiler, db, procedure, info.partitionInfo);
            if (procedure.getPartitionparameter() >= params.size()) {
                String msg = "PartitionInfo parameter not a valid parameter for procedure: " + procedure.getClassname();
                throw compiler.new VoltCompilerException(msg);
            }
            // TODO: The planner does not currently validate that a single-statement plan declared as single-partition correctly uses
            // the designated parameter as a partitioning filter, maybe some day.
            // In theory, the PartitioningForStatement would confirm the use of (only) a parameter as a partition key --
            // or if the partition key was determined to be some other hard-coded constant (expression?) it might display a warning
            // message that the passed parameter is assumed to be equal to that constant (expression).
        } else {
            if (partitioning.getCountOfIndependentlyPartitionedTables() == 1) {
                AbstractExpression statementPartitionExpression = partitioning.singlePartitioningExpressionForReport();
                if (statementPartitionExpression != null) {
                    // The planner has uncovered an overlooked opportunity to run the statement SP.
                    String msg = null;
                    if (statementPartitionExpression instanceof ParameterValueExpression) {
                        msg = "This procedure would benefit from setting the attribute 'partitioninfo=" + partitioning.getFullColumnName() +
                                ":" + ((ParameterValueExpression) statementPartitionExpression).getParameterIndex() + "'";
                    } else {
                        String valueDescription = null;
                        Object partitionValue = partitioning.getInferredPartitioningValue();
                        if (partitionValue == null) {
                            // Statement partitioned on a runtime constant. This is likely to be cryptic, but hopefully gets the idea across.
                            valueDescription = "of " + statementPartitionExpression.explain("");
                        } else {
                            valueDescription = partitionValue.toString(); // A simple constant value COULD have been a parameter.
                        }
                        msg = "This procedure would benefit from adding a parameter to be passed the value " + valueDescription +
                                " and setting the attribute 'partitioninfo=" + partitioning.getFullColumnName() +
                                ":" + paramCount  + "'";
                    }
                    compiler.addWarn(msg);
                }
            }
View Full Code Here

     */
    public void promoteSinglePartitionInfo(
            HashMap<AbstractExpression, Set<AbstractExpression>> valueEquivalence,
            Set< Set<AbstractExpression> > eqSets)
    {
        StatementPartitioning stmtPartitioning = getPartitioningForStatement();

        if (stmtPartitioning.getCountOfPartitionedTables() == 0 ||
            stmtPartitioning.requiresTwoFragments()) {
            return;
        }
        // this sub-query is single partitioned query on partitioned tables
        // promoting the single partition express up the its parent level
        AbstractExpression spExpr = stmtPartitioning.singlePartitioningExpression();

        for (SchemaColumn col: m_partitioningColumns) {
            AbstractExpression tveKey = col.getExpression();
            assert(tveKey instanceof TupleValueExpression);
            Set<AbstractExpression> values = null;
View Full Code Here

TOP

Related Classes of org.voltdb.planner.StatementPartitioning

Copyright © 2018 www.massapicom. 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.