aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2014-07-31 22:59:04 +0000
committerdrh <drh@noemail.net>2014-07-31 22:59:04 +0000
commit5f1d1d9c870f2377d6907ec05df3c6d38d75cd57 (patch)
tree80aecd60f5713f3cec379e5292dbc9af8f7ad9c1 /src
parent37e08081f3da7ceab00ff4db996510f924de931a (diff)
downloadsqlite-5f1d1d9c870f2377d6907ec05df3c6d38d75cd57.tar.gz
sqlite-5f1d1d9c870f2377d6907ec05df3c6d38d75cd57.zip
Refactoring: Change "pIndex->onError!=OE_None" to use a macro:
"IsUniqueIndex(pIndex)". Easier to understand that way. FossilOrigin-Name: e75b26ee357bb3d3c1a539b05d633ebf314726d7
Diffstat (limited to 'src')
-rw-r--r--src/analyze.c2
-rw-r--r--src/build.c8
-rw-r--r--src/expr.c2
-rw-r--r--src/fkey.c2
-rw-r--r--src/insert.c2
-rw-r--r--src/pragma.c2
-rw-r--r--src/sqliteInt.h3
-rw-r--r--src/where.c8
8 files changed, 16 insertions, 13 deletions
diff --git a/src/analyze.c b/src/analyze.c
index 43aff141b..f9c03dc84 100644
--- a/src/analyze.c
+++ b/src/analyze.c
@@ -1129,7 +1129,7 @@ static void analyzeOneTable(
*/
sqlite3VdbeAddOp0(v, OP_Goto);
addrNextRow = sqlite3VdbeCurrentAddr(v);
- if( nColTest==1 && pIdx->nKeyCol==1 && pIdx->onError!=OE_None ){
+ if( nColTest==1 && pIdx->nKeyCol==1 && IsUniqueIndex(pIdx) ){
/* For a single-column UNIQUE index, once we have found a non-NULL
** row, we know that all the rest will be distinct, so skip
** subsequent distinctness tests. */
diff --git a/src/build.c b/src/build.c
index 384802c53..28205c4c6 100644
--- a/src/build.c
+++ b/src/build.c
@@ -2707,7 +2707,7 @@ static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){
addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
assert( pKey!=0 || db->mallocFailed || pParse->nErr );
- if( pIndex->onError!=OE_None && pKey!=0 ){
+ if( IsUniqueIndex(pIndex) && pKey!=0 ){
int j2 = sqlite3VdbeCurrentAddr(v) + 3;
sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
addr2 = sqlite3VdbeCurrentAddr(v);
@@ -3104,9 +3104,9 @@ Index *sqlite3CreateIndex(
Index *pIdx;
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
int k;
- assert( pIdx->onError!=OE_None );
+ assert( IsUniqueIndex(pIdx) );
assert( pIdx->idxType!=SQLITE_IDXTYPE_APPDEF );
- assert( pIndex->onError!=OE_None );
+ assert( IsUniqueIndex(pIndex) );
if( pIdx->nKeyCol!=pIndex->nKeyCol ) continue;
for(k=0; k<pIdx->nKeyCol; k++){
@@ -3297,7 +3297,7 @@ void sqlite3DefaultRowEst(Index *pIdx){
}
assert( 0==sqlite3LogEst(1) );
- if( pIdx->onError!=OE_None ) a[pIdx->nKeyCol] = 0;
+ if( IsUniqueIndex(pIdx) ) a[pIdx->nKeyCol] = 0;
}
/*
diff --git a/src/expr.c b/src/expr.c
index aa55ff7af..3b254f3d3 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -1604,7 +1604,7 @@ int sqlite3FindInIndex(Parse *pParse, Expr *pX, int *prNotFound){
for(pIdx=pTab->pIndex; pIdx && eType==0 && affinity_ok; pIdx=pIdx->pNext){
if( (pIdx->aiColumn[0]==iCol)
&& sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
- && (!mustBeUnique || (pIdx->nKeyCol==1 && pIdx->onError!=OE_None))
+ && (!mustBeUnique || (pIdx->nKeyCol==1 && IsUniqueIndex(pIdx)))
){
int iAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
sqlite3VdbeAddOp3(v, OP_OpenRead, iTab, pIdx->tnum, iDb);
diff --git a/src/fkey.c b/src/fkey.c
index c3cac276a..50c10da82 100644
--- a/src/fkey.c
+++ b/src/fkey.c
@@ -225,7 +225,7 @@ int sqlite3FkLocateIndex(
}
for(pIdx=pParent->pIndex; pIdx; pIdx=pIdx->pNext){
- if( pIdx->nKeyCol==nCol && pIdx->onError!=OE_None ){
+ if( pIdx->nKeyCol==nCol && IsUniqueIndex(pIdx) ){
/* pIdx is a UNIQUE index (or a PRIMARY KEY) and has the right number
** of columns. If each indexed column corresponds to a foreign key
** column of pFKey, then this index is a winner. */
diff --git a/src/insert.c b/src/insert.c
index 7b427d1eb..5964b91ca 100644
--- a/src/insert.c
+++ b/src/insert.c
@@ -1886,7 +1886,7 @@ static int xferOptimization(
}
}
for(pDestIdx=pDest->pIndex; pDestIdx; pDestIdx=pDestIdx->pNext){
- if( pDestIdx->onError!=OE_None ){
+ if( IsUniqueIndex(pDestIdx) ){
destHasUniqueIdx = 1;
}
for(pSrcIdx=pSrc->pIndex; pSrcIdx; pSrcIdx=pSrcIdx->pNext){
diff --git a/src/pragma.c b/src/pragma.c
index c4374cc71..a4a1b2a25 100644
--- a/src/pragma.c
+++ b/src/pragma.c
@@ -1544,7 +1544,7 @@ void sqlite3Pragma(
for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
sqlite3VdbeAddOp2(v, OP_Integer, i, 1);
sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0, pIdx->zName, 0);
- sqlite3VdbeAddOp2(v, OP_Integer, pIdx->onError!=OE_None, 3);
+ sqlite3VdbeAddOp2(v, OP_Integer, IsUniqueIndex(pIdx), 3);
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
}
}
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 5d72295d6..1aede95c1 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -1720,6 +1720,9 @@ struct Index {
/* Return true if index X is a PRIMARY KEY index */
#define IsPrimaryKeyIndex(X) ((X)->idxType==SQLITE_IDXTYPE_PRIMARYKEY)
+/* Return true if index X is a UNIQUE index */
+#define IsUniqueIndex(X) ((X)->onError!=OE_None)
+
/*
** Each sample stored in the sqlite_stat3 table is represented in memory
** using a structure of this type. See documentation at the top of the
diff --git a/src/where.c b/src/where.c
index 38d1014ac..3cc66a34b 100644
--- a/src/where.c
+++ b/src/where.c
@@ -1470,7 +1470,7 @@ static int isDistinctRedundant(
** contain a "col=X" term are subject to a NOT NULL constraint.
*/
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
- if( pIdx->onError==OE_None ) continue;
+ if( !IsUniqueIndex(pIdx) ) continue;
for(i=0; i<pIdx->nKeyCol; i++){
i16 iCol = pIdx->aiColumn[i];
if( 0==findTerm(pWC, iBase, iCol, ~(Bitmask)0, WO_EQ, pIdx) ){
@@ -4376,7 +4376,7 @@ static int whereLoopAddBtreeIndex(
}else if( eOp & (WO_EQ) ){
pNew->wsFlags |= WHERE_COLUMN_EQ;
if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1) ){
- if( iCol>=0 && pProbe->onError==OE_None ){
+ if( iCol>=0 && !IsUniqueIndex(pProbe) ){
pNew->wsFlags |= WHERE_UNQ_WANTED;
}else{
pNew->wsFlags |= WHERE_ONEROW;
@@ -5231,7 +5231,7 @@ static i8 wherePathSatisfiesOrderBy(
nColumn = pIndex->nColumn;
assert( nColumn==nKeyCol+1 || !HasRowid(pIndex->pTable) );
assert( pIndex->aiColumn[nColumn-1]==(-1) || !HasRowid(pIndex->pTable));
- isOrderDistinct = pIndex->onError!=OE_None;
+ isOrderDistinct = IsUniqueIndex(pIndex);
}
/* Loop through all columns of the index and deal with the ones
@@ -5746,7 +5746,7 @@ static int whereShortCut(WhereLoopBuilder *pBuilder){
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
assert( pLoop->aLTermSpace==pLoop->aLTerm );
assert( ArraySize(pLoop->aLTermSpace)==4 );
- if( pIdx->onError==OE_None
+ if( !IsUniqueIndex(pIdx)
|| pIdx->pPartIdxWhere!=0
|| pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace)
) continue;