From: drh Date: Tue, 24 Mar 2020 18:41:58 +0000 (+0000) Subject: Optimize the "subprog IS NULL" constraint. X-Git-Tag: version-3.32.0~50^2~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=779720755412c162f1863a48af94ace135dd1b18;p=thirdparty%2Fsqlite.git Optimize the "subprog IS NULL" constraint. FossilOrigin-Name: ca8c5f028b9f6f32639c8bc9df5dc02537e21385fcbe7e1ae600c640977ea0d5 --- diff --git a/manifest b/manifest index 88dd1f5dcb..046be95fb4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\smemory\sleak. -D 2020-03-24T17:52:31.944 +C Optimize\sthe\s"subprog\sIS\sNULL"\sconstraint. +D 2020-03-24T18:41:58.712 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -612,7 +612,7 @@ F src/vdbeblob.c 253ed82894924c362a7fa3079551d3554cd1cdace39aa833da77d3bc67e7c1b F src/vdbemem.c 39b942ecca179f4f30a32b54579a85d74ccaefa5af2a0ad2700abe5ef0768b22 F src/vdbesort.c 2be76d26998ce2b3324cdcc9f6443728e54b6c7677c553ad909c7d7cfab587df F src/vdbetrace.c fa3bf238002f0bbbdfb66cc8afb0cea284ff9f148d6439bc1f6f2b4c3b7143f0 -F src/vdbevtab.c 936aceaea948131aad90f159cb95ae81a0c48525b4fa1b177881e2dedfe2510b +F src/vdbevtab.c 7239b3469ab67f4698889780ab6808a6fc2ba49ceaaaf477053acc9501d77403 F src/vtab.c 7b704a90515a239c6cdba6a66b1bb3a385e62326cceb5ecb05ec7a091d6b8515 F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 697424314e40d99f93f548c7bfa526c10e87f4bdf64d5a76a96b999dd7133ebc @@ -1861,7 +1861,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P df893364b7cea07ff2b15b80cb294dccaffe701d51452264599b55304a36fa7c -R d325ffd7fee85af0b3d5e5cd91a71c1c +P c9f3405eeac8aff171b5d76bae954f3b51b353d16286a3d2af43ef942c212abc +R 48f17b54ce03a2f2b95d1ae2b04e26b9 U drh -Z f3524124f47701eec8f159f575451b7c +Z 2b8dc1bd4e5b101494ebc4134b3976ef diff --git a/manifest.uuid b/manifest.uuid index dd7249ae11..8fae101c8f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c9f3405eeac8aff171b5d76bae954f3b51b353d16286a3d2af43ef942c212abc \ No newline at end of file +ca8c5f028b9f6f32639c8bc9df5dc02537e21385fcbe7e1ae600c640977ea0d5 \ No newline at end of file diff --git a/src/vdbevtab.c b/src/vdbevtab.c index ffe246b8f4..7b3c066573 100644 --- a/src/vdbevtab.c +++ b/src/vdbevtab.c @@ -34,6 +34,7 @@ struct bytecodevtab_cursor { int iRowid; /* The rowid of the output table */ int iAddr; /* Address */ int needFinalize; /* Cursors owns pStmt and must finalize it */ + int showSubprograms; /* Provide a listing of subprograms */ Op *aOp; /* Operand array */ char *zP4; /* Rendered P4 value */ Mem sub; /* Subprograms */ @@ -135,8 +136,13 @@ static int bytecodevtabNext(sqlite3_vtab_cursor *cur){ sqlite3_free(pCur->zP4); pCur->zP4 = 0; } - rc = sqlite3VdbeNextOpcode((Vdbe*)pCur->pStmt, &pCur->sub, 0, - &pCur->iRowid, &pCur->iAddr, &pCur->aOp); + rc = sqlite3VdbeNextOpcode( + (Vdbe*)pCur->pStmt, + pCur->showSubprograms ? &pCur->sub : 0, + 0, + &pCur->iRowid, + &pCur->iAddr, + &pCur->aOp); if( rc!=SQLITE_OK ){ sqlite3VdbeMemSetNull(&pCur->sub); pCur->aOp = 0; @@ -228,10 +234,10 @@ static int bytecodevtabRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){ } /* -** Initialize a cursor to use a new -** to the first row of output. This method is always called at least -** once prior to any call to bytecodevtabColumn() or bytecodevtabRowid() or -** bytecodevtabEof(). +** Initialize a cursor. +** +** idxNum==0 means show all subprograms +** idxNum==1 means show only the main bytecode and omit subprograms. */ static int bytecodevtabFilter( sqlite3_vtab_cursor *pVtabCursor, @@ -245,6 +251,7 @@ static int bytecodevtabFilter( bytecodevtabCursorClear(pCur); pCur->iRowid = 0; pCur->iAddr = 0; + pCur->showSubprograms = idxNum==0; assert( argc==1 ); if( sqlite3_value_type(argv[0])==SQLITE_TEXT ){ const char *zSql = (const char*)sqlite3_value_text(argv[0]); @@ -279,16 +286,21 @@ static int bytecodevtabBestIndex( ){ int i; int rc = SQLITE_CONSTRAINT; + struct sqlite3_index_constraint *p; pIdxInfo->estimatedCost = (double)100; pIdxInfo->estimatedRows = 100; - for(i=0; inConstraint; i++){ - if( pIdxInfo->aConstraint[i].usable==0 ) continue; - if( pIdxInfo->aConstraint[i].op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue; - if( pIdxInfo->aConstraint[i].iColumn!=9 ) continue; - rc = SQLITE_OK; - pIdxInfo->aConstraintUsage[i].omit = 1; - pIdxInfo->aConstraintUsage[i].argvIndex = 1; - break; + pIdxInfo->idxNum = 0; + for(i=0, p=pIdxInfo->aConstraint; inConstraint; i++, p++){ + if( p->usable==0 ) continue; + if( p->op==SQLITE_INDEX_CONSTRAINT_EQ && p->iColumn==9 ){ + rc = SQLITE_OK; + pIdxInfo->aConstraintUsage[i].omit = 1; + pIdxInfo->aConstraintUsage[i].argvIndex = 1; + } + if( p->op==SQLITE_INDEX_CONSTRAINT_ISNULL && p->iColumn==8 ){ + pIdxInfo->aConstraintUsage[i].omit = 1; + pIdxInfo->idxNum = 1; + } } return rc; }