I have created an Rtree data structure using SQLite, which generates 4 tables (one for the original table, and three shadow tables). And I am trying to figure out how retrieve the id of a row in the original table using the nodeno attribute in the shadow tables.
According to the SQLite documentation, the %rowid table can be used to map the id(s) from the shadow tables to the original table. Below is what the documentation states
"The data structure for a single virtual r-tree table is stored in three native SQLite tables declared as follows. In each case, the '%' character in the table name is replaced with the user-supplied name of the r-tree table.
CREATE TABLE %_node(nodeno INTEGER PRIMARY KEY, data BLOB)
CREATE TABLE %_parent(nodeno INTEGER PRIMARY KEY, parentnode INTEGER)
CREATE TABLE %_rowid(rowid INTEGER PRIMARY KEY, nodeno INTEGER)
The data for each node of the r-tree structure is stored in the %_node table. For each node that is not the root node of the r-tree, there is an entry in the %_parent table associating the node with its parent. And for each row of data in the table, there is an entry in the %_rowid table that maps from the entries rowid to the id of the node that it is stored on."
I have tried to run the following query
SELECT p.id
FROM mytable_rowid r, mytable p
WHERE r.rowid = p.id
AND r.nodeno = 9341;
I was expecting that this query would return the id of a single node in the original table (mytable) that has a value of 9341 in the nodeno attribute of the shadow tables, but instead it retrieved several rows from the original table.