Compare commits

...

2 Commits

Author SHA1 Message Date
drh 5dc7c07d00 simple test cases for carray_asc.
FossilOrigin-Name: 1d4759c17c32f5ee693f7ff6e70e555f613dbcda
2017-02-15 17:47:49 +00:00
drh 2a40f00c7a Add the companion "carray_asc" table-valued function to the carray extension.
FossilOrigin-Name: a2b4f60b335058203c984d7b088c48e8cd2d3894
2017-02-15 16:11:06 +00:00
4 changed files with 71 additions and 10 deletions
+38 -2
View File
@@ -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;
}
+7 -7
View File
@@ -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 simple\stest\scases\sfor\scarray_asc.
D 2017-02-15T17:47:49.138
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
@@ -1157,7 +1157,7 @@ F test/symlink.test c9ebe7330d228249e447038276bfc8a7b22f4849
F test/sync.test 2f84bdbc2b2df1fcb0220575b4b9f8cea94b7529
F test/syscall.test f59ba4e25f7ba4a4c031026cc2ef8b6e4b4c639c
F test/sysfault.test c9f2b0d8d677558f74de750c75e12a5454719d04
F test/tabfunc01.test 699251cb99651415218a891384510a685c7ab012
F test/tabfunc01.test 10f5a739ad4d59f07fe84981c318819f048f4836
F test/table.test b708f3e5fa2542fa51dfab21fc07b36ea445cb2f
F test/tableapi.test 2674633fa95d80da917571ebdd759a14d9819126
F test/tableopts.test dba698ba97251017b7c80d738c198d39ab747930
@@ -1555,7 +1555,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 ee1e689633e517ce46307b9afbf1eda03482c928
R 09fd15812127544dc0546a143adbc35f
P a2b4f60b335058203c984d7b088c48e8cd2d3894
R 454c5abec12500da39f1ebf1cfb9caac
U drh
Z f21515d79bd695dc7bd9e01927424a91
Z ba771257749194f67d4f72e7442e48a9
+1 -1
View File
@@ -1 +1 @@
810d29320b853b3a01aa50d8f2a0bceacf79e0aa
1d4759c17c32f5ee693f7ff6e70e555f613dbcda
+25
View File
@@ -163,6 +163,31 @@ do_test tabfunc01-702 {
SELECT b FROM t600 WHERE a IN carray($PTR1,4,'int32');
}
} {(005) (007) (013) (017)}
do_test tabfunc01-703 {
db eval {
SELECT value FROM carray($PTR1, 5) ORDER BY value;
}
} {5 7 13 17 23}
do_test tabfunc01-703x {db status sort} 1
do_test tabfunc01-704 {
db eval {
SELECT value FROM carray_asc($PTR1, 5) ORDER BY value;
}
} {5 7 13 17 23}
do_test tabfunc01-704x {db status sort} 0
do_test tabfunc01-705 {
db eval {
SELECT value FROM carray($PTR1, 5) ORDER BY value DESC;
}
} {23 17 13 7 5}
do_test tabfunc01-705x {db status sort} 1
do_test tabfunc01-706 {
db eval {
SELECT value FROM carray_asc($PTR1, 5) ORDER BY value DESC;
}
} {23 17 13 7 5}
do_test tabfunc01-706x {db status sort} 1
do_catchsql_test tabfunc01-710 {
SELECT b FROM t600 WHERE a IN carray($PTR1,5,'int33');
} {1 {unknown datatype: 'int33'}}