Skip to content

Bug in C code for BestIndex #72

@rogerbinns

Description

@rogerbinns

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

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions