On 10/17/2017 01:22 PM, Hick Gunter wrote:
In our virtual table implementations, we are using the rowid to return the 
location of the record in the backing store (e.g. record offset in the file 
used as a backing store, offset within a shared memory section or maybe even 
the memory address of the record image) and also implement fast lookup by rowid.

If you don't require such ability, you may as well return a constant, a global 
counter value or a counter that is reset in the xFilter function.

So, YES you always have to implement the xRowid method.

It will only get called if your SELECT statement explicitly mentions it. No "INTEGER 
PRIMARY KEY" magic is performed for virtual tables.

I think the exception is queries with OR terms. With FTS[345], if you do something like:

  CREATE VIRTUAL TABLE t1 USING fts5(x);
  EXPLAIN SELECT x FROM t1 WHERE t1 MATCH 'abc' OR t1 MATCH 'def';

You can see the Rowid opcodes.

SQLite runs two separate queries on the virtual table - one with "MATCH 'abc'" and the other with "MATCH 'def'". It uses the rowids for each matched row to avoid returning duplicates. If the xRowid method always returned 0, then only the first set of matches would be returned (because SQLite would deem the second set to be duplicates of the first). Or if xRowid returned arbitrary values your results might include duplicates. etc.

Same applies to other virtual table types.

Dan.














-----Ursprüngliche Nachricht-----
Von: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] Im 
Auftrag von dave
Gesendet: Montag, 16. Oktober 2017 21:23
An: 'SQLite mailing list' <sqlite-users@mailinglists.sqlite.org>
Betreff: [EXTERNAL] [sqlite] xRowid and read only virtual tables....

Hi, I am building a system which involves a number of virtual table 
implementations.  They are all read-only, but will be involved in a bunch of 
joins amongst themselves.  My question is this:

the documentation
   http://sqlite.org/vtab.html#tabfunc2 at 2.12 xRowid seems (to my reading) to 
be always required to be implemented.  But does it really?  Is it ever used for 
read-only tables?  I have never seen it invoked, and I have been blithely 
ignoring implementing it, but I wonder if there is a case where it would be 
invoked for a read-only query and so I am tempting fate.

I ask in particular because implementing it will be quite awkward for the 
underlying implementation in my case, and I'd very much prefer to skip it.
Even a 'without rowid' table would imply specifying some primary key, which in 
a few cases would also be awkward.

Thanks in advance,

-dave
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


___________________________________________
  Gunter Hick | Software Engineer | Scientific Games International GmbH | 
Klitschgasse 2-4, A-1130 Vienna | FN 157284 a, HG Wien, DVR: 0430013 | (O) +43 
1 80100 - 0

May be privileged. May be confidential. Please delete if not the addressee.
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to