~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/optimizer/range.cc

  • Committer: Monty Taylor
  • Date: 2010-03-11 18:27:20 UTC
  • mfrom: (1333 staging)
  • mto: This revision was merged to the branch mainline in revision 1348.
  • Revision ID: mordred@inaugust.com-20100311182720-hd1h87y6cb1b1mp0
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
348
348
                                const char *msg,
349
349
                                struct st_ror_scan_info **start,
350
350
                                struct st_ror_scan_info **end);
 
351
static void print_ror_scans_vector(Table *table,
 
352
                                   const char *msg,
 
353
                                   vector<struct st_ror_scan_info *> &vec);
351
354
 
352
355
static SEL_TREE *tree_and(optimizer::RangeParameter *param, SEL_TREE *tree1, SEL_TREE *tree2);
353
356
 
1084
1087
              Try constructing covering ROR-intersect only if it looks possible
1085
1088
              and worth doing.
1086
1089
            */
1087
 
            if (!rori_trp->is_covering && can_build_covering &&
 
1090
            if (rori_trp->isRowRetrievalNecessary() && can_build_covering &&
1088
1091
                (rori_trp= get_best_covering_ror_intersect(&param, tree,
1089
1092
                                                           best_read_time)))
1090
1093
              best_trp= rori_trp;
1260
1263
    all_scans_ror_able &= ((*ptree)->n_ror_scans > 0);
1261
1264
    all_scans_rors &= (*cur_child)->is_ror;
1262
1265
    if (pk_is_clustered &&
1263
 
        param->real_keynr[(*cur_child)->key_idx] ==
 
1266
        param->real_keynr[(*cur_child)->getKeyIndex()] ==
1264
1267
        param->table->s->primary_key)
1265
1268
    {
1266
1269
      cpk_scan= cur_child;
1368
1371
    {
1369
1372
      /* Ok, we have index_only cost, now get full rows scan cost */
1370
1373
      cost= param->table->cursor->
1371
 
              read_time(param->real_keynr[(*cur_child)->key_idx], 1,
 
1374
              read_time(param->real_keynr[(*cur_child)->getKeyIndex()], 1,
1372
1375
                        (*cur_child)->records) +
1373
1376
              rows2double((*cur_child)->records) / TIME_FOR_COMPARE;
1374
1377
    }
1386
1389
      roru_index_costs += (*cur_roru_plan)->read_cost;
1387
1390
    }
1388
1391
    else
 
1392
    {
1389
1393
      roru_index_costs +=
1390
 
        ((optimizer::RorIntersectReadPlan*)(*cur_roru_plan))->index_scan_costs;
 
1394
        ((optimizer::RorIntersectReadPlan *)(*cur_roru_plan))->getCostOfIndexScans();
 
1395
    }
1391
1396
    roru_total_records += (*cur_roru_plan)->records;
1392
1397
    roru_intersect_part *= (*cur_roru_plan)->records /
1393
1398
                           param->table->cursor->stats.records;
1427
1432
  {
1428
1433
    if ((roru= new (param->mem_root) optimizer::RorUnionReadPlan))
1429
1434
    {
1430
 
      roru->first_ror= roru_read_plans;
1431
 
      roru->last_ror= roru_read_plans + n_child_scans;
 
1435
      roru->merged_scans.assign(roru_read_plans, roru_read_plans + n_child_scans);
1432
1436
      roru->read_cost= roru_total_cost;
1433
1437
      roru->records= roru_total_records;
1434
1438
      return roru;
2087
2091
    if (! (trp= new (param->mem_root) optimizer::RorIntersectReadPlan))
2088
2092
      return trp;
2089
2093
 
2090
 
    if (! (trp->first_scan=
2091
 
           (ROR_SCAN_INFO**)alloc_root(param->mem_root,
2092
 
                                       sizeof(ROR_SCAN_INFO*)*best_num)))
2093
 
      return NULL;
2094
 
    memcpy(trp->first_scan, intersect_scans, best_num*sizeof(ROR_SCAN_INFO*));
2095
 
    trp->last_scan=  trp->first_scan + best_num;
2096
 
    trp->is_covering= intersect_best->is_covering;
 
2094
    trp->ror_range_scans.assign(intersect_scans, intersect_scans + best_num);
 
2095
    trp->setRowRetrievalNecessary(intersect_best->is_covering);
2097
2096
    trp->read_cost= intersect_best->total_cost;
2098
2097
    /* Prevent divisons by zero */
2099
2098
    ha_rows best_rows = double2rows(intersect_best->out_rows);
2101
2100
      best_rows= 1;
2102
2101
    set_if_smaller(param->table->quick_condition_rows, best_rows);
2103
2102
    trp->records= best_rows;
2104
 
    trp->index_scan_costs= intersect_best->index_scan_costs;
 
2103
    trp->setCostOfIndexScans(intersect_best->index_scan_costs);
2105
2104
    trp->cpk_scan= cpk_scan_used? cpk_scan: NULL;
2106
2105
  }
2107
2106
  return(trp);
2242
2241
  }
2243
2242
 
2244
2243
  uint32_t best_num= (ror_scan_mark - tree->ror_scans);
2245
 
  if (!(trp->first_scan= (ROR_SCAN_INFO**)alloc_root(param->mem_root,
2246
 
                                                     sizeof(ROR_SCAN_INFO*)*
2247
 
                                                     best_num)))
2248
 
    return NULL;
2249
 
  memcpy(trp->first_scan, tree->ror_scans, best_num*sizeof(ROR_SCAN_INFO*));
2250
 
  trp->last_scan=  trp->first_scan + best_num;
2251
 
  trp->is_covering= true;
 
2244
  trp->ror_range_scans.assign(tree->ror_scans, tree->ror_scans + best_num);
 
2245
  trp->setRowRetrievalNecessary(true);
2252
2246
  trp->read_cost= total_cost;
2253
2247
  trp->records= records;
2254
2248
  trp->cpk_scan= NULL;
2352
2346
      read_plan->records= best_records;
2353
2347
      read_plan->is_ror= tree->ror_scans_map.test(idx);
2354
2348
      read_plan->read_cost= read_time;
2355
 
      read_plan->mrr_buf_size= best_buf_size;
 
2349
      read_plan->setMRRBufferSize(best_buf_size);
2356
2350
    }
2357
2351
  }
2358
2352
 
2402
2396
                                                (retrieve_full_rows? (! is_covering) : false),
2403
2397
                                                parent_alloc)))
2404
2398
  {
2405
 
    print_ror_scans_arr(param->table,
2406
 
                        "creating ROR-intersect",
2407
 
                        first_scan,
2408
 
                        last_scan);
 
2399
    print_ror_scans_vector(param->table,
 
2400
                           "creating ROR-intersect",
 
2401
                           ror_range_scans);
2409
2402
    alloc= parent_alloc ? parent_alloc : &quick_intersect->alloc;
2410
 
    for (; first_scan != last_scan; ++first_scan)
 
2403
    for (vector<struct st_ror_scan_info *>::iterator it= ror_range_scans.begin();
 
2404
         it != ror_range_scans.end();
 
2405
         ++it)
2411
2406
    {
2412
2407
      if (! (quick= optimizer::get_quick_select(param,
2413
 
                                                (*first_scan)->idx,
2414
 
                                                (*first_scan)->sel_arg,
 
2408
                                                (*it)->idx,
 
2409
                                                (*it)->sel_arg,
2415
2410
                                                HA_MRR_USE_DEFAULT_IMPL | HA_MRR_SORTED,
2416
2411
                                                0,
2417
2412
                                                alloc)) ||
2446
2441
optimizer::QuickSelectInterface *optimizer::RorUnionReadPlan::make_quick(optimizer::Parameter *param, bool, memory::Root *)
2447
2442
{
2448
2443
  optimizer::QuickRorUnionSelect *quick_roru= NULL;
2449
 
  optimizer::TableReadPlan **scan= NULL;
2450
2444
  optimizer::QuickSelectInterface *quick= NULL;
2451
2445
  /*
2452
2446
    It is impossible to construct a ROR-union that will not retrieve full
2454
2448
  */
2455
2449
  if ((quick_roru= new optimizer::QuickRorUnionSelect(param->session, param->table)))
2456
2450
  {
2457
 
    for (scan= first_ror; scan != last_ror; scan++)
 
2451
    for (vector<optimizer::TableReadPlan *>::iterator it= merged_scans.begin();
 
2452
         it != merged_scans.end();
 
2453
         ++it)
2458
2454
    {
2459
 
      if (! (quick= (*scan)->make_quick(param, false, &quick_roru->alloc)) ||
 
2455
      if (! (quick= (*it)->make_quick(param, false, &quick_roru->alloc)) ||
2460
2456
          quick_roru->push_quick_back(quick))
2461
2457
      {
2462
2458
        return NULL;
6408
6404
    tmp.append(STRING_WITH_LEN("(empty)"));
6409
6405
}
6410
6406
 
 
6407
static void print_ror_scans_vector(Table *table,
 
6408
                                   const char *,
 
6409
                                   vector<struct st_ror_scan_info *> &vec)
 
6410
{
 
6411
  char buff[1024];
 
6412
  String tmp(buff,sizeof(buff),&my_charset_bin);
 
6413
  tmp.length(0);
 
6414
  for (vector<struct st_ror_scan_info *>::iterator it= vec.begin();
 
6415
       it != vec.end();
 
6416
       ++it)
 
6417
  {
 
6418
    if (tmp.length())
 
6419
      tmp.append(',');
 
6420
    tmp.append(table->key_info[(*it)->keynr].name);
 
6421
  }
 
6422
  if (! tmp.length())
 
6423
    tmp.append(STRING_WITH_LEN("(empty)"));
 
6424
}
 
6425
 
6411
6426
} /* namespace drizzled */