@ Override public boolean isOrderDeterministic ( ) { if ( ! hasTopLevelScans ( ) ) { // This currently applies to parent queries that do all their // scanning in subqueries and so take on the order determinism of // their subqueries. This might have to be rethought to allow // ordering in parent queries to effect determinism of unordered // "FROM CLAUSE" subquery results. return true ; } if ( hasAOneRowResult ( ) ) { return true ; } if ( ! hasOrderByColumns ( ) ) { return false ; } // The nonOrdered expression list is used as a short-cut // -- if an expression has been determined to be // non-ordered when encountered as a GROUP BY expression, // it will also be non-ordered when encountered in the select list. ArrayList < AbstractExpression > nonOrdered = new ArrayList <> ( ) ; if ( isGrouped ( ) ) { // Does the ordering of a statements's GROUP BY columns // ensure determinism? // All display columns and order-by expressions // are functionally dependent on the GROUP BY // columns even if the display column's values // are not ordered or unique, // so ordering by ALL of the GROUP BY columns is enough // to get full determinism, // EVEN if ordering by other (dependent) expressions, // regardless of the placement of non-GROUP BY expressions // in the ORDER BY list. if ( orderByColumnsDetermineAllColumns ( m_groupByColumns , nonOrdered ) ) { return true ; } if ( orderByColumnsDetermineAllDisplayColumns ( nonOrdered ) ) { return true ; } } else { if ( orderByColumnsDetermineAllDisplayColumns ( nonOrdered ) ) { return true ; } if ( orderByColumnsCoverUniqueKeys ( ) ) { return true ; } } return false ; }
Returns true if this select statement can be proved to always produce its result rows in the same order every time that it is executed .