1
/* Copyright (C) 2000-2003, 2005 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
/* Read record based on a key */
19
* HA_READ_KEY_EXACT => SEARCH_BIGGER
20
* HA_READ_KEY_OR_NEXT => SEARCH_BIGGER
21
* HA_READ_AFTER_KEY => SEARCH_BIGGER
22
* HA_READ_PREFIX => SEARCH_BIGGER
23
* HA_READ_KEY_OR_PREV => SEARCH_SMALLER
24
* HA_READ_BEFORE_KEY => SEARCH_SMALLER
25
* HA_READ_PREFIX_LAST => SEARCH_SMALLER
31
/* todo: we could store some additional info to speedup lookups:
32
column (key, keyseg) can be constant per table
33
it can also be increasing (table1.val > table2.val > ...),
34
or decreasing, <=, >=, etc.
38
int myrg_rkey(MYRG_INFO *info,uchar *buf,int inx, const uchar *key,
39
key_part_map keypart_map, enum ha_rkey_function search_flag)
41
uchar *UNINIT_VAR(key_buff);
42
uint UNINIT_VAR(pack_key_length);
43
uint16 UNINIT_VAR(last_used_keyseg);
47
DBUG_ENTER("myrg_rkey");
49
if (_myrg_init_queue(info,inx,search_flag))
50
DBUG_RETURN(my_errno);
52
for (table=info->open_tables ; table != info->end_table ; table++)
56
if (table == info->open_tables)
58
err=mi_rkey(mi, 0, inx, key, keypart_map, search_flag);
59
/* Get the saved packed key and packed key length. */
60
key_buff=(uchar*) mi->lastkey+mi->s->base.max_key_length;
61
pack_key_length=mi->pack_key_length;
62
last_used_keyseg= mi->last_used_keyseg;
66
mi->once_flags|= USE_PACKED_KEYS;
67
mi->last_used_keyseg= last_used_keyseg;
68
err=mi_rkey(mi, 0, inx, key_buff, pack_key_length, search_flag);
70
info->last_used_table=table+1;
74
if (err == HA_ERR_KEY_NOT_FOUND)
76
DBUG_PRINT("exit", ("err: %d", err));
80
queue_insert(&(info->by_key),(uchar *)table);
84
DBUG_PRINT("info", ("tables with matches: %u", info->by_key.elements));
85
if (!info->by_key.elements)
86
DBUG_RETURN(HA_ERR_KEY_NOT_FOUND);
88
mi=(info->current_table=(MYRG_TABLE *)queue_top(&(info->by_key)))->table;
89
mi->once_flags|= RRND_PRESERVE_LASTINX;
90
DBUG_PRINT("info", ("using table no: %d",
91
(int) (info->current_table - info->open_tables + 1)));
92
DBUG_DUMP("result key", (uchar*) mi->lastkey, mi->lastkey_length);
93
DBUG_RETURN(_myrg_mi_read_record(mi,buf));