Fossil SCM

Update the built-in SQLite to the latest trunk version that includes the order-by-subquery optimization.

drh 2024-08-16 19:06 trunk
Commit a8aaed421614410c34e1bf9cddd44693f8982dfaafb84878ec506d36fb329396
+179 -50
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -2846,21 +2846,93 @@
28462846
** This SQLite extension implements functions that compute SHA3 hashes
28472847
** in the way described by the (U.S.) NIST FIPS 202 SHA-3 Standard.
28482848
** Two SQL functions are implemented:
28492849
**
28502850
** sha3(X,SIZE)
2851
-** sha3_query(Y,SIZE)
2851
+** sha3_agg(Y,SIZE)
2852
+** sha3_query(Z,SIZE)
28522853
**
28532854
** The sha3(X) function computes the SHA3 hash of the input X, or NULL if
2854
-** X is NULL.
2855
+** X is NULL. If inputs X is text, the UTF-8 rendering of that text is
2856
+** used to compute the hash. If X is a BLOB, then the binary data of the
2857
+** blob is used to compute the hash. If X is an integer or real number,
2858
+** then that number if converted into UTF-8 text and the hash is computed
2859
+** over the text.
2860
+**
2861
+** The sha3_agg(Y) function computes the SHA3 hash of all Y inputs. Since
2862
+** order is important for the hash, it is recommended that the Y expression
2863
+** by followed by an ORDER BY clause to guarantee that the inputs occur
2864
+** in the desired order.
28552865
**
28562866
** The sha3_query(Y) function evaluates all queries in the SQL statements of Y
28572867
** and returns a hash of their results.
28582868
**
28592869
** The SIZE argument is optional. If omitted, the SHA3-256 hash algorithm
28602870
** is used. If SIZE is included it must be one of the integers 224, 256,
28612871
** 384, or 512, to determine SHA3 hash variant that is computed.
2872
+**
2873
+** Because the sha3_agg() and sha3_query() functions compute a hash over
2874
+** multiple values, the values are encode to use include type information.
2875
+**
2876
+** In sha3_agg(), the sequence of bytes that gets hashed for each input
2877
+** Y depends on the datatype of Y:
2878
+**
2879
+** typeof(Y)='null' A single "N" is hashed. (One byte)
2880
+**
2881
+** typeof(Y)='integer' The data hash is the character "I" followed
2882
+** by an 8-byte big-endian binary of the
2883
+** 64-bit signed integer. (Nine bytes total.)
2884
+**
2885
+** typeof(Y)='real' The character "F" followed by an 8-byte
2886
+** big-ending binary of the double. (Nine
2887
+** bytes total.)
2888
+**
2889
+** typeof(Y)='text' The hash is over prefix "Tnnn:" followed
2890
+** by the UTF8 encoding of the text. The "nnn"
2891
+** in the prefix is the minimum-length decimal
2892
+** representation of the octet_length of the text.
2893
+** Notice the ":" at the end of the prefix, which
2894
+** is needed to separate the prefix from the
2895
+** content in cases where the content starts
2896
+** with a digit.
2897
+**
2898
+** typeof(Y)='blob' The hash is taken over prefix "Bnnn:" followed
2899
+** by the binary content of the blob. The "nnn"
2900
+** in the prefix is the mimimum-length decimal
2901
+** representation of the byte-length of the blob.
2902
+**
2903
+** According to the rules above, all of the following SELECT statements
2904
+** should return TRUE:
2905
+**
2906
+** SELECT sha3(1) = sha3('1');
2907
+**
2908
+** SELECT sha3('hello') = sha3(x'68656c6c6f');
2909
+**
2910
+** WITH a(x) AS (VALUES('xyzzy'))
2911
+** SELECT sha3_agg(x) = sha3('T5:xyzzy') FROM a;
2912
+**
2913
+** WITH a(x) AS (VALUES(x'010203'))
2914
+** SELECT sha3_agg(x) = sha3(x'42333a010203') FROM a;
2915
+**
2916
+** WITH a(x) AS (VALUES(0x123456))
2917
+** SELECT sha3_agg(x) = sha3(x'490000000000123456') FROM a;
2918
+**
2919
+** WITH a(x) AS (VALUES(100.015625))
2920
+** SELECT sha3_agg(x) = sha3(x'464059010000000000') FROM a;
2921
+**
2922
+** WITH a(x) AS (VALUES(NULL))
2923
+** SELECT sha3_agg(x) = sha3('N') FROM a;
2924
+**
2925
+**
2926
+** In sha3_query(), individual column values are encoded as with
2927
+** sha3_agg(), but with the addition that a single "R" character is
2928
+** inserted at the start of each row.
2929
+**
2930
+** Note that sha3_agg() hashes rows for which Y is NULL. Add a FILTER
2931
+** clause if NULL rows should be excluded:
2932
+**
2933
+** SELECT sha3_agg(x ORDER BY rowid) FILTER(WHERE x NOT NULL) FROM t1;
28622934
*/
28632935
/* #include "sqlite3ext.h" */
28642936
SQLITE_EXTENSION_INIT1
28652937
#include <assert.h>
28662938
#include <string.h>
@@ -2906,10 +2978,11 @@
29062978
unsigned char x[1600]; /* ... or 1600 bytes */
29072979
} u;
29082980
unsigned nRate; /* Bytes of input accepted per Keccak iteration */
29092981
unsigned nLoaded; /* Input bytes loaded into u.x[] so far this cycle */
29102982
unsigned ixMask; /* Insert next input into u.x[nLoaded^ixMask]. */
2983
+ unsigned iSize; /* 224, 256, 358, or 512 */
29112984
};
29122985
29132986
/*
29142987
** A single step of the Keccak mixing function for a 1600-bit state
29152988
*/
@@ -3235,10 +3308,11 @@
32353308
** in bits and should be one of 224, 256, 384, or 512. Or iSize
32363309
** can be zero to use the default hash size of 256 bits.
32373310
*/
32383311
static void SHA3Init(SHA3Context *p, int iSize){
32393312
memset(p, 0, sizeof(*p));
3313
+ p->iSize = iSize;
32403314
if( iSize>=128 && iSize<=512 ){
32413315
p->nRate = (1600 - ((iSize + 31)&~31)*2)/8;
32423316
}else{
32433317
p->nRate = (1600 - 2*256)/8;
32443318
}
@@ -3377,10 +3451,64 @@
33773451
sqlite3_vsnprintf(sizeof(zBuf),zBuf,zFormat,ap);
33783452
va_end(ap);
33793453
n = (int)strlen(zBuf);
33803454
SHA3Update(p, (unsigned char*)zBuf, n);
33813455
}
3456
+
3457
+/*
3458
+** Update a SHA3Context using a single sqlite3_value.
3459
+*/
3460
+static void sha3UpdateFromValue(SHA3Context *p, sqlite3_value *pVal){
3461
+ switch( sqlite3_value_type(pVal) ){
3462
+ case SQLITE_NULL: {
3463
+ SHA3Update(p, (const unsigned char*)"N",1);
3464
+ break;
3465
+ }
3466
+ case SQLITE_INTEGER: {
3467
+ sqlite3_uint64 u;
3468
+ int j;
3469
+ unsigned char x[9];
3470
+ sqlite3_int64 v = sqlite3_value_int64(pVal);
3471
+ memcpy(&u, &v, 8);
3472
+ for(j=8; j>=1; j--){
3473
+ x[j] = u & 0xff;
3474
+ u >>= 8;
3475
+ }
3476
+ x[0] = 'I';
3477
+ SHA3Update(p, x, 9);
3478
+ break;
3479
+ }
3480
+ case SQLITE_FLOAT: {
3481
+ sqlite3_uint64 u;
3482
+ int j;
3483
+ unsigned char x[9];
3484
+ double r = sqlite3_value_double(pVal);
3485
+ memcpy(&u, &r, 8);
3486
+ for(j=8; j>=1; j--){
3487
+ x[j] = u & 0xff;
3488
+ u >>= 8;
3489
+ }
3490
+ x[0] = 'F';
3491
+ SHA3Update(p,x,9);
3492
+ break;
3493
+ }
3494
+ case SQLITE_TEXT: {
3495
+ int n2 = sqlite3_value_bytes(pVal);
3496
+ const unsigned char *z2 = sqlite3_value_text(pVal);
3497
+ sha3_step_vformat(p,"T%d:",n2);
3498
+ SHA3Update(p, z2, n2);
3499
+ break;
3500
+ }
3501
+ case SQLITE_BLOB: {
3502
+ int n2 = sqlite3_value_bytes(pVal);
3503
+ const unsigned char *z2 = sqlite3_value_blob(pVal);
3504
+ sha3_step_vformat(p,"B%d:",n2);
3505
+ SHA3Update(p, z2, n2);
3506
+ break;
3507
+ }
3508
+ }
3509
+}
33823510
33833511
/*
33843512
** Implementation of the sha3_query(SQL,SIZE) function.
33853513
**
33863514
** This function compiles and runs the SQL statement(s) given in the
@@ -3467,64 +3595,55 @@
34673595
34683596
/* Compute a hash over the result of the query */
34693597
while( SQLITE_ROW==sqlite3_step(pStmt) ){
34703598
SHA3Update(&cx,(const unsigned char*)"R",1);
34713599
for(i=0; i<nCol; i++){
3472
- switch( sqlite3_column_type(pStmt,i) ){
3473
- case SQLITE_NULL: {
3474
- SHA3Update(&cx, (const unsigned char*)"N",1);
3475
- break;
3476
- }
3477
- case SQLITE_INTEGER: {
3478
- sqlite3_uint64 u;
3479
- int j;
3480
- unsigned char x[9];
3481
- sqlite3_int64 v = sqlite3_column_int64(pStmt,i);
3482
- memcpy(&u, &v, 8);
3483
- for(j=8; j>=1; j--){
3484
- x[j] = u & 0xff;
3485
- u >>= 8;
3486
- }
3487
- x[0] = 'I';
3488
- SHA3Update(&cx, x, 9);
3489
- break;
3490
- }
3491
- case SQLITE_FLOAT: {
3492
- sqlite3_uint64 u;
3493
- int j;
3494
- unsigned char x[9];
3495
- double r = sqlite3_column_double(pStmt,i);
3496
- memcpy(&u, &r, 8);
3497
- for(j=8; j>=1; j--){
3498
- x[j] = u & 0xff;
3499
- u >>= 8;
3500
- }
3501
- x[0] = 'F';
3502
- SHA3Update(&cx,x,9);
3503
- break;
3504
- }
3505
- case SQLITE_TEXT: {
3506
- int n2 = sqlite3_column_bytes(pStmt, i);
3507
- const unsigned char *z2 = sqlite3_column_text(pStmt, i);
3508
- sha3_step_vformat(&cx,"T%d:",n2);
3509
- SHA3Update(&cx, z2, n2);
3510
- break;
3511
- }
3512
- case SQLITE_BLOB: {
3513
- int n2 = sqlite3_column_bytes(pStmt, i);
3514
- const unsigned char *z2 = sqlite3_column_blob(pStmt, i);
3515
- sha3_step_vformat(&cx,"B%d:",n2);
3516
- SHA3Update(&cx, z2, n2);
3517
- break;
3518
- }
3519
- }
3600
+ sha3UpdateFromValue(&cx, sqlite3_column_value(pStmt,i));
35203601
}
35213602
}
35223603
sqlite3_finalize(pStmt);
35233604
}
35243605
sqlite3_result_blob(context, SHA3Final(&cx), iSize/8, SQLITE_TRANSIENT);
35253606
}
3607
+
3608
+/*
3609
+** xStep function for sha3_agg().
3610
+*/
3611
+static void sha3AggStep(
3612
+ sqlite3_context *context,
3613
+ int argc,
3614
+ sqlite3_value **argv
3615
+){
3616
+ SHA3Context *p;
3617
+ p = (SHA3Context*)sqlite3_aggregate_context(context, sizeof(*p));
3618
+ if( p==0 ) return;
3619
+ if( p->nRate==0 ){
3620
+ int sz = 256;
3621
+ if( argc==2 ){
3622
+ sz = sqlite3_value_int(argv[1]);
3623
+ if( sz!=224 && sz!=384 && sz!=512 ){
3624
+ sz = 256;
3625
+ }
3626
+ }
3627
+ SHA3Init(p, sz);
3628
+ }
3629
+ sha3UpdateFromValue(p, argv[0]);
3630
+}
3631
+
3632
+
3633
+/*
3634
+** xFinal function for sha3_agg().
3635
+*/
3636
+static void sha3AggFinal(sqlite3_context *context){
3637
+ SHA3Context *p;
3638
+ p = (SHA3Context*)sqlite3_aggregate_context(context, sizeof(*p));
3639
+ if( p==0 ) return;
3640
+ if( p->iSize ){
3641
+ sqlite3_result_blob(context, SHA3Final(p), p->iSize/8, SQLITE_TRANSIENT);
3642
+ }
3643
+}
3644
+
35263645
35273646
35283647
#ifdef _WIN32
35293648
35303649
#endif
@@ -3542,10 +3661,20 @@
35423661
if( rc==SQLITE_OK ){
35433662
rc = sqlite3_create_function(db, "sha3", 2,
35443663
SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC,
35453664
0, sha3Func, 0, 0);
35463665
}
3666
+ if( rc==SQLITE_OK ){
3667
+ rc = sqlite3_create_function(db, "sha3_agg", 1,
3668
+ SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC,
3669
+ 0, 0, sha3AggStep, sha3AggFinal);
3670
+ }
3671
+ if( rc==SQLITE_OK ){
3672
+ rc = sqlite3_create_function(db, "sha3_agg", 2,
3673
+ SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC,
3674
+ 0, 0, sha3AggStep, sha3AggFinal);
3675
+ }
35473676
if( rc==SQLITE_OK ){
35483677
rc = sqlite3_create_function(db, "sha3_query", 1,
35493678
SQLITE_UTF8 | SQLITE_DIRECTONLY,
35503679
0, sha3QueryFunc, 0, 0);
35513680
}
35523681
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -2846,21 +2846,93 @@
2846 ** This SQLite extension implements functions that compute SHA3 hashes
2847 ** in the way described by the (U.S.) NIST FIPS 202 SHA-3 Standard.
2848 ** Two SQL functions are implemented:
2849 **
2850 ** sha3(X,SIZE)
2851 ** sha3_query(Y,SIZE)
 
2852 **
2853 ** The sha3(X) function computes the SHA3 hash of the input X, or NULL if
2854 ** X is NULL.
 
 
 
 
 
 
 
 
 
2855 **
2856 ** The sha3_query(Y) function evaluates all queries in the SQL statements of Y
2857 ** and returns a hash of their results.
2858 **
2859 ** The SIZE argument is optional. If omitted, the SHA3-256 hash algorithm
2860 ** is used. If SIZE is included it must be one of the integers 224, 256,
2861 ** 384, or 512, to determine SHA3 hash variant that is computed.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2862 */
2863 /* #include "sqlite3ext.h" */
2864 SQLITE_EXTENSION_INIT1
2865 #include <assert.h>
2866 #include <string.h>
@@ -2906,10 +2978,11 @@
2906 unsigned char x[1600]; /* ... or 1600 bytes */
2907 } u;
2908 unsigned nRate; /* Bytes of input accepted per Keccak iteration */
2909 unsigned nLoaded; /* Input bytes loaded into u.x[] so far this cycle */
2910 unsigned ixMask; /* Insert next input into u.x[nLoaded^ixMask]. */
 
2911 };
2912
2913 /*
2914 ** A single step of the Keccak mixing function for a 1600-bit state
2915 */
@@ -3235,10 +3308,11 @@
3235 ** in bits and should be one of 224, 256, 384, or 512. Or iSize
3236 ** can be zero to use the default hash size of 256 bits.
3237 */
3238 static void SHA3Init(SHA3Context *p, int iSize){
3239 memset(p, 0, sizeof(*p));
 
3240 if( iSize>=128 && iSize<=512 ){
3241 p->nRate = (1600 - ((iSize + 31)&~31)*2)/8;
3242 }else{
3243 p->nRate = (1600 - 2*256)/8;
3244 }
@@ -3377,10 +3451,64 @@
3377 sqlite3_vsnprintf(sizeof(zBuf),zBuf,zFormat,ap);
3378 va_end(ap);
3379 n = (int)strlen(zBuf);
3380 SHA3Update(p, (unsigned char*)zBuf, n);
3381 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3382
3383 /*
3384 ** Implementation of the sha3_query(SQL,SIZE) function.
3385 **
3386 ** This function compiles and runs the SQL statement(s) given in the
@@ -3467,64 +3595,55 @@
3467
3468 /* Compute a hash over the result of the query */
3469 while( SQLITE_ROW==sqlite3_step(pStmt) ){
3470 SHA3Update(&cx,(const unsigned char*)"R",1);
3471 for(i=0; i<nCol; i++){
3472 switch( sqlite3_column_type(pStmt,i) ){
3473 case SQLITE_NULL: {
3474 SHA3Update(&cx, (const unsigned char*)"N",1);
3475 break;
3476 }
3477 case SQLITE_INTEGER: {
3478 sqlite3_uint64 u;
3479 int j;
3480 unsigned char x[9];
3481 sqlite3_int64 v = sqlite3_column_int64(pStmt,i);
3482 memcpy(&u, &v, 8);
3483 for(j=8; j>=1; j--){
3484 x[j] = u & 0xff;
3485 u >>= 8;
3486 }
3487 x[0] = 'I';
3488 SHA3Update(&cx, x, 9);
3489 break;
3490 }
3491 case SQLITE_FLOAT: {
3492 sqlite3_uint64 u;
3493 int j;
3494 unsigned char x[9];
3495 double r = sqlite3_column_double(pStmt,i);
3496 memcpy(&u, &r, 8);
3497 for(j=8; j>=1; j--){
3498 x[j] = u & 0xff;
3499 u >>= 8;
3500 }
3501 x[0] = 'F';
3502 SHA3Update(&cx,x,9);
3503 break;
3504 }
3505 case SQLITE_TEXT: {
3506 int n2 = sqlite3_column_bytes(pStmt, i);
3507 const unsigned char *z2 = sqlite3_column_text(pStmt, i);
3508 sha3_step_vformat(&cx,"T%d:",n2);
3509 SHA3Update(&cx, z2, n2);
3510 break;
3511 }
3512 case SQLITE_BLOB: {
3513 int n2 = sqlite3_column_bytes(pStmt, i);
3514 const unsigned char *z2 = sqlite3_column_blob(pStmt, i);
3515 sha3_step_vformat(&cx,"B%d:",n2);
3516 SHA3Update(&cx, z2, n2);
3517 break;
3518 }
3519 }
3520 }
3521 }
3522 sqlite3_finalize(pStmt);
3523 }
3524 sqlite3_result_blob(context, SHA3Final(&cx), iSize/8, SQLITE_TRANSIENT);
3525 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3526
3527
3528 #ifdef _WIN32
3529
3530 #endif
@@ -3542,10 +3661,20 @@
3542 if( rc==SQLITE_OK ){
3543 rc = sqlite3_create_function(db, "sha3", 2,
3544 SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC,
3545 0, sha3Func, 0, 0);
3546 }
 
 
 
 
 
 
 
 
 
 
3547 if( rc==SQLITE_OK ){
3548 rc = sqlite3_create_function(db, "sha3_query", 1,
3549 SQLITE_UTF8 | SQLITE_DIRECTONLY,
3550 0, sha3QueryFunc, 0, 0);
3551 }
3552
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -2846,21 +2846,93 @@
2846 ** This SQLite extension implements functions that compute SHA3 hashes
2847 ** in the way described by the (U.S.) NIST FIPS 202 SHA-3 Standard.
2848 ** Two SQL functions are implemented:
2849 **
2850 ** sha3(X,SIZE)
2851 ** sha3_agg(Y,SIZE)
2852 ** sha3_query(Z,SIZE)
2853 **
2854 ** The sha3(X) function computes the SHA3 hash of the input X, or NULL if
2855 ** X is NULL. If inputs X is text, the UTF-8 rendering of that text is
2856 ** used to compute the hash. If X is a BLOB, then the binary data of the
2857 ** blob is used to compute the hash. If X is an integer or real number,
2858 ** then that number if converted into UTF-8 text and the hash is computed
2859 ** over the text.
2860 **
2861 ** The sha3_agg(Y) function computes the SHA3 hash of all Y inputs. Since
2862 ** order is important for the hash, it is recommended that the Y expression
2863 ** by followed by an ORDER BY clause to guarantee that the inputs occur
2864 ** in the desired order.
2865 **
2866 ** The sha3_query(Y) function evaluates all queries in the SQL statements of Y
2867 ** and returns a hash of their results.
2868 **
2869 ** The SIZE argument is optional. If omitted, the SHA3-256 hash algorithm
2870 ** is used. If SIZE is included it must be one of the integers 224, 256,
2871 ** 384, or 512, to determine SHA3 hash variant that is computed.
2872 **
2873 ** Because the sha3_agg() and sha3_query() functions compute a hash over
2874 ** multiple values, the values are encode to use include type information.
2875 **
2876 ** In sha3_agg(), the sequence of bytes that gets hashed for each input
2877 ** Y depends on the datatype of Y:
2878 **
2879 ** typeof(Y)='null' A single "N" is hashed. (One byte)
2880 **
2881 ** typeof(Y)='integer' The data hash is the character "I" followed
2882 ** by an 8-byte big-endian binary of the
2883 ** 64-bit signed integer. (Nine bytes total.)
2884 **
2885 ** typeof(Y)='real' The character "F" followed by an 8-byte
2886 ** big-ending binary of the double. (Nine
2887 ** bytes total.)
2888 **
2889 ** typeof(Y)='text' The hash is over prefix "Tnnn:" followed
2890 ** by the UTF8 encoding of the text. The "nnn"
2891 ** in the prefix is the minimum-length decimal
2892 ** representation of the octet_length of the text.
2893 ** Notice the ":" at the end of the prefix, which
2894 ** is needed to separate the prefix from the
2895 ** content in cases where the content starts
2896 ** with a digit.
2897 **
2898 ** typeof(Y)='blob' The hash is taken over prefix "Bnnn:" followed
2899 ** by the binary content of the blob. The "nnn"
2900 ** in the prefix is the mimimum-length decimal
2901 ** representation of the byte-length of the blob.
2902 **
2903 ** According to the rules above, all of the following SELECT statements
2904 ** should return TRUE:
2905 **
2906 ** SELECT sha3(1) = sha3('1');
2907 **
2908 ** SELECT sha3('hello') = sha3(x'68656c6c6f');
2909 **
2910 ** WITH a(x) AS (VALUES('xyzzy'))
2911 ** SELECT sha3_agg(x) = sha3('T5:xyzzy') FROM a;
2912 **
2913 ** WITH a(x) AS (VALUES(x'010203'))
2914 ** SELECT sha3_agg(x) = sha3(x'42333a010203') FROM a;
2915 **
2916 ** WITH a(x) AS (VALUES(0x123456))
2917 ** SELECT sha3_agg(x) = sha3(x'490000000000123456') FROM a;
2918 **
2919 ** WITH a(x) AS (VALUES(100.015625))
2920 ** SELECT sha3_agg(x) = sha3(x'464059010000000000') FROM a;
2921 **
2922 ** WITH a(x) AS (VALUES(NULL))
2923 ** SELECT sha3_agg(x) = sha3('N') FROM a;
2924 **
2925 **
2926 ** In sha3_query(), individual column values are encoded as with
2927 ** sha3_agg(), but with the addition that a single "R" character is
2928 ** inserted at the start of each row.
2929 **
2930 ** Note that sha3_agg() hashes rows for which Y is NULL. Add a FILTER
2931 ** clause if NULL rows should be excluded:
2932 **
2933 ** SELECT sha3_agg(x ORDER BY rowid) FILTER(WHERE x NOT NULL) FROM t1;
2934 */
2935 /* #include "sqlite3ext.h" */
2936 SQLITE_EXTENSION_INIT1
2937 #include <assert.h>
2938 #include <string.h>
@@ -2906,10 +2978,11 @@
2978 unsigned char x[1600]; /* ... or 1600 bytes */
2979 } u;
2980 unsigned nRate; /* Bytes of input accepted per Keccak iteration */
2981 unsigned nLoaded; /* Input bytes loaded into u.x[] so far this cycle */
2982 unsigned ixMask; /* Insert next input into u.x[nLoaded^ixMask]. */
2983 unsigned iSize; /* 224, 256, 358, or 512 */
2984 };
2985
2986 /*
2987 ** A single step of the Keccak mixing function for a 1600-bit state
2988 */
@@ -3235,10 +3308,11 @@
3308 ** in bits and should be one of 224, 256, 384, or 512. Or iSize
3309 ** can be zero to use the default hash size of 256 bits.
3310 */
3311 static void SHA3Init(SHA3Context *p, int iSize){
3312 memset(p, 0, sizeof(*p));
3313 p->iSize = iSize;
3314 if( iSize>=128 && iSize<=512 ){
3315 p->nRate = (1600 - ((iSize + 31)&~31)*2)/8;
3316 }else{
3317 p->nRate = (1600 - 2*256)/8;
3318 }
@@ -3377,10 +3451,64 @@
3451 sqlite3_vsnprintf(sizeof(zBuf),zBuf,zFormat,ap);
3452 va_end(ap);
3453 n = (int)strlen(zBuf);
3454 SHA3Update(p, (unsigned char*)zBuf, n);
3455 }
3456
3457 /*
3458 ** Update a SHA3Context using a single sqlite3_value.
3459 */
3460 static void sha3UpdateFromValue(SHA3Context *p, sqlite3_value *pVal){
3461 switch( sqlite3_value_type(pVal) ){
3462 case SQLITE_NULL: {
3463 SHA3Update(p, (const unsigned char*)"N",1);
3464 break;
3465 }
3466 case SQLITE_INTEGER: {
3467 sqlite3_uint64 u;
3468 int j;
3469 unsigned char x[9];
3470 sqlite3_int64 v = sqlite3_value_int64(pVal);
3471 memcpy(&u, &v, 8);
3472 for(j=8; j>=1; j--){
3473 x[j] = u & 0xff;
3474 u >>= 8;
3475 }
3476 x[0] = 'I';
3477 SHA3Update(p, x, 9);
3478 break;
3479 }
3480 case SQLITE_FLOAT: {
3481 sqlite3_uint64 u;
3482 int j;
3483 unsigned char x[9];
3484 double r = sqlite3_value_double(pVal);
3485 memcpy(&u, &r, 8);
3486 for(j=8; j>=1; j--){
3487 x[j] = u & 0xff;
3488 u >>= 8;
3489 }
3490 x[0] = 'F';
3491 SHA3Update(p,x,9);
3492 break;
3493 }
3494 case SQLITE_TEXT: {
3495 int n2 = sqlite3_value_bytes(pVal);
3496 const unsigned char *z2 = sqlite3_value_text(pVal);
3497 sha3_step_vformat(p,"T%d:",n2);
3498 SHA3Update(p, z2, n2);
3499 break;
3500 }
3501 case SQLITE_BLOB: {
3502 int n2 = sqlite3_value_bytes(pVal);
3503 const unsigned char *z2 = sqlite3_value_blob(pVal);
3504 sha3_step_vformat(p,"B%d:",n2);
3505 SHA3Update(p, z2, n2);
3506 break;
3507 }
3508 }
3509 }
3510
3511 /*
3512 ** Implementation of the sha3_query(SQL,SIZE) function.
3513 **
3514 ** This function compiles and runs the SQL statement(s) given in the
@@ -3467,64 +3595,55 @@
3595
3596 /* Compute a hash over the result of the query */
3597 while( SQLITE_ROW==sqlite3_step(pStmt) ){
3598 SHA3Update(&cx,(const unsigned char*)"R",1);
3599 for(i=0; i<nCol; i++){
3600 sha3UpdateFromValue(&cx, sqlite3_column_value(pStmt,i));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3601 }
3602 }
3603 sqlite3_finalize(pStmt);
3604 }
3605 sqlite3_result_blob(context, SHA3Final(&cx), iSize/8, SQLITE_TRANSIENT);
3606 }
3607
3608 /*
3609 ** xStep function for sha3_agg().
3610 */
3611 static void sha3AggStep(
3612 sqlite3_context *context,
3613 int argc,
3614 sqlite3_value **argv
3615 ){
3616 SHA3Context *p;
3617 p = (SHA3Context*)sqlite3_aggregate_context(context, sizeof(*p));
3618 if( p==0 ) return;
3619 if( p->nRate==0 ){
3620 int sz = 256;
3621 if( argc==2 ){
3622 sz = sqlite3_value_int(argv[1]);
3623 if( sz!=224 && sz!=384 && sz!=512 ){
3624 sz = 256;
3625 }
3626 }
3627 SHA3Init(p, sz);
3628 }
3629 sha3UpdateFromValue(p, argv[0]);
3630 }
3631
3632
3633 /*
3634 ** xFinal function for sha3_agg().
3635 */
3636 static void sha3AggFinal(sqlite3_context *context){
3637 SHA3Context *p;
3638 p = (SHA3Context*)sqlite3_aggregate_context(context, sizeof(*p));
3639 if( p==0 ) return;
3640 if( p->iSize ){
3641 sqlite3_result_blob(context, SHA3Final(p), p->iSize/8, SQLITE_TRANSIENT);
3642 }
3643 }
3644
3645
3646
3647 #ifdef _WIN32
3648
3649 #endif
@@ -3542,10 +3661,20 @@
3661 if( rc==SQLITE_OK ){
3662 rc = sqlite3_create_function(db, "sha3", 2,
3663 SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC,
3664 0, sha3Func, 0, 0);
3665 }
3666 if( rc==SQLITE_OK ){
3667 rc = sqlite3_create_function(db, "sha3_agg", 1,
3668 SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC,
3669 0, 0, sha3AggStep, sha3AggFinal);
3670 }
3671 if( rc==SQLITE_OK ){
3672 rc = sqlite3_create_function(db, "sha3_agg", 2,
3673 SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC,
3674 0, 0, sha3AggStep, sha3AggFinal);
3675 }
3676 if( rc==SQLITE_OK ){
3677 rc = sqlite3_create_function(db, "sha3_query", 1,
3678 SQLITE_UTF8 | SQLITE_DIRECTONLY,
3679 0, sha3QueryFunc, 0, 0);
3680 }
3681
+136 -18
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
1616
** if you want a wrapper to interface SQLite with your choice of programming
1717
** language. The code for the "sqlite3" command-line shell is also in a
1818
** separate file. This file contains only code for the core SQLite library.
1919
**
2020
** The content in this amalgamation comes from Fossil check-in
21
-** 3778b2a9ca1cc12a88ef6c32a1ee7c58a0a8.
21
+** 7a0cdc7edb704a88a77b748cd28f6e00c498.
2222
*/
2323
#define SQLITE_CORE 1
2424
#define SQLITE_AMALGAMATION 1
2525
#ifndef SQLITE_PRIVATE
2626
# define SQLITE_PRIVATE static
@@ -462,11 +462,11 @@
462462
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
463463
** [sqlite_version()] and [sqlite_source_id()].
464464
*/
465465
#define SQLITE_VERSION "3.47.0"
466466
#define SQLITE_VERSION_NUMBER 3047000
467
-#define SQLITE_SOURCE_ID "2024-08-10 15:46:57 3778b2a9ca1cc12a88ef6c32a1ee7c58a0a829ed9715a3d32a225d377d7527ef"
467
+#define SQLITE_SOURCE_ID "2024-08-16 18:51:46 7a0cdc7edb704a88a77b748cd28f6e00c49849cc2c1af838b95b34232ecc21f9"
468468
469469
/*
470470
** CAPI3REF: Run-Time Library Version Numbers
471471
** KEYWORDS: sqlite3_version sqlite3_sourceid
472472
**
@@ -17915,10 +17915,11 @@
1791517915
/* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
1791617916
#define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
1791717917
#define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
1791817918
#define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
1791917919
#define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
17920
+#define SQLITE_OrderBySubq 0x10000000 /* ORDER BY in subquery helps outer */
1792017921
#define SQLITE_AllOpts 0xffffffff /* All optimizations */
1792117922
1792217923
/*
1792317924
** Macros for testing whether or not optimizations are enabled or disabled.
1792417925
*/
@@ -120471,16 +120472,17 @@
120471120472
if( rc ) return rc;
120472120473
120473120474
while( sqlite3_step(pStmt)==SQLITE_ROW ){
120474120475
int nIdxCol = 1; /* Number of columns in stat4 records */
120475120476
120476
- char *zIndex; /* Index name */
120477
- Index *pIdx; /* Pointer to the index object */
120478
- int nSample; /* Number of samples */
120479
- int nByte; /* Bytes of space required */
120480
- int i; /* Bytes of space required */
120481
- tRowcnt *pSpace;
120477
+ char *zIndex; /* Index name */
120478
+ Index *pIdx; /* Pointer to the index object */
120479
+ int nSample; /* Number of samples */
120480
+ int nByte; /* Bytes of space required */
120481
+ int i; /* Bytes of space required */
120482
+ tRowcnt *pSpace; /* Available allocated memory space */
120483
+ u8 *pPtr; /* Available memory as a u8 for easier manipulation */
120482120484
120483120485
zIndex = (char *)sqlite3_column_text(pStmt, 0);
120484120486
if( zIndex==0 ) continue;
120485120487
nSample = sqlite3_column_int(pStmt, 1);
120486120488
pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
@@ -120496,20 +120498,22 @@
120496120498
}else{
120497120499
nIdxCol = pIdx->nColumn;
120498120500
}
120499120501
pIdx->nSampleCol = nIdxCol;
120500120502
pIdx->mxSample = nSample;
120501
- nByte = sizeof(IndexSample) * nSample;
120503
+ nByte = ROUND8(sizeof(IndexSample) * nSample);
120502120504
nByte += sizeof(tRowcnt) * nIdxCol * 3 * nSample;
120503120505
nByte += nIdxCol * sizeof(tRowcnt); /* Space for Index.aAvgEq[] */
120504120506
120505120507
pIdx->aSample = sqlite3DbMallocZero(db, nByte);
120506120508
if( pIdx->aSample==0 ){
120507120509
sqlite3_finalize(pStmt);
120508120510
return SQLITE_NOMEM_BKPT;
120509120511
}
120510
- pSpace = (tRowcnt*)&pIdx->aSample[nSample];
120512
+ pPtr = (u8*)pIdx->aSample;
120513
+ pPtr += ROUND8(nSample*sizeof(pIdx->aSample[0]));
120514
+ pSpace = (tRowcnt*)pPtr;
120511120515
assert( EIGHT_BYTE_ALIGNMENT( pSpace ) );
120512120516
pIdx->aAvgEq = pSpace; pSpace += nIdxCol;
120513120517
pIdx->pTable->tabFlags |= TF_HasStat4;
120514120518
for(i=0; i<nSample; i++){
120515120519
pIdx->aSample[i].anEq = pSpace; pSpace += nIdxCol;
@@ -157188,10 +157192,11 @@
157188157192
u16 nEq; /* Number of equality constraints */
157189157193
u16 nBtm; /* Size of BTM vector */
157190157194
u16 nTop; /* Size of TOP vector */
157191157195
u16 nDistinctCol; /* Index columns used to sort for DISTINCT */
157192157196
Index *pIndex; /* Index used, or NULL */
157197
+ ExprList *pOrderBy; /* ORDER BY clause if this is really a subquery */
157193157198
} btree;
157194157199
struct { /* Information for virtual tables */
157195157200
int idxNum; /* Index number */
157196157201
u32 needFree : 1; /* True if sqlite3_free(idxStr) is needed */
157197157202
u32 bOmitOffset : 1; /* True to let virtual table handle offset */
@@ -157681,11 +157686,12 @@
157681157686
#define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */
157682157687
#define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */
157683157688
#define WHERE_BLOOMFILTER 0x00400000 /* Consider using a Bloom-filter */
157684157689
#define WHERE_SELFCULL 0x00800000 /* nOut reduced by extra WHERE terms */
157685157690
#define WHERE_OMIT_OFFSET 0x01000000 /* Set offset counter to zero */
157686
- /* 0x02000000 -- available for reuse */
157691
+#define WHERE_COROUTINE 0x02000000 /* Implemented by co-routine.
157692
+ ** NB: False-negatives are possible */
157687157693
#define WHERE_EXPRIDX 0x04000000 /* Uses an index-on-expressions */
157688157694
157689157695
#endif /* !defined(SQLITE_WHEREINT_H) */
157690157696
157691157697
/************** End of whereInt.h ********************************************/
@@ -166458,10 +166464,14 @@
166458166464
#else
166459166465
pNew->rRun = rSize + 16;
166460166466
#endif
166461166467
ApplyCostMultiplier(pNew->rRun, pTab->costMult);
166462166468
whereLoopOutputAdjust(pWC, pNew, rSize);
166469
+ if( pSrc->pSelect ){
166470
+ if( pSrc->fg.viaCoroutine ) pNew->wsFlags |= WHERE_COROUTINE;
166471
+ pNew->u.btree.pOrderBy = pSrc->pSelect->pOrderBy;
166472
+ }
166463166473
rc = whereLoopInsert(pBuilder, pNew);
166464166474
pNew->nOut = rSize;
166465166475
if( rc ) break;
166466166476
}else{
166467166477
Bitmask m;
@@ -167290,10 +167300,101 @@
167290167300
}
167291167301
167292167302
whereLoopClear(db, pNew);
167293167303
return rc;
167294167304
}
167305
+
167306
+/* Implementation of the order-by-subquery optimization:
167307
+**
167308
+** WhereLoop pLoop, which the iLoop-th term of the nested loop, is really
167309
+** a subquery or CTE that has an ORDER BY clause. See if any of the terms
167310
+** in the subquery ORDER BY clause will satisfy pOrderBy from the outer
167311
+** query. Mark off all satisfied terms (by setting bits in *pOBSat) and
167312
+** return TRUE if they do. If not, return false.
167313
+**
167314
+** Example:
167315
+**
167316
+** CREATE TABLE t1(a,b,c, PRIMARY KEY(a,b));
167317
+** CREATE TABLE t2(x,y);
167318
+** WITH t3(p,q) AS MATERIALIZED (SELECT x+y, x-y FROM t2 ORDER BY x+y)
167319
+** SELECT * FROM t3 JOIN t1 ON a=q ORDER BY p, b;
167320
+**
167321
+** The CTE named "t3" comes out in the natural order of "p", so the first
167322
+** first them of "ORDER BY p,b" is satisfied by a sequential scan of "t3"
167323
+** and sorting only needs to occur on the second term "b".
167324
+**
167325
+** Limitations:
167326
+**
167327
+** (1) The optimization is not applied if the outer ORDER BY contains
167328
+** a COLLATE clause. The optimization might be applied if the
167329
+** outer ORDER BY uses NULLS FIRST, NULLS LAST, ASC, and/or DESC as
167330
+** long as the subquery ORDER BY does the same. But if the
167331
+** outer ORDER BY uses COLLATE, even a redundant COLLATE, the
167332
+** optimization is bypassed.
167333
+**
167334
+** (2) The subquery ORDER BY terms must exactly match subquery result
167335
+** columns, including any COLLATE annotations. This routine relies
167336
+** on iOrderByCol to do matching between order by terms and result
167337
+** columns, and iOrderByCol will not be set if the result column
167338
+** and ORDER BY collations differ.
167339
+**
167340
+** (3) The subquery and outer ORDER BY can be in opposite directions as
167341
+** long as the subquery is materialized. If the subquery is
167342
+** implemented as a co-routine, the sort orders must be in the same
167343
+** direction because there is no way to run a co-routine backwards.
167344
+*/
167345
+static SQLITE_NOINLINE int wherePathMatchSubqueryOB(
167346
+ WhereInfo *pWInfo, /* The WHERE clause */
167347
+ WhereLoop *pLoop, /* The nested loop term that is a subquery */
167348
+ int iLoop, /* Which level of the nested loop. 0==outermost */
167349
+ int iCur, /* Cursor used by the this loop */
167350
+ ExprList *pOrderBy, /* The ORDER BY clause on the whole query */
167351
+ Bitmask *pRevMask, /* When loops need to go in reverse order */
167352
+ Bitmask *pOBSat /* Which terms of pOrderBy are satisfied so far */
167353
+){
167354
+ int iOB; /* Index into pOrderBy->a[] */
167355
+ int jSub; /* Index into pSubOB->a[] */
167356
+ u8 rev = 0; /* True if iOB and jSub sort in opposite directions */
167357
+ u8 revIdx = 0; /* Sort direction for jSub */
167358
+ Expr *pOBExpr; /* Current term of outer ORDER BY */
167359
+ ExprList *pSubOB; /* Complete ORDER BY on the subquery */
167360
+
167361
+ pSubOB = pLoop->u.btree.pOrderBy;
167362
+ assert( pSubOB!=0 );
167363
+ for(iOB=0; (MASKBIT(iOB) & *pOBSat)!=0; iOB++){}
167364
+ for(jSub=0; jSub<pSubOB->nExpr && iOB<pOrderBy->nExpr; jSub++, iOB++){
167365
+ if( pSubOB->a[jSub].u.x.iOrderByCol==0 ) break;
167366
+ pOBExpr = pOrderBy->a[iOB].pExpr;
167367
+ if( pOBExpr->op!=TK_COLUMN && pOBExpr->op!=TK_AGG_COLUMN ) break;
167368
+ if( pOBExpr->iTable!=iCur ) break;
167369
+ if( pOBExpr->iColumn!=pSubOB->a[jSub].u.x.iOrderByCol-1 ) break;
167370
+ if( (pWInfo->wctrlFlags & WHERE_GROUPBY)==0 ){
167371
+ u8 sfOB = pOrderBy->a[iOB].fg.sortFlags; /* sortFlags for iOB */
167372
+ u8 sfSub = pSubOB->a[jSub].fg.sortFlags; /* sortFlags for jSub */
167373
+ if( (sfSub & KEYINFO_ORDER_BIGNULL) != (sfOB & KEYINFO_ORDER_BIGNULL) ){
167374
+ break;
167375
+ }
167376
+ revIdx = sfSub & KEYINFO_ORDER_DESC;
167377
+ if( jSub>0 ){
167378
+ if( (rev^revIdx)!=(sfOB & KEYINFO_ORDER_DESC) ){
167379
+ break;
167380
+ }
167381
+ }else{
167382
+ rev = revIdx ^ (sfOB & KEYINFO_ORDER_DESC);
167383
+ if( rev ){
167384
+ if( (pLoop->wsFlags & WHERE_COROUTINE)!=0 ){
167385
+ /* Cannot run a co-routine in reverse order */
167386
+ break;
167387
+ }
167388
+ *pRevMask |= MASKBIT(iLoop);
167389
+ }
167390
+ }
167391
+ }
167392
+ *pOBSat |= MASKBIT(iOB);
167393
+ }
167394
+ return jSub>0;
167395
+}
167295167396
167296167397
/*
167297167398
** Examine a WherePath (with the addition of the extra WhereLoop of the 6th
167298167399
** parameters) to see if it outputs rows in the requested ORDER BY
167299167400
** (or GROUP BY) without requiring a separate sort operation. Return N:
@@ -167436,13 +167537,22 @@
167436167537
obSat |= MASKBIT(i);
167437167538
}
167438167539
167439167540
if( (pLoop->wsFlags & WHERE_ONEROW)==0 ){
167440167541
if( pLoop->wsFlags & WHERE_IPK ){
167542
+ if( pLoop->u.btree.pOrderBy
167543
+ && OptimizationEnabled(db, SQLITE_OrderBySubq)
167544
+ && wherePathMatchSubqueryOB(pWInfo,pLoop,iLoop,iCur,
167545
+ pOrderBy,pRevMask, &obSat)
167546
+ ){
167547
+ nColumn = 0;
167548
+ isOrderDistinct = 0;
167549
+ }else{
167550
+ nColumn = 1;
167551
+ }
167441167552
pIndex = 0;
167442167553
nKeyCol = 0;
167443
- nColumn = 1;
167444167554
}else if( (pIndex = pLoop->u.btree.pIndex)==0 || pIndex->bUnordered ){
167445167555
return 0;
167446167556
}else{
167447167557
nKeyCol = pIndex->nKeyCol;
167448167558
nColumn = pIndex->nColumn;
@@ -167533,11 +167643,11 @@
167533167643
isOrderDistinct = 0;
167534167644
}
167535167645
}
167536167646
167537167647
/* Find the ORDER BY term that corresponds to the j-th column
167538
- ** of the index and mark that ORDER BY term off
167648
+ ** of the index and mark that ORDER BY term having been satisfied.
167539167649
*/
167540167650
isMatch = 0;
167541167651
for(i=0; bOnce && i<nOrderBy; i++){
167542167652
if( MASKBIT(i) & obSat ) continue;
167543167653
pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr);
@@ -237272,17 +237382,21 @@
237272237382
Fts5ExprPhrase **apExprPhrase; /* Pointers to phrase objects */
237273237383
};
237274237384
237275237385
/*
237276237386
** eType:
237277
-** Expression node type. Always one of:
237387
+** Expression node type. Usually one of:
237278237388
**
237279237389
** FTS5_AND (nChild, apChild valid)
237280237390
** FTS5_OR (nChild, apChild valid)
237281237391
** FTS5_NOT (nChild, apChild valid)
237282237392
** FTS5_STRING (pNear valid)
237283237393
** FTS5_TERM (pNear valid)
237394
+**
237395
+** An expression node with eType==0 may also exist. It always matches zero
237396
+** rows. This is created when a phrase containing no tokens is parsed.
237397
+** e.g. "".
237284237398
**
237285237399
** iHeight:
237286237400
** Distance from this node to furthest leaf. This is always 0 for nodes
237287237401
** of type FTS5_STRING and FTS5_TERM. For all other nodes it is one
237288237402
** greater than the largest child value.
@@ -240330,10 +240444,11 @@
240330240444
240331240445
static int fts5ExprCheckPoslists(Fts5ExprNode *pNode, i64 iRowid){
240332240446
pNode->iRowid = iRowid;
240333240447
pNode->bEof = 0;
240334240448
switch( pNode->eType ){
240449
+ case 0:
240335240450
case FTS5_TERM:
240336240451
case FTS5_STRING:
240337240452
return (pNode->pNear->apPhrase[0]->poslist.n>0);
240338240453
240339240454
case FTS5_AND: {
@@ -252389,24 +252504,27 @@
252389252504
252390252505
return pRet;
252391252506
}
252392252507
252393252508
static void fts5ApiPhraseNext(
252394
- Fts5Context *pUnused,
252509
+ Fts5Context *pCtx,
252395252510
Fts5PhraseIter *pIter,
252396252511
int *piCol, int *piOff
252397252512
){
252398
- UNUSED_PARAM(pUnused);
252399252513
if( pIter->a>=pIter->b ){
252400252514
*piCol = -1;
252401252515
*piOff = -1;
252402252516
}else{
252403252517
int iVal;
252404252518
pIter->a += fts5GetVarint32(pIter->a, iVal);
252405252519
if( iVal==1 ){
252520
+ /* Avoid returning a (*piCol) value that is too large for the table,
252521
+ ** even if the position-list is corrupt. The caller might not be
252522
+ ** expecting it. */
252523
+ int nCol = ((Fts5Table*)(((Fts5Cursor*)pCtx)->base.pVtab))->pConfig->nCol;
252406252524
pIter->a += fts5GetVarint32(pIter->a, iVal);
252407
- *piCol = iVal;
252525
+ *piCol = (iVal>=nCol ? nCol-1 : iVal);
252408252526
*piOff = 0;
252409252527
pIter->a += fts5GetVarint32(pIter->a, iVal);
252410252528
}
252411252529
*piOff += (iVal-2);
252412252530
}
@@ -253117,11 +253235,11 @@
253117253235
int nArg, /* Number of args */
253118253236
sqlite3_value **apUnused /* Function arguments */
253119253237
){
253120253238
assert( nArg==0 );
253121253239
UNUSED_PARAM2(nArg, apUnused);
253122
- sqlite3_result_text(pCtx, "fts5: 2024-08-10 15:46:57 3778b2a9ca1cc12a88ef6c32a1ee7c58a0a829ed9715a3d32a225d377d7527ef", -1, SQLITE_TRANSIENT);
253240
+ sqlite3_result_text(pCtx, "fts5: 2024-08-16 18:51:46 7a0cdc7edb704a88a77b748cd28f6e00c49849cc2c1af838b95b34232ecc21f9", -1, SQLITE_TRANSIENT);
253123253241
}
253124253242
253125253243
/*
253126253244
** Return true if zName is the extension on one of the shadow tables used
253127253245
** by this module.
253128253246
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 3778b2a9ca1cc12a88ef6c32a1ee7c58a0a8.
22 */
23 #define SQLITE_CORE 1
24 #define SQLITE_AMALGAMATION 1
25 #ifndef SQLITE_PRIVATE
26 # define SQLITE_PRIVATE static
@@ -462,11 +462,11 @@
462 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
463 ** [sqlite_version()] and [sqlite_source_id()].
464 */
465 #define SQLITE_VERSION "3.47.0"
466 #define SQLITE_VERSION_NUMBER 3047000
467 #define SQLITE_SOURCE_ID "2024-08-10 15:46:57 3778b2a9ca1cc12a88ef6c32a1ee7c58a0a829ed9715a3d32a225d377d7527ef"
468
469 /*
470 ** CAPI3REF: Run-Time Library Version Numbers
471 ** KEYWORDS: sqlite3_version sqlite3_sourceid
472 **
@@ -17915,10 +17915,11 @@
17915 /* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
17916 #define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
17917 #define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
17918 #define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
17919 #define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
 
17920 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
17921
17922 /*
17923 ** Macros for testing whether or not optimizations are enabled or disabled.
17924 */
@@ -120471,16 +120472,17 @@
120471 if( rc ) return rc;
120472
120473 while( sqlite3_step(pStmt)==SQLITE_ROW ){
120474 int nIdxCol = 1; /* Number of columns in stat4 records */
120475
120476 char *zIndex; /* Index name */
120477 Index *pIdx; /* Pointer to the index object */
120478 int nSample; /* Number of samples */
120479 int nByte; /* Bytes of space required */
120480 int i; /* Bytes of space required */
120481 tRowcnt *pSpace;
 
120482
120483 zIndex = (char *)sqlite3_column_text(pStmt, 0);
120484 if( zIndex==0 ) continue;
120485 nSample = sqlite3_column_int(pStmt, 1);
120486 pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
@@ -120496,20 +120498,22 @@
120496 }else{
120497 nIdxCol = pIdx->nColumn;
120498 }
120499 pIdx->nSampleCol = nIdxCol;
120500 pIdx->mxSample = nSample;
120501 nByte = sizeof(IndexSample) * nSample;
120502 nByte += sizeof(tRowcnt) * nIdxCol * 3 * nSample;
120503 nByte += nIdxCol * sizeof(tRowcnt); /* Space for Index.aAvgEq[] */
120504
120505 pIdx->aSample = sqlite3DbMallocZero(db, nByte);
120506 if( pIdx->aSample==0 ){
120507 sqlite3_finalize(pStmt);
120508 return SQLITE_NOMEM_BKPT;
120509 }
120510 pSpace = (tRowcnt*)&pIdx->aSample[nSample];
 
 
120511 assert( EIGHT_BYTE_ALIGNMENT( pSpace ) );
120512 pIdx->aAvgEq = pSpace; pSpace += nIdxCol;
120513 pIdx->pTable->tabFlags |= TF_HasStat4;
120514 for(i=0; i<nSample; i++){
120515 pIdx->aSample[i].anEq = pSpace; pSpace += nIdxCol;
@@ -157188,10 +157192,11 @@
157188 u16 nEq; /* Number of equality constraints */
157189 u16 nBtm; /* Size of BTM vector */
157190 u16 nTop; /* Size of TOP vector */
157191 u16 nDistinctCol; /* Index columns used to sort for DISTINCT */
157192 Index *pIndex; /* Index used, or NULL */
 
157193 } btree;
157194 struct { /* Information for virtual tables */
157195 int idxNum; /* Index number */
157196 u32 needFree : 1; /* True if sqlite3_free(idxStr) is needed */
157197 u32 bOmitOffset : 1; /* True to let virtual table handle offset */
@@ -157681,11 +157686,12 @@
157681 #define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */
157682 #define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */
157683 #define WHERE_BLOOMFILTER 0x00400000 /* Consider using a Bloom-filter */
157684 #define WHERE_SELFCULL 0x00800000 /* nOut reduced by extra WHERE terms */
157685 #define WHERE_OMIT_OFFSET 0x01000000 /* Set offset counter to zero */
157686 /* 0x02000000 -- available for reuse */
 
157687 #define WHERE_EXPRIDX 0x04000000 /* Uses an index-on-expressions */
157688
157689 #endif /* !defined(SQLITE_WHEREINT_H) */
157690
157691 /************** End of whereInt.h ********************************************/
@@ -166458,10 +166464,14 @@
166458 #else
166459 pNew->rRun = rSize + 16;
166460 #endif
166461 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
166462 whereLoopOutputAdjust(pWC, pNew, rSize);
 
 
 
 
166463 rc = whereLoopInsert(pBuilder, pNew);
166464 pNew->nOut = rSize;
166465 if( rc ) break;
166466 }else{
166467 Bitmask m;
@@ -167290,10 +167300,101 @@
167290 }
167291
167292 whereLoopClear(db, pNew);
167293 return rc;
167294 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167295
167296 /*
167297 ** Examine a WherePath (with the addition of the extra WhereLoop of the 6th
167298 ** parameters) to see if it outputs rows in the requested ORDER BY
167299 ** (or GROUP BY) without requiring a separate sort operation. Return N:
@@ -167436,13 +167537,22 @@
167436 obSat |= MASKBIT(i);
167437 }
167438
167439 if( (pLoop->wsFlags & WHERE_ONEROW)==0 ){
167440 if( pLoop->wsFlags & WHERE_IPK ){
 
 
 
 
 
 
 
 
 
 
167441 pIndex = 0;
167442 nKeyCol = 0;
167443 nColumn = 1;
167444 }else if( (pIndex = pLoop->u.btree.pIndex)==0 || pIndex->bUnordered ){
167445 return 0;
167446 }else{
167447 nKeyCol = pIndex->nKeyCol;
167448 nColumn = pIndex->nColumn;
@@ -167533,11 +167643,11 @@
167533 isOrderDistinct = 0;
167534 }
167535 }
167536
167537 /* Find the ORDER BY term that corresponds to the j-th column
167538 ** of the index and mark that ORDER BY term off
167539 */
167540 isMatch = 0;
167541 for(i=0; bOnce && i<nOrderBy; i++){
167542 if( MASKBIT(i) & obSat ) continue;
167543 pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr);
@@ -237272,17 +237382,21 @@
237272 Fts5ExprPhrase **apExprPhrase; /* Pointers to phrase objects */
237273 };
237274
237275 /*
237276 ** eType:
237277 ** Expression node type. Always one of:
237278 **
237279 ** FTS5_AND (nChild, apChild valid)
237280 ** FTS5_OR (nChild, apChild valid)
237281 ** FTS5_NOT (nChild, apChild valid)
237282 ** FTS5_STRING (pNear valid)
237283 ** FTS5_TERM (pNear valid)
 
 
 
 
237284 **
237285 ** iHeight:
237286 ** Distance from this node to furthest leaf. This is always 0 for nodes
237287 ** of type FTS5_STRING and FTS5_TERM. For all other nodes it is one
237288 ** greater than the largest child value.
@@ -240330,10 +240444,11 @@
240330
240331 static int fts5ExprCheckPoslists(Fts5ExprNode *pNode, i64 iRowid){
240332 pNode->iRowid = iRowid;
240333 pNode->bEof = 0;
240334 switch( pNode->eType ){
 
240335 case FTS5_TERM:
240336 case FTS5_STRING:
240337 return (pNode->pNear->apPhrase[0]->poslist.n>0);
240338
240339 case FTS5_AND: {
@@ -252389,24 +252504,27 @@
252389
252390 return pRet;
252391 }
252392
252393 static void fts5ApiPhraseNext(
252394 Fts5Context *pUnused,
252395 Fts5PhraseIter *pIter,
252396 int *piCol, int *piOff
252397 ){
252398 UNUSED_PARAM(pUnused);
252399 if( pIter->a>=pIter->b ){
252400 *piCol = -1;
252401 *piOff = -1;
252402 }else{
252403 int iVal;
252404 pIter->a += fts5GetVarint32(pIter->a, iVal);
252405 if( iVal==1 ){
 
 
 
 
252406 pIter->a += fts5GetVarint32(pIter->a, iVal);
252407 *piCol = iVal;
252408 *piOff = 0;
252409 pIter->a += fts5GetVarint32(pIter->a, iVal);
252410 }
252411 *piOff += (iVal-2);
252412 }
@@ -253117,11 +253235,11 @@
253117 int nArg, /* Number of args */
253118 sqlite3_value **apUnused /* Function arguments */
253119 ){
253120 assert( nArg==0 );
253121 UNUSED_PARAM2(nArg, apUnused);
253122 sqlite3_result_text(pCtx, "fts5: 2024-08-10 15:46:57 3778b2a9ca1cc12a88ef6c32a1ee7c58a0a829ed9715a3d32a225d377d7527ef", -1, SQLITE_TRANSIENT);
253123 }
253124
253125 /*
253126 ** Return true if zName is the extension on one of the shadow tables used
253127 ** by this module.
253128
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -16,11 +16,11 @@
16 ** if you want a wrapper to interface SQLite with your choice of programming
17 ** language. The code for the "sqlite3" command-line shell is also in a
18 ** separate file. This file contains only code for the core SQLite library.
19 **
20 ** The content in this amalgamation comes from Fossil check-in
21 ** 7a0cdc7edb704a88a77b748cd28f6e00c498.
22 */
23 #define SQLITE_CORE 1
24 #define SQLITE_AMALGAMATION 1
25 #ifndef SQLITE_PRIVATE
26 # define SQLITE_PRIVATE static
@@ -462,11 +462,11 @@
462 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
463 ** [sqlite_version()] and [sqlite_source_id()].
464 */
465 #define SQLITE_VERSION "3.47.0"
466 #define SQLITE_VERSION_NUMBER 3047000
467 #define SQLITE_SOURCE_ID "2024-08-16 18:51:46 7a0cdc7edb704a88a77b748cd28f6e00c49849cc2c1af838b95b34232ecc21f9"
468
469 /*
470 ** CAPI3REF: Run-Time Library Version Numbers
471 ** KEYWORDS: sqlite3_version sqlite3_sourceid
472 **
@@ -17915,10 +17915,11 @@
17915 /* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
17916 #define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
17917 #define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
17918 #define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
17919 #define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
17920 #define SQLITE_OrderBySubq 0x10000000 /* ORDER BY in subquery helps outer */
17921 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
17922
17923 /*
17924 ** Macros for testing whether or not optimizations are enabled or disabled.
17925 */
@@ -120471,16 +120472,17 @@
120472 if( rc ) return rc;
120473
120474 while( sqlite3_step(pStmt)==SQLITE_ROW ){
120475 int nIdxCol = 1; /* Number of columns in stat4 records */
120476
120477 char *zIndex; /* Index name */
120478 Index *pIdx; /* Pointer to the index object */
120479 int nSample; /* Number of samples */
120480 int nByte; /* Bytes of space required */
120481 int i; /* Bytes of space required */
120482 tRowcnt *pSpace; /* Available allocated memory space */
120483 u8 *pPtr; /* Available memory as a u8 for easier manipulation */
120484
120485 zIndex = (char *)sqlite3_column_text(pStmt, 0);
120486 if( zIndex==0 ) continue;
120487 nSample = sqlite3_column_int(pStmt, 1);
120488 pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
@@ -120496,20 +120498,22 @@
120498 }else{
120499 nIdxCol = pIdx->nColumn;
120500 }
120501 pIdx->nSampleCol = nIdxCol;
120502 pIdx->mxSample = nSample;
120503 nByte = ROUND8(sizeof(IndexSample) * nSample);
120504 nByte += sizeof(tRowcnt) * nIdxCol * 3 * nSample;
120505 nByte += nIdxCol * sizeof(tRowcnt); /* Space for Index.aAvgEq[] */
120506
120507 pIdx->aSample = sqlite3DbMallocZero(db, nByte);
120508 if( pIdx->aSample==0 ){
120509 sqlite3_finalize(pStmt);
120510 return SQLITE_NOMEM_BKPT;
120511 }
120512 pPtr = (u8*)pIdx->aSample;
120513 pPtr += ROUND8(nSample*sizeof(pIdx->aSample[0]));
120514 pSpace = (tRowcnt*)pPtr;
120515 assert( EIGHT_BYTE_ALIGNMENT( pSpace ) );
120516 pIdx->aAvgEq = pSpace; pSpace += nIdxCol;
120517 pIdx->pTable->tabFlags |= TF_HasStat4;
120518 for(i=0; i<nSample; i++){
120519 pIdx->aSample[i].anEq = pSpace; pSpace += nIdxCol;
@@ -157188,10 +157192,11 @@
157192 u16 nEq; /* Number of equality constraints */
157193 u16 nBtm; /* Size of BTM vector */
157194 u16 nTop; /* Size of TOP vector */
157195 u16 nDistinctCol; /* Index columns used to sort for DISTINCT */
157196 Index *pIndex; /* Index used, or NULL */
157197 ExprList *pOrderBy; /* ORDER BY clause if this is really a subquery */
157198 } btree;
157199 struct { /* Information for virtual tables */
157200 int idxNum; /* Index number */
157201 u32 needFree : 1; /* True if sqlite3_free(idxStr) is needed */
157202 u32 bOmitOffset : 1; /* True to let virtual table handle offset */
@@ -157681,11 +157686,12 @@
157686 #define WHERE_IN_SEEKSCAN 0x00100000 /* Seek-scan optimization for IN */
157687 #define WHERE_TRANSCONS 0x00200000 /* Uses a transitive constraint */
157688 #define WHERE_BLOOMFILTER 0x00400000 /* Consider using a Bloom-filter */
157689 #define WHERE_SELFCULL 0x00800000 /* nOut reduced by extra WHERE terms */
157690 #define WHERE_OMIT_OFFSET 0x01000000 /* Set offset counter to zero */
157691 #define WHERE_COROUTINE 0x02000000 /* Implemented by co-routine.
157692 ** NB: False-negatives are possible */
157693 #define WHERE_EXPRIDX 0x04000000 /* Uses an index-on-expressions */
157694
157695 #endif /* !defined(SQLITE_WHEREINT_H) */
157696
157697 /************** End of whereInt.h ********************************************/
@@ -166458,10 +166464,14 @@
166464 #else
166465 pNew->rRun = rSize + 16;
166466 #endif
166467 ApplyCostMultiplier(pNew->rRun, pTab->costMult);
166468 whereLoopOutputAdjust(pWC, pNew, rSize);
166469 if( pSrc->pSelect ){
166470 if( pSrc->fg.viaCoroutine ) pNew->wsFlags |= WHERE_COROUTINE;
166471 pNew->u.btree.pOrderBy = pSrc->pSelect->pOrderBy;
166472 }
166473 rc = whereLoopInsert(pBuilder, pNew);
166474 pNew->nOut = rSize;
166475 if( rc ) break;
166476 }else{
166477 Bitmask m;
@@ -167290,10 +167300,101 @@
167300 }
167301
167302 whereLoopClear(db, pNew);
167303 return rc;
167304 }
167305
167306 /* Implementation of the order-by-subquery optimization:
167307 **
167308 ** WhereLoop pLoop, which the iLoop-th term of the nested loop, is really
167309 ** a subquery or CTE that has an ORDER BY clause. See if any of the terms
167310 ** in the subquery ORDER BY clause will satisfy pOrderBy from the outer
167311 ** query. Mark off all satisfied terms (by setting bits in *pOBSat) and
167312 ** return TRUE if they do. If not, return false.
167313 **
167314 ** Example:
167315 **
167316 ** CREATE TABLE t1(a,b,c, PRIMARY KEY(a,b));
167317 ** CREATE TABLE t2(x,y);
167318 ** WITH t3(p,q) AS MATERIALIZED (SELECT x+y, x-y FROM t2 ORDER BY x+y)
167319 ** SELECT * FROM t3 JOIN t1 ON a=q ORDER BY p, b;
167320 **
167321 ** The CTE named "t3" comes out in the natural order of "p", so the first
167322 ** first them of "ORDER BY p,b" is satisfied by a sequential scan of "t3"
167323 ** and sorting only needs to occur on the second term "b".
167324 **
167325 ** Limitations:
167326 **
167327 ** (1) The optimization is not applied if the outer ORDER BY contains
167328 ** a COLLATE clause. The optimization might be applied if the
167329 ** outer ORDER BY uses NULLS FIRST, NULLS LAST, ASC, and/or DESC as
167330 ** long as the subquery ORDER BY does the same. But if the
167331 ** outer ORDER BY uses COLLATE, even a redundant COLLATE, the
167332 ** optimization is bypassed.
167333 **
167334 ** (2) The subquery ORDER BY terms must exactly match subquery result
167335 ** columns, including any COLLATE annotations. This routine relies
167336 ** on iOrderByCol to do matching between order by terms and result
167337 ** columns, and iOrderByCol will not be set if the result column
167338 ** and ORDER BY collations differ.
167339 **
167340 ** (3) The subquery and outer ORDER BY can be in opposite directions as
167341 ** long as the subquery is materialized. If the subquery is
167342 ** implemented as a co-routine, the sort orders must be in the same
167343 ** direction because there is no way to run a co-routine backwards.
167344 */
167345 static SQLITE_NOINLINE int wherePathMatchSubqueryOB(
167346 WhereInfo *pWInfo, /* The WHERE clause */
167347 WhereLoop *pLoop, /* The nested loop term that is a subquery */
167348 int iLoop, /* Which level of the nested loop. 0==outermost */
167349 int iCur, /* Cursor used by the this loop */
167350 ExprList *pOrderBy, /* The ORDER BY clause on the whole query */
167351 Bitmask *pRevMask, /* When loops need to go in reverse order */
167352 Bitmask *pOBSat /* Which terms of pOrderBy are satisfied so far */
167353 ){
167354 int iOB; /* Index into pOrderBy->a[] */
167355 int jSub; /* Index into pSubOB->a[] */
167356 u8 rev = 0; /* True if iOB and jSub sort in opposite directions */
167357 u8 revIdx = 0; /* Sort direction for jSub */
167358 Expr *pOBExpr; /* Current term of outer ORDER BY */
167359 ExprList *pSubOB; /* Complete ORDER BY on the subquery */
167360
167361 pSubOB = pLoop->u.btree.pOrderBy;
167362 assert( pSubOB!=0 );
167363 for(iOB=0; (MASKBIT(iOB) & *pOBSat)!=0; iOB++){}
167364 for(jSub=0; jSub<pSubOB->nExpr && iOB<pOrderBy->nExpr; jSub++, iOB++){
167365 if( pSubOB->a[jSub].u.x.iOrderByCol==0 ) break;
167366 pOBExpr = pOrderBy->a[iOB].pExpr;
167367 if( pOBExpr->op!=TK_COLUMN && pOBExpr->op!=TK_AGG_COLUMN ) break;
167368 if( pOBExpr->iTable!=iCur ) break;
167369 if( pOBExpr->iColumn!=pSubOB->a[jSub].u.x.iOrderByCol-1 ) break;
167370 if( (pWInfo->wctrlFlags & WHERE_GROUPBY)==0 ){
167371 u8 sfOB = pOrderBy->a[iOB].fg.sortFlags; /* sortFlags for iOB */
167372 u8 sfSub = pSubOB->a[jSub].fg.sortFlags; /* sortFlags for jSub */
167373 if( (sfSub & KEYINFO_ORDER_BIGNULL) != (sfOB & KEYINFO_ORDER_BIGNULL) ){
167374 break;
167375 }
167376 revIdx = sfSub & KEYINFO_ORDER_DESC;
167377 if( jSub>0 ){
167378 if( (rev^revIdx)!=(sfOB & KEYINFO_ORDER_DESC) ){
167379 break;
167380 }
167381 }else{
167382 rev = revIdx ^ (sfOB & KEYINFO_ORDER_DESC);
167383 if( rev ){
167384 if( (pLoop->wsFlags & WHERE_COROUTINE)!=0 ){
167385 /* Cannot run a co-routine in reverse order */
167386 break;
167387 }
167388 *pRevMask |= MASKBIT(iLoop);
167389 }
167390 }
167391 }
167392 *pOBSat |= MASKBIT(iOB);
167393 }
167394 return jSub>0;
167395 }
167396
167397 /*
167398 ** Examine a WherePath (with the addition of the extra WhereLoop of the 6th
167399 ** parameters) to see if it outputs rows in the requested ORDER BY
167400 ** (or GROUP BY) without requiring a separate sort operation. Return N:
@@ -167436,13 +167537,22 @@
167537 obSat |= MASKBIT(i);
167538 }
167539
167540 if( (pLoop->wsFlags & WHERE_ONEROW)==0 ){
167541 if( pLoop->wsFlags & WHERE_IPK ){
167542 if( pLoop->u.btree.pOrderBy
167543 && OptimizationEnabled(db, SQLITE_OrderBySubq)
167544 && wherePathMatchSubqueryOB(pWInfo,pLoop,iLoop,iCur,
167545 pOrderBy,pRevMask, &obSat)
167546 ){
167547 nColumn = 0;
167548 isOrderDistinct = 0;
167549 }else{
167550 nColumn = 1;
167551 }
167552 pIndex = 0;
167553 nKeyCol = 0;
 
167554 }else if( (pIndex = pLoop->u.btree.pIndex)==0 || pIndex->bUnordered ){
167555 return 0;
167556 }else{
167557 nKeyCol = pIndex->nKeyCol;
167558 nColumn = pIndex->nColumn;
@@ -167533,11 +167643,11 @@
167643 isOrderDistinct = 0;
167644 }
167645 }
167646
167647 /* Find the ORDER BY term that corresponds to the j-th column
167648 ** of the index and mark that ORDER BY term having been satisfied.
167649 */
167650 isMatch = 0;
167651 for(i=0; bOnce && i<nOrderBy; i++){
167652 if( MASKBIT(i) & obSat ) continue;
167653 pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr);
@@ -237272,17 +237382,21 @@
237382 Fts5ExprPhrase **apExprPhrase; /* Pointers to phrase objects */
237383 };
237384
237385 /*
237386 ** eType:
237387 ** Expression node type. Usually one of:
237388 **
237389 ** FTS5_AND (nChild, apChild valid)
237390 ** FTS5_OR (nChild, apChild valid)
237391 ** FTS5_NOT (nChild, apChild valid)
237392 ** FTS5_STRING (pNear valid)
237393 ** FTS5_TERM (pNear valid)
237394 **
237395 ** An expression node with eType==0 may also exist. It always matches zero
237396 ** rows. This is created when a phrase containing no tokens is parsed.
237397 ** e.g. "".
237398 **
237399 ** iHeight:
237400 ** Distance from this node to furthest leaf. This is always 0 for nodes
237401 ** of type FTS5_STRING and FTS5_TERM. For all other nodes it is one
237402 ** greater than the largest child value.
@@ -240330,10 +240444,11 @@
240444
240445 static int fts5ExprCheckPoslists(Fts5ExprNode *pNode, i64 iRowid){
240446 pNode->iRowid = iRowid;
240447 pNode->bEof = 0;
240448 switch( pNode->eType ){
240449 case 0:
240450 case FTS5_TERM:
240451 case FTS5_STRING:
240452 return (pNode->pNear->apPhrase[0]->poslist.n>0);
240453
240454 case FTS5_AND: {
@@ -252389,24 +252504,27 @@
252504
252505 return pRet;
252506 }
252507
252508 static void fts5ApiPhraseNext(
252509 Fts5Context *pCtx,
252510 Fts5PhraseIter *pIter,
252511 int *piCol, int *piOff
252512 ){
 
252513 if( pIter->a>=pIter->b ){
252514 *piCol = -1;
252515 *piOff = -1;
252516 }else{
252517 int iVal;
252518 pIter->a += fts5GetVarint32(pIter->a, iVal);
252519 if( iVal==1 ){
252520 /* Avoid returning a (*piCol) value that is too large for the table,
252521 ** even if the position-list is corrupt. The caller might not be
252522 ** expecting it. */
252523 int nCol = ((Fts5Table*)(((Fts5Cursor*)pCtx)->base.pVtab))->pConfig->nCol;
252524 pIter->a += fts5GetVarint32(pIter->a, iVal);
252525 *piCol = (iVal>=nCol ? nCol-1 : iVal);
252526 *piOff = 0;
252527 pIter->a += fts5GetVarint32(pIter->a, iVal);
252528 }
252529 *piOff += (iVal-2);
252530 }
@@ -253117,11 +253235,11 @@
253235 int nArg, /* Number of args */
253236 sqlite3_value **apUnused /* Function arguments */
253237 ){
253238 assert( nArg==0 );
253239 UNUSED_PARAM2(nArg, apUnused);
253240 sqlite3_result_text(pCtx, "fts5: 2024-08-16 18:51:46 7a0cdc7edb704a88a77b748cd28f6e00c49849cc2c1af838b95b34232ecc21f9", -1, SQLITE_TRANSIENT);
253241 }
253242
253243 /*
253244 ** Return true if zName is the extension on one of the shadow tables used
253245 ** by this module.
253246
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.47.0"
150150
#define SQLITE_VERSION_NUMBER 3047000
151
-#define SQLITE_SOURCE_ID "2024-08-10 15:46:57 3778b2a9ca1cc12a88ef6c32a1ee7c58a0a829ed9715a3d32a225d377d7527ef"
151
+#define SQLITE_SOURCE_ID "2024-08-16 18:51:46 7a0cdc7edb704a88a77b748cd28f6e00c49849cc2c1af838b95b34232ecc21f9"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
157157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.47.0"
150 #define SQLITE_VERSION_NUMBER 3047000
151 #define SQLITE_SOURCE_ID "2024-08-10 15:46:57 3778b2a9ca1cc12a88ef6c32a1ee7c58a0a829ed9715a3d32a225d377d7527ef"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.47.0"
150 #define SQLITE_VERSION_NUMBER 3047000
151 #define SQLITE_SOURCE_ID "2024-08-16 18:51:46 7a0cdc7edb704a88a77b748cd28f6e00c49849cc2c1af838b95b34232ecc21f9"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button