rogerbinns / apsw

Another Python SQLite wrapper
https://rogerbinns.github.io/apsw/
Other
713 stars 96 forks source link

Bug in C code for BestIndex #72

Closed rogerbinns closed 10 years ago

rogerbinns commented 10 years ago

From rogerbinns on September 25, 2009 15:10:09

Reported by a user: http://apsw.googlecode.com/svn/publish/vtable.html The documentation says (look for "a complete example"):


BestIndex(constraints, orderbys)

constraints= ( (2, apsw.SQLITE_INDEX_CONSTRAINT_GT), (5, apsw.SQLITE_INDEX_CONSTRAINT_LE), (0, apsw.SQLITE_INDEX_CONSTRAINT_EQ) )

orderbys= ( (2, True), (5, False) )

You return

( (1, None, 0), # constraints used 27, # index number "idx_pr_cust", # index name False, # results are not in orderbys order 1000 # about 1000 disk operations to access index )

Your Cursor.Filter method will be called with:

27, # index number you returned "idx_pr_cust", # index name you returned "Acme Widgets", # constraintarg[0] - customer

74.99 # constraintarg[1] - price

This should be:


( (2, None, 1), # constraints used

because sqlite returns the constraintarg starting counting from 1 and upwards. I fell for this, until i found this page: http://www.ddj.com/database/202802959;jsessionid=2QFN32G3HJDIFQE1GHRSKHWATMY32JVN?pgno=3 --- .... p_info->aConstraintUsage[0] = 1 p_info->aConstraintUsage[1] = 2

The values assigned to the aConstraintUsage[] elements are significant. They specify the order in which they are passed to xFilter(). In the example, this says "pass xFilter() the name column first, then the path column."


Original issue: http://code.google.com/p/apsw/issues/detail?id=72

rogerbinns commented 10 years ago

From rogerbinns on September 25, 2009 15:10:41

APSW does intend the counting to start at 0. See the note at http://apsw.googlecode.com/svn/publish/vtable.html#apsw.VTTable.BestIndex

rogerbinns commented 10 years ago

From rogerbinns on September 27, 2009 00:53:48

This was a bug in the C code which wasn't adding the one back to the data structure handed back to SQLite.

Summary: Big in C code for BestIndex
Status: Accepted
Labels: -Type-Other -Component-Docs Type-Defect

rogerbinns commented 10 years ago

From rogerbinns on September 27, 2009 00:54:14

Summary: Bug in C code for BestIndex

rogerbinns commented 10 years ago

From rogerbinns on September 27, 2009 01:00:59

Fixed in revision 889886627e

Status: Verified