diff options
author | drh <drh@noemail.net> | 2018-07-28 21:01:55 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2018-07-28 21:01:55 +0000 |
commit | f559ed3400d826c494bb23bbf31d280e7fbee28f (patch) | |
tree | 57e3508fc33c324c5fa978174a102a9241ca45fd /src | |
parent | 07aded63f44d6879ead369a30b723ffed00fffc1 (diff) | |
download | sqlite-f559ed3400d826c494bb23bbf31d280e7fbee28f.tar.gz sqlite-f559ed3400d826c494bb23bbf31d280e7fbee28f.zip |
Add a small cost penalty to sorting to bias the query planner in favor of
plans that do not require a final sorting pass.
FossilOrigin-Name: 85b9beb4605eb0cfe2ed063c2a1925186c9e37031f78c875e60a347cce891638
Diffstat (limited to 'src')
-rw-r--r-- | src/where.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/where.c b/src/where.c index b7e51f3d9..722a0062a 100644 --- a/src/where.c +++ b/src/where.c @@ -4056,7 +4056,11 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ pWInfo, nRowEst, nOrderBy, isOrdered ); } - rCost = sqlite3LogEstAdd(rUnsorted, aSortCost[isOrdered]); + /* TUNING: Add a small extra penalty (5) to sorting as an + ** extra encouragment to the query planner to select a plan + ** where the rows emerge in the correct order without any sorting + ** required. */ + rCost = sqlite3LogEstAdd(rUnsorted, aSortCost[isOrdered]) + 5; WHERETRACE(0x002, ("---- sort cost=%-3d (%d/%d) increases cost %3d to %-3d\n", |