aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parse.y28
-rw-r--r--src/select.c28
-rw-r--r--src/sqliteInt.h5
-rw-r--r--src/treeview.c2
-rw-r--r--src/where.c4
-rw-r--r--src/wherecode.c2
-rw-r--r--src/whereexpr.c6
7 files changed, 35 insertions, 40 deletions
diff --git a/src/parse.y b/src/parse.y
index 5b83b16b6..b1c50d750 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -659,7 +659,7 @@ selcollist(A) ::= sclp(A) scanpt STAR. {
}
selcollist(A) ::= sclp(A) scanpt nm(X) DOT STAR. {
Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
- Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &X, 1);
+ Expr *pLeft = tokenExpr(pParse, TK_ID, X);
Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
A = sqlite3ExprListAppend(pParse,A, pDot);
}
@@ -1025,10 +1025,7 @@ idlist(A) ::= nm(Y).
%include {
- /* Construct a new Expr object from a single identifier. Use the
- ** new Expr to populate pOut. Set the span of pOut to be the identifier
- ** that created the expression.
- */
+ /* Construct a new Expr object from a single token */
static Expr *tokenExpr(Parse *pParse, int op, Token t){
Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1);
if( p ){
@@ -1048,6 +1045,7 @@ idlist(A) ::= nm(Y).
p->u.zToken = (char*)&p[1];
memcpy(p->u.zToken, t.z, t.n);
p->u.zToken[t.n] = 0;
+ p->w.iOfst = (int)(t.z - pParse->zTail);
if( sqlite3Isquote(p->u.zToken[0]) ){
sqlite3DequoteExpr(p);
}
@@ -1068,23 +1066,15 @@ expr(A) ::= LP expr(X) RP. {A = X;}
expr(A) ::= id(X). {A=tokenExpr(pParse,TK_ID,X); /*A-overwrites-X*/}
expr(A) ::= JOIN_KW(X). {A=tokenExpr(pParse,TK_ID,X); /*A-overwrites-X*/}
expr(A) ::= nm(X) DOT nm(Y). {
- Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &X, 1);
- Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &Y, 1);
- if( IN_RENAME_OBJECT ){
- sqlite3RenameTokenMap(pParse, (void*)temp2, &Y);
- sqlite3RenameTokenMap(pParse, (void*)temp1, &X);
- }
+ Expr *temp1 = tokenExpr(pParse,TK_ID,X);
+ Expr *temp2 = tokenExpr(pParse,TK_ID,Y);
A = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
}
expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). {
- Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &X, 1);
- Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &Y, 1);
- Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &Z, 1);
+ Expr *temp1 = tokenExpr(pParse,TK_ID,X);
+ Expr *temp2 = tokenExpr(pParse,TK_ID,Y);
+ Expr *temp3 = tokenExpr(pParse,TK_ID,Z);
Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
- if( IN_RENAME_OBJECT ){
- sqlite3RenameTokenMap(pParse, (void*)temp3, &Z);
- sqlite3RenameTokenMap(pParse, (void*)temp2, &Y);
- }
A = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
}
term(A) ::= NULL|FLOAT|BLOB(X). {A=tokenExpr(pParse,@X,X); /*A-overwrites-X*/}
@@ -1593,7 +1583,7 @@ expr(A) ::= RAISE LP IGNORE RP. {
}
}
expr(A) ::= RAISE LP raisetype(T) COMMA nm(Z) RP. {
- A = sqlite3ExprAlloc(pParse->db, TK_RAISE, &Z, 1);
+ A = sqlite3ExprAlloc(pParse->db, TK_RAISE, &Z, 1);
if( A ) {
A->affExpr = (char)T;
}
diff --git a/src/select.c b/src/select.c
index a3985b70a..6719d4747 100644
--- a/src/select.c
+++ b/src/select.c
@@ -354,14 +354,14 @@ static void addWhereTerm(
ExprSetProperty(pEq, EP_FromJoin);
assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
ExprSetVVAProperty(pEq, EP_NoReduce);
- pEq->iRightJoinTable = pE2->iTable;
+ pEq->w.iRightJoinTable = pE2->iTable;
}
*ppWhere = sqlite3ExprAnd(pParse, *ppWhere, pEq);
}
/*
** Set the EP_FromJoin property on all terms of the given expression.
-** And set the Expr.iRightJoinTable to iTable for every term in the
+** And set the Expr.w.iRightJoinTable to iTable for every term in the
** expression.
**
** The EP_FromJoin property is used on terms of an expression to tell
@@ -371,8 +371,8 @@ static void addWhereTerm(
** WHERE clause during join processing but we need to remember that they
** originated in the ON or USING clause.
**
-** The Expr.iRightJoinTable tells the WHERE clause processing that the
-** expression depends on table iRightJoinTable even if that table is not
+** The Expr.w.iRightJoinTable tells the WHERE clause processing that the
+** expression depends on table w.iRightJoinTable even if that table is not
** explicitly mentioned in the expression. That information is needed
** for cases like this:
**
@@ -390,7 +390,7 @@ void sqlite3SetJoinExpr(Expr *p, int iTable){
ExprSetProperty(p, EP_FromJoin);
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
ExprSetVVAProperty(p, EP_NoReduce);
- p->iRightJoinTable = iTable;
+ p->w.iRightJoinTable = iTable;
if( p->op==TK_FUNCTION ){
assert( ExprUseXList(p) );
if( p->x.pList ){
@@ -406,7 +406,7 @@ void sqlite3SetJoinExpr(Expr *p, int iTable){
}
/* Undo the work of sqlite3SetJoinExpr(). In the expression p, convert every
-** term that is marked with EP_FromJoin and iRightJoinTable==iTable into
+** term that is marked with EP_FromJoin and w.iRightJoinTable==iTable into
** an ordinary term that omits the EP_FromJoin mark.
**
** This happens when a LEFT JOIN is simplified into an ordinary JOIN.
@@ -414,7 +414,7 @@ void sqlite3SetJoinExpr(Expr *p, int iTable){
static void unsetJoinExpr(Expr *p, int iTable){
while( p ){
if( ExprHasProperty(p, EP_FromJoin)
- && (iTable<0 || p->iRightJoinTable==iTable) ){
+ && (iTable<0 || p->w.iRightJoinTable==iTable) ){
ExprClearProperty(p, EP_FromJoin);
}
if( p->op==TK_COLUMN && p->iTable==iTable ){
@@ -3648,9 +3648,9 @@ static Expr *substExpr(
){
if( pExpr==0 ) return 0;
if( ExprHasProperty(pExpr, EP_FromJoin)
- && pExpr->iRightJoinTable==pSubst->iTable
+ && pExpr->w.iRightJoinTable==pSubst->iTable
){
- pExpr->iRightJoinTable = pSubst->iNewTable;
+ pExpr->w.iRightJoinTable = pSubst->iNewTable;
}
if( pExpr->op==TK_COLUMN
&& pExpr->iTable==pSubst->iTable
@@ -3689,7 +3689,7 @@ static Expr *substExpr(
ExprSetProperty(pNew, EP_CanBeNull);
}
if( ExprHasProperty(pExpr,EP_FromJoin) ){
- sqlite3SetJoinExpr(pNew, pExpr->iRightJoinTable);
+ sqlite3SetJoinExpr(pNew, pExpr->w.iRightJoinTable);
}
sqlite3ExprDelete(db, pExpr);
pExpr = pNew;
@@ -3854,7 +3854,7 @@ static int renumberCursorsCb(Walker *pWalker, Expr *pExpr){
renumberCursorDoMapping(pWalker, &pExpr->iTable);
}
if( ExprHasProperty(pExpr, EP_FromJoin) ){
- renumberCursorDoMapping(pWalker, &pExpr->iRightJoinTable);
+ renumberCursorDoMapping(pWalker, &pExpr->w.iRightJoinTable);
}
return WRC_Continue;
}
@@ -4864,11 +4864,13 @@ static int pushDownWhereTerms(
}
if( isLeftJoin
&& (ExprHasProperty(pWhere,EP_FromJoin)==0
- || pWhere->iRightJoinTable!=iCursor)
+ || pWhere->w.iRightJoinTable!=iCursor)
){
return 0; /* restriction (4) */
}
- if( ExprHasProperty(pWhere,EP_FromJoin) && pWhere->iRightJoinTable!=iCursor ){
+ if( ExprHasProperty(pWhere,EP_FromJoin)
+ && pWhere->w.iRightJoinTable!=iCursor
+ ){
return 0; /* restriction (5) */
}
if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 374fc9554..58fe64ea0 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -2824,7 +2824,10 @@ struct Expr {
** TK_VARIABLE: variable number (always >= 1).
** TK_SELECT_COLUMN: column of the result vector */
i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
- int iRightJoinTable; /* If EP_FromJoin, the right table of the join */
+ union {
+ int iRightJoinTable; /* If EP_FromJoin, the right table of the join */
+ int iOfst; /* else: start of token from start of statement */
+ } w;
AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
union {
Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL
diff --git a/src/treeview.c b/src/treeview.c
index 1b19ea679..86f06e832 100644
--- a/src/treeview.c
+++ b/src/treeview.c
@@ -412,7 +412,7 @@ void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
sqlite3_str_appendf(&x, " fg.af=%x.%c",
pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n');
if( ExprHasProperty(pExpr, EP_FromJoin) ){
- sqlite3_str_appendf(&x, " iRJT=%d", pExpr->iRightJoinTable);
+ sqlite3_str_appendf(&x, " iRJT=%d", pExpr->w.iRightJoinTable);
}
if( ExprHasProperty(pExpr, EP_FromDDL) ){
sqlite3_str_appendf(&x, " DDL");
diff --git a/src/where.c b/src/where.c
index bd4278977..41acbe39d 100644
--- a/src/where.c
+++ b/src/where.c
@@ -3166,7 +3166,7 @@ static int whereUsablePartialIndex(
for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
Expr *pExpr;
pExpr = pTerm->pExpr;
- if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
+ if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->w.iRightJoinTable==iTab)
&& (isLeft==0 || ExprHasProperty(pExpr, EP_FromJoin))
&& sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
&& (pTerm->wtFlags & TERM_VNULL)==0
@@ -5146,7 +5146,7 @@ static SQLITE_NOINLINE Bitmask whereOmitNoopJoin(
for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){
if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
if( !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
- || pTerm->pExpr->iRightJoinTable!=pItem->iCursor
+ || pTerm->pExpr->w.iRightJoinTable!=pItem->iCursor
){
break;
}
diff --git a/src/wherecode.c b/src/wherecode.c
index 603fcdfd7..79504159a 100644
--- a/src/wherecode.c
+++ b/src/wherecode.c
@@ -1062,7 +1062,7 @@ static void codeCursorHint(
if( pTabItem->fg.jointype & JT_LEFT ){
Expr *pExpr = pTerm->pExpr;
if( !ExprHasProperty(pExpr, EP_FromJoin)
- || pExpr->iRightJoinTable!=pTabItem->iCursor
+ || pExpr->w.iRightJoinTable!=pTabItem->iCursor
){
sWalker.eCode = 0;
sWalker.xExprCallback = codeCursorHintIsOrFunction;
diff --git a/src/whereexpr.c b/src/whereexpr.c
index ac4f2e1fb..bcc7bebeb 100644
--- a/src/whereexpr.c
+++ b/src/whereexpr.c
@@ -466,7 +466,7 @@ static int isAuxiliaryVtabOperator(
static void transferJoinMarkings(Expr *pDerived, Expr *pBase){
if( pDerived ){
pDerived->flags |= pBase->flags & EP_FromJoin;
- pDerived->iRightJoinTable = pBase->iRightJoinTable;
+ pDerived->w.iRightJoinTable = pBase->w.iRightJoinTable;
}
}
@@ -1111,7 +1111,7 @@ static void exprAnalyze(
#endif
if( ExprHasProperty(pExpr, EP_FromJoin) ){
- Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->iRightJoinTable);
+ Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->w.iRightJoinTable);
prereqAll |= x;
extraRight = x-1; /* ON clause terms may not be used with an index
** on left table of a LEFT JOIN. Ticket #3015 */
@@ -1462,7 +1462,7 @@ static void exprAnalyze(
0, sqlite3ExprDup(db, pRight, 0));
if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){
ExprSetProperty(pNewExpr, EP_FromJoin);
- pNewExpr->iRightJoinTable = pExpr->iRightJoinTable;
+ pNewExpr->w.iRightJoinTable = pExpr->w.iRightJoinTable;
}
idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
testcase( idxNew==0 );