diff --git a/.gitignore b/.gitignore index d26c37ce2ec..005b29e93fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ + +*.cmake-build-debug/ +*.idea/ + *-t *_test *.Plo @@ -3138,3 +3142,95 @@ storage/perfschema/gen_pfs_lex_token sql/share/bulgarian sql/lex_token.h sql/gen_lex_token +cmake-build-debug/CMakeCache.txt +cmake-build-debug/MySQL.cbp +cmake-build-debug/cmd-line-utils/libedit/makelist +cmake-build-debug/Docs/INFO_SRC +cmake-build-debug/extra/jemalloc/tmp/jemalloc-cfgcmd.txt +cmake-build-debug/extra/jemalloc/tmp/jemalloc-cfgcmd.txt.in +cmake-build-debug/include/my_config.h +cmake-build-debug/include/mysql_version.h +cmake-build-debug/libmysql/libmysql.ver +cmake-build-debug/libmysql/libmysql_exports_file.cc +cmake-build-debug/mysql-test/mtr +cmake-build-debug/mysql-test/mysql-test-run +cmake-build-debug/mysql-test/mysql-test-run.pl +cmake-build-debug/packaging/rpm-docker/my.cnf +cmake-build-debug/packaging/rpm-fedora/my.cnf +cmake-build-debug/packaging/rpm-fedora/my_config.h +cmake-build-debug/packaging/rpm-fedora/mysql-5.6.16-mysql-install.patch +cmake-build-debug/packaging/rpm-fedora/mysql-systemd-start +cmake-build-debug/packaging/rpm-fedora/mysql.conf +cmake-build-debug/packaging/rpm-fedora/mysql_config.sh +cmake-build-debug/packaging/rpm-fedora/mysqld.service +cmake-build-debug/packaging/rpm-oel/filter-provides.sh +cmake-build-debug/packaging/rpm-oel/filter-requires.sh +cmake-build-debug/packaging/rpm-oel/my.cnf +cmake-build-debug/packaging/rpm-oel/my_config.h +cmake-build-debug/packaging/rpm-oel/mysql-5.6.16-mysql-install.patch +cmake-build-debug/packaging/rpm-oel/mysql-systemd-start +cmake-build-debug/packaging/rpm-oel/mysql.conf +cmake-build-debug/packaging/rpm-oel/mysql.init +cmake-build-debug/packaging/rpm-oel/mysql_config.sh +cmake-build-debug/packaging/rpm-oel/mysqld.service +cmake-build-debug/packaging/rpm-sles/filter-provides.sh +cmake-build-debug/packaging/rpm-sles/filter-requires.sh +cmake-build-debug/packaging/rpm-sles/my.cnf +cmake-build-debug/packaging/rpm-sles/my_config.h +cmake-build-debug/packaging/rpm-sles/mysql-systemd-start +cmake-build-debug/packaging/rpm-sles/mysql.conf +cmake-build-debug/packaging/rpm-sles/mysql.init +cmake-build-debug/packaging/rpm-sles/mysqld.service +cmake-build-debug/scripts/make_binary_distribution +cmake-build-debug/scripts/msql2mysql +cmake-build-debug/scripts/mysql_config +cmake-build-debug/scripts/mysql_config.pl +cmake-build-debug/scripts/mysql_convert_table_format +cmake-build-debug/scripts/mysql_find_rows +cmake-build-debug/scripts/mysql_fix_extensions +cmake-build-debug/scripts/mysql_install_db +cmake-build-debug/scripts/mysql_secure_installation +cmake-build-debug/scripts/mysql_setpermission +cmake-build-debug/scripts/mysql_zap +cmake-build-debug/scripts/mysqlaccess +cmake-build-debug/scripts/mysqlaccess.conf +cmake-build-debug/scripts/mysqlbug +cmake-build-debug/scripts/mysqld_multi +cmake-build-debug/scripts/mysqld_safe +cmake-build-debug/scripts/mysqldumpslow +cmake-build-debug/scripts/mysqlhotcopy +cmake-build-debug/sql/sql_builtin.cc +cmake-build-debug/sql-bench/bench-count-distinct +cmake-build-debug/sql-bench/bench-init.pl +cmake-build-debug/sql-bench/compare-results +cmake-build-debug/sql-bench/copy-db +cmake-build-debug/sql-bench/crash-me +cmake-build-debug/sql-bench/example.bat +cmake-build-debug/sql-bench/graph-compare-results +cmake-build-debug/sql-bench/innotest1 +cmake-build-debug/sql-bench/innotest1a +cmake-build-debug/sql-bench/innotest1b +cmake-build-debug/sql-bench/innotest2 +cmake-build-debug/sql-bench/innotest2a +cmake-build-debug/sql-bench/innotest2b +cmake-build-debug/sql-bench/pwd.bat +cmake-build-debug/sql-bench/README +cmake-build-debug/sql-bench/run-all-tests +cmake-build-debug/sql-bench/server-cfg +cmake-build-debug/sql-bench/test-alter-table +cmake-build-debug/sql-bench/test-ATIS +cmake-build-debug/sql-bench/test-big-tables +cmake-build-debug/sql-bench/test-connect +cmake-build-debug/sql-bench/test-create +cmake-build-debug/sql-bench/test-insert +cmake-build-debug/sql-bench/test-select +cmake-build-debug/sql-bench/test-transactions +cmake-build-debug/sql-bench/test-wisconsin +cmake-build-debug/sql-bench/uname.bat +cmake-build-debug/sql/share/dictionary.txt +cmake-build-debug/support-files/binary-configure +cmake-build-debug/support-files/my-default.cnf +cmake-build-debug/support-files/mysql-log-rotate +cmake-build-debug/support-files/mysql.server +cmake-build-debug/support-files/mysqld_multi.server +cmake-build-debug/support-files/plugins.files diff --git a/README.md b/README.md index e4201975eec..a49f0cf1ba6 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,3 @@ -# AliSQL -AliSQL is a MySQL branch originated from Alibaba Group. It is based on the MySQL official release and has many feature and performance enhancements. AliSQL has proven to be very stable and efficient in production environment. It can be used as a free, fully compatible, enhanced and open source drop-in replacement for MySQL. +������ AliSql ��������ע�� -AliSQL has been an open source project since August 2016. It is being actively developed by engineers from Alibaba Group. Moreover, it includes patches from Percona, WebScaleSQL, and MariaDB. AliSQL is a fruit of community effort. Everyone is welcomed to get involved. -# AliSQL Release Notes - -[Changes in AliSQL 5.6.32 (2018-05-01) ](https://github.com/alibaba/AliSQL/wiki/Changes-in-AliSQL-5.6.32-(2018-05-01)) -[Changes in AliSQL 5.6.32 (2018-01-24) ](https://github.com/alibaba/AliSQL/wiki/Changes-in-AliSQL-5.6.32-(2018-01-24)) -[Changes in AliSQL 5.6.32 (2017-10-10) ](https://github.com/alibaba/AliSQL/wiki/Changes-in-AliSQL-5.6.32-(2017-10-10)) -[Changes in AliSQL 5.6.32 (2017-07-16) ](https://github.com/alibaba/AliSQL/wiki/Changes-in-AliSQL-5.6.32-(2017-07-16)) -[Changes in AliSQL 5.6.32 (2017-05-04) ](https://github.com/alibaba/AliSQL/wiki/Changes-in-AliSQL-5.6.32-(2017-05-04)) -[Changes in AliSQL 5.6.32 (2017-02-14) ](https://github.com/alibaba/AliSQL/wiki/Changes-in-AliSQL-5.6.32-(2017-02-14)) -[Changes in AliSQL 5.6.32 (2016-12-25) ](https://github.com/alibaba/AliSQL/wiki/Changes-in-AliSQL-5.6.32-(2016-12-25)) -[Changes in AliSQL 5.6.32 (2016-11-11) ](https://github.com/alibaba/AliSQL/wiki/Changes-in-AliSQL-5.6.32-(2016-11-11)) -[Changes in AliSQL 5.6.32 (2016-10-14) ](https://github.com/alibaba/AliSQL/wiki/Changes-in-AliSQL-5.6.32-(2016-10-14)) -[Changes in AliSQL 5.6.32 (2016-09-15) ](https://github.com/alibaba/AliSQL/wiki/Changes-in-AliSQL-5.6.32-(2016-09-15)) - -## AliSQL Compiler Guide -[AliSQL-Compiler-Guide](http://blog.fungo.me/2016/10/compile-alisql-from-source/) - -# AliSQL benchmark -[Performance benchmark ](https://github.com/alibaba/AliSQL/wiki/AliSQL-Performance-benchmark) -[Performance benchmark for inventory ](https://github.com/alibaba/AliSQL/wiki/AliSQL-Performance-benchmark-for-inventory) - -# AliSQL wiki -[Wiki](https://github.com/alibaba/AliSQL/wiki) - -# AliSQLBackup -[AliSQLBackup](https://github.com/alibaba/AliSQLBackup) -[AliSQLBackup.wiki](https://github.com/alibaba/AliSQLBackup/wiki) - -## AliSQL Sequence Engine -[AliSQL-Sequence-Doc](https://github.com/alibaba/AliSQL/wiki/AliSQL-Sequence-Doc_C) +annotation ��֧ \ No newline at end of file diff --git a/extra/innochecksum.cc b/extra/innochecksum.cc index 9c6ca996577..351820b1673 100644 --- a/extra/innochecksum.cc +++ b/extra/innochecksum.cc @@ -103,6 +103,7 @@ get_page_size( flags = mach_read_from_4(buf + FIL_PAGE_DATA + FSP_SPACE_FLAGS); /* srv_page_size is used by InnoDB code as UNIV_PAGE_SIZE */ + //wangyang @@ ������������ pageSize srv_page_size = *logical_page_size = fsp_flags_get_page_size(flags); /* fsp_flags_get_zip_size() will return zero if not compressed. */ diff --git a/include/my_alloc.h b/include/my_alloc.h index 9e2ef541b3c..729be64cc81 100644 --- a/include/my_alloc.h +++ b/include/my_alloc.h @@ -37,12 +37,17 @@ typedef struct st_used_mem typedef struct st_mem_root { + // �����ڴ� USED_MEM *free; /* blocks with free memory in it */ + //��ʹ���ڴ� USED_MEM *used; /* blocks almost without free memory */ + //Ԥ�����ڴ� USED_MEM *pre_alloc; /* preallocated block */ /* if block have less memory it will be put in 'used' list */ size_t min_malloc; + //��ʼ�� block_size Ĭ�� 1024 size_t block_size; /* initial block size */ + // �ѷ���� block ���� unsigned int block_num; /* allocated blocks counter */ /* first free block in queue test counter (if it exceed diff --git a/include/my_sys.h b/include/my_sys.h index 24aa4a95ff4..2f739c7ab6a 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -354,9 +354,12 @@ struct st_my_file_info extern struct st_my_file_info *my_file_info; +/** + * wangyang ** st_hash ��ʹ�õĶ�̬���� + */ typedef struct st_dynamic_array { - uchar *buffer; + uchar *buffer; //--> wangyang buffer �ַ����� uint elements,max_element; uint alloc_increment; uint size_of_element; @@ -825,6 +828,8 @@ extern void delete_dynamic(DYNAMIC_ARRAY *array); extern void delete_dynamic_element(DYNAMIC_ARRAY *array, uint array_index); extern void freeze_size(DYNAMIC_ARRAY *array); #define dynamic_array_ptr(array,array_index) ((array)->buffer+(array_index)*(array)->size_of_element) +//wangyang *** �����ʼ��ʱ�� ֻ��һ�� ��ͨ��ָ�룬���� char* ���ǻ�ת��Ϊ type ���ͣ��������Ⱦ������� +//����ֻ�� ��ȡ�����̬����� ij��λ�� #define dynamic_element(array,array_index,type) ((type)((array)->buffer) +(array_index)) #define push_dynamic(A,B) insert_dynamic((A),(B)) #define reset_dynamic(array) ((array)->elements= 0) diff --git a/mysys/array.c b/mysys/array.c index 0a320085360..f76e84a1cf1 100644 --- a/mysys/array.c +++ b/mysys/array.c @@ -40,6 +40,9 @@ FALSE Ok */ +/** + * wangyang @@ ��ʼ�� ��̬ ���� + */ my_bool init_dynamic_array2(DYNAMIC_ARRAY *array, uint element_size, void *init_buffer, uint init_alloc, uint alloc_increment) @@ -129,7 +132,7 @@ my_bool insert_dynamic(DYNAMIC_ARRAY *array, const void *element) void *alloc_dynamic(DYNAMIC_ARRAY *array) { - if (array->elements == array->max_element) + if (array->elements == array->max_element) //wangyang ��� elements�Ѿ��ﵽ������� ��ô ��Ҫ���� { char *new_ptr; if (array->buffer == (uchar *)(array + 1)) @@ -155,6 +158,9 @@ void *alloc_dynamic(DYNAMIC_ARRAY *array) array->buffer= (uchar*) new_ptr; array->max_element+=array->alloc_increment; } + /** + * wangyang ������Ƕ�̬������ ����һ�� �µ�Ԫ��λ�� ��ʹ�� elements + */ return array->buffer+(array->elements++ * array->size_of_element); } diff --git a/mysys/hash.c b/mysys/hash.c index 15a50083798..679956d9d52 100644 --- a/mysys/hash.c +++ b/mysys/hash.c @@ -55,6 +55,10 @@ static my_hash_value_type cset_hash_sort_adapter(const HASH *hash, const uchar *key, size_t length) { + /** + * wangyang ** hash_sort ���� ����� key ֵ���� sort ���� �������������� + * ctype-utf8.c �����ļ����� ��ѡ�����ַ����й�ϵ + */ ulong nr1=1, nr2=4; hash->charset->coll->hash_sort(hash->charset,(uchar*) key,length,&nr1,&nr2); return (my_hash_value_type)nr1; @@ -107,6 +111,7 @@ _my_hash_init(HASH *hash, uint growth_size, CHARSET_INFO *charset, hash->free=free_element; hash->flags=flags; hash->charset=charset; + //wangyang *** ������ ���г�ʼ�����õ� ʱ�� ��� hash_function ΪNULL ����ôʹ�� cset_hash_sort_adapter ���� hash->hash_function= hash_function ? hash_function : cset_hash_sort_adapter; DBUG_RETURN(my_init_dynamic_array_ci(&hash->array, sizeof(HASH_LINK), size, growth_size)); @@ -192,20 +197,45 @@ my_hash_key(const HASH *hash, const uchar *record, size_t *length, my_bool first) { if (hash->get_key) - return (char*) (*hash->get_key)(record,length,first); + return (char*) (*hash->get_key)(record,length,first); //--> �����ʹ�� get_key ������ȡ��Ӧ��key *length=hash->key_length; return (char*) record+hash->key_offset; } /* Calculate pos according to keys */ + /* + * wangyang ����� buffmax �ͻ��� hash�ṹ��� blength ��2��n���� + * ��̬hash ���ɷ�ʽ + * + * ͨ�� ȡģ�ķ�ʽ ��̬���� hash ֵ + */ static uint my_hash_mask(my_hash_value_type hashnr, size_t buffmax, size_t maxlength) { + /** + * wangyang ������� buffmax = 8 max length = 3 ��ôִ��if����� + * ��� buffmax = 9 max length = 3 ��ô ��ֻʹ�õ�λ + * + * + * ���Կ��Կ��� ��̬ hash ÿ�η��ص��Dz�һ���ģ���ʼ��ʱ�� �ᾡ���ڵ�λ��Ȼ���� + * ��չ�� ��λ + * + * һ��ʼ��ʱ�� ���� buffmax = 16 maxlength = 0 + * 2������ hashnr = 13 & 15 = 13 , 13 > 0����ô λ��ô 13 & (16 >> 1) - 1 = 13 & 7 = 7 + * + * 3������ hashnr = 13 Ȼ��max length = 14 + * ��ô 13 & 15 = 13�� 13 < 14 ����ô 13 & (16 - 1) = 13 ��λ�� + * + * + */ if ((hashnr & (buffmax-1)) < maxlength) return (hashnr & (buffmax-1)); return (hashnr & ((buffmax >> 1) -1)); } +/* + * wangyang + */ static uint my_hash_rec_mask(const HASH *hash, HASH_LINK *pos, size_t buffmax, size_t maxlength) { @@ -339,6 +369,19 @@ uchar* my_hash_next(const HASH *hash, const uchar *key, size_t length, /* Change link from pos to new_link */ + /** + + ���������Ŀ�� ������ �� HashLink �ƶ�����ȷ��λ�� + + old_link = array + next_link;--> ֮ǰ ���λ�õ�Ԫ�� + + ����һ������ ��10��Ԫ�أ�find ��λ���� 8��֮ǰ���λ����һ��Ԫ�أ�����������Ԫ�� + ����ͬһ��bucket,�����ҪΪ ��֮ǰ���λ�õ�Ԫ���ƶ����µ�λ��Ҳ����11(11���·����λ��) + + Ȼ�� ���Ԫ�����ڵ���ͰΪ 6 ����ô����������̾��Ǵ�6��ʼѰ�� ���� 6����һ���� 4 4����һ����3 + 3�����һ�� Ȼ��ֵ 3�� ��һ��Ϊ 11 ����������ôһ������ + + */ static void movelink(HASH_LINK *array,uint find,uint next_link,uint newlink) { HASH_LINK *old_link; @@ -383,6 +426,10 @@ static int hashcmp(const HASH *hash, HASH_LINK *pos, const uchar *key, /* Write a hash-key to the hash-index */ + /* + * wangyang *** hash ���� ����������� ����� hash �����в���һ����¼ + * + */ my_bool my_hash_insert(HASH *info, const uchar *record) { int flag; @@ -391,33 +438,84 @@ my_bool my_hash_insert(HASH *info, const uchar *record) uchar *UNINIT_VAR(ptr_to_rec),*UNINIT_VAR(ptr_to_rec2); HASH_LINK *data,*empty,*UNINIT_VAR(gpos),*UNINIT_VAR(gpos2),*pos; - if (HASH_UNIQUE & info->flags) + if (HASH_UNIQUE & info->flags) //wangyang �����Ƿ��� Ψһ�� { - uchar *key= (uchar*) my_hash_key(info, record, &idx, 1); + uchar *key= (uchar*) my_hash_key(info, record, &idx, 1); //wangyang * ������������hahs_key �����Բο� table_shared if (my_hash_search(info, key, idx)) return(TRUE); /* Duplicate entry */ } flag=0; + /** + * wangyang ������ empty ����һ�� ��ֵ�����ڻ�ȡ������һ�� �յ�λ��o + * + * empty �������ڻ�ȡһ���µĿյ�λ�� ���� empty ��ַ�Ѿ���ȷ���� + * + * + */ if (!(empty=(HASH_LINK*) alloc_dynamic(&info->array))) return(TRUE); /* No more memory */ - data=dynamic_element(&info->array,0,HASH_LINK*); - halfbuff= info->blength >> 1; - + /* + * wangyang ����궨��չ�� �൱�� array->buffer + array_index + */ + //dynamic_element(array,array_index,type) ((type)((array)->buffer) +(array_index)) + /** + * wangyang ** �������˼�� ��ȡ��� ��̬����� ��ͷλ�õ�ָ�룬Ҳ����array_indexΪ0 + */ + data=dynamic_element(&info->array,0,HASH_LINK*); //wangyang ����ᶯ̬����һ�� element �� HASH_LINK* ���͵� + halfbuff= info->blength >> 1; //wangyang ��һ���λ�� ���� blength �� 8 һ�����4 + + /* + * wangyang ** ��Ҫ����������λ��,��һ�� λ�� ��ʼ���� + * ����blength �� 16 ��hashbuff �� 8 + * records ������10 + * + * + * idx ���ڱ�ʾ �������е�����λ�� + * + * ����� first_index ���� records - һ�� + * + * records ���� һ���� ���� halfbuff�� ��Ϊ �Ǵﵽblength ��ʱ�� �Ż�Ŵ� һ�� + * + * + * + */ idx=first_index=info->records-halfbuff; + /** + * idx ��ʾ����λ�� + */ if (idx != info->records) /* If some records */ { do { - pos=data+idx; - hash_nr=rec_hashnr(info,pos->data); + pos=data+idx; //wangyang data ��һ��ָ�� + idx + hash_nr=rec_hashnr(info,pos->data); // ���ڻ�ȡ hash value ֵ if (flag == 0) /* First loop; Check if ok */ + /** + * wangyang ** ����ʹ���� ��̬hash �������� ��̬hash�� + * + * �⼸�������ĵ� ��˼�� ����� records - blength/2 �� pos��λ�� ���� ����hash + * + * ��� ���� ���� hash ֮��Ľ�� ������ ֮ǰ�Ľ�� ��ô ֱ�� break �Ϳ����� + * + * ��Ϊ����alloc_dynamic ���·�����һ��Ԫ�� ����������� ��ʹ��hash �����������·��� + * + */ + /** + * + * + * + * + */ if (my_hash_mask(hash_nr, info->blength, info->records) != first_index) break; - if (!(hash_nr & halfbuff)) + /** + * wangyang *** �������õ��� hash ֵ�� + */ + if (!(hash_nr & halfbuff)) // { /* Key will not move */ - if (!(flag & LOWFIND)) + if (!(flag & LOWFIND)) // Ѱ�ҵ�λ�� { if (flag & HIGHFIND) { @@ -449,7 +547,7 @@ my_bool my_hash_insert(HASH *info, const uchar *record) } else { /* key will be moved */ - if (!(flag & HIGHFIND)) + if (!(flag & HIGHFIND)) //--> wangyang *** �������˼ �� �ڸ�λ�ҵ� ��Ҫ�ƶ���Ͱ��, Ȼ�� { flag= (flag & LOWFIND) | HIGHFIND; /* key shall be moved to the last (empty) position */ @@ -458,10 +556,10 @@ my_bool my_hash_insert(HASH *info, const uchar *record) } else { - if (!(flag & HIGHUSED)) + if (!(flag & HIGHUSED)) //--> wangyang *** ����� �������ݵ�һ�� �ƶ� �� rec2 �ƶ��� gpos2 ��λ�ã�Ȼ�� empty ��λ�þͻ�ճ��� { /* Change link of previous hash-key and save */ - gpos2->data=ptr_to_rec2; + gpos2->data=ptr_to_rec2; // wangyang *** ���� �����һ���ƶ���ֵ gpos2->next=(uint) (pos-data); flag= (flag & LOWFIND) | (HIGHFIND | HIGHUSED); } @@ -470,7 +568,7 @@ my_bool my_hash_insert(HASH *info, const uchar *record) } } } - while ((idx=pos->next) != NO_RECORD); + while ((idx=pos->next) != NO_RECORD); // wangyang ����� ���ϵĽ��б�����ֱ�� next = no_record if ((flag & (LOWFIND | LOWUSED)) == LOWFIND) { @@ -485,27 +583,48 @@ my_bool my_hash_insert(HASH *info, const uchar *record) } /* Check if we are at the empty position */ + /* + * wangyang ���������������� ��ָ�� ij��λ�� + * + * rec_hashnr �������ڻ�ȡ hash_value + * + * �ٶ� һ��ʼ ���������߼� ����ô�����ȡһ�� idx + * + */ + /* + * wangyang ������� idx �ǻ�ȡ���� bucket ��λ�� + */ idx= my_hash_mask(rec_hashnr(info, record), info->blength, info->records + 1); - pos=data+idx; + pos=data+idx; //--> pos ��һ�� ָ��λ�� �� ���︳ֵ�� һ����ַ�����Կ���ȡ����Ӧ���� + /** + * wangyang ** ������˼�� ��� ����� λ��pos ����empty �൱�����µ�λ�� + */ if (pos == empty) { pos->data=(uchar*) record; - pos->next=NO_RECORD; + pos->next=NO_RECORD; //--> �������� next Ԫ�� } else { /* Check if more records in same hash-nr family */ + /** + * ����Ὣ pos[0] ��Ԫ�� ���Ƶ� empty[0] ��λ�� ���ﲢ���漰 ָ��ĸ��� + * �����ָ�븴�� Ӧ���� empty = pos ,��������ֻ��һ�� Ԫ�صĸ��� + */ empty[0]=pos[0]; + //�������ڻ�ȡ pos λ��ԭ�� Ԫ�ص� bucket + // pos ��ͬ��Ԫ�ؿ�����Ϊ�� ͬһ�� bucket gpos= data + my_hash_rec_mask(info, pos, info->blength, info->records + 1); - if (pos == gpos) + if (pos == gpos) // �����һ�� λ�� ����ͬһ��bucket ��ô ���� ��¼ �������̬�����е�λ�� { - pos->data=(uchar*) record; - pos->next=(uint) (empty - data); + pos->data=(uchar*) record; // wangyang ������ ��ǰ����Ԫ�� + pos->next=(uint) (empty - data); // ���������� } else { pos->data=(uchar*) record; pos->next=NO_RECORD; + //pos-data ����Ԫ��λ�� gpos-data �� ֮ǰ Ԫ�صĵ�����λ�� movelink(data,(uint) (pos-data),(uint) (gpos-data),(uint) (empty-data)); } } diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c index a5209835332..d1a0ccbc7b6 100644 --- a/mysys/my_alloc.c +++ b/mysys/my_alloc.c @@ -55,6 +55,12 @@ static void update_query_size(MEM_ROOT *root, size_t length, int flag) reported as error in first alloc_root() on this memory root. */ +/** + * + wangyang �����Ŀ���dz�ʼ�� mem_root ���� �� ǰ�洫�ݹ�������һ���սṹ�壬 + �������ڴ沿�� ������Ӧ�ij�ʼ�� + + */ void init_alloc_root(MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size MY_ATTRIBUTE((unused))) { @@ -69,6 +75,9 @@ void init_alloc_root(MEM_ROOT *mem_root, size_t block_size, mem_root->first_block_usage= 0; #if !(defined(HAVE_purify) && defined(EXTRA_DEBUG)) + /** + * wangyang ������һ�� ��ʾһ����Ԥ���� + */ if (pre_alloc_size) { if ((mem_root->free= mem_root->pre_alloc= @@ -220,20 +229,28 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) mem_root->first_block_usage++ >= ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP && (*prev)->left < ALLOC_MAX_BLOCK_TO_DROP) { + /** + * wangyang ��� ʣ�� �Ѿ�����length ��ô�Ƴ� free list �� + * ���뵽 used �б����� + */ next= *prev; *prev= next->next; /* Remove block from list */ next->next= mem_root->used; mem_root->used= next; mem_root->first_block_usage= 0; } + /** + * wangyang ����ᰴ�� free ָ�����Ѱ�ң�ֱ���ҵ� left > length ���ڴ�� + */ for (next= *prev ; next && next->left < length ; next= next->next) prev= &next->next; } if (! next) { /* Time to alloc new block */ + // block_nun = 4 >> 2 ==> 1 block_size= mem_root->block_size * (mem_root->block_num >> 2); get_size= length+ALIGN_SIZE(sizeof(USED_MEM)); - get_size= MY_MAX(get_size, block_size); + get_size= MY_MAX(get_size, block_size); // wangyang @@ ����� �Ƚ� ��ȡ ����ֵ if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME | ME_FATALERROR)))) { @@ -241,16 +258,26 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) (*mem_root->error_handler)(); DBUG_RETURN((void*) 0); /* purecov: inspected */ } + /** + * wangyang prev ָ�� ��ʾ���� free ָ�� + * ������Ҫ�ǽ� �����ӵ� �ڴ�� ������ ��ǰ�� + */ update_query_size(mem_root, length, 1); - mem_root->block_num++; + mem_root->block_num++; // ����Ŀ������ ���� next->next= *prev; - next->size= get_size; + next->size= get_size; // next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM)); *prev=next; } + /** + * wangyang ����� ȷ�� + */ point= (uchar*) ((char*) next+ (next->size-next->left)); /*TODO: next part may be unneded due to mem_root->first_block_usage counter*/ + /** + * wangyang ������ж� ����� ʣ�� �ڴ��С, С�� ��С�����С����ô���� used �������� + */ if ((next->left-= length) < mem_root->min_malloc) { /* Full block */ *prev= next->next; /* Remove block from list */ @@ -290,12 +317,20 @@ void *multi_alloc_root(MEM_ROOT *root, ...) size_t tot_length, length; DBUG_ENTER("multi_alloc_root"); + /** + * va_start ��ʹ�õ�ʱ�� ��һ�������� va_list , ���ڳ������е� �䳤���� + * �ڶ��������� �䳤����ǰ���һ�� ����������ȷ�Ϸֽ� + */ va_start(args, root); tot_length= 0; - while ((ptr= va_arg(args, char **))) + /** + * wangyang ʹ�� va_arg �������� ���ڴ� va_list �л�ȡ ij������ + * + */ + while ((ptr= va_arg(args, char **))) //�����Ŀ���Ǵ�va_list�л�ȡһ�������������� char** ���� { - length= va_arg(args, uint); - tot_length+= ALIGN_SIZE(length); + length= va_arg(args, uint); // �����Ǵ�va_list�л�ȡ������������uint Ŀ��������ȷ����Ӧ�Ĵ�С(�ڴ��С) + tot_length+= ALIGN_SIZE(length);// ������ܵ��ڴ��С�����ۼ� } va_end(args); @@ -304,11 +339,15 @@ void *multi_alloc_root(MEM_ROOT *root, ...) va_start(args, root); res= start; + /* + * �����Ŀ�������� ����Ӧ��ָ������ַ ��ptr�Ƕ���ָ�� + * Ȼ��ʹ�� *ptr ��ȷ�� ����� ��ַ + */ while ((ptr= va_arg(args, char **))) { *ptr= res; length= va_arg(args, uint); - res+= ALIGN_SIZE(length); + res+= ALIGN_SIZE(length); // �������ڶ����ڴ� } va_end(args); DBUG_RETURN((void*) start); diff --git a/mysys/my_malloc.c b/mysys/my_malloc.c index 871c735e343..0446a6f5f39 100644 --- a/mysys/my_malloc.c +++ b/mysys/my_malloc.c @@ -77,6 +77,9 @@ void *my_malloc(size_t size, myf my_flags) } else { + /** + * ���ڸ��� ȫ�� malloc �ڴ� + */ update_malloc_size(_msize(point)); DBUG_EXECUTE_IF("simulate_out_of_memory", { diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index 6d5615035c2..66eb04b0f56 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -113,6 +113,10 @@ void my_thread_global_reinit(void) 1 error (Couldn't create THR_KEY_mysys) */ +/** + * + wangyang ��ʼ�� �߳�ȫ�� ���� + */ my_bool my_thread_global_init(void) { int pth_ret; @@ -146,21 +150,29 @@ my_bool my_thread_global_init(void) #endif DBUG_ASSERT(! THR_KEY_mysys_initialized); + /** + * wangyang @@@ ����� ��ʼ�� THR_KEY_mysys(�� ͨ���궨�嶨��ı��� ����ʾ ϵͳ�߳� ) + */ if ((pth_ret= pthread_key_create(&THR_KEY_mysys, NULL)) != 0) { fprintf(stderr, "Can't initialize threads: error %d\n", pth_ret); return 1; } - THR_KEY_mysys_initialized= TRUE; + THR_KEY_mysys_initialized= TRUE; //wangyang ���ォ ��ʼ�� �ֶ�����Ϊtrue mysql_mutex_init(key_THR_LOCK_malloc, &THR_LOCK_malloc, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_THR_LOCK_open, &THR_LOCK_open, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_THR_LOCK_charset, &THR_LOCK_charset, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_THR_LOCK_threads, &THR_LOCK_threads, MY_MUTEX_INIT_FAST); - if (my_thread_init()) + if (my_thread_init()) //wangyang ��������̳߳�ʼ�� return 1; + /** + * wangyang ** mysql_mutex_init ����� pthread_mutex_init ���ڳ�ʼ��һ���ṹ�� + * + * pthread_cond_init ���� ����cond �ṹ�� + */ mysql_mutex_init(key_THR_LOCK_lock, &THR_LOCK_lock, MY_MUTEX_INIT_FAST); mysql_mutex_init(key_THR_LOCK_myisam, &THR_LOCK_myisam, MY_MUTEX_INIT_SLOW); mysql_mutex_init(key_THR_LOCK_myisam_mmap, &THR_LOCK_myisam_mmap, MY_MUTEX_INIT_FAST); @@ -292,8 +304,8 @@ my_bool my_thread_init(void) error= 1; goto end; } - set_mysys_var(tmp); - tmp->pthread_self= pthread_self(); + set_mysys_var(tmp); //wangyang *** �������ڽ���ʼ�����߳����õ� �ֲ������� + tmp->pthread_self= pthread_self(); // �߳̿���ͨ������pthread_self������������̱߳�ʶ ���ض����� pthread_t mysql_mutex_init(key_my_thread_var_mutex, &tmp->mutex, MY_MUTEX_INIT_FAST); mysql_cond_init(key_my_thread_var_suspend, &tmp->suspend, NULL); @@ -301,8 +313,8 @@ my_bool my_thread_init(void) STACK_DIRECTION * (long)my_thread_stack_size; mysql_mutex_lock(&THR_LOCK_threads); - tmp->id= ++thread_id; - ++THR_thread_count; + tmp->id= ++thread_id; //wangyang �߳�id ���� + ++THR_thread_count; //wangyang �߳����� ���� mysql_mutex_unlock(&THR_LOCK_threads); tmp->init= 1; #ifndef DBUG_OFF @@ -381,13 +393,24 @@ void my_thread_end(void) struct st_my_thread_var *_my_thread_var(void) { - if (THR_KEY_mysys_initialized) + if (THR_KEY_mysys_initialized) //wangyang ����Ѿ���ʼ��������ֲ߳̾�ȡ����Ӧ���ֲ߳̾����� return my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys); return NULL; } +/** + * wangyang *** + */ int set_mysys_var(struct st_my_thread_var *mysys_var) { + /** + * wangyang *** �������� �ֲ߳̾����� ����������ǽ� my_thr_init.c �ļ��� my_thread_init ������ + * ������ st_my_thread_var �������ù��� + * + * pthread_getspecific ���ڴ��ֲ߳̾������� ��ȡ��Ӧ�� �ֲ��������� + * pthread_key_t ��ʾ�ֲ߳̾��������͵�key + * + */ if (THR_KEY_mysys_initialized) return my_pthread_setspecific_ptr(THR_KEY_mysys, mysys_var); return 0; diff --git a/mysys/my_winthread.c b/mysys/my_winthread.c index fcb6e57ee53..4c995ac673f 100644 --- a/mysys/my_winthread.c +++ b/mysys/my_winthread.c @@ -54,15 +54,18 @@ win_pthread_mutex_trylock(pthread_mutex_t *mutex) static unsigned int __stdcall pthread_start(void *p) { - struct thread_start_parameter *par= (struct thread_start_parameter *)p; + struct thread_start_parameter *par= (struct thread_start_parameter *)p; //תΪ thread_start_parameter pthread_handler func= par->func; void *arg= par->arg; free(p); - (*func)(arg); + (*func)(arg); //wangyang ���ô����������Ӧ�ĺ��� return 0; } +/** + * wangyang ������ mysql ���ڴ��� pthread_create + */ int pthread_create(pthread_t *thread_id, const pthread_attr_t *attr, pthread_handler func, void *param) { @@ -80,6 +83,9 @@ int pthread_create(pthread_t *thread_id, const pthread_attr_t *attr, par->arg= param; stack_size= attr?attr->dwStackSize:0; + /** + * wangyang ����ϵͳ���� + */ handle= _beginthreadex(NULL, stack_size , pthread_start, par, 0, thread_id); if (!handle) goto error_return; diff --git a/sql/field.h b/sql/field.h index 12e6c0eedae..15dde2cffb9 100644 --- a/sql/field.h +++ b/sql/field.h @@ -449,7 +449,9 @@ void copy_integer(uchar *to, int to_length, } } - +/** + * wangyang ** Field ��ʾ�ֶ��࣬�� Item ���г�ʼ�� + */ class Field { Field(const Item &); /* Prevent use of these */ diff --git a/sql/handler.cc b/sql/handler.cc index 405963acfe0..2c90b6791b5 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -7611,10 +7611,14 @@ int handler::ha_reset() DBUG_RETURN(retval); } - +/** + * + wangyang ** handler�Ǵ洢����Ļ��� + */ int handler::ha_write_row(uchar *buf) { int error; + //wangyang ** ָ�� log event ���� Log_func *log_func= Write_rows_log_event::binlog_row_logging_function; DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE || m_lock_type == F_WRLCK); @@ -7627,7 +7631,7 @@ int handler::ha_write_row(uchar *buf) mark_trx_read_write(); MYSQL_TABLE_IO_WAIT(m_psi, PSI_TABLE_WRITE_ROW, MAX_KEY, 0, - { error= write_row(buf); limit_io(ha_thd()); }) + { error= write_row(buf); limit_io(ha_thd()); }) //wangyang ** ����д�� MYSQL_INSERT_ROW_DONE(error); if (unlikely(error)) diff --git a/sql/main.cc b/sql/main.cc index 4da4d6c2775..a1417bf3555 100644 --- a/sql/main.cc +++ b/sql/main.cc @@ -20,6 +20,10 @@ */ extern int mysqld_main(int argc, char **argv); +/** + * + wangyang *** mysql������ں��� + */ int main(int argc, char **argv) { return mysqld_main(argc, argv); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 5f1ffd2c247..f6d17061976 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4765,6 +4765,9 @@ initialize_storage_engine(char *se_name, const char *se_kind, } +/* + * �� mysql + */ static int init_server_components() { DBUG_ENTER("init_server_components"); @@ -4773,6 +4776,9 @@ static int init_server_components() all things are initialized so that unireg_abort() doesn't fail */ mdl_init(); + /** + * wangyang ** �����ʼ�� table_def_cache + */ if (table_def_init() | hostname_cache_init(host_cache_size)) unireg_abort(1); @@ -5364,6 +5370,10 @@ static void hash_item_free_entry(ic_hash_item_t *record) #ifdef __WIN__ int win_main(int argc, char **argv) #else +/** + * + wangyang @@ ������� main ���� ���� ��ʼ�� ����mysqld_main + */ int mysqld_main(int argc, char **argv) #endif { @@ -5377,7 +5387,10 @@ int mysqld_main(int argc, char **argv) #ifndef _WIN32 // For windows, my_init() is called from the win specific mysqld_main - if (my_init()) // init my_sys library & pthreads + /** + * wangyang ** ���ڽ��г�ʼ�� + */ + if (my_init()) // ע��˵�ĺ���� �����ڳ�ʼ�� ϵͳ���� �� pthread // init my_sys library & pthreads { fprintf(stderr, "my_init() failed."); return 1; @@ -5387,6 +5400,9 @@ int mysqld_main(int argc, char **argv) orig_argc= argc; orig_argv= argv; my_getopt_use_args_separator= TRUE; + /** + * wangyang @@ �������� �����ļ� ����ʼ�� �����ļ� my.cnf + */ if (load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv)) return 1; my_getopt_use_args_separator= FALSE; @@ -5399,7 +5415,7 @@ int mysqld_main(int argc, char **argv) system_charset_info= &my_charset_utf8_general_ci; init_sql_statement_names(); - sys_var_init(); + sys_var_init(); //wangyang ��ʼ��ϵͳ���� ������� load_default���Ⱥ�˳����ʹ������ ���� load_defaults int ho_error; @@ -5626,6 +5642,9 @@ int mysqld_main(int argc, char **argv) Service.SetSlowStarting(slow_start_timeout); #endif + /** + * ��mysqld.cc �� init �����е��ø÷��������ڳ�ʼ�� ������� + */ if (init_server_components()) unireg_abort(1); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 97f7cb67ae6..4bd4b22867d 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -329,10 +329,13 @@ uint get_table_def_key(const TABLE_LIST *table_list, const char **key) Functions to handle table definition cach (TABLE_SHARE) *****************************************************************************/ +/** + * wangyang ** table_def key���� + */ extern "C" uchar *table_def_key(const uchar *record, size_t *length, my_bool not_used MY_ATTRIBUTE((unused))) { - TABLE_SHARE *entry=(TABLE_SHARE*) record; + TABLE_SHARE *entry=(TABLE_SHARE*) record; //wangyang * ֱ�ӽ����ݽ�������ת�� *length= entry->table_cache_key.length; return (uchar*) entry->table_cache_key.str; } @@ -355,7 +358,10 @@ static void table_def_free_entry(TABLE_SHARE *share) DBUG_VOID_RETURN; } - +/** + * wangyang ���ڳ�ʼ�� ������ + * @return + */ bool table_def_init(void) { #ifdef HAVE_PSI_INTERFACE @@ -377,6 +383,9 @@ bool table_def_init(void) */ table_def_inited= true; + /** + * wangyang **** ������ ���ʼ����Ӧ�� table_def_cache ������ݽṹ + */ return my_hash_init(&table_def_cache, &my_charset_bin, table_def_size, 0, 0, table_def_key, (my_hash_free_key) table_def_free_entry, 0) != 0; @@ -454,6 +463,11 @@ uint cached_table_definitions(void) # Share for table */ +/* + * wangyang ** �������ڴ� table_def_cache �л�ȡ ���������� + * + * key �� �����Ƶ���˼ + */ TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, const char *key, uint key_length, uint db_flags, int *error, @@ -474,6 +488,7 @@ TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, MDL_SHARED)); /* Read table definition from cache */ + //wangyang @@ ����������Ѿ������ˣ���ô�Ϳ���ֱ�ӷ��� if ((share= (TABLE_SHARE*) my_hash_search_using_hash_value(&table_def_cache, hash_value, (uchar*) key, key_length))) goto found; @@ -498,6 +513,10 @@ TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, */ assign_new_table_id(share); + /** + * wangyang @@ ������Ҫ����table_def_cache �в�����Ӧ�� ����Ϣ + * + */ if (my_hash_insert(&table_def_cache, (uchar*) share)) { free_table_share(share); diff --git a/sql/sql_class.h b/sql/sql_class.h index 31b2abbbfa6..9abfebbaa67 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -5597,7 +5597,10 @@ void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var, STATUS_VAR *dec_var); /* Inline functions */ - +/** + * + wangyang ** ����Ὣ item ���뵽thd���� + */ inline bool add_item_to_list(THD *thd, Item *item) { return thd->lex->current_select->add_item_to_list(thd, item); diff --git a/sql/sql_cmd.h b/sql/sql_cmd.h index c30931af291..561a1476c99 100644 --- a/sql/sql_cmd.h +++ b/sql/sql_cmd.h @@ -30,6 +30,12 @@ added SQLCOM_. */ +/* + * + * wangyang ** ��ص�sql ���� + * + * + */ enum enum_sql_command { SQLCOM_SELECT, SQLCOM_CREATE_TABLE, SQLCOM_CREATE_INDEX, SQLCOM_ALTER_TABLE, SQLCOM_UPDATE, SQLCOM_INSERT, SQLCOM_INSERT_SELECT, diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 9b9c443d6e2..7bbb76e424f 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -694,6 +694,9 @@ class st_select_lex: public st_select_lex_node LEX *parent_lex; enum olap_type olap; /* FROM clause - points to the beginning of the TABLE_LIST::next_local list. */ + /** + * + */ SQL_I_List table_list; /* @@ -711,6 +714,9 @@ class st_select_lex: public st_select_lex_node SELECT: Fields and expressions in the SELECT list. UPDATE: Fields in the SET clause. */ + /* + * wangyang ���ڱ�ʾ �洢�����е� ���� field + */ List item_list; List interval_list; bool is_item_list_lookup; @@ -732,6 +738,11 @@ class st_select_lex: public st_select_lex_node inlcude all base tables including view tables. The tables are connected by TABLE_LIST::next_leaf, so leaf_tables points to the left-most leaf. */ + + /** + * wangyang ** ���ڱ�ʾ ��Ӧ��Ҷ�ӽڵ� + * + */ TABLE_LIST *leaf_tables; /** SELECT_LEX type enum @@ -1135,6 +1146,9 @@ class Query_tables_list */ enum_sql_command sql_command; /* Global list of all tables used by this statement */ + /** + * wangyang ** statement ��Ӧ�� table list (statement ��Ӧһ��sql) + */ TABLE_LIST *query_tables; /* Pointer to next_global member of last element in the previous list. */ TABLE_LIST **query_tables_last; @@ -2253,12 +2267,20 @@ struct Proc_analyse_params: public Sql_alloc /* The state of the lex parsing. This is saved in the THD struct */ - +/* + * wangyang ** �﷨ �������� + */ struct LEX: public Query_tables_list { SELECT_LEX_UNIT unit; /* most upper unit */ + /** + * wangyang ** select_lex ���� ���ڴ洢 ��Ӧ�� �������� sql �﷨��� + */ SELECT_LEX select_lex; /* first SELECT_LEX */ /* current SELECT_LEX in parsing */ + /* + * ���ڽ��� �����е� current select ��� + */ SELECT_LEX *current_select; /* list of all SELECT_LEX */ SELECT_LEX *all_selects_list; diff --git a/sql/sql_list.h b/sql/sql_list.h index b73cc313bd5..4d0da56c11b 100644 --- a/sql/sql_list.h +++ b/sql/sql_list.h @@ -109,6 +109,9 @@ class SQL_I_List :public Sql_alloc @note We never call a destructor for instances of this class. */ +/* + * wangyang list_node ����һ�� node , info ��ʾ ��ǰָ��Ľڵ� + */ struct list_node :public Sql_alloc { list_node *next; @@ -398,8 +401,8 @@ class base_list_iterator inline void init(base_list &list_par) { - list= &list_par; - el= &list_par.first; + list= &list_par; //wangyang ��ʾ����list + el= &list_par.first; //wangyang el���ڼ�¼ ��һ�� prev= 0; current= 0; } @@ -411,6 +414,9 @@ class base_list_iterator el= ¤t->next; return current->info; } + /* + * wangyang el ������ǰ�� + */ inline void *next_fast(void) { list_node *tmp; @@ -532,7 +538,7 @@ template class List_iterator_fast :public base_list_iterator inline List_iterator_fast(List &a) : base_list_iterator(a) {} inline List_iterator_fast() : base_list_iterator() {} inline void init(List &a) { base_list_iterator::init(a); } - inline T* operator++(int) { return (T*) base_list_iterator::next_fast(); } + inline T* operator++(int) { return (T*) base_list_iterator::next_fast(); } //wangyang ** ��д�� ++ ����� inline void rewind(void) { base_list_iterator::rewind(); } void sublist(List &list_arg, uint el_arg) { diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index d2221cea9b0..3718e9f59b0 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2488,7 +2488,7 @@ mysql_execute_command(THD *thd) */ lex->first_lists_tables_same(); /* should be assigned after making first tables same */ - all_tables= lex->query_tables; + all_tables= lex->query_tables; //wangyang �о����е� tables /* set context for commands which do not use setup_tables */ select_lex-> context.resolve_in_table_list_only(select_lex-> @@ -2521,7 +2521,7 @@ mysql_execute_command(THD *thd) !rpl_filter->db_ok(thd->db)) DBUG_RETURN(0); - if (lex->sql_command == SQLCOM_DROP_TRIGGER) + if (lex->sql_command == SQLCOM_DROP_TRIGGER) // wangyang ɾ�������� { /* When dropping a trigger, we need to load its table name @@ -3608,7 +3608,7 @@ case SQLCOM_PREPARE: DBUG_PRINT("debug", ("Just after generate_incident()")); } #endif - case SQLCOM_INSERT: + case SQLCOM_INSERT: //wangyang ** ����ִ�� ������� { DBUG_ASSERT(first_table == all_tables && first_table != 0); @@ -3628,6 +3628,13 @@ case SQLCOM_PREPARE: MYSQL_INSERT_START(thd->query()); check_queue_on_pk(thd, all_tables, lex); + /** + * wangyang ** �������� ִ�� sql ���� + * + * field_list ��ʾ �ֶ� + * all_tables ��ʾ ���еı� + * + */ res= mysql_insert(thd, all_tables, lex->field_list, lex->many_values, lex->update_list, lex->value_list, lex->duplicates, lex->ignore); @@ -6487,6 +6494,9 @@ void mysql_init_multi_delete(LEX *lex) the next query in the query text. */ +/* + * wangyang *** sql��ѯ���� + */ void mysql_parse(THD *thd, char *rawbuf, uint length, Parser_state *parser_state) { @@ -6518,6 +6528,9 @@ void mysql_parse(THD *thd, char *rawbuf, uint length, { LEX *lex= thd->lex; + /** + * wangyang ** ���ォsql ���дʷ�ת������ + */ bool err= parse_sql(thd, parser_state, NULL); const char *found_semicolon= parser_state->m_lip.found_semicolon; @@ -6613,7 +6626,7 @@ void mysql_parse(THD *thd, char *rawbuf, uint length, } else { - error= mysql_execute_command(thd); + error= mysql_execute_command(thd); //wangyang ** ����ִ�� command if (!thd->trx_end_by_hint) { if (!error && lex->ci_on_success) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index c29c79aed9e..b6996c64f64 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -8807,6 +8807,16 @@ opt_ignore_leaves: Select : retrieve data from table */ +/* + + 这里使用 bison bison中使用了大量 c++代码,将解析结果 嵌入到 对应的c++对象中 + 比如LEX + +第一步 1、 wangyang *** select语句入口 + +这里是 入口部分 select 起始语句 ,select_init 也是一个表达式 会继续寻找 + +*/ select: select_init @@ -8819,13 +8829,17 @@ select: /* SELECT...UPDATE is regarded as a DML.*/ if (lex->sql_command != SQLCOM_UPDATE) - lex->sql_command= SQLCOM_SELECT; + lex->sql_command= SQLCOM_SELECT; //wangyang 这里用于初始化 命令 } ; /* Need select_init2 for subselects. */ +/* +第二步 2、 SELECT_SYM 为select 关键字 +wangyang 这里的目的是嵌套子循环 +*/ select_init: - SELECT_SYM select_init2 + SELECT_SYM select_init2 /* wangyang 这里会 初始化城 终结符 select select_init2 select_init2继续寻找 */ | '(' select_paren ')' union_opt ; @@ -8848,8 +8862,11 @@ select_paren_derived: | '(' select_paren_derived ')' ; +/* +第三步 3 wangyang +*/ select_init2: - select_part2 + select_part2 /* wangyang 用于设置 */ { LEX *lex= Lex; SELECT_LEX * sel= lex->current_select; @@ -8868,6 +8885,10 @@ select_init2: union_clause ; +/* +第四步 wangyang ** +这里解析为 select_part2 +*/ select_part2: { LEX *lex= Lex; @@ -8883,7 +8904,7 @@ select_part2: MYSQL_YYABORT; } } - select_options select_item_list + select_options select_item_list /*wangyang ** 这里的目的是 用来解析列名 , 这里会展开 select_item_list子句 */ { Select->parsing_place= NO_MATTER; } @@ -9080,6 +9101,10 @@ select_lock_type: } ; +/* + 这里会继续展开 这里创建一个 item_field 并且调用add_item_to_list + 会标记 current_select 当前子句,因为 有可能存在嵌套,所以 需要使用 current_select 进行标记 +*/ select_item_list: select_item_list ',' select_item | select_item @@ -9097,6 +9122,9 @@ select_item_list: } ; +/** +wangyang 这里将每个 字段解析成item +*/ select_item: remember_name table_wild remember_end { @@ -9155,6 +9183,9 @@ optional_braces: ; /* all possible expressions */ +/* +wangyang 这里用于解释表达式 +*/ expr: expr or expr %prec OR_SYM { @@ -11536,7 +11567,7 @@ where_clause: { Select->parsing_place= IN_WHERE; } - expr + expr /*wangyang 表达式*/ { SELECT_LEX *select= Select; select->where= $3; diff --git a/sql/sys_vars.h b/sql/sys_vars.h index 2ed5ab61836..a4eba799a8a 100644 --- a/sql/sys_vars.h +++ b/sql/sys_vars.h @@ -102,6 +102,15 @@ struct CMD_LINE Backing store: uint, ulong, ha_rows, ulonglong, long, depending on the Sys_var_* */ + +/** + * + wangyang ����ʹ���� ģ��ģʽ ���Ҽ̳��� sys_var ���� + + ֻҪ ������Ӧ�Ķ���ͻ�ʹ�� all_sys_vars ������ע�ᵽȫ�ֱ����� + + + */ template class Sys_var_integer: public sys_var diff --git a/sql/table.cc b/sql/table.cc index 4c6ab0d906a..8c2e901048e 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -320,8 +320,8 @@ TABLE_CATEGORY get_table_category(const LEX_STRING *db, const LEX_STRING *name) TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, const char *key, uint key_length) { - MEM_ROOT mem_root; - TABLE_SHARE *share; + MEM_ROOT mem_root; //wangyang �ṹ�� ��ʼ�� ��һ���յĶ���, ������ NULL + TABLE_SHARE *share; //�����ʼ����� ��ַ����ʹ�� char *key_buff, *path_buff; char path[FN_REFLEN]; uint path_length; @@ -333,15 +333,31 @@ TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, const char *key, path_length= build_table_filename(path, sizeof(path) - 1, table_list->db, table_list->table_name, "", 0); + /** + * wangyang @@@ table_share ����������ʼ�� mem_root + * ��ʼ�� mem_root + */ init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0); + /** + * wangyang ��������� ������ʼ�������ǵ�������ķ��� + * ���淽���������� ��Ӧ��ָ����г�ʼ���� ���Կ������������� ���س�ʼ�� ����һ��������ָ�룬 + * �ڶ��������� ��Ӧ���ڴ�Ĵ�С + */ if (multi_alloc_root(&mem_root, - &share, sizeof(*share), - &key_buff, key_length, - &path_buff, path_length + 1, + &share, sizeof(*share), //share �DZ�ʾ table_share ���� + &key_buff, key_length, // key_buf �DZ�ʾ key(��ʾһ�ű���key) �ij��� + &path_buff, path_length + 1, // ��ʾ ����·����Ϣ &cache_element_array, table_cache_instances * sizeof(*cache_element_array), NULL)) { + + /* + # include +void *memset(void *s, int c, unsigned long n); +�����Ĺ����ǣ���ָ����� s ��ָ���ǰ n �ֽڵ��ڴ浥Ԫ��һ���������� c �滻��ע�� c �� int �͡�s �� void* �͵�ָ�����������������Ϊ�κ����͵����ݽ��г�ʼ���� + */ + //����������� �� share ָ��ָ��� �ڴ�ȫ����ʼ��Ϊ0 memset(share, 0, sizeof(*share)); share->set_table_cache_key(key_buff, key, key_length); @@ -366,10 +382,20 @@ TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, const char *key, share->m_flush_tickets.empty(); + /** + * �������ڳ�ʼ�� cache_element_array ��ַ��Ӧ���ڴ棬����Ϊ len + * ȫ����ʼ��Ϊ0 + */ memset(cache_element_array, 0, table_cache_instances * sizeof(*cache_element_array)); share->cache_element= cache_element_array; + /** + * wangyang �� �ڶ�������ָ����ڴ� ָ�� ��һ������ָ����ڴ� + * + * �ڴ濽�� �� �ֲ����� &mem_root ��Ӧ���ڴ� ���Ƶ� share �ж�Ӧ�� mem_root�� + * ��Ӧ�ĵ�ַ share �� mem_root �ǽṹ�壬��ֵ����null �� ���� �սṹ�� + */ memcpy((char*) &share->mem_root, (char*) &mem_root, sizeof(mem_root)); mysql_mutex_init(key_TABLE_SHARE_LOCK_ha_data, &share->LOCK_ha_data, MY_MUTEX_INIT_FAST); @@ -851,7 +877,7 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags) root_ptr= my_pthread_getspecific_ptr(MEM_ROOT**, THR_MALLOC); old_root= *root_ptr; *root_ptr= &share->mem_root; - error= open_binary_frm(thd, share, head, file); + error= open_binary_frm(thd, share, head, file); //wangyang @@@ �����򿪶������ļ� ������ʼ�� table_share ���� *root_ptr= old_root; error_given= 1; } diff --git a/sql/table.h b/sql/table.h index a2f33b4168c..e7e48497033 100644 --- a/sql/table.h +++ b/sql/table.h @@ -578,11 +578,17 @@ typedef I_P_List frame = frame; + block->frame = frame; // ������ָ�� ��Ӧ�� Page�ڴ�ĵ�ַ - block->page.buf_pool_index = buf_pool_index(buf_pool); + block->page.buf_pool_index = buf_pool_index(buf_pool); // ���������� buf pool block->page.state = BUF_BLOCK_NOT_USED; block->page.buf_fix_count = 0; block->page.io_fix = BUF_IO_NONE; @@ -1089,6 +1092,9 @@ buf_block_init( /********************************************************************//** Allocates a chunk of buffer frames. @return chunk, or NULL on failure */ +/** + * wangyang @@@ �����dz�ʼ�� buf chunk + */ static buf_chunk_t* buf_chunk_init( @@ -1096,6 +1102,7 @@ buf_chunk_init( buf_pool_t* buf_pool, /*!< in: buffer pool instance */ buf_chunk_t* chunk, /*!< out: chunk of buffers */ ulint mem_size) /*!< in: requested size in bytes */ + //wangyang @@ �����mem_size ���� ÿ�� buf instance �Ĵ�С { buf_block_t* block; byte* frame; @@ -1103,13 +1110,18 @@ buf_chunk_init( /* Round down to a multiple of page size, although it already should be. */ + //((n) & ~((m) - 1)) + //wangyang @@ ���ͨ��λ���� ��ȡ��Ӧ�� ����λ�� �����Ŀ���ǽ� mem_size ���뵽 Page(16k) ��2���� Ҳ����16k�ı��� + // �������� ����� mem_size ��С�� 16k + 3 ��ô����֮�󣬾���16k mem_size = ut_2pow_round(mem_size, UNIV_PAGE_SIZE); /* Reserve space for the block descriptors. */ + //wangyang @@ �����Ŀ���� ��Ҫ��������Ӧ�� block�ռ� , ���� ����ռ��С�� 16k * 10 ,��ô���� 10 * 4 ������ + // ������ sizeof (*block) block��һ��ָ�룬����ʵ��������� ���� buf_block_t �����ݿ�Ĵ�С mem_size += ut_2pow_round((mem_size / UNIV_PAGE_SIZE) * (sizeof *block) + (UNIV_PAGE_SIZE - 1), UNIV_PAGE_SIZE); chunk->mem_size = mem_size; - chunk->mem = os_mem_alloc_large(&chunk->mem_size); + chunk->mem = os_mem_alloc_large(&chunk->mem_size); //wangyang �����Ƿ��������ڴ� if (UNIV_UNLIKELY(chunk->mem == NULL)) { @@ -1132,16 +1144,40 @@ buf_chunk_init( } #endif // HAVE_LIBNUMA + /* + + struct buf_chunk_t{ + ulint mem_size; !< allocated size of the chunk + ulint size; !< size of frames[] and blocks[] + void* mem; !< pointer to the memory area which + was allocated for the frames + buf_block_t* blocks; !< array of buffer control blocks wangyang @@ ��������ᵽ�� chunk �� ��ÿ��chunk��������block���� +}; + */ + /* Allocate the block descriptors from the start of the memory block. */ - chunk->blocks = (buf_block_t*) chunk->mem; + /** + * wangyang @@ ���ォ mem �����Ϊ buf_block_t * ָ�� + */ + chunk->blocks = (buf_block_t*) chunk->mem; //wangyang mem ��Ӧ�ŷ�����ڴ� /* Align a pointer to the first frame. Note that when os_large_page_size is smaller than UNIV_PAGE_SIZE, we may allocate one fewer block than requested. When it is bigger, we may allocate more blocks than requested. */ + /** + * wangyang @@@ ����� �� mem ����8k ���ж���, ��Ҫ�ǽ��׵�ַ ���չ̶���ʽ���� + */ frame = (byte*) ut_align(chunk->mem, UNIV_PAGE_SIZE); + //wangyang �������� ��ȡ Page ������ + /** + * wangyang @@@ �����mem_size �� �ϲ� ��ʼ�� size �Լ����� ���ӵ� *block_t �Ļ�� + * + * + * + */ chunk->size = chunk->mem_size / UNIV_PAGE_SIZE - (frame != chunk->mem); @@ -1149,23 +1185,41 @@ buf_chunk_init( { ulint size = chunk->size; + /** + * wangyang @@@ ����ܾ����Ҫ�������ǽ�����mem�ڴ�ֳ� + * 2���֣�һ������ͷ��һ������ ÿ��Page���൱��ÿ��Page + * ����һ����Ӧ��ָ�� + * + * �����Ŀ�����ҵ� block_t ��frame �ķֽ�㣬frame ���� Page ǰ���� + * + * + */ while (frame < (byte*) (chunk->blocks + size)) { - frame += UNIV_PAGE_SIZE; - size--; + frame += UNIV_PAGE_SIZE; // wangyang @@ ������� frame ����Page ����ǰ�� + size--; //wangyang @@ ��Ϊ���� ǰ����Page , �������� ��Ҫ���������� �ᳬ����Ӧ�� �ڴ�ʹ�ý��� } - chunk->size = size; + chunk->size = size; // wangyang @@@ ������޸� ���� ��size ���� } /* Init block structs and assign frames for them. Then we assign the frames to the first blocks (we already mapped the memory above). */ + /** + * wangyang @@@ ���Կ��Կ��� ����� block ���ָ���� chunk �ṹ���� blocks �ֶ� + */ block = chunk->blocks; + /** + * wangyang @@ ������ block ���� ��ʼ�� + */ for (i = chunk->size; i--; ) { - buf_block_init(buf_pool, block, frame); + /** + * wangyang @@@ ������ʼ�� + */ + buf_block_init(buf_pool, block, frame); //wangyang �����ʼ��ÿ��Page UNIV_MEM_INVALID(block->frame, UNIV_PAGE_SIZE); /* Add the block to the free list */ @@ -1175,7 +1229,7 @@ buf_chunk_init( ut_ad(buf_pool_from_block(block) == buf_pool); block++; - frame += UNIV_PAGE_SIZE; + frame += UNIV_PAGE_SIZE; //wangyang ���ﲻ�ϱ���ÿ��Page } #ifdef PFS_GROUP_BUFFER_SYNC @@ -1317,6 +1371,10 @@ buf_pool_set_sizes(void) /********************************************************************//** Initialize a buffer pool instance. @return DB_SUCCESS if all goes well. */ +/* + * wangyang @@@ ���� buf pool instance ʵ����ʼ�� + * ʹ�õ�ʱ�� �������Ӧ��chunk ���г�ʼ�� + */ UNIV_INTERN ulint buf_pool_init_instance( @@ -1338,13 +1396,26 @@ buf_pool_init_instance( buf_pool_mutex_enter(buf_pool); if (buf_pool_size > 0) { + + /** + * + */ buf_pool->n_chunks = 1; + /** + * wangyang @@ ��ʼ��ʱ�� ֻ��һ�� chunk + */ buf_pool->chunks = chunk = (buf_chunk_t*) mem_zalloc(sizeof *chunk); UT_LIST_INIT(buf_pool->free); + /** + * wangyang @@ ������ʼ�� chunk ,����ij�ʼ�� �Ὣ���е��ڴ涼��ʼ��Ϊ chunk (һ���Գ�ʼ��) + * + * ��û�� ���� �ָ� + * + */ if (!buf_chunk_init(buf_pool, chunk, buf_pool_size)) { mem_free(chunk); mem_free(buf_pool); @@ -1469,7 +1540,7 @@ buf_pool_init( ulint n_instances) /*!< in: number of instances */ { ulint i; - const ulint size = total_size / n_instances; + const ulint size = total_size / n_instances; //wangyang @@ �����ʹ�� total size / count ��ȡ��Ӧʵ������ ut_ad(n_instances > 0); ut_ad(n_instances <= MAX_BUFFER_POOLS); @@ -1490,12 +1561,21 @@ buf_pool_init( } #endif // HAVE_LIBNUMA +/** + * wangyang @@ ������м��㣬 + */ + /** + * wangyang @@@ ���������� ��ǰ��� pool ����Ĵ�С + */ buf_pool_ptr = (buf_pool_t*) mem_zalloc( n_instances * sizeof *buf_pool_ptr); for (i = 0; i < n_instances; i++) { buf_pool_t* ptr = &buf_pool_ptr[i]; + /** + * wangyang @@ ����� һ��һ���� ��ʼ�� ÿ�� instance + */ if (buf_pool_init_instance(ptr, size, i) != DB_SUCCESS) { /* Free all the instances created so far. */ diff --git a/storage/innobase/dict/dict0boot.cc b/storage/innobase/dict/dict0boot.cc index 94a3af2852b..d0cce0d9e7a 100644 --- a/storage/innobase/dict/dict0boot.cc +++ b/storage/innobase/dict/dict0boot.cc @@ -243,6 +243,10 @@ dict_hdr_create( Initializes the data dictionary memory structures when the database is started. This function is also called when the data dictionary is created. @return DB_SUCCESS or error code. */ +/** + * wangyang ��ʼ������ �ֵ��ڴ�ṹ + + */ UNIV_INTERN dberr_t dict_boot(void) @@ -276,6 +280,9 @@ dict_boot(void) mtr_start(&mtr); /* Create the hash tables etc. */ + /** + * wangyang @@@ �����Ǵ�����Ӧ�� Ŀ¼�� + */ dict_init(); heap = mem_heap_create(450); @@ -302,6 +309,9 @@ dict_boot(void) /* Insert into the dictionary cache the descriptions of the basic system tables */ /*-------------------------*/ + /** + * wangyang ������Ӧ��ϵͳ�� + */ table = dict_mem_table_create("SYS_TABLES", DICT_HDR_SPACE, 8, 0, 0); dict_mem_table_add_col(table, heap, "NAME", DATA_BINARY, 0, 0); diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index 1c9da17cbc0..f10a7145d03 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -1086,6 +1086,7 @@ void dict_init(void) /*===========*/ { + //wangyang @@@ dict_sys 初始化 dict_sys = static_cast(mem_zalloc(sizeof(*dict_sys))); mutex_create(dict_sys_mutex_key, &dict_sys->mutex, SYNC_DICT); @@ -1340,6 +1341,13 @@ dict_table_add_to_cache( } /* Add table to hash table of tables */ + /** + * wangyang 第三个参数 table_hash 是hash 表 , 这里会插入到 + * hash_table 当中 + * + * 这里的功能是 将 table 信息 插入到 table_hash 里面去 + * + */ HASH_INSERT(dict_table_t, name_hash, dict_sys->table_hash, fold, table); diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc index 4d0e0d49259..9259e654c44 100644 --- a/storage/innobase/dict/dict0mem.cc +++ b/storage/innobase/dict/dict0mem.cc @@ -80,6 +80,10 @@ dict_mem_table_create( ut_a(dict_tf_is_valid(flags)); ut_a(!(flags2 & ~DICT_TF2_BIT_MASK)); + /** + * wangyang @@ ��������Կ��� mem_heap_create���� ������ͨ����µ��ڴ���䣬��ͨʱ�� + * ʹ�õ��ڴ��õĶ��� mem_heap_create���� + */ heap = mem_heap_create(DICT_HEAP_SIZE); table = static_cast( diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 6ce4da48bfe..88b73ae880a 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -2978,6 +2978,9 @@ ha_innobase::init_table_handle_for_HANDLER(void) /*********************************************************************//** Opens an InnoDB database. @return 0 on success, error code on failure */ +/** + * wangyang @@ �����ʼ�� innobase + */ static int innobase_init( @@ -3484,6 +3487,9 @@ innobase_init( modules, we check at run time that the size is the same in these compilation modules. */ + /** + * wangyang @@@ �����ʼ�� ���� innobase + */ err = innobase_start_or_create_for_mysql(); if (err != DB_SUCCESS) { @@ -6710,6 +6716,10 @@ ha_innobase::innobase_set_max_autoinc( Stores a row in an InnoDB database, to the table specified in this handle. @return error code */ + +/** + * wangyang *** �������� д������Ϣ + */ UNIV_INTERN int ha_innobase::write_row( @@ -6859,6 +6869,9 @@ ha_innobase::write_row( innobase_srv_conc_enter_innodb(prebuilt->trx); + /** + * wangyang ** ����� ����Ϣ���� + */ error = row_insert_for_mysql((byte*) record, prebuilt); DEBUG_SYNC(user_thd, "ib_after_row_insert"); @@ -17237,6 +17250,9 @@ static struct st_mysql_sys_var* innobase_system_variables[]= { NULL }; +/** + * wangyang @@ ��������� mysql �ij�ʼ��� + */ mysql_declare_plugin(innobase) { MYSQL_STORAGE_ENGINE_PLUGIN, @@ -17245,7 +17261,7 @@ mysql_declare_plugin(innobase) plugin_author, "Supports transactions, row-level locking, and foreign keys", PLUGIN_LICENSE_GPL, - innobase_init, /* Plugin Init */ + innobase_init, /* Plugin Init */ //wangyang innobase ��ʼ�� ��� NULL, /* Plugin Deinit */ INNODB_VERSION_SHORT, innodb_status_variables_export,/* status variables */ diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index 9d3521a0f06..b5e52c7d3e7 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -1620,6 +1620,12 @@ struct buf_page_t{ /** The buffer control block structure */ +/* + * wangyang @@@ �����ʹ���� buf chunk ���� buf0buf.ic ���� + * Ҳ��������֮ǰ ������ buf pool �����ֳɺܶ� �� block + * Ȼ�� ÿ�� block �ֻ���л��� + * + */ struct buf_block_t{ /** @name General fields */ diff --git a/storage/innobase/include/buf0buf.ic b/storage/innobase/include/buf0buf.ic index 56616c6deeb..dcba678707a 100644 --- a/storage/innobase/include/buf0buf.ic +++ b/storage/innobase/include/buf0buf.ic @@ -42,7 +42,7 @@ struct buf_chunk_t{ ulint size; /*!< size of frames[] and blocks[] */ void* mem; /*!< pointer to the memory area which was allocated for the frames */ - buf_block_t* blocks; /*!< array of buffer control blocks */ + buf_block_t* blocks; /*!< array of buffer control blocks */ /* wangyang @@ ��������ᵽ�� chunk �� ��ÿ��chunk��������block���� */ }; /*********************************************************************//** diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h index 6f5643a50d2..1ea935d38e6 100644 --- a/storage/innobase/include/dict0mem.h +++ b/storage/innobase/include/dict0mem.h @@ -920,6 +920,9 @@ the table, DML from memcached will be blocked. */ /** Data structure for a database table. Most fields will be initialized to 0, NULL or FALSE in dict_mem_table_create(). */ +/** + * wangyang @@ ���ݿ���� ���ݽṹ�����ڴ洢��Ӧ�� + */ struct dict_table_t{ diff --git a/storage/innobase/include/hash0hash.h b/storage/innobase/include/hash0hash.h index 6f9a628df5d..0cf5a75b3e7 100644 --- a/storage/innobase/include/hash0hash.h +++ b/storage/innobase/include/hash0hash.h @@ -119,6 +119,14 @@ Assert that the mutex for the table is held */ /*******************************************************************//** Inserts a struct to a hash table. */ +/** + * wangyang Type ��ʾ���� Table ��ʾ hash �ṹ + * fold ��ʾ��Ӧ��hash ֵ data ��Ҫ��������� + * name ����Ӧ�����ƣ�������Ӧ�ڵ��ָ����� + * + * + * + */ #define HASH_INSERT(TYPE, NAME, TABLE, FOLD, DATA)\ do {\ hash_cell_t* cell3333;\ @@ -143,6 +151,8 @@ do {\ struct3333->NAME = DATA;\ }\ } while (0) +//wangyang ����struct3333 ������Ӧ�� hash ���еĽڵ㣬 ��ȡ node +// ��ʾ��Ӧ�� �ڵ���Ϣ��Ȼ��������Ӧ�� data ��Ϣ #ifdef UNIV_HASH_DEBUG # define HASH_ASSERT_VALID(DATA) ut_a((void*) (DATA) != (void*) -1) diff --git a/storage/innobase/include/mem0mem.h b/storage/innobase/include/mem0mem.h index de9b8b29fd9..0bbdadc268a 100644 --- a/storage/innobase/include/mem0mem.h +++ b/storage/innobase/include/mem0mem.h @@ -133,6 +133,9 @@ memory heap. For debugging purposes, takes also the file name and line as arguments. @return own: memory heap, NULL if did not succeed (only possible for MEM_HEAP_BTR_SEARCH type heaps) */ +/* + * wangyang @@ mem_heap_create ���� �� ���ڴ�����Ӧ�� mem_heap ������ mem0mem.ic���� + */ UNIV_INLINE mem_heap_t* mem_heap_create_func( @@ -172,6 +175,10 @@ mem_heap_zalloc( Allocates n bytes of memory from a memory heap. @return allocated storage, NULL if did not succeed (only possible for MEM_HEAP_BTR_SEARCH type heaps) */ +/** + wangyang @@ �����Ǵ� heap �з��� ��Ӧ���ڴ��С + �������� һ�� mem_heap_t �Լ�һ�� �����С���� + */ UNIV_INLINE void* mem_heap_alloc( @@ -237,6 +244,10 @@ Macro for memory buffer allocation */ #define mem_zalloc(N) memset(mem_alloc(N), 0, (N)) +/* + __LINE__����Դ�����в��뵱ǰԴ�����кţ� + __FILE__����Դ�ļ��в��뵱ǰԴ�ļ����� + */ #ifdef UNIV_DEBUG #define mem_alloc(N) mem_alloc_func((N), __FILE__, __LINE__, NULL) #define mem_alloc2(N,S) mem_alloc_func((N), __FILE__, __LINE__, (S)) @@ -251,6 +262,9 @@ Allocates a single buffer of memory from the dynamic memory of the C compiler. Is like malloc of C. The buffer must be freed with mem_free. @return own: free storage */ +/* + * wangyang �Ӷ�̬�ڴ��з����ڴ� + */ UNIV_INLINE void* mem_alloc_func( @@ -368,6 +382,16 @@ mem_validate_all_blocks(void); /*#######################################################################*/ /** The info structure stored at the beginning of a heap block */ +/** + * wangyang @@ ����� mem_block_info_t ���� mem_heap_t�ṹ�� + * ������� mem_block_t �γ����� , mem_block_t ���� mem_block_info_t + * block ���ڴ� ��Դ�� mem_pool (mem_pool �γ����� buddy�ķ��䷽ʽ) + * + * + * mem_block �� �����ķ�ʽ���й��������� ��С����ȷ�� + * + * + */ struct mem_block_info_t { ulint magic_n;/* magic number for debugging */ #ifdef UNIV_DEBUG @@ -387,8 +411,14 @@ struct mem_block_info_t { node and is set to ULINT_UNDEFINED in others. */ ulint type; /*!< type of heap: MEM_HEAP_DYNAMIC, or MEM_HEAP_BUF possibly ORed to MEM_HEAP_BTR_SEARCH */ + /** + * wangyang @@ ������ �����ڴ�ĵ�ַ + */ ulint free; /*!< offset in bytes of the first free position for user data in the block */ + /** + * �ڴ�block����ʼ��ַ + */ ulint start; /*!< the value of the struct field 'free' at the creation of the block */ #ifndef UNIV_HOTBACKUP diff --git a/storage/innobase/include/mem0mem.ic b/storage/innobase/include/mem0mem.ic index 63e68150b61..db845cb8adc 100644 --- a/storage/innobase/include/mem0mem.ic +++ b/storage/innobase/include/mem0mem.ic @@ -186,7 +186,7 @@ mem_heap_alloc( ut_ad(mem_heap_check(heap)); - block = UT_LIST_GET_LAST(heap->base); + block = UT_LIST_GET_LAST(heap->base); //wangyang @@ �������ڻ�ȡ ��Ӧ�� heap�� base ��ַ ut_ad(!(block->type & MEM_HEAP_BUFFER) || (n <= MEM_MAX_ALLOC_IN_BUF)); @@ -204,6 +204,10 @@ mem_heap_alloc( } } + /* + wangyang @@�� heap ��Ѱ�ҳ� �����������ڴ�� + ����� ��ǰ heap Ѱ�ҷ��������ڴ� Ȼ������ block �׵�ַ + */ free = mem_block_get_free(block); buf = (byte*) block + free; @@ -446,6 +450,7 @@ mem_heap_create_func( n = MEM_BLOCK_START_SIZE; } + // wangyang mem_heap_t ͬʱҲ�� mem_block_t ��ͬһ�������ڴ�������Դ�� mem_pool block = mem_heap_create_block(NULL, n, type, file_name, line); if (block == NULL) { @@ -460,6 +465,9 @@ mem_heap_create_func( #ifdef UNIV_MEM_DEBUG + /* + wangyang �����Dz��뵽��Ӧ��hash ���У��ᰴ���ļ����� �Լ� line ����hash + */ mem_hash_insert(block, file_name, line); #endif diff --git a/storage/innobase/include/mem0pool.h b/storage/innobase/include/mem0pool.h index a65ba50fdf9..1d0d0672304 100644 --- a/storage/innobase/include/mem0pool.h +++ b/storage/innobase/include/mem0pool.h @@ -37,11 +37,24 @@ struct mem_pool_t; extern mem_pool_t* mem_comm_pool; /** Memory area header */ +/** + * wangyang @@ �����ڴ�ͷ + */ struct mem_area_t{ ulint size_and_free; /*!< memory area size is obtained by anding with ~MEM_AREA_FREE; area in a free list if ANDing with MEM_AREA_FREE results in nonzero */ + /** + * wangyang ������� mem_area_t ��Ϊһ�� �ڵ� + */ + /* + ÿ�� free_list ������ һ�� Node�ڵ㣬�� ǰ���ͺ�� prev �� next + struct ut_list_node { + TYPE* prev; + TYPE* next; + }; + */ UT_LIST_NODE_T(mem_area_t) free_list; /*!< free list node */ }; diff --git a/storage/innobase/include/os0sync.h b/storage/innobase/include/os0sync.h index 367c2a31924..4b16a074d08 100644 --- a/storage/innobase/include/os0sync.h +++ b/storage/innobase/include/os0sync.h @@ -83,9 +83,22 @@ struct os_fast_mutex_t { }; /** Operating system event handle */ +/** + * wangyang �������� �ź��� + */ typedef struct os_event* os_event_t; /** An asynchronous signal sent between threads */ +/* + * wangyang ����˵�ĺ������ �����������߳�֮ǰ�� ���� �ź��� ���͵��߳� + * + * ������ź��� ��Ҫ�� ���������߳�֮���֪ͨ �����dz����Ķ���߳� + * + * ��Ҫ���� os_event_create os_event_set os_event_reset + * ÿ��reset ֮�� ������ signal_count �������ӣ� + * ����signal_count ��ʾ���� ���ô����������� �ȴ�֪ͨ������ + * + */ struct os_event { #ifdef __WIN__ HANDLE handle; /*!< kernel event object, slow, @@ -97,10 +110,18 @@ struct os_event { in the signaled state, i.e., a thread does not stop if it tries to wait for this event */ + /** + * wangyang + */ ib_int64_t signal_count; /*!< this is incremented each time the event becomes signaled */ os_cond_t cond_var; /*!< condition variable is used in waiting for the event */ + + /** + * wangyang ut_list_node_t ��һ�� �ڵ��б� , ʹ����Ӧ�ĺ궨�� + * ÿ���ڵ� ��ʾһ�������еĽڵ�, ��prev �� next + */ UT_LIST_NODE_T(os_event_t) os_event_list; /*!< list of all created events */ }; diff --git a/storage/innobase/include/ut0byte.ic b/storage/innobase/include/ut0byte.ic index 873d98c727e..642b1c8b967 100644 --- a/storage/innobase/include/ut0byte.ic +++ b/storage/innobase/include/ut0byte.ic @@ -84,12 +84,18 @@ ut_align( const void* ptr, /*!< in: pointer */ ulint align_no) /*!< in: align by this number */ { - ut_ad(align_no > 0); + ut_ad(align_no > 0); //wangyang @@ ����� ut_ad �� assert �Ƕ��� �����ж��Ƿ� ut_ad(((align_no - 1) & align_no) == 0); ut_ad(ptr); ut_ad(sizeof(void*) == sizeof(ulint)); + /** + wangyang @@@ �����ͨ������ķ�ʽ ��ȡ ��Ӧ�Ķ����ַ + �������� �����һ�����룬����pageNo = 16 ����ô���� + �Ķ������ ~(16 - 1) ��Ҳ���� 1111xxx0000, �����Ϳ��Խ�����Ӧ�Ķ��� + +(����)һ�� (pageNo -1)��ԭ���� �������׵�ַ�� ǰ��ķ����� + */ return((void*)((((ulint) ptr) + align_no - 1) & ~(align_no - 1))); } diff --git a/storage/innobase/include/ut0list.h b/storage/innobase/include/ut0list.h index 29fc8669ce4..c5cc5547318 100644 --- a/storage/innobase/include/ut0list.h +++ b/storage/innobase/include/ut0list.h @@ -151,6 +151,10 @@ ib_list_is_empty( const ib_list_t* list); /* in: list */ /* List. */ +/** + * wangyang @@@ mysql �����˫������ + * �����˫������ ֻ��һ�� �򵥵����� ������ʵ���̰߳�ȫ + */ struct ib_list_t { ib_list_node_t* first; /*!< first node */ ib_list_node_t* last; /*!< last node */ @@ -159,6 +163,9 @@ struct ib_list_t { }; /* A list node. */ +/** + * wangyang @@˫�������ڵ� + */ struct ib_list_node_t { ib_list_node_t* prev; /*!< previous node */ ib_list_node_t* next; /*!< next node */ diff --git a/storage/innobase/include/ut0lst.h b/storage/innobase/include/ut0lst.h index b53e7ade4c1..e42cbf69cbf 100644 --- a/storage/innobase/include/ut0lst.h +++ b/storage/innobase/include/ut0lst.h @@ -92,6 +92,9 @@ ut_elem_get_node(Type& elem, size_t offset) { ut_a(offset < sizeof(elem)); + /** + * wangyang reinterpret_cast���� �޹�����ת�� + */ return(*reinterpret_cast*>( reinterpret_cast(&elem) + offset)); } @@ -119,11 +122,19 @@ ut_list_prepend( Type& elem, size_t offset) { + /** + * wangyang �����Ŀ���� ��ȡ��� elem �еĽڵ㲿�� + * ����һ�� ut_mem_block_list �л�ȡ ��Ӧ�� ��� offset + * �ҵ���Ӧ��λ�� + */ ut_list_node& elem_node = ut_elem_get_node(elem, offset); elem_node.prev = 0; elem_node.next = list.start; + /** + * ��֮ǰ�� start �ڵ��prev ָ�� �����¼�������Ľڵ� + */ if (list.start != 0) { ut_list_node& base_node = ut_elem_get_node(*list.start, offset); diff --git a/storage/innobase/include/ut0vec.h b/storage/innobase/include/ut0vec.h index 432fb348a09..b7be6251cdb 100644 --- a/storage/innobase/include/ut0vec.h +++ b/storage/innobase/include/ut0vec.h @@ -311,17 +311,24 @@ ib_ut_allocator_free( ib_alloc_t* ib_ut_alloc); /* in: alloc instace to free */ /* Allocator used by ib_vector_t. */ +/** + * wangyang @@ + */ struct ib_alloc_t { - ib_mem_alloc_t mem_malloc; /* For allocating memory */ - ib_mem_free_t mem_release; /* For freeing memory */ - ib_mem_resize_t mem_resize; /* For resizing memory */ - void* arg; /* Currently if not NULL then it + //��Ӧ�� ����ָ�� ����������ʱ�� �ڽ���һ������ + ib_mem_alloc_t mem_malloc; /* For allocating memory */ ////��������malloc����ָ�� + ib_mem_free_t mem_release; /* For freeing memory */ //��������free����ָ�� + ib_mem_resize_t mem_resize; /* For resizing memory */ //�����������¶���Ѵ�Сָ�� + void* arg; /* Currently if not NULL then it //�Ѿ���������ϵͳ��malloc��ʽ�����ֵΪNULL points to the heap instance */ }; /* See comment at beginning of file. */ +/** + * wangyang ������ mysql �Զ��� verctor + */ struct ib_vector_t { - ib_alloc_t* allocator; /* Allocator, because one size + ib_alloc_t* allocator; /* Allocator, because one size ʹ�� ���涨��� ib_alloc_t���з���һ���ڴ� doesn't fit all */ void* data; /* data elements */ ulint used; /* number of elements currently used */ diff --git a/storage/innobase/include/ut0wqueue.h b/storage/innobase/include/ut0wqueue.h index 33385ddf2d4..0138f9c78d4 100644 --- a/storage/innobase/include/ut0wqueue.h +++ b/storage/innobase/include/ut0wqueue.h @@ -96,9 +96,14 @@ ib_wqueue_timedwait( ib_time_t wait_in_usecs); /* in: wait time in micro seconds */ /* Work queue. */ +/** + * wangyang @@ mysql ʵ�ֵ� fifo���� (��������) + * + * os_event_t ���ڽ��� ֪ͨ���������֮�� ֪ͨ������ + */ struct ib_wqueue_t { - ib_mutex_t mutex; /*!< mutex protecting everything */ - ib_list_t* items; /*!< work item list */ + ib_mutex_t mutex; /*!< mutex protecting everything */ // �����ź��� + ib_list_t* items; /*!< work item list */ //ʹ��list ��Ϊ�������� os_event_t event; /*!< event we use to signal additions to list */ }; diff --git a/storage/innobase/mem/mem0dbg.cc b/storage/innobase/mem/mem0dbg.cc index a77785a369a..2396cba7a1e 100644 --- a/storage/innobase/mem/mem0dbg.cc +++ b/storage/innobase/mem/mem0dbg.cc @@ -142,6 +142,21 @@ mem_field_trailer_get_check(byte* field) #ifndef UNIV_HOTBACKUP /******************************************************************//** Initializes the memory system. */ +/** + * wangyang �������˵�� ����������ڳ�ʼ innodb �ڴ�ϵͳ + */ + /* + innodb_additional_mem_pool_size �� InnoDB �������������ֵ���Ϣ�������ڲ����ݽṹ���ڴ�صĴ�С����λ�� byte������Ĭ��ֵΪ8M�����ݿ��еı�����Խ�࣬����ֵӦ��Խ����� InnoDB �������ڴ���е��ڴ棬�ͻ�Ӳ���ϵͳ�з����ڴ棬ͬʱ�� error log �д��뱨����Ϣ�� + +innodb_use_sys_malloc ����Ϊ ON ʱ��innodb_additional_mem_pool_size ʧЧ��ֱ�ӴӲ���ϵͳ�����ڴ棩�� + +innodb_additional_mem_pool_size �� innodb_use_sys_malloc �� MySQL 5.7.4 ���Ƴ��� + + + ���ڲ���ϵͳ���ڴ���������ܺͿ������Խϲ���ҵ�ʱû���ʺ϶����CPU���ڴ�����������ԣ�InnoDB ʵ����һ���Լ����ڴ����ϵͳ����Ϊ�ڴ�ϵͳ�IJ���֮һ��������innodb_additional_mem_pool_size�� +���Ŷ����CPU�Ĺ㷺Ӧ�úͲ���ϵͳ�ij��죬����ϵͳ�ܹ��ṩ���ܸ��ߡ��������Ը��õ��ڴ������������ Hoard��libumem��mtmalloc��ptmalloc��tbbmalloc �� TCMalloc �ȡ�InnoDB ʵ�ֵ��ڴ��������Ȳ���ϵͳ���ڴ��������û���������ƣ�������֮��İ汾�����Ƴ� innodb_additional_mem_pool_size �� innodb_use_sys_malloc ����������ͳһʹ�ò���ϵͳ���ڴ�������� + + */ UNIV_INTERN void mem_init( @@ -174,7 +189,10 @@ mem_init( size = 1; } - mem_comm_pool = mem_pool_create(size); + /** + * wangyang @@@ �������ڴ��� �ڴ�� + */ + mem_comm_pool = mem_pool_create(size); //���ﴴ�� �����ڴ�� } /******************************************************************//** diff --git a/storage/innobase/mem/mem0mem.cc b/storage/innobase/mem/mem0mem.cc index e066aff5b30..68b15ae227f 100644 --- a/storage/innobase/mem/mem0mem.cc +++ b/storage/innobase/mem/mem0mem.cc @@ -328,16 +328,23 @@ mem_heap_create_block_func( len = MEM_BLOCK_HEADER_SIZE + MEM_SPACE_NEEDED(n); #ifndef UNIV_HOTBACKUP + /** + * wangyang @@ ����Ҫ���� type �ķ�ʽ �����ж� ʹ�ú��ַ�ʽ �����з��ڴ� + * ������ dynamic ���� ���� С�� 1/2 Page + */ if (type == MEM_HEAP_DYNAMIC || len < UNIV_PAGE_SIZE / 2) { ut_ad(type == MEM_HEAP_DYNAMIC || n <= MEM_MAX_ALLOC_IN_BUF); + /** + * wangyang @@@ ������Կ��� mem_block_t �Ǵ� mem_area ���з�������� + */ block = static_cast( mem_area_alloc(&len, mem_comm_pool)); } else { len = UNIV_PAGE_SIZE; - if ((type & MEM_HEAP_BTR_SEARCH) && heap) { + if ((type & MEM_HEAP_BTR_SEARCH) && heap) { //wangyang @@ ��������� ������ ��������type Ȼ���� heap ������� /* We cannot allocate the block from the buffer pool, but must get the free block from the heap header free block field */ @@ -350,7 +357,7 @@ mem_heap_create_block_func( return(NULL); } } else { - buf_block = buf_block_alloc(NULL); + buf_block = buf_block_alloc(NULL); // wangyang @@ ��������� ��� buf_pool �н��з��� } block = (mem_block_t*) buf_block->frame; diff --git a/storage/innobase/mem/mem0pool.cc b/storage/innobase/mem/mem0pool.cc index fe9a84d21fa..26d61c329f9 100644 --- a/storage/innobase/mem/mem0pool.cc +++ b/storage/innobase/mem/mem0pool.cc @@ -100,12 +100,31 @@ pool, and after that its locks will grow into the buffer pool. */ /** Data structure for a memory pool. The space is allocated using the buddy algorithm, where free list i contains areas of size 2 to power i. */ +/** + * wangyang @@ ����һ���ڴ�� ��Ϊ mem_pool_t ȥʹ�� + */ struct mem_pool_t{ byte* buf; /*!< memory pool */ ulint size; /*!< memory common pool size */ ulint reserved; /*!< amount of currently allocated memory */ ib_mutex_t mutex; /*!< mutex protecting this struct */ + /** + * mem_pool_t ��free_list�� �����ڵ�, Ҳ���Կ����� + * ut_list_node�Ŀ��ƽڵ㣬���ڱ������� list�ж��� �ڵ� + * start ��ʼ�ڵ� + * end β���ڵ� + */ + /* + struct ut_list_base { + typedef TYPE elem_type; + ulint count; !< count of nodes in list + TYPE* start; !< pointer to list start, NULL if empty + TYPE* end; !< pointer to list end, NULL if empty +}; + + +*/ UT_LIST_BASE_NODE_T(mem_area_t) free_list[64]; /*!< lists of free memory areas: an area is put to the list whose number @@ -212,6 +231,14 @@ mem_area_set_free( | free; } +/* + * + �����ڴ�����ķ������£� + ut_malloc_low ����һ��n���ȵ��ڴ�飬��������Ŀ��¼��ut_mem_block_list����. + ut_malloc ��ut_malloc_low������ͬ�����ǻ���0��ʼ����������ڴ档 + ut_free �ͷ�һ��������ڴ�飬�������ut_mem_block_list����ɾ���� + ut_free_all_mem �ͷ�ut_mem_block_list���е��ڴ�鲢���ut_mem_block_list + */ /********************************************************************//** Creates a memory pool. @return memory pool */ @@ -226,11 +253,23 @@ mem_pool_create( ulint i; ulint used; + /** + * wangyang ���� malloc ������һ�� mem_pool_t ���� + */ pool = static_cast(ut_malloc(sizeof(mem_pool_t))); + /** + * + * wangyang ���� ʹ�õ��� os malloc �����һ�����ڴ棬 + * ��û��ʹ�� ��Ӧ���ڴ�������� ������һ���鵥�����ڴ� + * Ȼ����뵽 �������� + * + */ pool->buf = static_cast(ut_malloc_low(size, TRUE)); pool->size = size; + //wangyang @ ���ڴ��� һ�� mutex ���� + // mem_pool_mutex_key ��Ӧ�� ��Ӧ��ֵ mem_pool_mutex �����ڶ�Ӧ mutex ������ mutex_create(mem_pool_mutex_key, &pool->mutex, SYNC_MEM_POOL); /* Initialize the free lists */ @@ -359,6 +398,12 @@ mem_pool_fill_free_list( Allocates memory from a pool. NOTE: This low-level function should only be used in mem0mem.*! @return own: allocated memory buffer */ +/** + * + wangyang @@@ �� common_pool���� �����ڴ� �� mem_heap_t Ҳ�Ǵ������������ڴ� + mem_heap_t �� block �������ڴ������ʽ + mem_pool_t �� buddy �ķ��䷽ʽ������block + */ UNIV_INTERN void* mem_area_alloc( diff --git a/storage/innobase/os/os0proc.cc b/storage/innobase/os/os0proc.cc index ff6d65e4ae6..db19827b86c 100644 --- a/storage/innobase/os/os0proc.cc +++ b/storage/innobase/os/os0proc.cc @@ -154,6 +154,7 @@ os_mem_alloc_large( /* Align block size to system page size */ ut_ad(ut_is_2pow(size)); size = *n = ut_2pow_round(*n + (size - 1), size); + //wangyang @@@ �����ʹ�� mmap ���з��� ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | OS_MAP_ANON, -1, 0); if (UNIV_UNLIKELY(ptr == (void*) -1)) { diff --git a/storage/innobase/os/os0sync.cc b/storage/innobase/os/os0sync.cc index cd57abd0623..955e8534d2b 100644 --- a/storage/innobase/os/os0sync.cc +++ b/storage/innobase/os/os0sync.cc @@ -125,6 +125,9 @@ os_cond_init( ut_a(initialize_condition_variable != NULL); initialize_condition_variable(cond); #else + /** + * wangyang �������ڳ�ʼ�� cond �ṹ�� + */ ut_a(pthread_cond_init(cond, NULL) == 0); #endif } @@ -369,6 +372,8 @@ os_event_create(void) { event = static_cast(ut_malloc(sizeof *event)); +// os_event_wait_low(event,) + #ifndef PFS_SKIP_EVENT_MUTEX os_fast_mutex_init(event_os_mutex_key, &event->os_mutex); #else @@ -446,6 +451,10 @@ that this thread should not wait in case of an intervening call to os_event_set() between this os_event_reset() and the os_event_wait_low() call. See comments for os_event_wait_low(). @return current signal_count. */ +/** + + wangyang reset + */ UNIV_INTERN ib_int64_t os_event_reset( @@ -584,10 +593,18 @@ os_event_wait_low( os_fast_mutex_lock(&event->os_mutex); + /** + * wangyang ������� reset_sig_count ��0�Ļ�ô����ô�ͻ����¸�ֵΪ ��Ӧ���ź����� + */ if (!reset_sig_count) { reset_sig_count = event->signal_count; } + + + /** + * wangyang ����������� �ź����ĵȴ�������������ڵȴ� ��Ӧ��������� + */ while (!event->is_set && event->signal_count == reset_sig_count) { os_cond_wait(&(event->cond_var), &(event->os_mutex)); @@ -825,6 +842,12 @@ os_fast_mutex_init_func( InitializeCriticalSection((LPCRITICAL_SECTION) fast_mutex); #else + /** + * wangyang ����ʹ�� pthread_mutex �� �� fast_mutex ���г�ʼ�� + */ + +// pthread_mutex_lock(fast_mutex) + ut_a(0 == pthread_mutex_init(fast_mutex, MY_MUTEX_INIT_FAST)); #endif if (UNIV_LIKELY(os_sync_mutex_inited)) { diff --git a/storage/innobase/srv/srv0srv.cc b/storage/innobase/srv/srv0srv.cc index 21ac1aeee62..8afb45b79cc 100644 --- a/storage/innobase/srv/srv0srv.cc +++ b/storage/innobase/srv/srv0srv.cc @@ -1038,7 +1038,11 @@ srv_general_init(void) recv_sys_var_init(); os_sync_init(); sync_init(); - mem_init(srv_mem_pool_size); + /** + * wangyang @@ �����ʼ������ mem_pool �� buf_pool �Dz�һ���ģ���ʼ�� �õ��� malloc + * srv_mem_pool_size = innobase_additional_mem_pool_size + */ + mem_init(srv_mem_pool_size); //wangyang @@ �ڴ�س�ʼ�� innodb�ڴ� ϵͳ�ij�ʼ�� que_init(); row_mysql_init(); } @@ -1085,6 +1089,9 @@ srv_boot(void) /* Initialize synchronization primitives, memory management, and thread local storage */ + /** + * wangyang @@ �÷������� ����������ʼ�� ���� �ڴ�ϵͳ�ij�ʼ�� + */ srv_general_init(); /* Initialize this module */ diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index 25a27b701ce..107c4898b11 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -1849,6 +1849,9 @@ innobase_start_or_create_for_mysql(void) srv_buf_pool_instances = 1; } + /** + * wangyang @@ innobase ���� + */ srv_boot(); ib_logf(IB_LOG_LEVEL_INFO, @@ -1975,6 +1978,10 @@ innobase_start_or_create_for_mysql(void) ib_logf(IB_LOG_LEVEL_INFO, "Initializing buffer pool, size = %.1f%c", size, unit); + //wangyang @@ ����ᴴ�� buf pool �Լ� buf pool instances + /** + * ����ij�ʼ�� �dz�ʼ�� buf_pool ������ʹ�õĶ��� ʹ�� mmap + */ err = buf_pool_init(srv_buf_pool_size, srv_buf_pool_instances); if (err != DB_SUCCESS) { @@ -2446,7 +2453,8 @@ innobase_start_or_create_for_mysql(void) to access space 0, and the insert buffer at this stage already works for space 0. */ - err = dict_boot(); + + err = dict_boot(); //wangyang @@ ��ʼ�� dict_table if (err != DB_SUCCESS) { return(err); diff --git a/storage/innobase/ut/ut0mem.cc b/storage/innobase/ut/ut0mem.cc index 2bb5d9ce332..fa8d1eb58b5 100644 --- a/storage/innobase/ut/ut0mem.cc +++ b/storage/innobase/ut/ut0mem.cc @@ -88,6 +88,10 @@ ut_mem_init(void) /**********************************************************************//** Allocates memory. @return own: allocated memory */ + +/* + * wangyang ut_malloc_low ����һ��n���ȵ��ڴ�飬��������Ŀ��¼��ut_mem_block_list����. + */ UNIV_INTERN void* ut_malloc_low( @@ -114,6 +118,9 @@ ut_malloc_low( retry: os_fast_mutex_lock(&ut_list_mutex); + /** + * wangyang ����ͨ�� malloc �����ڴ� + */ ret = malloc(n + sizeof(ut_mem_block_t)); if (ret == NULL && retry_count < 60) { @@ -192,6 +199,10 @@ ut_malloc_low( ut_total_allocated_memory += n + sizeof(ut_mem_block_t); + /** + * wangyang �����Ŀ���� ���´������� ret �ڵ����ӵ� ut_mem_block_list ��������У���һ��ȫ�� ��̬���� + * ��һ�������� name �ڶ��������� ʵ�ʶ�Ӧ�� list ������������һ��ָ�� + */ UT_LIST_ADD_FIRST(mem_block_list, ut_mem_block_list, ((ut_mem_block_t*) ret)); os_fast_mutex_unlock(&ut_list_mutex); diff --git a/strings/ctype-big5.c b/strings/ctype-big5.c index 8838aa7e4f4..ffbf72ed1b7 100644 --- a/strings/ctype-big5.c +++ b/strings/ctype-big5.c @@ -6832,6 +6832,9 @@ size_t my_well_formed_len_big5(const CHARSET_INFO *cs MY_ATTRIBUTE((unused)), } +/** + * wangyang + */ static MY_COLLATION_HANDLER my_collation_big5_chinese_ci_handler = { NULL, /* init */ diff --git a/strings/ctype-mb.c b/strings/ctype-mb.c index faac2c94335..8b72249e947 100644 --- a/strings/ctype-mb.c +++ b/strings/ctype-mb.c @@ -677,6 +677,10 @@ my_strcasecmp_mb_bin(const CHARSET_INFO *cs MY_ATTRIBUTE((unused)), } +/** + * + wangyang ** �������� hash_sort ���� + */ void my_hash_sort_mb_bin(const CHARSET_INFO *cs MY_ATTRIBUTE((unused)), const uchar *key, size_t len,ulong *nr1, ulong *nr2) diff --git a/strings/ctype-utf8.c b/strings/ctype-utf8.c index e4d1faa2a8f..c1cd2e3c545 100644 --- a/strings/ctype-utf8.c +++ b/strings/ctype-utf8.c @@ -6089,6 +6089,9 @@ static MY_COLLATION_HANDLER my_collation_utf8_general_ci_handler = }; +/** + * wangyang *** 这里会设置 hash_sort 函数 + */ static MY_COLLATION_HANDLER my_collation_utf8_bin_handler = { NULL, /* init */ @@ -6100,7 +6103,7 @@ static MY_COLLATION_HANDLER my_collation_utf8_bin_handler = my_wildcmp_mb_bin, my_strcasecmp_mb_bin, my_instr_mb, - my_hash_sort_mb_bin, + my_hash_sort_mb_bin, //wangyang *** 这里设置 hash_sort函数 my_propagate_simple };