From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 890FD2E41A for ; Tue, 17 Apr 2018 16:36:23 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ohlUhO0m_szZ for ; Tue, 17 Apr 2018 16:36:23 -0400 (EDT) Received: from smtp34.i.mail.ru (smtp34.i.mail.ru [94.100.177.94]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 93CEE2D9FF for ; Tue, 17 Apr 2018 16:36:22 -0400 (EDT) From: Vladislav Shpilevoy Subject: [tarantool-patches] [PATCH 2/2] sql: remove OMIT_SUBQUERY definition Date: Tue, 17 Apr 2018 23:36:19 +0300 Message-Id: <6f9dacb524d25cdc8c590b83976a1f0934f4ee29.1523997306.git.v.shpilevoy@tarantool.org> In-Reply-To: References: In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: korablev@tarantool.org --- extra/mkkeywordhash.c | 6 +- src/box/sql/delete.c | 3 +- src/box/sql/expr.c | 54 +----- src/box/sql/parse.c | 446 +++++++++++++++++++++++----------------------- src/box/sql/parse.y | 206 +++++++++++---------- src/box/sql/resolve.c | 7 +- src/box/sql/select.c | 27 --- src/box/sql/sqliteInt.h | 6 +- src/box/sql/treeview.c | 3 - src/box/sql/wherecode.c | 7 +- src/box/sql/whereexpr.c | 6 +- test/sql-tap/in1.test.lua | 3 +- 12 files changed, 338 insertions(+), 436 deletions(-) diff --git a/extra/mkkeywordhash.c b/extra/mkkeywordhash.c index 63d63d2f0..6166119e2 100644 --- a/extra/mkkeywordhash.c +++ b/extra/mkkeywordhash.c @@ -100,11 +100,7 @@ struct Keyword { #else # define REINDEX 0x00000800 #endif -#ifdef SQLITE_OMIT_SUBQUERY -# define SUBQUERY 0 -#else -# define SUBQUERY 0x00001000 -#endif +#define SUBQUERY 0x00001000 #ifdef SQLITE_OMIT_TRIGGER # define TRIGGER 0 #else diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c index bb4338f47..3f74b933b 100644 --- a/src/box/sql/delete.c +++ b/src/box/sql/delete.c @@ -127,7 +127,7 @@ sqlite3MaterializeView(Parse * pParse, /* Parsing context */ } #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */ -#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) +#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) /* * Generate an expression tree to implement the WHERE, ORDER BY, * and LIMIT/OFFSET portion of DELETE and UPDATE statements. @@ -216,7 +216,6 @@ sqlite3LimitWhere(Parse * pParse, /* The parser context */ return 0; } #endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) */ - /* && !defined(SQLITE_OMIT_SUBQUERY) */ /* * Generate code for a DELETE FROM statement. diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c index 1784b1bcf..6d9a91e20 100644 --- a/src/box/sql/expr.c +++ b/src/box/sql/expr.c @@ -420,7 +420,6 @@ sqlite3ExprVectorSize(Expr * pExpr) } } -#ifndef SQLITE_OMIT_SUBQUERY /* * Return a pointer to a subexpression of pVector that is the i-th * column of the vector (numbered starting with 0). The caller must @@ -450,9 +449,7 @@ sqlite3VectorFieldSubexpr(Expr * pVector, int i) } return pVector; } -#endif /* !defined(SQLITE_OMIT_SUBQUERY) */ -#ifndef SQLITE_OMIT_SUBQUERY /* * Compute and return a new Expr object which when passed to * sqlite3ExprCode() will generate all necessary code to compute @@ -512,7 +509,6 @@ sqlite3ExprForVectorField(Parse * pParse, /* Parsing context */ } return pRet; } -#endif /* !define(SQLITE_OMIT_SUBQUERY) */ /* * If expression pExpr is of type TK_SELECT, generate code to evaluate @@ -525,13 +521,10 @@ sqlite3ExprForVectorField(Parse * pParse, /* Parsing context */ static int exprCodeSubselect(Parse * pParse, Expr * pExpr) { - int reg = 0; -#ifndef SQLITE_OMIT_SUBQUERY - if (pExpr->op == TK_SELECT) { - reg = sqlite3CodeSubselect(pParse, pExpr, 0); - } -#endif - return reg; + if (pExpr->op == TK_SELECT) + return sqlite3CodeSubselect(pParse, pExpr, 0); + else + return 0; } /* @@ -1537,8 +1530,6 @@ sqlite3ExprListDup(sqlite3 * db, ExprList * p, int flags) * sqlite3SelectDup(), can be called. sqlite3SelectDup() is sometimes * called with a NULL argument. */ -#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER) \ - || !defined(SQLITE_OMIT_SUBQUERY) SrcList * sqlite3SrcListDup(sqlite3 * db, SrcList * p, int flags) { @@ -1651,14 +1642,6 @@ sqlite3SelectDup(sqlite3 * db, Select * p, int flags) sqlite3SelectSetName(pNew, p->zSelName); return pNew; } -#else -Select * -sqlite3SelectDup(sqlite3 * db, Select * p, int flags) -{ - assert(p == 0); - return 0; -} -#endif /* * Add a new element to the end of an expression list. If pList is @@ -2225,7 +2208,6 @@ sqlite3ExprNeedsNoAffinityChange(const Expr * p, char aff) * or if the SELECT statement needs to be manifested into a transient * table, then return NULL. */ -#ifndef SQLITE_OMIT_SUBQUERY static Select * isCandidateForInOpt(Expr * pX) { @@ -2274,9 +2256,7 @@ isCandidateForInOpt(Expr * pX) } return p; } -#endif /* SQLITE_OMIT_SUBQUERY */ -#ifndef SQLITE_OMIT_SUBQUERY /* * Generate code that checks the left-most column of index table iCur to see if * it contains any NULL entries. Cause the register at regHasNull to be set @@ -2299,9 +2279,7 @@ sqlite3SetHasNullFlag(Vdbe * v, int iCur, int iCol, int regHasNull) VdbeComment((v, "first_entry_in(%d)", iCur)); sqlite3VdbeJumpHere(v, addr1); } -#endif -#ifndef SQLITE_OMIT_SUBQUERY /* * The argument is an IN operator with a list (not a subquery) on the * right-hand side. Return TRUE if that list is constant. @@ -2318,7 +2296,6 @@ sqlite3InRhsIsConstant(Expr * pIn) pIn->pLeft = pLHS; return res; } -#endif /* * This function is used by the implementation of the IN (...) operator. @@ -2400,7 +2377,6 @@ sqlite3InRhsIsConstant(Expr * pIn) * * then aiMap[] is populated with {2, 0, 1}. */ -#ifndef SQLITE_OMIT_SUBQUERY int sqlite3FindInIndex(Parse * pParse, /* Parsing context */ Expr * pX, /* The right-hand side (RHS) of the IN operator */ @@ -2638,9 +2614,7 @@ sqlite3FindInIndex(Parse * pParse, /* Parsing context */ } return eType; } -#endif -#ifndef SQLITE_OMIT_SUBQUERY /* * Argument pExpr is an (?, ?...) IN(...) expression. This * function allocates and returns a nul-terminated string containing @@ -2676,9 +2650,7 @@ exprINAffinity(Parse * pParse, Expr * pExpr) } return zRet; } -#endif -#ifndef SQLITE_OMIT_SUBQUERY /* * Load the Parse object passed as the first argument with an error * message of the form: @@ -2691,7 +2663,6 @@ sqlite3SubselectError(Parse * pParse, int nActual, int nExpect) const char *zFmt = "sub-select returns %d columns - expected %d"; sqlite3ErrorMsg(pParse, zFmt, nActual, nExpect); } -#endif /* * Expression pExpr is a vector that has been used in a context where @@ -2707,13 +2678,10 @@ sqlite3SubselectError(Parse * pParse, int nActual, int nExpect) void sqlite3VectorErrorMsg(Parse * pParse, Expr * pExpr) { -#ifndef SQLITE_OMIT_SUBQUERY if (pExpr->flags & EP_xIsSelect) { sqlite3SubselectError(pParse, pExpr->x.pSelect->pEList->nExpr, 1); - } else -#endif - { + } else { sqlite3ErrorMsg(pParse, "row value misused"); } } @@ -2741,7 +2709,6 @@ sqlite3VectorErrorMsg(Parse * pParse, Expr * pExpr) * array of registers and the return value is the register of the left-most * result column. Return 0 for IN operators or if an error occurs. */ -#ifndef SQLITE_OMIT_SUBQUERY int sqlite3CodeSubselect(Parse * pParse, /* Parsing context */ Expr * pExpr, /* The IN, SELECT, or EXISTS operator */ @@ -2986,9 +2953,7 @@ sqlite3CodeSubselect(Parse * pParse, /* Parsing context */ return rReg; } -#endif /* SQLITE_OMIT_SUBQUERY */ -#ifndef SQLITE_OMIT_SUBQUERY /* * Expr pIn is an IN(...) expression. This function checks that the * sub-select on the RHS of the IN() operator has the same number of @@ -3012,9 +2977,7 @@ sqlite3ExprCheckIN(Parse * pParse, Expr * pIn) } return 0; } -#endif -#ifndef SQLITE_OMIT_SUBQUERY /* * Generate code for an IN expression. * @@ -3309,7 +3272,6 @@ sqlite3ExprCodeIN(Parse * pParse, /* Parsing and code generating context */ sqlite3DbFree(pParse->db, aiMap); sqlite3DbFree(pParse->db, zAff); } -#endif /* SQLITE_OMIT_SUBQUERY */ #ifndef SQLITE_OMIT_FLOATING_POINT /* @@ -4195,7 +4157,6 @@ sqlite3ExprCodeTarget(Parse * pParse, Expr * pExpr, int target) } return target; } -#ifndef SQLITE_OMIT_SUBQUERY case TK_EXISTS: case TK_SELECT:{ int nCol; @@ -4240,7 +4201,6 @@ sqlite3ExprCodeTarget(Parse * pParse, Expr * pExpr, int target) sqlite3VdbeResolveLabel(v, destIfNull); return target; } -#endif /* SQLITE_OMIT_SUBQUERY */ /* * x BETWEEN y AND z @@ -4892,7 +4852,6 @@ sqlite3ExprIfTrue(Parse * pParse, Expr * pExpr, int dest, int jumpIfNull) jumpIfNull); break; } -#ifndef SQLITE_OMIT_SUBQUERY case TK_IN:{ int destIfFalse = sqlite3VdbeMakeLabel(v); int destIfNull = jumpIfNull ? dest : destIfFalse; @@ -4902,7 +4861,6 @@ sqlite3ExprIfTrue(Parse * pParse, Expr * pExpr, int dest, int jumpIfNull) sqlite3VdbeResolveLabel(v, destIfFalse); break; } -#endif default:{ default_expr: if (exprAlwaysTrue(pExpr)) { @@ -5077,7 +5035,6 @@ sqlite3ExprIfFalse(Parse * pParse, Expr * pExpr, int dest, int jumpIfNull) jumpIfNull); break; } -#ifndef SQLITE_OMIT_SUBQUERY case TK_IN:{ if (jumpIfNull) { sqlite3ExprCodeIN(pParse, pExpr, dest, dest); @@ -5089,7 +5046,6 @@ sqlite3ExprIfFalse(Parse * pParse, Expr * pExpr, int dest, int jumpIfNull) } break; } -#endif default:{ default_expr: if (exprAlwaysFalse(pExpr)) { diff --git a/src/box/sql/parse.c b/src/box/sql/parse.c index dcf0fc689..5c0f0ead0 100644 --- a/src/box/sql/parse.c +++ b/src/box/sql/parse.c @@ -104,7 +104,7 @@ static void disableLookaside(Parse *pParse){ } } } -#line 842 "parse.y" +#line 840 "parse.y" /* This is a utility routine used to set the ExprSpan.zStart and ** ExprSpan.zEnd values of pOut so that the span covers the complete @@ -140,7 +140,7 @@ static void disableLookaside(Parse *pParse){ pOut->zStart = t.z; pOut->zEnd = &t.z[t.n]; } -#line 950 "parse.y" +#line 948 "parse.y" /* This routine constructs a binary expression node out of two ExprSpan ** objects and uses the result to populate a new ExprSpan object. @@ -163,7 +163,7 @@ static void disableLookaside(Parse *pParse){ pSpan->pExpr = sqlite3PExpr(pParse, TK_NOT, pSpan->pExpr, 0); } } -#line 1024 "parse.y" +#line 1022 "parse.y" /* Construct an expression node for a unary postfix operator */ @@ -176,7 +176,7 @@ static void disableLookaside(Parse *pParse){ pOperand->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0); pOperand->zEnd = &pPostOp->z[pPostOp->n]; } -#line 1041 "parse.y" +#line 1039 "parse.y" /* A routine to convert a binary TK_IS or TK_ISNOT expression into a ** unary TK_ISNULL or TK_NOTNULL expression. */ @@ -188,7 +188,7 @@ static void disableLookaside(Parse *pParse){ pA->pRight = 0; } } -#line 1069 "parse.y" +#line 1067 "parse.y" /* Construct an expression node for a unary prefix operator */ @@ -203,7 +203,7 @@ static void disableLookaside(Parse *pParse){ pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0); pOut->zEnd = pOperand->zEnd; } -#line 1274 "parse.y" +#line 1268 "parse.y" /* Add a single new term to an ExprList that is used to store a ** list of identifiers. Report an error if the ID list contains @@ -1471,7 +1471,7 @@ sqlite3SelectDelete(pParse->db, (yypminor->yy279)); case 160: /* term */ case 161: /* expr */ { -#line 840 "parse.y" +#line 838 "parse.y" sql_expr_free(pParse->db, (yypminor->yy162).pExpr, false); #line 1477 "parse.c" } @@ -1489,7 +1489,7 @@ sql_expr_free(pParse->db, (yypminor->yy162).pExpr, false); case 213: /* paren_exprlist */ case 215: /* case_exprlist */ { -#line 1272 "parse.y" +#line 1266 "parse.y" sqlite3ExprListDelete(pParse->db, (yypminor->yy382)); #line 1495 "parse.c" } @@ -1499,7 +1499,7 @@ sqlite3ExprListDelete(pParse->db, (yypminor->yy382)); case 199: /* seltablist */ case 200: /* stl_prefix */ { -#line 624 "parse.y" +#line 622 "parse.y" sqlite3SrcListDelete(pParse->db, (yypminor->yy387)); #line 1505 "parse.c" } @@ -1507,7 +1507,7 @@ sqlite3SrcListDelete(pParse->db, (yypminor->yy387)); case 184: /* with */ case 229: /* wqlist */ { -#line 1523 "parse.y" +#line 1517 "parse.y" sqlite3WithDelete(pParse->db, (yypminor->yy151)); #line 1513 "parse.c" } @@ -1519,7 +1519,7 @@ sqlite3WithDelete(pParse->db, (yypminor->yy151)); case 216: /* case_else */ case 225: /* when_clause */ { -#line 749 "parse.y" +#line 747 "parse.y" sql_expr_free(pParse->db, (yypminor->yy362), false); #line 1525 "parse.c" } @@ -1528,7 +1528,7 @@ sql_expr_free(pParse->db, (yypminor->yy362), false); case 206: /* idlist */ case 209: /* idlist_opt */ { -#line 661 "parse.y" +#line 659 "parse.y" sqlite3IdListDelete(pParse->db, (yypminor->yy40)); #line 1534 "parse.c" } @@ -1536,14 +1536,14 @@ sqlite3IdListDelete(pParse->db, (yypminor->yy40)); case 221: /* trigger_cmd_list */ case 226: /* trigger_cmd */ { -#line 1396 "parse.y" +#line 1390 "parse.y" sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy427)); #line 1542 "parse.c" } break; case 223: /* trigger_event */ { -#line 1382 "parse.y" +#line 1376 "parse.y" sqlite3IdListDelete(pParse->db, (yypminor->yy10).b); #line 1549 "parse.c" } @@ -2756,59 +2756,59 @@ static void yy_reduce( #line 2757 "parse.c" break; case 99: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */ -#line 596 "parse.y" +#line 595 "parse.y" { - yymsp[-6].minor.yy387 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy387,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy279,yymsp[-1].minor.yy362,yymsp[0].minor.yy40); - } + yymsp[-6].minor.yy387 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy387,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy279,yymsp[-1].minor.yy362,yymsp[0].minor.yy40); +} #line 2764 "parse.c" break; case 100: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */ -#line 600 "parse.y" -{ - if( yymsp[-6].minor.yy387==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy362==0 && yymsp[0].minor.yy40==0 ){ - yymsp[-6].minor.yy387 = yymsp[-4].minor.yy387; - }else if( yymsp[-4].minor.yy387->nSrc==1 ){ - yymsp[-6].minor.yy387 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy387,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy362,yymsp[0].minor.yy40); - if( yymsp[-6].minor.yy387 ){ - struct SrcList_item *pNew = &yymsp[-6].minor.yy387->a[yymsp[-6].minor.yy387->nSrc-1]; - struct SrcList_item *pOld = yymsp[-4].minor.yy387->a; - pNew->zName = pOld->zName; - pNew->pSelect = pOld->pSelect; - pOld->zName = 0; - pOld->pSelect = 0; - } - sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy387); - }else{ - Select *pSubquery; - sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy387); - pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy387,0,0,0,0,SF_NestedFrom,0,0); - yymsp[-6].minor.yy387 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy387,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy362,yymsp[0].minor.yy40); +#line 599 "parse.y" +{ + if( yymsp[-6].minor.yy387==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy362==0 && yymsp[0].minor.yy40==0 ){ + yymsp[-6].minor.yy387 = yymsp[-4].minor.yy387; + }else if( yymsp[-4].minor.yy387->nSrc==1 ){ + yymsp[-6].minor.yy387 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy387,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy362,yymsp[0].minor.yy40); + if( yymsp[-6].minor.yy387 ){ + struct SrcList_item *pNew = &yymsp[-6].minor.yy387->a[yymsp[-6].minor.yy387->nSrc-1]; + struct SrcList_item *pOld = yymsp[-4].minor.yy387->a; + pNew->zName = pOld->zName; + pNew->pSelect = pOld->pSelect; + pOld->zName = 0; + pOld->pSelect = 0; } + sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy387); + }else{ + Select *pSubquery; + sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy387); + pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy387,0,0,0,0,SF_NestedFrom,0,0); + yymsp[-6].minor.yy387 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy387,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy362,yymsp[0].minor.yy40); } +} #line 2789 "parse.c" break; case 101: /* fullname ::= nm */ -#line 626 "parse.y" +#line 624 "parse.y" {yymsp[0].minor.yy387 = sqlite3SrcListAppend(pParse->db,0,&yymsp[0].minor.yy0); /*A-overwrites-X*/} #line 2794 "parse.c" break; case 102: /* joinop ::= COMMA|JOIN */ -#line 632 "parse.y" +#line 630 "parse.y" { yymsp[0].minor.yy52 = JT_INNER; } #line 2799 "parse.c" break; case 103: /* joinop ::= JOIN_KW JOIN */ -#line 634 "parse.y" +#line 632 "parse.y" {yymsp[-1].minor.yy52 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/} #line 2804 "parse.c" break; case 104: /* joinop ::= JOIN_KW join_nm JOIN */ -#line 636 "parse.y" +#line 634 "parse.y" {yymsp[-2].minor.yy52 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/} #line 2809 "parse.c" break; case 105: /* joinop ::= JOIN_KW join_nm join_nm JOIN */ -#line 638 "parse.y" +#line 636 "parse.y" {yymsp[-3].minor.yy52 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/} #line 2814 "parse.c" break; @@ -2816,7 +2816,7 @@ static void yy_reduce( case 123: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==123); case 130: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==130); case 192: /* case_else ::= ELSE expr */ yytestcase(yyruleno==192); -#line 642 "parse.y" +#line 640 "parse.y" {yymsp[-1].minor.yy362 = yymsp[0].minor.yy162.pExpr;} #line 2822 "parse.c" break; @@ -2825,44 +2825,44 @@ static void yy_reduce( case 129: /* where_opt ::= */ yytestcase(yyruleno==129); case 193: /* case_else ::= */ yytestcase(yyruleno==193); case 195: /* case_operand ::= */ yytestcase(yyruleno==195); -#line 643 "parse.y" +#line 641 "parse.y" {yymsp[1].minor.yy362 = 0;} #line 2831 "parse.c" break; case 108: /* indexed_opt ::= */ -#line 656 "parse.y" +#line 654 "parse.y" {yymsp[1].minor.yy0.z=0; yymsp[1].minor.yy0.n=0;} #line 2836 "parse.c" break; case 109: /* indexed_opt ::= INDEXED BY nm */ -#line 657 "parse.y" +#line 655 "parse.y" {yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;} #line 2841 "parse.c" break; case 110: /* indexed_opt ::= NOT INDEXED */ -#line 658 "parse.y" +#line 656 "parse.y" {yymsp[-1].minor.yy0.z=0; yymsp[-1].minor.yy0.n=1;} #line 2846 "parse.c" break; case 111: /* using_opt ::= USING LP idlist RP */ -#line 662 "parse.y" +#line 660 "parse.y" {yymsp[-3].minor.yy40 = yymsp[-1].minor.yy40;} #line 2851 "parse.c" break; case 112: /* using_opt ::= */ case 140: /* idlist_opt ::= */ yytestcase(yyruleno==140); -#line 663 "parse.y" +#line 661 "parse.y" {yymsp[1].minor.yy40 = 0;} #line 2857 "parse.c" break; case 114: /* orderby_opt ::= ORDER BY sortlist */ case 121: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==121); -#line 677 "parse.y" +#line 675 "parse.y" {yymsp[-2].minor.yy382 = yymsp[0].minor.yy382;} #line 2863 "parse.c" break; case 115: /* sortlist ::= sortlist COMMA expr sortorder */ -#line 678 "parse.y" +#line 676 "parse.y" { yymsp[-3].minor.yy382 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy382,yymsp[-1].minor.yy162.pExpr); sqlite3ExprListSetSortOrder(yymsp[-3].minor.yy382,yymsp[0].minor.yy52); @@ -2870,7 +2870,7 @@ static void yy_reduce( #line 2871 "parse.c" break; case 116: /* sortlist ::= expr sortorder */ -#line 682 "parse.y" +#line 680 "parse.y" { yymsp[-1].minor.yy382 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy162.pExpr); /*A-overwrites-Y*/ sqlite3ExprListSetSortOrder(yymsp[-1].minor.yy382,yymsp[0].minor.yy52); @@ -2878,42 +2878,42 @@ static void yy_reduce( #line 2879 "parse.c" break; case 117: /* sortorder ::= ASC */ -#line 689 "parse.y" +#line 687 "parse.y" {yymsp[0].minor.yy52 = SQLITE_SO_ASC;} #line 2884 "parse.c" break; case 118: /* sortorder ::= DESC */ -#line 690 "parse.y" +#line 688 "parse.y" {yymsp[0].minor.yy52 = SQLITE_SO_DESC;} #line 2889 "parse.c" break; case 119: /* sortorder ::= */ -#line 691 "parse.y" +#line 689 "parse.y" {yymsp[1].minor.yy52 = SQLITE_SO_UNDEFINED;} #line 2894 "parse.c" break; case 124: /* limit_opt ::= */ -#line 716 "parse.y" +#line 714 "parse.y" {yymsp[1].minor.yy384.pLimit = 0; yymsp[1].minor.yy384.pOffset = 0;} #line 2899 "parse.c" break; case 125: /* limit_opt ::= LIMIT expr */ -#line 717 "parse.y" +#line 715 "parse.y" {yymsp[-1].minor.yy384.pLimit = yymsp[0].minor.yy162.pExpr; yymsp[-1].minor.yy384.pOffset = 0;} #line 2904 "parse.c" break; case 126: /* limit_opt ::= LIMIT expr OFFSET expr */ -#line 719 "parse.y" +#line 717 "parse.y" {yymsp[-3].minor.yy384.pLimit = yymsp[-2].minor.yy162.pExpr; yymsp[-3].minor.yy384.pOffset = yymsp[0].minor.yy162.pExpr;} #line 2909 "parse.c" break; case 127: /* limit_opt ::= LIMIT expr COMMA expr */ -#line 721 "parse.y" +#line 719 "parse.y" {yymsp[-3].minor.yy384.pOffset = yymsp[-2].minor.yy162.pExpr; yymsp[-3].minor.yy384.pLimit = yymsp[0].minor.yy162.pExpr;} #line 2914 "parse.c" break; case 128: /* cmd ::= with DELETE FROM fullname indexed_opt where_opt */ -#line 738 "parse.y" +#line 736 "parse.y" { sqlite3WithPush(pParse, yymsp[-5].minor.yy151, 1); sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy387, &yymsp[-1].minor.yy0); @@ -2925,7 +2925,7 @@ static void yy_reduce( #line 2926 "parse.c" break; case 131: /* cmd ::= with UPDATE orconf fullname indexed_opt SET setlist where_opt */ -#line 771 "parse.y" +#line 769 "parse.y" { sqlite3WithPush(pParse, yymsp[-7].minor.yy151, 1); sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy387, &yymsp[-3].minor.yy0); @@ -2938,7 +2938,7 @@ static void yy_reduce( #line 2939 "parse.c" break; case 132: /* setlist ::= setlist COMMA nm EQ expr */ -#line 785 "parse.y" +#line 783 "parse.y" { yymsp[-4].minor.yy382 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy382, yymsp[0].minor.yy162.pExpr); sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy382, &yymsp[-2].minor.yy0, 1); @@ -2946,14 +2946,14 @@ static void yy_reduce( #line 2947 "parse.c" break; case 133: /* setlist ::= setlist COMMA LP idlist RP EQ expr */ -#line 789 "parse.y" +#line 787 "parse.y" { yymsp[-6].minor.yy382 = sqlite3ExprListAppendVector(pParse, yymsp[-6].minor.yy382, yymsp[-3].minor.yy40, yymsp[0].minor.yy162.pExpr); } #line 2954 "parse.c" break; case 134: /* setlist ::= nm EQ expr */ -#line 792 "parse.y" +#line 790 "parse.y" { yylhsminor.yy382 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy162.pExpr); sqlite3ExprListSetName(pParse, yylhsminor.yy382, &yymsp[-2].minor.yy0, 1); @@ -2962,14 +2962,14 @@ static void yy_reduce( yymsp[-2].minor.yy382 = yylhsminor.yy382; break; case 135: /* setlist ::= LP idlist RP EQ expr */ -#line 796 "parse.y" +#line 794 "parse.y" { yymsp[-4].minor.yy382 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy40, yymsp[0].minor.yy162.pExpr); } #line 2970 "parse.c" break; case 136: /* cmd ::= with insert_cmd INTO fullname idlist_opt select */ -#line 802 "parse.y" +#line 800 "parse.y" { sqlite3WithPush(pParse, yymsp[-5].minor.yy151, 1); sqlSubProgramsRemaining = SQL_MAX_COMPILING_TRIGGERS; @@ -2980,7 +2980,7 @@ static void yy_reduce( #line 2981 "parse.c" break; case 137: /* cmd ::= with insert_cmd INTO fullname idlist_opt DEFAULT VALUES */ -#line 810 "parse.y" +#line 808 "parse.y" { sqlite3WithPush(pParse, yymsp[-6].minor.yy151, 1); sqlSubProgramsRemaining = SQL_MAX_COMPILING_TRIGGERS; @@ -2991,40 +2991,40 @@ static void yy_reduce( #line 2992 "parse.c" break; case 141: /* idlist_opt ::= LP idlist RP */ -#line 828 "parse.y" +#line 826 "parse.y" {yymsp[-2].minor.yy40 = yymsp[-1].minor.yy40;} #line 2997 "parse.c" break; case 142: /* idlist ::= idlist COMMA nm */ -#line 830 "parse.y" +#line 828 "parse.y" {yymsp[-2].minor.yy40 = sqlite3IdListAppend(pParse->db,yymsp[-2].minor.yy40,&yymsp[0].minor.yy0);} #line 3002 "parse.c" break; case 143: /* idlist ::= nm */ -#line 832 "parse.y" +#line 830 "parse.y" {yymsp[0].minor.yy40 = sqlite3IdListAppend(pParse->db,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/} #line 3007 "parse.c" break; case 144: /* expr ::= LP expr RP */ -#line 881 "parse.y" +#line 879 "parse.y" {spanSet(&yymsp[-2].minor.yy162,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/ yymsp[-2].minor.yy162.pExpr = yymsp[-1].minor.yy162.pExpr;} #line 3012 "parse.c" break; case 145: /* term ::= NULL */ case 149: /* term ::= FLOAT|BLOB */ yytestcase(yyruleno==149); case 150: /* term ::= STRING */ yytestcase(yyruleno==150); -#line 882 "parse.y" +#line 880 "parse.y" {spanExpr(&yymsp[0].minor.yy162,pParse,yymsp[0].major,yymsp[0].minor.yy0);/*A-overwrites-X*/} #line 3019 "parse.c" break; case 146: /* expr ::= ID|INDEXED */ case 147: /* expr ::= JOIN_KW */ yytestcase(yyruleno==147); -#line 883 "parse.y" +#line 881 "parse.y" {spanExpr(&yymsp[0].minor.yy162,pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/} #line 3025 "parse.c" break; case 148: /* expr ::= nm DOT nm */ -#line 885 "parse.y" +#line 883 "parse.y" { Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1); Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1); @@ -3034,7 +3034,7 @@ static void yy_reduce( #line 3035 "parse.c" break; case 151: /* term ::= INTEGER */ -#line 893 "parse.y" +#line 891 "parse.y" { yylhsminor.yy162.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1); yylhsminor.yy162.zStart = yymsp[0].minor.yy0.z; @@ -3045,7 +3045,7 @@ static void yy_reduce( yymsp[0].minor.yy162 = yylhsminor.yy162; break; case 152: /* expr ::= VARIABLE */ -#line 899 "parse.y" +#line 897 "parse.y" { if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){ u32 n = yymsp[0].minor.yy0.n; @@ -3070,7 +3070,7 @@ static void yy_reduce( #line 3071 "parse.c" break; case 153: /* expr ::= expr COLLATE ID|INDEXED */ -#line 920 "parse.y" +#line 918 "parse.y" { yymsp[-2].minor.yy162.pExpr = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy162.pExpr, &yymsp[0].minor.yy0, 1); yymsp[-2].minor.yy162.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; @@ -3078,7 +3078,7 @@ static void yy_reduce( #line 3079 "parse.c" break; case 154: /* expr ::= CAST LP expr AS typetoken RP */ -#line 925 "parse.y" +#line 923 "parse.y" { spanSet(&yymsp[-5].minor.yy162,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/ yymsp[-5].minor.yy162.pExpr = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1); @@ -3087,7 +3087,7 @@ static void yy_reduce( #line 3088 "parse.c" break; case 155: /* expr ::= ID|INDEXED LP distinct exprlist RP */ -#line 931 "parse.y" +#line 929 "parse.y" { if( yymsp[-1].minor.yy382 && yymsp[-1].minor.yy382->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){ sqlite3ErrorMsg(pParse, "too many arguments on function %T", &yymsp[-4].minor.yy0); @@ -3102,7 +3102,7 @@ static void yy_reduce( yymsp[-4].minor.yy162 = yylhsminor.yy162; break; case 156: /* expr ::= ID|INDEXED LP STAR RP */ -#line 941 "parse.y" +#line 939 "parse.y" { yylhsminor.yy162.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0); spanSet(&yylhsminor.yy162,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); @@ -3111,7 +3111,7 @@ static void yy_reduce( yymsp[-3].minor.yy162 = yylhsminor.yy162; break; case 157: /* term ::= CTIME_KW */ -#line 945 "parse.y" +#line 943 "parse.y" { yylhsminor.yy162.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0); spanSet(&yylhsminor.yy162, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0); @@ -3120,7 +3120,7 @@ static void yy_reduce( yymsp[0].minor.yy162 = yylhsminor.yy162; break; case 158: /* expr ::= LP nexprlist COMMA expr RP */ -#line 974 "parse.y" +#line 972 "parse.y" { ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy382, yymsp[-1].minor.yy162.pExpr); yylhsminor.yy162.pExpr = sqlite3PExpr(pParse, TK_VECTOR, 0, 0); @@ -3142,22 +3142,22 @@ static void yy_reduce( case 164: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==164); case 165: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==165); case 166: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==166); -#line 985 "parse.y" +#line 983 "parse.y" {spanBinaryExpr(pParse,yymsp[-1].major,&yymsp[-2].minor.yy162,&yymsp[0].minor.yy162);} #line 3148 "parse.c" break; case 167: /* likeop ::= LIKE_KW|MATCH */ -#line 998 "parse.y" +#line 996 "parse.y" {yymsp[0].minor.yy0=yymsp[0].minor.yy0;/*A-overwrites-X*/} #line 3153 "parse.c" break; case 168: /* likeop ::= NOT LIKE_KW|MATCH */ -#line 999 "parse.y" +#line 997 "parse.y" {yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/} #line 3158 "parse.c" break; case 169: /* expr ::= expr likeop expr */ -#line 1000 "parse.y" +#line 998 "parse.y" { ExprList *pList; int bNot = yymsp[-1].minor.yy0.n & 0x80000000; @@ -3172,7 +3172,7 @@ static void yy_reduce( #line 3173 "parse.c" break; case 170: /* expr ::= expr likeop expr ESCAPE expr */ -#line 1011 "parse.y" +#line 1009 "parse.y" { ExprList *pList; int bNot = yymsp[-3].minor.yy0.n & 0x80000000; @@ -3188,17 +3188,17 @@ static void yy_reduce( #line 3189 "parse.c" break; case 171: /* expr ::= expr ISNULL|NOTNULL */ -#line 1038 "parse.y" +#line 1036 "parse.y" {spanUnaryPostfix(pParse,yymsp[0].major,&yymsp[-1].minor.yy162,&yymsp[0].minor.yy0);} #line 3194 "parse.c" break; case 172: /* expr ::= expr NOT NULL */ -#line 1039 "parse.y" +#line 1037 "parse.y" {spanUnaryPostfix(pParse,TK_NOTNULL,&yymsp[-2].minor.yy162,&yymsp[0].minor.yy0);} #line 3199 "parse.c" break; case 173: /* expr ::= expr IS expr */ -#line 1060 "parse.y" +#line 1058 "parse.y" { spanBinaryExpr(pParse,TK_IS,&yymsp[-2].minor.yy162,&yymsp[0].minor.yy162); binaryToUnaryIfNull(pParse, yymsp[0].minor.yy162.pExpr, yymsp[-2].minor.yy162.pExpr, TK_ISNULL); @@ -3206,7 +3206,7 @@ static void yy_reduce( #line 3207 "parse.c" break; case 174: /* expr ::= expr IS NOT expr */ -#line 1064 "parse.y" +#line 1062 "parse.y" { spanBinaryExpr(pParse,TK_ISNOT,&yymsp[-3].minor.yy162,&yymsp[0].minor.yy162); binaryToUnaryIfNull(pParse, yymsp[0].minor.yy162.pExpr, yymsp[-3].minor.yy162.pExpr, TK_NOTNULL); @@ -3215,28 +3215,28 @@ static void yy_reduce( break; case 175: /* expr ::= NOT expr */ case 176: /* expr ::= BITNOT expr */ yytestcase(yyruleno==176); -#line 1088 "parse.y" +#line 1086 "parse.y" {spanUnaryPrefix(&yymsp[-1].minor.yy162,pParse,yymsp[-1].major,&yymsp[0].minor.yy162,&yymsp[-1].minor.yy0);/*A-overwrites-B*/} #line 3221 "parse.c" break; case 177: /* expr ::= MINUS expr */ -#line 1092 "parse.y" +#line 1090 "parse.y" {spanUnaryPrefix(&yymsp[-1].minor.yy162,pParse,TK_UMINUS,&yymsp[0].minor.yy162,&yymsp[-1].minor.yy0);/*A-overwrites-B*/} #line 3226 "parse.c" break; case 178: /* expr ::= PLUS expr */ -#line 1094 "parse.y" +#line 1092 "parse.y" {spanUnaryPrefix(&yymsp[-1].minor.yy162,pParse,TK_UPLUS,&yymsp[0].minor.yy162,&yymsp[-1].minor.yy0);/*A-overwrites-B*/} #line 3231 "parse.c" break; case 179: /* between_op ::= BETWEEN */ case 182: /* in_op ::= IN */ yytestcase(yyruleno==182); -#line 1097 "parse.y" +#line 1095 "parse.y" {yymsp[0].minor.yy52 = 0;} #line 3237 "parse.c" break; case 181: /* expr ::= expr between_op expr AND expr */ -#line 1099 "parse.y" +#line 1097 "parse.y" { ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy162.pExpr); pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy162.pExpr); @@ -3252,104 +3252,104 @@ static void yy_reduce( #line 3253 "parse.c" break; case 184: /* expr ::= expr in_op LP exprlist RP */ -#line 1115 "parse.y" +#line 1112 "parse.y" { - if( yymsp[-1].minor.yy382==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. - */ - sql_expr_free(pParse->db, yymsp[-4].minor.yy162.pExpr, false); - yymsp[-4].minor.yy162.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy52],1); - }else if( yymsp[-1].minor.yy382->nExpr==1 ){ - /* Expressions of the form: - ** - ** expr1 IN (?1) - ** expr1 NOT IN (?2) - ** - ** with exactly one value on the RHS can be simplified to something - ** like this: - ** - ** expr1 == ?1 - ** expr1 <> ?2 - ** - ** But, the RHS of the == or <> is marked with the EP_Generic flag - ** so that it may not contribute to the computation of comparison - ** affinity or the collating sequence to use for comparison. Otherwise, - ** the semantics would be subtly different from IN or NOT IN. - */ - Expr *pRHS = yymsp[-1].minor.yy382->a[0].pExpr; - yymsp[-1].minor.yy382->a[0].pExpr = 0; - sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy382); - /* pRHS cannot be NULL because a malloc error would have been detected - ** before now and control would have never reached this point */ - if( ALWAYS(pRHS) ){ - pRHS->flags &= ~EP_Collate; - pRHS->flags |= EP_Generic; - } - yymsp[-4].minor.yy162.pExpr = sqlite3PExpr(pParse, yymsp[-3].minor.yy52 ? TK_NE : TK_EQ, yymsp[-4].minor.yy162.pExpr, pRHS); + if( yymsp[-1].minor.yy382==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. + */ + sql_expr_free(pParse->db, yymsp[-4].minor.yy162.pExpr, false); + yymsp[-4].minor.yy162.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy52],1); + }else if( yymsp[-1].minor.yy382->nExpr==1 ){ + /* Expressions of the form: + ** + ** expr1 IN (?1) + ** expr1 NOT IN (?2) + ** + ** with exactly one value on the RHS can be simplified to something + ** like this: + ** + ** expr1 == ?1 + ** expr1 <> ?2 + ** + ** But, the RHS of the == or <> is marked with the EP_Generic flag + ** so that it may not contribute to the computation of comparison + ** affinity or the collating sequence to use for comparison. Otherwise, + ** the semantics would be subtly different from IN or NOT IN. + */ + Expr *pRHS = yymsp[-1].minor.yy382->a[0].pExpr; + yymsp[-1].minor.yy382->a[0].pExpr = 0; + sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy382); + /* pRHS cannot be NULL because a malloc error would have been detected + ** before now and control would have never reached this point */ + if( ALWAYS(pRHS) ){ + pRHS->flags &= ~EP_Collate; + pRHS->flags |= EP_Generic; + } + yymsp[-4].minor.yy162.pExpr = sqlite3PExpr(pParse, yymsp[-3].minor.yy52 ? TK_NE : TK_EQ, yymsp[-4].minor.yy162.pExpr, pRHS); + }else{ + yymsp[-4].minor.yy162.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy162.pExpr, 0); + if( yymsp[-4].minor.yy162.pExpr ){ + yymsp[-4].minor.yy162.pExpr->x.pList = yymsp[-1].minor.yy382; + sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy162.pExpr); }else{ - yymsp[-4].minor.yy162.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy162.pExpr, 0); - if( yymsp[-4].minor.yy162.pExpr ){ - yymsp[-4].minor.yy162.pExpr->x.pList = yymsp[-1].minor.yy382; - sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy162.pExpr); - }else{ - sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy382); - } - exprNot(pParse, yymsp[-3].minor.yy52, &yymsp[-4].minor.yy162); + sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy382); } - yymsp[-4].minor.yy162.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; + exprNot(pParse, yymsp[-3].minor.yy52, &yymsp[-4].minor.yy162); } + yymsp[-4].minor.yy162.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; +} #line 3308 "parse.c" break; case 185: /* expr ::= LP select RP */ -#line 1166 "parse.y" +#line 1163 "parse.y" { - spanSet(&yymsp[-2].minor.yy162,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/ - yymsp[-2].minor.yy162.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0); - sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy162.pExpr, yymsp[-1].minor.yy279); - } + spanSet(&yymsp[-2].minor.yy162,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/ + yymsp[-2].minor.yy162.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0); + sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy162.pExpr, yymsp[-1].minor.yy279); +} #line 3317 "parse.c" break; case 186: /* expr ::= expr in_op LP select RP */ -#line 1171 "parse.y" +#line 1168 "parse.y" { - yymsp[-4].minor.yy162.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy162.pExpr, 0); - sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy162.pExpr, yymsp[-1].minor.yy279); - exprNot(pParse, yymsp[-3].minor.yy52, &yymsp[-4].minor.yy162); - yymsp[-4].minor.yy162.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; - } + yymsp[-4].minor.yy162.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy162.pExpr, 0); + sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy162.pExpr, yymsp[-1].minor.yy279); + exprNot(pParse, yymsp[-3].minor.yy52, &yymsp[-4].minor.yy162); + yymsp[-4].minor.yy162.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; +} #line 3327 "parse.c" break; case 187: /* expr ::= expr in_op nm paren_exprlist */ -#line 1177 "parse.y" -{ - SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0); - Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0); - if( yymsp[0].minor.yy382 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy382); - yymsp[-3].minor.yy162.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy162.pExpr, 0); - sqlite3PExprAddSelect(pParse, yymsp[-3].minor.yy162.pExpr, pSelect); - exprNot(pParse, yymsp[-2].minor.yy52, &yymsp[-3].minor.yy162); - yymsp[-3].minor.yy162.zEnd = &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]; - } +#line 1174 "parse.y" +{ + SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0); + Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0); + if( yymsp[0].minor.yy382 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy382); + yymsp[-3].minor.yy162.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy162.pExpr, 0); + sqlite3PExprAddSelect(pParse, yymsp[-3].minor.yy162.pExpr, pSelect); + exprNot(pParse, yymsp[-2].minor.yy52, &yymsp[-3].minor.yy162); + yymsp[-3].minor.yy162.zEnd = &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]; +} #line 3340 "parse.c" break; case 188: /* expr ::= EXISTS LP select RP */ -#line 1186 "parse.y" +#line 1183 "parse.y" { - Expr *p; - spanSet(&yymsp[-3].minor.yy162,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/ - p = yymsp[-3].minor.yy162.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0); - sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy279); - } + Expr *p; + spanSet(&yymsp[-3].minor.yy162,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/ + p = yymsp[-3].minor.yy162.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0); + sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy279); +} #line 3350 "parse.c" break; case 189: /* expr ::= CASE case_operand case_exprlist case_else END */ -#line 1195 "parse.y" +#line 1191 "parse.y" { spanSet(&yymsp[-4].minor.yy162,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/ yymsp[-4].minor.yy162.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy362, 0); @@ -3364,7 +3364,7 @@ static void yy_reduce( #line 3365 "parse.c" break; case 190: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */ -#line 1208 "parse.y" +#line 1204 "parse.y" { yymsp[-4].minor.yy382 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy382, yymsp[-2].minor.yy162.pExpr); yymsp[-4].minor.yy382 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy382, yymsp[0].minor.yy162.pExpr); @@ -3372,7 +3372,7 @@ static void yy_reduce( #line 3373 "parse.c" break; case 191: /* case_exprlist ::= WHEN expr THEN expr */ -#line 1212 "parse.y" +#line 1208 "parse.y" { yymsp[-3].minor.yy382 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy162.pExpr); yymsp[-3].minor.yy382 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy382, yymsp[0].minor.yy162.pExpr); @@ -3380,28 +3380,28 @@ static void yy_reduce( #line 3381 "parse.c" break; case 194: /* case_operand ::= expr */ -#line 1222 "parse.y" +#line 1218 "parse.y" {yymsp[0].minor.yy362 = yymsp[0].minor.yy162.pExpr; /*A-overwrites-X*/} #line 3386 "parse.c" break; case 197: /* nexprlist ::= nexprlist COMMA expr */ -#line 1233 "parse.y" +#line 1229 "parse.y" {yymsp[-2].minor.yy382 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy382,yymsp[0].minor.yy162.pExpr);} #line 3391 "parse.c" break; case 198: /* nexprlist ::= expr */ -#line 1235 "parse.y" +#line 1231 "parse.y" {yymsp[0].minor.yy382 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy162.pExpr); /*A-overwrites-Y*/} #line 3396 "parse.c" break; case 200: /* paren_exprlist ::= LP exprlist RP */ case 205: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==205); -#line 1243 "parse.y" +#line 1238 "parse.y" {yymsp[-2].minor.yy382 = yymsp[-1].minor.yy382;} #line 3402 "parse.c" break; case 201: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm ON nm LP sortlist RP where_opt */ -#line 1250 "parse.y" +#line 1244 "parse.y" { sqlite3CreateIndex(pParse, &yymsp[-6].minor.yy0, sqlite3SrcListAppend(pParse->db,0,&yymsp[-4].minor.yy0), yymsp[-2].minor.yy382, yymsp[-9].minor.yy52, @@ -3411,87 +3411,87 @@ static void yy_reduce( break; case 202: /* uniqueflag ::= UNIQUE */ case 243: /* raisetype ::= ABORT */ yytestcase(yyruleno==243); -#line 1257 "parse.y" +#line 1251 "parse.y" {yymsp[0].minor.yy52 = ON_CONFLICT_ACTION_ABORT;} #line 3417 "parse.c" break; case 203: /* uniqueflag ::= */ -#line 1258 "parse.y" +#line 1252 "parse.y" {yymsp[1].minor.yy52 = ON_CONFLICT_ACTION_NONE;} #line 3422 "parse.c" break; case 206: /* eidlist ::= eidlist COMMA nm collate sortorder */ -#line 1301 "parse.y" +#line 1295 "parse.y" { yymsp[-4].minor.yy382 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy382, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy52, yymsp[0].minor.yy52); } #line 3429 "parse.c" break; case 207: /* eidlist ::= nm collate sortorder */ -#line 1304 "parse.y" +#line 1298 "parse.y" { yymsp[-2].minor.yy382 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy52, yymsp[0].minor.yy52); /*A-overwrites-Y*/ } #line 3436 "parse.c" break; case 210: /* cmd ::= DROP INDEX ifexists fullname ON nm */ -#line 1315 "parse.y" +#line 1309 "parse.y" { sql_drop_index(pParse, yymsp[-2].minor.yy387, &yymsp[0].minor.yy0, yymsp[-3].minor.yy52); } #line 3443 "parse.c" break; case 211: /* cmd ::= PRAGMA nm */ -#line 1322 "parse.y" +#line 1316 "parse.y" { sqlite3Pragma(pParse,&yymsp[0].minor.yy0,0,0,0); } #line 3450 "parse.c" break; case 212: /* cmd ::= PRAGMA nm EQ nmnum */ -#line 1325 "parse.y" +#line 1319 "parse.y" { sqlite3Pragma(pParse,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0,0); } #line 3457 "parse.c" break; case 213: /* cmd ::= PRAGMA nm LP nmnum RP */ -#line 1328 "parse.y" +#line 1322 "parse.y" { sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0,0); } #line 3464 "parse.c" break; case 214: /* cmd ::= PRAGMA nm EQ minus_num */ -#line 1331 "parse.y" +#line 1325 "parse.y" { sqlite3Pragma(pParse,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0,0,1); } #line 3471 "parse.c" break; case 215: /* cmd ::= PRAGMA nm LP minus_num RP */ -#line 1334 "parse.y" +#line 1328 "parse.y" { sqlite3Pragma(pParse,&yymsp[-3].minor.yy0,&yymsp[-1].minor.yy0,0,1); } #line 3478 "parse.c" break; case 216: /* cmd ::= PRAGMA nm EQ nm DOT nm */ -#line 1337 "parse.y" +#line 1331 "parse.y" { sqlite3Pragma(pParse,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0,&yymsp[-2].minor.yy0,0); } #line 3485 "parse.c" break; case 217: /* cmd ::= PRAGMA */ -#line 1340 "parse.y" +#line 1334 "parse.y" { sqlite3Pragma(pParse, 0,0,0,0); } #line 3492 "parse.c" break; case 220: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */ -#line 1360 "parse.y" +#line 1354 "parse.y" { Token all; all.z = yymsp[-3].minor.yy0.z; @@ -3502,7 +3502,7 @@ static void yy_reduce( #line 3503 "parse.c" break; case 221: /* trigger_decl ::= TRIGGER ifnotexists nm trigger_time trigger_event ON fullname foreach_clause when_clause */ -#line 1370 "parse.y" +#line 1364 "parse.y" { sqlite3BeginTrigger(pParse, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy52, yymsp[-4].minor.yy10.a, yymsp[-4].minor.yy10.b, yymsp[-2].minor.yy387, yymsp[0].minor.yy362, yymsp[-7].minor.yy52); yymsp[-8].minor.yy0 = yymsp[-6].minor.yy0; /*yymsp[-8].minor.yy0-overwrites-T*/ @@ -3510,48 +3510,48 @@ static void yy_reduce( #line 3511 "parse.c" break; case 222: /* trigger_time ::= BEFORE */ -#line 1376 "parse.y" +#line 1370 "parse.y" { yymsp[0].minor.yy52 = TK_BEFORE; } #line 3516 "parse.c" break; case 223: /* trigger_time ::= AFTER */ -#line 1377 "parse.y" +#line 1371 "parse.y" { yymsp[0].minor.yy52 = TK_AFTER; } #line 3521 "parse.c" break; case 224: /* trigger_time ::= INSTEAD OF */ -#line 1378 "parse.y" +#line 1372 "parse.y" { yymsp[-1].minor.yy52 = TK_INSTEAD;} #line 3526 "parse.c" break; case 225: /* trigger_time ::= */ -#line 1379 "parse.y" +#line 1373 "parse.y" { yymsp[1].minor.yy52 = TK_BEFORE; } #line 3531 "parse.c" break; case 226: /* trigger_event ::= DELETE|INSERT */ case 227: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==227); -#line 1383 "parse.y" +#line 1377 "parse.y" {yymsp[0].minor.yy10.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy10.b = 0;} #line 3537 "parse.c" break; case 228: /* trigger_event ::= UPDATE OF idlist */ -#line 1385 "parse.y" +#line 1379 "parse.y" {yymsp[-2].minor.yy10.a = TK_UPDATE; yymsp[-2].minor.yy10.b = yymsp[0].minor.yy40;} #line 3542 "parse.c" break; case 229: /* when_clause ::= */ -#line 1392 "parse.y" +#line 1386 "parse.y" { yymsp[1].minor.yy362 = 0; } #line 3547 "parse.c" break; case 230: /* when_clause ::= WHEN expr */ -#line 1393 "parse.y" +#line 1387 "parse.y" { yymsp[-1].minor.yy362 = yymsp[0].minor.yy162.pExpr; } #line 3552 "parse.c" break; case 231: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */ -#line 1397 "parse.y" +#line 1391 "parse.y" { assert( yymsp[-2].minor.yy427!=0 ); yymsp[-2].minor.yy427->pLast->pNext = yymsp[-1].minor.yy427; @@ -3560,7 +3560,7 @@ static void yy_reduce( #line 3561 "parse.c" break; case 232: /* trigger_cmd_list ::= trigger_cmd SEMI */ -#line 1402 "parse.y" +#line 1396 "parse.y" { assert( yymsp[-1].minor.yy427!=0 ); yymsp[-1].minor.yy427->pLast = yymsp[-1].minor.yy427; @@ -3568,7 +3568,7 @@ static void yy_reduce( #line 3569 "parse.c" break; case 233: /* trnm ::= nm DOT nm */ -#line 1413 "parse.y" +#line 1407 "parse.y" { yymsp[-2].minor.yy0 = yymsp[0].minor.yy0; sqlite3ErrorMsg(pParse, @@ -3578,7 +3578,7 @@ static void yy_reduce( #line 3579 "parse.c" break; case 234: /* tridxby ::= INDEXED BY nm */ -#line 1425 "parse.y" +#line 1419 "parse.y" { sqlite3ErrorMsg(pParse, "the INDEXED BY clause is not allowed on UPDATE or DELETE statements " @@ -3587,7 +3587,7 @@ static void yy_reduce( #line 3588 "parse.c" break; case 235: /* tridxby ::= NOT INDEXED */ -#line 1430 "parse.y" +#line 1424 "parse.y" { sqlite3ErrorMsg(pParse, "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements " @@ -3596,27 +3596,27 @@ static void yy_reduce( #line 3597 "parse.c" break; case 236: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt */ -#line 1443 "parse.y" +#line 1437 "parse.y" {yymsp[-6].minor.yy427 = sqlite3TriggerUpdateStep(pParse->db, &yymsp[-4].minor.yy0, yymsp[-1].minor.yy382, yymsp[0].minor.yy362, yymsp[-5].minor.yy52);} #line 3602 "parse.c" break; case 237: /* trigger_cmd ::= insert_cmd INTO trnm idlist_opt select */ -#line 1447 "parse.y" +#line 1441 "parse.y" {yymsp[-4].minor.yy427 = sqlite3TriggerInsertStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy40, yymsp[0].minor.yy279, yymsp[-4].minor.yy52);/*A-overwrites-R*/} #line 3607 "parse.c" break; case 238: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt */ -#line 1451 "parse.y" +#line 1445 "parse.y" {yymsp[-4].minor.yy427 = sqlite3TriggerDeleteStep(pParse->db, &yymsp[-2].minor.yy0, yymsp[0].minor.yy362);} #line 3612 "parse.c" break; case 239: /* trigger_cmd ::= select */ -#line 1455 "parse.y" +#line 1449 "parse.y" {yymsp[0].minor.yy427 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy279); /*A-overwrites-X*/} #line 3617 "parse.c" break; case 240: /* expr ::= RAISE LP IGNORE RP */ -#line 1458 "parse.y" +#line 1452 "parse.y" { spanSet(&yymsp[-3].minor.yy162,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/ yymsp[-3].minor.yy162.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0); @@ -3627,7 +3627,7 @@ static void yy_reduce( #line 3628 "parse.c" break; case 241: /* expr ::= RAISE LP raisetype COMMA STRING RP */ -#line 1465 "parse.y" +#line 1459 "parse.y" { spanSet(&yymsp[-5].minor.yy162,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/ yymsp[-5].minor.yy162.pExpr = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1); @@ -3638,63 +3638,63 @@ static void yy_reduce( #line 3639 "parse.c" break; case 242: /* raisetype ::= ROLLBACK */ -#line 1475 "parse.y" +#line 1469 "parse.y" {yymsp[0].minor.yy52 = ON_CONFLICT_ACTION_ROLLBACK;} #line 3644 "parse.c" break; case 244: /* raisetype ::= FAIL */ -#line 1477 "parse.y" +#line 1471 "parse.y" {yymsp[0].minor.yy52 = ON_CONFLICT_ACTION_FAIL;} #line 3649 "parse.c" break; case 245: /* cmd ::= DROP TRIGGER ifexists fullname */ -#line 1482 "parse.y" +#line 1476 "parse.y" { sqlite3DropTrigger(pParse,yymsp[0].minor.yy387,yymsp[-1].minor.yy52); } #line 3656 "parse.c" break; case 246: /* cmd ::= ANALYZE */ -#line 1497 "parse.y" +#line 1491 "parse.y" {sqlite3Analyze(pParse, 0);} #line 3661 "parse.c" break; case 247: /* cmd ::= ANALYZE nm */ -#line 1498 "parse.y" +#line 1492 "parse.y" {sqlite3Analyze(pParse, &yymsp[0].minor.yy0);} #line 3666 "parse.c" break; case 248: /* cmd ::= ALTER TABLE fullname RENAME TO nm */ -#line 1503 "parse.y" +#line 1497 "parse.y" { sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy387,&yymsp[0].minor.yy0); } #line 3673 "parse.c" break; case 249: /* with ::= */ -#line 1526 "parse.y" +#line 1520 "parse.y" {yymsp[1].minor.yy151 = 0;} #line 3678 "parse.c" break; case 250: /* with ::= WITH wqlist */ -#line 1528 "parse.y" +#line 1522 "parse.y" { yymsp[-1].minor.yy151 = yymsp[0].minor.yy151; } #line 3683 "parse.c" break; case 251: /* with ::= WITH RECURSIVE wqlist */ -#line 1529 "parse.y" +#line 1523 "parse.y" { yymsp[-2].minor.yy151 = yymsp[0].minor.yy151; } #line 3688 "parse.c" break; case 252: /* wqlist ::= nm eidlist_opt AS LP select RP */ -#line 1531 "parse.y" +#line 1525 "parse.y" { yymsp[-5].minor.yy151 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy382, yymsp[-1].minor.yy279); /*A-overwrites-X*/ } #line 3695 "parse.c" break; case 253: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */ -#line 1534 "parse.y" +#line 1528 "parse.y" { yymsp[-7].minor.yy151 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy151, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy382, yymsp[-1].minor.yy279); } diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y index c64009175..b078e200d 100644 --- a/src/box/sql/parse.y +++ b/src/box/sql/parse.y @@ -591,34 +591,32 @@ seltablist(A) ::= stl_prefix(A) nm(Y) LP exprlist(E) RP as(Z) A = sqlite3SrcListAppendFromTerm(pParse,A,&Y,&Z,0,N,U); sqlite3SrcListFuncArgs(pParse, A, E); } -%ifndef SQLITE_OMIT_SUBQUERY - seltablist(A) ::= stl_prefix(A) LP select(S) RP - as(Z) on_opt(N) using_opt(U). { - A = sqlite3SrcListAppendFromTerm(pParse,A,0,&Z,S,N,U); - } - seltablist(A) ::= stl_prefix(A) LP seltablist(F) RP - as(Z) on_opt(N) using_opt(U). { - if( A==0 && Z.n==0 && N==0 && U==0 ){ - A = F; - }else if( F->nSrc==1 ){ - A = sqlite3SrcListAppendFromTerm(pParse,A,0,&Z,0,N,U); - if( A ){ - struct SrcList_item *pNew = &A->a[A->nSrc-1]; - struct SrcList_item *pOld = F->a; - pNew->zName = pOld->zName; - pNew->pSelect = pOld->pSelect; - pOld->zName = 0; - pOld->pSelect = 0; - } - sqlite3SrcListDelete(pParse->db, F); - }else{ - Select *pSubquery; - sqlite3SrcListShiftJoinType(F); - pSubquery = sqlite3SelectNew(pParse,0,F,0,0,0,0,SF_NestedFrom,0,0); - A = sqlite3SrcListAppendFromTerm(pParse,A,0,&Z,pSubquery,N,U); +seltablist(A) ::= stl_prefix(A) LP select(S) RP + as(Z) on_opt(N) using_opt(U). { + A = sqlite3SrcListAppendFromTerm(pParse,A,0,&Z,S,N,U); +} +seltablist(A) ::= stl_prefix(A) LP seltablist(F) RP + as(Z) on_opt(N) using_opt(U). { + if( A==0 && Z.n==0 && N==0 && U==0 ){ + A = F; + }else if( F->nSrc==1 ){ + A = sqlite3SrcListAppendFromTerm(pParse,A,0,&Z,0,N,U); + if( A ){ + struct SrcList_item *pNew = &A->a[A->nSrc-1]; + struct SrcList_item *pOld = F->a; + pNew->zName = pOld->zName; + pNew->pSelect = pOld->pSelect; + pOld->zName = 0; + pOld->pSelect = 0; } + sqlite3SrcListDelete(pParse->db, F); + }else{ + Select *pSubquery; + sqlite3SrcListShiftJoinType(F); + pSubquery = sqlite3SelectNew(pParse,0,F,0,0,0,0,SF_NestedFrom,0,0); + A = sqlite3SrcListAppendFromTerm(pParse,A,0,&Z,pSubquery,N,U); } -%endif SQLITE_OMIT_SUBQUERY +} %type fullname {SrcList*} %destructor fullname {sqlite3SrcListDelete(pParse->db, $$);} @@ -1108,88 +1106,86 @@ expr(A) ::= expr(A) between_op(N) expr(X) AND expr(Y). [BETWEEN] { exprNot(pParse, N, &A); 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(A) in_op(N) LP exprlist(Y) RP(E). [IN] { - if( Y==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. - */ - sql_expr_free(pParse->db, A.pExpr, false); - A.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[N],1); - }else if( Y->nExpr==1 ){ - /* Expressions of the form: - ** - ** expr1 IN (?1) - ** expr1 NOT IN (?2) - ** - ** with exactly one value on the RHS can be simplified to something - ** like this: - ** - ** expr1 == ?1 - ** expr1 <> ?2 - ** - ** But, the RHS of the == or <> is marked with the EP_Generic flag - ** so that it may not contribute to the computation of comparison - ** affinity or the collating sequence to use for comparison. Otherwise, - ** the semantics would be subtly different from IN or NOT IN. - */ - Expr *pRHS = Y->a[0].pExpr; - Y->a[0].pExpr = 0; - sqlite3ExprListDelete(pParse->db, Y); - /* pRHS cannot be NULL because a malloc error would have been detected - ** before now and control would have never reached this point */ - if( ALWAYS(pRHS) ){ - pRHS->flags &= ~EP_Collate; - pRHS->flags |= EP_Generic; - } - A.pExpr = sqlite3PExpr(pParse, N ? TK_NE : TK_EQ, A.pExpr, pRHS); - }else{ - A.pExpr = sqlite3PExpr(pParse, TK_IN, A.pExpr, 0); - if( A.pExpr ){ - A.pExpr->x.pList = Y; - sqlite3ExprSetHeightAndFlags(pParse, A.pExpr); - }else{ - sqlite3ExprListDelete(pParse->db, Y); - } - exprNot(pParse, N, &A); +%type in_op {int} +in_op(A) ::= IN. {A = 0;} +in_op(A) ::= NOT IN. {A = 1;} +expr(A) ::= expr(A) in_op(N) LP exprlist(Y) RP(E). [IN] { + if( Y==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. + */ + sql_expr_free(pParse->db, A.pExpr, false); + A.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[N],1); + }else if( Y->nExpr==1 ){ + /* Expressions of the form: + ** + ** expr1 IN (?1) + ** expr1 NOT IN (?2) + ** + ** with exactly one value on the RHS can be simplified to something + ** like this: + ** + ** expr1 == ?1 + ** expr1 <> ?2 + ** + ** But, the RHS of the == or <> is marked with the EP_Generic flag + ** so that it may not contribute to the computation of comparison + ** affinity or the collating sequence to use for comparison. Otherwise, + ** the semantics would be subtly different from IN or NOT IN. + */ + Expr *pRHS = Y->a[0].pExpr; + Y->a[0].pExpr = 0; + sqlite3ExprListDelete(pParse->db, Y); + /* pRHS cannot be NULL because a malloc error would have been detected + ** before now and control would have never reached this point */ + if( ALWAYS(pRHS) ){ + pRHS->flags &= ~EP_Collate; + pRHS->flags |= EP_Generic; } - A.zEnd = &E.z[E.n]; - } - expr(A) ::= LP(B) select(X) RP(E). { - spanSet(&A,&B,&E); /*A-overwrites-B*/ - A.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0); - sqlite3PExprAddSelect(pParse, A.pExpr, X); - } - expr(A) ::= expr(A) in_op(N) LP select(Y) RP(E). [IN] { - A.pExpr = sqlite3PExpr(pParse, TK_IN, A.pExpr, 0); - sqlite3PExprAddSelect(pParse, A.pExpr, Y); - exprNot(pParse, N, &A); - A.zEnd = &E.z[E.n]; - } - expr(A) ::= expr(A) in_op(N) nm(Y) paren_exprlist(E). [IN] { - SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&Y); - Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0); - if( E ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, E); + A.pExpr = sqlite3PExpr(pParse, N ? TK_NE : TK_EQ, A.pExpr, pRHS); + }else{ A.pExpr = sqlite3PExpr(pParse, TK_IN, A.pExpr, 0); - sqlite3PExprAddSelect(pParse, A.pExpr, pSelect); + if( A.pExpr ){ + A.pExpr->x.pList = Y; + sqlite3ExprSetHeightAndFlags(pParse, A.pExpr); + }else{ + sqlite3ExprListDelete(pParse->db, Y); + } exprNot(pParse, N, &A); - A.zEnd = &Y.z[Y.n]; - } - expr(A) ::= EXISTS(B) LP select(Y) RP(E). { - Expr *p; - spanSet(&A,&B,&E); /*A-overwrites-B*/ - p = A.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0); - sqlite3PExprAddSelect(pParse, p, Y); } -%endif SQLITE_OMIT_SUBQUERY + A.zEnd = &E.z[E.n]; +} +expr(A) ::= LP(B) select(X) RP(E). { + spanSet(&A,&B,&E); /*A-overwrites-B*/ + A.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0); + sqlite3PExprAddSelect(pParse, A.pExpr, X); +} +expr(A) ::= expr(A) in_op(N) LP select(Y) RP(E). [IN] { + A.pExpr = sqlite3PExpr(pParse, TK_IN, A.pExpr, 0); + sqlite3PExprAddSelect(pParse, A.pExpr, Y); + exprNot(pParse, N, &A); + A.zEnd = &E.z[E.n]; +} +expr(A) ::= expr(A) in_op(N) nm(Y) paren_exprlist(E). [IN] { + SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&Y); + Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0); + if( E ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, E); + A.pExpr = sqlite3PExpr(pParse, TK_IN, A.pExpr, 0); + sqlite3PExprAddSelect(pParse, A.pExpr, pSelect); + exprNot(pParse, N, &A); + A.zEnd = &Y.z[Y.n]; +} +expr(A) ::= EXISTS(B) LP select(Y) RP(E). { + Expr *p; + spanSet(&A,&B,&E); /*A-overwrites-B*/ + p = A.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0); + sqlite3PExprAddSelect(pParse, p, Y); +} /* CASE expressions */ expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). { @@ -1234,14 +1230,12 @@ nexprlist(A) ::= nexprlist(A) COMMA expr(Y). nexprlist(A) ::= expr(Y). {A = sqlite3ExprListAppend(pParse,0,Y.pExpr); /*A-overwrites-Y*/} -%ifndef SQLITE_OMIT_SUBQUERY /* A paren_exprlist is an optional expression list contained inside ** of parenthesis */ %type paren_exprlist {ExprList*} %destructor paren_exprlist {sqlite3ExprListDelete(pParse->db, $$);} paren_exprlist(A) ::= . {A = 0;} paren_exprlist(A) ::= LP exprlist(X) RP. {A = X;} -%endif SQLITE_OMIT_SUBQUERY ///////////////////////////// The CREATE INDEX command /////////////////////// diff --git a/src/box/sql/resolve.c b/src/box/sql/resolve.c index 63997f25e..823062a9e 100644 --- a/src/box/sql/resolve.c +++ b/src/box/sql/resolve.c @@ -591,7 +591,7 @@ resolveExprStep(Walker * pWalker, Expr * pExpr) #endif switch (pExpr->op) { -#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) +#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) /* The special operator TK_ROW means use the rowid for the first * column in the FROM clause. This is used by the LIMIT and ORDER BY * clause processing on UPDATE and DELETE statements. @@ -608,8 +608,7 @@ resolveExprStep(Walker * pWalker, Expr * pExpr) pExpr->affinity = SQLITE_AFF_INTEGER; break; } -#endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) - && !defined(SQLITE_OMIT_SUBQUERY) */ +#endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) */ /* A lone identifier is the name of a column. */ @@ -772,11 +771,9 @@ resolveExprStep(Walker * pWalker, Expr * pExpr) */ return WRC_Prune; } -#ifndef SQLITE_OMIT_SUBQUERY case TK_SELECT: case TK_EXISTS: testcase(pExpr->op == TK_EXISTS); -#endif case TK_IN:{ testcase(pExpr->op == TK_IN); if (ExprHasProperty(pExpr, EP_xIsSelect)) { diff --git a/src/box/sql/select.c b/src/box/sql/select.c index c48f417b0..4f26963b1 100644 --- a/src/box/sql/select.c +++ b/src/box/sql/select.c @@ -1040,8 +1040,6 @@ selectInnerLoop(Parse * pParse, /* The parser context */ sqlite3ReleaseTempRange(pParse, r1, nPrefixReg + 1); break; } - -#ifndef SQLITE_OMIT_SUBQUERY /* If we are creating a set for an "expr IN (SELECT ...)" construct, * then there should be a single item on the stack. Write this * item into the set table with bogus data. @@ -1095,7 +1093,6 @@ selectInnerLoop(Parse * pParse, /* The parser context */ } break; } -#endif /* #ifndef SQLITE_OMIT_SUBQUERY */ case SRT_Coroutine: /* Send data to a co-routine */ case SRT_Output:{ /* Return the results */ @@ -1489,7 +1486,6 @@ generateSortTail(Parse * pParse, /* Parsing context */ sqlite3ReleaseTempReg(pParse, regCopy); break; } -#ifndef SQLITE_OMIT_SUBQUERY case SRT_Set:{ assert((unsigned int)nColumn == sqlite3Strlen30(pDest->zAffSdst)); @@ -1503,7 +1499,6 @@ generateSortTail(Parse * pParse, /* Parsing context */ /* The LIMIT clause will terminate the loop for us */ break; } -#endif default: { assert(eDest == SRT_Output || eDest == SRT_Coroutine); testcase(eDest == SRT_Output); @@ -1677,7 +1672,6 @@ columnTypeImpl(NameContext * pNC, Expr * pExpr, } break; } -#ifndef SQLITE_OMIT_SUBQUERY case TK_SELECT:{ /* The expression is a sub-select. Return the declaration type and * origin info for the single column in the result set of the SELECT @@ -1695,7 +1689,6 @@ columnTypeImpl(NameContext * pNC, Expr * pExpr, &estWidth); break; } -#endif } #ifdef SQLITE_ENABLE_COLUMN_METADATA @@ -2941,8 +2934,6 @@ generateOutputSubroutine(Parse * pParse, /* Parsing context */ sqlite3ReleaseTempReg(pParse, regRec); break; } - -#ifndef SQLITE_OMIT_SUBQUERY /* If we are creating a set for an "expr IN (SELECT ...)". */ case SRT_Set:{ @@ -2971,8 +2962,6 @@ generateOutputSubroutine(Parse * pParse, /* Parsing context */ /* The LIMIT clause will jump out of the loop for us */ break; } -#endif /* #ifndef SQLITE_OMIT_SUBQUERY */ - /* The results are stored in a sequence of registers * starting at pDest->iSdst. Then the co-routine yields. */ @@ -3440,7 +3429,6 @@ multiSelectOrderBy(Parse * pParse, /* Parsing context */ } #endif -#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) /* Forward Declarations */ static void substExprList(Parse *, ExprList *, int, ExprList *); static void substSelect(Parse *, Select *, int, ExprList *, int); @@ -3545,9 +3533,7 @@ substSelect(Parse * pParse, /* Report errors here */ } } while (doPrior && (p = p->pPrior) != 0); } -#endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */ -#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) /* * This routine attempts to flatten subqueries as a performance optimization. * This routine returns 1 if it makes changes and 0 if no flattening occurs. @@ -4115,9 +4101,7 @@ flattenSubquery(Parse * pParse, /* Parsing context */ return 1; } -#endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */ -#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) /* * Make copies of relevant WHERE clause terms of the outer query into * the WHERE clause of subquery. Example: @@ -4194,7 +4178,6 @@ pushDownWhereTerms(Parse * pParse, /* Parse context (for malloc() and error repo } return nChng; } -#endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */ /* * Based on the contents of the AggInfo structure indicated by the first @@ -4686,7 +4669,6 @@ selectExpander(Walker * pWalker, Select * p) } else #endif if (pFrom->zName == 0) { -#ifndef SQLITE_OMIT_SUBQUERY Select *pSel = pFrom->pSelect; /* A sub-query in the FROM clause of a SELECT */ assert(pSel != 0); @@ -4709,7 +4691,6 @@ selectExpander(Walker * pWalker, Select * p) pTab->nRowLogEst = 200; assert(200 == sqlite3LogEst(1048576)); pTab->tabFlags |= TF_Ephemeral; -#endif } else { /* An ordinary table or view name in the FROM clause */ assert(pFrom->pTab == 0); @@ -5008,7 +4989,6 @@ sqlite3SelectExpand(Parse * pParse, Select * pSelect) sqlite3WalkSelect(&w, pSelect); } -#ifndef SQLITE_OMIT_SUBQUERY /* * This is a Walker.xSelectCallback callback for the sqlite3SelectTypeInfo() * interface. @@ -5051,7 +5031,6 @@ selectAddSubqueryTypeInfo(Walker * pWalker, Select * p) } } } -#endif /* * This routine adds datatype and collating sequence information to @@ -5063,14 +5042,12 @@ selectAddSubqueryTypeInfo(Walker * pWalker, Select * p) static void sqlite3SelectAddTypeInfo(Parse * pParse, Select * pSelect) { -#ifndef SQLITE_OMIT_SUBQUERY Walker w; memset(&w, 0, sizeof(w)); w.xSelectCallback2 = selectAddSubqueryTypeInfo; w.xExprCallback = sqlite3ExprWalkNoop; w.pParse = pParse; sqlite3WalkSelect(&w, pSelect); -#endif } /* @@ -5378,7 +5355,6 @@ sqlite3Select(Parse * pParse, /* The parser context */ /* Try to flatten subqueries in the FROM clause up into the main query */ -#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) for (i = 0; !p->pPrior && i < pTabList->nSrc; i++) { struct SrcList_item *pItem = &pTabList->a[i]; Select *pSub = pItem->pSelect; @@ -5414,7 +5390,6 @@ sqlite3Select(Parse * pParse, /* The parser context */ sSort.pOrderBy = p->pOrderBy; } } -#endif /* Get a pointer the VDBE under construction, allocating a new VDBE if one * does not already exist @@ -5440,7 +5415,6 @@ sqlite3Select(Parse * pParse, /* The parser context */ /* Generate code for all sub-queries in the FROM clause */ -#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) for (i = 0; i < pTabList->nSrc; i++) { struct SrcList_item *pItem = &pTabList->a[i]; SelectDest dest; @@ -5570,7 +5544,6 @@ sqlite3Select(Parse * pParse, /* The parser context */ goto select_end; pParse->nHeight -= sqlite3SelectExprHeight(p); } -#endif /* Various elements of the SELECT copied into local variables for * convenience diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index fa5141d5a..d2d9c849e 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -3600,7 +3600,7 @@ void sqlite3SelectDelete(sqlite3 *, Select *); Table *sqlite3SrcListLookup(Parse *, SrcList *); int sqlite3IsReadOnly(Parse *, Table *, int); void sqlite3OpenTable(Parse *, int iCur, Table *, int); -#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) +#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, char *); #endif @@ -3934,11 +3934,7 @@ void sqlite3StrAccumReset(StrAccum *); void sqlite3SelectDestInit(SelectDest *, int, int); Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); -#ifndef SQLITE_OMIT_SUBQUERY int sqlite3ExprCheckIN(Parse *, Expr *); -#else -#define sqlite3ExprCheckIN(x,y) SQLITE_OK -#endif void sqlite3AnalyzeFunctions(void); int sqlite3Stat4ProbeSetValue(Parse *, Index *, UnpackedRecord **, Expr *, int, diff --git a/src/box/sql/treeview.c b/src/box/sql/treeview.c index 3cdf64b56..1ff949cea 100644 --- a/src/box/sql/treeview.c +++ b/src/box/sql/treeview.c @@ -509,7 +509,6 @@ sqlite3TreeViewExpr(TreeView * pView, const Expr * pExpr, u8 moreToFollow) } break; } -#ifndef SQLITE_OMIT_SUBQUERY case TK_EXISTS:{ sqlite3TreeViewLine(pView, "EXISTS-expr"); sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); @@ -532,8 +531,6 @@ sqlite3TreeViewExpr(TreeView * pView, const Expr * pExpr, u8 moreToFollow) } break; } -#endif /* SQLITE_OMIT_SUBQUERY */ - /* * x BETWEEN y AND z * diff --git a/src/box/sql/wherecode.c b/src/box/sql/wherecode.c index 7d58b66ed..f1112f22d 100644 --- a/src/box/sql/wherecode.c +++ b/src/box/sql/wherecode.c @@ -453,7 +453,6 @@ codeEqualityTerm(Parse * pParse, /* The parsing context */ } else if (pX->op == TK_ISNULL) { iReg = iTarget; sqlite3VdbeAddOp2(v, OP_Null, 0, iReg); -#ifndef SQLITE_OMIT_SUBQUERY } else { int eType = IN_INDEX_NOOP; int iTab; @@ -617,7 +616,6 @@ codeEqualityTerm(Parse * pParse, /* The parsing context */ pLevel->u.in.nIn = 0; } sqlite3DbFree(pParse->db, aiMap); -#endif } disableTerm(pLevel, pTerm); return iReg; @@ -1070,14 +1068,11 @@ codeExprOrVector(Parse * pParse, Expr * p, int iReg, int nReg) { assert(nReg > 0); if (sqlite3ExprIsVector(p)) { -#ifndef SQLITE_OMIT_SUBQUERY if ((p->flags & EP_xIsSelect)) { Vdbe *v = pParse->pVdbe; int iSelect = sqlite3CodeSubselect(pParse, p, 0); sqlite3VdbeAddOp3(v, OP_Copy, iSelect, iReg, nReg - 1); - } else -#endif - { + } else { int i; ExprList *pList = p->x.pList; assert(nReg <= pList->nExpr); diff --git a/src/box/sql/whereexpr.c b/src/box/sql/whereexpr.c index ccdff4684..f4447d893 100644 --- a/src/box/sql/whereexpr.c +++ b/src/box/sql/whereexpr.c @@ -428,7 +428,7 @@ whereCombineDisjuncts(SrcList * pSrc, /* the FROM clause */ exprAnalyze(pSrc, pWC, idxNew); } -#if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY) +#if !defined(SQLITE_OMIT_OR_OPTIMIZATION) /* * Analyze a term that consists of two or more OR-connected * subterms. So in: @@ -801,7 +801,7 @@ exprAnalyzeOrTerm(SrcList * pSrc, /* the FROM clause */ } } } -#endif /* !SQLITE_OMIT_OR_OPTIMIZATION && !SQLITE_OMIT_SUBQUERY */ +#endif /* !SQLITE_OMIT_OR_OPTIMIZATION */ /* * We already know that pExpr is a binary operator where both operands are @@ -1134,7 +1134,7 @@ exprAnalyze(SrcList * pSrc, /* the FROM clause */ } #endif /* SQLITE_OMIT_BETWEEN_OPTIMIZATION */ -#if !defined(SQLITE_OMIT_OR_OPTIMIZATION) && !defined(SQLITE_OMIT_SUBQUERY) +#if !defined(SQLITE_OMIT_OR_OPTIMIZATION) /* Analyze a term that is composed of two or more subterms connected by * an OR operator. */ diff --git a/test/sql-tap/in1.test.lua b/test/sql-tap/in1.test.lua index 216e0c09b..fb31eb2ec 100755 --- a/test/sql-tap/in1.test.lua +++ b/test/sql-tap/in1.test.lua @@ -107,9 +107,8 @@ test:do_execsql_test( -- }) +-- -- The rest of this file concentrates on testing the IN operator. --- Skip this if the library is compiled with SQLITE_OMIT_SUBQUERY --- (because the IN operator is unavailable). -- -- 2.15.1 (Apple Git-101)