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>
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()))
45 this->info=
"const row 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;
68 Table->cursor->extra(HA_EXTRA_NO_KEYREAD);
72 this->info=
"unique row not found";
75 pos->clearRefDependMap();
76 if (!Table->maybe_null || error > 0)
82 if ((Table->null_row= test((*this->
on_expr_ref)->val_int() == 0)))
83 Table->mark_as_null_row();
89 Join *Join= this->join;
93 for (tbl= Join->select_lex->leaf_tables; tbl; tbl= tbl->next_leaf)
96 TableList *embedding= tbl;
100 if (embedded->on_expr)
102 embedding= embedded->getEmbedding();
105 &embedding->getNestedJoin()->join_list.front() == 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 join_read_system(JoinTable *tab)
159 Table *table= tab->table;
162 if (table->status & STATUS_GARBAGE)
164 if ((error= table->cursor->read_first_row(table->getInsertRecord(),
165 table->getShare()->getPrimaryKey())))
167 if (error != HA_ERR_END_OF_FILE)
169 return table->report_error(error);
172 tab->table->mark_as_null_row();
173 table->emptyRecord();
176 table->storeRecord();
178 else if (table->status == 0)
180 table->restoreRecord();
184 return table->status ? -1 : 0;
187 int JoinTable::joinReadSystem()
189 return join_read_system(
this);
TODO: Rename this file - func.h is stupid.
int join_read_const(JoinTable *tab)
void update_const_equal_items(COND *cond, JoinTable *tab)