~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join_table.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

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
 
4
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
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
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
 
21
#include <config.h>
 
22
 
 
23
#include <drizzled/field/blob.h>
22
24
#include <drizzled/join_table.h>
23
 
#include <drizzled/field/blob.h>
 
25
#include <drizzled/sql_lex.h>
 
26
#include <drizzled/sql_select.h>
 
27
#include <drizzled/table.h>
 
28
#include <drizzled/util/test.h>
24
29
 
25
30
namespace drizzled
26
31
{
27
32
 
 
33
int JoinTable::joinReadConstTable(optimizer::Position *pos)
 
34
{
 
35
  int error;
 
36
  Table *Table= this->table;
 
37
  Table->const_table=1;
 
38
  Table->null_row=0;
 
39
  Table->status=STATUS_NO_RECORD;
 
40
 
 
41
  if (this->type == AM_SYSTEM)
 
42
  {
 
43
    if ((error=this->joinReadSystem()))
 
44
    {                                           // Info for DESCRIBE
 
45
      this->info="const row not found";
 
46
      /* Mark for EXPLAIN that the row was not found */
 
47
      pos->setFanout(0.0);
 
48
      pos->clearRefDependMap();
 
49
      if (! Table->maybe_null || error > 0)
 
50
        return(error);
 
51
    }
 
52
  }
 
53
  else
 
54
  {
 
55
    if (! Table->key_read && 
 
56
        Table->covering_keys.test(this->ref.key) && 
 
57
        ! Table->no_keyread &&
 
58
        (int) Table->reginfo.lock_type <= (int) TL_READ_WITH_SHARED_LOCKS)
 
59
    {
 
60
      Table->key_read=1;
 
61
      Table->cursor->extra(HA_EXTRA_KEYREAD);
 
62
      this->index= this->ref.key;
 
63
    }
 
64
    error=join_read_const(this);
 
65
    if (Table->key_read)
 
66
    {
 
67
      Table->key_read=0;
 
68
      Table->cursor->extra(HA_EXTRA_NO_KEYREAD);
 
69
    }
 
70
    if (error)
 
71
    {
 
72
      this->info="unique row not found";
 
73
      /* Mark for EXPLAIN that the row was not found */
 
74
      pos->setFanout(0.0);
 
75
      pos->clearRefDependMap();
 
76
      if (!Table->maybe_null || error > 0)
 
77
        return(error);
 
78
    }
 
79
  }
 
80
  if (*this->on_expr_ref && !Table->null_row)
 
81
  {
 
82
    if ((Table->null_row= test((*this->on_expr_ref)->val_int() == 0)))
 
83
      Table->mark_as_null_row();
 
84
  }
 
85
  if (!Table->null_row)
 
86
    Table->maybe_null=0;
 
87
 
 
88
  /* Check appearance of new constant items in Item_equal objects */
 
89
  Join *Join= this->join;
 
90
  if (Join->conds)
 
91
    update_const_equal_items(Join->conds, this);
 
92
  TableList *tbl;
 
93
  for (tbl= Join->select_lex->leaf_tables; tbl; tbl= tbl->next_leaf)
 
94
  {
 
95
    TableList *embedded;
 
96
    TableList *embedding= tbl;
 
97
    do
 
98
    {
 
99
      embedded= embedding;
 
100
      if (embedded->on_expr)
 
101
         update_const_equal_items(embedded->on_expr, this);
 
102
      embedding= embedded->getEmbedding();
 
103
    }
 
104
    while (embedding &&
 
105
           embedding->getNestedJoin()->join_list.head() == embedded);
 
106
  }
 
107
 
 
108
  return(0);
 
109
}
 
110
 
28
111
void JoinTable::readCachedRecord()
29
112
{
30
113
  unsigned char *pos;
71
154
  this->cache.pos=pos;
72
155
}
73
156
 
 
157
int JoinTable::joinReadSystem()
 
158
{
 
159
  Table *Table= this->table;
 
160
  int error;
 
161
  if (Table->status & STATUS_GARBAGE)           // If first read
 
162
  {
 
163
    if ((error=Table->cursor->read_first_row(table->getInsertRecord(),
 
164
                                           Table->getShare()->getPrimaryKey())))
 
165
    {
 
166
      if (error != HA_ERR_END_OF_FILE)
 
167
        return Table->report_error(error);
 
168
      this->table->mark_as_null_row();
 
169
      Table->emptyRecord();                     // Make empty record
 
170
      return -1;
 
171
    }
 
172
    Table->storeRecord();
 
173
  }
 
174
  else if (!Table->status)                      // Only happens with left join
 
175
    Table->restoreRecord();                     // restore old record
 
176
  Table->null_row=0;
 
177
  return Table->status ? -1 : 0;
 
178
}
 
179
 
74
180
} /* namespace drizzled */