diff options
author | unknown <monty@mysql.com> | 2005-10-25 02:27:40 +0300 |
---|---|---|
committer | unknown <monty@mysql.com> | 2005-10-25 02:27:40 +0300 |
commit | fbb96451302f5ddfe36fc46ed6729958961054a5 (patch) | |
tree | 56b86b67bce65a21ff4ffd27cd2dd139b110b622 /sql/records.cc | |
parent | 027a7ef0ac022fde201c130deba510a2b1e7b324 (diff) | |
download | mariadb-git-fbb96451302f5ddfe36fc46ed6729958961054a5.tar.gz |
Added more tests for new UPDATE ... ORDER BY ... LIMIT optimization
heap/_check.c:
Change arguments to ha_key_cmp
heap/hp_create.c:
Change arguments to ha_key_cmp
include/my_base.h:
Remove SEARCH_RETURN_B_POS and instead always send an array to ha_key_cmp() as last argument
myisam/mi_check.c:
Change arguments to ha_key_cmp
myisam/mi_rnext_same.c:
Change arguments to ha_key_cmp
myisam/mi_search.c:
Change arguments to ha_key_cmp
myisam/mi_write.c:
Change arguments to ha_key_cmp
myisammrg/myrg_queue.c:
Change arguments to ha_key_cmp
mysys/my_handler.c:
Remove SEARCH_RETURN_B_POS and instead always send an array to ha_key_cmp() as last argument
(This removes an if in a loop at the expensive of an int on the stack)
sql/records.cc:
Simplify new rr_index() code
Create common error handling function for rr_() functions.
Remove loop from rr_index() as handler::index_next() can never return HA_ERR_RECORD_DELETED
sql/sql_load.cc:
Simplify
sql/sql_update.cc:
Simplify code
Fixed bug when one is updating an index column that could be used with ORDER BY
sql/structs.h:
Removed not needed structure element
Diffstat (limited to 'sql/records.cc')
-rw-r--r-- | sql/records.cc | 182 |
1 files changed, 83 insertions, 99 deletions
diff --git a/sql/records.cc b/sql/records.cc index 9150024d4b8..7e4a808f0c3 100644 --- a/sql/records.cc +++ b/sql/records.cc @@ -28,11 +28,10 @@ static int rr_from_pointers(READ_RECORD *info); static int rr_from_cache(READ_RECORD *info); static int init_rr_cache(READ_RECORD *info); static int rr_cmp(uchar *a,uchar *b); - +static int rr_index_first(READ_RECORD *info); static int rr_index(READ_RECORD *info); - /* Initialize READ_RECORD structure to perform full index scan @@ -58,26 +57,19 @@ void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table, bool print_error, uint idx) { bzero((char*) info,sizeof(*info)); - info->thd=thd; - info->table=table; - info->file= table->file; - info->forms= &info->table; /* Only one table */ - + info->table= table; + info->file= table->file; info->record= table->record[0]; - info->ref_length= table->file->ref_length; + info->print_error= print_error; - info->select=NULL; - info->print_error=print_error; - info->ignore_not_found_rows= 0; table->status=0; /* And it's always found */ - if (!table->file->inited) { table->file->ha_index_init(idx); table->file->extra(HA_EXTRA_RETRIEVE_PRIMARY_KEY); } - info->read_record= rr_index; - info->first= TRUE; + /* read_record will be changed to rr_index in rr_index_first */ + info->read_record= rr_index_first; } @@ -204,6 +196,21 @@ void end_read_record(READ_RECORD *info) } } +static int rr_handle_error(READ_RECORD *info, int error) +{ + if (error == HA_ERR_END_OF_FILE) + error= -1; + else + { + if (info->print_error) + info->table->file->print_error(error, MYF(0)); + if (error < 0) // Fix negative BDB errno + error= 1; + } + return error; +} + + /* Read a record from head-database */ static int rr_quick(READ_RECORD *info) @@ -218,15 +225,7 @@ static int rr_quick(READ_RECORD *info) } if (tmp != HA_ERR_RECORD_DELETED) { - if (tmp == HA_ERR_END_OF_FILE) - tmp= -1; - else - { - if (info->print_error) - info->file->print_error(tmp,MYF(0)); - if (tmp < 0) // Fix negative BDB errno - tmp=1; - } + tmp= rr_handle_error(info, tmp); break; } } @@ -235,7 +234,31 @@ static int rr_quick(READ_RECORD *info) /* - A READ_RECORD::read_record implementation that reads index sequentially + Reads first row in an index scan + + SYNOPSIS + rr_index_first() + info Scan info + + RETURN + 0 Ok + -1 End of records + 1 Error +*/ + + +static int rr_index_first(READ_RECORD *info) +{ + int tmp= info->file->index_first(info->record); + info->read_record= rr_index; + if (tmp) + tmp= rr_handle_error(info, tmp); + return tmp; +} + + +/* + Reads index sequentially after first row SYNOPSIS rr_index() @@ -251,43 +274,16 @@ static int rr_quick(READ_RECORD *info) 1 Error */ + static int rr_index(READ_RECORD *info) { - int tmp; - while (1) - { - if (info->first) - { - info->first= FALSE; - tmp= info->file->index_first(info->record); - } - else - tmp= info->file->index_next(info->record); - - if (!tmp) - break; - if (info->thd->killed) - { - my_error(ER_SERVER_SHUTDOWN,MYF(0)); - return 1; - } - if (tmp != HA_ERR_RECORD_DELETED) - { - if (tmp == HA_ERR_END_OF_FILE) - tmp= -1; - else - { - if (info->print_error) - info->table->file->print_error(tmp,MYF(0)); - if (tmp < 0) // Fix negative BDB errno - tmp=1; - } - break; - } - } + int tmp= info->file->index_next(info->record); + if (tmp) + tmp= rr_handle_error(info, tmp); return tmp; } + static int rr_sequential(READ_RECORD *info) { int tmp; @@ -298,17 +294,13 @@ static int rr_sequential(READ_RECORD *info) my_error(ER_SERVER_SHUTDOWN,MYF(0)); return 1; } + /* + rnd_next can return RECORD_DELETED for MyISAM when one thread is + reading and another deleting without locks. + */ if (tmp != HA_ERR_RECORD_DELETED) { - if (tmp == HA_ERR_END_OF_FILE) - tmp= -1; - else - { - if (info->print_error) - info->table->file->print_error(tmp,MYF(0)); - if (tmp < 0) // Fix negative BDB errno - tmp=1; - } + tmp= rr_handle_error(info, tmp); break; } } @@ -319,23 +311,18 @@ static int rr_sequential(READ_RECORD *info) static int rr_from_tempfile(READ_RECORD *info) { int tmp; -tryNext: - if (my_b_read(info->io_cache,info->ref_pos,info->ref_length)) - return -1; /* End of file */ - if ((tmp=info->file->rnd_pos(info->record,info->ref_pos))) + for (;;) { - if (tmp == HA_ERR_END_OF_FILE) - tmp= -1; - else if (tmp == HA_ERR_RECORD_DELETED || - (tmp == HA_ERR_KEY_NOT_FOUND && info->ignore_not_found_rows)) - goto tryNext; - else - { - if (info->print_error) - info->file->print_error(tmp,MYF(0)); - if (tmp < 0) // Fix negative BDB errno - tmp=1; - } + if (my_b_read(info->io_cache,info->ref_pos,info->ref_length)) + return -1; /* End of file */ + if (!(tmp=info->file->rnd_pos(info->record,info->ref_pos))) + break; + /* The following is extremely unlikely to happen */ + if (tmp == HA_ERR_RECORD_DELETED || + (tmp == HA_ERR_KEY_NOT_FOUND && info->ignore_not_found_rows)) + continue; + tmp= rr_handle_error(info, tmp); + break; } return tmp; } /* rr_from_tempfile */ @@ -373,26 +360,23 @@ static int rr_from_pointers(READ_RECORD *info) { int tmp; byte *cache_pos; -tryNext: - if (info->cache_pos == info->cache_end) - return -1; /* End of file */ - cache_pos=info->cache_pos; - info->cache_pos+=info->ref_length; - if ((tmp=info->file->rnd_pos(info->record,cache_pos))) + for (;;) { - if (tmp == HA_ERR_END_OF_FILE) - tmp= -1; - else if (tmp == HA_ERR_RECORD_DELETED || - (tmp == HA_ERR_KEY_NOT_FOUND && info->ignore_not_found_rows)) - goto tryNext; - else - { - if (info->print_error) - info->file->print_error(tmp,MYF(0)); - if (tmp < 0) // Fix negative BDB errno - tmp=1; - } + if (info->cache_pos == info->cache_end) + return -1; /* End of file */ + cache_pos= info->cache_pos; + info->cache_pos+= info->ref_length; + + if (!(tmp=info->file->rnd_pos(info->record,cache_pos))) + break; + + /* The following is extremely unlikely to happen */ + if (tmp == HA_ERR_RECORD_DELETED || + (tmp == HA_ERR_KEY_NOT_FOUND && info->ignore_not_found_rows)) + continue; + tmp= rr_handle_error(info, tmp); + break; } return tmp; } |