Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | The optimization of check-in [9b2879629c34fc0a] is incorrectly reasoned. The WHERE clause of the partial index might not be true if the table of the partial index is the right table of a left join. So disable the optimization in that case. Ticket [623eff57e76d45f6] |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
3be19e1151af1850b65991edb82420f9 |
User & Date: | drh 2019-11-03 00:07:41 |
Context
2019-11-04
| ||
02:05 | Fix a false-postive in the sqlite3ExprImpliesNonNullRow() decision routine, that resulted in an incorrect LEFT JOIN strength reduction when the WHERE clause contained a row-value comparison. Ticket [02aa2bd02f97d0f2] (check-in: ea20068e user: drh tags: trunk) | |
2019-11-03
| ||
00:07 | The optimization of check-in [9b2879629c34fc0a] is incorrectly reasoned. The WHERE clause of the partial index might not be true if the table of the partial index is the right table of a left join. So disable the optimization in that case. Ticket [623eff57e76d45f6] (check-in: 3be19e11 user: drh tags: trunk) | |
2019-11-02
| ||
17:59 | Fix a problem in VIEW creation that was introduced by the generated columns feature. (check-in: 9c795c4d user: drh tags: trunk) | |
Changes
Changes to src/wherecode.c.
︙ | ︙ | |||
1866 1867 1868 1869 1870 1871 1872 | k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[j]); sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j); } sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont, iRowidReg, pPk->nKeyCol); VdbeCoverage(v); } | > | | | | | | | | | | | | | | | | | | | | | | | | > > > | | | | > > > | > | 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 | k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[j]); sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j); } sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont, iRowidReg, pPk->nKeyCol); VdbeCoverage(v); } if( pLevel->iLeftJoin==0 ){ /* If pIdx is an index on one or more expressions, then look through ** all the expressions in pWInfo and try to transform matching expressions ** into reference to index columns. Also attempt to translate references ** to virtual columns in the table into references to (stored) columns ** of the index. ** ** Do not do this for the RHS of a LEFT JOIN. This is because the ** expression may be evaluated after OP_NullRow has been executed on ** the cursor. In this case it is important to do the full evaluation, ** as the result of the expression may not be NULL, even if all table ** column values are. https://www.sqlite.org/src/info/7fa8049685b50b5a ** ** Also, do not do this when processing one index an a multi-index ** OR clause, since the transformation will become invalid once we ** move forward to the next index. ** https://sqlite.org/src/info/4e8e4857d32d401f */ if( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){ whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo); } /* If a partial index is driving the loop, try to eliminate WHERE clause ** terms from the query that must be true due to the WHERE clause of ** the partial index. ** ** 2019-11-02 ticket 623eff57e76d45f6: This optimization does not work ** for a LEFT JOIN. */ if( pIdx->pPartIdxWhere ){ whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC); } }else{ testcase( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ); testcase( pIdx->pPartIdxWhere ); } /* Record the instruction used to terminate the loop. */ if( pLoop->wsFlags & WHERE_ONEROW ){ pLevel->op = OP_Noop; }else if( bRev ){ pLevel->op = OP_Prev; }else{ pLevel->op = OP_Next; |
︙ | ︙ |
Changes to test/join.test.
︙ | ︙ | |||
930 931 932 933 934 935 936 937 938 | SELECT (b IS NOT NULL) IS NOT NULL FROM t1 LEFT JOIN t2 } {1} do_execsql_test join-19.5 { SELECT * FROM t1 LEFT JOIN t2 WHERE (b IS NOT NULL AND b IS NOT NULL) IS NOT NULL; } {0 {}} finish_test | > > > > > > > > > > > > > > > > > > | 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 | SELECT (b IS NOT NULL) IS NOT NULL FROM t1 LEFT JOIN t2 } {1} do_execsql_test join-19.5 { SELECT * FROM t1 LEFT JOIN t2 WHERE (b IS NOT NULL AND b IS NOT NULL) IS NOT NULL; } {0 {}} # 2019-11-02 ticket 623eff57e76d45f6 # The optimization of exclusing the WHERE expression of a partial index # from the WHERE clause of the query if the index is used does not work # of the table of the index is the right-hand table of a LEFT JOIN. # db close sqlite3 db :memory: do_execsql_test join-20.1 { CREATE TABLE t1(c1); CREATE TABLE t0(c0); INSERT INTO t0(c0) VALUES (0); SELECT * FROM t0 LEFT JOIN t1 WHERE NULL IN (c1); } {} do_execsql_test join-20.2 { CREATE INDEX t1x ON t1(0) WHERE NULL IN (c1); SELECT * FROM t0 LEFT JOIN t1 WHERE NULL IN (c1); } {} finish_test |