From: drh <> Date: Fri, 17 Jan 2025 23:49:40 +0000 (+0000) Subject: For the purpose of the query planner heuristic added by [38db9b5c83], a query X-Git-Tag: version-3.49.0~91 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e432f2a316d281f6f4de268483fd113606ed14a7;p=thirdparty%2Fsqlite.git For the purpose of the query planner heuristic added by [38db9b5c83], a query should only count as a star query if the fact tables are connected to the dimension table by an INNER JOIN. If a LEFT JOIN is used, then the fact tables are constrained to be in inner loops anyhow and so the heuristic does not make any sense. But it does interfere with AUTOMATIC index creation, which causes the performance regression reported by [forum:/forumpost/d87570a145599033|forum post d87570a1455]. FossilOrigin-Name: 0852c57ee2768224af79910e6f26e70a4962651dae0f8b45cbfc847e6707d7bb --- diff --git a/manifest b/manifest index 48e8749eee..ddf6529f37 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sa\scomment\son\sa\stest\scase\sto\sadd\srecent\scontext. -D 2025-01-17T17:09:42.305 +C For\sthe\spurpose\sof\sthe\squery\splanner\sheuristic\sadded\sby\s[38db9b5c83],\sa\squery\nshould\sonly\scount\sas\sa\sstar\squery\sif\sthe\sfact\stables\sare\sconnected\sto\sthe\ndimension\stable\sby\san\sINNER\sJOIN.\s\sIf\sa\sLEFT\sJOIN\sis\sused,\sthen\sthe\sfact\ntables\sare\sconstrained\sto\sbe\sin\sinner\sloops\sanyhow\sand\sso\sthe\sheuristic\sdoes\nnot\smake\sany\ssense.\s\sBut\sit\sdoes\sinterfere\swith\sAUTOMATIC\sindex\screation,\swhich\ncauses\sthe\sperformance\sregression\sreported\sby\n[forum:/forumpost/d87570a145599033|forum\spost\sd87570a1455]. +D 2025-01-17T23:49:40.018 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md e108e1e69ae8e8a59e93c455654b8ac9356a11720d3345df2a4743e9590fb20d @@ -862,7 +862,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 4e6181d8780ab0af2e1388d0754cbe6f2f04593d2b1ab6c41699a89942fd8997 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452 F src/walker.c d5006d6b005e4ea7302ad390957a8d41ed83faa177e412f89bc5600a7462a014 -F src/where.c f081a371086f48201948431832f5e9bb1bf6c930397b8d7bcf8aaa9e21d819da +F src/where.c 7aa91f806d19d254d47763564e355cca50d1787d93fc0a62c7d5361d8dfbce70 F src/whereInt.h 2b0804f300c7f65de4046a1d81c65f01b208d6c08950ccd1fa6b8c16162a8af7 F src/wherecode.c 0c3d3199a2b769a5e2bb70feb5003dc85b3d86842ecaf903a47f2b4205ca5dab F src/whereexpr.c 0f93a29cabd3a338d09a1f5c6770620a1ac51ec1157f3229502a7e7767c60b6f @@ -2207,8 +2207,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 36027cf340fe2e351c63129d069f9bced090c4a028ffd78d5b8c0f418ad9f230 -R ef3d991b9c054b173fa221e38e326aa0 +P c2647d1bd16fd46dd03953afee6cad44ce14fa2c36713c487b678d63660bc072 +R 93d684fb6b94ab6c95c7721a922c90f7 U drh -Z 0b63cd7bd279966e11ae3eece17abfb9 +Z 89119702900b9ccbb1fc6836bf36a009 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e9d77082b4..f763ea63a8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c2647d1bd16fd46dd03953afee6cad44ce14fa2c36713c487b678d63660bc072 +0852c57ee2768224af79910e6f26e70a4962651dae0f8b45cbfc847e6707d7bb diff --git a/src/where.c b/src/where.c index 05dab8fdd5..b3f177fb40 100644 --- a/src/where.c +++ b/src/where.c @@ -5427,9 +5427,10 @@ static LogEst whereSortingCost( ** 12 otherwise ** ** For the purposes of SQLite, a star-query is defined as a query -** with a large central table that is joined against four or more -** smaller tables. The central table is called the "fact" table. -** The smaller tables that get joined are "dimension tables". +** with a large central table that is joined (using an INNER JOIN, +** not a LEFT JOIN) against four or more smaller tables. The central +** table is called the "fact" table. The smaller tables that get +** joined are "dimension tables". ** ** SIDE EFFECT: (and really the whole point of this subroutine) ** @@ -5457,7 +5458,11 @@ static int computeMxChoice(WhereInfo *pWInfo, LogEst nRowEst){ LogEst rDelta; /* Heuristic cost adjustment */ Bitmask mSeen = 0; /* Mask of dimension tables */ for(pWLoop=pWInfo->pLoops; pWLoop; pWLoop=pWLoop->pNextLoop){ - if( (pWLoop->prereq & m)!=0 && (pWLoop->maskSelf & mSeen)==0 ){ + if( (pWLoop->prereq & m)!=0 /* pWInfo depends on iLoop */ + && (pWLoop->maskSelf & mSeen)==0 /* pWInfo not already a dependency */ + && (pWInfo->pTabList->a[pWLoop->iTab].fg.jointype & JT_LEFT)==0 + /* ^- pWInfo isn't a LEFT JOIN */ + ){ nDep++; mSeen |= pWLoop->maskSelf; }