go-sqlite3 icon indicating copy to clipboard operation
go-sqlite3 copied to clipboard

Virtual Table "Column Used" Field

Open patrickdevivo opened this issue 4 years ago • 2 comments

The SQLite virtual table docs mention a colUsed field in the index information:

The colUsed field indicates which columns of the virtual table may be required by the current scan. Virtual table columns are numbered from zero in the order in which they appear within the CREATE TABLE statement passed to sqlite3_declare_vtab(). For the first 63 columns (columns 0-62), the corresponding bit is set within the colUsed mask if the column may be required by SQLite. If the table has at least 64 columns and any column to the right of the first 63 is required, then bit 63 of colUsed is also set. In other words, column iCol may be required if the expression (colUsed & ((sqlite3_uint64)1 << (iCol>=63 ? 63 : iCol))) evaluates to non-zero.

https://www.sqlite.org/c3ref/index_info.html

However I don't see any way to access that field in this library - is there something I'm missing? Or perhaps it's not implemented?

patrickdevivo avatar Aug 18 '20 01:08 patrickdevivo

It's not implemented. It would have to be a parameter to VTab.BestIndex as I understand it. Also, as per the docs the colUsed field was introduced in SQLite version 3.10.0, which makes things more complicated compatibility-wise. The only way out of it that I can think of is to deprecate the existing VTab interface (or at least VTab.BestIndex), and make a new interface that accepts the additional input parameter (or better yet, accepts a struct so that more parameters can be added in the future in a non-breaking way).

rittneje avatar Aug 18 '20 03:08 rittneje

@rittneje I see - understood! Thank you for the explanation

patrickdevivo avatar Aug 19 '20 00:08 patrickdevivo