]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Increase the estimated cost of sorting when sorting wide results sets, to
authordrh <drh@noemail.net>
Thu, 16 Feb 2017 21:29:53 +0000 (21:29 +0000)
committerdrh <drh@noemail.net>
Thu, 16 Feb 2017 21:29:53 +0000 (21:29 +0000)
account for the extra storage space and I/O required for the external sort.

FossilOrigin-Name: aa0703e5cef0c61bec965d4c88ee48bbc11c3649

manifest
manifest.uuid
src/where.c

index 4ce84926b2026f0dd91abd7af4873621c301d697..f0dc00bb2b2ea5dd5c73794a2f4e59003bfdee4c 100644 (file)
--- 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
index fe9afd07d439c0ddfe30dc2d64b475d37ef279ab..13f024c476674ee27361b05be0540a68a2ab062a 100644 (file)
@@ -1 +1 @@
-9fc5cd505fe6ab043519d68e999d2285e22452af
\ No newline at end of file
+aa0703e5cef0c61bec965d4c88ee48bbc11c3649
\ No newline at end of file
index f2bf400a2d7ceb7ad5ee005afdbefc52ac1f6b3e..cac951469c818b0275f8baaffe4bce2b06f2a1bc 100644 (file)
@@ -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<nRow ){