Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does TiDB create a new table?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to create a new table in TiDB". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to create a new table in TiDB.

TiDB is an open source distributed database, and uses TiKV written by Rust to store data, in which TiDB is a SQL syntax parsing layer. This paper uses MockDB to simulate local storage data, and analyzes how a data table is built from syntax parsing to actual storage operation.

The process is as follows:

First of all, we have to have a constructive statement.

CREATE TABLE Persons (Id_P int NOT NULL, LastName varchar (255) NOT NULL, FirstName varchar (255), Address varchar (255), City varchar (255), PRIMARY KEY (Id_P))

After TiDB gets a SQL statement, it first needs to use Parser for syntax parsing

The code in the figure above is the goyacc syntax of Parser. Finally, after walking around in Parser, SQL generates the structure of CreateTableStmt. The specific properties of this structure are shown in the following figure:

After the syntax parsing is complete, you need to generate an abstract syntax tree AST,TiDB uses the volcano model to drill down to generate the syntax tree. !

If there is no problem with the syntax tree generation, the next step is to build a LogicPlan. Of course, let's do some pre-checking before build:

Pre-inspection mainly includes some table name legitimacy check, list legitimacy check, constraint check, primary key check and so on.

After ensuring that the AST check is correct, we start working on the AST syntax tree generated in step 3. Among them, we do more detailed inspection in ddl_api.go, and finally generate a structure of TableInfo, which holds all the table-related information. And submit a Job of type Type: model.ActionCreateTable.

After ddl_worker.go receives the Job in step 5, you really start processing the task of saving the TableInfo as an atomic operation. Where t.CreateTable (schemaID, tbInfo) will actually call the API of the Hash API to serialize the TableInfo and store it in the back-end storage.

After the storage is complete, the call to job.FinishTableJob has been executed through the front-end table statement.

Thank you for your reading, the above is the content of "how to create a new table for TiDB". After the study of this article, I believe you have a deeper understanding of how to create a new table for TiDB, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report