Skip to content
feiben edited this page Apr 13, 2016 · 8 revisions

Before we actually insert any real data into the database, we have to create our first table,

String db_root = "/home/feiben/DBTest/RTSeventhDB";  
DBTaskCenter tc = new DBTaskCenter(db_root);    
String table = "order";  
		
tc.getActiveDB().createTable(table);   
tc.getActiveDB().openTable(table);  

The table we created is "order", createTable(...) and opentable(...) are two interfaces exposed to add new table into database. If you restart your DB instance, DBTaskCenter will open all the tables that created before. You need no manually open any of them one by one.

In non-relational database language, a table may be known as a model. In LunarBase context, one table may contain records with properties describing a purchase like userID, payment, product , timestamp..., while another table is a model of user specific properties like userID, name, age, favorite_color, degree, last_login_time. The two table link each other with the userID column.

You will specify which columns are searchable, meaning in real time analysis, the column data is well indexed for quick fetching the value(random point query or range query). For example, we need "name", "payment", "age" to be indexed:

LunarTable l_table = tc.getActiveDB().getTable(table);
l_table.addSearchable("string", "name");
l_table.addSearchable("int", "payment");
l_table.addSearchable("int", "age");  

It is quite similar to the secondary index that traditional database systems always implement, but in a free style of definition. Once the searchable columns is added, LunarBase build column redundant data storage in background thread. All the query system is built upon this data structure.

Any searchable column cost a memory up to the threshold specified by rt_max_memory and rt_vm_swap in real time configureation. The chapter of how to control memory consumption and how to use swap space as extra virtual memory should be revisited.

Plus, LunarBase enables multi-dimensional relational analysis, although it is a no-sql database system. We will talk about JOIN-like operations, denormalization, materialized view later, see how LunarBase handles these advanced features.

Clone this wiki locally