]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the companion "carray_asc" table-valued function to the carray extension.
authordrh <drh@noemail.net>
Wed, 15 Feb 2017 16:11:06 +0000 (16:11 +0000)
committerdrh <drh@noemail.net>
Wed, 15 Feb 2017 16:11:06 +0000 (16:11 +0000)
FossilOrigin-Name: a2b4f60b335058203c984d7b088c48e8cd2d3894

ext/misc/carray.c
manifest
manifest.uuid

index 025eb5db2c0ec685d44f8587b37ff2c492ed0da1..b54ba7c4a49aa3fa4b34c4278b81c3d4acb7503e 100644 (file)
 **
 **      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;
 }
index c24bc286f68b55db158b3b5b79b6dbc3885f9912..98fd051ad85a4ab43fde9cc040abadf0612a20f5 100644 (file)
--- 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
index f9059a7c4936714bd42755633abf289fa57e694c..526667c5b9c55137cdb4ac5969b85478e529a037 100644 (file)
@@ -1 +1 @@
-810d29320b853b3a01aa50d8f2a0bceacf79e0aa
\ No newline at end of file
+a2b4f60b335058203c984d7b088c48e8cd2d3894
\ No newline at end of file