~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join_table.cc

  • Committer: lbieber
  • Date: 2010-10-06 16:34:16 UTC
  • mfrom: (1816.1.3 build)
  • Revision ID: lbieber@orisndriz08-20101006163416-ea0sl59qgpglk21y
Merge Monty - Change the requirement from either libinnodb to libhaildb. Also, tied it to version 2.2
Merge Andrew - fix bug 650935: remove --compress from all clients
Merge Andrew - fix bug 653471: Add -A to drizzle client
Merge Travis - 621861 = To change C structs to C++ classes in Drizzle

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008-2009 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
21
21
#include "config.h"
22
22
#include <drizzled/join_table.h>
23
23
#include <drizzled/field/blob.h>
24
 
#include <drizzled/sql_select.h>
25
24
 
26
25
namespace drizzled
27
26
{
28
27
 
29
 
int JoinTable::joinReadConstTable(optimizer::Position *pos)
30
 
{
31
 
  int error;
32
 
  Table *Table= this->table;
33
 
  Table->const_table=1;
34
 
  Table->null_row=0;
35
 
  Table->status=STATUS_NO_RECORD;
36
 
 
37
 
  if (this->type == AM_SYSTEM)
38
 
  {
39
 
    if ((error=this->joinReadSystem()))
40
 
    {                                           // Info for DESCRIBE
41
 
      this->info="const row not found";
42
 
      /* Mark for EXPLAIN that the row was not found */
43
 
      pos->setFanout(0.0);
44
 
      pos->clearRefDependMap();
45
 
      if (! Table->maybe_null || error > 0)
46
 
        return(error);
47
 
    }
48
 
  }
49
 
  else
50
 
  {
51
 
    if (! Table->key_read && 
52
 
        Table->covering_keys.test(this->ref.key) && 
53
 
        ! Table->no_keyread &&
54
 
        (int) Table->reginfo.lock_type <= (int) TL_READ_WITH_SHARED_LOCKS)
55
 
    {
56
 
      Table->key_read=1;
57
 
      Table->cursor->extra(HA_EXTRA_KEYREAD);
58
 
      this->index= this->ref.key;
59
 
    }
60
 
    error=join_read_const(this);
61
 
    if (Table->key_read)
62
 
    {
63
 
      Table->key_read=0;
64
 
      Table->cursor->extra(HA_EXTRA_NO_KEYREAD);
65
 
    }
66
 
    if (error)
67
 
    {
68
 
      this->info="unique row not found";
69
 
      /* Mark for EXPLAIN that the row was not found */
70
 
      pos->setFanout(0.0);
71
 
      pos->clearRefDependMap();
72
 
      if (!Table->maybe_null || error > 0)
73
 
        return(error);
74
 
    }
75
 
  }
76
 
  if (*this->on_expr_ref && !Table->null_row)
77
 
  {
78
 
    if ((Table->null_row= test((*this->on_expr_ref)->val_int() == 0)))
79
 
      Table->mark_as_null_row();
80
 
  }
81
 
  if (!Table->null_row)
82
 
    Table->maybe_null=0;
83
 
 
84
 
  /* Check appearance of new constant items in Item_equal objects */
85
 
  Join *Join= this->join;
86
 
  if (Join->conds)
87
 
    update_const_equal_items(Join->conds, this);
88
 
  TableList *tbl;
89
 
  for (tbl= Join->select_lex->leaf_tables; tbl; tbl= tbl->next_leaf)
90
 
  {
91
 
    TableList *embedded;
92
 
    TableList *embedding= tbl;
93
 
    do
94
 
    {
95
 
      embedded= embedding;
96
 
      if (embedded->on_expr)
97
 
         update_const_equal_items(embedded->on_expr, this);
98
 
      embedding= embedded->getEmbedding();
99
 
    }
100
 
    while (embedding &&
101
 
           embedding->getNestedJoin()->join_list.head() == embedded);
102
 
  }
103
 
 
104
 
  return(0);
105
 
}
106
 
 
107
28
void JoinTable::readCachedRecord()
108
29
{
109
30
  unsigned char *pos;
150
71
  this->cache.pos=pos;
151
72
}
152
73
 
153
 
int JoinTable::joinReadSystem()
154
 
{
155
 
  Table *Table= this->table;
156
 
  int error;
157
 
  if (Table->status & STATUS_GARBAGE)           // If first read
158
 
  {
159
 
    if ((error=Table->cursor->read_first_row(table->getInsertRecord(),
160
 
                                           Table->getShare()->getPrimaryKey())))
161
 
    {
162
 
      if (error != HA_ERR_END_OF_FILE)
163
 
        return Table->report_error(error);
164
 
      this->table->mark_as_null_row();
165
 
      Table->emptyRecord();                     // Make empty record
166
 
      return -1;
167
 
    }
168
 
    Table->storeRecord();
169
 
  }
170
 
  else if (!Table->status)                      // Only happens with left join
171
 
    Table->restoreRecord();                     // restore old record
172
 
  Table->null_row=0;
173
 
  return Table->status ? -1 : 0;
174
 
}
175
 
 
176
74
} /* namespace drizzled */