1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008-2009 Sun Microsystems, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
#include <drizzled/field/blob.h>
24
#include <drizzled/join_table.h>
25
#include <drizzled/sql_lex.h>
26
#include <drizzled/sql_select.h>
27
#include <drizzled/table.h>
28
#include <drizzled/util/test.h>
33
int JoinTable::joinReadConstTable(optimizer::Position *pos)
36
Table *Table= this->table;
39
Table->status=STATUS_NO_RECORD;
41
if (this->type == AM_SYSTEM)
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 */
48
pos->clearRefDependMap();
49
if (! Table->maybe_null || error > 0)
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)
61
Table->cursor->extra(HA_EXTRA_KEYREAD);
62
this->index= this->ref.key;
64
error=join_read_const(this);
68
Table->cursor->extra(HA_EXTRA_NO_KEYREAD);
72
this->info="unique row not found";
73
/* Mark for EXPLAIN that the row was not found */
75
pos->clearRefDependMap();
76
if (!Table->maybe_null || error > 0)
80
if (*this->on_expr_ref && !Table->null_row)
82
if ((Table->null_row= test((*this->on_expr_ref)->val_int() == 0)))
83
Table->mark_as_null_row();
88
/* Check appearance of new constant items in Item_equal objects */
89
Join *Join= this->join;
91
update_const_equal_items(Join->conds, this);
93
for (tbl= Join->select_lex->leaf_tables; tbl; tbl= tbl->next_leaf)
96
TableList *embedding= tbl;
100
if (embedded->on_expr)
101
update_const_equal_items(embedded->on_expr, this);
102
embedding= embedded->getEmbedding();
105
embedding->getNestedJoin()->join_list.head() == embedded);
111
void JoinTable::readCachedRecord()
116
CacheField *copy,*end_field;
118
last_record= this->cache.record_nr++ == this->cache.ptr_record;
119
pos= this->cache.pos;
120
for (copy= this->cache.field, end_field= copy+this->cache.fields;
124
if (copy->blob_field)
128
copy->blob_field->set_image(pos, copy->length+sizeof(char*),
129
copy->blob_field->charset());
130
pos+=copy->length+sizeof(char*);
134
copy->blob_field->set_ptr(pos, pos+copy->length);
135
pos+=copy->length+copy->blob_field->get_length();
142
length= uint2korr(pos);
143
memcpy(copy->str, pos+2, length);
144
memset(copy->str+length, ' ', copy->length-length);
149
memcpy(copy->str,pos,copy->length);
157
int JoinTable::joinReadSystem()
159
Table *Table= this->table;
161
if (Table->status & STATUS_GARBAGE) // If first read
163
if ((error=Table->cursor->read_first_row(table->getInsertRecord(),
164
Table->getShare()->getPrimaryKey())))
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
172
Table->storeRecord();
174
else if (!Table->status) // Only happens with left join
175
Table->restoreRecord(); // restore old record
177
return Table->status ? -1 : 0;
180
} /* namespace drizzled */