mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-05 04:30:38 +03:00
Changes to make the new constant expression factoring logic more general
and more testable. FossilOrigin-Name: d10fb49a92f5f6e93093ae83544e5aec7984361a
This commit is contained in:
22
manifest
22
manifest
@@ -1,5 +1,5 @@
|
||||
C Add\stest\scases\sfor\sINSERT\sINTO\s...\sDEFAULT\sVALUES\son\stables\swith\snumeric\nconstants\sin\sCHECK\sconstraints.
|
||||
D 2013-11-15T16:48:23.550
|
||||
C Changes\sto\smake\sthe\snew\sconstant\sexpression\sfactoring\slogic\smore\sgeneral\nand\smore\stestable.
|
||||
D 2013-11-15T18:15:19.953
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in 8a07bebafbfda0eb67728f4bd15a36201662d1a1
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@@ -169,13 +169,13 @@ F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
|
||||
F src/btree.c 260dedc13119e6fb7930380bd3d294b98362bf5a
|
||||
F src/btree.h bfe0e8c5759b4ec77b0d18390064a6ef3cdffaaf
|
||||
F src/btreeInt.h f038e818bfadf75afbd09819ed93c26a333d39e0
|
||||
F src/build.c 5b744617019f6011ee35a88fe046f3fdf6f85c53
|
||||
F src/build.c 07054d45319953e54a89d726e589a423e9c1c590
|
||||
F src/callback.c f99a8957ba2adf369645fac0db09ad8adcf1caa2
|
||||
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
|
||||
F src/ctime.c ea4b7f3623a0fcb1146e7f245d7410033e86859c
|
||||
F src/date.c 593c744b2623971e45affd0bde347631bdfa4625
|
||||
F src/delete.c ddb92f44595366c4817e576b5f11cad5a915c3ef
|
||||
F src/expr.c eb7eb7fa7848dc4e3b67a2f0bf32f794804ca38a
|
||||
F src/expr.c 016e9dccac357b32d3ef960fa1690c3b17625e1e
|
||||
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
|
||||
F src/fkey.c 78364daed38e26269c53ddb94c515bceac1063c6
|
||||
F src/func.c 96caa9dfd1febf9a4b720de4c43ccfb392a52b73
|
||||
@@ -217,14 +217,14 @@ F src/pragma.c c8d70c47ec8d8ba93575d92e34d30ddff8e9b517
|
||||
F src/prepare.c 359d1a1e9c9bd4488e4dd3a1aaaf2d2ebb9bb768
|
||||
F src/printf.c da9119eb31a187a4b99f60aa4a225141c0ebb74b
|
||||
F src/random.c 0b2dbc37fdfbfa6bd455b091dfcef5bdb32dba68
|
||||
F src/resolve.c fc4673cc49b116e51e7f12de074c0acf8f2388f9
|
||||
F src/resolve.c 6fcceeb653a0020b14491975d567c989e794d408
|
||||
F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
|
||||
F src/select.c 7317406831ecced390edba972818f3c5f82238c0
|
||||
F src/select.c 253cb683e4a05b0b56b0f9c816f3c4a4e5575ebb
|
||||
F src/shell.c b98e74123d6c2e20369607c1da2d23c71db633d9
|
||||
F src/sqlite.h.in 4dedcab5b32358bf7a596badffe7363be1f1a82d
|
||||
F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e
|
||||
F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc
|
||||
F src/sqliteInt.h 11b0dd04b1a2eb86a348fd818c7a63bf015cb0dd
|
||||
F src/sqliteInt.h e16eb6e62146234c05f34a4403a75cf242777ad7
|
||||
F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
|
||||
F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158
|
||||
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
|
||||
@@ -293,7 +293,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd
|
||||
F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4
|
||||
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
|
||||
F src/walker.c e9e593d5bb798c3e67fc3893dfe7055c9e7d8d74
|
||||
F src/where.c 6e7e932ee32a4b2a0e4741880c06fe7a545e0059
|
||||
F src/where.c c7d50e26bad54218d8fa109d3127b9769b9474ab
|
||||
F src/whereInt.h 96a75c61f1d2b9d4a8e4bb17d89deb0cf7cba358
|
||||
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
||||
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
||||
@@ -1139,7 +1139,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
|
||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
|
||||
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
|
||||
P 835be656bb0e83c8108104869166aa9dd850d265
|
||||
R eed45a05b059c0c6c1ee8ceb9dc6b477
|
||||
P 79ec485b548fcfc508c4d5fa32ed0604e1b0c5d9
|
||||
R 81b3d4bed81861e7b07996884febd358
|
||||
U drh
|
||||
Z 845e07c690cff6d1b0e87cc7b8d86036
|
||||
Z 2fbf2a6281b456f08de0df7e1fd4f785
|
||||
|
||||
@@ -1 +1 @@
|
||||
79ec485b548fcfc508c4d5fa32ed0604e1b0c5d9
|
||||
d10fb49a92f5f6e93093ae83544e5aec7984361a
|
||||
@@ -187,7 +187,7 @@ void sqlite3FinishCoding(Parse *pParse){
|
||||
ExprList *pEL = pParse->pConstExpr;
|
||||
pParse->cookieGoto = 0;
|
||||
for(i=0; i<pEL->nExpr; i++){
|
||||
sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].iAlias);
|
||||
sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
28
src/expr.c
28
src/expr.c
@@ -930,8 +930,7 @@ ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
|
||||
pItem->sortOrder = pOldItem->sortOrder;
|
||||
pItem->done = 0;
|
||||
pItem->bSpanIsTab = pOldItem->bSpanIsTab;
|
||||
pItem->iOrderByCol = pOldItem->iOrderByCol;
|
||||
pItem->iAlias = pOldItem->iAlias;
|
||||
pItem->u = pOldItem->u;
|
||||
}
|
||||
return pNew;
|
||||
}
|
||||
@@ -2908,7 +2907,6 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
if( (pX = pExpr->pLeft)!=0 ){
|
||||
tempX = *pX;
|
||||
testcase( pX->op==TK_COLUMN );
|
||||
testcase( pX->op==TK_REGISTER );
|
||||
exprToRegister(&tempX, sqlite3ExprCodeTemp(pParse, pX, ®Free1));
|
||||
testcase( regFree1==0 );
|
||||
opCompare.op = TK_EQ;
|
||||
@@ -2932,7 +2930,6 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
testcase( pTest->op==TK_COLUMN );
|
||||
sqlite3ExprIfFalse(pParse, pTest, nextCase, SQLITE_JUMPIFNULL);
|
||||
testcase( aListelem[i+1].pExpr->op==TK_COLUMN );
|
||||
testcase( aListelem[i+1].pExpr->op==TK_REGISTER );
|
||||
sqlite3ExprCode(pParse, aListelem[i+1].pExpr, target);
|
||||
sqlite3VdbeAddOp2(v, OP_Goto, 0, endLabel);
|
||||
sqlite3ExprCachePop(pParse, 1);
|
||||
@@ -3000,7 +2997,6 @@ int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
|
||||
int r2;
|
||||
pExpr = sqlite3ExprSkipCollate(pExpr);
|
||||
if( pParse->cookieGoto>0
|
||||
&& pParse->nMem<32768
|
||||
&& pExpr->op!=TK_REGISTER
|
||||
&& sqlite3ExprIsConstantNotJoin(pExpr)
|
||||
){
|
||||
@@ -3010,14 +3006,14 @@ int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
|
||||
if( p ){
|
||||
for(i=0; i<p->nExpr; i++){
|
||||
if( sqlite3ExprCompare(p->a[i].pExpr, pExpr, -1)==0 ){
|
||||
return p->a[i].iAlias;
|
||||
return p->a[i].u.iConstExprReg;
|
||||
}
|
||||
}
|
||||
}
|
||||
p = sqlite3ExprListAppend(pParse, p, sqlite3ExprDup(pParse->db, pExpr, 0));
|
||||
pParse->pConstExpr = p;
|
||||
r2 = ++pParse->nMem;
|
||||
if( p ) p->a[p->nExpr-1].iAlias = r2;
|
||||
if( p ) p->a[p->nExpr-1].u.iConstExprReg = r2;
|
||||
}else{
|
||||
int r1 = sqlite3GetTempReg(pParse);
|
||||
r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
|
||||
@@ -3069,12 +3065,13 @@ int sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){
|
||||
int inReg;
|
||||
inReg = sqlite3ExprCode(pParse, pExpr, target);
|
||||
assert( target>0 );
|
||||
/* This routine is called for terms to INSERT or UPDATE. And the only
|
||||
** other place where expressions can be converted into TK_REGISTER is
|
||||
** in WHERE clause processing. So as currently implemented, there is
|
||||
** no way for a TK_REGISTER to exist here. But it seems prudent to
|
||||
** keep the ALWAYS() in case the conditions above change with future
|
||||
** modifications or enhancements. */
|
||||
/* The only place, other than this routine, where expressions can be
|
||||
** converted to TK_REGISTER is internal subexpressions in BETWEEN and
|
||||
** CASE operators. Neither ever calls this routine. And this routine
|
||||
** is never called twice on the same expression. Hence it is impossible
|
||||
** for the input to this routine to already be a register. Nevertheless,
|
||||
** it seems prudent to keep the ALWAYS() in case the conditions above
|
||||
** change with future modifications or enhancements. */
|
||||
if( ALWAYS(pExpr->op!=TK_REGISTER) ){
|
||||
int iMem;
|
||||
iMem = ++pParse->nMem;
|
||||
@@ -3745,7 +3742,7 @@ int sqlite3ExprCompare(Expr *pA, Expr *pB, int iTab){
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
if( pA->op!=pB->op /*&& (pA->op!=TK_REGISTER || pA->op2!=pB->op)*/ ){
|
||||
if( pA->op!=pB->op ){
|
||||
if( pA->op==TK_COLLATE && sqlite3ExprCompare(pA->pLeft, pB, iTab)<2 ){
|
||||
return 1;
|
||||
}
|
||||
@@ -3760,8 +3757,6 @@ int sqlite3ExprCompare(Expr *pA, Expr *pB, int iTab){
|
||||
}
|
||||
}
|
||||
if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
|
||||
testcase( combinedFlags & EP_TokenOnly );
|
||||
testcase( combinedFlags & EP_Reduced );
|
||||
if( (combinedFlags & EP_TokenOnly)==0 ){
|
||||
if( combinedFlags & EP_xIsSelect ) return 2;
|
||||
if( sqlite3ExprCompare(pA->pLeft, pB->pLeft, iTab) ) return 2;
|
||||
@@ -3770,7 +3765,6 @@ int sqlite3ExprCompare(Expr *pA, Expr *pB, int iTab){
|
||||
if( (combinedFlags & EP_Reduced)==0 ){
|
||||
if( pA->iColumn!=pB->iColumn ) return 2;
|
||||
if( pA->iTable!=pB->iTable
|
||||
&& pA->op!=TK_REGISTER
|
||||
&& (pA->iTable!=iTab || pB->iTable>=0) ) return 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,10 +108,10 @@ static void resolveAlias(
|
||||
pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
|
||||
if( pDup==0 ) return;
|
||||
ExprSetProperty(pDup, EP_Skip);
|
||||
if( pEList->a[iCol].iAlias==0 ){
|
||||
pEList->a[iCol].iAlias = (u16)(++pParse->nAlias);
|
||||
if( pEList->a[iCol].u.x.iAlias==0 ){
|
||||
pEList->a[iCol].u.x.iAlias = (u16)(++pParse->nAlias);
|
||||
}
|
||||
pDup->iTable = pEList->a[iCol].iAlias;
|
||||
pDup->iTable = pEList->a[iCol].u.x.iAlias;
|
||||
}
|
||||
if( pExpr->op==TK_COLLATE ){
|
||||
pDup = sqlite3ExprAddCollateString(pParse, pDup, pExpr->u.zToken);
|
||||
@@ -976,7 +976,7 @@ static int resolveCompoundOrderBy(
|
||||
pItem->pExpr->pLeft = pNew;
|
||||
}
|
||||
sqlite3ExprDelete(db, pE);
|
||||
pItem->iOrderByCol = (u16)iCol;
|
||||
pItem->u.x.iOrderByCol = (u16)iCol;
|
||||
pItem->done = 1;
|
||||
}else{
|
||||
moreToDo = 1;
|
||||
@@ -997,8 +997,8 @@ static int resolveCompoundOrderBy(
|
||||
/*
|
||||
** Check every term in the ORDER BY or GROUP BY clause pOrderBy of
|
||||
** the SELECT statement pSelect. If any term is reference to a
|
||||
** result set expression (as determined by the ExprList.a.iOrderByCol field)
|
||||
** then convert that term into a copy of the corresponding result set
|
||||
** result set expression (as determined by the ExprList.a.u.x.iOrderByCol
|
||||
** field) then convert that term into a copy of the corresponding result set
|
||||
** column.
|
||||
**
|
||||
** If any errors are detected, add an error message to pParse and
|
||||
@@ -1025,12 +1025,12 @@ int sqlite3ResolveOrderGroupBy(
|
||||
pEList = pSelect->pEList;
|
||||
assert( pEList!=0 ); /* sqlite3SelectNew() guarantees this */
|
||||
for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
|
||||
if( pItem->iOrderByCol ){
|
||||
if( pItem->iOrderByCol>pEList->nExpr ){
|
||||
if( pItem->u.x.iOrderByCol ){
|
||||
if( pItem->u.x.iOrderByCol>pEList->nExpr ){
|
||||
resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr);
|
||||
return 1;
|
||||
}
|
||||
resolveAlias(pParse, pEList, pItem->iOrderByCol-1, pItem->pExpr, zType,0);
|
||||
resolveAlias(pParse, pEList, pItem->u.x.iOrderByCol-1, pItem->pExpr, zType,0);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -1079,7 +1079,7 @@ static int resolveOrderGroupBy(
|
||||
** a copy of the iCol-th result-set column. The subsequent call to
|
||||
** sqlite3ResolveOrderGroupBy() will convert the expression to a
|
||||
** copy of the iCol-th result-set expression. */
|
||||
pItem->iOrderByCol = (u16)iCol;
|
||||
pItem->u.x.iOrderByCol = (u16)iCol;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -1091,18 +1091,18 @@ static int resolveOrderGroupBy(
|
||||
resolveOutOfRangeError(pParse, zType, i+1, nResult);
|
||||
return 1;
|
||||
}
|
||||
pItem->iOrderByCol = (u16)iCol;
|
||||
pItem->u.x.iOrderByCol = (u16)iCol;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Otherwise, treat the ORDER BY term as an ordinary expression */
|
||||
pItem->iOrderByCol = 0;
|
||||
pItem->u.x.iOrderByCol = 0;
|
||||
if( sqlite3ResolveExprNames(pNC, pE) ){
|
||||
return 1;
|
||||
}
|
||||
for(j=0; j<pSelect->pEList->nExpr; j++){
|
||||
if( sqlite3ExprCompare(pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
|
||||
pItem->iOrderByCol = j+1;
|
||||
pItem->u.x.iOrderByCol = j+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
17
src/select.c
17
src/select.c
@@ -2372,8 +2372,8 @@ static int multiSelectOrderBy(
|
||||
for(i=1; db->mallocFailed==0 && i<=p->pEList->nExpr; i++){
|
||||
struct ExprList_item *pItem;
|
||||
for(j=0, pItem=pOrderBy->a; j<nOrderBy; j++, pItem++){
|
||||
assert( pItem->iOrderByCol>0 );
|
||||
if( pItem->iOrderByCol==i ) break;
|
||||
assert( pItem->u.x.iOrderByCol>0 );
|
||||
if( pItem->u.x.iOrderByCol==i ) break;
|
||||
}
|
||||
if( j==nOrderBy ){
|
||||
Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
|
||||
@@ -2381,7 +2381,7 @@ static int multiSelectOrderBy(
|
||||
pNew->flags |= EP_IntValue;
|
||||
pNew->u.iValue = i;
|
||||
pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
|
||||
if( pOrderBy ) pOrderBy->a[nOrderBy++].iOrderByCol = (u16)i;
|
||||
if( pOrderBy ) pOrderBy->a[nOrderBy++].u.x.iOrderByCol = (u16)i;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2397,8 +2397,9 @@ static int multiSelectOrderBy(
|
||||
if( aPermute ){
|
||||
struct ExprList_item *pItem;
|
||||
for(i=0, pItem=pOrderBy->a; i<nOrderBy; i++, pItem++){
|
||||
assert( pItem->iOrderByCol>0 && pItem->iOrderByCol<=p->pEList->nExpr );
|
||||
aPermute[i] = pItem->iOrderByCol - 1;
|
||||
assert( pItem->u.x.iOrderByCol>0
|
||||
&& pItem->u.x.iOrderByCol<=p->pEList->nExpr );
|
||||
aPermute[i] = pItem->u.x.iOrderByCol - 1;
|
||||
}
|
||||
pKeyMerge = sqlite3KeyInfoAlloc(db, nOrderBy, 1);
|
||||
if( pKeyMerge ){
|
||||
@@ -2978,7 +2979,7 @@ static int flattenSubquery(
|
||||
if( p->pOrderBy ){
|
||||
int ii;
|
||||
for(ii=0; ii<p->pOrderBy->nExpr; ii++){
|
||||
if( p->pOrderBy->a[ii].iOrderByCol==0 ) return 0;
|
||||
if( p->pOrderBy->a[ii].u.x.iOrderByCol==0 ) return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4385,10 +4386,10 @@ int sqlite3Select(
|
||||
struct ExprList_item *pItem; /* For looping over expression in a list */
|
||||
|
||||
for(k=p->pEList->nExpr, pItem=p->pEList->a; k>0; k--, pItem++){
|
||||
pItem->iAlias = 0;
|
||||
pItem->u.x.iAlias = 0;
|
||||
}
|
||||
for(k=pGroupBy->nExpr, pItem=pGroupBy->a; k>0; k--, pItem++){
|
||||
pItem->iAlias = 0;
|
||||
pItem->u.x.iAlias = 0;
|
||||
}
|
||||
if( p->nSelectRow>100 ) p->nSelectRow = 100;
|
||||
}else{
|
||||
|
||||
@@ -1900,8 +1900,13 @@ struct ExprList {
|
||||
u8 sortOrder; /* 1 for DESC or 0 for ASC */
|
||||
unsigned done :1; /* A flag to indicate when processing is finished */
|
||||
unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
|
||||
union {
|
||||
struct {
|
||||
u16 iOrderByCol; /* For ORDER BY, column number in result set */
|
||||
u16 iAlias; /* Index into Parse.aAlias[] for zName */
|
||||
} x;
|
||||
int iConstExprReg; /* Register in which Expr value is cached */
|
||||
} u;
|
||||
} *a; /* Alloc a power of two greater or equal to nExpr */
|
||||
};
|
||||
|
||||
|
||||
@@ -669,9 +669,6 @@ static int isLikeOrGlob(
|
||||
|
||||
pRight = pList->a[0].pExpr;
|
||||
op = pRight->op;
|
||||
if( op==TK_REGISTER ){
|
||||
op = pRight->op2;
|
||||
}
|
||||
if( op==TK_VARIABLE ){
|
||||
Vdbe *pReprepare = pParse->pReprepare;
|
||||
int iCol = pRight->iColumn;
|
||||
|
||||
Reference in New Issue
Block a user