~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/myisammrg/myrg_rkey.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000-2003, 2005 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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 */
 
15
 
 
16
/* Read record based on a key */
 
17
 
 
18
/*
 
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
 
26
 */
 
27
 
 
28
 
 
29
#include "myrg_def.h"
 
30
 
 
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.
 
35
                                                                   SerG
 
36
*/
 
37
 
 
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)
 
40
{
 
41
  uchar *UNINIT_VAR(key_buff);
 
42
  uint UNINIT_VAR(pack_key_length);
 
43
  uint16 UNINIT_VAR(last_used_keyseg);
 
44
  MYRG_TABLE *table;
 
45
  MI_INFO *mi;
 
46
  int err;
 
47
  DBUG_ENTER("myrg_rkey");
 
48
 
 
49
  if (_myrg_init_queue(info,inx,search_flag))
 
50
    DBUG_RETURN(my_errno);
 
51
 
 
52
  for (table=info->open_tables ; table != info->end_table ; table++)
 
53
  {
 
54
    mi=table->table;
 
55
 
 
56
    if (table == info->open_tables)
 
57
    {
 
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;
 
63
    }
 
64
    else
 
65
    {
 
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);
 
69
    }
 
70
    info->last_used_table=table+1;
 
71
 
 
72
    if (err)
 
73
    {
 
74
      if (err == HA_ERR_KEY_NOT_FOUND)
 
75
        continue;
 
76
      DBUG_PRINT("exit", ("err: %d", err));
 
77
      DBUG_RETURN(err);
 
78
    }
 
79
    /* adding to queue */
 
80
    queue_insert(&(info->by_key),(uchar *)table);
 
81
 
 
82
  }
 
83
 
 
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);
 
87
 
 
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));
 
94
}