mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-18 10:21:03 +03:00
Enable bloom filters for the right table of a LEFT JOIN. Fix unreachable
branches. FossilOrigin-Name: d342ab722de1fc3f34219c9755253db9d88eb50a6fa5cc257207008b00e7fc03
This commit is contained in:
@@ -236,42 +236,37 @@ int sqlite3WhereExplainBloomFilter(
|
||||
const WhereLevel *pLevel /* Bloom filter on this level */
|
||||
){
|
||||
int ret = 0;
|
||||
#if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS)
|
||||
if( sqlite3ParseToplevel(pParse)->explain==2 )
|
||||
#endif
|
||||
{
|
||||
SrcItem *pItem = &pWInfo->pTabList->a[pLevel->iFrom];
|
||||
Vdbe *v = pParse->pVdbe; /* VM being constructed */
|
||||
sqlite3 *db = pParse->db; /* Database handle */
|
||||
char *zMsg; /* Text to add to EQP output */
|
||||
int i; /* Loop counter */
|
||||
WhereLoop *pLoop; /* The where loop */
|
||||
StrAccum str; /* EQP output string */
|
||||
char zBuf[100]; /* Initial space for EQP output string */
|
||||
SrcItem *pItem = &pWInfo->pTabList->a[pLevel->iFrom];
|
||||
Vdbe *v = pParse->pVdbe; /* VM being constructed */
|
||||
sqlite3 *db = pParse->db; /* Database handle */
|
||||
char *zMsg; /* Text to add to EQP output */
|
||||
int i; /* Loop counter */
|
||||
WhereLoop *pLoop; /* The where loop */
|
||||
StrAccum str; /* EQP output string */
|
||||
char zBuf[100]; /* Initial space for EQP output string */
|
||||
|
||||
sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
|
||||
str.printfFlags = SQLITE_PRINTF_INTERNAL;
|
||||
sqlite3_str_appendf(&str, "BLOOM FILTER ON %S (", pItem);
|
||||
pLoop = pLevel->pWLoop;
|
||||
if( pLoop->wsFlags & WHERE_IPK ){
|
||||
const Table *pTab = pItem->pTab;
|
||||
if( pTab->iPKey>=0 ){
|
||||
sqlite3_str_appendf(&str, "%s=?", pTab->aCol[pTab->iPKey].zCnName);
|
||||
}else{
|
||||
sqlite3_str_appendf(&str, "rowid=?");
|
||||
}
|
||||
sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
|
||||
str.printfFlags = SQLITE_PRINTF_INTERNAL;
|
||||
sqlite3_str_appendf(&str, "BLOOM FILTER ON %S (", pItem);
|
||||
pLoop = pLevel->pWLoop;
|
||||
if( pLoop->wsFlags & WHERE_IPK ){
|
||||
const Table *pTab = pItem->pTab;
|
||||
if( pTab->iPKey>=0 ){
|
||||
sqlite3_str_appendf(&str, "%s=?", pTab->aCol[pTab->iPKey].zCnName);
|
||||
}else{
|
||||
for(i=pLoop->nSkip; i<pLoop->u.btree.nEq; i++){
|
||||
const char *z = explainIndexColumnName(pLoop->u.btree.pIndex, i);
|
||||
if( i>pLoop->nSkip ) sqlite3_str_append(&str, " AND ", 5);
|
||||
sqlite3_str_appendf(&str, "%s=?", z);
|
||||
}
|
||||
sqlite3_str_appendf(&str, "rowid=?");
|
||||
}
|
||||
}else{
|
||||
for(i=pLoop->nSkip; i<pLoop->u.btree.nEq; i++){
|
||||
const char *z = explainIndexColumnName(pLoop->u.btree.pIndex, i);
|
||||
if( i>pLoop->nSkip ) sqlite3_str_append(&str, " AND ", 5);
|
||||
sqlite3_str_appendf(&str, "%s=?", z);
|
||||
}
|
||||
sqlite3_str_append(&str, ")", 1);
|
||||
zMsg = sqlite3StrAccumFinish(&str);
|
||||
ret = sqlite3VdbeAddOp4(v, OP_Explain, sqlite3VdbeCurrentAddr(v),
|
||||
pParse->addrExplain, 0, zMsg,P4_DYNAMIC);
|
||||
}
|
||||
sqlite3_str_append(&str, ")", 1);
|
||||
zMsg = sqlite3StrAccumFinish(&str);
|
||||
ret = sqlite3VdbeAddOp4(v, OP_Explain, sqlite3VdbeCurrentAddr(v),
|
||||
pParse->addrExplain, 0, zMsg,P4_DYNAMIC);
|
||||
return ret;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_EXPLAIN */
|
||||
@@ -1390,7 +1385,9 @@ static SQLITE_NOINLINE void filterPullDown(
|
||||
WhereLevel *pLevel = &pWInfo->a[iLevel];
|
||||
WhereLoop *pLoop = pLevel->pWLoop;
|
||||
if( pLevel->regFilter==0 ) continue;
|
||||
if( pLoop->prereq & notReady ) continue;
|
||||
/* ,--- Because constructBloomFilter() has will not have set
|
||||
** vvvvv--' pLevel->regFilter if this were true. */
|
||||
if( NEVER(pLoop->prereq & notReady) ) continue;
|
||||
if( pLoop->wsFlags & WHERE_IPK ){
|
||||
WhereTerm *pTerm = pLoop->aLTerm[0];
|
||||
int regRowid;
|
||||
|
||||
Reference in New Issue
Block a user