Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Fix incorrect index cost assumptions that occur after an ANALYZE. Ticket #2643. (CVS 4424) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
2cfdbfe6543bac42961deecec7d085d8 |
User & Date: | drh 2007-09-13 17:54:40.000 |
Context
2007-09-13
| ||
18:12 | Mark the table-named column HIDDEN. Add tests to make sure it's working as expected. (CVS 4425) (check-in: ca669eaf1b user: shess tags: trunk) | |
17:54 | Fix incorrect index cost assumptions that occur after an ANALYZE. Ticket #2643. (CVS 4424) (check-in: 2cfdbfe654 user: drh tags: trunk) | |
2007-09-12
| ||
17:01 | Fixes for compilation/testing when the various OMIT macros are defined. (CVS 4423) (check-in: c8405b15c0 user: danielk1977 tags: trunk) | |
Changes
Changes to src/where.c.
︙ | ︙ | |||
12 13 14 15 16 17 18 | ** This module contains C code that generates VDBE code used to process ** the WHERE clause of SQL statements. This module is reponsible for ** generating the code that loops through a table looking for applicable ** rows. Indices are selected and used to speed the search when doing ** so is applicable. Because this module is responsible for selecting ** indices, you might also think of this module as the "query optimizer". ** | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ** This module contains C code that generates VDBE code used to process ** the WHERE clause of SQL statements. This module is reponsible for ** generating the code that loops through a table looking for applicable ** rows. Indices are selected and used to speed the search when doing ** 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.261 2007/09/13 17:54:40 drh Exp $ */ #include "sqliteInt.h" /* ** The number of bits in a Bitmask. "BMS" means "BitMask Size". */ #define BMS (sizeof(Bitmask)*8) |
︙ | ︙ | |||
1561 1562 1563 1564 1565 1566 1567 | } cost = pProbe->aiRowEst[i] * inMultiplier * estLog(inMultiplier); nEq = i; if( pProbe->onError!=OE_None && (flags & WHERE_COLUMN_IN)==0 && nEq==pProbe->nColumn ){ flags |= WHERE_UNIQUE; } | | | 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 | } cost = pProbe->aiRowEst[i] * inMultiplier * estLog(inMultiplier); nEq = i; if( pProbe->onError!=OE_None && (flags & WHERE_COLUMN_IN)==0 && nEq==pProbe->nColumn ){ flags |= WHERE_UNIQUE; } WHERETRACE(("...... nEq=%d inMult=%.9g cost=%.9g\n",nEq,inMultiplier,cost)); /* Look for range constraints */ if( nEq<pProbe->nColumn ){ int j = pProbe->aiColumn[nEq]; pTerm = findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE|WO_GT|WO_GE, pProbe); if( pTerm ){ |
︙ | ︙ | |||
1622 1623 1624 1625 1626 1627 1628 | cost /= 2; WHERETRACE(("...... idx-only reduces cost to %.9g\n", cost)); } } /* If this index has achieved the lowest cost so far, then use it. */ | | < | 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 | cost /= 2; WHERETRACE(("...... idx-only reduces cost to %.9g\n", cost)); } } /* If this index has achieved the lowest cost so far, then use it. */ if( flags && cost < lowestCost ){ bestIdx = pProbe; lowestCost = cost; bestFlags = flags; bestNEq = nEq; } } /* Report the best result */ |
︙ | ︙ |
Added test/tkt2643.test.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | # 2007 Sep 12 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # # This file is to test that ticket #2643 has been fixed. # # $Id: tkt2643.test,v 1.1 2007/09/13 17:54:41 drh Exp $ # # The problem in ticket #2643 has to do with the query optimizer # making bad assumptions about index cost when data from ANALYZE # is available. set testdir [file dirname $argv0] source $testdir/tester.tcl do_test tkt2643-1.1 { execsql { CREATE TABLE t1(a INTEGER PRIMARY KEY, b UNIQUE, c); INSERT INTO t1 VALUES(1,2,3); INSERT INTO t1 VALUES(2,3,4); ANALYZE; } db close sqlite3 db test.db execsql { CREATE INDEX i1 ON t1(c); SELECT count(*) FROM t1 WHERE c IS NOT NULL } } {2} finish_test |