summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2005-02-28 12:18:39 +0200
committerunknown <monty@mysql.com>2005-02-28 12:18:39 +0200
commit45a26d449d157fb2f5c4b5ae871eb98728d9ee55 (patch)
treef466a4f954ca82d8aae5e4d3ab0a985e7fdce2f7 /sql/sql_select.cc
parent108702a34e37bae22f117a3a7e18e7cead3e63c8 (diff)
parent8e3addf9284742a6b29fb3016b8c612dfd1a5778 (diff)
downloadmariadb-git-45a26d449d157fb2f5c4b5ae871eb98728d9ee55.tar.gz
merge with 4.1
BitKeeper/etc/ignore: auto-union BitKeeper/etc/logging_ok: auto-union client/mysql.cc: Auto merged client/mysqldump.c: Auto merged innobase/dict/dict0dict.c: Auto merged innobase/fil/fil0fil.c: Auto merged innobase/row/row0sel.c: Auto merged mysql-test/r/select_found.result: Auto merged mysql-test/r/type_set.result: Auto merged mysys/default.c: Auto merged sql/field.h: Auto merged sql/item_cmpfunc.cc: Auto merged sql/mysqld.cc: Auto merged sql/sql_db.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_repl.cc: Auto merged sql/sql_select.cc: Auto merged strings/ctype-simple.c: Auto merged include/mysql_com.h: Merge sql/filesort.cc: merge
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc33
1 files changed, 23 insertions, 10 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 2c1d5f03aa2..549ecedcef7 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -10906,8 +10906,8 @@ static int remove_dup_with_hash_index(THD *thd, TABLE *table,
{
byte *key_buffer, *key_pos, *record=table->record[0];
int error;
- handler *file=table->file;
- ulong extra_length=ALIGN_SIZE(key_length)-key_length;
+ handler *file= table->file;
+ ulong extra_length= ALIGN_SIZE(key_length)-key_length;
uint *field_lengths,*field_length;
HASH hash;
DBUG_ENTER("remove_dup_with_hash_index");
@@ -10921,22 +10921,34 @@ static int remove_dup_with_hash_index(THD *thd, TABLE *table,
NullS))
DBUG_RETURN(1);
+ {
+ Field **ptr;
+ ulong total_length= 0;
+ for (ptr= first_field, field_length=field_lengths ; *ptr ; ptr++)
+ {
+ uint length= (*ptr)->pack_length();
+ (*field_length++)= length;
+ total_length+= length;
+ }
+ DBUG_PRINT("info",("field_count: %u key_length: %lu total_length: %lu",
+ field_count, key_length, total_length));
+ DBUG_ASSERT(total_length <= key_length);
+ key_length= total_length;
+ extra_length= ALIGN_SIZE(key_length)-key_length;
+ }
+
if (hash_init(&hash, &my_charset_bin, (uint) file->records, 0,
- key_length,(hash_get_key) 0, 0, 0))
+ key_length, (hash_get_key) 0, 0, 0))
{
my_free((char*) key_buffer,MYF(0));
DBUG_RETURN(1);
}
- {
- Field **ptr;
- for (ptr= first_field, field_length=field_lengths ; *ptr ; ptr++)
- (*field_length++)= (*ptr)->pack_length();
- }
file->ha_rnd_init(1);
key_pos=key_buffer;
for (;;)
{
+ byte *org_key_pos;
if (thd->killed)
{
thd->send_kill_message();
@@ -10959,6 +10971,7 @@ static int remove_dup_with_hash_index(THD *thd, TABLE *table,
}
/* copy fields to key buffer */
+ org_key_pos= key_pos;
field_length=field_lengths;
for (Field **ptr= first_field ; *ptr ; ptr++)
{
@@ -10966,14 +10979,14 @@ static int remove_dup_with_hash_index(THD *thd, TABLE *table,
key_pos+= *field_length++;
}
/* Check if it exists before */
- if (hash_search(&hash,key_pos-key_length,key_length))
+ if (hash_search(&hash, org_key_pos, key_length))
{
/* Duplicated found ; Remove the row */
if ((error=file->delete_row(record)))
goto err;
}
else
- (void) my_hash_insert(&hash, key_pos-key_length);
+ (void) my_hash_insert(&hash, org_key_pos);
key_pos+=extra_length;
}
my_free((char*) key_buffer,MYF(0));