Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | When a scalar subquery has a pre-existing "LIMIT X" then change it to "LIMIT X<>0" rather than just "LIMIT 1" so that if X is 0 the limit will still be zero. Ticket [99cd4807dc03f178]. Test cases in TH3. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
82e5dcf5c1d500ed82f398b38fdae0f3 |
User & Date: | drh 2019-09-23 11:55:22.905 |
Original Comment: | When a scalar subquery has a pre-existing "LIMIT X" then change it to "LIMIT X<>0" rather than just "LIMIT 1" so that if X is 0 the limit will still be zero. Ticket [99cd4807dc03f178] |
Context
2019-09-23
| ||
12:38 | Omit the sqlite3IntTokens array constant for a code simplification. (check-in: f907395ef5 user: drh tags: trunk) | |
11:55 | When a scalar subquery has a pre-existing "LIMIT X" then change it to "LIMIT X<>0" rather than just "LIMIT 1" so that if X is 0 the limit will still be zero. Ticket [99cd4807dc03f178]. Test cases in TH3. (check-in: 82e5dcf5c1 user: drh tags: trunk) | |
2019-09-21
| ||
18:49 | Fix a harmless unused variable warning in the test logic. (check-in: d7673a445f user: drh tags: trunk) | |
Changes
Changes to src/expr.c.
︙ | ︙ | |||
2955 2956 2957 2958 2959 2960 2961 | sqlite3VdbeAddOp3(v, OP_Null, 0, dest.iSDParm, dest.iSDParm+nReg-1); VdbeComment((v, "Init subquery result")); }else{ dest.eDest = SRT_Exists; sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm); VdbeComment((v, "Init EXISTS result")); } | < > > > > > > > > > | > > | 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 | sqlite3VdbeAddOp3(v, OP_Null, 0, dest.iSDParm, dest.iSDParm+nReg-1); VdbeComment((v, "Init subquery result")); }else{ dest.eDest = SRT_Exists; sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm); VdbeComment((v, "Init EXISTS result")); } if( pSel->pLimit ){ /* The subquery already has a limit. If the pre-existing limit is X ** then make the new limit X<>0 so that the new limit is either 1 or 0 */ sqlite3 *db = pParse->db; pLimit = sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0); if( pLimit ){ pLimit->affExpr = SQLITE_AFF_NUMERIC; pLimit = sqlite3PExpr(pParse, TK_NE, sqlite3ExprDup(db, pSel->pLimit->pLeft, 0), pLimit); } sqlite3ExprDelete(db, pSel->pLimit->pLeft); pSel->pLimit->pLeft = pLimit; }else{ /* If there is no pre-existing limit add a limit of 1 */ pLimit = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &sqlite3IntTokens[1], 0); pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0); } pSel->iLimit = 0; if( sqlite3Select(pParse, pSel, &dest) ){ return 0; } pExpr->iTable = rReg = dest.iSDParm; |
︙ | ︙ |