1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

Optimization: Convert an ORDER BY clause into a no-op if the query also

contains a GROUP BY clause that will force the same output order.

FossilOrigin-Name: ca9d86baf70f210d331ce93102177c8005c494cb
This commit is contained in:
drh
2010-04-26 19:17:26 +00:00
parent 93791ea0ba
commit 8c6f666b26
5 changed files with 53 additions and 26 deletions

View File

@@ -3718,6 +3718,18 @@ int sqlite3Select(
isDistinct = 0;
}
/* If there is both a GROUP BY and an ORDER BY clause and they are
** identical, then disable the ORDER BY clause since the GROUP BY
** will cause elements to come out in the correct order. This is
** an optimization - the correct answer should result regardless.
** Use the SQLITE_GroupByOrder flag with SQLITE_TESTCTRL_OPTIMIZER
** to disable this optimization for testing purposes.
*/
if( sqlite3ExprListCompare(p->pGroupBy, pOrderBy)==0
&& (db->flags & SQLITE_GroupByOrder)==0 ){
pOrderBy = 0;
}
/* If there is an ORDER BY clause, then this sorting
** index might end up being unused if the data can be
** extracted in pre-sorted order. If that is the case, then the