Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Change fts5 expression processing to avoid linear scans of long doclists caused by phrases that match specific columns only. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | fts5 |
Files: | files | file ages | folders |
SHA1: |
ec69e09a55b4daf1c40aeaaf9ee95091 |
User & Date: | dan 2015-06-01 09:15:20.958 |
References
2015-06-02
| ||
17:57 | Reimplement [ec69e09a] so that each call to the xNext() method does not involve two iterations of the match expression tree (only one). (check-in: 80fe305b3e user: dan tags: fts5) | |
Context
2015-06-01
| ||
19:17 | Improve performance of the fts5 AND operator. (check-in: b43e9a5b7a user: dan tags: fts5) | |
09:15 | Change fts5 expression processing to avoid linear scans of long doclists caused by phrases that match specific columns only. (check-in: ec69e09a55 user: dan tags: fts5) | |
2015-05-30
| ||
11:49 | Remove the "#include sqlite3Int.h" from fts5Int.h. (check-in: e008c3c8e2 user: dan tags: fts5) | |
Changes
Changes to ext/fts5/fts5_expr.c.
︙ | |||
649 650 651 652 653 654 655 | 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 | - - - + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + | ** EOF. */ static int fts5ExprNearNextRowidMatch( Fts5Expr *pExpr, /* Expression pPhrase belongs to */ Fts5ExprNode *pNode ){ Fts5ExprNearset *pNear = pNode->pNear; |
︙ | |||
734 735 736 737 738 739 740 741 742 743 744 745 746 747 | 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | if( nSub ){ fts5BufferAppendBlob(&rc, pBuf, nSub, pSub); } } return rc; } static int fts5ExprNearTest( int *pRc, Fts5Expr *pExpr, /* Expression that pNear is a part of */ Fts5ExprNode *pNode /* The "NEAR" node (FTS5_STRING) */ ){ Fts5ExprNearset *pNear = pNode->pNear; int rc = *pRc; if( pNear->nPhrase==1 && pNear->apPhrase[0]->nTerm==1 ){ /* If this "NEAR" object is actually a single phrase that consists ** of a single term only, then grab pointers into the poslist ** managed by the fts5_index.c iterator object. This is much faster ** than synthesizing a new poslist the way we have to for more ** complicated phrase or NEAR expressions. */ Fts5ExprPhrase *pPhrase = pNear->apPhrase[0]; Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter; Fts5ExprColset *pColset = pNear->pColset; const u8 *pPos; int nPos; if( rc!=SQLITE_OK ) return 0; rc = sqlite3Fts5IterPoslist(pIter, &pPos, &nPos, &pNode->iRowid); /* If the term may match any column, then this must be a match. ** Return immediately in this case. Otherwise, try to find the ** part of the poslist that corresponds to the required column. ** If it can be found, return. If it cannot, the next iteration ** of the loop will test the next rowid in the database for this ** term. */ if( pColset==0 ){ assert( pPhrase->poslist.nSpace==0 ); pPhrase->poslist.p = (u8*)pPos; pPhrase->poslist.n = nPos; }else if( pColset->nCol==1 ){ assert( pPhrase->poslist.nSpace==0 ); pPhrase->poslist.n = fts5ExprExtractCol(&pPos, nPos, pColset->aiCol[0]); pPhrase->poslist.p = (u8*)pPos; }else if( rc==SQLITE_OK ){ rc = fts5ExprExtractColset(pColset, pPos, nPos, &pPhrase->poslist); } *pRc = rc; return (pPhrase->poslist.n>0); }else{ int i; /* Check that each phrase in the nearset matches the current row. ** Populate the pPhrase->poslist buffers at the same time. If any ** phrase is not a match, break out of the loop early. */ for(i=0; rc==SQLITE_OK && i<pNear->nPhrase; i++){ Fts5ExprPhrase *pPhrase = pNear->apPhrase[i]; if( pPhrase->nTerm>1 || pNear->pColset ){ int bMatch = 0; rc = fts5ExprPhraseIsMatch(pExpr, pNear->pColset, pPhrase, &bMatch); if( bMatch==0 ) break; }else{ rc = sqlite3Fts5IterPoslistBuffer( pPhrase->aTerm[0].pIter, &pPhrase->poslist ); } } *pRc = rc; if( i==pNear->nPhrase && (i==1 || fts5ExprNearIsMatch(pRc, pNear)) ){ return 1; } } return 0; } /* ** Argument pNode points to a NEAR node. All individual term iterators ** point to valid entries (not EOF). * ** This function tests if the term iterators currently all point to the ** same rowid, and if so, if the row matches the phrase and NEAR constraints. |
︙ | |||
756 757 758 759 760 761 762 | 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 | - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - + - - | ** otherwise. It is not considered an error code if an iterator reaches ** EOF. */ static int fts5ExprNearNextMatch( Fts5Expr *pExpr, /* Expression that pNear is a part of */ Fts5ExprNode *pNode /* The "NEAR" node (FTS5_STRING) */ ){ |
︙ | |||
938 939 940 941 942 943 944 | 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | + - - - - + + + + | switch( pNode->eType ){ case FTS5_STRING: { rc = fts5ExprNearAdvanceFirst(pExpr, pNode, bFromValid, iFrom); break; }; case FTS5_AND: { Fts5ExprNode *pLeft = pNode->pLeft; |
︙ | |||
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 | 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | || rc!=SQLITE_OK /* a */ || pNode->bEof /* b */ || pNode->iRowid==iFrom || pExpr->bDesc==(pNode->iRowid<iFrom) /* c */ ); return rc; } static void fts5ExprNodeZeroPoslist(Fts5ExprNode *pNode){ if( pNode->eType==FTS5_STRING ){ Fts5ExprNearset *pNear = pNode->pNear; int i; for(i=0; i<pNear->nPhrase; i++){ Fts5ExprPhrase *pPhrase = pNear->apPhrase[i]; pPhrase->poslist.n = 0; } }else{ fts5ExprNodeZeroPoslist(pNode->pLeft); fts5ExprNodeZeroPoslist(pNode->pRight); } } static int fts5ExprNodeTest( int *pRc, Fts5Expr *pExpr, i64 iRowid, Fts5ExprNode *pNode ){ int bRes = 0; if( pNode->bEof || pNode->iRowid!=iRowid ){ bRes = 0; }else { switch( pNode->eType ){ case FTS5_STRING: bRes = fts5ExprNearTest(pRc, pExpr, pNode); if( *pRc ) bRes = 0; break; case FTS5_AND: { int bRes1 = fts5ExprNodeTest(pRc, pExpr, iRowid, pNode->pLeft); int bRes2 = fts5ExprNodeTest(pRc, pExpr, iRowid, pNode->pRight); assert( (bRes1==0 || bRes1==1) && (bRes2==0 || bRes2==1) ); bRes = (bRes1 && bRes2); if( bRes1!=bRes2 ){ fts5ExprNodeZeroPoslist(bRes1 ? pNode->pLeft : pNode->pRight); } break; } case FTS5_OR: { int bRes1 = fts5ExprNodeTest(pRc, pExpr, iRowid, pNode->pLeft); int bRes2 = fts5ExprNodeTest(pRc, pExpr, iRowid, pNode->pRight); bRes = (bRes1 || bRes2); break; } default: assert( pNode->eType==FTS5_NOT ); bRes = fts5ExprNodeTest(pRc, pExpr, iRowid, pNode->pLeft); break; } } return bRes; } static void fts5ExprSetEof(Fts5ExprNode *pNode){ if( pNode ){ pNode->bEof = 1; fts5ExprSetEof(pNode->pLeft); fts5ExprSetEof(pNode->pRight); } |
︙ | |||
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 | + + + | Fts5ExprNode *pNode /* Expression node to test */ ){ int rc = SQLITE_OK; if( pNode->bEof==0 ){ switch( pNode->eType ){ case FTS5_STRING: { #if 0 rc = fts5ExprNearNextMatch(pExpr, pNode); #endif rc = fts5ExprNearNextRowidMatch(pExpr, pNode); break; } case FTS5_AND: { Fts5ExprNode *p1 = pNode->pLeft; Fts5ExprNode *p2 = pNode->pRight; |
︙ | |||
1061 1062 1063 1064 1065 1066 1067 | 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 | - + | while( rc==SQLITE_OK && p1->bEof==0 ){ int cmp = fts5NodeCompare(pExpr, p1, p2); if( cmp>0 ){ rc = fts5ExprNodeNext(pExpr, p2, 1, p1->iRowid); cmp = fts5NodeCompare(pExpr, p1, p2); } assert( rc!=SQLITE_OK || cmp<=0 ); |
︙ | |||
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 | 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 | + + + - + - + - + + + + + + + + - + + + + + | if( pNode->eType==FTS5_STRING ){ /* Initialize all term iterators in the NEAR object. */ rc = fts5ExprNearInitAll(pExpr, pNode); /* Attempt to advance to the first match */ if( rc==SQLITE_OK && pNode->bEof==0 ){ #if 0 rc = fts5ExprNearNextMatch(pExpr, pNode); #endif rc = fts5ExprNearNextRowidMatch(pExpr, pNode); } }else{ rc = fts5ExprNodeFirst(pExpr, pNode->pLeft); if( rc==SQLITE_OK ){ rc = fts5ExprNodeFirst(pExpr, pNode->pRight); } if( rc==SQLITE_OK ){ rc = fts5ExprNodeNextMatch(pExpr, pNode); } } return rc; } |
︙ |
Changes to ext/fts5/test/fts5_common.tcl.
︙ | |||
275 276 277 278 279 280 281 | 275 276 277 278 279 280 281 282 283 284 285 | - + | if {[llength $a]==0 || [llength $b]==0} { return [list] } sort_poslist [concat $a $b] } proc OR {a b} { sort_poslist [concat $a $b] } proc NOT {a b} { |
Changes to ext/fts5/test/fts5auto.test.
︙ | |||
222 223 224 225 226 227 228 | 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | - + - - - + - - - - - - - - - - - + - - - - + - - - - - + - + - - + - - - - - - - + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + - - - - - - + + + + + + + - - - + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + | {d} {j x i b x u y d c p v a h} 2391989 {b n w x w f q h p i} {e u b b i n a i o c d g} {v a z o i e n l x l r} {r u f o r k w m d w} {k s} {r f e j q p w} } |