~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_select.cc

  • Committer: Mark Atwood
  • Date: 2011-06-24 11:45:17 UTC
  • mfrom: (2318.6.64 rf)
  • Revision ID: me@mark.atwood.name-20110624114517-1mq8no6jlp2nrg7m
mergeĀ lp:~olafvdspek/drizzle/refactor15

Show diffs side-by-side

added added

removed removed

Lines of Context:
462
462
{
463
463
  int error;
464
464
  if (check_stack_overrun(session, STACK_MIN_SIZE, NULL))
465
 
    return(0);                           // Fatal error flag is set
 
465
    return 0;                           // Fatal error flag is set
466
466
  if (select)
467
467
  {
468
468
    select->head=table;
473
473
    if (error == -1)
474
474
    {
475
475
      table->reginfo.impossible_range=1;
476
 
      return(0);
 
476
      return 0;
477
477
    }
478
478
  }
479
479
  return(HA_POS_ERROR);                 /* This shouldn't happend */
549
549
                         Select_Lex *select_lex,
550
550
                         vector<optimizer::SargableParam> &sargables)
551
551
{
552
 
  uint  and_level,found_eq_constant;
553
 
  optimizer::KeyField *key_fields, *end, *field;
554
 
  uint32_t sz;
555
552
  uint32_t m= max(select_lex->max_equal_elems,(uint32_t)1);
556
553
 
557
554
  /*
571
568
    can be not more than select_lex->max_equal_elems such
572
569
    substitutions.
573
570
  */
574
 
  sz= sizeof(optimizer::KeyField) *
575
 
      (((session->lex().current_select->cond_count+1)*2 +
576
 
        session->lex().current_select->between_count)*m+1);
577
 
  key_fields= (optimizer::KeyField*) session->mem.alloc(sz);
578
 
  and_level= 0;
 
571
  optimizer::KeyField* key_fields= new (session->mem) optimizer::KeyField[((session->lex().current_select->cond_count+1)*2 + session->lex().current_select->between_count)*m+1];
 
572
  uint and_level= 0;
 
573
  optimizer::KeyField* end, *field;
579
574
  field= end= key_fields;
580
575
 
581
576
  my_init_dynamic_array(keyuse, sizeof(optimizer::KeyUse), 20, 64);
648
643
 
649
644
    use= save_pos= (optimizer::KeyUse*)keyuse->buffer;
650
645
    prev= &key_end;
651
 
    found_eq_constant= 0;
 
646
    uint found_eq_constant= 0;
652
647
    {
653
648
      uint32_t i;
654
649
 
1000
995
  j->ref.key_length=length;
1001
996
  j->ref.key=(int) key;
1002
997
  j->ref.key_buff= (unsigned char*) session->mem.calloc(ALIGN_SIZE(length)*2);
1003
 
  j->ref.key_copy= (StoredKey**) session->mem.alloc((sizeof(StoredKey*) * (keyparts+1)));
1004
 
  j->ref.items=    (Item**) session->mem.alloc(sizeof(Item*)*keyparts);
1005
 
  j->ref.cond_guards= (bool**) session->mem.alloc(sizeof(uint*)*keyparts);
 
998
  j->ref.key_copy= new (session->mem) StoredKey*[keyparts + 1];
 
999
  j->ref.items= new (session->mem) Item*[keyparts];
 
1000
  j->ref.cond_guards= new (session->mem) bool*[keyparts];
1006
1001
  j->ref.key_buff2=j->ref.key_buff+ALIGN_SIZE(length);
1007
1002
  j->ref.key_err=1;
1008
1003
  j->ref.null_rejecting= 0;
4232
4227
          return(1);
4233
4228
      }
4234
4229
      else
4235
 
        return(0);
 
4230
        return 0;
4236
4231
    }
4237
4232
 
4238
4233
    if (key_part->field != field)
4239
 
      return(0);
 
4234
      return 0;
4240
4235
 
4241
4236
    /* set flag to 1 if we can use read-next on key, else to -1 */
4242
4237
    flag= ((order->asc == !(key_part->key_part_flag & HA_REVERSE_SORT)) ?
4243
4238
           1 : -1);
4244
4239
    if (reverse && flag != reverse)
4245
 
      return(0);
 
4240
      return 0;
4246
4241
    reverse=flag;                               // Remember if reverse
4247
4242
    key_part++;
4248
4243
  }
4487
4482
    if (item->type() != Item::FIELD_ITEM)
4488
4483
    {
4489
4484
      usable_keys.reset();
4490
 
      return(0);
 
4485
      return 0;
4491
4486
    }
4492
4487
    usable_keys&= ((Item_field*) item)->field->part_of_sortkey;
4493
4488
    if (usable_keys.none())
4494
 
      return(0);                                        // No usable keys
 
4489
      return 0;                                 // No usable keys
4495
4490
  }
4496
4491
 
4497
4492
  ref_key= -1;
4501
4496
    ref_key=       tab->ref.key;
4502
4497
    ref_key_parts= tab->ref.key_parts;
4503
4498
    if (tab->type == AM_REF_OR_NULL)
4504
 
      return(0);
 
4499
      return 0;
4505
4500
  }
4506
4501
  else if (select && select->quick)             // Range found by optimizer/range
4507
4502
  {
4516
4511
    if (quick_type == optimizer::QuickSelectInterface::QS_TYPE_INDEX_MERGE ||
4517
4512
        quick_type == optimizer::QuickSelectInterface::QS_TYPE_ROR_UNION ||
4518
4513
        quick_type == optimizer::QuickSelectInterface::QS_TYPE_ROR_INTERSECT)
4519
 
      return(0);
 
4514
      return 0;
4520
4515
    ref_key=       select->quick->index;
4521
4516
    ref_key_parts= select->quick->used_key_parts;
4522
4517
  }
4560
4555
 
4561
4556
          if (create_ref_for_key(tab->join, tab, keyuse,
4562
4557
                                 tab->join->const_table_map))
4563
 
            return(0);
 
4558
            return 0;
4564
4559
        }
4565
4560
        else
4566
4561
        {
4583
4578
                                        tab->join->unit->select_limit_cnt,0,
4584
4579
                                        true) <=
4585
4580
              0)
4586
 
            return(0);
 
4581
            return 0;
4587
4582
        }
4588
4583
        ref_key= new_ref_key;
4589
4584
      }
4628
4623
        index order and not using join cache
4629
4624
        */
4630
4625
      if (tab->type == AM_ALL && tab->join->tables > tab->join->const_tables + 1)
4631
 
        return(0);
 
4626
        return 0;
4632
4627
      keys= *table->cursor->keys_to_use_for_scanning();
4633
4628
      keys|= table->covering_keys;
4634
4629
 
4819
4814
      order_direction= best_key_direction;
4820
4815
    }
4821
4816
    else
4822
 
      return(0);
 
4817
      return 0;
4823
4818
  }
4824
4819
 
4825
4820
check_reverse_order:
4915
4910
  JoinTable *tab;
4916
4911
 
4917
4912
  if (join->tables == join->const_tables)
4918
 
    return(0);                          // One row, no need to sort
 
4913
    return 0;                           // One row, no need to sort
4919
4914
  tab=    join->join_tab + join->const_tables;
4920
4915
  table=  tab->table;
4921
4916
  select= tab->select;
4932
4927
      test_if_skip_sort_order(tab,order,select_limit,0,
4933
4928
                              is_order_by ?  &table->keys_in_use_for_order_by :
4934
4929
                              &table->keys_in_use_for_group_by))
4935
 
    return(0);
 
4930
    return 0;
4936
4931
  for (Order *ord= join->order; ord; ord= ord->next)
4937
4932
    length++;
4938
4933
  join->sortorder= make_unireg_sortorder(order, &length, join->sortorder);
5073
5068
  }
5074
5069
 
5075
5070
  cursor->extra(HA_EXTRA_NO_CACHE);
5076
 
  return(0);
 
5071
  return 0;
5077
5072
err:
5078
5073
  cursor->extra(HA_EXTRA_NO_CACHE);
5079
5074
  if (error)
5856
5851
  */
5857
5852
  param->copy_funcs.concat(&extra_funcs);
5858
5853
 
5859
 
  return(0);
 
5854
  return 0;
5860
5855
 
5861
5856
err:
5862
5857
  if (copy)