Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Normal Table vs Virtual Table SQLite DB

Android developer manual seems to prefer FTS3 in SQLite DB when search is needed. I read the FTS3 description and it appears that it creates a virtual table instead of a permanent table. What's the difference between virtual table (FTS3) and normal table in SQLite? Is virtual table permanent and remains in the database even after I quit the app? Thank you.

like image 950
androidnerd Avatar asked Dec 26 '12 14:12

androidnerd


People also ask

What is virtual table in SQLite?

A virtual table is an object that presents an SQL table interface but which is not stored in the database file, at least not directly. The virtual table mechanism is a feature of SQLite that allows SQLite to access and manipulate resources other than bits in the database file using the powerful SQL query language.

Why do we need virtual table in SQL?

It helps us to provide an abstraction to various users or hide the complexity for users who are accessing data from the table. For example, a user has permission to access particular columns of data rather than the whole table. It can help us to simplify complex queries into a simpler one.

Are the virtual tables that do not really exist like the tables of the database?

Views in SQL are the virtual tables that do not really exist like the tables of the database. These Views are created by SQL statements that join one or more tables. The views contain rows and columns.

What is a virtual table derived from one or more tables?

A view is a single table that is derived from other tables. These other tables can be base tables or previously defined views. A view does not necessarily exist in physical form it is considered as virtual table in contrast to base tables whose tuples are actually stored in the database.


1 Answers

A virtual table allows the SQLite engine to access the contents of a data store, using (usually) non-SQLite code. This allows the developer to add custom functionality to SQLite.

In the case of FTS, it was originally not a part of the SQLite engine. It was code that was external to SQLite, that allowed the end user to do a full text search on data.

Is a virtual table permanent? That depends on the implementation. For FTS the data is permanent. However, you could create an implementation that uses RAM for storage - this obviously would disappear when the application is terminated.

More on virtual tables: http://www.sqlite.org/vtab.html

like image 67
chue x Avatar answered Oct 07 '22 14:10

chue x