--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.iapi.sql.compile.OptimizablePredicateList\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.iapi.sql.compile;\r
+\r
+import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;\r
+\r
+import org.apache.derby.iapi.services.compiler.MethodBuilder;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.util.JBitSet;\r
+\r
+/**\r
+ * OptimizablePredicateList provides services for optimizing a table in a query.\r
+ * RESOLVE - the methods for this interface need to get defined.\r
+ */\r
+\r
+public interface OptimizablePredicateList \r
+{\r
+ /**\r
+ * Return the number of OptimizablePredicates in the list.\r
+ *\r
+ * @return integer The number of OptimizablePredicates in the list.\r
+ */\r
+ public int size();\r
+\r
+ /**\r
+ * Return the nth OptimizablePredicate in the list.\r
+ *\r
+ * @param n "index" (0 based) into the list.\r
+ *\r
+ * @return OptimizablePredicate The nth OptimizablePredicate in the list.\r
+ */\r
+ public OptimizablePredicate getOptPredicate(int n);\r
+\r
+ /**\r
+ * Remove the OptimizablePredicate at the specified index (0-based) from the list.\r
+ *\r
+ * @param predCtr The index.\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ void removeOptPredicate(int predCtr) throws StandardException;\r
+\r
+ /**\r
+ * Add the given OptimizablePredicate to the end of this list.\r
+ *\r
+ * @param optPredicate The predicate to add\r
+ */\r
+ void addOptPredicate(OptimizablePredicate optPredicate);\r
+\r
+ /**\r
+ * Return true if this predicate list is useful for limiting the scan on\r
+ * the given table using the given conglomerate.\r
+ *\r
+ * @param optTable An Optimizable for the table in question\r
+ * @param cd A ConglomerateDescriptor for the conglomerate in question\r
+ *\r
+ * @return true if this predicate list can limit the scan\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ boolean useful(Optimizable optTable, ConglomerateDescriptor cd)\r
+ throws StandardException;\r
+\r
+ /**\r
+ * Determine which predicates in this list are useful for limiting\r
+ * the scan on the given table using its best conglomerate. Remove\r
+ * those predicates from this list and push them down to the given\r
+ * Optimizable table. The predicates are pushed down in the order of\r
+ * the index columns that they qualify. Also, the predicates are\r
+ * "marked" as start predicates, stop predicates, or qualifier\r
+ * predicates. Finally, the start and stop operators are set in\r
+ * the given Optimizable.\r
+ *\r
+ * @param optTable An Optimizable for the table in question\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ void pushUsefulPredicates(Optimizable optTable)\r
+ throws StandardException;\r
+\r
+ /**\r
+ * Classify the predicates in this list according to the given\r
+ * table and conglomerate. Each predicate can be a start key, stop key,\r
+ * and/or qualifier, or it can be none of the above. This method\r
+ * also orders the predicates to match the order of the columns\r
+ * in a keyed conglomerate. No ordering is done for heaps.\r
+ *\r
+ * @param optTable The Optimizable table for which to classify\r
+ * the predicates in this list.\r
+ * @param cd The ConglomerateDescriptor for which to classify\r
+ * the predicates in this list.\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ void classify(Optimizable optTable, ConglomerateDescriptor cd)\r
+ throws StandardException;\r
+\r
+ /**\r
+ * Mark all of the predicates as Qualifiers and set the numberOfQualifiers\r
+ * to reflect this. This is useful for hash joins where all of the\r
+ * predicates in the list to be evaluated during the probe into the\r
+ * hash table on a next are qualifiers.\r
+ */\r
+ public void markAllPredicatesQualifiers();\r
+\r
+ /**\r
+ * Is there an optimizable equality predicate on the specified column?\r
+ *\r
+ * @param optTable The optimizable the column comes from.\r
+ * @param columnNumber The column number within the base table.\r
+ * @param isNullOkay boolean, whether or not the IS NULL operator\r
+ * satisfies the search\r
+ *\r
+ * @return Whether or not there is an optimizable equality predicate on the specified column.\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ boolean hasOptimizableEqualityPredicate(Optimizable optTable,\r
+ int columnNumber,\r
+ boolean isNullOkay)\r
+ throws StandardException;\r
+\r
+ /**\r
+ * Is there an optimizable equijoin on the specified column?\r
+ *\r
+ * @param optTable The optimizable the column comes from.\r
+ * @param columnNumber The column number within the base table.\r
+ *\r
+ * @return Whether or not there is an optimizable equijoin on the specified column.\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ boolean hasOptimizableEquijoin(Optimizable optTable,\r
+ int columnNumber)\r
+ throws StandardException;\r
+ \r
+\r
+ /**\r
+ * Find the optimizable equality predicate on the specified column and make\r
+ * it the first predicate in this list. This is useful for hash joins where\r
+ * Qualifier[0] is assumed to be on the hash key.\r
+ *\r
+ * @param optTable The optimizable the column comes from.\r
+ * @param columnNumber The column number within the base table.\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ void putOptimizableEqualityPredicateFirst(Optimizable optTable,\r
+ int columnNumber)\r
+ throws StandardException;\r
+\r
+ /**\r
+ * Transfer the predicates whose referenced set is contained by the\r
+ * specified referencedTableMap from this list to the other list.\r
+ * This is useful when splitting out a set of predicates from a larger\r
+ * set, like when generating a HashScanResultSet.\r
+ *\r
+ * @param otherList The predicateList to xfer to\r
+ * @param referencedTableMap The table map to check against\r
+ * @param table The table to order the new predicates\r
+ * against\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ public void transferPredicates(OptimizablePredicateList otherList,\r
+ JBitSet referencedTableMap,\r
+ Optimizable table)\r
+ throws StandardException;\r
+\r
+\r
+ /**\r
+ * Transfer all the predicates from this list to the given list.\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ public void transferAllPredicates(OptimizablePredicateList otherList)\r
+ throws StandardException;\r
+\r
+ /**\r
+ * Non-destructive copy of all of the predicates from this list to the\r
+ * other list.\r
+ *\r
+ * This is useful when splitting out a set of predicates from a larger\r
+ * set, like when generating a HashScanResultSet.\r
+ *\r
+ * @param otherList The predicateList to xfer to\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ public void copyPredicatesToOtherList(OptimizablePredicateList otherList)\r
+ throws StandardException;\r
+\r
+ /**\r
+ * Sets the given list to have the same elements as this one, and\r
+ * the same properties as this one (number of qualifiers and start\r
+ * and stop predicates.\r
+ *\r
+ * @param otherList The list to set the same as this one.\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ public void setPredicatesAndProperties(OptimizablePredicateList otherList)\r
+ throws StandardException;\r
+\r
+ /**\r
+ * Return whether or not the specified entry in the list is a redundant\r
+ * predicate. This is useful for selectivity calculations because we\r
+ * do not want redundant predicates included in the selectivity calculation.\r
+ *\r
+ * @param predNum The entry in the list\r
+ *\r
+ * @return Whether or not the specified entry in the list is a redundant predicate.\r
+ */\r
+ public boolean isRedundantPredicate(int predNum);\r
+\r
+ /**\r
+ * Get the start operator for the given Optimizable for a heap or\r
+ * index scan.\r
+ */\r
+ int startOperator(Optimizable optTable);\r
+\r
+ /**\r
+ * Get the stop operator for the given Optimizable for a heap or\r
+ * index scan.\r
+ */\r
+ int stopOperator(Optimizable optTable);\r
+\r
+ /**\r
+ * Generate the qualifiers for a scan. This method generates an array\r
+ * of Qualifiers, and fills them in with calls to the factory method\r
+ * for generating Qualifiers in the constructor for the activation.\r
+ * It stores the array of Qualifiers in a field in the activation, and\r
+ * returns a reference to that field.\r
+ *\r
+ * If there are no qualifiers, it initializes the array of Qualifiers\r
+ * to null.\r
+ *\r
+ * @param acb The ExpressionClassBuilderInterface for the class we are building\r
+ * @param mb The method the generated code is going into\r
+ * @param optTable The Optimizable table the Qualifiers are on\r
+ * @param absolute Generate absolute column positions if true,\r
+ * else relative column positions (within the underlying\r
+ * row)\r
+ *\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ void generateQualifiers(ExpressionClassBuilderInterface acb,\r
+ MethodBuilder mb,\r
+ Optimizable optTable,\r
+ boolean absolute)\r
+ throws StandardException;\r
+\r
+ /**\r
+ * Generate the start key for a heap or index scan.\r
+ *\r
+ * @param acb The ExpressionClassBuilderInterface for the class we're building\r
+ * @param mb The method the generated code is to go into\r
+ * @param optTable The Optimizable table the start key is for\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ void generateStartKey(ExpressionClassBuilderInterface acb,\r
+ MethodBuilder mb,\r
+ Optimizable optTable)\r
+ throws StandardException;\r
+\r
+ /**\r
+ * Generate the stop key for a heap or index scan.\r
+ *\r
+ * @param acb The ExpressionClassBuilderInterface for the class we're building\r
+ * @param mb the method the generated code is to go into\r
+ * @param optTable The Optimizable table the stop key is for\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ void generateStopKey(ExpressionClassBuilderInterface acb,\r
+ MethodBuilder mb,\r
+ Optimizable optTable)\r
+ throws StandardException;\r
+\r
+ /**\r
+ * Can we use the same key for both the start and stop key.\r
+ * This is possible when doing an exact match on an index\r
+ * where there are no other sargable predicates.\r
+ *\r
+ * @return Whether or not we can use the same key for both the start and stop key.\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ public boolean sameStartStopPosition()\r
+ throws StandardException;\r
+ \r
+ /**\r
+ * calculate the selectivity for a set of predicates. \r
+ * If statistics exist for the predicates this method uses the\r
+ * statistics. If statistics do not exist, then simply call \r
+ * selectivity for each of the predicates and return the result.\r
+ *\r
+ * @param optTable the Optimizable that the predicate list restricts.\r
+ */ \r
+ public double selectivity(Optimizable optTable) throws StandardException;\r
+ \r
+ /**\r
+ * Walk through the predicates in this list and make any adjustments\r
+ * that are required to allow for proper handling of an ORDER BY\r
+ * clause.\r
+ */\r
+ public void adjustForSortElimination(RequiredRowOrdering ordering)\r
+ throws StandardException;\r
+\r
+}\r