1
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008-2009 Sun Microsystems, Inc.
4
* Copyright (C) 2008-2009 Sun Microsystems
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>
29
int JoinTable::joinReadConstTable(optimizer::Position *pos)
32
Table *Table= this->table;
35
Table->status=STATUS_NO_RECORD;
37
if (this->type == AM_SYSTEM)
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 */
44
pos->clearRefDependMap();
45
if (! Table->maybe_null || error > 0)
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)
57
Table->cursor->extra(HA_EXTRA_KEYREAD);
58
this->index= this->ref.key;
60
error=join_read_const(this);
64
Table->cursor->extra(HA_EXTRA_NO_KEYREAD);
68
this->info="unique row not found";
69
/* Mark for EXPLAIN that the row was not found */
71
pos->clearRefDependMap();
72
if (!Table->maybe_null || error > 0)
76
if (*this->on_expr_ref && !Table->null_row)
78
if ((Table->null_row= test((*this->on_expr_ref)->val_int() == 0)))
79
Table->mark_as_null_row();
84
/* Check appearance of new constant items in Item_equal objects */
85
Join *Join= this->join;
87
update_const_equal_items(Join->conds, this);
89
for (tbl= Join->select_lex->leaf_tables; tbl; tbl= tbl->next_leaf)
92
TableList *embedding= tbl;
96
if (embedded->on_expr)
97
update_const_equal_items(embedded->on_expr, this);
98
embedding= embedded->getEmbedding();
101
embedding->getNestedJoin()->join_list.head() == embedded);
107
28
void JoinTable::readCachedRecord()
109
30
unsigned char *pos;
150
71
this->cache.pos=pos;
153
int JoinTable::joinReadSystem()
155
Table *Table= this->table;
157
if (Table->status & STATUS_GARBAGE) // If first read
159
if ((error=Table->cursor->read_first_row(table->getInsertRecord(),
160
Table->getShare()->getPrimaryKey())))
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
168
Table->storeRecord();
170
else if (!Table->status) // Only happens with left join
171
Table->restoreRecord(); // restore old record
173
return Table->status ? -1 : 0;
176
74
} /* namespace drizzled */