Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | An optimization that converts "a IN (b)" into "a==b". Seems to work, but needs additional test cases. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | degenerate_IN |
Files: | files | file ages | folders |
SHA1: |
8b4c3c5e506267c18550063cb9bd9351 |
User & Date: | drh 2012-10-16 21:08:03.250 |
Context
2012-10-16
| ||
21:08 | An optimization that converts "a IN (b)" into "a==b". Seems to work, but needs additional test cases. (Leaf check-in: 8b4c3c5e50 user: drh tags: degenerate_IN) | |
2012-10-15
| ||
20:28 | Correct comments and enhance readability of the mkvsix tool. (check-in: 2c3af657fe user: mistachkin tags: trunk) | |
Changes
Changes to src/parse.y.
︙ | ︙ | |||
994 995 996 997 998 999 1000 | A.zEnd = Y.zEnd; } %ifndef SQLITE_OMIT_SUBQUERY %type in_op {int} in_op(A) ::= IN. {A = 0;} in_op(A) ::= NOT IN. {A = 1;} expr(A) ::= expr(X) in_op(N) LP exprlist(Y) RP(E). [IN] { | > > | | > > > > > > > > > > | | | 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 | A.zEnd = Y.zEnd; } %ifndef SQLITE_OMIT_SUBQUERY %type in_op {int} in_op(A) ::= IN. {A = 0;} in_op(A) ::= NOT IN. {A = 1;} expr(A) ::= expr(X) in_op(N) LP exprlist(Y) RP(E). [IN] { sqlite3 *db = pParse->db; ExprList *pY = Y; if( pY==0 ){ /* Expressions of the form ** ** expr1 IN () ** expr1 NOT IN () ** ** simplify to constants 0 (false) and 1 (true), respectively, ** regardless of the value of expr1. */ A.pExpr = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &sqlite3IntTokens[N]); sqlite3ExprDelete(db, X.pExpr); }else if( pY->nExpr==1 ){ /* If the RHS of the IN operator has a single term, simplify as follows: ** ** expr1 IN (Y) --> expr1 = Y ** expr1 NOT IN (Y) --> expr1 <> Y */ assert( TK_EQ==TK_NE+1 ); A.pExpr = sqlite3PExpr(pParse, TK_EQ-N, X.pExpr, pY->a[0].pExpr, 0); pY->a[0].pExpr = 0; sqlite3ExprListDelete(db, pY); }else{ A.pExpr = sqlite3PExpr(pParse, TK_IN, X.pExpr, 0, 0); if( A.pExpr ){ A.pExpr->x.pList = pY; sqlite3ExprSetHeight(pParse, A.pExpr); }else{ sqlite3ExprListDelete(pParse->db, pY); } if( N ) A.pExpr = sqlite3PExpr(pParse, TK_NOT, A.pExpr, 0, 0); } A.zStart = X.zStart; A.zEnd = &E.z[E.n]; } expr(A) ::= LP(B) select(X) RP(E). { |
︙ | ︙ |