Consider explicit collate clauses when matching WHERE constraints to indices. Fix for #2391. (CVS 4040)
FossilOrigin-Name: f9a95e92dfaaa61ec0a44b9b7017b07929c94d26
This commit is contained in:
+12
-6
@@ -12,7 +12,7 @@
|
||||
** This file contains routines used for analyzing expressions and
|
||||
** for generating VDBE code that evaluates expressions in SQLite.
|
||||
**
|
||||
** $Id: expr.c,v 1.294 2007/05/15 07:00:34 danielk1977 Exp $
|
||||
** $Id: expr.c,v 1.295 2007/05/29 12:11:30 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@@ -171,15 +171,21 @@ static int binaryCompareP1(Expr *pExpr1, Expr *pExpr2, int jumpIfNull){
|
||||
** used. Otherwise the collation sequence for the right hand expression
|
||||
** is used, or the default (BINARY) if neither expression has a collating
|
||||
** type.
|
||||
**
|
||||
** Argument pRight (but not pLeft) may be a null pointer. In this case,
|
||||
** it is not considered.
|
||||
*/
|
||||
static CollSeq* binaryCompareCollSeq(Parse *pParse, Expr *pLeft, Expr *pRight){
|
||||
CollSeq* sqlite3BinaryCompareCollSeq(
|
||||
Parse *pParse,
|
||||
Expr *pLeft,
|
||||
Expr *pRight
|
||||
){
|
||||
CollSeq *pColl;
|
||||
assert( pLeft );
|
||||
assert( pRight );
|
||||
if( pLeft->flags & EP_ExpCollate ){
|
||||
assert( pLeft->pColl );
|
||||
pColl = pLeft->pColl;
|
||||
}else if( pRight->flags & EP_ExpCollate ){
|
||||
}else if( pRight && pRight->flags & EP_ExpCollate ){
|
||||
assert( pRight->pColl );
|
||||
pColl = pRight->pColl;
|
||||
}else{
|
||||
@@ -203,7 +209,7 @@ static int codeCompare(
|
||||
int jumpIfNull /* If true, jump if either operand is NULL */
|
||||
){
|
||||
int p1 = binaryCompareP1(pLeft, pRight, jumpIfNull);
|
||||
CollSeq *p3 = binaryCompareCollSeq(pParse, pLeft, pRight);
|
||||
CollSeq *p3 = sqlite3BinaryCompareCollSeq(pParse, pLeft, pRight);
|
||||
return sqlite3VdbeOp3(pParse->pVdbe, opcode, p1, dest, (void*)p3, P3_COLLSEQ);
|
||||
}
|
||||
|
||||
@@ -1533,7 +1539,7 @@ void sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
|
||||
}
|
||||
pEList = pExpr->pSelect->pEList;
|
||||
if( pEList && pEList->nExpr>0 ){
|
||||
keyInfo.aColl[0] = binaryCompareCollSeq(pParse, pExpr->pLeft,
|
||||
keyInfo.aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft,
|
||||
pEList->a[0].pExpr);
|
||||
}
|
||||
}else if( pExpr->pList ){
|
||||
|
||||
+3
-2
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** Internal interface definitions for SQLite.
|
||||
**
|
||||
** @(#) $Id: sqliteInt.h,v 1.569 2007/05/16 17:28:43 danielk1977 Exp $
|
||||
** @(#) $Id: sqliteInt.h,v 1.570 2007/05/29 12:11:30 danielk1977 Exp $
|
||||
*/
|
||||
#ifndef _SQLITEINT_H_
|
||||
#define _SQLITEINT_H_
|
||||
@@ -1569,7 +1569,7 @@ extern const unsigned char sqlite3UtfTrans1[];
|
||||
** be encoded as a multi-byte character. Any multi-byte character that
|
||||
** attempts to encode a value between 0x00 and 0x7f is rendered as 0xfffd.
|
||||
**
|
||||
** * These macros never allow a UTF16 surragate value to be encoded.
|
||||
** * These macros never allow a UTF16 surrogate value to be encoded.
|
||||
** If a multi-byte character attempts to encode a value between
|
||||
** 0xd800 and 0xe000 then it is rendered as 0xfffd.
|
||||
**
|
||||
@@ -1954,6 +1954,7 @@ FuncDef *sqlite3VtabOverloadFunction(FuncDef*, int nArg, Expr*);
|
||||
void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
|
||||
int sqlite3Reprepare(Vdbe*);
|
||||
void sqlite3ExprListCheckLength(Parse*, ExprList*, int, const char*);
|
||||
CollSeq* sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
|
||||
|
||||
#if SQLITE_MAX_EXPR_DEPTH>0
|
||||
void sqlite3ExprSetHeight(Expr *);
|
||||
|
||||
+10
-8
@@ -16,7 +16,7 @@
|
||||
** so is applicable. Because this module is responsible for selecting
|
||||
** indices, you might also think of this module as the "query optimizer".
|
||||
**
|
||||
** $Id: where.c,v 1.248 2007/05/04 13:15:57 drh Exp $
|
||||
** $Id: where.c,v 1.249 2007/05/29 12:11:30 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -452,15 +452,17 @@ static WhereTerm *findTerm(
|
||||
|
||||
idxaff = pIdx->pTable->aCol[iColumn].affinity;
|
||||
if( !sqlite3IndexAffinityOk(pX, idxaff) ) continue;
|
||||
pColl = sqlite3ExprCollSeq(pParse, pX->pLeft);
|
||||
|
||||
/* Figure out the collation sequence required from an index for
|
||||
** it to be useful for optimising expression pX. Store this
|
||||
** value in variable pColl.
|
||||
*/
|
||||
assert(pX->pLeft);
|
||||
pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
|
||||
if( !pColl ){
|
||||
if( pX->pRight ){
|
||||
pColl = sqlite3ExprCollSeq(pParse, pX->pRight);
|
||||
}
|
||||
if( !pColl ){
|
||||
pColl = pParse->db->pDfltColl;
|
||||
}
|
||||
pColl = pParse->db->pDfltColl;
|
||||
}
|
||||
|
||||
for(j=0; j<pIdx->nColumn && pIdx->aiColumn[j]!=iColumn; j++){}
|
||||
assert( j<pIdx->nColumn );
|
||||
if( sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue;
|
||||
|
||||
Reference in New Issue
Block a user