diff options
author | unknown <monty@donna.mysql.com> | 2000-10-25 01:50:46 +0300 |
---|---|---|
committer | unknown <monty@donna.mysql.com> | 2000-10-25 01:50:46 +0300 |
commit | 5aacf92e2215cc40a8d8934fe7376180fe30ee10 (patch) | |
tree | e2752fa618359db15b27254ae137517f9bd19779 /sql | |
parent | 08dc21df3ad57f782bce0b7277900e880415a0a5 (diff) | |
download | mariadb-git-5aacf92e2215cc40a8d8934fe7376180fe30ee10.tar.gz |
Added bdb_lock_max and fixed bug in BDB tables when using key parts
Docs/Makefile.am:
Don't try to get the manual from SCCS
Docs/manual.texi:
Added bdb_lock_max + some information about Linux and big files
myisam/myisamchk.c:
Code cleanup
mysql.proj:
updated
sql/field.cc:
Added compare of packed BDB key
sql/field.h:
Added compare of packed BDB key
sql/ha_berkeley.cc:
Added compare of packed BDB keys and bdb_lock_max variable
sql/ha_berkeley.h:
Added bdb_lock_max variable
sql/key.cc:
cleanup
sql/mysqld.cc:
Added bdb_lock_max
Diffstat (limited to 'sql')
-rw-r--r-- | sql/field.cc | 65 | ||||
-rw-r--r-- | sql/field.h | 5 | ||||
-rw-r--r-- | sql/ha_berkeley.cc | 47 | ||||
-rw-r--r-- | sql/ha_berkeley.h | 2 | ||||
-rw-r--r-- | sql/key.cc | 2 | ||||
-rw-r--r-- | sql/mysqld.cc | 3 |
6 files changed, 117 insertions, 7 deletions
diff --git a/sql/field.cc b/sql/field.cc index 459c53ffcb1..639c2def068 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -3439,6 +3439,23 @@ int Field_string::pack_cmp(const char *a, const char *b, uint length) } +int Field_string::pack_cmp(const char *b, uint length) +{ + uint b_length= (uint) (uchar) *b++; + char *end= ptr + field_length; + while (end > ptr && end[-1] == ' ') + end--; + uint a_length = (uint) (end - ptr); + + if (binary_flag) + { + int cmp= memcmp(ptr,b,min(a_length,b_length)); + return cmp ? cmp : (int) (a_length - b_length); + } + return my_sortncmp(ptr,a_length, b, b_length); +} + + uint Field_string::packed_col_length(const char *ptr) { if (field_length > 255) @@ -3637,6 +3654,27 @@ int Field_varstring::pack_cmp(const char *a, const char *b, uint key_length) return my_sortncmp(a,a_length, b,b_length); } +int Field_varstring::pack_cmp(const char *b, uint key_length) +{ + char *a=ptr+2; + uint a_length=uint2korr(ptr); + uint b_length; + if (key_length > 255) + { + b_length=uint2korr(b); b+=2; + } + else + { + b_length= (uint) (uchar) *b++; + } + if (binary_flag) + { + int cmp= memcmp(a,b,min(a_length,b_length)); + return cmp ? cmp : (int) (a_length - b_length); + } + return my_sortncmp(a,a_length, b,b_length); +} + uint Field_varstring::packed_col_length(const char *ptr) { if (field_length > 255) @@ -4019,6 +4057,33 @@ int Field_blob::pack_cmp(const char *a, const char *b, uint key_length) return my_sortncmp(a,a_length, b,b_length); } + +int Field_blob::pack_cmp(const char *b, uint key_length) +{ + char *a; + memcpy_fixed(&a,ptr+packlength,sizeof(char*)); + if (!a) + return key_length > 0 ? -1 : 0; + uint a_length=get_length(ptr); + uint b_length; + + if (key_length > 255) + { + b_length=uint2korr(b); b+=2; + } + else + { + b_length= (uint) (uchar) *b++; + } + if (binary_flag) + { + int cmp= memcmp(a,b,min(a_length,b_length)); + return cmp ? cmp : (int) (a_length - b_length); + } + return my_sortncmp(a,a_length, b,b_length); +} + + char *Field_blob::pack_key(char *to, const char *from, uint max_length) { uint length=uint2korr(to); diff --git a/sql/field.h b/sql/field.h index f8ba329375b..4af7c17486a 100644 --- a/sql/field.h +++ b/sql/field.h @@ -177,6 +177,8 @@ public: virtual int pack_cmp(const char *a,const char *b, uint key_length_arg) { return cmp(a,b); } + virtual int pack_cmp(const char *b, uint key_length_arg) + { return cmp(ptr,b); } uint offset(); // Should be inline ... void copy_from_tmp(int offset); uint fill_cache_field(struct st_cache_field *copy); @@ -726,6 +728,7 @@ public: char *pack(char *to, const char *from, uint max_length=~(uint) 0); const char *unpack(char* to, const char *from); int pack_cmp(const char *a,const char *b,uint key_length); + int pack_cmp(const char *b,uint key_length); uint packed_col_length(const char *to); uint max_packed_col_length(uint max_length); uint size_of() const { return sizeof(*this); } @@ -777,6 +780,7 @@ public: char *pack(char *to, const char *from, uint max_length=~(uint) 0); const char *unpack(char* to, const char *from); int pack_cmp(const char *a, const char *b, uint key_length); + int pack_cmp(const char *b, uint key_length); uint packed_col_length(const char *to); uint max_packed_col_length(uint max_length); uint size_of() const { return sizeof(*this); } @@ -891,6 +895,7 @@ public: } char *pack_key(char *to, const char *from, uint max_length=~(uint) 0); int pack_cmp(const char *a, const char *b, uint key_length); + int pack_cmp(const char *b, uint key_length); uint packed_col_length(const char *col_ptr) { return get_length(col_ptr)+packlength;} virtual uint max_packed_col_length(uint max_length) diff --git a/sql/ha_berkeley.cc b/sql/ha_berkeley.cc index 06d0927854f..1239c7db7d3 100644 --- a/sql/ha_berkeley.cc +++ b/sql/ha_berkeley.cc @@ -68,6 +68,7 @@ ulong berkeley_cache_size; char *berkeley_home, *berkeley_tmpdir, *berkeley_logdir; long berkeley_lock_scan_time=0; ulong berkeley_trans_retry=5; +ulong berkeley_lock_max; pthread_mutex_t bdb_mutex; static DB_ENV *db_env; @@ -116,6 +117,8 @@ bool berkeley_init(void) db_env->set_cachesize(db_env, 0, berkeley_cache_size, 0); db_env->set_lk_detect(db_env, berkeley_lock_type); + if (berkeley_lock_max) + db_env->set_lk_max(db_env, berkeley_lock_max); if (db_env->open(db_env, berkeley_home, berkeley_init_flags | DB_INIT_LOCK | @@ -224,8 +227,13 @@ berkeley_cmp_packed_key(DB *file, const DBT *new_key, const DBT *saved_key) int cmp; if (key_part->null_bit) { - if (*new_key_ptr++ != *saved_key_ptr++) - return ((int) new_key_ptr[-1] - (int) saved_key_ptr[-1]); + if (*new_key_ptr != *saved_key_ptr++) + return ((int) *new_key_ptr - (int) saved_key_ptr[-1]); + if (!*new_key_ptr++) + { + key_length--; + continue; + } } if ((cmp=key_part->field->pack_cmp(new_key_ptr,saved_key_ptr, key_part->length))) @@ -263,6 +271,36 @@ berkeley_cmp_fix_length_key(DB *file, const DBT *new_key, const DBT *saved_key) } +/* Compare key against row */ + +static bool +berkeley_key_cmp(TABLE *table, KEY *key_info, const char *key, uint key_length) +{ + KEY_PART_INFO *key_part= key_info->key_part, + *end=key_part+key_info->key_parts; + + for ( ; key_part != end && (int) key_length > 0; key_part++) + { + int cmp; + if (key_part->null_bit) + { + key_length--; + if (*key != (table->record[0][key_part->null_offset] & + key_part->null_bit) ? 0 : 1) + return 1; + if (!*key++) // Null value + continue; + } + if ((cmp=key_part->field->pack_cmp(key,key_part->length))) + return cmp; + uint length=key_part->field->packed_col_length(key); + key+=length; + key_length-=length; + } + return 0; +} + + int ha_berkeley::open(const char *name, int mode, uint test_if_locked) { char name_buff[FN_REFLEN]; @@ -1118,9 +1156,8 @@ int ha_berkeley::index_read(byte * buf, const byte * key, key_info->handler.bdb_return_if_eq= 0; if (!error && find_flag == HA_READ_KEY_EXACT) { - /* Check that we didn't find a key that wasn't equal to the current - one */ - if (!error && ::key_cmp(table, key_buff2, active_index, key_len)) + /* Ensure that we found a key that is equal to the current one */ + if (!error && berkeley_key_cmp(table, key_info, key_buff2, key_len)) error=HA_ERR_KEY_NOT_FOUND; } } diff --git a/sql/ha_berkeley.h b/sql/ha_berkeley.h index b44b112b0ed..84061ae09be 100644 --- a/sql/ha_berkeley.h +++ b/sql/ha_berkeley.h @@ -147,7 +147,7 @@ class ha_berkeley: public handler extern bool berkeley_skip; extern u_int32_t berkeley_init_flags,berkeley_lock_type,berkeley_lock_types[]; -extern ulong berkeley_cache_size; +extern ulong berkeley_cache_size, berkeley_lock_max; extern char *berkeley_home, *berkeley_tmpdir, *berkeley_logdir; extern long berkeley_lock_scan_time; extern TYPELIB berkeley_lock_typelib; diff --git a/sql/key.cc b/sql/key.cc index 8678202922e..87595fda06d 100644 --- a/sql/key.cc +++ b/sql/key.cc @@ -171,7 +171,7 @@ int key_cmp(TABLE *table,const byte *key,uint idx,uint key_length) { key_length--; if (*key != test(table->record[0][key_part->null_offset] & - key_part->null_bit)) + key_part->null_bit)) return 1; if (*key) { diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 7e156077723..6cb24de17c5 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2333,6 +2333,8 @@ CHANGEABLE_VAR changeable_vars[] = { #ifdef HAVE_BERKELEY_DB { "bdb_cache_size", (long*) &berkeley_cache_size, KEY_CACHE_SIZE, 20*1024, (long) ~0, 0, IO_SIZE }, + { "bdb_lock_max", (long*) &berkeley_lock_max, + 1000, 0, (long) ~0, 0, 1 }, #endif { "connect_timeout", (long*) &connect_timeout, CONNECT_TIMEOUT, 2, 65535, 0, 1 }, @@ -2413,6 +2415,7 @@ struct show_var_st init_vars[]= { #ifdef HAVE_BERKELEY_DB {"bdb_cache_size", (char*) &berkeley_cache_size, SHOW_LONG}, {"bdb_home", (char*) &berkeley_home, SHOW_CHAR_PTR}, + {"bdb_lock_max", (char*) &berkeley_lock_max, SHOW_LONG}, {"bdb_logdir", (char*) &berkeley_logdir, SHOW_CHAR_PTR}, {"bdb_tmpdir", (char*) &berkeley_tmpdir, SHOW_CHAR_PTR}, #endif |