Fossil SCM

Update to the latest SQLite 3.8.0 alpha from upstream.

drh 2013-06-27 01:57 trunk
Commit f92056c996a28dc2aced6d5acb1179f76016c9ec
3 files changed +185 -78 +189 -94 +13 -3
+185 -78
--- src/shell.c
+++ src/shell.c
@@ -1107,10 +1107,12 @@
11071107
fprintf(pArg->out, "Fullscan Steps: %d\n", iCur);
11081108
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
11091109
fprintf(pArg->out, "Sort Operations: %d\n", iCur);
11101110
iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, bReset);
11111111
fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
1112
+ iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
1113
+ fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
11121114
}
11131115
11141116
return 0;
11151117
}
11161118
@@ -1645,10 +1647,111 @@
16451647
*/
16461648
static void test_breakpoint(void){
16471649
static int nCall = 0;
16481650
nCall++;
16491651
}
1652
+
1653
+/*
1654
+** An object used to read a CSV file
1655
+*/
1656
+typedef struct CSVReader CSVReader;
1657
+struct CSVReader {
1658
+ const char *zFile; /* Name of the input file */
1659
+ FILE *in; /* Read the CSV text from this input stream */
1660
+ char *z; /* Accumulated text for a field */
1661
+ int n; /* Number of bytes in z */
1662
+ int nAlloc; /* Space allocated for z[] */
1663
+ int nLine; /* Current line number */
1664
+ int cTerm; /* Character that terminated the most recent field */
1665
+ int cSeparator; /* The separator character. (Usually ",") */
1666
+};
1667
+
1668
+/* Append a single byte to z[] */
1669
+static void csv_append_char(CSVReader *p, int c){
1670
+ if( p->n+1>=p->nAlloc ){
1671
+ p->nAlloc += p->nAlloc + 100;
1672
+ p->z = sqlite3_realloc(p->z, p->nAlloc);
1673
+ if( p->z==0 ){
1674
+ fprintf(stderr, "out of memory\n");
1675
+ exit(1);
1676
+ }
1677
+ }
1678
+ p->z[p->n++] = (char)c;
1679
+}
1680
+
1681
+/* Read a single field of CSV text. Compatible with rfc4180 and extended
1682
+** with the option of having a separator other than ",".
1683
+**
1684
+** + Input comes from p->in.
1685
+** + Store results in p->z of length p->n. Space to hold p->z comes
1686
+** from sqlite3_malloc().
1687
+** + Use p->cSep as the separator. The default is ",".
1688
+** + Keep track of the line number in p->nLine.
1689
+** + Store the character that terminates the field in p->cTerm. Store
1690
+** EOF on end-of-file.
1691
+** + Report syntax errors on stderr
1692
+*/
1693
+static char *csv_read_one_field(CSVReader *p){
1694
+ int c, pc;
1695
+ int cSep = p->cSeparator;
1696
+ p->n = 0;
1697
+ c = fgetc(p->in);
1698
+ if( c==EOF || seenInterrupt ){
1699
+ p->cTerm = EOF;
1700
+ return 0;
1701
+ }
1702
+ if( c=='"' ){
1703
+ int startLine = p->nLine;
1704
+ int cQuote = c;
1705
+ pc = 0;
1706
+ while( 1 ){
1707
+ c = fgetc(p->in);
1708
+ if( c=='\n' ) p->nLine++;
1709
+ if( c==cQuote ){
1710
+ if( pc==cQuote ){
1711
+ pc = 0;
1712
+ continue;
1713
+ }
1714
+ }
1715
+ if( (c==cSep && pc==cQuote)
1716
+ || (c=='\n' && pc==cQuote)
1717
+ || (c=='\n' && pc=='\r' && p->n>2 && p->z[p->n-2]==cQuote)
1718
+ || (c==EOF && pc==cQuote)
1719
+ ){
1720
+ do{ p->n--; }while( p->z[p->n]!=cQuote );
1721
+ p->z[p->n] = 0;
1722
+ p->cTerm = c;
1723
+ break;
1724
+ }
1725
+ if( pc==cQuote && c!='\r' ){
1726
+ fprintf(stderr, "%s:%d: unescaped %c character\n",
1727
+ p->zFile, p->nLine, cQuote);
1728
+ }
1729
+ if( c==EOF ){
1730
+ fprintf(stderr, "%s:%d: unterminated %c-quoted field\n",
1731
+ p->zFile, startLine, cQuote);
1732
+ p->z[p->n] = 0;
1733
+ p->cTerm = EOF;
1734
+ break;
1735
+ }
1736
+ csv_append_char(p, c);
1737
+ pc = c;
1738
+ }
1739
+ }else{
1740
+ csv_append_char(p, c);
1741
+ while( (c = fgetc(p->in))!=EOF && c!=cSep && c!='\n' ){
1742
+ csv_append_char(p, c);
1743
+ }
1744
+ if( c=='\n' ){
1745
+ p->nLine++;
1746
+ if( p->n>1 && p->z[p->n-1]=='\r' ) p->n--;
1747
+ }
1748
+ p->z[p->n] = 0;
1749
+ p->cTerm = c;
1750
+ }
1751
+ return p->z;
1752
+}
16501753
16511754
/*
16521755
** If an input line begins with "." then invoke this routine to
16531756
** process that line.
16541757
**
@@ -1884,133 +1987,137 @@
18841987
}
18851988
}else
18861989
18871990
if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg==3 ){
18881991
char *zTable = azArg[2]; /* Insert data into this table */
1889
- char *zFile = azArg[1]; /* The file from which to extract data */
18901992
sqlite3_stmt *pStmt = NULL; /* A statement */
18911993
int nCol; /* Number of columns in the table */
18921994
int nByte; /* Number of bytes in an SQL string */
18931995
int i, j; /* Loop counters */
18941996
int nSep; /* Number of bytes in p->separator[] */
18951997
char *zSql; /* An SQL statement */
1896
- char *zLine; /* A single line of input from the file */
1897
- char **azCol; /* zLine[] broken up into columns */
1898
- char *zCommit; /* How to commit changes */
1899
- FILE *in; /* The input file */
1900
- int lineno = 0; /* Line number of input file */
1998
+ CSVReader sCsv; /* Reader context */
19011999
2000
+ seenInterrupt = 0;
2001
+ memset(&sCsv, 0, sizeof(sCsv));
2002
+ sCsv.zFile = azArg[1];
2003
+ sCsv.nLine = 1;
19022004
open_db(p);
19032005
nSep = strlen30(p->separator);
19042006
if( nSep==0 ){
19052007
fprintf(stderr, "Error: non-null separator required for import\n");
19062008
return 1;
19072009
}
2010
+ if( nSep>1 ){
2011
+ fprintf(stderr, "Error: multi-character separators not allowed"
2012
+ " for import\n");
2013
+ return 1;
2014
+ }
2015
+ sCsv.in = fopen(sCsv.zFile, "rb");
2016
+ if( sCsv.in==0 ){
2017
+ fprintf(stderr, "Error: cannot open \"%s\"\n", sCsv.zFile);
2018
+ return 1;
2019
+ }
2020
+ sCsv.cSeparator = p->separator[0];
19082021
zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
19092022
if( zSql==0 ){
19102023
fprintf(stderr, "Error: out of memory\n");
2024
+ fclose(sCsv.in);
19112025
return 1;
19122026
}
19132027
nByte = strlen30(zSql);
19142028
rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
2029
+ if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
2030
+ char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
2031
+ char cSep = '(';
2032
+ while( csv_read_one_field(&sCsv) ){
2033
+ zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCsv.z);
2034
+ cSep = ',';
2035
+ if( sCsv.cTerm!=sCsv.cSeparator ) break;
2036
+ }
2037
+ zCreate = sqlite3_mprintf("%z\n)", zCreate);
2038
+ rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
2039
+ sqlite3_free(zCreate);
2040
+ if( rc ){
2041
+ fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
2042
+ sqlite3_errmsg(db));
2043
+ sqlite3_free(sCsv.z);
2044
+ fclose(sCsv.in);
2045
+ return 1;
2046
+ }
2047
+ rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
2048
+ }
19152049
sqlite3_free(zSql);
19162050
if( rc ){
19172051
if (pStmt) sqlite3_finalize(pStmt);
19182052
fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
2053
+ fclose(sCsv.in);
19192054
return 1;
19202055
}
19212056
nCol = sqlite3_column_count(pStmt);
19222057
sqlite3_finalize(pStmt);
19232058
pStmt = 0;
19242059
if( nCol==0 ) return 0; /* no columns, no error */
1925
- zSql = malloc( nByte + 20 + nCol*2 );
2060
+ zSql = sqlite3_malloc( nByte*2 + 20 + nCol*2 );
19262061
if( zSql==0 ){
19272062
fprintf(stderr, "Error: out of memory\n");
2063
+ fclose(sCsv.in);
19282064
return 1;
19292065
}
1930
- sqlite3_snprintf(nByte+20, zSql, "INSERT INTO %s VALUES(?", zTable);
2066
+ sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
19312067
j = strlen30(zSql);
19322068
for(i=1; i<nCol; i++){
19332069
zSql[j++] = ',';
19342070
zSql[j++] = '?';
19352071
}
19362072
zSql[j++] = ')';
19372073
zSql[j] = 0;
19382074
rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
1939
- free(zSql);
2075
+ sqlite3_free(zSql);
19402076
if( rc ){
19412077
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
19422078
if (pStmt) sqlite3_finalize(pStmt);
1943
- return 1;
1944
- }
1945
- in = fopen(zFile, "rb");
1946
- if( in==0 ){
1947
- fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
1948
- sqlite3_finalize(pStmt);
1949
- return 1;
1950
- }
1951
- azCol = malloc( sizeof(azCol[0])*(nCol+1) );
1952
- if( azCol==0 ){
1953
- fprintf(stderr, "Error: out of memory\n");
1954
- fclose(in);
1955
- sqlite3_finalize(pStmt);
1956
- return 1;
1957
- }
1958
- sqlite3_exec(p->db, "BEGIN", 0, 0, 0);
1959
- zCommit = "COMMIT";
1960
- while( (zLine = local_getline(0, in, 1))!=0 ){
1961
- char *z, c;
1962
- int inQuote = 0;
1963
- lineno++;
1964
- azCol[0] = zLine;
1965
- for(i=0, z=zLine; (c = *z)!=0; z++){
1966
- if( c=='"' ) inQuote = !inQuote;
1967
- if( c=='\n' ) lineno++;
1968
- if( !inQuote && c==p->separator[0] && strncmp(z,p->separator,nSep)==0 ){
1969
- *z = 0;
1970
- i++;
1971
- if( i<nCol ){
1972
- azCol[i] = &z[nSep];
1973
- z += nSep-1;
1974
- }
1975
- }
1976
- } /* end for */
1977
- *z = 0;
1978
- if( i+1!=nCol ){
1979
- fprintf(stderr,
1980
- "Error: %s line %d: expected %d columns of data but found %d\n",
1981
- zFile, lineno, nCol, i+1);
1982
- zCommit = "ROLLBACK";
1983
- free(zLine);
1984
- rc = 1;
1985
- break; /* from while */
1986
- }
1987
- for(i=0; i<nCol; i++){
1988
- if( azCol[i][0]=='"' ){
1989
- int k;
1990
- for(z=azCol[i], j=1, k=0; z[j]; j++){
1991
- if( z[j]=='"' ){ j++; if( z[j]==0 ) break; }
1992
- z[k++] = z[j];
1993
- }
1994
- z[k] = 0;
1995
- }
1996
- sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC);
1997
- }
1998
- sqlite3_step(pStmt);
1999
- rc = sqlite3_reset(pStmt);
2000
- free(zLine);
2001
- if( rc!=SQLITE_OK ){
2002
- fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
2003
- zCommit = "ROLLBACK";
2004
- rc = 1;
2005
- break; /* from while */
2006
- }
2007
- } /* end while */
2008
- free(azCol);
2009
- fclose(in);
2010
- sqlite3_finalize(pStmt);
2011
- sqlite3_exec(p->db, zCommit, 0, 0, 0);
2079
+ fclose(sCsv.in);
2080
+ return 1;
2081
+ }
2082
+ do{
2083
+ int startLine = sCsv.nLine;
2084
+ for(i=0; i<nCol; i++){
2085
+ char *z = csv_read_one_field(&sCsv);
2086
+ if( z==0 && i==0 ) break;
2087
+ sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
2088
+ if( i<nCol-1 && sCsv.cTerm!=sCsv.cSeparator ){
2089
+ fprintf(stderr, "%s:%d: expected %d columns but found %d - "
2090
+ "filling the rest with NULL\n",
2091
+ sCsv.zFile, startLine, nCol, i+1);
2092
+ i++;
2093
+ while( i<nCol ){ sqlite3_bind_null(pStmt, i); i++; }
2094
+ }
2095
+ }
2096
+ if( sCsv.cTerm==sCsv.cSeparator ){
2097
+ do{
2098
+ csv_read_one_field(&sCsv);
2099
+ i++;
2100
+ }while( sCsv.cTerm==sCsv.cSeparator );
2101
+ fprintf(stderr, "%s:%d: expected %d columns but found %d - "
2102
+ "extras ignored\n",
2103
+ sCsv.zFile, startLine, nCol, i);
2104
+ }
2105
+ if( i>=nCol ){
2106
+ sqlite3_step(pStmt);
2107
+ rc = sqlite3_reset(pStmt);
2108
+ if( rc!=SQLITE_OK ){
2109
+ fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCsv.zFile, startLine,
2110
+ sqlite3_errmsg(db));
2111
+ }
2112
+ }
2113
+ }while( sCsv.cTerm!=EOF );
2114
+
2115
+ fclose(sCsv.in);
2116
+ sqlite3_free(sCsv.z);
2117
+ sqlite3_finalize(pStmt);
2118
+ sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
20122119
}else
20132120
20142121
if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
20152122
struct callback_data data;
20162123
char *zErrMsg = 0;
20172124
--- src/shell.c
+++ src/shell.c
@@ -1107,10 +1107,12 @@
1107 fprintf(pArg->out, "Fullscan Steps: %d\n", iCur);
1108 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
1109 fprintf(pArg->out, "Sort Operations: %d\n", iCur);
1110 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, bReset);
1111 fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
 
 
1112 }
1113
1114 return 0;
1115 }
1116
@@ -1645,10 +1647,111 @@
1645 */
1646 static void test_breakpoint(void){
1647 static int nCall = 0;
1648 nCall++;
1649 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1650
1651 /*
1652 ** If an input line begins with "." then invoke this routine to
1653 ** process that line.
1654 **
@@ -1884,133 +1987,137 @@
1884 }
1885 }else
1886
1887 if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg==3 ){
1888 char *zTable = azArg[2]; /* Insert data into this table */
1889 char *zFile = azArg[1]; /* The file from which to extract data */
1890 sqlite3_stmt *pStmt = NULL; /* A statement */
1891 int nCol; /* Number of columns in the table */
1892 int nByte; /* Number of bytes in an SQL string */
1893 int i, j; /* Loop counters */
1894 int nSep; /* Number of bytes in p->separator[] */
1895 char *zSql; /* An SQL statement */
1896 char *zLine; /* A single line of input from the file */
1897 char **azCol; /* zLine[] broken up into columns */
1898 char *zCommit; /* How to commit changes */
1899 FILE *in; /* The input file */
1900 int lineno = 0; /* Line number of input file */
1901
 
 
 
 
1902 open_db(p);
1903 nSep = strlen30(p->separator);
1904 if( nSep==0 ){
1905 fprintf(stderr, "Error: non-null separator required for import\n");
1906 return 1;
1907 }
 
 
 
 
 
 
 
 
 
 
 
1908 zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
1909 if( zSql==0 ){
1910 fprintf(stderr, "Error: out of memory\n");
 
1911 return 1;
1912 }
1913 nByte = strlen30(zSql);
1914 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1915 sqlite3_free(zSql);
1916 if( rc ){
1917 if (pStmt) sqlite3_finalize(pStmt);
1918 fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
 
1919 return 1;
1920 }
1921 nCol = sqlite3_column_count(pStmt);
1922 sqlite3_finalize(pStmt);
1923 pStmt = 0;
1924 if( nCol==0 ) return 0; /* no columns, no error */
1925 zSql = malloc( nByte + 20 + nCol*2 );
1926 if( zSql==0 ){
1927 fprintf(stderr, "Error: out of memory\n");
 
1928 return 1;
1929 }
1930 sqlite3_snprintf(nByte+20, zSql, "INSERT INTO %s VALUES(?", zTable);
1931 j = strlen30(zSql);
1932 for(i=1; i<nCol; i++){
1933 zSql[j++] = ',';
1934 zSql[j++] = '?';
1935 }
1936 zSql[j++] = ')';
1937 zSql[j] = 0;
1938 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
1939 free(zSql);
1940 if( rc ){
1941 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
1942 if (pStmt) sqlite3_finalize(pStmt);
1943 return 1;
1944 }
1945 in = fopen(zFile, "rb");
1946 if( in==0 ){
1947 fprintf(stderr, "Error: cannot open \"%s\"\n", zFile);
1948 sqlite3_finalize(pStmt);
1949 return 1;
1950 }
1951 azCol = malloc( sizeof(azCol[0])*(nCol+1) );
1952 if( azCol==0 ){
1953 fprintf(stderr, "Error: out of memory\n");
1954 fclose(in);
1955 sqlite3_finalize(pStmt);
1956 return 1;
1957 }
1958 sqlite3_exec(p->db, "BEGIN", 0, 0, 0);
1959 zCommit = "COMMIT";
1960 while( (zLine = local_getline(0, in, 1))!=0 ){
1961 char *z, c;
1962 int inQuote = 0;
1963 lineno++;
1964 azCol[0] = zLine;
1965 for(i=0, z=zLine; (c = *z)!=0; z++){
1966 if( c=='"' ) inQuote = !inQuote;
1967 if( c=='\n' ) lineno++;
1968 if( !inQuote && c==p->separator[0] && strncmp(z,p->separator,nSep)==0 ){
1969 *z = 0;
1970 i++;
1971 if( i<nCol ){
1972 azCol[i] = &z[nSep];
1973 z += nSep-1;
1974 }
1975 }
1976 } /* end for */
1977 *z = 0;
1978 if( i+1!=nCol ){
1979 fprintf(stderr,
1980 "Error: %s line %d: expected %d columns of data but found %d\n",
1981 zFile, lineno, nCol, i+1);
1982 zCommit = "ROLLBACK";
1983 free(zLine);
1984 rc = 1;
1985 break; /* from while */
1986 }
1987 for(i=0; i<nCol; i++){
1988 if( azCol[i][0]=='"' ){
1989 int k;
1990 for(z=azCol[i], j=1, k=0; z[j]; j++){
1991 if( z[j]=='"' ){ j++; if( z[j]==0 ) break; }
1992 z[k++] = z[j];
1993 }
1994 z[k] = 0;
1995 }
1996 sqlite3_bind_text(pStmt, i+1, azCol[i], -1, SQLITE_STATIC);
1997 }
1998 sqlite3_step(pStmt);
1999 rc = sqlite3_reset(pStmt);
2000 free(zLine);
2001 if( rc!=SQLITE_OK ){
2002 fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
2003 zCommit = "ROLLBACK";
2004 rc = 1;
2005 break; /* from while */
2006 }
2007 } /* end while */
2008 free(azCol);
2009 fclose(in);
2010 sqlite3_finalize(pStmt);
2011 sqlite3_exec(p->db, zCommit, 0, 0, 0);
2012 }else
2013
2014 if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
2015 struct callback_data data;
2016 char *zErrMsg = 0;
2017
--- src/shell.c
+++ src/shell.c
@@ -1107,10 +1107,12 @@
1107 fprintf(pArg->out, "Fullscan Steps: %d\n", iCur);
1108 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset);
1109 fprintf(pArg->out, "Sort Operations: %d\n", iCur);
1110 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX, bReset);
1111 fprintf(pArg->out, "Autoindex Inserts: %d\n", iCur);
1112 iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset);
1113 fprintf(pArg->out, "Virtual Machine Steps: %d\n", iCur);
1114 }
1115
1116 return 0;
1117 }
1118
@@ -1645,10 +1647,111 @@
1647 */
1648 static void test_breakpoint(void){
1649 static int nCall = 0;
1650 nCall++;
1651 }
1652
1653 /*
1654 ** An object used to read a CSV file
1655 */
1656 typedef struct CSVReader CSVReader;
1657 struct CSVReader {
1658 const char *zFile; /* Name of the input file */
1659 FILE *in; /* Read the CSV text from this input stream */
1660 char *z; /* Accumulated text for a field */
1661 int n; /* Number of bytes in z */
1662 int nAlloc; /* Space allocated for z[] */
1663 int nLine; /* Current line number */
1664 int cTerm; /* Character that terminated the most recent field */
1665 int cSeparator; /* The separator character. (Usually ",") */
1666 };
1667
1668 /* Append a single byte to z[] */
1669 static void csv_append_char(CSVReader *p, int c){
1670 if( p->n+1>=p->nAlloc ){
1671 p->nAlloc += p->nAlloc + 100;
1672 p->z = sqlite3_realloc(p->z, p->nAlloc);
1673 if( p->z==0 ){
1674 fprintf(stderr, "out of memory\n");
1675 exit(1);
1676 }
1677 }
1678 p->z[p->n++] = (char)c;
1679 }
1680
1681 /* Read a single field of CSV text. Compatible with rfc4180 and extended
1682 ** with the option of having a separator other than ",".
1683 **
1684 ** + Input comes from p->in.
1685 ** + Store results in p->z of length p->n. Space to hold p->z comes
1686 ** from sqlite3_malloc().
1687 ** + Use p->cSep as the separator. The default is ",".
1688 ** + Keep track of the line number in p->nLine.
1689 ** + Store the character that terminates the field in p->cTerm. Store
1690 ** EOF on end-of-file.
1691 ** + Report syntax errors on stderr
1692 */
1693 static char *csv_read_one_field(CSVReader *p){
1694 int c, pc;
1695 int cSep = p->cSeparator;
1696 p->n = 0;
1697 c = fgetc(p->in);
1698 if( c==EOF || seenInterrupt ){
1699 p->cTerm = EOF;
1700 return 0;
1701 }
1702 if( c=='"' ){
1703 int startLine = p->nLine;
1704 int cQuote = c;
1705 pc = 0;
1706 while( 1 ){
1707 c = fgetc(p->in);
1708 if( c=='\n' ) p->nLine++;
1709 if( c==cQuote ){
1710 if( pc==cQuote ){
1711 pc = 0;
1712 continue;
1713 }
1714 }
1715 if( (c==cSep && pc==cQuote)
1716 || (c=='\n' && pc==cQuote)
1717 || (c=='\n' && pc=='\r' && p->n>2 && p->z[p->n-2]==cQuote)
1718 || (c==EOF && pc==cQuote)
1719 ){
1720 do{ p->n--; }while( p->z[p->n]!=cQuote );
1721 p->z[p->n] = 0;
1722 p->cTerm = c;
1723 break;
1724 }
1725 if( pc==cQuote && c!='\r' ){
1726 fprintf(stderr, "%s:%d: unescaped %c character\n",
1727 p->zFile, p->nLine, cQuote);
1728 }
1729 if( c==EOF ){
1730 fprintf(stderr, "%s:%d: unterminated %c-quoted field\n",
1731 p->zFile, startLine, cQuote);
1732 p->z[p->n] = 0;
1733 p->cTerm = EOF;
1734 break;
1735 }
1736 csv_append_char(p, c);
1737 pc = c;
1738 }
1739 }else{
1740 csv_append_char(p, c);
1741 while( (c = fgetc(p->in))!=EOF && c!=cSep && c!='\n' ){
1742 csv_append_char(p, c);
1743 }
1744 if( c=='\n' ){
1745 p->nLine++;
1746 if( p->n>1 && p->z[p->n-1]=='\r' ) p->n--;
1747 }
1748 p->z[p->n] = 0;
1749 p->cTerm = c;
1750 }
1751 return p->z;
1752 }
1753
1754 /*
1755 ** If an input line begins with "." then invoke this routine to
1756 ** process that line.
1757 **
@@ -1884,133 +1987,137 @@
1987 }
1988 }else
1989
1990 if( c=='i' && strncmp(azArg[0], "import", n)==0 && nArg==3 ){
1991 char *zTable = azArg[2]; /* Insert data into this table */
 
1992 sqlite3_stmt *pStmt = NULL; /* A statement */
1993 int nCol; /* Number of columns in the table */
1994 int nByte; /* Number of bytes in an SQL string */
1995 int i, j; /* Loop counters */
1996 int nSep; /* Number of bytes in p->separator[] */
1997 char *zSql; /* An SQL statement */
1998 CSVReader sCsv; /* Reader context */
 
 
 
 
1999
2000 seenInterrupt = 0;
2001 memset(&sCsv, 0, sizeof(sCsv));
2002 sCsv.zFile = azArg[1];
2003 sCsv.nLine = 1;
2004 open_db(p);
2005 nSep = strlen30(p->separator);
2006 if( nSep==0 ){
2007 fprintf(stderr, "Error: non-null separator required for import\n");
2008 return 1;
2009 }
2010 if( nSep>1 ){
2011 fprintf(stderr, "Error: multi-character separators not allowed"
2012 " for import\n");
2013 return 1;
2014 }
2015 sCsv.in = fopen(sCsv.zFile, "rb");
2016 if( sCsv.in==0 ){
2017 fprintf(stderr, "Error: cannot open \"%s\"\n", sCsv.zFile);
2018 return 1;
2019 }
2020 sCsv.cSeparator = p->separator[0];
2021 zSql = sqlite3_mprintf("SELECT * FROM %s", zTable);
2022 if( zSql==0 ){
2023 fprintf(stderr, "Error: out of memory\n");
2024 fclose(sCsv.in);
2025 return 1;
2026 }
2027 nByte = strlen30(zSql);
2028 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
2029 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
2030 char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
2031 char cSep = '(';
2032 while( csv_read_one_field(&sCsv) ){
2033 zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCsv.z);
2034 cSep = ',';
2035 if( sCsv.cTerm!=sCsv.cSeparator ) break;
2036 }
2037 zCreate = sqlite3_mprintf("%z\n)", zCreate);
2038 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
2039 sqlite3_free(zCreate);
2040 if( rc ){
2041 fprintf(stderr, "CREATE TABLE %s(...) failed: %s\n", zTable,
2042 sqlite3_errmsg(db));
2043 sqlite3_free(sCsv.z);
2044 fclose(sCsv.in);
2045 return 1;
2046 }
2047 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
2048 }
2049 sqlite3_free(zSql);
2050 if( rc ){
2051 if (pStmt) sqlite3_finalize(pStmt);
2052 fprintf(stderr,"Error: %s\n", sqlite3_errmsg(db));
2053 fclose(sCsv.in);
2054 return 1;
2055 }
2056 nCol = sqlite3_column_count(pStmt);
2057 sqlite3_finalize(pStmt);
2058 pStmt = 0;
2059 if( nCol==0 ) return 0; /* no columns, no error */
2060 zSql = sqlite3_malloc( nByte*2 + 20 + nCol*2 );
2061 if( zSql==0 ){
2062 fprintf(stderr, "Error: out of memory\n");
2063 fclose(sCsv.in);
2064 return 1;
2065 }
2066 sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
2067 j = strlen30(zSql);
2068 for(i=1; i<nCol; i++){
2069 zSql[j++] = ',';
2070 zSql[j++] = '?';
2071 }
2072 zSql[j++] = ')';
2073 zSql[j] = 0;
2074 rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
2075 sqlite3_free(zSql);
2076 if( rc ){
2077 fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
2078 if (pStmt) sqlite3_finalize(pStmt);
2079 fclose(sCsv.in);
2080 return 1;
2081 }
2082 do{
2083 int startLine = sCsv.nLine;
2084 for(i=0; i<nCol; i++){
2085 char *z = csv_read_one_field(&sCsv);
2086 if( z==0 && i==0 ) break;
2087 sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
2088 if( i<nCol-1 && sCsv.cTerm!=sCsv.cSeparator ){
2089 fprintf(stderr, "%s:%d: expected %d columns but found %d - "
2090 "filling the rest with NULL\n",
2091 sCsv.zFile, startLine, nCol, i+1);
2092 i++;
2093 while( i<nCol ){ sqlite3_bind_null(pStmt, i); i++; }
2094 }
2095 }
2096 if( sCsv.cTerm==sCsv.cSeparator ){
2097 do{
2098 csv_read_one_field(&sCsv);
2099 i++;
2100 }while( sCsv.cTerm==sCsv.cSeparator );
2101 fprintf(stderr, "%s:%d: expected %d columns but found %d - "
2102 "extras ignored\n",
2103 sCsv.zFile, startLine, nCol, i);
2104 }
2105 if( i>=nCol ){
2106 sqlite3_step(pStmt);
2107 rc = sqlite3_reset(pStmt);
2108 if( rc!=SQLITE_OK ){
2109 fprintf(stderr, "%s:%d: INSERT failed: %s\n", sCsv.zFile, startLine,
2110 sqlite3_errmsg(db));
2111 }
2112 }
2113 }while( sCsv.cTerm!=EOF );
2114
2115 fclose(sCsv.in);
2116 sqlite3_free(sCsv.z);
2117 sqlite3_finalize(pStmt);
2118 sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2119 }else
2120
2121 if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
2122 struct callback_data data;
2123 char *zErrMsg = 0;
2124
+189 -94
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.7.17. By combining all the individual C code files into this
3
+** version 3.8.0. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -668,13 +668,13 @@
668668
**
669669
** See also: [sqlite3_libversion()],
670670
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
671671
** [sqlite_version()] and [sqlite_source_id()].
672672
*/
673
-#define SQLITE_VERSION "3.7.17"
674
-#define SQLITE_VERSION_NUMBER 3007017
675
-#define SQLITE_SOURCE_ID "2013-06-20 14:17:39 d94db3fd921890ab1d6414ab629410ae50779686"
673
+#define SQLITE_VERSION "3.8.0"
674
+#define SQLITE_VERSION_NUMBER 3008000
675
+#define SQLITE_SOURCE_ID "2013-06-26 22:46:00 93f632152e464a89322a0130adaf9f342411bf7d"
676676
677677
/*
678678
** CAPI3REF: Run-Time Library Version Numbers
679679
** KEYWORDS: sqlite3_version, sqlite3_sourceid
680680
**
@@ -6869,15 +6869,25 @@
68696869
** <dd>^This is the number of rows inserted into transient indices that
68706870
** were created automatically in order to help joins run faster.
68716871
** A non-zero value in this counter may indicate an opportunity to
68726872
** improvement performance by adding permanent indices that do not
68736873
** need to be reinitialized each time the statement is run.</dd>
6874
+**
6875
+** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
6876
+** <dd>^This is the number of virtual machine operations executed
6877
+** by the prepared statement if that number is less than or equal
6878
+** to 2147483647. The number of virtual machine operations can be
6879
+** used as a proxy for the total work done by the prepared statement.
6880
+** If the number of virtual machine operations exceeds 2147483647
6881
+** then the value returned by this statement status code is undefined.
6882
+** </dd>
68746883
** </dl>
68756884
*/
68766885
#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
68776886
#define SQLITE_STMTSTATUS_SORT 2
68786887
#define SQLITE_STMTSTATUS_AUTOINDEX 3
6888
+#define SQLITE_STMTSTATUS_VM_STEP 4
68796889
68806890
/*
68816891
** CAPI3REF: Custom Page Cache Object
68826892
**
68836893
** The sqlite3_pcache type is opaque. It is implemented by
@@ -10193,10 +10203,11 @@
1019310203
#define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
1019410204
#define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
1019510205
#define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
1019610206
#define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
1019710207
#define SQLITE_Transitive 0x0200 /* Transitive constraints */
10208
+#define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
1019810209
#define SQLITE_AllOpts 0xffff /* All optimizations */
1019910210
1020010211
/*
1020110212
** Macros for testing whether or not optimizations are enabled or disabled.
1020210213
*/
@@ -11143,10 +11154,11 @@
1114311154
#define WHERE_FORCE_TABLE 0x0020 /* Do not use an index-only search */
1114411155
#define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
1114511156
#define WHERE_AND_ONLY 0x0080 /* Don't use indices for OR terms */
1114611157
#define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */
1114711158
#define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */
11159
+#define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
1114811160
1114911161
/* Allowed return values from sqlite3WhereIsDistinct()
1115011162
*/
1115111163
#define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */
1115211164
#define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */
@@ -13507,11 +13519,11 @@
1350713519
bft doingRerun:1; /* True if rerunning after an auto-reprepare */
1350813520
int nChange; /* Number of db changes made since last reset */
1350913521
yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
1351013522
yDbMask lockMask; /* Subset of btreeMask that requires a lock */
1351113523
int iStatement; /* Statement number (or 0 if has not opened stmt) */
13512
- int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
13524
+ int aCounter[4]; /* Counters used by sqlite3_stmt_status() */
1351313525
#ifndef SQLITE_OMIT_TRACE
1351413526
i64 startTime; /* Time when query started - used for profiling */
1351513527
#endif
1351613528
i64 nFkConstraint; /* Number of imm. FK constraints this VM */
1351713529
i64 nStmtDefCons; /* Number of def. constraints when stmt started */
@@ -65351,16 +65363,17 @@
6535165363
u8 encoding = ENC(db); /* The database encoding */
6535265364
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
6535365365
int checkProgress; /* True if progress callbacks are enabled */
6535465366
int nProgressOps = 0; /* Opcodes executed since progress callback. */
6535565367
#endif
65368
+ int iCompare = 0; /* Result of last OP_Compare operation */
65369
+ unsigned nVmStep = 0; /* Number of virtual machine steps */
6535665370
Mem *aMem = p->aMem; /* Copy of p->aMem */
6535765371
Mem *pIn1 = 0; /* 1st input operand */
6535865372
Mem *pIn2 = 0; /* 2nd input operand */
6535965373
Mem *pIn3 = 0; /* 3rd input operand */
6536065374
Mem *pOut = 0; /* Output operand */
65361
- int iCompare = 0; /* Result of last OP_Compare operation */
6536265375
int *aPermute = 0; /* Permutation of columns for OP_Compare */
6536365376
i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
6536465377
#ifdef VDBE_PROFILE
6536565378
u64 start; /* CPU clock count at start of opcode */
6536665379
int origPc; /* Program counter at start of opcode */
@@ -65830,10 +65843,11 @@
6583065843
if( db->mallocFailed ) goto no_mem;
6583165844
#ifdef VDBE_PROFILE
6583265845
origPc = pc;
6583365846
start = sqlite3Hwtime();
6583465847
#endif
65848
+ nVmStep++;
6583565849
pOp = &aOp[pc];
6583665850
6583765851
/* Only allow tracing if SQLITE_DEBUG is defined.
6583865852
*/
6583965853
#ifdef SQLITE_DEBUG
@@ -71566,10 +71580,11 @@
7156671580
/* This is the only way out of this procedure. We have to
7156771581
** release the mutexes on btrees that were acquired at the
7156871582
** top. */
7156971583
vdbe_return:
7157071584
db->lastRowid = lastRowid;
71585
+ p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1] += (int)nVmStep;
7157171586
sqlite3VdbeLeave(p);
7157271587
return rc;
7157371588
7157471589
/* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
7157571590
** is encountered.
@@ -76044,10 +76059,11 @@
7604476059
pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
7604576060
pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
7604676061
pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
7604776062
pItem->sortOrder = pOldItem->sortOrder;
7604876063
pItem->done = 0;
76064
+ pItem->bSpanIsTab = pOldItem->bSpanIsTab;
7604976065
pItem->iOrderByCol = pOldItem->iOrderByCol;
7605076066
pItem->iAlias = pOldItem->iAlias;
7605176067
}
7605276068
return pNew;
7605376069
}
@@ -100236,19 +100252,20 @@
100236100252
sDistinct.eTnctType = WHERE_DISTINCT_NOOP;
100237100253
}
100238100254
100239100255
if( !isAgg && pGroupBy==0 ){
100240100256
/* No aggregate functions and no GROUP BY clause */
100241
- ExprList *pDist = (sDistinct.isTnct ? p->pEList : 0);
100257
+ u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0);
100242100258
100243100259
/* Begin the database scan. */
100244
- pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pOrderBy, pDist, 0,0);
100260
+ pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pOrderBy, p->pEList,
100261
+ wctrlFlags, 0);
100245100262
if( pWInfo==0 ) goto select_end;
100246100263
if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
100247100264
p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
100248100265
}
100249
- if( sqlite3WhereIsDistinct(pWInfo) ){
100266
+ if( sDistinct.isTnct && sqlite3WhereIsDistinct(pWInfo) ){
100250100267
sDistinct.eTnctType = sqlite3WhereIsDistinct(pWInfo);
100251100268
}
100252100269
if( pOrderBy && sqlite3WhereIsOrdered(pWInfo) ) pOrderBy = 0;
100253100270
100254100271
/* If sorting index that was created by a prior OP_OpenEphemeral
@@ -104664,23 +104681,23 @@
104664104681
*/
104665104682
struct WhereInfo {
104666104683
Parse *pParse; /* Parsing and code generating context */
104667104684
SrcList *pTabList; /* List of tables in the join */
104668104685
ExprList *pOrderBy; /* The ORDER BY clause or NULL */
104669
- ExprList *pDistinct; /* DISTINCT ON values, or NULL */
104686
+ ExprList *pResultSet; /* Result set. DISTINCT operates on these */
104670104687
WhereLoop *pLoops; /* List of all WhereLoop objects */
104671104688
Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
104672104689
WhereCost nRowOut; /* Estimated number of output rows */
104673104690
u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
104674104691
u8 bOBSat; /* ORDER BY satisfied by indices */
104675104692
u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE/DELETE */
104676104693
u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */
104677104694
u8 eDistinct; /* One of the WHERE_DISTINCT_* values below */
104695
+ u8 nLevel; /* Number of nested loop */
104678104696
int iTop; /* The very beginning of the WHERE loop */
104679104697
int iContinue; /* Jump here to continue with next record */
104680104698
int iBreak; /* Jump here to break out of the loop */
104681
- int nLevel; /* Number of nested loop */
104682104699
int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
104683104700
WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
104684104701
WhereClause sWC; /* Decomposition of the WHERE clause */
104685104702
WhereLevel a[1]; /* Information about each nest loop in WHERE */
104686104703
};
@@ -106690,13 +106707,14 @@
106690106707
z = (const u8 *)sqlite3_value_blob(pVal);
106691106708
pColl = db->pDfltColl;
106692106709
assert( pColl->enc==SQLITE_UTF8 );
106693106710
}else{
106694106711
pColl = sqlite3GetCollSeq(pParse, SQLITE_UTF8, 0, *pIdx->azColl);
106695
- if( pColl==0 ){
106696
- return SQLITE_ERROR;
106697
- }
106712
+ /* If the collating sequence was unavailable, we should have failed
106713
+ ** long ago and never reached this point. But we'll check just to
106714
+ ** be doubly sure. */
106715
+ if( NEVER(pColl==0) ) return SQLITE_ERROR;
106698106716
z = (const u8 *)sqlite3ValueText(pVal, pColl->enc);
106699106717
if( !z ){
106700106718
return SQLITE_NOMEM;
106701106719
}
106702106720
assert( z && pColl && pColl->xCmp );
@@ -108208,13 +108226,13 @@
108208108226
*/
108209108227
static void whereLoopPrint(WhereLoop *p, SrcList *pTabList){
108210108228
int nb = 1+(pTabList->nSrc+7)/8;
108211108229
struct SrcList_item *pItem = pTabList->a + p->iTab;
108212108230
Table *pTab = pItem->pTab;
108213
- sqlite3DebugPrintf("%c %2d.%0*llx.%0*llx", p->cId,
108231
+ sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
108214108232
p->iTab, nb, p->maskSelf, nb, p->prereq);
108215
- sqlite3DebugPrintf(" %8s",
108233
+ sqlite3DebugPrintf(" %12s",
108216108234
pItem->zAlias ? pItem->zAlias : pTab->zName);
108217108235
if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
108218108236
if( p->u.btree.pIndex ){
108219108237
const char *zName = p->u.btree.pIndex->zName;
108220108238
if( zName==0 ) zName = "ipk";
@@ -108221,26 +108239,26 @@
108221108239
if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
108222108240
int i = sqlite3Strlen30(zName) - 1;
108223108241
while( zName[i]!='_' ) i--;
108224108242
zName += i;
108225108243
}
108226
- sqlite3DebugPrintf(".%-12s %2d", zName, p->u.btree.nEq);
108244
+ sqlite3DebugPrintf(".%-16s %2d", zName, p->u.btree.nEq);
108227108245
}else{
108228
- sqlite3DebugPrintf("%16s","");
108246
+ sqlite3DebugPrintf("%20s","");
108229108247
}
108230108248
}else{
108231108249
char *z;
108232108250
if( p->u.vtab.idxStr ){
108233108251
z = sqlite3_mprintf("(%d,\"%s\",%x)",
108234108252
p->u.vtab.idxNum, p->u.vtab.idxStr, p->u.vtab.omitMask);
108235108253
}else{
108236108254
z = sqlite3_mprintf("(%d,%x)", p->u.vtab.idxNum, p->u.vtab.omitMask);
108237108255
}
108238
- sqlite3DebugPrintf(" %-15s", z);
108256
+ sqlite3DebugPrintf(" %-19s", z);
108239108257
sqlite3_free(z);
108240108258
}
108241
- sqlite3DebugPrintf(" fg %05x N %d", p->wsFlags, p->nLTerm);
108259
+ sqlite3DebugPrintf(" f %04x N %d", p->wsFlags, p->nLTerm);
108242108260
sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
108243108261
}
108244108262
#endif
108245108263
108246108264
/*
@@ -109650,16 +109668,17 @@
109650109668
WhereLevel *pLevel = pWInfo->a + iLoop;
109651109669
pLevel->pWLoop = pWLoop = pFrom->aLoop[iLoop];
109652109670
pLevel->iFrom = pWLoop->iTab;
109653109671
pLevel->iTabCur = pWInfo->pTabList->a[pLevel->iFrom].iCursor;
109654109672
}
109655
- if( (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
109656
- && pWInfo->pDistinct
109673
+ if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0
109674
+ && (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
109675
+ && pWInfo->eDistinct==WHERE_DISTINCT_NOOP
109657109676
&& nRowEst
109658109677
){
109659109678
Bitmask notUsed;
109660
- int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pDistinct, pFrom,
109679
+ int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pResultSet, pFrom,
109661109680
WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
109662109681
if( rc==1 ) pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
109663109682
}
109664109683
if( pFrom->isOrdered ){
109665109684
if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
@@ -109744,11 +109763,13 @@
109744109763
pWInfo->a[0].pWLoop = pLoop;
109745109764
pLoop->maskSelf = getMask(&pWInfo->sMaskSet, iCur);
109746109765
pWInfo->a[0].iTabCur = iCur;
109747109766
pWInfo->nRowOut = 1;
109748109767
if( pWInfo->pOrderBy ) pWInfo->bOBSat = 1;
109749
- if( pWInfo->pDistinct ) pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
109768
+ if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){
109769
+ pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
109770
+ }
109750109771
#ifdef SQLITE_DEBUG
109751109772
pLoop->cId = '0';
109752109773
#endif
109753109774
return 1;
109754109775
}
@@ -109834,14 +109855,14 @@
109834109855
** if there is one. If there is no ORDER BY clause or if this routine
109835109856
** is called from an UPDATE or DELETE statement, then pOrderBy is NULL.
109836109857
*/
109837109858
SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
109838109859
Parse *pParse, /* The parser context */
109839
- SrcList *pTabList, /* A list of all tables to be scanned */
109860
+ SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
109840109861
Expr *pWhere, /* The WHERE clause */
109841109862
ExprList *pOrderBy, /* An ORDER BY clause, or NULL */
109842
- ExprList *pDistinct, /* The select-list for DISTINCT queries - or NULL */
109863
+ ExprList *pResultSet, /* Result set of the query */
109843109864
u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
109844109865
int iIdxCur /* If WHERE_ONETABLE_ONLY is set, index cursor number */
109845109866
){
109846109867
int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
109847109868
int nTabList; /* Number of elements in pTabList */
@@ -109849,18 +109870,26 @@
109849109870
Vdbe *v = pParse->pVdbe; /* The virtual database engine */
109850109871
Bitmask notReady; /* Cursors that are not yet positioned */
109851109872
WhereLoopBuilder sWLB; /* The WhereLoop builder */
109852109873
WhereMaskSet *pMaskSet; /* The expression mask set */
109853109874
WhereLevel *pLevel; /* A single level in pWInfo->a[] */
109875
+ WhereLoop *pLoop; /* Pointer to a single WhereLoop object */
109854109876
int ii; /* Loop counter */
109855109877
sqlite3 *db; /* Database connection */
109856109878
int rc; /* Return code */
109857109879
109858109880
109859109881
/* Variable initialization */
109882
+ db = pParse->db;
109860109883
memset(&sWLB, 0, sizeof(sWLB));
109861109884
sWLB.pOrderBy = pOrderBy;
109885
+
109886
+ /* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via
109887
+ ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */
109888
+ if( OptimizationDisabled(db, SQLITE_DistinctOpt) ){
109889
+ wctrlFlags &= ~WHERE_WANT_DISTINCT;
109890
+ }
109862109891
109863109892
/* The number of tables in the FROM clause is limited by the number of
109864109893
** bits in a Bitmask
109865109894
*/
109866109895
testcase( pTabList->nSrc==BMS );
@@ -109881,11 +109910,10 @@
109881109910
** struct, the contents of WhereInfo.a[], the WhereClause structure
109882109911
** and the WhereMaskSet structure. Since WhereClause contains an 8-byte
109883109912
** field (type Bitmask) it must be aligned on an 8-byte boundary on
109884109913
** some architectures. Hence the ROUND8() below.
109885109914
*/
109886
- db = pParse->db;
109887109915
nByteWInfo = ROUND8(sizeof(WhereInfo)+(nTabList-1)*sizeof(WhereLevel));
109888109916
pWInfo = sqlite3DbMallocZero(db, nByteWInfo + sizeof(WhereLoop));
109889109917
if( db->mallocFailed ){
109890109918
sqlite3DbFree(db, pWInfo);
109891109919
pWInfo = 0;
@@ -109893,11 +109921,11 @@
109893109921
}
109894109922
pWInfo->nLevel = nTabList;
109895109923
pWInfo->pParse = pParse;
109896109924
pWInfo->pTabList = pTabList;
109897109925
pWInfo->pOrderBy = pOrderBy;
109898
- pWInfo->pDistinct = pDistinct;
109926
+ pWInfo->pResultSet = pResultSet;
109899109927
pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
109900109928
pWInfo->wctrlFlags = wctrlFlags;
109901109929
pWInfo->savedNQueryLoop = pParse->nQueryLoop;
109902109930
pMaskSet = &pWInfo->sMaskSet;
109903109931
sWLB.pWInfo = pWInfo;
@@ -109906,14 +109934,10 @@
109906109934
whereLoopInit(sWLB.pNew);
109907109935
#ifdef SQLITE_DEBUG
109908109936
sWLB.pNew->cId = '*';
109909109937
#endif
109910109938
109911
- /* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via
109912
- ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */
109913
- if( OptimizationDisabled(db, SQLITE_DistinctOpt) ) pDistinct = 0;
109914
-
109915109939
/* Split the WHERE clause into separate subexpressions where each
109916109940
** subexpression is separated by an AND operator.
109917109941
*/
109918109942
initMaskSet(pMaskSet);
109919109943
whereClauseInit(&pWInfo->sWC, pWInfo);
@@ -109930,11 +109954,13 @@
109930109954
109931109955
/* Special case: No FROM clause
109932109956
*/
109933109957
if( nTabList==0 ){
109934109958
if( pOrderBy ) pWInfo->bOBSat = 1;
109935
- if( pDistinct ) pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
109959
+ if( wctrlFlags & WHERE_WANT_DISTINCT ){
109960
+ pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
109961
+ }
109936109962
}
109937109963
109938109964
/* Assign a bit from the bitmask to every term in the FROM clause.
109939109965
**
109940109966
** When assigning bitmask values to FROM clause cursors, it must be
@@ -109977,11 +110003,11 @@
109977110003
109978110004
/* If the ORDER BY (or GROUP BY) clause contains references to general
109979110005
** expressions, then we won't be able to satisfy it using indices, so
109980110006
** go ahead and disable it now.
109981110007
*/
109982
- if( pOrderBy && pDistinct ){
110008
+ if( pOrderBy && (wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){
109983110009
for(ii=0; ii<pOrderBy->nExpr; ii++){
109984110010
Expr *pExpr = sqlite3ExprSkipCollate(pOrderBy->a[ii].pExpr);
109985110011
if( pExpr->op!=TK_COLUMN ){
109986110012
pWInfo->pOrderBy = pOrderBy = 0;
109987110013
break;
@@ -109989,21 +110015,18 @@
109989110015
break;
109990110016
}
109991110017
}
109992110018
}
109993110019
109994
- /* Check if the DISTINCT qualifier, if there is one, is redundant.
109995
- ** If it is, then set pDistinct to NULL and WhereInfo.eDistinct to
109996
- ** WHERE_DISTINCT_UNIQUE to tell the caller to ignore the DISTINCT.
109997
- */
109998
- if( pDistinct ){
109999
- if( isDistinctRedundant(pParse,pTabList,&pWInfo->sWC,pDistinct) ){
110000
- pDistinct = 0;
110020
+ if( wctrlFlags & WHERE_WANT_DISTINCT ){
110021
+ if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
110022
+ /* The DISTINCT marking is pointless. Ignore it. */
110001110023
pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
110002110024
}else if( pOrderBy==0 ){
110025
+ /* Try to ORDER BY the result set to make distinct processing easier */
110003110026
pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
110004
- pWInfo->pOrderBy = pDistinct;
110027
+ pWInfo->pOrderBy = pResultSet;
110005110028
}
110006110029
}
110007110030
110008110031
/* Construct the WhereLoop objects */
110009110032
WHERETRACE(0xffff,("*** Optimizer Start ***\n"));
@@ -110013,15 +110036,15 @@
110013110036
110014110037
/* Display all of the WhereLoop objects if wheretrace is enabled */
110015110038
#ifdef WHERETRACE_ENABLED
110016110039
if( sqlite3WhereTrace ){
110017110040
WhereLoop *p;
110018
- int i = 0;
110041
+ int i;
110019110042
static char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz"
110020110043
"ABCDEFGHIJKLMNOPQRSTUVWYXZ";
110021
- for(p=pWInfo->pLoops; p; p=p->pNextLoop){
110022
- p->cId = zLabel[(i++)%sizeof(zLabel)];
110044
+ for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
110045
+ p->cId = zLabel[i%sizeof(zLabel)];
110023110046
whereLoopPrint(p, pTabList);
110024110047
}
110025110048
}
110026110049
#endif
110027110050
@@ -110058,15 +110081,36 @@
110058110081
sqlite3DebugPrintf(" DISTINCT=unordered");
110059110082
break;
110060110083
}
110061110084
}
110062110085
sqlite3DebugPrintf("\n");
110063
- for(ii=0; ii<nTabList; ii++){
110086
+ for(ii=0; ii<pWInfo->nLevel; ii++){
110064110087
whereLoopPrint(pWInfo->a[ii].pWLoop, pTabList);
110065110088
}
110066110089
}
110067110090
#endif
110091
+ /* Attempt to omit tables from the join that do not effect the result */
110092
+ if( pWInfo->nLevel>=2
110093
+ && pResultSet!=0
110094
+ && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
110095
+ ){
110096
+ Bitmask tabUsed = exprListTableUsage(pMaskSet, pResultSet);
110097
+ if( pOrderBy ) tabUsed |= exprListTableUsage(pMaskSet, pOrderBy);
110098
+ while( pWInfo->nLevel>=2 ){
110099
+ pLoop = pWInfo->a[pWInfo->nLevel-1].pWLoop;
110100
+ if( (pWInfo->pTabList->a[pLoop->iTab].jointype & JT_LEFT)==0 ) break;
110101
+ if( (wctrlFlags & WHERE_WANT_DISTINCT)==0
110102
+ && (pLoop->wsFlags & WHERE_ONEROW)==0
110103
+ ){
110104
+ break;
110105
+ }
110106
+ if( (tabUsed & pLoop->maskSelf)!=0 ) break;
110107
+ WHERETRACE(0xffff, ("-> drop loop %c not used\n", pLoop->cId));
110108
+ pWInfo->nLevel--;
110109
+ nTabList--;
110110
+ }
110111
+ }
110068110112
WHERETRACE(0xffff,("*** Optimizer Finished ***\n"));
110069110113
pWInfo->pParse->nQueryLoop += pWInfo->nRowOut;
110070110114
110071110115
/* If the caller is an UPDATE or DELETE statement that is requesting
110072110116
** to use a one-pass algorithm, determine if this is appropriate.
@@ -110231,11 +110275,11 @@
110231110275
*/
110232110276
sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
110233110277
110234110278
/* Close all of the cursors that were opened by sqlite3WhereBegin.
110235110279
*/
110236
- assert( pWInfo->nLevel==1 || pWInfo->nLevel==pTabList->nSrc );
110280
+ assert( pWInfo->nLevel<=pTabList->nSrc );
110237110281
for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
110238110282
Index *pIdx = 0;
110239110283
struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
110240110284
Table *pTab = pTabItem->pTab;
110241110285
assert( pTab!=0 );
@@ -119407,10 +119451,11 @@
119407119451
sqlite3 *db; /* The database connection */
119408119452
const char *zDb; /* logical database name */
119409119453
const char *zName; /* virtual table name */
119410119454
int nColumn; /* number of named columns in virtual table */
119411119455
char **azColumn; /* column names. malloced */
119456
+ u8 *abNotindexed; /* True for 'notindexed' columns */
119412119457
sqlite3_tokenizer *pTokenizer; /* tokenizer for inserts and queries */
119413119458
char *zContentTbl; /* content=xxx option, or NULL */
119414119459
char *zLanguageid; /* languageid=xxx option, or NULL */
119415119460
u8 bAutoincrmerge; /* True if automerge=1 */
119416119461
u32 nLeafAdd; /* Number of leaf blocks added this trans */
@@ -119634,11 +119679,10 @@
119634119679
sqlite3_int64, sqlite3_int64, const char *, int, Fts3SegReader**);
119635119680
SQLITE_PRIVATE int sqlite3Fts3SegReaderPending(
119636119681
Fts3Table*,int,const char*,int,int,Fts3SegReader**);
119637119682
SQLITE_PRIVATE void sqlite3Fts3SegReaderFree(Fts3SegReader *);
119638119683
SQLITE_PRIVATE int sqlite3Fts3AllSegdirs(Fts3Table*, int, int, int, sqlite3_stmt **);
119639
-SQLITE_PRIVATE int sqlite3Fts3ReadLock(Fts3Table *);
119640119684
SQLITE_PRIVATE int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*, int*);
119641119685
119642119686
SQLITE_PRIVATE int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **);
119643119687
SQLITE_PRIVATE int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **);
119644119688
@@ -120567,22 +120611,34 @@
120567120611
char *zPrefix = 0; /* Prefix parameter value (or NULL) */
120568120612
char *zCompress = 0; /* compress=? parameter (or NULL) */
120569120613
char *zUncompress = 0; /* uncompress=? parameter (or NULL) */
120570120614
char *zContent = 0; /* content=? parameter (or NULL) */
120571120615
char *zLanguageid = 0; /* languageid=? parameter (or NULL) */
120616
+ char **azNotindexed = 0; /* The set of notindexed= columns */
120617
+ int nNotindexed = 0; /* Size of azNotindexed[] array */
120572120618
120573120619
assert( strlen(argv[0])==4 );
120574120620
assert( (sqlite3_strnicmp(argv[0], "fts4", 4)==0 && isFts4)
120575120621
|| (sqlite3_strnicmp(argv[0], "fts3", 4)==0 && !isFts4)
120576120622
);
120577120623
120578120624
nDb = (int)strlen(argv[1]) + 1;
120579120625
nName = (int)strlen(argv[2]) + 1;
120580120626
120581
- aCol = (const char **)sqlite3_malloc(sizeof(const char *) * (argc-2) );
120582
- if( !aCol ) return SQLITE_NOMEM;
120583
- memset((void *)aCol, 0, sizeof(const char *) * (argc-2));
120627
+ nByte = sizeof(const char *) * (argc-2);
120628
+ aCol = (const char **)sqlite3_malloc(nByte);
120629
+ if( aCol ){
120630
+ memset(aCol, 0, nByte);
120631
+ azNotindexed = (char **)sqlite3_malloc(nByte);
120632
+ }
120633
+ if( azNotindexed ){
120634
+ memset(azNotindexed, 0, nByte);
120635
+ }
120636
+ if( !aCol || !azNotindexed ){
120637
+ rc = SQLITE_NOMEM;
120638
+ goto fts3_init_out;
120639
+ }
120584120640
120585120641
/* Loop through all of the arguments passed by the user to the FTS3/4
120586120642
** module (i.e. all the column names and special arguments). This loop
120587120643
** does the following:
120588120644
**
@@ -120617,11 +120673,12 @@
120617120673
{ "prefix", 6 }, /* 1 -> PREFIX */
120618120674
{ "compress", 8 }, /* 2 -> COMPRESS */
120619120675
{ "uncompress", 10 }, /* 3 -> UNCOMPRESS */
120620120676
{ "order", 5 }, /* 4 -> ORDER */
120621120677
{ "content", 7 }, /* 5 -> CONTENT */
120622
- { "languageid", 10 } /* 6 -> LANGUAGEID */
120678
+ { "languageid", 10 }, /* 6 -> LANGUAGEID */
120679
+ { "notindexed", 10 } /* 7 -> NOTINDEXED */
120623120680
};
120624120681
120625120682
int iOpt;
120626120683
if( !zVal ){
120627120684
rc = SQLITE_NOMEM;
@@ -120683,10 +120740,15 @@
120683120740
assert( iOpt==6 );
120684120741
sqlite3_free(zLanguageid);
120685120742
zLanguageid = zVal;
120686120743
zVal = 0;
120687120744
break;
120745
+
120746
+ case 7: /* NOTINDEXED */
120747
+ azNotindexed[nNotindexed++] = zVal;
120748
+ zVal = 0;
120749
+ break;
120688120750
}
120689120751
}
120690120752
sqlite3_free(zVal);
120691120753
}
120692120754
}
@@ -120754,10 +120816,11 @@
120754120816
120755120817
/* Allocate and populate the Fts3Table structure. */
120756120818
nByte = sizeof(Fts3Table) + /* Fts3Table */
120757120819
nCol * sizeof(char *) + /* azColumn */
120758120820
nIndex * sizeof(struct Fts3Index) + /* aIndex */
120821
+ nCol * sizeof(u8) + /* abNotindexed */
120759120822
nName + /* zName */
120760120823
nDb + /* zDb */
120761120824
nString; /* Space for azColumn strings */
120762120825
p = (Fts3Table*)sqlite3_malloc(nByte);
120763120826
if( p==0 ){
@@ -120787,13 +120850,14 @@
120787120850
memcpy(p->aIndex, aIndex, sizeof(struct Fts3Index) * nIndex);
120788120851
p->nIndex = nIndex;
120789120852
for(i=0; i<nIndex; i++){
120790120853
fts3HashInit(&p->aIndex[i].hPending, FTS3_HASH_STRING, 1);
120791120854
}
120855
+ p->abNotindexed = (u8 *)&p->aIndex[nIndex];
120792120856
120793120857
/* Fill in the zName and zDb fields of the vtab structure. */
120794
- zCsr = (char *)&p->aIndex[nIndex];
120858
+ zCsr = (char *)&p->abNotindexed[nCol];
120795120859
p->zName = zCsr;
120796120860
memcpy(zCsr, argv[2], nName);
120797120861
zCsr += nName;
120798120862
p->zDb = zCsr;
120799120863
memcpy(zCsr, argv[1], nDb);
@@ -120810,11 +120874,30 @@
120810120874
p->azColumn[iCol] = zCsr;
120811120875
zCsr += n+1;
120812120876
assert( zCsr <= &((char *)p)[nByte] );
120813120877
}
120814120878
120815
- if( (zCompress==0)!=(zUncompress==0) ){
120879
+ /* Fill in the abNotindexed array */
120880
+ for(iCol=0; iCol<nCol; iCol++){
120881
+ int n = strlen(p->azColumn[iCol]);
120882
+ for(i=0; i<nNotindexed; i++){
120883
+ char *zNot = azNotindexed[i];
120884
+ if( zNot && 0==sqlite3_strnicmp(p->azColumn[iCol], zNot, n) ){
120885
+ p->abNotindexed[iCol] = 1;
120886
+ sqlite3_free(zNot);
120887
+ azNotindexed[i] = 0;
120888
+ }
120889
+ }
120890
+ }
120891
+ for(i=0; i<nNotindexed; i++){
120892
+ if( azNotindexed[i] ){
120893
+ *pzErr = sqlite3_mprintf("no such column: %s", azNotindexed[i]);
120894
+ rc = SQLITE_ERROR;
120895
+ }
120896
+ }
120897
+
120898
+ if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
120816120899
char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
120817120900
rc = SQLITE_ERROR;
120818120901
*pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss);
120819120902
}
120820120903
p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
@@ -120851,11 +120934,13 @@
120851120934
sqlite3_free(aIndex);
120852120935
sqlite3_free(zCompress);
120853120936
sqlite3_free(zUncompress);
120854120937
sqlite3_free(zContent);
120855120938
sqlite3_free(zLanguageid);
120939
+ for(i=0; i<nNotindexed; i++) sqlite3_free(azNotindexed[i]);
120856120940
sqlite3_free((void *)aCol);
120941
+ sqlite3_free((void *)azNotindexed);
120857120942
if( rc!=SQLITE_OK ){
120858120943
if( p ){
120859120944
fts3DisconnectMethod((sqlite3_vtab *)p);
120860120945
}else if( pTokenizer ){
120861120946
pTokenizer->pModule->xDestroy(pTokenizer);
@@ -129717,16 +129802,19 @@
129717129802
sqlite3_value **apVal,
129718129803
u32 *aSz
129719129804
){
129720129805
int i; /* Iterator variable */
129721129806
for(i=2; i<p->nColumn+2; i++){
129722
- const char *zText = (const char *)sqlite3_value_text(apVal[i]);
129723
- int rc = fts3PendingTermsAdd(p, iLangid, zText, i-2, &aSz[i-2]);
129724
- if( rc!=SQLITE_OK ){
129725
- return rc;
129807
+ int iCol = i-2;
129808
+ if( p->abNotindexed[iCol]==0 ){
129809
+ const char *zText = (const char *)sqlite3_value_text(apVal[i]);
129810
+ int rc = fts3PendingTermsAdd(p, iLangid, zText, iCol, &aSz[iCol]);
129811
+ if( rc!=SQLITE_OK ){
129812
+ return rc;
129813
+ }
129814
+ aSz[p->nColumn] += sqlite3_value_bytes(apVal[i]);
129726129815
}
129727
- aSz[p->nColumn] += sqlite3_value_bytes(apVal[i]);
129728129816
}
129729129817
return SQLITE_OK;
129730129818
}
129731129819
129732129820
/*
@@ -129869,13 +129957,16 @@
129869129957
if( SQLITE_ROW==sqlite3_step(pSelect) ){
129870129958
int i;
129871129959
int iLangid = langidFromSelect(p, pSelect);
129872129960
rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pSelect, 0));
129873129961
for(i=1; rc==SQLITE_OK && i<=p->nColumn; i++){
129874
- const char *zText = (const char *)sqlite3_column_text(pSelect, i);
129875
- rc = fts3PendingTermsAdd(p, iLangid, zText, -1, &aSz[i-1]);
129876
- aSz[p->nColumn] += sqlite3_column_bytes(pSelect, i);
129962
+ int iCol = i-1;
129963
+ if( p->abNotindexed[iCol]==0 ){
129964
+ const char *zText = (const char *)sqlite3_column_text(pSelect, i);
129965
+ rc = fts3PendingTermsAdd(p, iLangid, zText, -1, &aSz[iCol]);
129966
+ aSz[p->nColumn] += sqlite3_column_bytes(pSelect, i);
129967
+ }
129877129968
}
129878129969
if( rc!=SQLITE_OK ){
129879129970
sqlite3_reset(pSelect);
129880129971
*pRC = rc;
129881129972
return;
@@ -132113,13 +132204,15 @@
132113132204
int iCol;
132114132205
int iLangid = langidFromSelect(p, pStmt);
132115132206
rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pStmt, 0));
132116132207
memset(aSz, 0, sizeof(aSz[0]) * (p->nColumn+1));
132117132208
for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){
132118
- const char *z = (const char *) sqlite3_column_text(pStmt, iCol+1);
132119
- rc = fts3PendingTermsAdd(p, iLangid, z, iCol, &aSz[iCol]);
132120
- aSz[p->nColumn] += sqlite3_column_bytes(pStmt, iCol+1);
132209
+ if( p->abNotindexed[iCol]==0 ){
132210
+ const char *z = (const char *) sqlite3_column_text(pStmt, iCol+1);
132211
+ rc = fts3PendingTermsAdd(p, iLangid, z, iCol, &aSz[iCol]);
132212
+ aSz[p->nColumn] += sqlite3_column_bytes(pStmt, iCol+1);
132213
+ }
132121132214
}
132122132215
if( p->bHasDocsize ){
132123132216
fts3InsertDocsize(&rc, p, aSz);
132124132217
}
132125132218
if( rc!=SQLITE_OK ){
@@ -133918,39 +134011,41 @@
133918134011
133919134012
assert( pCsr->isRequireSeek==0 );
133920134013
iDocid = sqlite3_column_int64(pCsr->pStmt, 0);
133921134014
133922134015
for(i=0; i<p->nColumn && rc==SQLITE_OK; i++){
133923
- const char *zText = (const char *)sqlite3_column_text(pCsr->pStmt, i+1);
133924
- sqlite3_tokenizer_cursor *pTC = 0;
133925
-
133926
- rc = sqlite3Fts3OpenTokenizer(pT, pCsr->iLangid, zText, -1, &pTC);
133927
- while( rc==SQLITE_OK ){
133928
- char const *zToken; /* Buffer containing token */
133929
- int nToken = 0; /* Number of bytes in token */
133930
- int iDum1 = 0, iDum2 = 0; /* Dummy variables */
133931
- int iPos = 0; /* Position of token in zText */
133932
-
133933
- rc = pModule->xNext(pTC, &zToken, &nToken, &iDum1, &iDum2, &iPos);
133934
- for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
133935
- Fts3PhraseToken *pPT = pDef->pToken;
133936
- if( (pDef->iCol>=p->nColumn || pDef->iCol==i)
133937
- && (pPT->bFirst==0 || iPos==0)
133938
- && (pPT->n==nToken || (pPT->isPrefix && pPT->n<nToken))
133939
- && (0==memcmp(zToken, pPT->z, pPT->n))
133940
- ){
133941
- fts3PendingListAppend(&pDef->pList, iDocid, i, iPos, &rc);
133942
- }
133943
- }
133944
- }
133945
- if( pTC ) pModule->xClose(pTC);
133946
- if( rc==SQLITE_DONE ) rc = SQLITE_OK;
133947
- }
133948
-
133949
- for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
133950
- if( pDef->pList ){
133951
- rc = fts3PendingListAppendVarint(&pDef->pList, 0);
134016
+ if( p->abNotindexed[i]==0 ){
134017
+ const char *zText = (const char *)sqlite3_column_text(pCsr->pStmt, i+1);
134018
+ sqlite3_tokenizer_cursor *pTC = 0;
134019
+
134020
+ rc = sqlite3Fts3OpenTokenizer(pT, pCsr->iLangid, zText, -1, &pTC);
134021
+ while( rc==SQLITE_OK ){
134022
+ char const *zToken; /* Buffer containing token */
134023
+ int nToken = 0; /* Number of bytes in token */
134024
+ int iDum1 = 0, iDum2 = 0; /* Dummy variables */
134025
+ int iPos = 0; /* Position of token in zText */
134026
+
134027
+ rc = pModule->xNext(pTC, &zToken, &nToken, &iDum1, &iDum2, &iPos);
134028
+ for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
134029
+ Fts3PhraseToken *pPT = pDef->pToken;
134030
+ if( (pDef->iCol>=p->nColumn || pDef->iCol==i)
134031
+ && (pPT->bFirst==0 || iPos==0)
134032
+ && (pPT->n==nToken || (pPT->isPrefix && pPT->n<nToken))
134033
+ && (0==memcmp(zToken, pPT->z, pPT->n))
134034
+ ){
134035
+ fts3PendingListAppend(&pDef->pList, iDocid, i, iPos, &rc);
134036
+ }
134037
+ }
134038
+ }
134039
+ if( pTC ) pModule->xClose(pTC);
134040
+ if( rc==SQLITE_DONE ) rc = SQLITE_OK;
134041
+ }
134042
+
134043
+ for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
134044
+ if( pDef->pList ){
134045
+ rc = fts3PendingListAppendVarint(&pDef->pList, 0);
134046
+ }
133952134047
}
133953134048
}
133954134049
}
133955134050
133956134051
return rc;
133957134052
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.7.17. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -668,13 +668,13 @@
668 **
669 ** See also: [sqlite3_libversion()],
670 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
671 ** [sqlite_version()] and [sqlite_source_id()].
672 */
673 #define SQLITE_VERSION "3.7.17"
674 #define SQLITE_VERSION_NUMBER 3007017
675 #define SQLITE_SOURCE_ID "2013-06-20 14:17:39 d94db3fd921890ab1d6414ab629410ae50779686"
676
677 /*
678 ** CAPI3REF: Run-Time Library Version Numbers
679 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
680 **
@@ -6869,15 +6869,25 @@
6869 ** <dd>^This is the number of rows inserted into transient indices that
6870 ** were created automatically in order to help joins run faster.
6871 ** A non-zero value in this counter may indicate an opportunity to
6872 ** improvement performance by adding permanent indices that do not
6873 ** need to be reinitialized each time the statement is run.</dd>
 
 
 
 
 
 
 
 
 
6874 ** </dl>
6875 */
6876 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
6877 #define SQLITE_STMTSTATUS_SORT 2
6878 #define SQLITE_STMTSTATUS_AUTOINDEX 3
 
6879
6880 /*
6881 ** CAPI3REF: Custom Page Cache Object
6882 **
6883 ** The sqlite3_pcache type is opaque. It is implemented by
@@ -10193,10 +10203,11 @@
10193 #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
10194 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
10195 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10196 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10197 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
 
10198 #define SQLITE_AllOpts 0xffff /* All optimizations */
10199
10200 /*
10201 ** Macros for testing whether or not optimizations are enabled or disabled.
10202 */
@@ -11143,10 +11154,11 @@
11143 #define WHERE_FORCE_TABLE 0x0020 /* Do not use an index-only search */
11144 #define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
11145 #define WHERE_AND_ONLY 0x0080 /* Don't use indices for OR terms */
11146 #define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */
11147 #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */
 
11148
11149 /* Allowed return values from sqlite3WhereIsDistinct()
11150 */
11151 #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */
11152 #define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */
@@ -13507,11 +13519,11 @@
13507 bft doingRerun:1; /* True if rerunning after an auto-reprepare */
13508 int nChange; /* Number of db changes made since last reset */
13509 yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
13510 yDbMask lockMask; /* Subset of btreeMask that requires a lock */
13511 int iStatement; /* Statement number (or 0 if has not opened stmt) */
13512 int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
13513 #ifndef SQLITE_OMIT_TRACE
13514 i64 startTime; /* Time when query started - used for profiling */
13515 #endif
13516 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
13517 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
@@ -65351,16 +65363,17 @@
65351 u8 encoding = ENC(db); /* The database encoding */
65352 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65353 int checkProgress; /* True if progress callbacks are enabled */
65354 int nProgressOps = 0; /* Opcodes executed since progress callback. */
65355 #endif
 
 
65356 Mem *aMem = p->aMem; /* Copy of p->aMem */
65357 Mem *pIn1 = 0; /* 1st input operand */
65358 Mem *pIn2 = 0; /* 2nd input operand */
65359 Mem *pIn3 = 0; /* 3rd input operand */
65360 Mem *pOut = 0; /* Output operand */
65361 int iCompare = 0; /* Result of last OP_Compare operation */
65362 int *aPermute = 0; /* Permutation of columns for OP_Compare */
65363 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
65364 #ifdef VDBE_PROFILE
65365 u64 start; /* CPU clock count at start of opcode */
65366 int origPc; /* Program counter at start of opcode */
@@ -65830,10 +65843,11 @@
65830 if( db->mallocFailed ) goto no_mem;
65831 #ifdef VDBE_PROFILE
65832 origPc = pc;
65833 start = sqlite3Hwtime();
65834 #endif
 
65835 pOp = &aOp[pc];
65836
65837 /* Only allow tracing if SQLITE_DEBUG is defined.
65838 */
65839 #ifdef SQLITE_DEBUG
@@ -71566,10 +71580,11 @@
71566 /* This is the only way out of this procedure. We have to
71567 ** release the mutexes on btrees that were acquired at the
71568 ** top. */
71569 vdbe_return:
71570 db->lastRowid = lastRowid;
 
71571 sqlite3VdbeLeave(p);
71572 return rc;
71573
71574 /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
71575 ** is encountered.
@@ -76044,10 +76059,11 @@
76044 pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
76045 pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
76046 pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
76047 pItem->sortOrder = pOldItem->sortOrder;
76048 pItem->done = 0;
 
76049 pItem->iOrderByCol = pOldItem->iOrderByCol;
76050 pItem->iAlias = pOldItem->iAlias;
76051 }
76052 return pNew;
76053 }
@@ -100236,19 +100252,20 @@
100236 sDistinct.eTnctType = WHERE_DISTINCT_NOOP;
100237 }
100238
100239 if( !isAgg && pGroupBy==0 ){
100240 /* No aggregate functions and no GROUP BY clause */
100241 ExprList *pDist = (sDistinct.isTnct ? p->pEList : 0);
100242
100243 /* Begin the database scan. */
100244 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pOrderBy, pDist, 0,0);
 
100245 if( pWInfo==0 ) goto select_end;
100246 if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
100247 p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
100248 }
100249 if( sqlite3WhereIsDistinct(pWInfo) ){
100250 sDistinct.eTnctType = sqlite3WhereIsDistinct(pWInfo);
100251 }
100252 if( pOrderBy && sqlite3WhereIsOrdered(pWInfo) ) pOrderBy = 0;
100253
100254 /* If sorting index that was created by a prior OP_OpenEphemeral
@@ -104664,23 +104681,23 @@
104664 */
104665 struct WhereInfo {
104666 Parse *pParse; /* Parsing and code generating context */
104667 SrcList *pTabList; /* List of tables in the join */
104668 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
104669 ExprList *pDistinct; /* DISTINCT ON values, or NULL */
104670 WhereLoop *pLoops; /* List of all WhereLoop objects */
104671 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
104672 WhereCost nRowOut; /* Estimated number of output rows */
104673 u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
104674 u8 bOBSat; /* ORDER BY satisfied by indices */
104675 u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE/DELETE */
104676 u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */
104677 u8 eDistinct; /* One of the WHERE_DISTINCT_* values below */
 
104678 int iTop; /* The very beginning of the WHERE loop */
104679 int iContinue; /* Jump here to continue with next record */
104680 int iBreak; /* Jump here to break out of the loop */
104681 int nLevel; /* Number of nested loop */
104682 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
104683 WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
104684 WhereClause sWC; /* Decomposition of the WHERE clause */
104685 WhereLevel a[1]; /* Information about each nest loop in WHERE */
104686 };
@@ -106690,13 +106707,14 @@
106690 z = (const u8 *)sqlite3_value_blob(pVal);
106691 pColl = db->pDfltColl;
106692 assert( pColl->enc==SQLITE_UTF8 );
106693 }else{
106694 pColl = sqlite3GetCollSeq(pParse, SQLITE_UTF8, 0, *pIdx->azColl);
106695 if( pColl==0 ){
106696 return SQLITE_ERROR;
106697 }
 
106698 z = (const u8 *)sqlite3ValueText(pVal, pColl->enc);
106699 if( !z ){
106700 return SQLITE_NOMEM;
106701 }
106702 assert( z && pColl && pColl->xCmp );
@@ -108208,13 +108226,13 @@
108208 */
108209 static void whereLoopPrint(WhereLoop *p, SrcList *pTabList){
108210 int nb = 1+(pTabList->nSrc+7)/8;
108211 struct SrcList_item *pItem = pTabList->a + p->iTab;
108212 Table *pTab = pItem->pTab;
108213 sqlite3DebugPrintf("%c %2d.%0*llx.%0*llx", p->cId,
108214 p->iTab, nb, p->maskSelf, nb, p->prereq);
108215 sqlite3DebugPrintf(" %8s",
108216 pItem->zAlias ? pItem->zAlias : pTab->zName);
108217 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
108218 if( p->u.btree.pIndex ){
108219 const char *zName = p->u.btree.pIndex->zName;
108220 if( zName==0 ) zName = "ipk";
@@ -108221,26 +108239,26 @@
108221 if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
108222 int i = sqlite3Strlen30(zName) - 1;
108223 while( zName[i]!='_' ) i--;
108224 zName += i;
108225 }
108226 sqlite3DebugPrintf(".%-12s %2d", zName, p->u.btree.nEq);
108227 }else{
108228 sqlite3DebugPrintf("%16s","");
108229 }
108230 }else{
108231 char *z;
108232 if( p->u.vtab.idxStr ){
108233 z = sqlite3_mprintf("(%d,\"%s\",%x)",
108234 p->u.vtab.idxNum, p->u.vtab.idxStr, p->u.vtab.omitMask);
108235 }else{
108236 z = sqlite3_mprintf("(%d,%x)", p->u.vtab.idxNum, p->u.vtab.omitMask);
108237 }
108238 sqlite3DebugPrintf(" %-15s", z);
108239 sqlite3_free(z);
108240 }
108241 sqlite3DebugPrintf(" fg %05x N %d", p->wsFlags, p->nLTerm);
108242 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
108243 }
108244 #endif
108245
108246 /*
@@ -109650,16 +109668,17 @@
109650 WhereLevel *pLevel = pWInfo->a + iLoop;
109651 pLevel->pWLoop = pWLoop = pFrom->aLoop[iLoop];
109652 pLevel->iFrom = pWLoop->iTab;
109653 pLevel->iTabCur = pWInfo->pTabList->a[pLevel->iFrom].iCursor;
109654 }
109655 if( (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
109656 && pWInfo->pDistinct
 
109657 && nRowEst
109658 ){
109659 Bitmask notUsed;
109660 int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pDistinct, pFrom,
109661 WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
109662 if( rc==1 ) pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
109663 }
109664 if( pFrom->isOrdered ){
109665 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
@@ -109744,11 +109763,13 @@
109744 pWInfo->a[0].pWLoop = pLoop;
109745 pLoop->maskSelf = getMask(&pWInfo->sMaskSet, iCur);
109746 pWInfo->a[0].iTabCur = iCur;
109747 pWInfo->nRowOut = 1;
109748 if( pWInfo->pOrderBy ) pWInfo->bOBSat = 1;
109749 if( pWInfo->pDistinct ) pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
 
 
109750 #ifdef SQLITE_DEBUG
109751 pLoop->cId = '0';
109752 #endif
109753 return 1;
109754 }
@@ -109834,14 +109855,14 @@
109834 ** if there is one. If there is no ORDER BY clause or if this routine
109835 ** is called from an UPDATE or DELETE statement, then pOrderBy is NULL.
109836 */
109837 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
109838 Parse *pParse, /* The parser context */
109839 SrcList *pTabList, /* A list of all tables to be scanned */
109840 Expr *pWhere, /* The WHERE clause */
109841 ExprList *pOrderBy, /* An ORDER BY clause, or NULL */
109842 ExprList *pDistinct, /* The select-list for DISTINCT queries - or NULL */
109843 u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
109844 int iIdxCur /* If WHERE_ONETABLE_ONLY is set, index cursor number */
109845 ){
109846 int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
109847 int nTabList; /* Number of elements in pTabList */
@@ -109849,18 +109870,26 @@
109849 Vdbe *v = pParse->pVdbe; /* The virtual database engine */
109850 Bitmask notReady; /* Cursors that are not yet positioned */
109851 WhereLoopBuilder sWLB; /* The WhereLoop builder */
109852 WhereMaskSet *pMaskSet; /* The expression mask set */
109853 WhereLevel *pLevel; /* A single level in pWInfo->a[] */
 
109854 int ii; /* Loop counter */
109855 sqlite3 *db; /* Database connection */
109856 int rc; /* Return code */
109857
109858
109859 /* Variable initialization */
 
109860 memset(&sWLB, 0, sizeof(sWLB));
109861 sWLB.pOrderBy = pOrderBy;
 
 
 
 
 
 
109862
109863 /* The number of tables in the FROM clause is limited by the number of
109864 ** bits in a Bitmask
109865 */
109866 testcase( pTabList->nSrc==BMS );
@@ -109881,11 +109910,10 @@
109881 ** struct, the contents of WhereInfo.a[], the WhereClause structure
109882 ** and the WhereMaskSet structure. Since WhereClause contains an 8-byte
109883 ** field (type Bitmask) it must be aligned on an 8-byte boundary on
109884 ** some architectures. Hence the ROUND8() below.
109885 */
109886 db = pParse->db;
109887 nByteWInfo = ROUND8(sizeof(WhereInfo)+(nTabList-1)*sizeof(WhereLevel));
109888 pWInfo = sqlite3DbMallocZero(db, nByteWInfo + sizeof(WhereLoop));
109889 if( db->mallocFailed ){
109890 sqlite3DbFree(db, pWInfo);
109891 pWInfo = 0;
@@ -109893,11 +109921,11 @@
109893 }
109894 pWInfo->nLevel = nTabList;
109895 pWInfo->pParse = pParse;
109896 pWInfo->pTabList = pTabList;
109897 pWInfo->pOrderBy = pOrderBy;
109898 pWInfo->pDistinct = pDistinct;
109899 pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
109900 pWInfo->wctrlFlags = wctrlFlags;
109901 pWInfo->savedNQueryLoop = pParse->nQueryLoop;
109902 pMaskSet = &pWInfo->sMaskSet;
109903 sWLB.pWInfo = pWInfo;
@@ -109906,14 +109934,10 @@
109906 whereLoopInit(sWLB.pNew);
109907 #ifdef SQLITE_DEBUG
109908 sWLB.pNew->cId = '*';
109909 #endif
109910
109911 /* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via
109912 ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */
109913 if( OptimizationDisabled(db, SQLITE_DistinctOpt) ) pDistinct = 0;
109914
109915 /* Split the WHERE clause into separate subexpressions where each
109916 ** subexpression is separated by an AND operator.
109917 */
109918 initMaskSet(pMaskSet);
109919 whereClauseInit(&pWInfo->sWC, pWInfo);
@@ -109930,11 +109954,13 @@
109930
109931 /* Special case: No FROM clause
109932 */
109933 if( nTabList==0 ){
109934 if( pOrderBy ) pWInfo->bOBSat = 1;
109935 if( pDistinct ) pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
 
 
109936 }
109937
109938 /* Assign a bit from the bitmask to every term in the FROM clause.
109939 **
109940 ** When assigning bitmask values to FROM clause cursors, it must be
@@ -109977,11 +110003,11 @@
109977
109978 /* If the ORDER BY (or GROUP BY) clause contains references to general
109979 ** expressions, then we won't be able to satisfy it using indices, so
109980 ** go ahead and disable it now.
109981 */
109982 if( pOrderBy && pDistinct ){
109983 for(ii=0; ii<pOrderBy->nExpr; ii++){
109984 Expr *pExpr = sqlite3ExprSkipCollate(pOrderBy->a[ii].pExpr);
109985 if( pExpr->op!=TK_COLUMN ){
109986 pWInfo->pOrderBy = pOrderBy = 0;
109987 break;
@@ -109989,21 +110015,18 @@
109989 break;
109990 }
109991 }
109992 }
109993
109994 /* Check if the DISTINCT qualifier, if there is one, is redundant.
109995 ** If it is, then set pDistinct to NULL and WhereInfo.eDistinct to
109996 ** WHERE_DISTINCT_UNIQUE to tell the caller to ignore the DISTINCT.
109997 */
109998 if( pDistinct ){
109999 if( isDistinctRedundant(pParse,pTabList,&pWInfo->sWC,pDistinct) ){
110000 pDistinct = 0;
110001 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
110002 }else if( pOrderBy==0 ){
 
110003 pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
110004 pWInfo->pOrderBy = pDistinct;
110005 }
110006 }
110007
110008 /* Construct the WhereLoop objects */
110009 WHERETRACE(0xffff,("*** Optimizer Start ***\n"));
@@ -110013,15 +110036,15 @@
110013
110014 /* Display all of the WhereLoop objects if wheretrace is enabled */
110015 #ifdef WHERETRACE_ENABLED
110016 if( sqlite3WhereTrace ){
110017 WhereLoop *p;
110018 int i = 0;
110019 static char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz"
110020 "ABCDEFGHIJKLMNOPQRSTUVWYXZ";
110021 for(p=pWInfo->pLoops; p; p=p->pNextLoop){
110022 p->cId = zLabel[(i++)%sizeof(zLabel)];
110023 whereLoopPrint(p, pTabList);
110024 }
110025 }
110026 #endif
110027
@@ -110058,15 +110081,36 @@
110058 sqlite3DebugPrintf(" DISTINCT=unordered");
110059 break;
110060 }
110061 }
110062 sqlite3DebugPrintf("\n");
110063 for(ii=0; ii<nTabList; ii++){
110064 whereLoopPrint(pWInfo->a[ii].pWLoop, pTabList);
110065 }
110066 }
110067 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110068 WHERETRACE(0xffff,("*** Optimizer Finished ***\n"));
110069 pWInfo->pParse->nQueryLoop += pWInfo->nRowOut;
110070
110071 /* If the caller is an UPDATE or DELETE statement that is requesting
110072 ** to use a one-pass algorithm, determine if this is appropriate.
@@ -110231,11 +110275,11 @@
110231 */
110232 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
110233
110234 /* Close all of the cursors that were opened by sqlite3WhereBegin.
110235 */
110236 assert( pWInfo->nLevel==1 || pWInfo->nLevel==pTabList->nSrc );
110237 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
110238 Index *pIdx = 0;
110239 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
110240 Table *pTab = pTabItem->pTab;
110241 assert( pTab!=0 );
@@ -119407,10 +119451,11 @@
119407 sqlite3 *db; /* The database connection */
119408 const char *zDb; /* logical database name */
119409 const char *zName; /* virtual table name */
119410 int nColumn; /* number of named columns in virtual table */
119411 char **azColumn; /* column names. malloced */
 
119412 sqlite3_tokenizer *pTokenizer; /* tokenizer for inserts and queries */
119413 char *zContentTbl; /* content=xxx option, or NULL */
119414 char *zLanguageid; /* languageid=xxx option, or NULL */
119415 u8 bAutoincrmerge; /* True if automerge=1 */
119416 u32 nLeafAdd; /* Number of leaf blocks added this trans */
@@ -119634,11 +119679,10 @@
119634 sqlite3_int64, sqlite3_int64, const char *, int, Fts3SegReader**);
119635 SQLITE_PRIVATE int sqlite3Fts3SegReaderPending(
119636 Fts3Table*,int,const char*,int,int,Fts3SegReader**);
119637 SQLITE_PRIVATE void sqlite3Fts3SegReaderFree(Fts3SegReader *);
119638 SQLITE_PRIVATE int sqlite3Fts3AllSegdirs(Fts3Table*, int, int, int, sqlite3_stmt **);
119639 SQLITE_PRIVATE int sqlite3Fts3ReadLock(Fts3Table *);
119640 SQLITE_PRIVATE int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*, int*);
119641
119642 SQLITE_PRIVATE int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **);
119643 SQLITE_PRIVATE int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **);
119644
@@ -120567,22 +120611,34 @@
120567 char *zPrefix = 0; /* Prefix parameter value (or NULL) */
120568 char *zCompress = 0; /* compress=? parameter (or NULL) */
120569 char *zUncompress = 0; /* uncompress=? parameter (or NULL) */
120570 char *zContent = 0; /* content=? parameter (or NULL) */
120571 char *zLanguageid = 0; /* languageid=? parameter (or NULL) */
 
 
120572
120573 assert( strlen(argv[0])==4 );
120574 assert( (sqlite3_strnicmp(argv[0], "fts4", 4)==0 && isFts4)
120575 || (sqlite3_strnicmp(argv[0], "fts3", 4)==0 && !isFts4)
120576 );
120577
120578 nDb = (int)strlen(argv[1]) + 1;
120579 nName = (int)strlen(argv[2]) + 1;
120580
120581 aCol = (const char **)sqlite3_malloc(sizeof(const char *) * (argc-2) );
120582 if( !aCol ) return SQLITE_NOMEM;
120583 memset((void *)aCol, 0, sizeof(const char *) * (argc-2));
 
 
 
 
 
 
 
 
 
 
120584
120585 /* Loop through all of the arguments passed by the user to the FTS3/4
120586 ** module (i.e. all the column names and special arguments). This loop
120587 ** does the following:
120588 **
@@ -120617,11 +120673,12 @@
120617 { "prefix", 6 }, /* 1 -> PREFIX */
120618 { "compress", 8 }, /* 2 -> COMPRESS */
120619 { "uncompress", 10 }, /* 3 -> UNCOMPRESS */
120620 { "order", 5 }, /* 4 -> ORDER */
120621 { "content", 7 }, /* 5 -> CONTENT */
120622 { "languageid", 10 } /* 6 -> LANGUAGEID */
 
120623 };
120624
120625 int iOpt;
120626 if( !zVal ){
120627 rc = SQLITE_NOMEM;
@@ -120683,10 +120740,15 @@
120683 assert( iOpt==6 );
120684 sqlite3_free(zLanguageid);
120685 zLanguageid = zVal;
120686 zVal = 0;
120687 break;
 
 
 
 
 
120688 }
120689 }
120690 sqlite3_free(zVal);
120691 }
120692 }
@@ -120754,10 +120816,11 @@
120754
120755 /* Allocate and populate the Fts3Table structure. */
120756 nByte = sizeof(Fts3Table) + /* Fts3Table */
120757 nCol * sizeof(char *) + /* azColumn */
120758 nIndex * sizeof(struct Fts3Index) + /* aIndex */
 
120759 nName + /* zName */
120760 nDb + /* zDb */
120761 nString; /* Space for azColumn strings */
120762 p = (Fts3Table*)sqlite3_malloc(nByte);
120763 if( p==0 ){
@@ -120787,13 +120850,14 @@
120787 memcpy(p->aIndex, aIndex, sizeof(struct Fts3Index) * nIndex);
120788 p->nIndex = nIndex;
120789 for(i=0; i<nIndex; i++){
120790 fts3HashInit(&p->aIndex[i].hPending, FTS3_HASH_STRING, 1);
120791 }
 
120792
120793 /* Fill in the zName and zDb fields of the vtab structure. */
120794 zCsr = (char *)&p->aIndex[nIndex];
120795 p->zName = zCsr;
120796 memcpy(zCsr, argv[2], nName);
120797 zCsr += nName;
120798 p->zDb = zCsr;
120799 memcpy(zCsr, argv[1], nDb);
@@ -120810,11 +120874,30 @@
120810 p->azColumn[iCol] = zCsr;
120811 zCsr += n+1;
120812 assert( zCsr <= &((char *)p)[nByte] );
120813 }
120814
120815 if( (zCompress==0)!=(zUncompress==0) ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120816 char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
120817 rc = SQLITE_ERROR;
120818 *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss);
120819 }
120820 p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
@@ -120851,11 +120934,13 @@
120851 sqlite3_free(aIndex);
120852 sqlite3_free(zCompress);
120853 sqlite3_free(zUncompress);
120854 sqlite3_free(zContent);
120855 sqlite3_free(zLanguageid);
 
120856 sqlite3_free((void *)aCol);
 
120857 if( rc!=SQLITE_OK ){
120858 if( p ){
120859 fts3DisconnectMethod((sqlite3_vtab *)p);
120860 }else if( pTokenizer ){
120861 pTokenizer->pModule->xDestroy(pTokenizer);
@@ -129717,16 +129802,19 @@
129717 sqlite3_value **apVal,
129718 u32 *aSz
129719 ){
129720 int i; /* Iterator variable */
129721 for(i=2; i<p->nColumn+2; i++){
129722 const char *zText = (const char *)sqlite3_value_text(apVal[i]);
129723 int rc = fts3PendingTermsAdd(p, iLangid, zText, i-2, &aSz[i-2]);
129724 if( rc!=SQLITE_OK ){
129725 return rc;
 
 
 
 
129726 }
129727 aSz[p->nColumn] += sqlite3_value_bytes(apVal[i]);
129728 }
129729 return SQLITE_OK;
129730 }
129731
129732 /*
@@ -129869,13 +129957,16 @@
129869 if( SQLITE_ROW==sqlite3_step(pSelect) ){
129870 int i;
129871 int iLangid = langidFromSelect(p, pSelect);
129872 rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pSelect, 0));
129873 for(i=1; rc==SQLITE_OK && i<=p->nColumn; i++){
129874 const char *zText = (const char *)sqlite3_column_text(pSelect, i);
129875 rc = fts3PendingTermsAdd(p, iLangid, zText, -1, &aSz[i-1]);
129876 aSz[p->nColumn] += sqlite3_column_bytes(pSelect, i);
 
 
 
129877 }
129878 if( rc!=SQLITE_OK ){
129879 sqlite3_reset(pSelect);
129880 *pRC = rc;
129881 return;
@@ -132113,13 +132204,15 @@
132113 int iCol;
132114 int iLangid = langidFromSelect(p, pStmt);
132115 rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pStmt, 0));
132116 memset(aSz, 0, sizeof(aSz[0]) * (p->nColumn+1));
132117 for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){
132118 const char *z = (const char *) sqlite3_column_text(pStmt, iCol+1);
132119 rc = fts3PendingTermsAdd(p, iLangid, z, iCol, &aSz[iCol]);
132120 aSz[p->nColumn] += sqlite3_column_bytes(pStmt, iCol+1);
 
 
132121 }
132122 if( p->bHasDocsize ){
132123 fts3InsertDocsize(&rc, p, aSz);
132124 }
132125 if( rc!=SQLITE_OK ){
@@ -133918,39 +134011,41 @@
133918
133919 assert( pCsr->isRequireSeek==0 );
133920 iDocid = sqlite3_column_int64(pCsr->pStmt, 0);
133921
133922 for(i=0; i<p->nColumn && rc==SQLITE_OK; i++){
133923 const char *zText = (const char *)sqlite3_column_text(pCsr->pStmt, i+1);
133924 sqlite3_tokenizer_cursor *pTC = 0;
133925
133926 rc = sqlite3Fts3OpenTokenizer(pT, pCsr->iLangid, zText, -1, &pTC);
133927 while( rc==SQLITE_OK ){
133928 char const *zToken; /* Buffer containing token */
133929 int nToken = 0; /* Number of bytes in token */
133930 int iDum1 = 0, iDum2 = 0; /* Dummy variables */
133931 int iPos = 0; /* Position of token in zText */
133932
133933 rc = pModule->xNext(pTC, &zToken, &nToken, &iDum1, &iDum2, &iPos);
133934 for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
133935 Fts3PhraseToken *pPT = pDef->pToken;
133936 if( (pDef->iCol>=p->nColumn || pDef->iCol==i)
133937 && (pPT->bFirst==0 || iPos==0)
133938 && (pPT->n==nToken || (pPT->isPrefix && pPT->n<nToken))
133939 && (0==memcmp(zToken, pPT->z, pPT->n))
133940 ){
133941 fts3PendingListAppend(&pDef->pList, iDocid, i, iPos, &rc);
133942 }
133943 }
133944 }
133945 if( pTC ) pModule->xClose(pTC);
133946 if( rc==SQLITE_DONE ) rc = SQLITE_OK;
133947 }
133948
133949 for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
133950 if( pDef->pList ){
133951 rc = fts3PendingListAppendVarint(&pDef->pList, 0);
 
 
133952 }
133953 }
133954 }
133955
133956 return rc;
133957
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -668,13 +668,13 @@
668 **
669 ** See also: [sqlite3_libversion()],
670 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
671 ** [sqlite_version()] and [sqlite_source_id()].
672 */
673 #define SQLITE_VERSION "3.8.0"
674 #define SQLITE_VERSION_NUMBER 3008000
675 #define SQLITE_SOURCE_ID "2013-06-26 22:46:00 93f632152e464a89322a0130adaf9f342411bf7d"
676
677 /*
678 ** CAPI3REF: Run-Time Library Version Numbers
679 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
680 **
@@ -6869,15 +6869,25 @@
6869 ** <dd>^This is the number of rows inserted into transient indices that
6870 ** were created automatically in order to help joins run faster.
6871 ** A non-zero value in this counter may indicate an opportunity to
6872 ** improvement performance by adding permanent indices that do not
6873 ** need to be reinitialized each time the statement is run.</dd>
6874 **
6875 ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
6876 ** <dd>^This is the number of virtual machine operations executed
6877 ** by the prepared statement if that number is less than or equal
6878 ** to 2147483647. The number of virtual machine operations can be
6879 ** used as a proxy for the total work done by the prepared statement.
6880 ** If the number of virtual machine operations exceeds 2147483647
6881 ** then the value returned by this statement status code is undefined.
6882 ** </dd>
6883 ** </dl>
6884 */
6885 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
6886 #define SQLITE_STMTSTATUS_SORT 2
6887 #define SQLITE_STMTSTATUS_AUTOINDEX 3
6888 #define SQLITE_STMTSTATUS_VM_STEP 4
6889
6890 /*
6891 ** CAPI3REF: Custom Page Cache Object
6892 **
6893 ** The sqlite3_pcache type is opaque. It is implemented by
@@ -10193,10 +10203,11 @@
10203 #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
10204 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
10205 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10206 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10207 #define SQLITE_Transitive 0x0200 /* Transitive constraints */
10208 #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
10209 #define SQLITE_AllOpts 0xffff /* All optimizations */
10210
10211 /*
10212 ** Macros for testing whether or not optimizations are enabled or disabled.
10213 */
@@ -11143,10 +11154,11 @@
11154 #define WHERE_FORCE_TABLE 0x0020 /* Do not use an index-only search */
11155 #define WHERE_ONETABLE_ONLY 0x0040 /* Only code the 1st table in pTabList */
11156 #define WHERE_AND_ONLY 0x0080 /* Don't use indices for OR terms */
11157 #define WHERE_GROUPBY 0x0100 /* pOrderBy is really a GROUP BY */
11158 #define WHERE_DISTINCTBY 0x0200 /* pOrderby is really a DISTINCT clause */
11159 #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */
11160
11161 /* Allowed return values from sqlite3WhereIsDistinct()
11162 */
11163 #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */
11164 #define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */
@@ -13507,11 +13519,11 @@
13519 bft doingRerun:1; /* True if rerunning after an auto-reprepare */
13520 int nChange; /* Number of db changes made since last reset */
13521 yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
13522 yDbMask lockMask; /* Subset of btreeMask that requires a lock */
13523 int iStatement; /* Statement number (or 0 if has not opened stmt) */
13524 int aCounter[4]; /* Counters used by sqlite3_stmt_status() */
13525 #ifndef SQLITE_OMIT_TRACE
13526 i64 startTime; /* Time when query started - used for profiling */
13527 #endif
13528 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
13529 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
@@ -65351,16 +65363,17 @@
65363 u8 encoding = ENC(db); /* The database encoding */
65364 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
65365 int checkProgress; /* True if progress callbacks are enabled */
65366 int nProgressOps = 0; /* Opcodes executed since progress callback. */
65367 #endif
65368 int iCompare = 0; /* Result of last OP_Compare operation */
65369 unsigned nVmStep = 0; /* Number of virtual machine steps */
65370 Mem *aMem = p->aMem; /* Copy of p->aMem */
65371 Mem *pIn1 = 0; /* 1st input operand */
65372 Mem *pIn2 = 0; /* 2nd input operand */
65373 Mem *pIn3 = 0; /* 3rd input operand */
65374 Mem *pOut = 0; /* Output operand */
 
65375 int *aPermute = 0; /* Permutation of columns for OP_Compare */
65376 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
65377 #ifdef VDBE_PROFILE
65378 u64 start; /* CPU clock count at start of opcode */
65379 int origPc; /* Program counter at start of opcode */
@@ -65830,10 +65843,11 @@
65843 if( db->mallocFailed ) goto no_mem;
65844 #ifdef VDBE_PROFILE
65845 origPc = pc;
65846 start = sqlite3Hwtime();
65847 #endif
65848 nVmStep++;
65849 pOp = &aOp[pc];
65850
65851 /* Only allow tracing if SQLITE_DEBUG is defined.
65852 */
65853 #ifdef SQLITE_DEBUG
@@ -71566,10 +71580,11 @@
71580 /* This is the only way out of this procedure. We have to
71581 ** release the mutexes on btrees that were acquired at the
71582 ** top. */
71583 vdbe_return:
71584 db->lastRowid = lastRowid;
71585 p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1] += (int)nVmStep;
71586 sqlite3VdbeLeave(p);
71587 return rc;
71588
71589 /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH
71590 ** is encountered.
@@ -76044,10 +76059,11 @@
76059 pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
76060 pItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
76061 pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan);
76062 pItem->sortOrder = pOldItem->sortOrder;
76063 pItem->done = 0;
76064 pItem->bSpanIsTab = pOldItem->bSpanIsTab;
76065 pItem->iOrderByCol = pOldItem->iOrderByCol;
76066 pItem->iAlias = pOldItem->iAlias;
76067 }
76068 return pNew;
76069 }
@@ -100236,19 +100252,20 @@
100252 sDistinct.eTnctType = WHERE_DISTINCT_NOOP;
100253 }
100254
100255 if( !isAgg && pGroupBy==0 ){
100256 /* No aggregate functions and no GROUP BY clause */
100257 u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0);
100258
100259 /* Begin the database scan. */
100260 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pOrderBy, p->pEList,
100261 wctrlFlags, 0);
100262 if( pWInfo==0 ) goto select_end;
100263 if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
100264 p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
100265 }
100266 if( sDistinct.isTnct && sqlite3WhereIsDistinct(pWInfo) ){
100267 sDistinct.eTnctType = sqlite3WhereIsDistinct(pWInfo);
100268 }
100269 if( pOrderBy && sqlite3WhereIsOrdered(pWInfo) ) pOrderBy = 0;
100270
100271 /* If sorting index that was created by a prior OP_OpenEphemeral
@@ -104664,23 +104681,23 @@
104681 */
104682 struct WhereInfo {
104683 Parse *pParse; /* Parsing and code generating context */
104684 SrcList *pTabList; /* List of tables in the join */
104685 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
104686 ExprList *pResultSet; /* Result set. DISTINCT operates on these */
104687 WhereLoop *pLoops; /* List of all WhereLoop objects */
104688 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
104689 WhereCost nRowOut; /* Estimated number of output rows */
104690 u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
104691 u8 bOBSat; /* ORDER BY satisfied by indices */
104692 u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE/DELETE */
104693 u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */
104694 u8 eDistinct; /* One of the WHERE_DISTINCT_* values below */
104695 u8 nLevel; /* Number of nested loop */
104696 int iTop; /* The very beginning of the WHERE loop */
104697 int iContinue; /* Jump here to continue with next record */
104698 int iBreak; /* Jump here to break out of the loop */
 
104699 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
104700 WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
104701 WhereClause sWC; /* Decomposition of the WHERE clause */
104702 WhereLevel a[1]; /* Information about each nest loop in WHERE */
104703 };
@@ -106690,13 +106707,14 @@
106707 z = (const u8 *)sqlite3_value_blob(pVal);
106708 pColl = db->pDfltColl;
106709 assert( pColl->enc==SQLITE_UTF8 );
106710 }else{
106711 pColl = sqlite3GetCollSeq(pParse, SQLITE_UTF8, 0, *pIdx->azColl);
106712 /* If the collating sequence was unavailable, we should have failed
106713 ** long ago and never reached this point. But we'll check just to
106714 ** be doubly sure. */
106715 if( NEVER(pColl==0) ) return SQLITE_ERROR;
106716 z = (const u8 *)sqlite3ValueText(pVal, pColl->enc);
106717 if( !z ){
106718 return SQLITE_NOMEM;
106719 }
106720 assert( z && pColl && pColl->xCmp );
@@ -108208,13 +108226,13 @@
108226 */
108227 static void whereLoopPrint(WhereLoop *p, SrcList *pTabList){
108228 int nb = 1+(pTabList->nSrc+7)/8;
108229 struct SrcList_item *pItem = pTabList->a + p->iTab;
108230 Table *pTab = pItem->pTab;
108231 sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
108232 p->iTab, nb, p->maskSelf, nb, p->prereq);
108233 sqlite3DebugPrintf(" %12s",
108234 pItem->zAlias ? pItem->zAlias : pTab->zName);
108235 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
108236 if( p->u.btree.pIndex ){
108237 const char *zName = p->u.btree.pIndex->zName;
108238 if( zName==0 ) zName = "ipk";
@@ -108221,26 +108239,26 @@
108239 if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
108240 int i = sqlite3Strlen30(zName) - 1;
108241 while( zName[i]!='_' ) i--;
108242 zName += i;
108243 }
108244 sqlite3DebugPrintf(".%-16s %2d", zName, p->u.btree.nEq);
108245 }else{
108246 sqlite3DebugPrintf("%20s","");
108247 }
108248 }else{
108249 char *z;
108250 if( p->u.vtab.idxStr ){
108251 z = sqlite3_mprintf("(%d,\"%s\",%x)",
108252 p->u.vtab.idxNum, p->u.vtab.idxStr, p->u.vtab.omitMask);
108253 }else{
108254 z = sqlite3_mprintf("(%d,%x)", p->u.vtab.idxNum, p->u.vtab.omitMask);
108255 }
108256 sqlite3DebugPrintf(" %-19s", z);
108257 sqlite3_free(z);
108258 }
108259 sqlite3DebugPrintf(" f %04x N %d", p->wsFlags, p->nLTerm);
108260 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);
108261 }
108262 #endif
108263
108264 /*
@@ -109650,16 +109668,17 @@
109668 WhereLevel *pLevel = pWInfo->a + iLoop;
109669 pLevel->pWLoop = pWLoop = pFrom->aLoop[iLoop];
109670 pLevel->iFrom = pWLoop->iTab;
109671 pLevel->iTabCur = pWInfo->pTabList->a[pLevel->iFrom].iCursor;
109672 }
109673 if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0
109674 && (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
109675 && pWInfo->eDistinct==WHERE_DISTINCT_NOOP
109676 && nRowEst
109677 ){
109678 Bitmask notUsed;
109679 int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pResultSet, pFrom,
109680 WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
109681 if( rc==1 ) pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
109682 }
109683 if( pFrom->isOrdered ){
109684 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
@@ -109744,11 +109763,13 @@
109763 pWInfo->a[0].pWLoop = pLoop;
109764 pLoop->maskSelf = getMask(&pWInfo->sMaskSet, iCur);
109765 pWInfo->a[0].iTabCur = iCur;
109766 pWInfo->nRowOut = 1;
109767 if( pWInfo->pOrderBy ) pWInfo->bOBSat = 1;
109768 if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){
109769 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
109770 }
109771 #ifdef SQLITE_DEBUG
109772 pLoop->cId = '0';
109773 #endif
109774 return 1;
109775 }
@@ -109834,14 +109855,14 @@
109855 ** if there is one. If there is no ORDER BY clause or if this routine
109856 ** is called from an UPDATE or DELETE statement, then pOrderBy is NULL.
109857 */
109858 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
109859 Parse *pParse, /* The parser context */
109860 SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
109861 Expr *pWhere, /* The WHERE clause */
109862 ExprList *pOrderBy, /* An ORDER BY clause, or NULL */
109863 ExprList *pResultSet, /* Result set of the query */
109864 u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
109865 int iIdxCur /* If WHERE_ONETABLE_ONLY is set, index cursor number */
109866 ){
109867 int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
109868 int nTabList; /* Number of elements in pTabList */
@@ -109849,18 +109870,26 @@
109870 Vdbe *v = pParse->pVdbe; /* The virtual database engine */
109871 Bitmask notReady; /* Cursors that are not yet positioned */
109872 WhereLoopBuilder sWLB; /* The WhereLoop builder */
109873 WhereMaskSet *pMaskSet; /* The expression mask set */
109874 WhereLevel *pLevel; /* A single level in pWInfo->a[] */
109875 WhereLoop *pLoop; /* Pointer to a single WhereLoop object */
109876 int ii; /* Loop counter */
109877 sqlite3 *db; /* Database connection */
109878 int rc; /* Return code */
109879
109880
109881 /* Variable initialization */
109882 db = pParse->db;
109883 memset(&sWLB, 0, sizeof(sWLB));
109884 sWLB.pOrderBy = pOrderBy;
109885
109886 /* Disable the DISTINCT optimization if SQLITE_DistinctOpt is set via
109887 ** sqlite3_test_ctrl(SQLITE_TESTCTRL_OPTIMIZATIONS,...) */
109888 if( OptimizationDisabled(db, SQLITE_DistinctOpt) ){
109889 wctrlFlags &= ~WHERE_WANT_DISTINCT;
109890 }
109891
109892 /* The number of tables in the FROM clause is limited by the number of
109893 ** bits in a Bitmask
109894 */
109895 testcase( pTabList->nSrc==BMS );
@@ -109881,11 +109910,10 @@
109910 ** struct, the contents of WhereInfo.a[], the WhereClause structure
109911 ** and the WhereMaskSet structure. Since WhereClause contains an 8-byte
109912 ** field (type Bitmask) it must be aligned on an 8-byte boundary on
109913 ** some architectures. Hence the ROUND8() below.
109914 */
 
109915 nByteWInfo = ROUND8(sizeof(WhereInfo)+(nTabList-1)*sizeof(WhereLevel));
109916 pWInfo = sqlite3DbMallocZero(db, nByteWInfo + sizeof(WhereLoop));
109917 if( db->mallocFailed ){
109918 sqlite3DbFree(db, pWInfo);
109919 pWInfo = 0;
@@ -109893,11 +109921,11 @@
109921 }
109922 pWInfo->nLevel = nTabList;
109923 pWInfo->pParse = pParse;
109924 pWInfo->pTabList = pTabList;
109925 pWInfo->pOrderBy = pOrderBy;
109926 pWInfo->pResultSet = pResultSet;
109927 pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
109928 pWInfo->wctrlFlags = wctrlFlags;
109929 pWInfo->savedNQueryLoop = pParse->nQueryLoop;
109930 pMaskSet = &pWInfo->sMaskSet;
109931 sWLB.pWInfo = pWInfo;
@@ -109906,14 +109934,10 @@
109934 whereLoopInit(sWLB.pNew);
109935 #ifdef SQLITE_DEBUG
109936 sWLB.pNew->cId = '*';
109937 #endif
109938
 
 
 
 
109939 /* Split the WHERE clause into separate subexpressions where each
109940 ** subexpression is separated by an AND operator.
109941 */
109942 initMaskSet(pMaskSet);
109943 whereClauseInit(&pWInfo->sWC, pWInfo);
@@ -109930,11 +109954,13 @@
109954
109955 /* Special case: No FROM clause
109956 */
109957 if( nTabList==0 ){
109958 if( pOrderBy ) pWInfo->bOBSat = 1;
109959 if( wctrlFlags & WHERE_WANT_DISTINCT ){
109960 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
109961 }
109962 }
109963
109964 /* Assign a bit from the bitmask to every term in the FROM clause.
109965 **
109966 ** When assigning bitmask values to FROM clause cursors, it must be
@@ -109977,11 +110003,11 @@
110003
110004 /* If the ORDER BY (or GROUP BY) clause contains references to general
110005 ** expressions, then we won't be able to satisfy it using indices, so
110006 ** go ahead and disable it now.
110007 */
110008 if( pOrderBy && (wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){
110009 for(ii=0; ii<pOrderBy->nExpr; ii++){
110010 Expr *pExpr = sqlite3ExprSkipCollate(pOrderBy->a[ii].pExpr);
110011 if( pExpr->op!=TK_COLUMN ){
110012 pWInfo->pOrderBy = pOrderBy = 0;
110013 break;
@@ -109989,21 +110015,18 @@
110015 break;
110016 }
110017 }
110018 }
110019
110020 if( wctrlFlags & WHERE_WANT_DISTINCT ){
110021 if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
110022 /* The DISTINCT marking is pointless. Ignore it. */
 
 
 
 
110023 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
110024 }else if( pOrderBy==0 ){
110025 /* Try to ORDER BY the result set to make distinct processing easier */
110026 pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
110027 pWInfo->pOrderBy = pResultSet;
110028 }
110029 }
110030
110031 /* Construct the WhereLoop objects */
110032 WHERETRACE(0xffff,("*** Optimizer Start ***\n"));
@@ -110013,15 +110036,15 @@
110036
110037 /* Display all of the WhereLoop objects if wheretrace is enabled */
110038 #ifdef WHERETRACE_ENABLED
110039 if( sqlite3WhereTrace ){
110040 WhereLoop *p;
110041 int i;
110042 static char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz"
110043 "ABCDEFGHIJKLMNOPQRSTUVWYXZ";
110044 for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
110045 p->cId = zLabel[i%sizeof(zLabel)];
110046 whereLoopPrint(p, pTabList);
110047 }
110048 }
110049 #endif
110050
@@ -110058,15 +110081,36 @@
110081 sqlite3DebugPrintf(" DISTINCT=unordered");
110082 break;
110083 }
110084 }
110085 sqlite3DebugPrintf("\n");
110086 for(ii=0; ii<pWInfo->nLevel; ii++){
110087 whereLoopPrint(pWInfo->a[ii].pWLoop, pTabList);
110088 }
110089 }
110090 #endif
110091 /* Attempt to omit tables from the join that do not effect the result */
110092 if( pWInfo->nLevel>=2
110093 && pResultSet!=0
110094 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
110095 ){
110096 Bitmask tabUsed = exprListTableUsage(pMaskSet, pResultSet);
110097 if( pOrderBy ) tabUsed |= exprListTableUsage(pMaskSet, pOrderBy);
110098 while( pWInfo->nLevel>=2 ){
110099 pLoop = pWInfo->a[pWInfo->nLevel-1].pWLoop;
110100 if( (pWInfo->pTabList->a[pLoop->iTab].jointype & JT_LEFT)==0 ) break;
110101 if( (wctrlFlags & WHERE_WANT_DISTINCT)==0
110102 && (pLoop->wsFlags & WHERE_ONEROW)==0
110103 ){
110104 break;
110105 }
110106 if( (tabUsed & pLoop->maskSelf)!=0 ) break;
110107 WHERETRACE(0xffff, ("-> drop loop %c not used\n", pLoop->cId));
110108 pWInfo->nLevel--;
110109 nTabList--;
110110 }
110111 }
110112 WHERETRACE(0xffff,("*** Optimizer Finished ***\n"));
110113 pWInfo->pParse->nQueryLoop += pWInfo->nRowOut;
110114
110115 /* If the caller is an UPDATE or DELETE statement that is requesting
110116 ** to use a one-pass algorithm, determine if this is appropriate.
@@ -110231,11 +110275,11 @@
110275 */
110276 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
110277
110278 /* Close all of the cursors that were opened by sqlite3WhereBegin.
110279 */
110280 assert( pWInfo->nLevel<=pTabList->nSrc );
110281 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
110282 Index *pIdx = 0;
110283 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
110284 Table *pTab = pTabItem->pTab;
110285 assert( pTab!=0 );
@@ -119407,10 +119451,11 @@
119451 sqlite3 *db; /* The database connection */
119452 const char *zDb; /* logical database name */
119453 const char *zName; /* virtual table name */
119454 int nColumn; /* number of named columns in virtual table */
119455 char **azColumn; /* column names. malloced */
119456 u8 *abNotindexed; /* True for 'notindexed' columns */
119457 sqlite3_tokenizer *pTokenizer; /* tokenizer for inserts and queries */
119458 char *zContentTbl; /* content=xxx option, or NULL */
119459 char *zLanguageid; /* languageid=xxx option, or NULL */
119460 u8 bAutoincrmerge; /* True if automerge=1 */
119461 u32 nLeafAdd; /* Number of leaf blocks added this trans */
@@ -119634,11 +119679,10 @@
119679 sqlite3_int64, sqlite3_int64, const char *, int, Fts3SegReader**);
119680 SQLITE_PRIVATE int sqlite3Fts3SegReaderPending(
119681 Fts3Table*,int,const char*,int,int,Fts3SegReader**);
119682 SQLITE_PRIVATE void sqlite3Fts3SegReaderFree(Fts3SegReader *);
119683 SQLITE_PRIVATE int sqlite3Fts3AllSegdirs(Fts3Table*, int, int, int, sqlite3_stmt **);
 
119684 SQLITE_PRIVATE int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*, int*);
119685
119686 SQLITE_PRIVATE int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **);
119687 SQLITE_PRIVATE int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **);
119688
@@ -120567,22 +120611,34 @@
120611 char *zPrefix = 0; /* Prefix parameter value (or NULL) */
120612 char *zCompress = 0; /* compress=? parameter (or NULL) */
120613 char *zUncompress = 0; /* uncompress=? parameter (or NULL) */
120614 char *zContent = 0; /* content=? parameter (or NULL) */
120615 char *zLanguageid = 0; /* languageid=? parameter (or NULL) */
120616 char **azNotindexed = 0; /* The set of notindexed= columns */
120617 int nNotindexed = 0; /* Size of azNotindexed[] array */
120618
120619 assert( strlen(argv[0])==4 );
120620 assert( (sqlite3_strnicmp(argv[0], "fts4", 4)==0 && isFts4)
120621 || (sqlite3_strnicmp(argv[0], "fts3", 4)==0 && !isFts4)
120622 );
120623
120624 nDb = (int)strlen(argv[1]) + 1;
120625 nName = (int)strlen(argv[2]) + 1;
120626
120627 nByte = sizeof(const char *) * (argc-2);
120628 aCol = (const char **)sqlite3_malloc(nByte);
120629 if( aCol ){
120630 memset(aCol, 0, nByte);
120631 azNotindexed = (char **)sqlite3_malloc(nByte);
120632 }
120633 if( azNotindexed ){
120634 memset(azNotindexed, 0, nByte);
120635 }
120636 if( !aCol || !azNotindexed ){
120637 rc = SQLITE_NOMEM;
120638 goto fts3_init_out;
120639 }
120640
120641 /* Loop through all of the arguments passed by the user to the FTS3/4
120642 ** module (i.e. all the column names and special arguments). This loop
120643 ** does the following:
120644 **
@@ -120617,11 +120673,12 @@
120673 { "prefix", 6 }, /* 1 -> PREFIX */
120674 { "compress", 8 }, /* 2 -> COMPRESS */
120675 { "uncompress", 10 }, /* 3 -> UNCOMPRESS */
120676 { "order", 5 }, /* 4 -> ORDER */
120677 { "content", 7 }, /* 5 -> CONTENT */
120678 { "languageid", 10 }, /* 6 -> LANGUAGEID */
120679 { "notindexed", 10 } /* 7 -> NOTINDEXED */
120680 };
120681
120682 int iOpt;
120683 if( !zVal ){
120684 rc = SQLITE_NOMEM;
@@ -120683,10 +120740,15 @@
120740 assert( iOpt==6 );
120741 sqlite3_free(zLanguageid);
120742 zLanguageid = zVal;
120743 zVal = 0;
120744 break;
120745
120746 case 7: /* NOTINDEXED */
120747 azNotindexed[nNotindexed++] = zVal;
120748 zVal = 0;
120749 break;
120750 }
120751 }
120752 sqlite3_free(zVal);
120753 }
120754 }
@@ -120754,10 +120816,11 @@
120816
120817 /* Allocate and populate the Fts3Table structure. */
120818 nByte = sizeof(Fts3Table) + /* Fts3Table */
120819 nCol * sizeof(char *) + /* azColumn */
120820 nIndex * sizeof(struct Fts3Index) + /* aIndex */
120821 nCol * sizeof(u8) + /* abNotindexed */
120822 nName + /* zName */
120823 nDb + /* zDb */
120824 nString; /* Space for azColumn strings */
120825 p = (Fts3Table*)sqlite3_malloc(nByte);
120826 if( p==0 ){
@@ -120787,13 +120850,14 @@
120850 memcpy(p->aIndex, aIndex, sizeof(struct Fts3Index) * nIndex);
120851 p->nIndex = nIndex;
120852 for(i=0; i<nIndex; i++){
120853 fts3HashInit(&p->aIndex[i].hPending, FTS3_HASH_STRING, 1);
120854 }
120855 p->abNotindexed = (u8 *)&p->aIndex[nIndex];
120856
120857 /* Fill in the zName and zDb fields of the vtab structure. */
120858 zCsr = (char *)&p->abNotindexed[nCol];
120859 p->zName = zCsr;
120860 memcpy(zCsr, argv[2], nName);
120861 zCsr += nName;
120862 p->zDb = zCsr;
120863 memcpy(zCsr, argv[1], nDb);
@@ -120810,11 +120874,30 @@
120874 p->azColumn[iCol] = zCsr;
120875 zCsr += n+1;
120876 assert( zCsr <= &((char *)p)[nByte] );
120877 }
120878
120879 /* Fill in the abNotindexed array */
120880 for(iCol=0; iCol<nCol; iCol++){
120881 int n = strlen(p->azColumn[iCol]);
120882 for(i=0; i<nNotindexed; i++){
120883 char *zNot = azNotindexed[i];
120884 if( zNot && 0==sqlite3_strnicmp(p->azColumn[iCol], zNot, n) ){
120885 p->abNotindexed[iCol] = 1;
120886 sqlite3_free(zNot);
120887 azNotindexed[i] = 0;
120888 }
120889 }
120890 }
120891 for(i=0; i<nNotindexed; i++){
120892 if( azNotindexed[i] ){
120893 *pzErr = sqlite3_mprintf("no such column: %s", azNotindexed[i]);
120894 rc = SQLITE_ERROR;
120895 }
120896 }
120897
120898 if( rc==SQLITE_OK && (zCompress==0)!=(zUncompress==0) ){
120899 char const *zMiss = (zCompress==0 ? "compress" : "uncompress");
120900 rc = SQLITE_ERROR;
120901 *pzErr = sqlite3_mprintf("missing %s parameter in fts4 constructor", zMiss);
120902 }
120903 p->zReadExprlist = fts3ReadExprList(p, zUncompress, &rc);
@@ -120851,11 +120934,13 @@
120934 sqlite3_free(aIndex);
120935 sqlite3_free(zCompress);
120936 sqlite3_free(zUncompress);
120937 sqlite3_free(zContent);
120938 sqlite3_free(zLanguageid);
120939 for(i=0; i<nNotindexed; i++) sqlite3_free(azNotindexed[i]);
120940 sqlite3_free((void *)aCol);
120941 sqlite3_free((void *)azNotindexed);
120942 if( rc!=SQLITE_OK ){
120943 if( p ){
120944 fts3DisconnectMethod((sqlite3_vtab *)p);
120945 }else if( pTokenizer ){
120946 pTokenizer->pModule->xDestroy(pTokenizer);
@@ -129717,16 +129802,19 @@
129802 sqlite3_value **apVal,
129803 u32 *aSz
129804 ){
129805 int i; /* Iterator variable */
129806 for(i=2; i<p->nColumn+2; i++){
129807 int iCol = i-2;
129808 if( p->abNotindexed[iCol]==0 ){
129809 const char *zText = (const char *)sqlite3_value_text(apVal[i]);
129810 int rc = fts3PendingTermsAdd(p, iLangid, zText, iCol, &aSz[iCol]);
129811 if( rc!=SQLITE_OK ){
129812 return rc;
129813 }
129814 aSz[p->nColumn] += sqlite3_value_bytes(apVal[i]);
129815 }
 
129816 }
129817 return SQLITE_OK;
129818 }
129819
129820 /*
@@ -129869,13 +129957,16 @@
129957 if( SQLITE_ROW==sqlite3_step(pSelect) ){
129958 int i;
129959 int iLangid = langidFromSelect(p, pSelect);
129960 rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pSelect, 0));
129961 for(i=1; rc==SQLITE_OK && i<=p->nColumn; i++){
129962 int iCol = i-1;
129963 if( p->abNotindexed[iCol]==0 ){
129964 const char *zText = (const char *)sqlite3_column_text(pSelect, i);
129965 rc = fts3PendingTermsAdd(p, iLangid, zText, -1, &aSz[iCol]);
129966 aSz[p->nColumn] += sqlite3_column_bytes(pSelect, i);
129967 }
129968 }
129969 if( rc!=SQLITE_OK ){
129970 sqlite3_reset(pSelect);
129971 *pRC = rc;
129972 return;
@@ -132113,13 +132204,15 @@
132204 int iCol;
132205 int iLangid = langidFromSelect(p, pStmt);
132206 rc = fts3PendingTermsDocid(p, iLangid, sqlite3_column_int64(pStmt, 0));
132207 memset(aSz, 0, sizeof(aSz[0]) * (p->nColumn+1));
132208 for(iCol=0; rc==SQLITE_OK && iCol<p->nColumn; iCol++){
132209 if( p->abNotindexed[iCol]==0 ){
132210 const char *z = (const char *) sqlite3_column_text(pStmt, iCol+1);
132211 rc = fts3PendingTermsAdd(p, iLangid, z, iCol, &aSz[iCol]);
132212 aSz[p->nColumn] += sqlite3_column_bytes(pStmt, iCol+1);
132213 }
132214 }
132215 if( p->bHasDocsize ){
132216 fts3InsertDocsize(&rc, p, aSz);
132217 }
132218 if( rc!=SQLITE_OK ){
@@ -133918,39 +134011,41 @@
134011
134012 assert( pCsr->isRequireSeek==0 );
134013 iDocid = sqlite3_column_int64(pCsr->pStmt, 0);
134014
134015 for(i=0; i<p->nColumn && rc==SQLITE_OK; i++){
134016 if( p->abNotindexed[i]==0 ){
134017 const char *zText = (const char *)sqlite3_column_text(pCsr->pStmt, i+1);
134018 sqlite3_tokenizer_cursor *pTC = 0;
134019
134020 rc = sqlite3Fts3OpenTokenizer(pT, pCsr->iLangid, zText, -1, &pTC);
134021 while( rc==SQLITE_OK ){
134022 char const *zToken; /* Buffer containing token */
134023 int nToken = 0; /* Number of bytes in token */
134024 int iDum1 = 0, iDum2 = 0; /* Dummy variables */
134025 int iPos = 0; /* Position of token in zText */
134026
134027 rc = pModule->xNext(pTC, &zToken, &nToken, &iDum1, &iDum2, &iPos);
134028 for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
134029 Fts3PhraseToken *pPT = pDef->pToken;
134030 if( (pDef->iCol>=p->nColumn || pDef->iCol==i)
134031 && (pPT->bFirst==0 || iPos==0)
134032 && (pPT->n==nToken || (pPT->isPrefix && pPT->n<nToken))
134033 && (0==memcmp(zToken, pPT->z, pPT->n))
134034 ){
134035 fts3PendingListAppend(&pDef->pList, iDocid, i, iPos, &rc);
134036 }
134037 }
134038 }
134039 if( pTC ) pModule->xClose(pTC);
134040 if( rc==SQLITE_DONE ) rc = SQLITE_OK;
134041 }
134042
134043 for(pDef=pCsr->pDeferred; pDef && rc==SQLITE_OK; pDef=pDef->pNext){
134044 if( pDef->pList ){
134045 rc = fts3PendingListAppendVarint(&pDef->pList, 0);
134046 }
134047 }
134048 }
134049 }
134050
134051 return rc;
134052
+13 -3
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.7.17"
111
-#define SQLITE_VERSION_NUMBER 3007017
112
-#define SQLITE_SOURCE_ID "2013-06-20 14:17:39 d94db3fd921890ab1d6414ab629410ae50779686"
110
+#define SQLITE_VERSION "3.8.0"
111
+#define SQLITE_VERSION_NUMBER 3008000
112
+#define SQLITE_SOURCE_ID "2013-06-26 22:46:00 93f632152e464a89322a0130adaf9f342411bf7d"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -6306,15 +6306,25 @@
63066306
** <dd>^This is the number of rows inserted into transient indices that
63076307
** were created automatically in order to help joins run faster.
63086308
** A non-zero value in this counter may indicate an opportunity to
63096309
** improvement performance by adding permanent indices that do not
63106310
** need to be reinitialized each time the statement is run.</dd>
6311
+**
6312
+** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
6313
+** <dd>^This is the number of virtual machine operations executed
6314
+** by the prepared statement if that number is less than or equal
6315
+** to 2147483647. The number of virtual machine operations can be
6316
+** used as a proxy for the total work done by the prepared statement.
6317
+** If the number of virtual machine operations exceeds 2147483647
6318
+** then the value returned by this statement status code is undefined.
6319
+** </dd>
63116320
** </dl>
63126321
*/
63136322
#define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
63146323
#define SQLITE_STMTSTATUS_SORT 2
63156324
#define SQLITE_STMTSTATUS_AUTOINDEX 3
6325
+#define SQLITE_STMTSTATUS_VM_STEP 4
63166326
63176327
/*
63186328
** CAPI3REF: Custom Page Cache Object
63196329
**
63206330
** The sqlite3_pcache type is opaque. It is implemented by
63216331
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.17"
111 #define SQLITE_VERSION_NUMBER 3007017
112 #define SQLITE_SOURCE_ID "2013-06-20 14:17:39 d94db3fd921890ab1d6414ab629410ae50779686"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -6306,15 +6306,25 @@
6306 ** <dd>^This is the number of rows inserted into transient indices that
6307 ** were created automatically in order to help joins run faster.
6308 ** A non-zero value in this counter may indicate an opportunity to
6309 ** improvement performance by adding permanent indices that do not
6310 ** need to be reinitialized each time the statement is run.</dd>
 
 
 
 
 
 
 
 
 
6311 ** </dl>
6312 */
6313 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
6314 #define SQLITE_STMTSTATUS_SORT 2
6315 #define SQLITE_STMTSTATUS_AUTOINDEX 3
 
6316
6317 /*
6318 ** CAPI3REF: Custom Page Cache Object
6319 **
6320 ** The sqlite3_pcache type is opaque. It is implemented by
6321
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.0"
111 #define SQLITE_VERSION_NUMBER 3008000
112 #define SQLITE_SOURCE_ID "2013-06-26 22:46:00 93f632152e464a89322a0130adaf9f342411bf7d"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -6306,15 +6306,25 @@
6306 ** <dd>^This is the number of rows inserted into transient indices that
6307 ** were created automatically in order to help joins run faster.
6308 ** A non-zero value in this counter may indicate an opportunity to
6309 ** improvement performance by adding permanent indices that do not
6310 ** need to be reinitialized each time the statement is run.</dd>
6311 **
6312 ** [[SQLITE_STMTSTATUS_VM_STEP]] <dt>SQLITE_STMTSTATUS_VM_STEP</dt>
6313 ** <dd>^This is the number of virtual machine operations executed
6314 ** by the prepared statement if that number is less than or equal
6315 ** to 2147483647. The number of virtual machine operations can be
6316 ** used as a proxy for the total work done by the prepared statement.
6317 ** If the number of virtual machine operations exceeds 2147483647
6318 ** then the value returned by this statement status code is undefined.
6319 ** </dd>
6320 ** </dl>
6321 */
6322 #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1
6323 #define SQLITE_STMTSTATUS_SORT 2
6324 #define SQLITE_STMTSTATUS_AUTOINDEX 3
6325 #define SQLITE_STMTSTATUS_VM_STEP 4
6326
6327 /*
6328 ** CAPI3REF: Custom Page Cache Object
6329 **
6330 ** The sqlite3_pcache type is opaque. It is implemented by
6331

Keyboard Shortcuts

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