From: drh Date: Thu, 16 Feb 2017 21:29:53 +0000 (+0000) Subject: Increase the estimated cost of sorting when sorting wide results sets, to X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=689ed8c89a90e41183c1ab2ca6a43b157d72aadc;p=thirdparty%2Fsqlite.git Increase the estimated cost of sorting when sorting wide results sets, to account for the extra storage space and I/O required for the external sort. FossilOrigin-Name: aa0703e5cef0c61bec965d4c88ee48bbc11c3649 --- diff --git a/manifest b/manifest index 4ce84926b2..f0dc00bb2b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sname\sof\sWhereInfo.pDistinctSet\sto\spResultSet,\ssince\sit\sis\snow\nused\sfor\smore\sthan\sjust\sDISTINCT\sprocessing. -D 2017-02-16T20:52:52.517 +C Increase\sthe\sestimated\scost\sof\ssorting\swhen\ssorting\swide\sresults\ssets,\sto\naccount\sfor\sthe\sextra\sstorage\sspace\sand\sI/O\srequired\sfor\sthe\sexternal\ssort. +D 2017-02-16T21:29:53.177 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 067a6766f800cc8d72845ab61f8de4ffe8f3fc99 @@ -475,7 +475,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 40c543f0a2195d1b0dc88ef12142bea690009344 F src/wal.h 06b2a0b599cc0f53ea97f497cf8c6b758c999f71 F src/walker.c 91a6df7435827e41cff6bb7df50ea00934ee78b0 -F src/where.c 01baf58b72f3ddb7793cdee2871f751e3e09b35e +F src/where.c 69eb9080ca38ee9cb4d149e9ef3b9fe942299251 F src/whereInt.h c0b092180f04608d80c258174b0a14a1f9c8d02f F src/wherecode.c 677e95413c472c0b413023b6b69a47f40fce1b04 F src/whereexpr.c 130cdd1a43af71b19755270fb1224874cf55158c @@ -1556,7 +1556,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ff5e733cbffd73faa4046e0f1c7f24bb6e131738 -R 771ea12d7c4097594afa32049854d91e +P 9fc5cd505fe6ab043519d68e999d2285e22452af +R 1f872b1c8c31c63af17ddb410f721ab3 +T *branch * increased-sorting-cost +T *sym-increased-sorting-cost * +T -sym-trunk * U drh -Z f13a633082a8173e1922e71dbb49e7e9 +Z a2b62b6254c86979a9aba59b56b00be7 diff --git a/manifest.uuid b/manifest.uuid index fe9afd07d4..13f024c476 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9fc5cd505fe6ab043519d68e999d2285e22452af \ No newline at end of file +aa0703e5cef0c61bec965d4c88ee48bbc11c3649 \ No newline at end of file diff --git a/src/where.c b/src/where.c index f2bf400a2d..cac951469c 100644 --- a/src/where.c +++ b/src/where.c @@ -3793,6 +3793,16 @@ static LogEst whereSortingCost( rScale = sqlite3LogEst((nOrderBy-nSorted)*100/nOrderBy) - 66; rSortCost = nRow + rScale + 16; + /* For wide sorts (many payload columns) increase the sorting cost + ** to account for the additional I/O used by the external sorting + ** algorithm when it flushes PMAs to disk. + */ + if( pWInfo->pResultSet + && pWInfo->pResultSet->nExpr>6 + ){ + rSortCost += sqlite3LogEst(pWInfo->pResultSet->nExpr) - 26; + } + /* Multiple by log(M) where M is the number of output rows. ** Use the LIMIT for M if it is smaller */ if( (pWInfo->wctrlFlags & WHERE_USE_LIMIT)!=0 && pWInfo->iLimit