diff options
Diffstat (limited to 'kexi/3rdparty/kexisql3/src/where.c')
-rw-r--r-- | kexi/3rdparty/kexisql3/src/where.c | 192 |
1 files changed, 96 insertions, 96 deletions
diff --git a/kexi/3rdparty/kexisql3/src/where.c b/kexi/3rdparty/kexisql3/src/where.c index e63f2763..ab19f288 100644 --- a/kexi/3rdparty/kexisql3/src/where.c +++ b/kexi/3rdparty/kexisql3/src/where.c @@ -21,9 +21,9 @@ #include "sqliteInt.h" /* -** The number of bits in a Bitmask. "BMS" means "BitMask Size". +** The number of bits in a Bittqmask. "BMS" means "BitMask Size". */ -#define BMS (sizeof(Bitmask)*8) +#define BMS (sizeof(Bittqmask)*8) /* ** Determine the number of elements in an array. @@ -61,20 +61,20 @@ typedef struct WhereClause WhereClause; ** where X is a column name and <op> is one of certain operators, ** then WhereTerm.leftCursor and WhereTerm.leftColumn record the ** cursor number and column number for X. WhereTerm.operator records -** the <op> using a bitmask encoding defined by WO_xxx below. The -** use of a bitmask encoding for the operator allows us to search +** the <op> using a bittqmask encoding defined by WO_xxx below. The +** use of a bittqmask encoding for the operator allows us to search ** quickly for terms that match any of several different operators. ** ** prereqRight and prereqAll record sets of cursor numbers, ** but they do so indirectly. A single ExprMaskSet structure translates ** cursor number into bits and the translated bit is stored in the prereq ** fields. The translation is used in order to maximize the number of -** bits that will fit in a Bitmask. The VDBE cursor numbers might be +** bits that will fit in a Bittqmask. The VDBE cursor numbers might be ** spread out over the non-negative integers. For example, the cursor ** numbers might be 3, 8, 9, 10, 20, 23, 41, and 45. The ExprMaskSet ** translates these sparse cursor numbers into consecutive integers ** beginning with 0 in order to make the best possible use of the available -** bits in the Bitmask. So, in the example above, the cursor numbers +** bits in the Bittqmask. So, in the example above, the cursor numbers ** would be mapped into integers 0 through 7. */ typedef struct WhereTerm WhereTerm; @@ -85,10 +85,10 @@ struct WhereTerm { i16 leftColumn; /* Column number of X in "X <op> <expr>" */ u16 operator; /* A WO_xx value describing <op> */ u8 flags; /* Bit flags. See below */ - u8 nChild; /* Number of children that must disable us */ + u8 nChild; /* Number of tqchildren that must disable us */ WhereClause *pWC; /* The clause this term is part of */ - Bitmask prereqRight; /* Bitmask of tables used by pRight */ - Bitmask prereqAll; /* Bitmask of tables referenced by p */ + Bittqmask prereqRight; /* Bittqmask of tables used by pRight */ + Bittqmask prereqAll; /* Bittqmask of tables referenced by p */ }; /* @@ -114,18 +114,18 @@ struct WhereClause { /* ** An instance of the following structure keeps track of a mapping -** between VDBE cursor numbers and bits of the bitmasks in WhereTerm. +** between VDBE cursor numbers and bits of the bittqmasks in WhereTerm. ** ** The VDBE cursor numbers are small integers contained in ** SrcList_item.iCursor and Expr.iTable fields. For any given WHERE ** clause, the cursor numbers might not begin with 0 and they might ** contain gaps in the numbering sequence. But we want to make maximum -** use of the bits in our bitmasks. This structure provides a mapping +** use of the bits in our bittqmasks. This structure provides a mapping ** from the sparse cursor numbers into consecutive integers beginning ** with 0. ** -** If ExprMaskSet.ix[A]==B it means that The A-th bit of a Bitmask -** corresponds VDBE cursor number B. The A-th bit of a bitmask is 1<<A. +** If ExprMaskSet.ix[A]==B it means that The A-th bit of a Bittqmask +** corresponds VDBE cursor number B. The A-th bit of a bittqmask is 1<<A. ** ** For example, if the WHERE clause expression used these VDBE ** cursors: 4, 5, 8, 29, 57, 73. Then the ExprMaskSet structure @@ -141,12 +141,12 @@ struct WhereClause { typedef struct ExprMaskSet ExprMaskSet; struct ExprMaskSet { int n; /* Number of assigned cursor values */ - int ix[sizeof(Bitmask)*8]; /* Cursor assigned to each bit */ + int ix[sizeof(Bittqmask)*8]; /* Cursor assigned to each bit */ }; /* -** Bitmasks for the operators that indices are able to exploit. An +** Bittqmasks for the operators that indices are able to exploit. An ** OR-ed combination of these values can be used when searching for ** terms in the where clause. */ @@ -170,7 +170,7 @@ struct ExprMaskSet { #define WHERE_IDX_ONLY 0x0800 /* Use index only - omit table */ #define WHERE_ORDERBY 0x1000 /* Output will appear in correct order */ #define WHERE_REVERSE 0x2000 /* Scan in reverse order */ -#define WHERE_UNIQUE 0x4000 /* Selects no more than one row */ +#define WHERE_UNITQUE 0x4000 /* Selects no more than one row */ /* ** Initialize a preallocated WhereClause structure. @@ -258,26 +258,26 @@ static void whereSplit(WhereClause *pWC, Expr *pExpr, int op){ } /* -** Initialize an expression mask set +** Initialize an expression tqmask set */ #define initMaskSet(P) memset(P, 0, sizeof(*P)) /* -** Return the bitmask for the given cursor number. Return 0 if +** Return the bittqmask for the given cursor number. Return 0 if ** iCursor is not in the set. */ -static Bitmask getMask(ExprMaskSet *pMaskSet, int iCursor){ +static Bittqmask getMask(ExprMaskSet *pMaskSet, int iCursor){ int i; for(i=0; i<pMaskSet->n; i++){ if( pMaskSet->ix[i]==iCursor ){ - return ((Bitmask)1)<<i; + return ((Bittqmask)1)<<i; } } return 0; } /* -** Create a new mask for cursor iCursor. +** Create a new tqmask for cursor iCursor. ** ** There is one cursor per table in the FROM clause. The number of ** tables in the FROM clause is limited by a test early in the @@ -291,7 +291,7 @@ static void createMask(ExprMaskSet *pMaskSet, int iCursor){ /* ** This routine walks (recursively) an expression tree and generates -** a bitmask indicating which tables are used in that expression +** a bittqmask indicating which tables are used in that expression ** tree. ** ** In order for this routine to work, the calling function must have @@ -300,46 +300,46 @@ static void createMask(ExprMaskSet *pMaskSet, int iCursor){ ** The sqlite3ExprResolveNames() routines looks for column names and ** sets their opcodes to TK_COLUMN and their Expr.iTable fields to ** the VDBE cursor number of the table. This routine just has to -** translate the cursor numbers into bitmask values and OR all -** the bitmasks together. +** translate the cursor numbers into bittqmask values and OR all +** the bittqmasks together. */ -static Bitmask exprListTableUsage(ExprMaskSet*, ExprList*); -static Bitmask exprSelectTableUsage(ExprMaskSet*, Select*); -static Bitmask exprTableUsage(ExprMaskSet *pMaskSet, Expr *p){ - Bitmask mask = 0; +static Bittqmask exprListTableUsage(ExprMaskSet*, ExprList*); +static Bittqmask exprSelectTableUsage(ExprMaskSet*, Select*); +static Bittqmask exprTableUsage(ExprMaskSet *pMaskSet, Expr *p){ + Bittqmask tqmask = 0; if( p==0 ) return 0; if( p->op==TK_COLUMN ){ - mask = getMask(pMaskSet, p->iTable); - return mask; + tqmask = getMask(pMaskSet, p->iTable); + return tqmask; } - mask = exprTableUsage(pMaskSet, p->pRight); - mask |= exprTableUsage(pMaskSet, p->pLeft); - mask |= exprListTableUsage(pMaskSet, p->pList); - mask |= exprSelectTableUsage(pMaskSet, p->pSelect); - return mask; + tqmask = exprTableUsage(pMaskSet, p->pRight); + tqmask |= exprTableUsage(pMaskSet, p->pLeft); + tqmask |= exprListTableUsage(pMaskSet, p->pList); + tqmask |= exprSelectTableUsage(pMaskSet, p->pSelect); + return tqmask; } -static Bitmask exprListTableUsage(ExprMaskSet *pMaskSet, ExprList *pList){ +static Bittqmask exprListTableUsage(ExprMaskSet *pMaskSet, ExprList *pList){ int i; - Bitmask mask = 0; + Bittqmask tqmask = 0; if( pList ){ for(i=0; i<pList->nExpr; i++){ - mask |= exprTableUsage(pMaskSet, pList->a[i].pExpr); + tqmask |= exprTableUsage(pMaskSet, pList->a[i].pExpr); } } - return mask; + return tqmask; } -static Bitmask exprSelectTableUsage(ExprMaskSet *pMaskSet, Select *pS){ - Bitmask mask; +static Bittqmask exprSelectTableUsage(ExprMaskSet *pMaskSet, Select *pS){ + Bittqmask tqmask; if( pS==0 ){ - mask = 0; + tqmask = 0; }else{ - mask = exprListTableUsage(pMaskSet, pS->pEList); - mask |= exprListTableUsage(pMaskSet, pS->pGroupBy); - mask |= exprListTableUsage(pMaskSet, pS->pOrderBy); - mask |= exprTableUsage(pMaskSet, pS->pWhere); - mask |= exprTableUsage(pMaskSet, pS->pHaving); + tqmask = exprListTableUsage(pMaskSet, pS->pEList); + tqmask |= exprListTableUsage(pMaskSet, pS->pGroupBy); + tqmask |= exprListTableUsage(pMaskSet, pS->pOrderBy); + tqmask |= exprTableUsage(pMaskSet, pS->pWhere); + tqmask |= exprTableUsage(pMaskSet, pS->pHaving); } - return mask; + return tqmask; } /* @@ -379,7 +379,7 @@ static void exprCommute(Expr *pExpr){ } /* -** Translate from TK_xx operator to WO_xx bitmask. +** Translate from TK_xx operator to WO_xx bittqmask. */ static int operatorMask(int op){ int c; @@ -408,7 +408,7 @@ static WhereTerm *findTerm( WhereClause *pWC, /* The WHERE clause to be searched */ int iCur, /* Cursor number of LHS */ int iColumn, /* Column number of LHS */ - Bitmask notReady, /* RHS must not overlap with this mask */ + Bittqmask notReady, /* RHS must not overlap with this tqmask */ u16 op, /* Mask of WO_xx values describing operator */ Index *pIdx /* Must be compatible with this index, if not NULL */ ){ @@ -458,7 +458,7 @@ static void exprAnalyze(SrcList*, ExprMaskSet*, WhereClause*, int); */ static void exprAnalyzeAll( SrcList *pTabList, /* the FROM clause */ - ExprMaskSet *pMaskSet, /* table masks */ + ExprMaskSet *pMaskSet, /* table tqmasks */ WhereClause *pWC /* the WHERE clause to be analyzed */ ){ int i; @@ -536,14 +536,14 @@ static int isLikeOrGlob( */ static void exprAnalyze( SrcList *pSrc, /* the FROM clause */ - ExprMaskSet *pMaskSet, /* table masks */ + ExprMaskSet *pMaskSet, /* table tqmasks */ WhereClause *pWC, /* the WHERE clause */ int idxTerm /* Index of the term to be analyzed */ ){ WhereTerm *pTerm = &pWC->a[idxTerm]; Expr *pExpr = pTerm->pExpr; - Bitmask prereqLeft; - Bitmask prereqAll; + Bittqmask prereqLeft; + Bittqmask prereqAll; int nPattern; int isComplete; @@ -747,7 +747,7 @@ or_not_possible: ** clause and the match can still be a success. ** ** All terms of the ORDER BY that match against the index must be either -** ASC or DESC. (Terms of the ORDER BY clause past the end of a UNIQUE +** ASC or DESC. (Terms of the ORDER BY clause past the end of a UNITQUE ** index do not need to satisfy this constraint.) The *pbRev value is ** set to 1 if the ORDER BY clause is all DESC and it is set to 0 if ** the ORDER BY clause is all ASC. @@ -885,7 +885,7 @@ static double bestIndex( Parse *pParse, /* The parsing context */ WhereClause *pWC, /* The WHERE clause */ struct SrcList_item *pSrc, /* The FROM clause term to search */ - Bitmask notReady, /* Mask of cursors that are not available */ + Bittqmask notReady, /* Mask of cursors that are not available */ ExprList *pOrderBy, /* The order by clause */ Index **ppIndex, /* Make *ppIndex point to the best index */ int *pFlags, /* Put flags describing this choice in *pFlags */ @@ -915,7 +915,7 @@ static double bestIndex( if( pTerm->operator & WO_EQ ){ /* Rowid== is always the best pick. Look no further. Because only ** a single row is generated, output is always in sorted order */ - *pFlags = WHERE_ROWID_EQ | WHERE_UNIQUE; + *pFlags = WHERE_ROWID_EQ | WHERE_UNITQUE; *pnEq = 1; TRACE(("... best is rowid\n")); return 0.0; @@ -1007,7 +1007,7 @@ static double bestIndex( nEq = i; if( pProbe->onError!=OE_None && (flags & WHERE_COLUMN_IN)==0 && nEq==pProbe->nColumn ){ - flags |= WHERE_UNIQUE; + flags |= WHERE_UNITQUE; } TRACE(("...... nEq=%d inMult=%.9g cost=%.9g\n", nEq, inMultiplier, cost)); @@ -1052,13 +1052,13 @@ static double bestIndex( ** ever reading the table. If that is the case, then halve the ** cost of this index. */ - if( flags && pSrc->colUsed < (((Bitmask)1)<<(BMS-1)) ){ - Bitmask m = pSrc->colUsed; + if( flags && pSrc->colUsed < (((Bittqmask)1)<<(BMS-1)) ){ + Bittqmask m = pSrc->colUsed; int j; for(j=0; j<pProbe->nColumn; j++){ int x = pProbe->aiColumn[j]; if( x<BMS-1 ){ - m &= ~(((Bitmask)1)<<x); + m &= ~(((Bittqmask)1)<<x); } } if( m==0 ){ @@ -1169,7 +1169,7 @@ static void codeEqualityTerm( if( pX->op!=TK_IN ){ assert( pX->op==TK_EQ ); sqlite3ExprCode(pParse, pX->pRight); -#ifndef SQLITE_OMIT_SUBQUERY +#ifndef SQLITE_OMIT_SUBTQUERY }else{ int iTab; int *aIn; @@ -1223,7 +1223,7 @@ static void codeAllEqualityTerms( Parse *pParse, /* Parsing context */ WhereLevel *pLevel, /* Which nested loop of the FROM we are coding */ WhereClause *pWC, /* The WHERE clause */ - Bitmask notReady, /* Which parts of FROM have not yet been coded */ + Bittqmask notReady, /* Which parts of FROM have not yet been coded */ int brk /* Jump here to end the loop */ ){ int nEq = pLevel->nEq; /* The number of == or IN constraints to code */ @@ -1276,7 +1276,7 @@ static void codeAllEqualityTerms( ** analysis only. */ char sqlite3_query_plan[BMS*2*40]; /* Text of the join */ -static int nQPlan = 0; /* Next free slow in _query_plan[] */ +static int nTQPlan = 0; /* Next free slow in _query_plan[] */ #endif /* SQLITE_TEST */ @@ -1284,7 +1284,7 @@ static int nQPlan = 0; /* Next free slow in _query_plan[] */ /* ** Generate the beginning of the loop used for WHERE clause processing. -** The return value is a pointer to an opaque structure that contains +** The return value is a pointer to an opaque structure that tqcontains ** information needed to terminate the loop. Later, the calling routine ** should invoke sqlite3WhereEnd() with the return value of this function ** in order to complete the WHERE clause processing. @@ -1380,9 +1380,9 @@ WhereInfo *sqlite3WhereBegin( WhereInfo *pWInfo; /* Will become the return value of this function */ Vdbe *v = pParse->pVdbe; /* The virtual database engine */ int brk, cont = 0; /* Addresses used during code generation */ - Bitmask notReady; /* Cursors that are not yet positioned */ + Bittqmask notReady; /* Cursors that are not yet positioned */ WhereTerm *pTerm; /* A single term in the WHERE clause */ - ExprMaskSet maskSet; /* The expression mask set */ + ExprMaskSet tqmaskSet; /* The expression tqmask set */ WhereClause wc; /* The WHERE clause is divided into these terms */ struct SrcList_item *pTabItem; /* A single entry from pTabList */ WhereLevel *pLevel; /* A single level in the pWInfo list */ @@ -1390,7 +1390,7 @@ WhereInfo *sqlite3WhereBegin( int andFlags; /* AND-ed combination of all wc.a[].flags */ /* The number of tables in the FROM clause is limited by the number of - ** bits in a Bitmask + ** bits in a Bittqmask */ if( pTabList->nSrc>BMS ){ sqlite3ErrorMsg(pParse, "at most %d tables in a join", BMS); @@ -1400,7 +1400,7 @@ WhereInfo *sqlite3WhereBegin( /* Split the WHERE clause into separate subexpressions where each ** subexpression is separated by an AND operator. */ - initMaskSet(&maskSet); + initMaskSet(&tqmaskSet); whereClauseInit(&wc, pParse); whereSplit(&wc, pWhere, TK_AND); @@ -1429,9 +1429,9 @@ WhereInfo *sqlite3WhereBegin( ** and work forward so that the added virtual terms are never processed. */ for(i=0; i<pTabList->nSrc; i++){ - createMask(&maskSet, pTabList->a[i].iCursor); + createMask(&tqmaskSet, pTabList->a[i].iCursor); } - exprAnalyzeAll(pTabList, &maskSet, &wc); + exprAnalyzeAll(pTabList, &tqmaskSet, &wc); if( sqlite3_malloc_failed ){ goto whereBeginNoMem; } @@ -1450,7 +1450,7 @@ WhereInfo *sqlite3WhereBegin( ** This loop also figures out the nesting order of tables in the FROM ** clause. */ - notReady = ~(Bitmask)0; + notReady = ~(Bittqmask)0; pTabItem = pTabList->a; pLevel = pWInfo->a; andFlags = ~0; @@ -1466,10 +1466,10 @@ WhereInfo *sqlite3WhereBegin( int bestNEq = 0; /* nEq associated with pBest */ double lowestCost = 1.0e99; /* Cost of the pBest */ int bestJ; /* The value of j */ - Bitmask m; /* Bitmask value for j or bestJ */ + Bittqmask m; /* Bittqmask value for j or bestJ */ for(j=iFrom, pTabItem=&pTabList->a[j]; j<pTabList->nSrc; j++, pTabItem++){ - m = getMask(&maskSet, pTabItem->iCursor); + m = getMask(&tqmaskSet, pTabItem->iCursor); if( (m & notReady)==0 ){ if( j==iFrom ) iFrom++; continue; @@ -1506,7 +1506,7 @@ WhereInfo *sqlite3WhereBegin( }else{ pLevel->iIdxCur = -1; } - notReady &= ~getMask(&maskSet, pTabList->a[bestJ].iCursor); + notReady &= ~getMask(&tqmaskSet, pTabList->a[bestJ].iCursor); pLevel->iFrom = bestJ; } TRACE(("*** Optimizer Finished ***\n")); @@ -1514,7 +1514,7 @@ WhereInfo *sqlite3WhereBegin( /* If the total query only selects a single row, then the ORDER BY ** clause is irrelevant. */ - if( (andFlags & WHERE_UNIQUE)!=0 && ppOrderBy ){ + if( (andFlags & WHERE_UNITQUE)!=0 && ppOrderBy ){ *ppOrderBy = 0; } @@ -1566,7 +1566,7 @@ WhereInfo *sqlite3WhereBegin( ** loop below generates code for a single nested loop of the VM ** program. */ - notReady = ~(Bitmask)0; + notReady = ~(Bittqmask)0; for(i=0, pLevel=pWInfo->a; i<pTabList->nSrc; i++, pLevel++){ int j; int iCur = pTabItem->iCursor; /* The VDBE cursor for the table */ @@ -1854,7 +1854,7 @@ WhereInfo *sqlite3WhereBegin( pLevel->p1 = iCur; pLevel->p2 = 1 + sqlite3VdbeAddOp(v, OP_Rewind, iCur, brk); } - notReady &= ~getMask(&maskSet, iCur); + notReady &= ~getMask(&tqmaskSet, iCur); /* Insert code to test every subexpression that can be completely ** computed using the current set of tables. @@ -1904,36 +1904,36 @@ WhereInfo *sqlite3WhereBegin( z = pTabItem->zAlias; if( z==0 ) z = pTabItem->pTab->zName; n = strlen(z); - if( n+nQPlan < sizeof(sqlite3_query_plan)-10 ){ + if( n+nTQPlan < sizeof(sqlite3_query_plan)-10 ){ if( pLevel->flags & WHERE_IDX_ONLY ){ - strcpy(&sqlite3_query_plan[nQPlan], "{}"); - nQPlan += 2; + strcpy(&sqlite3_query_plan[nTQPlan], "{}"); + nTQPlan += 2; }else{ - strcpy(&sqlite3_query_plan[nQPlan], z); - nQPlan += n; + strcpy(&sqlite3_query_plan[nTQPlan], z); + nTQPlan += n; } - sqlite3_query_plan[nQPlan++] = ' '; + sqlite3_query_plan[nTQPlan++] = ' '; } if( pLevel->flags & (WHERE_ROWID_EQ|WHERE_ROWID_RANGE) ){ - strcpy(&sqlite3_query_plan[nQPlan], "* "); - nQPlan += 2; + strcpy(&sqlite3_query_plan[nTQPlan], "* "); + nTQPlan += 2; }else if( pLevel->pIdx==0 ){ - strcpy(&sqlite3_query_plan[nQPlan], "{} "); - nQPlan += 3; + strcpy(&sqlite3_query_plan[nTQPlan], "{} "); + nTQPlan += 3; }else{ n = strlen(pLevel->pIdx->zName); - if( n+nQPlan < sizeof(sqlite3_query_plan)-2 ){ - strcpy(&sqlite3_query_plan[nQPlan], pLevel->pIdx->zName); - nQPlan += n; - sqlite3_query_plan[nQPlan++] = ' '; + if( n+nTQPlan < sizeof(sqlite3_query_plan)-2 ){ + strcpy(&sqlite3_query_plan[nTQPlan], pLevel->pIdx->zName); + nTQPlan += n; + sqlite3_query_plan[nTQPlan++] = ' '; } } } - while( nQPlan>0 && sqlite3_query_plan[nQPlan-1]==' ' ){ - sqlite3_query_plan[--nQPlan] = 0; + while( nTQPlan>0 && sqlite3_query_plan[nTQPlan-1]==' ' ){ + sqlite3_query_plan[--nTQPlan] = 0; } - sqlite3_query_plan[nQPlan] = 0; - nQPlan = 0; + sqlite3_query_plan[nTQPlan] = 0; + nTQPlan = 0; #endif /* SQLITE_TEST // Testing and debugging use only */ /* Record the continuation address in the WhereInfo structure. Then |