18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include <drizzled/join_table.h>
23
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
28
void JoinTable::readCachedRecord()
113
30
unsigned char *pos;
154
71
this->cache.pos=pos;
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
74
} /* namespace drizzled */