From: drh Date: Wed, 15 Feb 2017 16:11:06 +0000 (+0000) Subject: Add the companion "carray_asc" table-valued function to the carray extension. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2a40f00c7a4466e0d9c16a1160a0bd478a076357;p=thirdparty%2Fsqlite.git Add the companion "carray_asc" table-valued function to the carray extension. FossilOrigin-Name: a2b4f60b335058203c984d7b088c48e8cd2d3894 --- diff --git a/ext/misc/carray.c b/ext/misc/carray.c index 025eb5db2c..b54ba7c4a4 100644 --- a/ext/misc/carray.c +++ b/ext/misc/carray.c @@ -26,6 +26,14 @@ ** ** SELECT * FROM carray($ptr,10,'char*'); ** +** There is a second table-valued funnction named "carrray_asc" that works +** exactly like carray except that it requires the values in the $ptr array +** to be in ascending order. Queries involving ORDER BY clauses can sometimes +** be a little faster with carray_asc compared to plain carray. However, if +** the application provides carray_asc($ptr) with a $ptr array in which the +** elements are not in ascending order, then incorrect query results might +** result. +** ** HOW IT WORKS ** ** The carray "function" is really a virtual table with the @@ -64,6 +72,20 @@ SQLITE_EXTENSION_INIT1 */ static const char *azType[] = { "int32", "int64", "double", "char*" }; +/* carray_vtab is a subclass of sqlite3_vtab containing carray-specific +** extensions. +*/ +typedef struct carray_vtab carray_vtab; +struct carray_vtab { + sqlite3_vtab base; /* Base class - must be first */ + unsigned int mFlags; /* Operational flags */ +}; + +/* +** Possible values for carray_vtab.mFlags +*/ +#define CARRAY_ASC 0x0001 /* Values are always in ascending order */ + /* carray_cursor is a subclass of sqlite3_vtab_cursor which will ** serve as the underlying representation of a cursor that scans @@ -98,7 +120,7 @@ static int carrayConnect( sqlite3_vtab **ppVtab, char **pzErr ){ - sqlite3_vtab *pNew; + carray_vtab *pNew; int rc; /* Column numbers */ @@ -110,9 +132,11 @@ static int carrayConnect( rc = sqlite3_declare_vtab(db, "CREATE TABLE x(value,pointer hidden,count hidden,ctype hidden)"); if( rc==SQLITE_OK ){ - pNew = *ppVtab = sqlite3_malloc( sizeof(*pNew) ); + pNew = sqlite3_malloc( sizeof(*pNew) ); + *ppVtab = (sqlite3_vtab*)pNew; if( pNew==0 ) return SQLITE_NOMEM; memset(pNew, 0, sizeof(*pNew)); + if( pAux ) pNew->mFlags = *(unsigned int*)pAux; } return rc; } @@ -305,6 +329,13 @@ static int carrayBestIndex( pIdxInfo->estimatedCost = (double)1; pIdxInfo->estimatedRows = 100; pIdxInfo->idxNum = 2; + if( pIdxInfo->nOrderBy==1 + && pIdxInfo->aOrderBy[0].iColumn==0 + && pIdxInfo->aOrderBy[0].desc==0 + && (((carray_vtab*)tab)->mFlags & CARRAY_ASC)!=0 + ){ + pIdxInfo->orderByConsumed = 1; + } if( ctypeIdx>=0 ){ pIdxInfo->aConstraintUsage[ctypeIdx].argvIndex = 3; pIdxInfo->aConstraintUsage[ctypeIdx].omit = 1; @@ -356,9 +387,14 @@ int sqlite3_carray_init( const sqlite3_api_routines *pApi ){ int rc = SQLITE_OK; + static const unsigned int mAscFlags = CARRAY_ASC; SQLITE_EXTENSION_INIT2(pApi); #ifndef SQLITE_OMIT_VIRTUALTABLE rc = sqlite3_create_module(db, "carray", &carrayModule, 0); + if( rc==SQLITE_OK ){ + rc = sqlite3_create_module(db, "carray_asc", &carrayModule, + (void*)&mAscFlags); + } #endif return rc; } diff --git a/manifest b/manifest index c24bc286f6..98fd051ad8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sthe\sCLANG_VERSION\smacro,\ssince\swe\shave\slearned\sthat\sversion\snumbers\sin\nclang\sare\s"marketing"\sand\sare\sinconsistent\sand\sunreliable.\s\sBuilds\susing\sclang\nwill\sstill\suse\sthe\sGCC_VERSION\smacro\ssince\sclang\sworks\shard\sto\sbe\sgcc\ncompatible. -D 2017-02-15T15:09:09.031 +C Add\sthe\scompanion\s"carray_asc"\stable-valued\sfunction\sto\sthe\scarray\sextension. +D 2017-02-15T16:11:06.169 F Makefile.in edb6bcdd37748d2b1c3422ff727c748df7ffe918 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 067a6766f800cc8d72845ab61f8de4ffe8f3fc99 @@ -205,7 +205,7 @@ F ext/icu/README.txt d9fbbad0c2f647c3fdf715fc9fd64af53aedfc43 F ext/icu/icu.c 84900472a088a3a172c6c079f58a1d3a1952c332 F ext/icu/sqliteicu.h 728867a802baa5a96de7495e9689a8e01715ef37 F ext/misc/amatch.c 211108e201105e4bb0c076527b8cfd34330fc234 -F ext/misc/carray.c 40c27641010a4dc67e3690bdb7c9d36ca58b3c2d +F ext/misc/carray.c f98fc506df22b74b3cde996da5d702b520f84945 F ext/misc/closure.c 0d2a038df8fbae7f19de42e7c7d71f2e4dc88704 F ext/misc/compress.c 122faa92d25033d6c3f07c39231de074ab3d2e83 F ext/misc/csv.c 531a46cbad789fca0aa9db69a0e6c8ac9e68767d @@ -1555,7 +1555,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 ee1e689633e517ce46307b9afbf1eda03482c928 -R 09fd15812127544dc0546a143adbc35f +P 810d29320b853b3a01aa50d8f2a0bceacf79e0aa +Q +396b9d99ae43cc5c9ce18509754aac001eae0ecf +R 854f2bd98a5aec3c801c3b865d9cafe4 +T *branch * carray_asc +T *sym-carray_asc * +T -sym-trunk * U drh -Z f21515d79bd695dc7bd9e01927424a91 +Z 5a5965a82585c6466315592e6eda4385 diff --git a/manifest.uuid b/manifest.uuid index f9059a7c49..526667c5b9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -810d29320b853b3a01aa50d8f2a0bceacf79e0aa \ No newline at end of file +a2b4f60b335058203c984d7b088c48e8cd2d3894 \ No newline at end of file