Reread metadata management of simpledb (1)

Source: Internet
Author: User

We have introduced the parsing of SQL statements. Before we begin to introduce the implementation of query actions, we need to take a look at simpledb's management of metadata (metadata.

Integrity considerations correspondCodeHere we will introduce record and metadata together.

The class diagrams of metadata and record are as follows:

Figure 1 metadata and record class diagram

The class diagram shows that simpledb maintains four types of metadata: Table information (including field information), view information, index information, and statistical information. Some of these four types of data are stored on disks, such as table information, field information, view information, and index information. Others are maintained in the runtime memory, such as statistical information.

Figure 2 metadata composition diagram

The following describes how to manage these four types of information one by one.

1. (tablemgr) TABLE Information Management

I plan to introduce it in the top-down order, for example:

Figure 2 Table Management

    • Tablemgr

Table Information Manager maintains two tableinfo objects: tcatinfo and fcatinfo. The table information is persisted to tcatinfo. TBL and fcatinfo. TBL.

Table 1 tcatinfo Schema

Tablename Recordlength

Table 2 schema of fcatinfo

Tablename Fldname Type Length Offset

For example: Create Table students (SID varchar (5), sname varchar (20 ));

Tcatinfo adds the following records

Students 58

Fcatinfo adds the following records

Students Sid 4 14 0
Students Sname 12 44 14

Note:

The A. Type field is marked with the const int type value:

 
Public Const IntInteger = 4, varchar = 12;

B. as mentioned in the previous storage, simpledb stores strings in the form of "Length + content", and each Char has two locations in the byte array, therefore, the length of varchar (5) is 2*5 + 4 = 44.

When creating a new table:

A. Write basic table information to tcatinfo. TBL;

B. Write the field information of the table to fcatinfo. TBL.

When querying:

A. Open the tcatinfo. TBL file,SequenceScan files to obtain basic information about the target table. The key is recordlength;

B. Open the fcatinfo. TBL file,SequenceScan the file to obtain the field information of the target table. The key is the table schema and the offsets of each field offset;

C. Return a tableinfo object that contains all the obtained table information.

    • Tableinfo

Table information, including four elements: tablename, table schema, offsets of each field offset, and recordlength

Offsets is a <fieldname, Offset> dictionary. You can use offsets [fieldname] to obtain the offset of a specified field in a single-pick record.

Here, recordlength refers to the byte length, taking into account the special storage format of strings in simpledb mentioned above.

    • Schema

Maintains a <fieldname, fieldinfo> dictionary. fieldinfo contains the type and length of the corresponding field.

Note that only integer and varchar types are supported, and the field length is different as follows:

Public VoidAddintfield (StringFldname)

 
{

 
Addfiled (fldname, integer, 0 );

 
}

 
Public VoidAddstringfield (StringFldname,IntLength)

 
{

 
Addfiled (fldname, varchar, length );

 
}

The length of integer is set to 0.

    • Fieldinfo

Contains two key fields: type and length.

 

The above is the management of table information in metadata management, and the management of the other three types of information will be resumed later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.