Always want to analyze the source of MySQL, at the beginning do not know where to start, first from the CSV file storage start it, this is relatively simple. I am using the mysql5.7.16 version of the source code.
CSV source files in the MySQL source mysql-5.7.16\storage\csv folder, which in addition to a make file, the remaining four files is the CSV storage read code.
The transparent_file.h/cc file is simple and defines only one Transparent_file class to read data from the specified file into the cache.
classtransparent_file{file filedes; Uchar*buff;/*in-memory window to the file or mmaped area*/ /*Current window sizes*/my_off_t Lower_bound;//file offset start positionmy_off_t Upper_bound;//file offset End position UINTBuff_size;//the length of the cache file Public: Transparent_file (); ~Transparent_file (); voidInit_buff (File filedes_arg);//reading data from a file into the in-memory cacheUchar *ptr ();//returns the memory cache pointermy_off_t start (); my_off_t end (); Charget_value (my_off_t offset); my_off_t Read_next ();//read the next paragraph};
The 1.transparent_file constructor, based on the size of the buff_size and the characters, requests a specified length of space, just the application, without initializing the data in the file.
The purpose of the 2.init_buff function is to load the file contents into the cache from the specified file.
3.read_next the contents of the next buff_size length from the file into the cache and overrides the values of Lower_bound and Upper_bound.
4.get_value reads data from a file with a specified location length of buff_size and puts it in the cache.
Not to be continued ...
MySQL source analysis--csv storage engine