~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join.cc

  • Committer: Olaf van der Spek
  • Date: 2011-06-21 18:18:14 UTC
  • mto: This revision was merged to the branch mainline in revision 2346.
  • Revision ID: olafvdspek@gmail.com-20110621181814-4wsfwjgbw49tzq1e
Refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
                                             uint32_t depth,
105
105
                                             uint32_t prune_level);
106
106
static uint32_t determine_search_depth(Join* join);
107
 
static bool make_simple_join(Join *join,Table *tmp_table);
 
107
static void make_simple_join(Join*, Table*);
108
108
static void make_outerjoin_info(Join *join);
109
109
static bool make_join_select(Join *join, optimizer::SqlSelect *select,COND *item);
110
110
static void make_join_readinfo(Join&);
1344
1344
*/
1345
1345
void Join::init_save_join_tab()
1346
1346
{
1347
 
  tmp_join= (Join*)session->mem.allocate(sizeof(Join));
 
1347
  tmp_join= (Join*)session->mem.alloc(sizeof(Join));
1348
1348
 
1349
1349
  error= 0;              // Ensure that tmp_join.error= 0
1350
1350
  restore_tmp();
1565
1565
    {         /* Must copy to another table */
1566
1566
      /* Free first data from old join */
1567
1567
      curr_join->join_free();
1568
 
      if (make_simple_join(curr_join, curr_tmp_table))
1569
 
        return;
 
1568
      make_simple_join(curr_join, curr_tmp_table);
1570
1569
      calc_group_buffer(curr_join, group_list);
1571
1570
      count_field_types(select_lex, &curr_join->tmp_table_param,
1572
1571
      curr_join->tmp_all_fields1,
1687
1686
      curr_join->select_distinct=0;
1688
1687
    }
1689
1688
    curr_tmp_table->reginfo.lock_type= TL_UNLOCK;
1690
 
    if (make_simple_join(curr_join, curr_tmp_table))
1691
 
      return;
 
1689
    make_simple_join(curr_join, curr_tmp_table);
1692
1690
    calc_group_buffer(curr_join, curr_join->group_list);
1693
1691
    count_field_types(select_lex, &curr_join->tmp_table_param, *curr_all_fields, 0);
1694
1692
 
2226
2224
/** Allocate memory needed for other rollup functions. */
2227
2225
bool Join::rollup_init()
2228
2226
{
2229
 
  Item **ref_array;
2230
2227
 
2231
2228
  tmp_table_param.quick_group= 0; // Can't create groups in tmp table
2232
2229
  rollup.setState(Rollup::STATE_INITED);
2237
2234
  */
2238
2235
  tmp_table_param.group_parts= send_group_parts;
2239
2236
 
2240
 
  rollup.setNullItems((Item_null_result**) session->getMemRoot()->allocate((sizeof(Item*) +
2241
 
                                                                sizeof(Item**) +
2242
 
                                                                sizeof(List<Item>) +
2243
 
                                                                ref_pointer_array_size)
2244
 
                                                               * send_group_parts ));
2245
 
  if (! rollup.getNullItems())
2246
 
  {
2247
 
    return 1;
2248
 
  }
2249
 
 
 
2237
  rollup.setNullItems((Item_null_result**) session->mem.alloc((sizeof(Item*) + sizeof(Item**) + sizeof(List<Item>) + ref_pointer_array_size) * send_group_parts));
2250
2238
  rollup.setFields((List<Item>*) (rollup.getNullItems() + send_group_parts));
2251
2239
  rollup.setRefPointerArrays((Item***) (rollup.getFields() + send_group_parts));
2252
 
  ref_array= (Item**) (rollup.getRefPointerArrays()+send_group_parts);
 
2240
  Item** ref_array= (Item**) (rollup.getRefPointerArrays()+send_group_parts);
2253
2241
 
2254
2242
  /*
2255
2243
    Prepare space for field list for the different levels
2273
2261
  }
2274
2262
 
2275
2263
  List<Item>::iterator it(all_fields.begin());
2276
 
  Item *item;
2277
 
  while ((item= it++))
 
2264
  while (Item* item= it++)
2278
2265
  {
2279
2266
    Order *group_tmp;
2280
2267
    bool found_in_group= 0;
3381
3368
  optimizer::Position cur_pos;
3382
3369
 
3383
3370
  table_count=join->tables;
3384
 
  if (!(join->join_tab=join_tab=
3385
 
  (JoinTable*) session->getMemRoot()->allocate(sizeof(JoinTable)*table_count)))
3386
 
    return(true);
 
3371
  join->join_tab=join_tab= (JoinTable*) session->mem.alloc(sizeof(JoinTable)*table_count);
3387
3372
 
3388
3373
  for (i= 0; i < table_count; i++)
3389
3374
    new (join_tab+i) JoinTable();
4529
4514
  return search_depth;
4530
4515
}
4531
4516
 
4532
 
static bool make_simple_join(Join *join,Table *tmp_table)
 
4517
static void make_simple_join(Join *join,Table *tmp_table)
4533
4518
{
4534
 
  Table **tableptr;
4535
 
  JoinTable *join_tab;
4536
 
 
4537
4519
  /*
4538
4520
    Reuse Table * and JoinTable if already allocated by a previous call
4539
4521
    to this function through Join::exec (may happen for sub-queries).
4540
4522
  */
4541
4523
  if (!join->table_reexec)
4542
4524
  {
4543
 
    if (!(join->table_reexec= (Table**) join->session->getMemRoot()->allocate(sizeof(Table*))))
4544
 
      return(true);
 
4525
    join->table_reexec= (Table**) join->session->mem.alloc(sizeof(Table*));
4545
4526
    if (join->tmp_join)
4546
4527
      join->tmp_join->table_reexec= join->table_reexec;
4547
4528
  }
4548
4529
  if (!join->join_tab_reexec)
4549
4530
  {
4550
 
    if (!(join->join_tab_reexec=
4551
 
          (JoinTable*) join->session->getMemRoot()->allocate(sizeof(JoinTable))))
4552
 
      return(true);
 
4531
    join->join_tab_reexec= (JoinTable*) join->session->mem.alloc(sizeof(JoinTable));
4553
4532
    new (join->join_tab_reexec) JoinTable();
4554
4533
    if (join->tmp_join)
4555
4534
      join->tmp_join->join_tab_reexec= join->join_tab_reexec;
4556
4535
  }
4557
 
  tableptr= join->table_reexec;
4558
 
  join_tab= join->join_tab_reexec;
 
4536
  Table** tableptr= join->table_reexec;
 
4537
  JoinTable* join_tab= join->join_tab_reexec;
4559
4538
 
4560
4539
  join->join_tab=join_tab;
4561
4540
  join->table=tableptr; tableptr[0]=tmp_table;
4589
4568
  join_tab->read_record.init();
4590
4569
  tmp_table->status=0;
4591
4570
  tmp_table->null_row=0;
4592
 
 
4593
 
  return false;
4594
4571
}
4595
4572
 
4596
4573
/**
5084
5061
 
5085
5062
    if (tab->insideout_match_tab)
5086
5063
    {
5087
 
      tab->insideout_buf= (unsigned char*) join.session->getMemRoot()->allocate(tab->table->key_info[tab->index].key_length);
 
5064
      tab->insideout_buf= (unsigned char*) join.session->mem.alloc(tab->table->key_info[tab->index].key_length);
5088
5065
    }
5089
5066
 
5090
5067
    optimizer::AccessMethodFactory &factory= optimizer::AccessMethodFactory::singleton();
5640
5617
 
5641
5618
  table_count= join->tables;
5642
5619
  stat= (JoinTable*) join->session->mem.calloc(sizeof(JoinTable)*table_count);
5643
 
  stat_ref= (JoinTable**) join->session->mem.allocate(sizeof(JoinTable*)*MAX_TABLES);
5644
 
  table_vector= (Table**) join->session->mem.allocate(sizeof(Table*)*(table_count*2));
 
5620
  stat_ref= (JoinTable**) join->session->mem.alloc(sizeof(JoinTable*)*MAX_TABLES);
 
5621
  table_vector= (Table**) join->session->mem.alloc(sizeof(Table*)*(table_count*2));
5645
5622
  if (! stat || ! stat_ref || ! table_vector)
5646
5623
    return 1;
5647
5624