From: drh Date: Fri, 17 Feb 2017 21:23:25 +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=refs%2Fheads%2Fapple-increased-sorting-cost;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: 38298ef923c8dad6860385ac4a20849eeac2d174 --- diff --git a/manifest b/manifest index f8c34d5338..22cc8c4e47 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sopening\sthe\s*-shm\sfile\sfor\sa\sreadonly\sdatabase,\stry\sto\sopen\sit\sin\sread-write\smode\sbefore\sfalling\sback\sto\sreadonly.\sThis\sis\sin\scase\ssome\sother\sread/write\sconnection\swithin\sthe\ssame\sprocess\suses\sthe\ssame\sfile\sdescriptor. -D 2016-11-17T14:02:50.490 +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-17T21:23:25.595 F Makefile.in c9c70541089a9755069a9dad0b609cf14a382649 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc a8af814f63c124db048517b63a0b8650c3fc26fc @@ -472,7 +472,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c b782fa386a4f7b5a8c974f481d8bc004464849a2 F src/wal.h 8fed212c25dc0b33abb9c287ccd8e242796a73e8 F src/walker.c 91a6df7435827e41cff6bb7df50ea00934ee78b0 -F src/where.c 952f76e7a03727480b274b66ca6641b1657cd591 +F src/where.c a7a99b84a975d1c0518c72041ff6c3a9898fd102 F src/whereInt.h 2bcc3d176e6091cb8f50a30b65c006e88a73614d F src/wherecode.c 717a65294df46f30e9b9933d2a63a4bcbca5a9a8 F src/whereexpr.c a83d70154f3bbce5051a7e9710021f647c0fe4f2 @@ -1535,7 +1535,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0e5ffd9123d6d2d2b8f3701e8a73cc98a3a7ff5f -R dd715a7090f8ccbb07a44c145e36e97f -U dan -Z dc2784f452c216a6da4c2c53fde33522 +P a07c581e88aa4d9835f6144c0fd5e58ef42f14ac +Q +aa0703e5cef0c61bec965d4c88ee48bbc11c3649 +R f99a043c5d8ac4d72fc50b0745a12dd6 +T *branch * apple-increased-sorting-cost +T *sym-apple-increased-sorting-cost * +T -sym-apple-osx * +U drh +Z a2fb6a39b09ee759202942947acdb999 diff --git a/manifest.uuid b/manifest.uuid index 958987df12..63a0598478 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a07c581e88aa4d9835f6144c0fd5e58ef42f14ac \ No newline at end of file +38298ef923c8dad6860385ac4a20849eeac2d174 \ No newline at end of file diff --git a/src/where.c b/src/where.c index ddcb2fc881..7932f36188 100644 --- a/src/where.c +++ b/src/where.c @@ -3791,6 +3791,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->pDistinctSet + && pWInfo->pDistinctSet->nExpr>6 + ){ + rSortCost += sqlite3LogEst(pWInfo->pDistinctSet->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