Class FromVTI

    • Field Detail

      • correlationMap

        JBitSet correlationMap
      • dependencyMap

        JBitSet dependencyMap
      • implementsVTICosting

        boolean implementsVTICosting
      • optimized

        boolean optimized
      • materializable

        boolean materializable
      • isTarget

        boolean isTarget
      • isDerbyStyleTableFunction

        boolean isDerbyStyleTableFunction
      • isRestrictedTableFunction

        boolean isRestrictedTableFunction
      • rs

        java.sql.ResultSet rs
      • numVTICols

        protected int numVTICols
      • estimatedCost

        double estimatedCost
      • estimatedRowCount

        double estimatedRowCount
      • supportsMultipleInstantiations

        boolean supportsMultipleInstantiations
      • vtiCosted

        boolean vtiCosted
      • version2

        protected boolean version2
      • implementsPushable

        private boolean implementsPushable
      • ps

        private java.sql.PreparedStatement ps
      • controlsDeferral

        private boolean controlsDeferral
      • resultSetType

        private int resultSetType
      • projectedColumnNames

        private java.lang.String[] projectedColumnNames
      • outerFromLists

        private java.util.ArrayList<FromList> outerFromLists
      • argSources

        private java.util.HashMap<java.lang.Integer,​FromTable> argSources
    • Constructor Detail

      • FromVTI

        FromVTI​(MethodCallNode invocation,
                java.lang.String correlationName,
                ResultColumnList derivedRCL,
                java.util.Properties tableProperties,
                ContextManager cm)
         throws StandardException
        Constructor.
        Parameters:
        invocation - The constructor or static method for the VTI
        correlationName - The correlation name
        derivedRCL - The derived column list
        tableProperties - Properties list associated with the table
        Throws:
        StandardException - Thrown on error
      • FromVTI

        FromVTI​(MethodCallNode invocation,
                java.lang.String correlationName,
                ResultColumnList derivedRCL,
                java.util.Properties tableProperties,
                TableName exposedTableName,
                ContextManager cm)
        Constructor.
        Parameters:
        invocation - The constructor or static method for the VTI
        correlationName - The correlation name
        derivedRCL - The derived column list
        tableProperties - Properties list associated with the table
        exposedTableName - The table name (TableName class)
        cm - The context manager
    • Method Detail

      • isDerbyStyleTableFunction

        public boolean isDerbyStyleTableFunction()
        Return true if this is a user-defined table function
      • adjustForSortElimination

        void adjustForSortElimination()
        Description copied from class: ResultSetNode
        Notify the underlying result set tree that the optimizer has chosen to "eliminate" a sort. Sort elimination can happen as part of preprocessing (see esp. SelectNode.preprocess(...)) or it can happen if the optimizer chooses an access path that inherently returns the rows in the correct order (also known as a "sort avoidance" plan). In either case we drop the sort and rely on the underlying result set tree to return its rows in the correct order. For most types of ResultSetNodes we automatically get the rows in the correct order if the sort was eliminated. One exception to this rule, though, is the case of an IndexRowToBaseRowNode, for which we have to disable bulk fetching on the underlying base table. Otherwise the index scan could return rows out of order if the base table is updated while the scan is "in progress" (i.e. while the result set is open). In order to account for this (and potentially other, similar issues in the future) this method exists to notify the result set node that it is expected to return rows in the correct order. The result set can then take necessary action to satsify this requirement--such as disabling bulk fetch in the case of IndexRowToBaseRowNode. All of that said, any ResultSetNodes for which we could potentially eliminate sorts should override this method accordingly. So we don't ever expect to get here.
        Overrides:
        adjustForSortElimination in class ResultSetNode
        See Also:
        ResultSetNode.adjustForSortElimination()
      • addOuterFromList

        public void addOuterFromList​(FromList fromList)
        Add a FromList to the collection of FromLists which bindExpressions() checks when vetting VTI arguments which reference columns in other tables. See DERBY-5554 and DERBY-5779.
      • toString

        public java.lang.String toString()
        Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.
        Overrides:
        toString in class FromTable
        Returns:
        This object as a String
      • printSubNodes

        void printSubNodes​(int depth)
        Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.
        Overrides:
        printSubNodes in class ResultSetNode
        Parameters:
        depth - The depth of this node in the tree
      • isConstructor

        boolean isConstructor()
        Return true if this VTI is a constructor. Otherwise, it is a static method.
      • getMethodCall

        final MethodCallNode getMethodCall()
        Return the constructor or static method invoked from this node
      • getExposedName

        java.lang.String getExposedName()
        Get the exposed name for this table, which is the name that can be used to refer to it in the rest of the query.
        Overrides:
        getExposedName in class FromTable
        Returns:
        The exposed name for this table.
      • getExposedTableName

        public TableName getExposedTableName()
        Returns:
        the table name used for matching with column references.
      • setTarget

        void setTarget()
        Mark this VTI as the target of a delete or update.
      • bindNonVTITables

        ResultSetNode bindNonVTITables​(DataDictionary dataDictionary,
                                       FromList fromListParam)
                                throws StandardException
        Bind the non VTI tables in this ResultSetNode. This includes getting their descriptors from the data dictionary and numbering them.
        Overrides:
        bindNonVTITables in class ResultSetNode
        Parameters:
        dataDictionary - The DataDictionary to use for binding
        fromListParam - FromList to use/append to.
        Returns:
        ResultSetNode
        Throws:
        StandardException - Thrown on error
      • getVTIName

        java.lang.String getVTIName()
        Returns:
        The name of the VTI, mainly for debugging and error messages.
      • getResultSetMetaData

        java.sql.ResultSetMetaData getResultSetMetaData()
                                                 throws StandardException
        Get the ResultSetMetaData for the class/object. We first look for the optional static method which has the same signature as the constructor. If it doesn't exist, then we instantiate an object and get the ResultSetMetaData from that object.
        Returns:
        The ResultSetMetaData from the class/object.
        Throws:
        StandardException - Thrown on error
      • getResultSetType

        public int getResultSetType()
        Returns:
        the ResultSet type of the VTI, TYPE_FORWARD_ONLY if the getResultSetType() method of the VTI class throws an exception.
      • bindExpressions

        void bindExpressions​(FromList fromListParam)
                      throws StandardException
        Bind the expressions in this VTI. This means binding the sub-expressions, as well as figuring out what the return type is for each expression.
        Overrides:
        bindExpressions in class ResultSetNode
        Parameters:
        fromListParam - FromList to use/append to.
        Throws:
        StandardException - Thrown on error
      • getNodesFromParameters

        <T extends Visitable> java.util.List<T> getNodesFromParameters​(java.lang.Class<T> nodeClass)
                                                                throws StandardException
        Get all of the nodes of the specified class from the parameters to this VTI.
        Parameters:
        nodeClass - The Class of interest.
        Returns:
        A list containing all of the nodes of interest.
        Throws:
        StandardException - Thrown on error
      • getAllResultColumns

        ResultColumnList getAllResultColumns​(TableName allTableName)
                                      throws StandardException
        Expand a "*" into a ResultColumnList with all of the result columns from the subquery.
        Overrides:
        getAllResultColumns in class ResultSetNode
        Parameters:
        allTableName - The qualifier on the "*"
        Returns:
        ResultColumnList The expanded list, or null if allTableName is non-null and doesn't match a table name in this result set
        Throws:
        StandardException - Thrown on error
      • getMatchingColumn

        ResultColumn getMatchingColumn​(ColumnReference columnReference)
                                throws StandardException
        Try to find a ResultColumn in the table represented by this FromBaseTable that matches the name in the given ColumnReference.
        Overrides:
        getMatchingColumn in class ResultSetNode
        Parameters:
        columnReference - The columnReference whose name we're looking for in the given table.
        Returns:
        A ResultColumn whose expression is the ColumnNode that matches the ColumnReference. Returns null if there is no match.
        Throws:
        StandardException - Thrown on error
      • preprocess

        ResultSetNode preprocess​(int numTables,
                                 GroupByList gbl,
                                 FromList fromList)
                          throws StandardException
        Preprocess a ResultSetNode - this currently means: o Generating a referenced table map for each ResultSetNode. o Putting the WHERE and HAVING clauses in conjunctive normal form (CNF). o Converting the WHERE and HAVING clauses into PredicateLists and classifying them. o Ensuring that a ProjectRestrictNode is generated on top of every FromBaseTable and generated in place of every FromSubquery. o Pushing single table predicates down to the new ProjectRestrictNodes.
        Overrides:
        preprocess in class ResultSetNode
        Parameters:
        numTables - The number of tables in the DML Statement
        gbl - The group by list, if any
        fromList - The from list, if any
        Returns:
        ResultSetNode at top of preprocessed tree.
        Throws:
        StandardException - Thrown on error
      • genProjectRestrict

        protected ResultSetNode genProjectRestrict​(int numTables)
                                            throws StandardException
        Put a ProjectRestrictNode on top of each FromTable in the FromList. ColumnReferences must continue to point to the same ResultColumn, so that ResultColumn must percolate up to the new PRN. However, that ResultColumn will point to a new expression, a VirtualColumnNode, which points to the FromTable and the ResultColumn that is the source for the ColumnReference. (The new PRN will have the original of the ResultColumnList and the ResultColumns from that list. The FromTable will get shallow copies of the ResultColumnList and its ResultColumns. ResultColumn.expression will remain at the FromTable, with the PRN getting a new VirtualColumnNode for each ResultColumn.expression.) We then project out the non-referenced columns. If there are no referenced columns, then the PRN's ResultColumnList will consist of a single ResultColumn whose expression is 1.
        Overrides:
        genProjectRestrict in class ResultSetNode
        Parameters:
        numTables - Number of tables in the DML Statement
        Returns:
        The generated ProjectRestrictNode atop the original FromTable.
        Throws:
        StandardException - Thrown on error
      • computeProjectionAndRestriction

        void computeProjectionAndRestriction​(PredicateList parentPredicates)
                                      throws StandardException
        Compute the projection and restriction to be pushed to the external table function if it is a RestrictedVTI. This method is called by the parent ProjectRestrictNode at code generation time. See DERBY-4357.
        Parameters:
        parentPredicates - The full list of predicates to be applied by the parent ProjectRestrictNode
        Throws:
        StandardException
      • computeProjection

        private java.util.HashMap<java.lang.String,​java.lang.String> computeProjection()
                                                                                      throws StandardException
        Fills in the array of projected column names suitable for handing to RestrictedVTI.initScan(). Returns a map of the exposed column names to the actual names of columns in the table function. This is useful because the predicate refers to the exposed column names.
        Throws:
        StandardException
      • computeRestriction

        private void computeRestriction​(PredicateList parentPredicates,
                                        java.util.HashMap<java.lang.String,​java.lang.String> columnNameMap)
                                 throws StandardException
        Fills in the restriction to be handed to a RestrictedVTI at run-time.
        Parameters:
        parentPredicates - The full list of predicates to be applied by the parent ProjectRestrictNode
        columnNameMap - Mapping between the exposed column names used in the predicates and the actual column names declared for the table function at CREATE FUNCTION time.
        Throws:
        StandardException
      • makeRestriction

        private Restriction makeRestriction​(ValueNode clause,
                                            java.util.HashMap<java.lang.String,​java.lang.String> columnNameMap)
                                     throws StandardException
        Turn a compile-time WHERE clause fragment into a run-time Restriction. Returns null if the clause could not be understood.
        Parameters:
        clause - The clause which should be turned into a Restriction.
        columnNameMap - Mapping between the exposed column names used in the predicates and the actual column names declared for the table function at CREATE FUNCTION time.
        Throws:
        StandardException
      • makeLeafRestriction

        private Restriction makeLeafRestriction​(BinaryRelationalOperatorNode clause,
                                                java.util.HashMap<java.lang.String,​java.lang.String> columnNameMap)
                                         throws StandardException
        Makes a Restriction out of a comparison between a constant and a column in the VTI.
        Parameters:
        clause - The clause which should be turned into a Restriction.
        columnNameMap - Mapping between the exposed column names used in the predicates and the actual column names declared for the table function at CREATE FUNCTION time.
        Throws:
        StandardException
      • makeIsNullRestriction

        private Restriction makeIsNullRestriction​(IsNullNode clause,
                                                  java.util.HashMap<java.lang.String,​java.lang.String> columnNameMap)
                                           throws StandardException
        Makes an IS NULL comparison of a column in the VTI.
        Parameters:
        clause - The IS NULL (or IS NOT NULL) node
        columnNameMap - Mapping between the exposed column names used in the predicates and the actual column names declared for the table function at CREATE FUNCTION time.
        Throws:
        StandardException
      • squeezeConstantValue

        private java.lang.Object squeezeConstantValue​(ValueNode valueNode)
                                               throws StandardException
        Get the constant or parameter reference out of a comparand. Return null if we are confused. A parameter reference is wrapped in an integer array to distinguish it from a constant integer.
        Throws:
        StandardException
      • remapBaseTableColumns

        private void remapBaseTableColumns()
                                    throws StandardException

        Remap the column references in vti arguments. Point those column references at the result columns for the base table. This prevents us from code-generating the args from references to unfilled columns in higher join nodes. See DERBY-5554.

        Throws:
        StandardException
      • referencesTarget

        boolean referencesTarget​(java.lang.String name,
                                 boolean baseTable)
                          throws StandardException
        Search to see if a query references the specifed table name.
        Overrides:
        referencesTarget in class ResultSetNode
        Parameters:
        name - Table name (String) to search for.
        baseTable - Whether or not name is for a base table
        Returns:
        true if found, else false
        Throws:
        StandardException - Thrown on error
      • getSpecialTriggerVTITableName

        private UUID getSpecialTriggerVTITableName​(LanguageConnectionContext lcc,
                                                   java.lang.String className)
                                            throws StandardException
        Check and see if we have a special trigger VTI. If it cannot be bound (because we aren't actually compiling or executing a trigger), then throw an exception.
        Returns:
        null if not a special trigger vti, or the table id if it is
        Throws:
        StandardException
      • isCompileTime

        public final boolean isCompileTime()
        Description copied from interface: VTIEnvironment
        Return true if this instance of the Table Function has been created for compilation, false if it is for runtime execution.
        Specified by:
        isCompileTime in interface VTIEnvironment
      • getOriginalSQL

        public java.lang.String getOriginalSQL()
        Description copied from interface: VTIEnvironment
        Return the SQL text of the original SQL statement.
        Specified by:
        getOriginalSQL in interface VTIEnvironment
      • getStatementIsolationLevel

        public final int getStatementIsolationLevel()
        Description copied from interface: VTIEnvironment
        Get the specific JDBC isolation of the statement. If it returns Connection.TRANSACTION_NONE then no isolation was specified and the connection's isolation level is implied.
        Specified by:
        getStatementIsolationLevel in interface VTIEnvironment
      • setSharedState

        public void setSharedState​(java.lang.String key,
                                   java.io.Serializable value)
        Description copied from interface: VTIEnvironment
        Saves an object associated with a key that will be maintained for the lifetime of the statement plan. Any previous value associated with the key is discarded. Any saved object can be seen by any JDBC Connection that has a Statement object that references the same statement plan.
        Specified by:
        setSharedState in interface VTIEnvironment
      • getSharedState

        public java.lang.Object getSharedState​(java.lang.String key)
        Description copied from interface: VTIEnvironment
        Get an object associated with a key from set of objects maintained with the statement plan.
        Specified by:
        getSharedState in interface VTIEnvironment
      • implementsDerbyStyleVTICosting

        private boolean implementsDerbyStyleVTICosting​(java.lang.String className)
                                                throws StandardException
        Return true if this Derby Style Table Function implements the VTICosting interface. The class must satisfy the following conditions:
        • Implements VTICosting
        • Has a public, no-arg constructor
        Throws:
        StandardException
      • lookupClass

        private java.lang.Class<?> lookupClass​(java.lang.String className)
                                        throws StandardException
        Lookup the class that holds the VTI.
        Throws:
        StandardException