--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.iapi.sql.compile.RequiredRowOrdering\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.error.StandardException;\r
+\r
+import org.apache.derby.iapi.util.JBitSet;\r
+\r
+/**\r
+ * This interface provides a representation of the required ordering of rows\r
+ * from a ResultSet. Different operations can require ordering: ORDER BY,\r
+ * DISTINCT, GROUP BY. Some operations, like ORDER BY, require that the\r
+ * columns be ordered a particular way, while others, like DISTINCT and\r
+ * GROUP BY, reuire only that there be no duplicates in the result.\r
+ */\r
+public interface RequiredRowOrdering\r
+{\r
+ static final int SORT_REQUIRED = 1;\r
+ static final int ELIMINATE_DUPS = 2;\r
+ static final int NOTHING_REQUIRED = 3;\r
+\r
+ /**\r
+ * Tell whether sorting is required for this RequiredRowOrdering,\r
+ * given a RowOrdering.\r
+ *\r
+ * @param rowOrdering The order of rows in question\r
+ *\r
+ * @return SORT_REQUIRED if sorting is required,\r
+ * ELIMINATE_DUPS if no sorting is required but duplicates\r
+ * must be eliminated (i.e. the rows are in\r
+ * the right order but there may be duplicates),\r
+ * NOTHING_REQUIRED is no operation is required\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ int sortRequired(RowOrdering rowOrdering) throws StandardException;\r
+\r
+ /**\r
+ * Tell whether sorting is required for this RequiredRowOrdering,\r
+ * given a RowOrdering representing a partial join order, and\r
+ * a bit map telling what tables are represented in the join order.\r
+ * This is useful for reducing the number of cases the optimizer\r
+ * has to consider.\r
+ *\r
+ * @param rowOrdering The order of rows in the partial join order\r
+ * @param tableMap A bit map of the tables in the partial join order\r
+ *\r
+ * @return SORT_REQUIRED if sorting is required,\r
+ * ELIMINATE_DUPS if no sorting is required by duplicates\r
+ * must be eliminated (i.e. the rows are in\r
+ * the right order but there may be duplicates),\r
+ * NOTHING_REQUIRED is no operation is required\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ int sortRequired(RowOrdering rowOrdering, JBitSet tableMap)\r
+ throws StandardException;\r
+\r
+ /**\r
+ * Estimate the cost of doing a sort for this row ordering, given\r
+ * the number of rows to be sorted. This does not take into account\r
+ * whether the sort is really needed. It also estimates the number of\r
+ * result rows.\r
+ *\r
+ * @param estimatedInputRows The estimated number of rows to sort\r
+ * @param rowOrdering The ordering of the input rows\r
+ * @param resultCost A place to store the resulting cost\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ void estimateCost(double estimatedInputRows,\r
+ RowOrdering rowOrdering,\r
+ CostEstimate resultCost)\r
+ throws StandardException;\r
+\r
+ /**\r
+ * Indicate that a sort is necessary to fulfill this required ordering.\r
+ * This method may be called many times during a single optimization.\r
+ */\r
+ void sortNeeded();\r
+\r
+ /**\r
+ * Indicate that a sort is *NOT* necessary to fulfill this required\r
+ * ordering. This method may be called many times during a single\r
+ * optimization.\r
+ */\r
+ void sortNotNeeded();\r
+\r
+ boolean getSortNeeded();\r
+}\r