Tuesday, September 11, 2018

Adding a field in a table without interrupting live traffic


Figure 1. Structure of data in a database table

Assuming that data fields (columns) in a table are stored using linked list in a hard drive, the last pointer is usually set to “null” to end a linked list.

Let’s say the original table has 2 fields at first. Users wanted to add the third field without interrupting traffic. The second field would point to a pointer with value “null”.

If the database engine is structured left to right, i.e. the first column would be indexed as 1, and second field indexed as 2. During a search, update, or delete a field the correct index is used. Indexing could be done by a compiler to compile an application program and translate those fields into database’s table indices.

So, when a user adds another field, the database engine would modify the original “null” pointer at the first construction to point to another field in the hard drive, i.e. connecting the second field to the third field. Of course, the third field would point to the “null” pointer again. This scenario is useful when doing live upgrading on the executive node with new data field introduced for additional software.

The index of the “pointer to third field” is not counted.

Removing a field is complicated because the database structure has changed. Doing so may cause corrupting data during live traffic due to incorrect indices.

The process to remove a second data field is described in figure 1 by updating the pointer and its index.

1 comment:

  1. Compiling an application to translate database field names into indices is not an easy task as the compiler must try to connect to a data source and count the fields of each table based on its field names, i.e. similar to running an application in real time.

    ReplyDelete