SQLite Forum

pointer to memory as index?
Login
Funny enough, we were just discussing this in another thread.

The hard answer is no, the rowid is already the "pointer" index, but you can create a table with "WITHOUT ROWID" by which the PK will become the "pointer index", but you can't have more than one of those.

Getting it faster, if you know you will only need the fields for "fruit" and "price", then this will reduce that query to a single binary search:

```
CREATE INDEX fruit_price ON fruitforsale(fruit,price);
```

Now when you do this query:

```
SELECT price FROM fruitsforsale WHERE fruit='Peach';
```

The engine only needs to look up ONE BTREE to obtain both fields it needs to give the result.

Why this is not always feasible:

- The Index costs extra space (it matters if your DB has millions of rows)
- A small bit of extra cycles when inserting (it has to insert new rows into the table and also into every index you have on that table).

That said, it makes look-ups lightning-fast.

As an aside, for a medium-sized normal DB that can wholly fit in memory, I doubt you would see much of a gain. Memory is already pretty speedy, it will be hard to see a difference in human time-scales between one and two look-ups of an in-memory DB.