52
52
#include "drizzled/records.h"
53
53
#include "drizzled/internal/iocache.h"
54
54
#include "drizzled/drizzled.h"
55
#include "drizzled/plugin/storage_engine.h"
57
56
#include "drizzled/sql_union.h"
58
57
#include "drizzled/optimizer/key_field.h"
573
572
sz= sizeof(optimizer::KeyField) *
574
573
(((session->lex->current_select->cond_count+1)*2 +
575
574
session->lex->current_select->between_count)*m+1);
576
if (! (key_fields= (optimizer::KeyField*) session->getMemRoot()->allocate(sz)))
575
if (! (key_fields= (optimizer::KeyField*) session->alloc(sz)))
579
578
field= end= key_fields;
1005
1004
j->ref.key_length=length;
1006
1005
j->ref.key=(int) key;
1007
1006
if (!(j->ref.key_buff= (unsigned char*) session->calloc(ALIGN_SIZE(length)*2)) ||
1008
!(j->ref.key_copy= (StoredKey**) session->getMemRoot()->allocate((sizeof(StoredKey*) *
1007
!(j->ref.key_copy= (StoredKey**) session->alloc((sizeof(StoredKey*) *
1009
1008
(keyparts+1)))) ||
1010
!(j->ref.items= (Item**) session->getMemRoot()->allocate(sizeof(Item*)*keyparts)) ||
1011
!(j->ref.cond_guards= (bool**) session->getMemRoot()->allocate(sizeof(uint*)*keyparts)))
1009
!(j->ref.items= (Item**) session->alloc(sizeof(Item*)*keyparts)) ||
1010
!(j->ref.cond_guards= (bool**) session->alloc(sizeof(uint*)*keyparts)))
2308
2307
@param cond condition whose multiple equalities are to be checked
2309
2308
@param table constant table that has been read
2311
void update_const_equal_items(COND *cond, JoinTable *tab)
2310
static void update_const_equal_items(COND *cond, JoinTable *tab)
2313
2312
if (!(cond->used_tables() & tab->table->map))
2608
2607
1. join->cur_embedding_map - bitmap of pairs of brackets (aka nested
2609
2608
joins) we've opened but didn't close.
2610
2. {each NestedJoin class not simplified away}->counter - number
2609
2. {each nested_join_st structure not simplified away}->counter - number
2611
2610
of this nested join's children that have already been added to to
2612
2611
the partial join order.
3370
int join_read_const_table(JoinTable *tab, optimizer::Position *pos)
3373
Table *table=tab->table;
3374
table->const_table=1;
3376
table->status=STATUS_NO_RECORD;
3378
if (tab->type == AM_SYSTEM)
3380
if ((error=join_read_system(tab)))
3381
{ // Info for DESCRIBE
3382
tab->info="const row not found";
3383
/* Mark for EXPLAIN that the row was not found */
3384
pos->setFanout(0.0);
3385
pos->clearRefDependMap();
3386
if (! table->maybe_null || error > 0)
3392
if (! table->key_read &&
3393
table->covering_keys.test(tab->ref.key) &&
3394
! table->no_keyread &&
3395
(int) table->reginfo.lock_type <= (int) TL_READ_WITH_SHARED_LOCKS)
3398
table->cursor->extra(HA_EXTRA_KEYREAD);
3399
tab->index= tab->ref.key;
3401
error=join_read_const(tab);
3402
if (table->key_read)
3405
table->cursor->extra(HA_EXTRA_NO_KEYREAD);
3409
tab->info="unique row not found";
3410
/* Mark for EXPLAIN that the row was not found */
3411
pos->setFanout(0.0);
3412
pos->clearRefDependMap();
3413
if (!table->maybe_null || error > 0)
3417
if (*tab->on_expr_ref && !table->null_row)
3419
if ((table->null_row= test((*tab->on_expr_ref)->val_int() == 0)))
3420
table->mark_as_null_row();
3422
if (!table->null_row)
3423
table->maybe_null=0;
3425
/* Check appearance of new constant items in Item_equal objects */
3426
Join *join= tab->join;
3428
update_const_equal_items(join->conds, tab);
3430
for (tbl= join->select_lex->leaf_tables; tbl; tbl= tbl->next_leaf)
3432
TableList *embedded;
3433
TableList *embedding= tbl;
3436
embedded= embedding;
3437
if (embedded->on_expr)
3438
update_const_equal_items(embedded->on_expr, tab);
3439
embedding= embedded->getEmbedding();
3442
embedding->getNestedJoin()->join_list.head() == embedded);
3448
int join_read_system(JoinTable *tab)
3450
Table *table= tab->table;
3452
if (table->status & STATUS_GARBAGE) // If first read
3454
if ((error=table->cursor->read_first_row(table->getInsertRecord(),
3455
table->getShare()->getPrimaryKey())))
3457
if (error != HA_ERR_END_OF_FILE)
3458
return table->report_error(error);
3459
tab->table->mark_as_null_row();
3460
table->emptyRecord(); // Make empty record
3463
table->storeRecord();
3465
else if (!table->status) // Only happens with left join
3466
table->restoreRecord(); // restore old record
3468
return table->status ? -1 : 0;
3372
3472
Read a (constant) table when there is at most one matching row.
3922
4022
return NESTED_LOOP_ERROR;
3925
if (join->rollup.getState() != Rollup::STATE_NONE)
4025
if (join->rollup.state != ROLLUP::STATE_NONE)
3927
4027
if (join->rollup_write_data((uint32_t) (idx+1), table))
3928
4028
return NESTED_LOOP_ERROR;
5364
5464
if (!count || count > fields.elements)
5366
5466
my_error(ER_BAD_FIELD_ERROR, MYF(0),
5367
order_item->full_name(), session->where());
5467
order_item->full_name(), session->where);
5370
5470
order->item= ref_pointer_array + count - 1;
5483
5583
List<Item> &all_fields,
5486
session->setWhere("order clause");
5586
session->where="order clause";
5487
5587
for (; order; order=order->next)
5489
5589
if (find_order_in_list(session, ref_pointer_array, tables, order, fields,
5535
5635
uint32_t org_fields=all_fields.elements;
5537
session->setWhere("group statement");
5637
session->where="group statement";
5538
5638
for (ord= order; ord; ord= ord->next)
5540
5640
if (find_order_in_list(session, ref_pointer_array, tables, ord, fields,