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 to achieve MYSQL and INNODB layering

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

How to achieve MYSQL and INNODB layering, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

When open table is the first open table, it will generate a table_shared structure, which is a structural record.

A lot of information from frm is basically the definition of a table, and we call it static caching, in other words, this thing, the whole mysql.

The API is get_table_share

Then, when each connection thread opens the table, it creates a table structure based on the information from table_shared.

This structure is dynamic, one is established for each session, and it passes the actual information to the innodb level

Finally, open the table of innodb. Of course, this dynamic table structure will have a linked list to join in table shared.

The API is open_table_from_share

Please refer to the fourth chapter of the internal reference of operation and maintenance, which is briefly mentioned here.

Here we mainly talk about how polymorphism occurs.

Three conditions for the establishment of polymorphism

1. Virtual function rewriting

2. Inheritance

3. The parent pointer points to such objects.

1 、

MYSQL hierarchy and INNODB interactive polymorphic core objects:

Handler handler is the base class, which is located in Handler.h at the MYSQL level

Ha_innobase: public handler this is an inherited class from the handler base class of MYSQL, which is located in the innodb layer, in Ha_innodb.h

The conditions are completed here.

2. Inherit here take open as an example

There is a function in the handler class

Handler::ha_open, which calls the method open, such as

If ((error=open (name,mode,test_if_locked)

So let's take a look at the definition of open in the MYSQL hierarchy as

Virtual int open (const char * name, int mode, uint test_if_locked) = 0

You can see that he is a pure virtual function.

Let's take a look at the function implementation in Ha_innodb.cc.

Int

Ha_innobase::open (

/ * /

Const char* name / *!

< in: table name */ int mode, /*!< in: not used */ uint test_if_locked) /*!< in: not used */ ) 这里完成了虚函数从写,也就完成了条件1 3、 在TABLE类中有这样一个句柄 handler *file; 在open_table_from_share会执行 outparam->

File= get_new_handler (share, & outparam- > mem_root,share- > db_type ()) / / db_type engine type db_plugin / * storage engine plugin * /

If ((file= db_type- > create (db_type, share, alloc))

File- > init ()

DBUG_RETURN (file)

The pointer here is the value returned by db_type- > create, the db_type here is innobase, and the db_type- > create is a function pointer

Handler * (* create) (handlerton * hton, TABLE_SHARE * table, MEM_ROOT * mem_root)

He pointed to

Handler* innobase_create_handler (handlerton* hton, / *!

< in: InnoDB handlerton */ TABLE_SHARE* table,MEM_ROOT* mem_root) 通过这里outparam->

File has pointed to a concrete instance of an engine hierarchy, where condition 3 parent class pointers point to objects like this

That is, the handler pointer points to ha_innobase.

So all three conditions here have been met, and polymorphism has occurred.

Let's take open as an example. We know that this open function has been overwritten at the innodb level.

The table is actually opened at the end of the open_table_from_share

If (ha_err= (outparam- > file- >)

Ha_open (outparam, share- > normalized_path.str

(db_stat & HA_READ_ONLY? O_RDONLY: O_RDWR)

(db_stat & HA_OPEN_TEMPORARY? HA_OPEN_TMP_TABLE:

(db_stat & HA_WAIT_IF_LOCKED)

HA_OPEN_WAIT_IF_LOCKED:

(db_stat & (HA_ABORT_IF_LOCKED | HA_GET_INFO))?

HA_OPEN_ABORT_IF_LOCKED:

HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags)

Let's focus on the polymorphism here.

We know that ha_open actually calls open,open at the innodb level, and outparam- > file is such a

Pointer, which points to a concrete instance of the innodb layer, when executed in ha_open

If ((error=open (name,mode,test_if_locked)

The ha_innobase::open of the innodb level has been called to complete the division of the hierarchy, which is also the division of the module. In fact, everything

All of them are implemented on the basis of CumberCure + polymorphism.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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

Database

Wechat

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

12
Report