
How to write a simple database engine?
1 Expert Answer

Patrick B. answered 05/24/19
Math and computer tutor/teacher
The metadata and database table schema are stored in another file: the names of the field columns, the size and type of each field column, # of records in the table, size of each record, primary keys, etc.
So when the open command is sent, the engine reads the database table's schema and metadata, so it knows
what the column fields are, what is the size of each record, etc. and begins loading them into memory.
Depending on the query, it will have to sort the records in memory so that the records are listed in the order specified.
Generically you can do a similar thing as follows:
For each table X in your database:
- stores the record size and # of records in a file called Xmetadataschema.dat
- stores the actual records in X.dat
- declares,defines, and implements a function pointer that compares two records from table x; this function takes two void pointers as arguments, by typecasts them into pointers to structure x.
Now when the table is requested, you can load these records into memory and sort them easily using Quicksort which is implemented for you in stdlib.h. You will need to pass the comparison function pointer created in step 3. Otherwise you will have to write your own generic sorting routine.
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Shao X.
There are two types of database, NoSql and Relational database. Which one do you want to build ?05/27/19